| 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 |
#ifndef __dng_orientation__ |
| 10 |
#define __dng_orientation__ |
| 11 |
|
| 12 |
/******************************************************************************/ |
| 13 |
|
| 14 |
#include "dng_matrix.h" |
| 15 |
#include "dng_types.h" |
| 16 |
|
| 17 |
/******************************************************************************/ |
| 18 |
|
| 19 |
class dng_orientation |
| 20 |
{ |
| 21 |
|
| 22 |
private: |
| 23 |
|
| 24 |
// We internally use an orientation encoding ("Adobe") that is |
| 25 |
// different than the TIFF orientation encoding ("TIFF"). |
| 26 |
|
| 27 |
uint32 fAdobeOrientation; |
| 28 |
|
| 29 |
public: |
| 30 |
|
| 31 |
enum |
| 32 |
{ |
| 33 |
kNormal = 0, |
| 34 |
kRotate90CW = 1, |
| 35 |
kRotate180 = 2, |
| 36 |
kRotate90CCW = 3, |
| 37 |
kMirror = 4, |
| 38 |
kMirror90CW = 5, |
| 39 |
kMirror180 = 6, |
| 40 |
kMirror90CCW = 7, |
| 41 |
kUnknown = 8 |
| 42 |
}; |
| 43 |
|
| 44 |
dng_orientation () |
| 45 |
|
| 46 |
: fAdobeOrientation (kNormal) |
| 47 |
|
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
void SetAdobe (uint32 adobe) |
| 52 |
{ |
| 53 |
fAdobeOrientation = adobe; |
| 54 |
} |
| 55 |
|
| 56 |
uint32 GetAdobe () const |
| 57 |
{ |
| 58 |
return fAdobeOrientation; |
| 59 |
} |
| 60 |
|
| 61 |
void SetTIFF (uint32 tiff); |
| 62 |
|
| 63 |
uint32 GetTIFF () const; |
| 64 |
|
| 65 |
static dng_orientation AdobeToDNG (uint32 adobe) |
| 66 |
{ |
| 67 |
|
| 68 |
dng_orientation result; |
| 69 |
|
| 70 |
result.SetAdobe (adobe); |
| 71 |
|
| 72 |
return result; |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
static dng_orientation TIFFtoDNG (uint32 tiff) |
| 77 |
{ |
| 78 |
|
| 79 |
dng_orientation result; |
| 80 |
|
| 81 |
result.SetTIFF (tiff); |
| 82 |
|
| 83 |
return result; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
static dng_orientation Normal () |
| 88 |
{ |
| 89 |
return AdobeToDNG (kNormal); |
| 90 |
} |
| 91 |
|
| 92 |
static dng_orientation Rotate90CW () |
| 93 |
{ |
| 94 |
return AdobeToDNG (kRotate90CW); |
| 95 |
} |
| 96 |
|
| 97 |
static dng_orientation Rotate180 () |
| 98 |
{ |
| 99 |
return AdobeToDNG (kRotate180); |
| 100 |
} |
| 101 |
|
| 102 |
static dng_orientation Rotate90CCW () |
| 103 |
{ |
| 104 |
return AdobeToDNG (kRotate90CCW); |
| 105 |
} |
| 106 |
|
| 107 |
static dng_orientation Mirror () |
| 108 |
{ |
| 109 |
return AdobeToDNG (kMirror); |
| 110 |
} |
| 111 |
|
| 112 |
static dng_orientation Mirror90CW () |
| 113 |
{ |
| 114 |
return AdobeToDNG (kMirror90CW); |
| 115 |
} |
| 116 |
|
| 117 |
static dng_orientation Mirror180 () |
| 118 |
{ |
| 119 |
return AdobeToDNG (kMirror180); |
| 120 |
} |
| 121 |
|
| 122 |
static dng_orientation Mirror90CCW () |
| 123 |
{ |
| 124 |
return AdobeToDNG (kMirror90CCW); |
| 125 |
} |
| 126 |
|
| 127 |
static dng_orientation Unknown () |
| 128 |
{ |
| 129 |
return AdobeToDNG (kUnknown); |
| 130 |
} |
| 131 |
|
| 132 |
bool IsValid () const |
| 133 |
{ |
| 134 |
return fAdobeOrientation < kUnknown; |
| 135 |
} |
| 136 |
|
| 137 |
bool NotValid () const |
| 138 |
{ |
| 139 |
return !IsValid (); |
| 140 |
} |
| 141 |
|
| 142 |
bool FlipD () const; |
| 143 |
|
| 144 |
bool FlipH () const; |
| 145 |
|
| 146 |
bool FlipV () const; |
| 147 |
|
| 148 |
bool IsMirrored () const; |
| 149 |
|
| 150 |
bool operator== (const dng_orientation &b) const |
| 151 |
{ |
| 152 |
return fAdobeOrientation == b.fAdobeOrientation; |
| 153 |
} |
| 154 |
|
| 155 |
bool operator!= (const dng_orientation &b) const |
| 156 |
{ |
| 157 |
return !(*this == b); |
| 158 |
} |
| 159 |
|
| 160 |
dng_orientation operator- () const; |
| 161 |
|
| 162 |
// Be careful when composing orientations using the + and - operators. |
| 163 |
// In mathematics, the + operator is commutative, namely, |
| 164 |
// |
| 165 |
// a + b == b + a |
| 166 |
// |
| 167 |
// An orientation transform represents a linear transform, so |
| 168 |
// composing two orientation transforms amounts to a matrix |
| 169 |
// multiplication, which is associative but NOT commutative. |
| 170 |
// |
| 171 |
// For example, suppose we know that A, B, and C are dng_orientation |
| 172 |
// objects such that |
| 173 |
// |
| 174 |
// C = A + B |
| 175 |
// |
| 176 |
// That is, C is the orientation obtained by applying A then B. If |
| 177 |
// we're given A and C and want to calculate B, the correct expression |
| 178 |
// is: |
| 179 |
// |
| 180 |
// B = -A + C // correct |
| 181 |
// |
| 182 |
// and not |
| 183 |
// |
| 184 |
// B = C - A // incorrect |
| 185 |
// |
| 186 |
// On first glance, these appear to be the same expressions but they |
| 187 |
// are not. |
| 188 |
|
| 189 |
dng_orientation operator+ (const dng_orientation &b) const; |
| 190 |
|
| 191 |
dng_orientation operator- (const dng_orientation &b) const |
| 192 |
{ |
| 193 |
return (*this) + (-b); |
| 194 |
} |
| 195 |
|
| 196 |
void operator+= (const dng_orientation &b) |
| 197 |
{ |
| 198 |
*this = *this + b; |
| 199 |
} |
| 200 |
|
| 201 |
void operator-= (const dng_orientation &b) |
| 202 |
{ |
| 203 |
*this = *this - b; |
| 204 |
} |
| 205 |
|
| 206 |
// If horizontalFirstRow is true, then the x (horizontal h) component |
| 207 |
// of the transform will be in the first row of the resulting matrix, |
| 208 |
// and the y (vertical v) component will be in the second row. |
| 209 |
// |
| 210 |
// If horizontalFirstRow is false, then the y (vertical v) component |
| 211 |
// of the transform will be in the first row of the resulting matrix, |
| 212 |
// and the x (horizontal h) component will be in the second row. |
| 213 |
|
| 214 |
bool CalcForwardMatrix3by3 (dng_matrix &matrix, |
| 215 |
bool horizontalFirstRow) const; |
| 216 |
|
| 217 |
bool CalcForwardMatrix4by4 (dng_matrix &matrix, |
| 218 |
bool horizontalFirstRow) const; |
| 219 |
|
| 220 |
}; |
| 221 |
|
| 222 |
/******************************************************************************/ |
| 223 |
|
| 224 |
#endif |
| 225 |
|
| 226 |
/******************************************************************************/ |