1 /*****************************************************************************/ 2 // Copyright 2008-2009 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_misc_opcodes.h#2 $ */ 10 /* $DateTime: 2012/08/02 06:09:06 $ */ 11 /* $Change: 841096 $ */ 12 /* $Author: erichan $ */ 13 14 /** \file 15 * Miscellaneous DNG opcodes. 16 */ 17 18 /*****************************************************************************/ 19 20 #ifndef __dng_misc_opcodes__ 21 #define __dng_misc_opcodes__ 22 23 /*****************************************************************************/ 24 25 #include "dng_opcodes.h" 26 27 /*****************************************************************************/ 28 29 /// \brief Opcode to trim image to a specified rectangle. 30 31 class dng_opcode_TrimBounds: public dng_opcode 32 { 33 34 private: 35 36 dng_rect fBounds; 37 38 public: 39 40 /// Create opcode to trim image to the specified bounds. 41 42 dng_opcode_TrimBounds (const dng_rect &bounds); 43 44 dng_opcode_TrimBounds (dng_stream &stream); 45 46 virtual void PutData (dng_stream &stream) const; 47 48 virtual void Apply (dng_host &host, 49 dng_negative &negative, 50 AutoPtr<dng_image> &image); 51 52 }; 53 54 /*****************************************************************************/ 55 56 /// \brief A class to describe an area of an image, including a pixel subrectangle, 57 /// plane range, and row/column pitch (e.g., for mosaic images). Useful for 58 /// specifying opcodes that only apply to specific color planes or pixel types (e.g., 59 /// only one of the two green Bayer pixels). 60 61 class dng_area_spec 62 { 63 64 public: 65 66 enum 67 { 68 kDataSize = 32 69 }; 70 71 private: 72 73 dng_rect fArea; 74 75 uint32 fPlane; 76 uint32 fPlanes; 77 78 uint32 fRowPitch; 79 uint32 fColPitch; 80 81 public: 82 83 /// Create an empty area. 84 85 dng_area_spec (const dng_rect &area = dng_rect (), 86 uint32 plane = 0, 87 uint32 planes = 1, 88 uint32 rowPitch = 1, 89 uint32 colPitch = 1) 90 91 : fArea (area) 92 , fPlane (plane) 93 , fPlanes (planes) 94 , fRowPitch (rowPitch) 95 , fColPitch (colPitch) 96 97 { 98 } 99 100 /// The pixel area. 101 102 const dng_rect & Area () const 103 { 104 return fArea; 105 } 106 107 /// The first plane. 108 109 const uint32 Plane () const 110 { 111 return fPlane; 112 } 113 114 /// The total number of planes. 115 116 const uint32 Planes () const 117 { 118 return fPlanes; 119 } 120 121 /// The row pitch (i.e., stride). A pitch of 1 means all rows. 122 123 const uint32 RowPitch () const 124 { 125 return fRowPitch; 126 } 127 128 /// The column pitch (i.e., stride). A pitch of 1 means all columns. 129 130 const uint32 ColPitch () const 131 { 132 return fColPitch; 133 } 134 135 /// Read area data from the specified stream. 136 137 void GetData (dng_stream &stream); 138 139 /// Write area data to the specified stream. 140 141 void PutData (dng_stream &stream) const; 142 143 /// Compute and return pixel area overlap (i.e., intersection) between this 144 /// area and the specified tile. 145 146 dng_rect Overlap (const dng_rect &tile) const; 147 148 }; 149 150 /*****************************************************************************/ 151 152 /// \brief An opcode to apply a 1D function (represented as a 16-bit table) to an 153 /// image area. 154 155 class dng_opcode_MapTable: public dng_inplace_opcode 156 { 157 158 private: 159 160 dng_area_spec fAreaSpec; 161 162 AutoPtr<dng_memory_block> fTable; 163 164 uint32 fCount; 165 166 public: 167 168 /// Create a MapTable opcode with the specified area, table, and number of 169 /// table entries. 170 171 dng_opcode_MapTable (dng_host &host, 172 const dng_area_spec &areaSpec, 173 const uint16 *table, 174 uint32 count = 0x10000); 175 176 dng_opcode_MapTable (dng_host &host, 177 dng_stream &stream); 178 179 virtual void PutData (dng_stream &stream) const; 180 181 virtual uint32 BufferPixelType (uint32 imagePixelType); 182 183 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds); 184 185 virtual void ProcessArea (dng_negative &negative, 186 uint32 threadIndex, 187 dng_pixel_buffer &buffer, 188 const dng_rect &dstArea, 189 const dng_rect &imageBounds); 190 191 private: 192 193 void ReplicateLastEntry (); 194 195 }; 196 197 /*****************************************************************************/ 198 199 /// \brief An opcode to apply a 1D function (represented as a polynomial) to an 200 /// image area. 201 202 class dng_opcode_MapPolynomial: public dng_inplace_opcode 203 { 204 205 public: 206 207 enum 208 { 209 kMaxDegree = 8 210 }; 211 212 private: 213 214 dng_area_spec fAreaSpec; 215 216 uint32 fDegree; 217 218 real64 fCoefficient [kMaxDegree + 1]; 219 220 real32 fCoefficient32 [kMaxDegree + 1]; 221 222 public: 223 224 /// Create a MapPolynomial opcode with the specified area, polynomial 225 /// degree, and polynomial coefficients. The function that will be 226 /// applied to each pixel x is: 227 /// 228 /// f (x) = coefficient [0] + ((x * coefficient [1]) + 229 /// (x^2 * coefficient [2]) + 230 /// (x^3 * coefficient [3]) + 231 /// (x^4 * coefficient [4]) ... 232 233 dng_opcode_MapPolynomial (const dng_area_spec &areaSpec, 234 uint32 degree, 235 const real64 *coefficient); 236 237 dng_opcode_MapPolynomial (dng_stream &stream); 238 239 virtual void PutData (dng_stream &stream) const; 240 241 virtual uint32 BufferPixelType (uint32 imagePixelType); 242 243 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds); 244 245 virtual void ProcessArea (dng_negative &negative, 246 uint32 threadIndex, 247 dng_pixel_buffer &buffer, 248 const dng_rect &dstArea, 249 const dng_rect &imageBounds); 250 251 }; 252 253 /*****************************************************************************/ 254 255 /// \brief An opcode to apply a delta (i.e., offset) that varies per row. Within 256 /// a row, the same delta value is applied to all specified pixels. 257 258 class dng_opcode_DeltaPerRow: public dng_inplace_opcode 259 { 260 261 private: 262 263 dng_area_spec fAreaSpec; 264 265 AutoPtr<dng_memory_block> fTable; 266 267 real32 fScale; 268 269 public: 270 271 /// Create a DeltaPerRow opcode with the specified area and row deltas 272 /// (specified as a table of 32-bit floats). 273 274 dng_opcode_DeltaPerRow (const dng_area_spec &areaSpec, 275 AutoPtr<dng_memory_block> &table); 276 277 dng_opcode_DeltaPerRow (dng_host &host, 278 dng_stream &stream); 279 280 virtual void PutData (dng_stream &stream) const; 281 282 virtual uint32 BufferPixelType (uint32 imagePixelType); 283 284 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds); 285 286 virtual void ProcessArea (dng_negative &negative, 287 uint32 threadIndex, 288 dng_pixel_buffer &buffer, 289 const dng_rect &dstArea, 290 const dng_rect &imageBounds); 291 292 }; 293 294 /*****************************************************************************/ 295 296 /// \brief An opcode to apply a delta (i.e., offset) that varies per column. 297 /// Within a column, the same delta value is applied to all specified pixels. 298 299 class dng_opcode_DeltaPerColumn: public dng_inplace_opcode 300 { 301 302 private: 303 304 dng_area_spec fAreaSpec; 305 306 AutoPtr<dng_memory_block> fTable; 307 308 real32 fScale; 309 310 public: 311 312 /// Create a DeltaPerColumn opcode with the specified area and column 313 /// deltas (specified as a table of 32-bit floats). 314 315 dng_opcode_DeltaPerColumn (const dng_area_spec &areaSpec, 316 AutoPtr<dng_memory_block> &table); 317 318 dng_opcode_DeltaPerColumn (dng_host &host, 319 dng_stream &stream); 320 321 virtual void PutData (dng_stream &stream) const; 322 323 virtual uint32 BufferPixelType (uint32 imagePixelType); 324 325 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds); 326 327 virtual void ProcessArea (dng_negative &negative, 328 uint32 threadIndex, 329 dng_pixel_buffer &buffer, 330 const dng_rect &dstArea, 331 const dng_rect &imageBounds); 332 333 }; 334 335 /*****************************************************************************/ 336 337 /// \brief An opcode to apply a scale factor that varies per row. Within a row, 338 /// the same scale factor is applied to all specified pixels. 339 340 class dng_opcode_ScalePerRow: public dng_inplace_opcode 341 { 342 343 private: 344 345 dng_area_spec fAreaSpec; 346 347 AutoPtr<dng_memory_block> fTable; 348 349 public: 350 351 /// Create a ScalePerRow opcode with the specified area and row scale 352 /// factors (specified as a table of 32-bit floats). 353 354 dng_opcode_ScalePerRow (const dng_area_spec &areaSpec, 355 AutoPtr<dng_memory_block> &table); 356 357 dng_opcode_ScalePerRow (dng_host &host, 358 dng_stream &stream); 359 360 virtual void PutData (dng_stream &stream) const; 361 362 virtual uint32 BufferPixelType (uint32 imagePixelType); 363 364 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds); 365 366 virtual void ProcessArea (dng_negative &negative, 367 uint32 threadIndex, 368 dng_pixel_buffer &buffer, 369 const dng_rect &dstArea, 370 const dng_rect &imageBounds); 371 372 }; 373 374 /*****************************************************************************/ 375 376 /// \brief An opcode to apply a scale factor that varies per column. Within a 377 /// column, the same scale factor is applied to all specified pixels. 378 379 class dng_opcode_ScalePerColumn: public dng_inplace_opcode 380 { 381 382 private: 383 384 dng_area_spec fAreaSpec; 385 386 AutoPtr<dng_memory_block> fTable; 387 388 public: 389 390 /// Create a ScalePerColumn opcode with the specified area and column 391 /// scale factors (specified as a table of 32-bit floats). 392 393 dng_opcode_ScalePerColumn (const dng_area_spec &areaSpec, 394 AutoPtr<dng_memory_block> &table); 395 396 dng_opcode_ScalePerColumn (dng_host &host, 397 dng_stream &stream); 398 399 virtual void PutData (dng_stream &stream) const; 400 401 virtual uint32 BufferPixelType (uint32 imagePixelType); 402 403 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds); 404 405 virtual void ProcessArea (dng_negative &negative, 406 uint32 threadIndex, 407 dng_pixel_buffer &buffer, 408 const dng_rect &dstArea, 409 const dng_rect &imageBounds); 410 411 }; 412 413 /*****************************************************************************/ 414 415 #endif 416 417 /*****************************************************************************/ 418