Debian Codegraph @

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