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_image.h#1 $ */ 10 /* $DateTime: 2012/05/30 13:28:51 $ */ 11 /* $Change: 832332 $ */ 12 /* $Author: tknoll $ */ 13 14 /** \file 15 * Support for working with image data in DNG SDK. 16 */ 17 18 /*****************************************************************************/ 19 20 #ifndef __dng_image__ 21 #define __dng_image__ 22 23 /*****************************************************************************/ 24 25 #include "dng_assertions.h" 26 #include "dng_classes.h" 27 #include "dng_pixel_buffer.h" 28 #include "dng_point.h" 29 #include "dng_rect.h" 30 #include "dng_tag_types.h" 31 #include "dng_types.h" 32 33 /*****************************************************************************/ 34 35 /// \brief Class to get resource acquisition is instantiation behavior for tile 36 /// buffers. Can be dirty or constant tile access. 37 38 class dng_tile_buffer: public dng_pixel_buffer 39 { 40 41 protected: 42 43 const dng_image &fImage; 44 45 void *fRefData; 46 47 protected: 48 49 /// Obtain a tile from an image. 50 /// \param image Image tile will come from. 51 /// \param tile Rectangle denoting extent of tile. 52 /// \param dirty Flag indicating whether this is read-only or read-write acesss. 53 54 dng_tile_buffer (const dng_image &image, 55 const dng_rect &tile, 56 bool dirty); 57 58 virtual ~dng_tile_buffer (); 59 60 public: 61 SetRefData(void * refData)62 void SetRefData (void *refData) 63 { 64 fRefData = refData; 65 } 66 GetRefData()67 void * GetRefData () const 68 { 69 return fRefData; 70 } 71 72 private: 73 74 // Hidden copy constructor and assignment operator. 75 76 dng_tile_buffer (const dng_tile_buffer &buffer); 77 78 dng_tile_buffer & operator= (const dng_tile_buffer &buffer); 79 80 }; 81 82 /*****************************************************************************/ 83 84 /// \brief Class to get resource acquisition is instantiation behavior for 85 /// constant (read-only) tile buffers. 86 87 class dng_const_tile_buffer: public dng_tile_buffer 88 { 89 90 public: 91 92 /// Obtain a read-only tile from an image. 93 /// \param image Image tile will come from. 94 /// \param tile Rectangle denoting extent of tile. 95 96 dng_const_tile_buffer (const dng_image &image, 97 const dng_rect &tile); 98 99 virtual ~dng_const_tile_buffer (); 100 101 }; 102 103 /*****************************************************************************/ 104 105 /// \brief Class to get resource acquisition is instantiation behavior for 106 /// dirty (writable) tile buffers. 107 108 class dng_dirty_tile_buffer: public dng_tile_buffer 109 { 110 111 public: 112 113 /// Obtain a writable tile from an image. 114 /// \param image Image tile will come from. 115 /// \param tile Rectangle denoting extent of tile. 116 117 dng_dirty_tile_buffer (dng_image &image, 118 const dng_rect &tile); 119 120 virtual ~dng_dirty_tile_buffer (); 121 122 }; 123 124 /*****************************************************************************/ 125 126 /// \brief Base class for holding image data in DNG SDK. See dng_simple_image 127 /// for derived class most often used in DNG SDK. 128 129 class dng_image 130 { 131 132 friend class dng_tile_buffer; 133 134 protected: 135 136 // Bounds for this image. 137 138 dng_rect fBounds; 139 140 // Number of image planes. 141 142 uint32 fPlanes; 143 144 // Basic pixel type (TIFF tag type code). 145 146 uint32 fPixelType; 147 148 public: 149 150 /// How to handle requests to get image areas outside the image bounds. 151 152 enum edge_option 153 { 154 155 /// Leave edge pixels unchanged. 156 157 edge_none, 158 159 /// Pad with zeros. 160 161 edge_zero, 162 163 /// Repeat edge pixels. 164 165 edge_repeat, 166 167 /// Repeat edge pixels, except for last plane which is zero padded. 168 169 edge_repeat_zero_last 170 171 }; 172 173 protected: 174 175 dng_image (const dng_rect &bounds, 176 uint32 planes, 177 uint32 pixelType); 178 179 public: 180 181 virtual ~dng_image (); 182 183 virtual dng_image * Clone () const; 184 185 /// Getter method for bounds of an image. 186 Bounds()187 const dng_rect & Bounds () const 188 { 189 return fBounds; 190 } 191 192 /// Getter method for size of an image. 193 Size()194 dng_point Size () const 195 { 196 return Bounds ().Size (); 197 } 198 199 /// Getter method for width of an image. 200 Width()201 uint32 Width () const 202 { 203 return Bounds ().W (); 204 } 205 206 /// Getter method for height of an image. 207 Height()208 uint32 Height () const 209 { 210 return Bounds ().H (); 211 } 212 213 /// Getter method for number of planes in an image. 214 Planes()215 uint32 Planes () const 216 { 217 return fPlanes; 218 } 219 220 /// Getter for pixel type. 221 /// \retval See dng_tagtypes.h . Valid values are ttByte, ttShort, ttSShort, 222 /// ttLong, ttFloat . 223 PixelType()224 uint32 PixelType () const 225 { 226 return fPixelType; 227 } 228 229 /// Setter for pixel type. 230 /// \param pixelType The new pixel type . 231 232 virtual void SetPixelType (uint32 pixelType); 233 234 /// Getter for pixel size. 235 /// \retval Size, in bytes, of pixel type for this image . 236 237 uint32 PixelSize () const; 238 239 /// Getter for pixel range. 240 /// For unsigned types, range is 0 to return value. 241 /// For signed types, range is return value - 0x8000U. 242 /// For ttFloat type, pixel range is 0.0 to 1.0 and this routine returns 1. 243 244 uint32 PixelRange () const; 245 246 /// Getter for best "tile stride" for accessing image. 247 248 virtual dng_rect RepeatingTile () const; 249 250 /// Get a pixel buffer of data on image with proper edge padding. 251 /// \param buffer Receives resulting pixel buffer. 252 /// \param edgeOption edge_option describing how to pad edges. 253 /// \param repeatV Amount of repeated padding needed in vertical for 254 /// edge_repeat and edge_repeat_zero_last edgeOption cases. 255 /// \param repeatH Amount of repeated padding needed in horizontal for 256 /// edge_repeat and edge_repeat_zero_last edgeOption cases. 257 258 void Get (dng_pixel_buffer &buffer, 259 edge_option edgeOption = edge_none, 260 uint32 repeatV = 1, 261 uint32 repeatH = 1) const; 262 263 /// Put a pixel buffer into image. 264 /// \param buffer Pixel buffer to copy from. 265 266 void Put (const dng_pixel_buffer &buffer); 267 268 /// Shrink bounds of image to given rectangle. 269 /// \param r Rectangle to crop to. 270 271 virtual void Trim (const dng_rect &r); 272 273 /// Rotate image to reflect given orientation change. 274 /// \param orientation Directive to rotate image in a certain way. 275 276 virtual void Rotate (const dng_orientation &orientation); 277 278 /// Copy image data from an area of one image to same area of another. 279 /// \param src Image to copy from. 280 /// \param area Rectangle of images to copy. 281 /// \param srcPlane Plane to start copying in src. 282 /// \param dstPlane Plane to start copying in this. 283 /// \param planes Number of planes to copy. 284 285 void CopyArea (const dng_image &src, 286 const dng_rect &area, 287 uint32 srcPlane, 288 uint32 dstPlane, 289 uint32 planes); 290 291 /// Copy image data from an area of one image to same area of another. 292 /// \param src Image to copy from. 293 /// \param area Rectangle of images to copy. 294 /// \param plane Plane to start copying in src and this. 295 /// \param planes Number of planes to copy. 296 CopyArea(const dng_image & src,const dng_rect & area,uint32 plane,uint32 planes)297 void CopyArea (const dng_image &src, 298 const dng_rect &area, 299 uint32 plane, 300 uint32 planes) 301 { 302 303 CopyArea (src, area, plane, plane, planes); 304 305 } 306 307 /// Return true if the contents of an area of the image are the same as those of another. 308 /// \param rhs Image to compare against. 309 /// \param area Rectangle of image to test. 310 /// \param plane Plane to start comparing. 311 /// \param planes Number of planes to compare. 312 313 bool EqualArea (const dng_image &rhs, 314 const dng_rect &area, 315 uint32 plane, 316 uint32 planes) const; 317 318 // Routines to set the entire image to a constant value. 319 SetConstant_uint8(uint8 value,const dng_rect & area)320 void SetConstant_uint8 (uint8 value, 321 const dng_rect &area) 322 { 323 324 DNG_ASSERT (fPixelType == ttByte, "Mismatched pixel type"); 325 326 SetConstant ((uint32) value, area); 327 328 } 329 SetConstant_uint8(uint8 value)330 void SetConstant_uint8 (uint8 value) 331 { 332 SetConstant (value, Bounds ()); 333 } 334 SetConstant_uint16(uint16 value,const dng_rect & area)335 void SetConstant_uint16 (uint16 value, 336 const dng_rect &area) 337 { 338 339 DNG_ASSERT (fPixelType == ttShort, "Mismatched pixel type"); 340 341 SetConstant ((uint32) value, area); 342 343 } 344 SetConstant_uint16(uint16 value)345 void SetConstant_uint16 (uint16 value) 346 { 347 SetConstant_uint16 (value, Bounds ()); 348 } 349 SetConstant_int16(int16 value,const dng_rect & area)350 void SetConstant_int16 (int16 value, 351 const dng_rect &area) 352 { 353 354 DNG_ASSERT (fPixelType == ttSShort, "Mismatched pixel type"); 355 356 SetConstant ((uint32) (uint16) value, area); 357 358 } 359 SetConstant_int16(int16 value)360 void SetConstant_int16 (int16 value) 361 { 362 SetConstant_int16 (value, Bounds ()); 363 } 364 SetConstant_uint32(uint32 value,const dng_rect & area)365 void SetConstant_uint32 (uint32 value, 366 const dng_rect &area) 367 { 368 369 DNG_ASSERT (fPixelType == ttLong, "Mismatched pixel type"); 370 371 SetConstant (value, area); 372 373 } 374 SetConstant_uint32(uint32 value)375 void SetConstant_uint32 (uint32 value) 376 { 377 SetConstant_uint32 (value, Bounds ()); 378 } 379 SetConstant_real32(real32 value,const dng_rect & area)380 void SetConstant_real32 (real32 value, 381 const dng_rect &area) 382 { 383 384 DNG_ASSERT (fPixelType == ttFloat, "Mismatched pixel type"); 385 386 union 387 { 388 uint32 i; 389 real32 f; 390 } x; 391 392 x.f = value; 393 394 SetConstant (x.i, area); 395 396 } 397 SetConstant_real32(real32 value)398 void SetConstant_real32 (real32 value) 399 { 400 SetConstant_real32 (value, Bounds ()); 401 } 402 403 virtual void GetRepeat (dng_pixel_buffer &buffer, 404 const dng_rect &srcArea, 405 const dng_rect &dstArea) const; 406 407 protected: 408 409 virtual void AcquireTileBuffer (dng_tile_buffer &buffer, 410 const dng_rect &area, 411 bool dirty) const; 412 413 virtual void ReleaseTileBuffer (dng_tile_buffer &buffer) const; 414 415 virtual void DoGet (dng_pixel_buffer &buffer) const; 416 417 virtual void DoPut (const dng_pixel_buffer &buffer); 418 419 void GetEdge (dng_pixel_buffer &buffer, 420 edge_option edgeOption, 421 const dng_rect &srcArea, 422 const dng_rect &dstArea) const; 423 424 virtual void SetConstant (uint32 value, 425 const dng_rect &area); 426 427 }; 428 429 /*****************************************************************************/ 430 431 #endif 432 433 /*****************************************************************************/ 434