DocumentationOverviewBuilding ASL Documentation Library Wiki Docs Indices Browse Perforce More InfoRelease NotesWiki Site Search License Success Stories Contributors MediaDownloadPerforce Depots SupportASL SourceForge HomeMailing Lists Discussion Forums Report Bugs Suggest Features Contribute to ASL RSSShort-text newsFull-text news File releases Other Adobe ProjectsAdobe AirAdobe GIL Adobe Labs Adobe Media Gallery Adobe XMP Tamarin project (Mozilla Foundation) Other ResourcesBoostRIAForge SGI STL |
dng_rect.h00001 /*****************************************************************************/ 00002 // Copyright 2006-2007 Adobe Systems Incorporated 00003 // All Rights Reserved. 00004 // 00005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 00006 // accordance with the terms of the Adobe license agreement accompanying it. 00007 /*****************************************************************************/ 00008 00009 /* $Id: //mondo/workarea/stern/camera_raw/dng_sdk/source/dng_rect.h#8 $ */ 00010 /* $DateTime: 2009/06/17 18:39:18 $ */ 00011 /* $Change: 577175 $ */ 00012 /* $Author: stern $ */ 00013 00014 /*****************************************************************************/ 00015 00016 #ifndef __dng_rect__ 00017 #define __dng_rect__ 00018 00019 /*****************************************************************************/ 00020 00021 #include "dng_types.h" 00022 #include "dng_point.h" 00023 #include "dng_utils.h" 00024 00025 /*****************************************************************************/ 00026 00027 class dng_rect 00028 { 00029 00030 public: 00031 00032 int32 t; 00033 int32 l; 00034 int32 b; 00035 int32 r; 00036 00037 public: 00038 00039 dng_rect () 00040 : t (0) 00041 , l (0) 00042 , b (0) 00043 , r (0) 00044 { 00045 } 00046 00047 dng_rect (int32 tt, int32 ll, int32 bb, int32 rr) 00048 : t (tt) 00049 , l (ll) 00050 , b (bb) 00051 , r (rr) 00052 { 00053 } 00054 00055 dng_rect (uint32 h, uint32 w) 00056 : t (0) 00057 , l (0) 00058 , b (h) 00059 , r (w) 00060 { 00061 } 00062 00063 dng_rect (const dng_point &size) 00064 : t (0) 00065 , l (0) 00066 , b (size.v) 00067 , r (size.h) 00068 { 00069 } 00070 00071 void Clear () 00072 { 00073 *this = dng_rect (); 00074 } 00075 00076 bool operator== (const dng_rect &rect) const; 00077 00078 bool operator!= (const dng_rect &rect) const 00079 { 00080 return !(*this == rect); 00081 } 00082 00083 bool IsZero () const; 00084 00085 bool NotZero () const 00086 { 00087 return !IsZero (); 00088 } 00089 00090 bool IsEmpty () const 00091 { 00092 return (t >= b) || (l >= r); 00093 } 00094 00095 bool NotEmpty () const 00096 { 00097 return !IsEmpty (); 00098 } 00099 00100 uint32 W () const 00101 { 00102 return (r >= l ? (uint32) (r - l) : 0); 00103 } 00104 00105 uint32 H () const 00106 { 00107 return (b >= t ? (uint32) (b - t) : 0); 00108 } 00109 00110 dng_point TL () const 00111 { 00112 return dng_point (t, l); 00113 } 00114 00115 dng_point TR () const 00116 { 00117 return dng_point (t, r); 00118 } 00119 00120 dng_point BL () const 00121 { 00122 return dng_point (b, l); 00123 } 00124 00125 dng_point BR () const 00126 { 00127 return dng_point (b, r); 00128 } 00129 00130 dng_point Size () const 00131 { 00132 return dng_point (H (), W ()); 00133 } 00134 00135 real64 Diagonal () const 00136 { 00137 return hypot ((real64) W (), 00138 (real64) H ()); 00139 } 00140 00141 }; 00142 00143 /*****************************************************************************/ 00144 00145 class dng_rect_real64 00146 { 00147 00148 public: 00149 00150 real64 t; 00151 real64 l; 00152 real64 b; 00153 real64 r; 00154 00155 public: 00156 00157 dng_rect_real64 () 00158 : t (0.0) 00159 , l (0.0) 00160 , b (0.0) 00161 , r (0.0) 00162 { 00163 } 00164 00165 dng_rect_real64 (real64 tt, real64 ll, real64 bb, real64 rr) 00166 : t (tt) 00167 , l (ll) 00168 , b (bb) 00169 , r (rr) 00170 { 00171 } 00172 00173 dng_rect_real64 (real64 h, real64 w) 00174 : t (0) 00175 , l (0) 00176 , b (h) 00177 , r (w) 00178 { 00179 } 00180 00181 dng_rect_real64 (const dng_point_real64 &size) 00182 : t (0) 00183 , l (0) 00184 , b (size.v) 00185 , r (size.h) 00186 { 00187 } 00188 00189 dng_rect_real64 (const dng_rect &rect) 00190 : t ((real64) rect.t) 00191 , l ((real64) rect.l) 00192 , b ((real64) rect.b) 00193 , r ((real64) rect.r) 00194 { 00195 } 00196 00197 void Clear () 00198 { 00199 *this = dng_point_real64 (); 00200 } 00201 00202 bool operator== (const dng_rect_real64 &rect) const; 00203 00204 bool operator!= (const dng_rect_real64 &rect) const 00205 { 00206 return !(*this == rect); 00207 } 00208 00209 bool IsZero () const; 00210 00211 bool NotZero () const 00212 { 00213 return !IsZero (); 00214 } 00215 00216 bool IsEmpty () const 00217 { 00218 return (t >= b) || (l >= r); 00219 } 00220 00221 bool NotEmpty () const 00222 { 00223 return !IsEmpty (); 00224 } 00225 00226 real64 W () const 00227 { 00228 return Max_real64 (r - l, 0.0); 00229 } 00230 00231 real64 H () const 00232 { 00233 return Max_real64 (b - t, 0.0); 00234 } 00235 00236 dng_point_real64 TL () const 00237 { 00238 return dng_point_real64 (t, l); 00239 } 00240 00241 dng_point_real64 TR () const 00242 { 00243 return dng_point_real64 (t, r); 00244 } 00245 00246 dng_point_real64 BL () const 00247 { 00248 return dng_point_real64 (b, l); 00249 } 00250 00251 dng_point_real64 BR () const 00252 { 00253 return dng_point_real64 (b, r); 00254 } 00255 00256 dng_point_real64 Size () const 00257 { 00258 return dng_point_real64 (H (), W ()); 00259 } 00260 00261 dng_rect Round () const 00262 { 00263 return dng_rect (Round_int32 (t), 00264 Round_int32 (l), 00265 Round_int32 (b), 00266 Round_int32 (r)); 00267 } 00268 00269 real64 Diagonal () const 00270 { 00271 return hypot (W (), H ()); 00272 } 00273 00274 }; 00275 00276 /*****************************************************************************/ 00277 00278 dng_rect operator& (const dng_rect &a, 00279 const dng_rect &b); 00280 00281 dng_rect operator| (const dng_rect &a, 00282 const dng_rect &b); 00283 00284 /*****************************************************************************/ 00285 00286 dng_rect_real64 operator& (const dng_rect_real64 &a, 00287 const dng_rect_real64 &b); 00288 00289 dng_rect_real64 operator| (const dng_rect_real64 &a, 00290 const dng_rect_real64 &b); 00291 00292 /*****************************************************************************/ 00293 00294 inline dng_rect operator+ (const dng_rect &a, 00295 const dng_point &b) 00296 { 00297 00298 return dng_rect (a.t + b.v, 00299 a.l + b.h, 00300 a.b + b.v, 00301 a.r + b.h); 00302 00303 } 00304 00305 /*****************************************************************************/ 00306 00307 inline dng_rect_real64 operator+ (const dng_rect_real64 &a, 00308 const dng_point_real64 &b) 00309 { 00310 00311 return dng_rect_real64 (a.t + b.v, 00312 a.l + b.h, 00313 a.b + b.v, 00314 a.r + b.h); 00315 00316 } 00317 00318 /*****************************************************************************/ 00319 00320 inline dng_rect operator- (const dng_rect &a, 00321 const dng_point &b) 00322 { 00323 00324 return dng_rect (a.t - b.v, 00325 a.l - b.h, 00326 a.b - b.v, 00327 a.r - b.h); 00328 00329 } 00330 00331 /*****************************************************************************/ 00332 00333 inline dng_rect_real64 operator- (const dng_rect_real64 &a, 00334 const dng_point_real64 &b) 00335 { 00336 00337 return dng_rect_real64 (a.t - b.v, 00338 a.l - b.h, 00339 a.b - b.v, 00340 a.r - b.h); 00341 00342 } 00343 00344 /*****************************************************************************/ 00345 00346 inline dng_rect Transpose (const dng_rect &a) 00347 { 00348 00349 return dng_rect (a.l, a.t, a.r, a.b); 00350 00351 } 00352 00353 /*****************************************************************************/ 00354 00355 inline dng_rect_real64 Transpose (const dng_rect_real64 &a) 00356 { 00357 00358 return dng_rect_real64 (a.l, a.t, a.r, a.b); 00359 00360 } 00361 00362 /*****************************************************************************/ 00363 00364 inline void HalfRect (dng_rect &rect) 00365 { 00366 00367 rect.r = rect.l + (rect.W () >> 1); 00368 rect.b = rect.t + (rect.H () >> 1); 00369 00370 } 00371 00372 /*****************************************************************************/ 00373 00374 inline void DoubleRect (dng_rect &rect) 00375 { 00376 00377 rect.r = rect.l + (rect.W () << 1); 00378 rect.b = rect.t + (rect.H () << 1); 00379 00380 } 00381 00382 /*****************************************************************************/ 00383 00384 inline void InnerPadRect (dng_rect &rect, 00385 int32 pad) 00386 { 00387 00388 rect.l += pad; 00389 rect.r -= pad; 00390 rect.t += pad; 00391 rect.b -= pad; 00392 00393 } 00394 00395 /*****************************************************************************/ 00396 00397 inline void OuterPadRect (dng_rect &rect, 00398 int32 pad) 00399 { 00400 00401 InnerPadRect (rect, -pad); 00402 00403 } 00404 00405 /*****************************************************************************/ 00406 00407 inline void InnerPadRectH (dng_rect &rect, 00408 int32 pad) 00409 { 00410 00411 rect.l += pad; 00412 rect.r -= pad; 00413 00414 } 00415 00416 /*****************************************************************************/ 00417 00418 inline void InnerPadRectV (dng_rect &rect, 00419 int32 pad) 00420 { 00421 00422 rect.t += pad; 00423 rect.b -= pad; 00424 00425 } 00426 00427 /*****************************************************************************/ 00428 00429 inline dng_rect MakeHalfRect (const dng_rect &rect) 00430 { 00431 00432 dng_rect out = rect; 00433 00434 HalfRect (out); 00435 00436 return out; 00437 00438 } 00439 00440 /*****************************************************************************/ 00441 00442 inline dng_rect MakeDoubleRect (const dng_rect &rect) 00443 { 00444 00445 dng_rect out = rect; 00446 00447 DoubleRect (out); 00448 00449 return out; 00450 00451 } 00452 00453 /*****************************************************************************/ 00454 00455 inline dng_rect MakeInnerPadRect (const dng_rect &rect, 00456 int32 pad) 00457 { 00458 00459 dng_rect out = rect; 00460 00461 InnerPadRect (out, pad); 00462 00463 return out; 00464 00465 } 00466 00467 /*****************************************************************************/ 00468 00469 #endif 00470 00471 /*****************************************************************************/ |