/src/skia/third_party/externals/dng_sdk/source/dng_opcode_list.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /*****************************************************************************/ |
2 | | // Copyright 2008-2009 Adobe Systems Incorporated |
3 | | // All Rights Reserved. |
4 | | // |
5 | | // NOTICE: Adobe permits you to use, modify, and distribute this file in |
6 | | // accordance with the terms of the Adobe license agreement accompanying it. |
7 | | /*****************************************************************************/ |
8 | | |
9 | | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_opcode_list.cpp#1 $ */ |
10 | | /* $DateTime: 2012/05/30 13:28:51 $ */ |
11 | | /* $Change: 832332 $ */ |
12 | | /* $Author: tknoll $ */ |
13 | | |
14 | | /*****************************************************************************/ |
15 | | |
16 | | #include "dng_opcode_list.h" |
17 | | |
18 | | #include "dng_globals.h" |
19 | | #include "dng_host.h" |
20 | | #include "dng_memory_stream.h" |
21 | | #include "dng_negative.h" |
22 | | #include "dng_tag_values.h" |
23 | | #include "dng_utils.h" |
24 | | |
25 | | #include <algorithm> |
26 | | |
27 | | /*****************************************************************************/ |
28 | | |
29 | | dng_opcode_list::dng_opcode_list (uint32 stage) |
30 | | |
31 | | : fList () |
32 | | , fAlwaysApply (false) |
33 | | , fStage (stage) |
34 | | |
35 | 0 | { |
36 | | |
37 | 0 | } |
38 | | |
39 | | /******************************************************************************/ |
40 | | |
41 | | dng_opcode_list::~dng_opcode_list () |
42 | 0 | { |
43 | | |
44 | 0 | Clear (); |
45 | | |
46 | 0 | } |
47 | | |
48 | | /******************************************************************************/ |
49 | | |
50 | | void dng_opcode_list::Clear () |
51 | 0 | { |
52 | | |
53 | 0 | for (size_t index = 0; index < fList.size (); index++) |
54 | 0 | { |
55 | | |
56 | 0 | if (fList [index]) |
57 | 0 | { |
58 | | |
59 | 0 | delete fList [index]; |
60 | | |
61 | 0 | fList [index] = NULL; |
62 | | |
63 | 0 | } |
64 | | |
65 | 0 | } |
66 | | |
67 | 0 | fList.clear (); |
68 | | |
69 | 0 | fAlwaysApply = false; |
70 | | |
71 | 0 | } |
72 | | |
73 | | /******************************************************************************/ |
74 | | |
75 | | void dng_opcode_list::Swap (dng_opcode_list &otherList) |
76 | 0 | { |
77 | | |
78 | 0 | fList.swap (otherList.fList); |
79 | | |
80 | 0 | std::swap (fAlwaysApply, otherList.fAlwaysApply); |
81 | | |
82 | 0 | std::swap (fStage, otherList.fStage); |
83 | | |
84 | 0 | } |
85 | | |
86 | | /******************************************************************************/ |
87 | | |
88 | | uint32 dng_opcode_list::MinVersion (bool includeOptional) const |
89 | 0 | { |
90 | | |
91 | 0 | uint32 result = dngVersion_None; |
92 | | |
93 | 0 | for (size_t index = 0; index < fList.size (); index++) |
94 | 0 | { |
95 | | |
96 | 0 | if (includeOptional || !fList [index]->Optional ()) |
97 | 0 | { |
98 | | |
99 | 0 | result = Max_uint32 (result, fList [index]->MinVersion ()); |
100 | | |
101 | 0 | } |
102 | | |
103 | 0 | } |
104 | | |
105 | 0 | return result; |
106 | | |
107 | 0 | } |
108 | | |
109 | | /*****************************************************************************/ |
110 | | |
111 | | void dng_opcode_list::Apply (dng_host &host, |
112 | | dng_negative &negative, |
113 | | AutoPtr<dng_image> &image) |
114 | 0 | { |
115 | | |
116 | 0 | for (uint32 index = 0; index < Count (); index++) |
117 | 0 | { |
118 | | |
119 | 0 | dng_opcode &opcode (Entry (index)); |
120 | | |
121 | 0 | if (opcode.AboutToApply (host, negative)) |
122 | 0 | { |
123 | | |
124 | 0 | opcode.Apply (host, |
125 | 0 | negative, |
126 | 0 | image); |
127 | | |
128 | 0 | } |
129 | | |
130 | 0 | } |
131 | |
|
132 | 0 | } |
133 | | |
134 | | /*****************************************************************************/ |
135 | | |
136 | | void dng_opcode_list::Append (AutoPtr<dng_opcode> &opcode) |
137 | 0 | { |
138 | | |
139 | 0 | if (opcode->OpcodeID () == dngOpcode_Private) |
140 | 0 | { |
141 | 0 | SetAlwaysApply (); |
142 | 0 | } |
143 | | |
144 | 0 | opcode->SetStage (fStage); |
145 | | |
146 | 0 | fList.push_back (NULL); |
147 | |
|
148 | 0 | fList [fList.size () - 1] = opcode.Release (); |
149 | | |
150 | 0 | } |
151 | | |
152 | | /*****************************************************************************/ |
153 | | |
154 | | dng_memory_block * dng_opcode_list::Spool (dng_host &host) const |
155 | 0 | { |
156 | | |
157 | 0 | if (IsEmpty ()) |
158 | 0 | { |
159 | 0 | return NULL; |
160 | 0 | } |
161 | | |
162 | 0 | if (AlwaysApply ()) |
163 | 0 | { |
164 | 0 | ThrowProgramError (); |
165 | 0 | } |
166 | | |
167 | 0 | dng_memory_stream stream (host.Allocator ()); |
168 | | |
169 | 0 | stream.SetBigEndian (); |
170 | | |
171 | 0 | stream.Put_uint32 ((uint32) fList.size ()); |
172 | | |
173 | 0 | for (size_t index = 0; index < fList.size (); index++) |
174 | 0 | { |
175 | | |
176 | 0 | stream.Put_uint32 (fList [index]->OpcodeID ()); |
177 | 0 | stream.Put_uint32 (fList [index]->MinVersion ()); |
178 | 0 | stream.Put_uint32 (fList [index]->Flags ()); |
179 | | |
180 | 0 | fList [index]->PutData (stream); |
181 | | |
182 | 0 | } |
183 | | |
184 | 0 | return stream.AsMemoryBlock (host.Allocator ()); |
185 | | |
186 | 0 | } |
187 | | |
188 | | /*****************************************************************************/ |
189 | | |
190 | | void dng_opcode_list::FingerprintToStream (dng_stream &stream) const |
191 | 0 | { |
192 | | |
193 | 0 | if (IsEmpty ()) |
194 | 0 | { |
195 | 0 | return; |
196 | 0 | } |
197 | | |
198 | 0 | stream.Put_uint32 ((uint32) fList.size ()); |
199 | | |
200 | 0 | for (size_t index = 0; index < fList.size (); index++) |
201 | 0 | { |
202 | | |
203 | 0 | stream.Put_uint32 (fList [index]->OpcodeID ()); |
204 | 0 | stream.Put_uint32 (fList [index]->MinVersion ()); |
205 | 0 | stream.Put_uint32 (fList [index]->Flags ()); |
206 | | |
207 | 0 | if (fList [index]->OpcodeID () != dngOpcode_Private) |
208 | 0 | { |
209 | | |
210 | 0 | fList [index]->PutData (stream); |
211 | | |
212 | 0 | } |
213 | | |
214 | 0 | } |
215 | | |
216 | 0 | } |
217 | | |
218 | | /*****************************************************************************/ |
219 | | |
220 | | void dng_opcode_list::Parse (dng_host &host, |
221 | | dng_stream &stream, |
222 | | uint32 byteCount, |
223 | | uint64 streamOffset) |
224 | 0 | { |
225 | | |
226 | 0 | Clear (); |
227 | | |
228 | 0 | TempBigEndian tempBigEndian (stream); |
229 | | |
230 | 0 | stream.SetReadPosition (streamOffset); |
231 | | |
232 | 0 | uint32 count = stream.Get_uint32 (); |
233 | | |
234 | | #if qDNGValidate |
235 | | |
236 | | if (gVerbose) |
237 | | { |
238 | | |
239 | | if (count == 1) |
240 | | { |
241 | | printf ("1 opcode\n"); |
242 | | } |
243 | | |
244 | | else |
245 | | { |
246 | | printf ("%u opcodes\n", (unsigned) count); |
247 | | } |
248 | | |
249 | | } |
250 | | |
251 | | #endif |
252 | | |
253 | 0 | for (uint32 index = 0; index < count; index++) |
254 | 0 | { |
255 | | |
256 | 0 | uint32 opcodeID = stream.Get_uint32 (); |
257 | | |
258 | 0 | AutoPtr<dng_opcode> opcode (host.Make_dng_opcode (opcodeID, |
259 | 0 | stream)); |
260 | | |
261 | 0 | Append (opcode); |
262 | | |
263 | 0 | } |
264 | | |
265 | 0 | if (stream.Position () != streamOffset + byteCount) |
266 | 0 | { |
267 | | |
268 | 0 | ThrowBadFormat ("Error parsing opcode list"); |
269 | | |
270 | 0 | } |
271 | | |
272 | 0 | } |
273 | | |
274 | | /*****************************************************************************/ |