1 | /*****************************************************************************/ |
2 | // Copyright 2006-2008 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_matrix.h#2 $ */ |
10 | /* $DateTime: 2012/07/31 22:04:34 $ */ |
11 | /* $Change: 840853 $ */ |
12 | /* $Author: tknoll $ */ |
13 | |
14 | /** \file |
15 | * Matrix and vector classes, including specialized 3x3 and 4x3 versions as |
16 | * well as length 3 vectors. |
17 | */ |
18 | |
19 | /*****************************************************************************/ |
20 | |
21 | #ifndef __dng_matrix__ |
22 | #define __dng_matrix__ |
23 | |
24 | /*****************************************************************************/ |
25 | |
26 | #include "dng_sdk_limits.h" |
27 | #include "dng_types.h" |
28 | |
29 | /*****************************************************************************/ |
30 | |
31 | /// \brief Class to represent 2D matrix up to kMaxColorPlanes x kMaxColorPlanes |
32 | /// in size. |
33 | |
34 | class dng_matrix |
35 | { |
36 | |
37 | protected: |
38 | |
39 | uint32 fRows; |
40 | uint32 fCols; |
41 | |
42 | real64 fData [kMaxColorPlanes] [kMaxColorPlanes]; |
43 | |
44 | public: |
45 | |
46 | dng_matrix (); |
47 | |
48 | dng_matrix (uint32 rows, |
49 | uint32 cols); |
50 | |
51 | dng_matrix (const dng_matrix &m); |
52 | |
53 | virtual ~dng_matrix () |
54 | { |
55 | } |
56 | |
57 | void Clear (); |
58 | |
59 | void SetIdentity (uint32 count); |
60 | |
61 | uint32 Rows () const |
62 | { |
63 | return fRows; |
64 | } |
65 | |
66 | uint32 Cols () const |
67 | { |
68 | return fCols; |
69 | } |
70 | |
71 | real64 * operator [] (uint32 row) |
72 | { |
73 | return fData [row]; |
74 | } |
75 | |
76 | const real64 * operator [] (uint32 row) const |
77 | { |
78 | return fData [row]; |
79 | } |
80 | |
81 | bool operator== (const dng_matrix &m) const; |
82 | |
83 | bool operator!= (const dng_matrix &m) const |
84 | { |
85 | return !(*this == m); |
86 | } |
87 | |
88 | bool IsEmpty () const |
89 | { |
90 | return fRows == 0 || fCols == 0; |
91 | } |
92 | |
93 | bool NotEmpty () const |
94 | { |
95 | return !IsEmpty (); |
96 | } |
97 | |
98 | bool IsDiagonal () const; |
99 | |
100 | real64 MaxEntry () const; |
101 | |
102 | real64 MinEntry () const; |
103 | |
104 | void Scale (real64 factor); |
105 | |
106 | void Round (real64 factor); |
107 | |
108 | void SafeRound (real64 factor); |
109 | |
110 | }; |
111 | |
112 | /*****************************************************************************/ |
113 | |
114 | /// \brief A 3x3 matrix. |
115 | |
116 | class dng_matrix_3by3: public dng_matrix |
117 | { |
118 | |
119 | public: |
120 | |
121 | dng_matrix_3by3 (); |
122 | |
123 | dng_matrix_3by3 (const dng_matrix &m); |
124 | |
125 | dng_matrix_3by3 (real64 a00, real64 a01, real64 a02, |
126 | real64 a10, real64 a11, real64 a12, |
127 | real64 a20, real64 a21, real64 a22); |
128 | |
129 | dng_matrix_3by3 (real64 a00, real64 a11, real64 a22); |
130 | |
131 | }; |
132 | |
133 | /*****************************************************************************/ |
134 | |
135 | /// \brief A 4x3 matrix. Handy for working with 4-color cameras. |
136 | |
137 | class dng_matrix_4by3: public dng_matrix |
138 | { |
139 | |
140 | public: |
141 | |
142 | dng_matrix_4by3 (); |
143 | |
144 | dng_matrix_4by3 (const dng_matrix &m); |
145 | |
146 | dng_matrix_4by3 (real64 a00, real64 a01, real64 a02, |
147 | real64 a10, real64 a11, real64 a12, |
148 | real64 a20, real64 a21, real64 a22, |
149 | real64 a30, real64 a31, real64 a32); |
150 | |
151 | }; |
152 | |
153 | /*****************************************************************************/ |
154 | |
155 | /// \brief Class to represent 1-dimensional vector with up to kMaxColorPlanes |
156 | /// components. |
157 | |
158 | class dng_vector |
159 | { |
160 | |
161 | protected: |
162 | |
163 | uint32 fCount; |
164 | |
165 | real64 fData [kMaxColorPlanes]; |
166 | |
167 | public: |
168 | |
169 | dng_vector (); |
170 | |
171 | dng_vector (uint32 count); |
172 | |
173 | dng_vector (const dng_vector &v); |
174 | |
175 | virtual ~dng_vector () |
176 | { |
177 | } |
178 | |
179 | void Clear (); |
180 | |
181 | void SetIdentity (uint32 count); |
182 | |
183 | uint32 Count () const |
184 | { |
185 | return fCount; |
186 | } |
187 | |
188 | real64 & operator [] (uint32 index) |
189 | { |
190 | return fData [index]; |
191 | } |
192 | |
193 | const real64 & operator [] (uint32 index) const |
194 | { |
195 | return fData [index]; |
196 | } |
197 | |
198 | bool operator== (const dng_vector &v) const; |
199 | |
200 | bool operator!= (const dng_vector &v) const |
201 | { |
202 | return !(*this == v); |
203 | } |
204 | |
205 | bool IsEmpty () const |
206 | { |
207 | return fCount == 0; |
208 | } |
209 | |
210 | bool NotEmpty () const |
211 | { |
212 | return !IsEmpty (); |
213 | } |
214 | |
215 | real64 MaxEntry () const; |
216 | |
217 | real64 MinEntry () const; |
218 | |
219 | void Scale (real64 factor); |
220 | |
221 | void Round (real64 factor); |
222 | |
223 | dng_matrix AsDiagonal () const; |
224 | |
225 | dng_matrix AsColumn () const; |
226 | |
227 | }; |
228 | |
229 | /*****************************************************************************/ |
230 | |
231 | /// \brief A 3-element vector. |
232 | |
233 | class dng_vector_3: public dng_vector |
234 | { |
235 | |
236 | public: |
237 | |
238 | dng_vector_3 (); |
239 | |
240 | dng_vector_3 (const dng_vector &v); |
241 | |
242 | dng_vector_3 (real64 a0, |
243 | real64 a1, |
244 | real64 a2); |
245 | |
246 | }; |
247 | |
248 | /*****************************************************************************/ |
249 | |
250 | /// \brief A 4-element vector. |
251 | |
252 | class dng_vector_4: public dng_vector |
253 | { |
254 | |
255 | public: |
256 | |
257 | dng_vector_4 (); |
258 | |
259 | dng_vector_4 (const dng_vector &v); |
260 | |
261 | dng_vector_4 (real64 a0, |
262 | real64 a1, |
263 | real64 a2, |
264 | real64 a3); |
265 | |
266 | }; |
267 | |
268 | /*****************************************************************************/ |
269 | |
270 | dng_matrix operator* (const dng_matrix &A, |
271 | const dng_matrix &B); |
272 | |
273 | dng_vector operator* (const dng_matrix &A, |
274 | const dng_vector &B); |
275 | |
276 | dng_matrix operator* (real64 scale, |
277 | const dng_matrix &A); |
278 | |
279 | dng_vector operator* (real64 scale, |
280 | const dng_vector &A); |
281 | |
282 | /*****************************************************************************/ |
283 | |
284 | dng_matrix operator+ (const dng_matrix &A, |
285 | const dng_matrix &B); |
286 | |
287 | /*****************************************************************************/ |
288 | |
289 | dng_matrix Transpose (const dng_matrix &A); |
290 | |
291 | /*****************************************************************************/ |
292 | |
293 | dng_matrix Invert (const dng_matrix &A); |
294 | |
295 | dng_matrix Invert (const dng_matrix &A, |
296 | const dng_matrix &hint); |
297 | |
298 | /*****************************************************************************/ |
299 | |
300 | inline real64 MaxEntry (const dng_matrix &A) |
301 | { |
302 | return A.MaxEntry (); |
303 | } |
304 | |
305 | inline real64 MaxEntry (const dng_vector &A) |
306 | { |
307 | return A.MaxEntry (); |
308 | } |
309 | |
310 | /*****************************************************************************/ |
311 | |
312 | inline real64 MinEntry (const dng_matrix &A) |
313 | { |
314 | return A.MinEntry (); |
315 | } |
316 | |
317 | inline real64 MinEntry (const dng_vector &A) |
318 | { |
319 | return A.MinEntry (); |
320 | } |
321 | |
322 | /*****************************************************************************/ |
323 | |
324 | #endif |
325 | |
326 | /*****************************************************************************/ |
327 | |