Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_opcodes.h

raw
1 /*****************************************************************************/
2 // Copyright 2008-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 /** \file
10 * Base class and common data structures for opcodes (introduced in DNG 1.3).
11 */
12
13 /*****************************************************************************/
14
15 #ifndef __dng_opcodes__
16 #define __dng_opcodes__
17
18 /*****************************************************************************/
19
20 #include "dng_auto_ptr.h"
21 #include "dng_classes.h"
22 #include "dng_rect.h"
23 #include "dng_types.h"
24
25 /*****************************************************************************/
26
27 /// @brief List of supported opcodes (by ID).
28
29 enum dng_opcode_id
30 {
31
32 // Internal use only opcode. Never written to DNGs.
33
34 dngOpcode_Private = 0,
35
36 // Warp image to correct distortion and lateral chromatic aberration for
37 // rectilinear lenses.
38
39 dngOpcode_WarpRectilinear = 1,
40
41 // Warp image to correction distortion for fisheye lenses (i.e., map the
42 // fisheye projection to a perspective projection).
43
44 dngOpcode_WarpFisheye = 2,
45
46 // Radial vignette correction.
47
48 dngOpcode_FixVignetteRadial = 3,
49
50 // Patch bad Bayer pixels which are marked with a special value in the image.
51
52 dngOpcode_FixBadPixelsConstant = 4,
53
54 // Patch bad Bayer pixels/rectangles at a list of specified coordinates.
55
56 dngOpcode_FixBadPixelsList = 5,
57
58 // Trim image to specified bounds.
59
60 dngOpcode_TrimBounds = 6,
61
62 // Map an area through a 16-bit LUT.
63
64 dngOpcode_MapTable = 7,
65
66 // Map an area using a polynomial function.
67
68 dngOpcode_MapPolynomial = 8,
69
70 // Apply a gain map to an area.
71
72 dngOpcode_GainMap = 9,
73
74 // Apply a per-row delta to an area.
75
76 dngOpcode_DeltaPerRow = 10,
77
78 // Apply a per-column delta to an area.
79
80 dngOpcode_DeltaPerColumn = 11,
81
82 // Apply a per-row scale to an area.
83
84 dngOpcode_ScalePerRow = 12,
85
86 // Apply a per-column scale to an area.
87
88 dngOpcode_ScalePerColumn = 13,
89
90 // Opcodes introduced in DNG 1.6.
91
92 // Warp image to correct distortion and lateral chromatic aberration for
93 // rectilinear lenses. Extension of WarpRectilinear.
94
95 dngOpcode_WarpRectilinear2 = 14,
96
97 };
98
99 /*****************************************************************************/
100
101 /// @brief Virtual base class for opcode.
102
103 class dng_opcode
104 {
105
106 public:
107
108 /// Opcode flags.
109
110 enum
111 {
112 kFlag_None = 0, //!< No flag.
113 kFlag_Optional = 1, //!< This opcode is optional.
114 kFlag_SkipIfPreview = 2 //!< May skip opcode for preview images.
115 };
116
117 private:
118
119 uint32 fOpcodeID;
120
121 uint32 fMinVersion;
122
123 uint32 fFlags;
124
125 bool fWasReadFromStream;
126
127 uint32 fStage;
128
129 protected:
130
131 dng_opcode (uint32 opcodeID,
132 uint32 minVersion,
133 uint32 flags);
134
135 dng_opcode (uint32 opcodeID,
136 dng_stream &stream,
137 const char *name);
138
139 // This helper routine will be called by AboutToApply if AboutToApply
140 // passes its internal checking and plans to return true. This is an
141 // opportunity for subclasses to perform some internal preparation
142 // based on the negative, image bounds, and number of image planes.
143
144 virtual void DoAboutToApply (dng_host & /* host */,
145 dng_negative & /* negative */,
146 const dng_rect & /* imageBounds */,
147 uint32 /* imagePlanes */)
148 {
149 }
150
151 public:
152
153 virtual ~dng_opcode ();
154
155 /// The ID of this opcode.
156
157 uint32 OpcodeID () const
158 {
159 return fOpcodeID;
160 }
161
162 /// The first DNG version that supports this opcode.
163
164 uint32 MinVersion () const
165 {
166 return fMinVersion;
167 }
168
169 /// The flags for this opcode.
170
171 uint32 Flags () const
172 {
173 return fFlags;
174 }
175
176 /// Is this opcode optional?
177
178 bool Optional () const
179 {
180 return (Flags () & kFlag_Optional) != 0;
181 }
182
183 /// Should the opcode be skipped when rendering preview images?
184
185 bool SkipIfPreview () const
186 {
187 return (Flags () & kFlag_SkipIfPreview) != 0;
188 }
189
190 /// Was this opcode read from a data stream?
191
192 bool WasReadFromStream () const
193 {
194 return fWasReadFromStream;
195 }
196
197 /// Which image processing stage (1, 2, 3) is associated with this
198 /// opcode?
199
200 uint32 Stage () const
201 {
202 return fStage;
203 }
204
205 /// Set the image processing stage (1, 2, 3) for this opcode. Stage 1 is
206 /// the original image data, including masked areas. Stage 2 is
207 /// linearized image data and trimmed to the active area. Stage 3 is
208 /// demosaiced and trimmed to the active area.
209
210 void SetStage (uint32 stage)
211 {
212 fStage = stage;
213 }
214
215 /// Is the opcode a NOP (i.e., does nothing)? An opcode could be a NOP
216 /// for some specific parameters.
217
218 virtual bool IsNOP () const
219 {
220 return false;
221 }
222
223 /// Is this opcode valid for the specified negative?
224
225 virtual bool IsValidForNegative (const dng_negative & /* negative */) const
226 {
227 return true;
228 }
229
230 /// Write opcode to a stream.
231 /// \param stream The stream to which to write the opcode data.
232
233 virtual void PutData (dng_stream &stream) const;
234
235 /// Perform error checking prior to applying this opcode to the
236 /// specified negative. Returns true if this opcode should be applied to
237 /// the negative, false otherwise.
238
239 bool AboutToApply (dng_host &host,
240 dng_negative &negative,
241 const dng_rect &imageBounds,
242 uint32 imagePlanes);
243
244 /// Apply this opcode to the specified image with associated negative.
245
246 virtual void Apply (dng_host &host,
247 dng_negative &negative,
248 AutoPtr<dng_image> &image) = 0;
249
250 /// Apply scale factor to account for a resized image. Example is
251 /// stage 3 image being scaled to 2x the linear dimension of the stage
252 /// 2 image. Opcodes that express their internal parameters using
253 /// normalized (relative) image coordinates do not need any changes.
254
255 virtual void ApplyAreaScale (const dng_urational & /* scale */)
256 {
257 }
258
259 };
260
261 /*****************************************************************************/
262
263 /// @brief Class to represent unknown opcodes (e.g, opcodes defined in future
264 /// DNG versions).
265
266 class dng_opcode_Unknown: public dng_opcode
267 {
268
269 private:
270
271 AutoPtr<dng_memory_block> fData;
272
273 public:
274
275 dng_opcode_Unknown (dng_host &host,
276 uint32 opcodeID,
277 dng_stream &stream);
278
279 virtual void PutData (dng_stream &stream) const;
280
281 virtual void Apply (dng_host &host,
282 dng_negative &negative,
283 AutoPtr<dng_image> &image);
284
285 };
286
287 /*****************************************************************************/
288
289 /// @brief Class to represent a filter opcode, such as a convolution.
290
291 class dng_filter_opcode: public dng_opcode
292 {
293
294 protected:
295
296 dng_filter_opcode (uint32 opcodeID,
297 uint32 minVersion,
298 uint32 flags);
299
300 dng_filter_opcode (uint32 opcodeID,
301 dng_stream &stream,
302 const char *name);
303
304 public:
305
306 /// The pixel data type of this opcode.
307
308 virtual uint32 BufferPixelType (uint32 imagePixelType)
309 {
310 return imagePixelType;
311 }
312
313 /// The adjusted bounds (processing area) of this opcode. It is limited to
314 /// the intersection of the specified image area and the GainMap area.
315
316 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds)
317 {
318 return imageBounds;
319 }
320
321 /// Returns the width and height (in pixels) of the repeating mosaic pattern.
322
323 virtual dng_point SrcRepeat ()
324 {
325 return dng_point (1, 1);
326 }
327
328 /// Returns the source pixel area needed to process a destination pixel area
329 /// that lies within the specified bounds.
330 /// \param dstArea The destination pixel area to be computed.
331 /// \param imageBounds The overall image area (dstArea will lie within these
332 /// bounds).
333 /// \retval The source pixel area needed to process the specified dstArea.
334
335 virtual dng_rect SrcArea (const dng_rect &dstArea,
336 const dng_rect &imageBounds)
337 {
338 (void) imageBounds;
339 return dstArea;
340 }
341
342 /// Given a destination tile size, calculate input tile size. Simlar to
343 /// SrcArea, and should seldom be overridden.
344 ///
345 /// \param dstTileSize The destination tile size that is targeted for output.
346 ///
347 /// \param imageBounds The image bounds (the destination tile will
348 /// always lie within these bounds).
349 ///
350 /// \retval The source tile size needed to compute a tile of the destination
351 /// size.
352
353 virtual dng_point SrcTileSize (const dng_point &dstTileSize,
354 const dng_rect &imageBounds)
355 {
356 return SrcArea (dng_rect (dstTileSize),
357 imageBounds).Size ();
358 }
359
360 /// Startup method called before any processing is performed on pixel areas.
361 /// It can be used to allocate (per-thread) memory and setup tasks.
362 ///
363 /// \param negative The negative object to be processed.
364 ///
365 /// \param threadCount Total number of threads that will be used for
366 /// processing. Less than or equal to MaxThreads.
367 ///
368 /// \param tileSize Size of source tiles which will be processed. (Not all
369 /// tiles will be this size due to edge conditions.)
370 ///
371 /// \param imageBounds Total size of image to be processed.
372 ///
373 /// \param imagePlanes Number of planes in the image. Less than or equal to
374 /// kMaxColorPlanes.
375 ///
376 /// \param bufferPixelType Pixel type of image buffer (see dng_tag_types.h).
377 ///
378 /// \param allocator dng_memory_allocator to use for allocating temporary
379 /// buffers, etc.
380
381 virtual void Prepare (dng_negative &negative,
382 uint32 threadCount,
383 const dng_point &tileSize,
384 const dng_rect &imageBounds,
385 uint32 imagePlanes,
386 uint32 bufferPixelType,
387 dng_memory_allocator &allocator)
388 {
389 (void) negative;
390 (void) threadCount;
391 (void) tileSize;
392 (void) imageBounds;
393 (void) imagePlanes;
394 (void) bufferPixelType;
395 (void) allocator;
396 }
397
398 /// Implements filtering operation from one buffer to another. Source
399 /// and destination pixels are set up in member fields of this class.
400 /// Ideally, no allocation should be done in this routine.
401 ///
402 /// \param negative The negative associated with the pixels to be
403 /// processed.
404 ///
405 /// \param threadIndex The thread on which this routine is being called,
406 /// between 0 and threadCount - 1 for the threadCount passed to Prepare
407 /// method.
408 ///
409 /// \param srcBuffer Input area and source pixels.
410 ///
411 /// \param dstBuffer Destination pixels.
412 ///
413 /// \param dstArea Destination pixel processing area.
414 ///
415 /// \param imageBounds Total image area to be processed; dstArea will
416 /// always lie within these bounds.
417
418 virtual void ProcessArea (dng_negative &negative,
419 uint32 threadIndex,
420 dng_pixel_buffer &srcBuffer,
421 dng_pixel_buffer &dstBuffer,
422 const dng_rect &dstArea,
423 const dng_rect &imageBounds) = 0;
424
425 virtual void Apply (dng_host &host,
426 dng_negative &negative,
427 AutoPtr<dng_image> &image);
428
429 };
430
431 /*****************************************************************************/
432
433 /// @brief Class to represent an in-place (i.e., pointwise, per-pixel) opcode,
434 /// such as a global tone curve.
435
436 class dng_inplace_opcode: public dng_opcode
437 {
438
439 protected:
440
441 dng_inplace_opcode (uint32 opcodeID,
442 uint32 minVersion,
443 uint32 flags);
444
445 dng_inplace_opcode (uint32 opcodeID,
446 dng_stream &stream,
447 const char *name);
448
449 public:
450
451 /// The pixel data type of this opcode.
452
453 virtual uint32 BufferPixelType (uint32 imagePixelType)
454 {
455 return imagePixelType;
456 }
457
458 /// The adjusted bounds (processing area) of this opcode. It is limited to
459 /// the intersection of the specified image area and the GainMap area.
460
461 virtual dng_rect ModifiedBounds (const dng_rect &imageBounds)
462 {
463 return imageBounds;
464 }
465
466 /// Startup method called before any processing is performed on pixel areas.
467 /// It can be used to allocate (per-thread) memory and setup tasks.
468 ///
469 /// \param negative The negative object to be processed.
470 ///
471 /// \param threadCount Total number of threads that will be used for
472 /// processing. Less than or equal to MaxThreads.
473 ///
474 /// \param tileSize Size of source tiles which will be processed. (Not all
475 /// tiles will be this size due to edge conditions.)
476 ///
477 /// \param imageBounds Total size of image to be processed.
478 ///
479 /// \param imagePlanes Number of planes in the image. Less than or equal to
480 /// kMaxColorPlanes.
481 ///
482 /// \param bufferPixelType Pixel type of image buffer (see dng_tag_types.h).
483 ///
484 /// \param allocator dng_memory_allocator to use for allocating temporary
485 /// buffers, etc.
486
487 virtual void Prepare (dng_negative &negative,
488 uint32 threadCount,
489 const dng_point &tileSize,
490 const dng_rect &imageBounds,
491 uint32 imagePlanes,
492 uint32 bufferPixelType,
493 dng_memory_allocator &allocator)
494 {
495 (void) negative;
496 (void) threadCount;
497 (void) tileSize;
498 (void) imageBounds;
499 (void) imagePlanes;
500 (void) bufferPixelType;
501 (void) allocator;
502 }
503
504 /// Implements image processing operation in a single buffer. The source
505 /// pixels are provided as input to the buffer, and this routine
506 /// calculates and writes the destination pixels to the same buffer.
507 /// Ideally, no allocation should be done in this routine.
508 ///
509 /// \param negative The negative associated with the pixels to be
510 /// processed.
511 ///
512 /// \param threadIndex The thread on which this routine is being called,
513 /// between 0 and threadCount - 1 for the threadCount passed to Prepare
514 /// method.
515 ///
516 /// \param buffer Source and Destination pixels.
517 ///
518 /// \param dstArea Destination pixel processing area.
519 ///
520 /// \param imageBounds Total image area to be processed; dstArea will
521 /// always lie within these bounds.
522
523 virtual void ProcessArea (dng_negative &negative,
524 uint32 threadIndex,
525 dng_pixel_buffer &buffer,
526 const dng_rect &dstArea,
527 const dng_rect &imageBounds) = 0;
528
529 virtual void Apply (dng_host &host,
530 dng_negative &negative,
531 AutoPtr<dng_image> &image);
532
533 };
534
535 /*****************************************************************************/
536
537 #endif
538
539 /*****************************************************************************/