Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_orientation.cpp

raw
1 /*****************************************************************************/
2 // Copyright 2006-2019 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 #include "dng_orientation.h"
10
11 /*****************************************************************************/
12
13 void dng_orientation::SetTIFF (uint32 tiff)
14 {
15
16 switch (tiff)
17 {
18
19 case 1:
20 {
21 fAdobeOrientation = kNormal;
22 break;
23 }
24
25 case 2:
26 {
27 fAdobeOrientation = kMirror;
28 break;
29 }
30
31 case 3:
32 {
33 fAdobeOrientation = kRotate180;
34 break;
35 }
36
37 case 4:
38 {
39 fAdobeOrientation = kMirror180;
40 break;
41 }
42
43 case 5:
44 {
45 fAdobeOrientation = kMirror90CCW;
46 break;
47 }
48
49 case 6:
50 {
51 fAdobeOrientation = kRotate90CW;
52 break;
53 }
54
55 case 7:
56 {
57 fAdobeOrientation = kMirror90CW;
58 break;
59 }
60
61 case 8:
62 {
63 fAdobeOrientation = kRotate90CCW;
64 break;
65 }
66
67 case 9:
68 {
69 fAdobeOrientation = kUnknown;
70 break;
71 }
72
73 default:
74 {
75 fAdobeOrientation = kNormal;
76 }
77
78 }
79
80 }
81
82 /*****************************************************************************/
83
84 uint32 dng_orientation::GetTIFF () const
85 {
86
87 switch (fAdobeOrientation)
88 {
89
90 case kNormal:
91 {
92 return 1;
93 }
94
95 case kMirror:
96 {
97 return 2;
98 }
99
100 case kRotate180:
101 {
102 return 3;
103 }
104
105 case kMirror180:
106 {
107 return 4;
108 }
109
110 case kMirror90CCW:
111 {
112 return 5;
113 }
114
115 case kRotate90CW:
116 {
117 return 6;
118 }
119
120 case kMirror90CW:
121 {
122 return 7;
123 }
124
125 case kRotate90CCW:
126 {
127 return 8;
128 }
129
130 case kUnknown:
131 {
132 return 9;
133 }
134
135 default:
136 break;
137
138 }
139
140 return 1;
141
142 }
143
144 /*****************************************************************************/
145
146 bool dng_orientation::FlipD () const
147 {
148
149 return (fAdobeOrientation & 1) != 0;
150
151 }
152
153 /*****************************************************************************/
154
155 bool dng_orientation::FlipH () const
156 {
157
158 if (fAdobeOrientation & 4)
159 return (fAdobeOrientation & 2) == 0;
160
161 else
162 return (fAdobeOrientation & 2) != 0;
163
164 }
165
166 /*****************************************************************************/
167
168 bool dng_orientation::FlipV () const
169 {
170
171 if (fAdobeOrientation & 4)
172 return FlipD () == FlipH ();
173
174 else
175 return FlipD () != FlipH ();
176
177 }
178
179 /*****************************************************************************/
180
181 bool dng_orientation::IsMirrored () const
182 {
183
184 return (fAdobeOrientation & 4) != 0;
185
186 }
187
188 /*****************************************************************************/
189
190 dng_orientation dng_orientation::operator- () const
191 {
192
193 uint32 x = GetAdobe ();
194
195 if ((x & 5) == 5)
196 {
197
198 x ^= 2;
199
200 }
201
202 dng_orientation result;
203
204 result.SetAdobe (((4 - x) & 3) | (x & 4));
205
206 return result;
207
208 }
209
210 /*****************************************************************************/
211
212 dng_orientation dng_orientation::operator+ (const dng_orientation &b) const
213 {
214
215 uint32 x = GetAdobe ();
216
217 uint32 y = b.GetAdobe ();
218
219 if (y & 4)
220 {
221
222 if (x & 1)
223 x ^= 6;
224 else
225 x ^= 4;
226
227 }
228
229 dng_orientation result;
230
231 result.SetAdobe (((x + y) & 3) | (x & 4));
232
233 return result;
234
235 }
236
237 /*****************************************************************************/
238
239 bool dng_orientation::CalcForwardMatrix3by3 (dng_matrix &orientationMatrix,
240 const bool horizontalFirstRow) const
241 {
242
243 bool hasOrient = false;
244
245 orientationMatrix.SetIdentity (3);
246
247 if (FlipH ())
248 {
249
250 hasOrient = true;
251
252 if (horizontalFirstRow)
253 {
254
255 orientationMatrix = dng_matrix_3by3 (-1.0, 0.0, 1.0,
256 0.0, 1.0, 0.0,
257 0.0, 0.0, 1.0) *
258 orientationMatrix;
259
260 }
261
262 else
263 {
264
265 orientationMatrix = dng_matrix_3by3 (1.0, 0.0, 0.0,
266 0.0, -1.0, 1.0,
267 0.0, 0.0, 1.0) *
268 orientationMatrix;
269
270 }
271
272 }
273
274 if (FlipV ())
275 {
276
277 hasOrient = true;
278
279 if (horizontalFirstRow)
280 {
281
282 orientationMatrix = dng_matrix_3by3 (1.0, 0.0, 0.0,
283 0.0, -1.0, 1.0,
284 0.0, 0.0, 1.0) *
285 orientationMatrix;
286
287 }
288
289 else
290 {
291
292 orientationMatrix = dng_matrix_3by3 (-1.0, 0.0, 1.0,
293 0.0, 1.0, 0.0,
294 0.0, 0.0, 1.0) *
295 orientationMatrix;
296
297 }
298
299 }
300
301 if (FlipD ())
302 {
303
304 hasOrient = true;
305
306 orientationMatrix = dng_matrix_3by3 (0.0, 1.0, 0.0,
307 1.0, 0.0, 0.0,
308 0.0, 0.0, 1.0) *
309 orientationMatrix;
310
311 }
312
313 return hasOrient;
314
315 }
316
317 /*****************************************************************************/
318
319 bool dng_orientation::CalcForwardMatrix4by4 (dng_matrix &orientationMatrix,
320 const bool horizontalFirstRow) const
321 {
322
323 bool hasOrient = false;
324
325 orientationMatrix.SetIdentity (4);
326
327 if (FlipH ())
328 {
329
330 hasOrient = true;
331
332 if (horizontalFirstRow)
333 {
334
335 orientationMatrix = dng_matrix_4by4 (-1.0, 0.0, 0.0, 1.0,
336 0.0, 1.0, 0.0, 0.0,
337 0.0, 0.0, 1.0, 0.0,
338 0.0, 0.0, 0.0, 1.0);
339
340 }
341
342 else
343 {
344
345 orientationMatrix = dng_matrix_4by4 (1.0, 0.0, 0.0, 0.0,
346 0.0, -1.0, 0.0, 1.0,
347 0.0, 0.0, 1.0, 0.0,
348 0.0, 0.0, 0.0, 1.0);
349
350 }
351
352 }
353
354 if (FlipV ())
355 {
356
357 hasOrient = true;
358
359 if (horizontalFirstRow)
360 {
361
362 orientationMatrix = dng_matrix_4by4 (1.0, 0.0, 0.0, 0.0,
363 0.0, -1.0, 0.0, 1.0,
364 0.0, 0.0, 1.0, 0.0,
365 0.0, 0.0, 0.0, 1.0) *
366 orientationMatrix;
367
368 }
369
370 else
371 {
372
373 orientationMatrix = dng_matrix_4by4 (-1.0, 0.0, 0.0, 1.0,
374 0.0, 1.0, 0.0, 0.0,
375 0.0, 0.0, 1.0, 0.0,
376 0.0, 0.0, 0.0, 1.0) *
377 orientationMatrix;
378
379 }
380
381 }
382
383 if (FlipD ())
384 {
385
386 hasOrient = true;
387
388 orientationMatrix = dng_matrix_4by4 (0.0, 1.0, 0.0, 0.0,
389 1.0, 0.0, 0.0, 0.0,
390 0.0, 0.0, 1.0, 0.0,
391 0.0, 0.0, 0.0, 1.0) *
392 orientationMatrix;
393
394 }
395
396 return hasOrient;
397
398 }
399
400 /*****************************************************************************/