Debian Codegraph @

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

raw
1 /*****************************************************************************/
2 // Copyright 2006-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 * Support for holding buffers of sample data.
11 */
12
13 /*****************************************************************************/
14
15 #ifndef __dng_pixel_buffer__
16 #define __dng_pixel_buffer__
17
18 /*****************************************************************************/
19
20 #include "dng_assertions.h"
21 #include "dng_rect.h"
22 #include "dng_safe_arithmetic.h"
23 #include "dng_tag_types.h"
24
25 /*****************************************************************************/
26
27 /// Compute best set of step values for a given source and destination area and stride.
28
29 void OptimizeOrder (const void *&sPtr,
30 void *&dPtr,
31 uint32 sPixelSize,
32 uint32 dPixelSize,
33 uint32 &count0,
34 uint32 &count1,
35 uint32 &count2,
36 int32 &sStep0,
37 int32 &sStep1,
38 int32 &sStep2,
39 int32 &dStep0,
40 int32 &dStep1,
41 int32 &dStep2);
42
43 void OptimizeOrder (const void *&sPtr,
44 uint32 sPixelSize,
45 uint32 &count0,
46 uint32 &count1,
47 uint32 &count2,
48 int32 &sStep0,
49 int32 &sStep1,
50 int32 &sStep2);
51
52 void OptimizeOrder (void *&dPtr,
53 uint32 dPixelSize,
54 uint32 &count0,
55 uint32 &count1,
56 uint32 &count2,
57 int32 &dStep0,
58 int32 &dStep1,
59 int32 &dStep2);
60
61 /*****************************************************************************/
62
63 #define qDebugPixelType 0
64
65 #if qDebugPixelType
66
67 #define ASSERT_PIXEL_TYPE(typeVal) CheckPixelType (typeVal)
68
69 #else
70
71 #define ASSERT_PIXEL_TYPE(typeVal) DNG_ASSERT (fPixelType == typeVal, "Pixel type access mismatch")
72
73 #endif
74
75 /*****************************************************************************/
76
77 /// @brief Holds a buffer of pixel data with "pixel geometry" metadata.
78 ///
79 /// The pixel geometry describes the layout in terms of how many planes, rows and columns
80 /// plus the steps (in bytes) between each column, row and plane.
81
82 class dng_pixel_buffer
83 {
84
85 public:
86
87 // Area this buffer holds.
88
89 dng_rect fArea;
90
91 // Range of planes this buffer holds.
92
93 uint32 fPlane;
94 uint32 fPlanes;
95
96 // Steps between pixels.
97
98 int32 fRowStep;
99 int32 fColStep;
100 int32 fPlaneStep;
101
102 // Basic pixel type (TIFF tag type code).
103
104 uint32 fPixelType;
105
106 // Size of pixel type in bytes.
107
108 uint32 fPixelSize;
109
110 // Pointer to buffer's data.
111
112 void *fData;
113
114 // Do we have write-access to this data?
115
116 bool fDirty;
117
118 private:
119
120 void * InternalPixel (int32 row,
121 int32 col,
122 uint32 plane = 0) const
123 {
124
125 // TO DO: review this. do we set up buffers sometimes with "col" parameter
126 // equal to 0, which would then cause this exception to throw?!
127
128 #if 0
129
130 // Ensure pixel to be accessed lies inside valid area.
131 if (row < fArea.t || row >= fArea.b ||
132 col < fArea.l || col >= fArea.r ||
133 plane < fPlane || (plane - fPlane) >= fPlanes)
134 {
135 ThrowProgramError ("Out-of-range pixel access");
136 }
137
138 // Compute offset of pixel.
139 const int64 rowOffset = SafeInt64Mult(fRowStep,
140 static_cast<int64> (row) - static_cast<int64> (fArea.t));
141 const int64 colOffset = SafeInt64Mult(fColStep,
142 static_cast<int64> (col) - static_cast<int64> (fArea.l));
143 const int64 planeOffset = SafeInt64Mult(fPlaneStep,
144 static_cast<int64> (plane - fPlane));
145 const int64 offset = SafeInt64Mult(static_cast<int64>(fPixelSize),
146 SafeInt64Add(SafeInt64Add(rowOffset, colOffset), planeOffset));
147
148 // Add offset to buffer base address.
149 return static_cast<void *> (static_cast<uint8 *> (fData) + offset);
150
151 #else
152
153 #if qDNG64Bit
154
155 return (void *)
156 (((uint8 *) fData) + (int64) fPixelSize *
157 (fRowStep * (int64) (row - fArea.t) +
158 fColStep * (int64) (col - fArea.l) +
159 fPlaneStep * (int64) (plane - fPlane )));
160
161 #else
162
163 return (void *)
164 (((uint8 *) fData) + (int32) fPixelSize *
165 (fRowStep * (int32) (row - fArea.t) +
166 fColStep * (int32) (col - fArea.l) +
167 fPlaneStep * (int32) (plane - fPlane )));
168
169 #endif
170
171 #endif
172
173 }
174
175 #if qDebugPixelType
176
177 void CheckPixelType (uint32 pixelType) const;
178
179 #endif
180
181 public:
182
183 dng_pixel_buffer ();
184
185 /// Note: This constructor is for internal use only and should not be
186 /// considered part of the DNG SDK API.
187 ///
188 /// Initialize the pixel buffer according to the given parameters (see
189 /// below). May throw an error if arithmetic overflow occurs when
190 /// computing the row, column or plane step, or if an invalid value
191 /// was passed for planarConfiguration.
192 ///
193 /// \param area Area covered by the pixel buffer
194 /// \param plane Index of the first plane
195 /// \param planes Number of planes
196 /// \param pixelType Pixel data type (one of the values defined in
197 /// dng_tag_types.h)
198 /// \param planarConfiguration Layout of the pixel planes in memory: One
199 /// of pcInterleaved, pcPlanar, or pcRowInterleaved (defined in
200 /// dng_tag_values.h)
201 /// \param data Pointer to the pixel data
202
203 dng_pixel_buffer (const dng_rect &area,
204 uint32 plane,
205 uint32 planes,
206 uint32 pixelType,
207 uint32 planarConfiguration,
208 void *data);
209
210 dng_pixel_buffer (const dng_pixel_buffer &buffer);
211
212 dng_pixel_buffer & operator= (const dng_pixel_buffer &buffer);
213
214 virtual ~dng_pixel_buffer ();
215
216 /// Get the range of pixel values.
217 /// \retval Range of value a pixel can take. (Meaning [0, max] for unsigned case. Signed case is biased so [-32768, max - 32768].)
218
219 uint32 PixelRange () const;
220
221 /// Get extent of pixels in buffer
222 /// \retval Rectangle giving valid extent of buffer.
223
224 const dng_rect & Area () const
225 {
226 return fArea;
227 }
228
229 /// Number of planes of image data.
230 /// \retval Number of planes held in buffer.
231
232 uint32 Planes () const
233 {
234 return fPlanes;
235 }
236
237 /// Step, in pixels not bytes, between rows of data in buffer.
238 /// \retval row step in pixels. May be negative.
239
240 int32 RowStep () const
241 {
242 return fRowStep;
243 }
244
245 /// Step, in pixels not bytes, between planes of data in buffer.
246 /// \retval plane step in pixels. May be negative.
247
248 int32 PlaneStep () const
249 {
250 return fPlaneStep;
251 }
252
253 /// Get read-only untyped (void *) pointer to pixel data starting at a specific pixel in the buffer.
254 /// \param row Start row for buffer pointer.
255 /// \param col Start column for buffer pointer.
256 /// \param plane Start plane for buffer pointer.
257 /// \retval Pointer to pixel data as void *.
258
259 const void * ConstPixel (int32 row,
260 int32 col,
261 uint32 plane = 0) const
262 {
263
264 return InternalPixel (row, col, plane);
265
266 }
267
268 /// Get a writable untyped (void *) pointer to pixel data starting at a specific pixel in the buffer.
269 /// \param row Start row for buffer pointer.
270 /// \param col Start column for buffer pointer.
271 /// \param plane Start plane for buffer pointer.
272 /// \retval Pointer to pixel data as void *.
273
274 void * DirtyPixel (int32 row,
275 int32 col,
276 uint32 plane = 0)
277 {
278
279 DNG_ASSERT (fDirty, "Dirty access to const pixel buffer");
280
281 return InternalPixel (row, col, plane);
282
283 }
284
285 /// Get read-only uint8 * to pixel data starting at a specific pixel in the buffer.
286 /// \param row Start row for buffer pointer.
287 /// \param col Start column for buffer pointer.
288 /// \param plane Start plane for buffer pointer.
289 /// \retval Pointer to pixel data as uint8 *.
290
291 const uint8 * ConstPixel_uint8 (int32 row,
292 int32 col,
293 uint32 plane = 0) const
294 {
295
296 ASSERT_PIXEL_TYPE (ttByte);
297
298 return (const uint8 *) ConstPixel (row, col, plane);
299
300 }
301
302 const uint8 * ConstPixel_uint8_overrideType (int32 row,
303 int32 col,
304 uint32 plane = 0) const
305 {
306
307 // No type check
308
309 return (const uint8 *) ConstPixel (row, col, plane);
310
311 }
312
313 /// Get a writable uint8 * to pixel data starting at a specific pixel in the buffer.
314 /// \param row Start row for buffer pointer.
315 /// \param col Start column for buffer pointer.
316 /// \param plane Start plane for buffer pointer.
317 /// \retval Pointer to pixel data as uint8 *.
318
319 uint8 * DirtyPixel_uint8 (int32 row,
320 int32 col,
321 uint32 plane = 0)
322 {
323
324 ASSERT_PIXEL_TYPE (ttByte);
325
326 return (uint8 *) DirtyPixel (row, col, plane);
327
328 }
329
330 uint8 * DirtyPixel_uint8_overrideType (int32 row,
331 int32 col,
332 uint32 plane = 0)
333 {
334
335 // No type check
336
337 return (uint8 *) DirtyPixel (row, col, plane);
338
339 }
340
341 /// Get read-only int8 * to pixel data starting at a specific pixel in the buffer.
342 /// \param row Start row for buffer pointer.
343 /// \param col Start column for buffer pointer.
344 /// \param plane Start plane for buffer pointer.
345 /// \retval Pointer to pixel data as int8 *.
346
347 const int8 * ConstPixel_int8 (int32 row,
348 int32 col,
349 uint32 plane = 0) const
350 {
351
352 ASSERT_PIXEL_TYPE (ttSByte);
353
354 return (const int8 *) ConstPixel (row, col, plane);
355
356 }
357
358 /// Get a writable int8 * to pixel data starting at a specific pixel in the buffer.
359 /// \param row Start row for buffer pointer.
360 /// \param col Start column for buffer pointer.
361 /// \param plane Start plane for buffer pointer.
362 /// \retval Pointer to pixel data as int8 *.
363
364 int8 * DirtyPixel_int8 (int32 row,
365 int32 col,
366 uint32 plane = 0)
367 {
368
369 ASSERT_PIXEL_TYPE (ttSByte);
370
371 return (int8 *) DirtyPixel (row, col, plane);
372
373 }
374
375 /// Get read-only uint16 * to pixel data starting at a specific pixel in the buffer.
376 /// \param row Start row for buffer pointer.
377 /// \param col Start column for buffer pointer.
378 /// \param plane Start plane for buffer pointer.
379 /// \retval Pointer to pixel data as uint16 *.
380
381 const uint16 * ConstPixel_uint16 (int32 row,
382 int32 col,
383 uint32 plane = 0) const
384 {
385
386 ASSERT_PIXEL_TYPE (ttShort);
387
388 return (const uint16 *) ConstPixel (row, col, plane);
389
390 }
391
392 /// Get a writable uint16 * to pixel data starting at a specific pixel in the buffer.
393 /// \param row Start row for buffer pointer.
394 /// \param col Start column for buffer pointer.
395 /// \param plane Start plane for buffer pointer.
396 /// \retval Pointer to pixel data as uint16 *.
397
398 uint16 * DirtyPixel_uint16 (int32 row,
399 int32 col,
400 uint32 plane = 0)
401 {
402
403 ASSERT_PIXEL_TYPE (ttShort);
404
405 return (uint16 *) DirtyPixel (row, col, plane);
406
407 }
408
409 /// Get read-only int16 * to pixel data starting at a specific pixel in the buffer.
410 /// \param row Start row for buffer pointer.
411 /// \param col Start column for buffer pointer.
412 /// \param plane Start plane for buffer pointer.
413 /// \retval Pointer to pixel data as int16 *.
414
415 const int16 * ConstPixel_int16 (int32 row,
416 int32 col,
417 uint32 plane = 0) const
418 {
419
420 ASSERT_PIXEL_TYPE (ttSShort);
421
422 return (const int16 *) ConstPixel (row, col, plane);
423
424 }
425
426 /// Get a writable int16 * to pixel data starting at a specific pixel in the buffer.
427 /// \param row Start row for buffer pointer.
428 /// \param col Start column for buffer pointer.
429 /// \param plane Start plane for buffer pointer.
430 /// \retval Pointer to pixel data as int16 *.
431
432 int16 * DirtyPixel_int16 (int32 row,
433 int32 col,
434 uint32 plane = 0)
435 {
436
437 ASSERT_PIXEL_TYPE (ttSShort);
438
439 return (int16 *) DirtyPixel (row, col, plane);
440
441 }
442
443 /// Get read-only uint32 * to pixel data starting at a specific pixel in the buffer.
444 /// \param row Start row for buffer pointer.
445 /// \param col Start column for buffer pointer.
446 /// \param plane Start plane for buffer pointer.
447 /// \retval Pointer to pixel data as uint32 *.
448
449 const uint32 * ConstPixel_uint32 (int32 row,
450 int32 col,
451 uint32 plane = 0) const
452 {
453
454 ASSERT_PIXEL_TYPE (ttLong);
455
456 return (const uint32 *) ConstPixel (row, col, plane);
457
458 }
459
460 /// Get a writable uint32 * to pixel data starting at a specific pixel in the buffer.
461 /// \param row Start row for buffer pointer.
462 /// \param col Start column for buffer pointer.
463 /// \param plane Start plane for buffer pointer.
464 /// \retval Pointer to pixel data as uint32 *.
465
466 uint32 * DirtyPixel_uint32 (int32 row,
467 int32 col,
468 uint32 plane = 0)
469 {
470
471 ASSERT_PIXEL_TYPE (ttLong);
472
473 return (uint32 *) DirtyPixel (row, col, plane);
474
475 }
476
477 /// Get read-only int32 * to pixel data starting at a specific pixel in the buffer.
478 /// \param row Start row for buffer pointer.
479 /// \param col Start column for buffer pointer.
480 /// \param plane Start plane for buffer pointer.
481 /// \retval Pointer to pixel data as int32 *.
482
483 const int32 * ConstPixel_int32 (int32 row,
484 int32 col,
485 uint32 plane = 0) const
486 {
487
488 ASSERT_PIXEL_TYPE (ttSLong);
489
490 return (const int32 *) ConstPixel (row, col, plane);
491
492 }
493
494 /// Get a writable int32 * to pixel data starting at a specific pixel in the buffer.
495 /// \param row Start row for buffer pointer.
496 /// \param col Start column for buffer pointer.
497 /// \param plane Start plane for buffer pointer.
498 /// \retval Pointer to pixel data as int32 *.
499
500 int32 * DirtyPixel_int32 (int32 row,
501 int32 col,
502 uint32 plane = 0)
503 {
504
505 ASSERT_PIXEL_TYPE (ttSLong);
506
507 return (int32 *) DirtyPixel (row, col, plane);
508
509 }
510
511 /// Get read-only uint64 * to pixel data starting at a specific pixel in the buffer.
512 /// \param row Start row for buffer pointer.
513 /// \param col Start column for buffer pointer.
514 /// \param plane Start plane for buffer pointer.
515 /// \retval Pointer to pixel data as uint64 *.
516
517 const uint64 * ConstPixel_uint64 (int32 row,
518 int32 col,
519 uint32 plane = 0) const
520 {
521
522 ASSERT_PIXEL_TYPE (ttLong8);
523
524 return (const uint64 *) ConstPixel (row, col, plane);
525
526 }
527
528 /// Get a writable uint64 * to pixel data starting at a specific pixel in the buffer.
529 /// \param row Start row for buffer pointer.
530 /// \param col Start column for buffer pointer.
531 /// \param plane Start plane for buffer pointer.
532 /// \retval Pointer to pixel data as uint64 *.
533
534 uint64 * DirtyPixel_uint64 (int32 row,
535 int32 col,
536 uint32 plane = 0)
537 {
538
539 ASSERT_PIXEL_TYPE (ttLong8);
540
541 return (uint64 *) DirtyPixel (row, col, plane);
542
543 }
544
545 /// Get read-only int64 * to pixel data starting at a specific pixel in the buffer.
546 /// \param row Start row for buffer pointer.
547 /// \param col Start column for buffer pointer.
548 /// \param plane Start plane for buffer pointer.
549 /// \retval Pointer to pixel data as int64 *.
550
551 const int64 * ConstPixel_int64 (int32 row,
552 int32 col,
553 uint32 plane = 0) const
554 {
555
556 ASSERT_PIXEL_TYPE (ttSLong8);
557
558 return (const int64 *) ConstPixel (row, col, plane);
559
560 }
561
562 /// Get a writable int64 * to pixel data starting at a specific pixel in the buffer.
563 /// \param row Start row for buffer pointer.
564 /// \param col Start column for buffer pointer.
565 /// \param plane Start plane for buffer pointer.
566 /// \retval Pointer to pixel data as int64 *.
567
568 int64 * DirtyPixel_int64 (int32 row,
569 int32 col,
570 uint32 plane = 0)
571 {
572
573 ASSERT_PIXEL_TYPE (ttSLong8);
574
575 return (int64 *) DirtyPixel (row, col, plane);
576
577 }
578
579 /// Get read-only real32 * to pixel data starting at a specific pixel in the buffer.
580 /// \param row Start row for buffer pointer.
581 /// \param col Start column for buffer pointer.
582 /// \param plane Start plane for buffer pointer.
583 /// \retval Pointer to pixel data as real32 *.
584
585 const real32 * ConstPixel_real32 (int32 row,
586 int32 col,
587 uint32 plane = 0) const
588 {
589
590 ASSERT_PIXEL_TYPE (ttFloat);
591
592 return (const real32 *) ConstPixel (row, col, plane);
593
594 }
595
596 /// Get a writable real32 * to pixel data starting at a specific pixel in the buffer.
597 /// \param row Start row for buffer pointer.
598 /// \param col Start column for buffer pointer.
599 /// \param plane Start plane for buffer pointer.
600 /// \retval Pointer to pixel data as real32 *.
601
602 real32 * DirtyPixel_real32 (int32 row,
603 int32 col,
604 uint32 plane = 0)
605 {
606
607 ASSERT_PIXEL_TYPE (ttFloat);
608
609 return (real32 *) DirtyPixel (row, col, plane);
610
611 }
612
613 /// Get read-only real64 * to pixel data starting at a specific pixel in the buffer.
614 /// \param row Start row for buffer pointer.
615 /// \param col Start column for buffer pointer.
616 /// \param plane Start plane for buffer pointer.
617 /// \retval Pointer to pixel data as real64 *.
618
619 const real64 * ConstPixel_real64 (int32 row,
620 int32 col,
621 uint32 plane = 0) const
622 {
623
624 ASSERT_PIXEL_TYPE (ttDouble);
625
626 return (const real64 *) ConstPixel (row, col, plane);
627
628 }
629
630 /// Get a writable real64 * to pixel data starting at a specific pixel in the buffer.
631 /// \param row Start row for buffer pointer.
632 /// \param col Start column for buffer pointer.
633 /// \param plane Start plane for buffer pointer.
634 /// \retval Pointer to pixel data as real64 *.
635
636 real64 * DirtyPixel_real64 (int32 row,
637 int32 col,
638 uint32 plane = 0)
639 {
640
641 ASSERT_PIXEL_TYPE (ttDouble);
642
643 return (real64 *) DirtyPixel (row, col, plane);
644
645 }
646
647 /// Initialize a rectangular area of pixel buffer to a constant.
648 /// \param area Rectangle of pixel buffer to set.
649 /// \param plane Plane to start filling on.
650 /// \param planes Number of planes to fill.
651 /// \param value Constant value to set pixels to.
652
653 void SetConstant (const dng_rect &area,
654 uint32 plane,
655 uint32 planes,
656 uint32 value);
657
658 /// Initialize a rectangular area of pixel buffer to a constant unsigned 8-bit value.
659 /// \param area Rectangle of pixel buffer to set.
660 /// \param plane Plane to start filling on.
661 /// \param planes Number of planes to fill.
662 /// \param value Constant uint8 value to set pixels to.
663
664 void SetConstant_uint8 (const dng_rect &area,
665 uint32 plane,
666 uint32 planes,
667 uint8 value)
668 {
669
670 DNG_ASSERT (fPixelType == ttByte, "Mismatched pixel type");
671
672 SetConstant (area, plane, planes, (uint32) value);
673
674 }
675
676 /// Initialize a rectangular area of pixel buffer to a constant unsigned 16-bit value.
677 /// \param area Rectangle of pixel buffer to set.
678 /// \param plane Plane to start filling on.
679 /// \param planes Number of planes to fill.
680 /// \param value Constant uint16 value to set pixels to.
681
682 void SetConstant_uint16 (const dng_rect &area,
683 uint32 plane,
684 uint32 planes,
685 uint16 value)
686 {
687
688 DNG_ASSERT (fPixelType == ttShort, "Mismatched pixel type");
689
690 SetConstant (area, plane, planes, (uint32) value);
691
692 }
693
694 /// Initialize a rectangular area of pixel buffer to a constant signed 16-bit value.
695 /// \param area Rectangle of pixel buffer to set.
696 /// \param plane Plane to start filling on.
697 /// \param planes Number of planes to fill.
698 /// \param value Constant int16 value to set pixels to.
699
700 void SetConstant_int16 (const dng_rect &area,
701 uint32 plane,
702 uint32 planes,
703 int16 value)
704 {
705
706 DNG_ASSERT (fPixelType == ttSShort, "Mismatched pixel type");
707
708 SetConstant (area, plane, planes, (uint32) (uint16) value);
709
710 }
711
712 /// Initialize a rectangular area of pixel buffer to a constant unsigned 32-bit value.
713 /// \param area Rectangle of pixel buffer to set.
714 /// \param plane Plane to start filling on.
715 /// \param planes Number of planes to fill.
716 /// \param value Constant uint32 value to set pixels to.
717
718 void SetConstant_uint32 (const dng_rect &area,
719 uint32 plane,
720 uint32 planes,
721 uint32 value)
722 {
723
724 DNG_ASSERT (fPixelType == ttLong, "Mismatched pixel type");
725
726 SetConstant (area, plane, planes, value);
727
728 }
729
730 /// Initialize a rectangular area of pixel buffer to a constant real 32-bit value.
731 /// \param area Rectangle of pixel buffer to set.
732 /// \param plane Plane to start filling on.
733 /// \param planes Number of planes to fill.
734 /// \param value Constant real32 value to set pixels to.
735
736 void SetConstant_real32 (const dng_rect &area,
737 uint32 plane,
738 uint32 planes,
739 real32 value)
740 {
741
742 DNG_ASSERT (fPixelType == ttFloat, "Mismatched pixel type");
743
744 union
745 {
746 uint32 i;
747 real32 f;
748 } x;
749
750 x.f = value;
751
752 SetConstant (area, plane, planes, x.i);
753
754 }
755
756 /// Initialize a rectangular area of pixel buffer to zeros.
757 /// \param area Rectangle of pixel buffer to zero.
758 /// \param plane Plane to start filling on.
759 /// \param planes Number of planes to fill.
760
761 void SetZero (const dng_rect &area,
762 uint32 plane,
763 uint32 planes);
764
765 /// Copy image data from an area of one pixel buffer to same area of another.
766 /// \param src Buffer to copy from.
767 /// \param area Rectangle of pixel buffer to copy.
768 /// \param srcPlane Plane to start copy in src.
769 /// \param dstPlane Plane to start copy in dst.
770 /// \param planes Number of planes to copy.
771 ///
772 /// Most pairings of the pixel types
773 /// {ttByte, ttShort, ttSShort, ttLong, ttFloat}
774 /// are currently supported, though not all pairings.
775 ///
776 /// Copies between the identical pixel types preserve values.
777 ///
778 /// Copies between an integer pixel type and ttFloat treat the
779 /// integer pixel type as normalized values in [0,1].
780 ///
781 /// Copies between ttShort and ttSShort toggle the sign bit and thus
782 /// preserve the data as normalized values.
783 ///
784 /// Copies supported between integer pixel types of different sizes
785 /// generally perform a promotion or demotion; they do not scale
786 /// the values (ttByte -> ttSShort is a special case, though it does
787 /// not scale values either). Consequently, copies between integer
788 /// pixel types of different sizes DO NOT PRESERVE NORMALIZED VALUES
789 /// and thus in general do not preserve the appearance of image
790 /// data represented by normalized values. This is by design, since
791 /// dng_pixel_buffer objects are often used for non-normalized data.
792 /// For example, a buffer may contain 10, 12 or 14-bit data.
793
794 void CopyArea (const dng_pixel_buffer &src,
795 const dng_rect &area,
796 uint32 srcPlane,
797 uint32 dstPlane,
798 uint32 planes);
799
800 /// Copy image data from an area of one pixel buffer to same area of another.
801 /// \param src Buffer to copy from.
802 /// \param area Rectangle of pixel buffer to copy.
803 /// \param plane Plane to start copy in src and this.
804 /// \param planes Number of planes to copy.
805
806 void CopyArea (const dng_pixel_buffer &src,
807 const dng_rect &area,
808 uint32 plane,
809 uint32 planes)
810 {
811
812 CopyArea (src, area, plane, plane, planes);
813
814 }
815
816 /// Calculate the offset phase of destination rectangle relative to source rectangle.
817 /// Phase is based on a 0,0 origin and the notion of repeating srcArea across dstArea.
818 /// It is the number of pixels into srcArea to start repeating from when tiling dstArea.
819 /// \retval dng_point containing horizontal and vertical phase.
820
821 static dng_point RepeatPhase (const dng_rect &srcArea,
822 const dng_rect &dstArea);
823
824 /// Repeat the image data in srcArea across dstArea.
825 /// (Generally used for padding operations.)
826 /// \param srcArea Area to repeat from.
827 /// \param dstArea Area to fill with data from srcArea.
828
829 void RepeatArea (const dng_rect &srcArea,
830 const dng_rect &dstArea);
831
832 /// Replicates a sub-area of a buffer to fill the entire buffer.
833
834 void RepeatSubArea (const dng_rect subArea,
835 uint32 repeatV = 1,
836 uint32 repeatH = 1);
837
838 /// Apply a right shift (C++ oerpator >>) to all pixel values. Only implemented for 16-bit (signed or unsigned) pixel buffers.
839 /// \param shift Number of bits by which to right shift each pixel value.
840
841 void ShiftRight (uint32 shift);
842
843 /// Change metadata so pixels are iterated in opposite horizontal order.
844 /// This operation does not require movement of actual pixel data.
845
846 void FlipH ();
847
848 /// Change metadata so pixels are iterated in opposite vertical order.
849 /// This operation does not require movement of actual pixel data.
850
851 void FlipV ();
852
853 /// Change metadata so pixels are iterated in opposite plane order.
854 /// This operation does not require movement of actual pixel data.
855
856 void FlipZ (); // Flip planes
857
858 /// Return true if the contents of an area of the pixel buffer area are the same as those of another.
859 /// \param rhs Buffer to compare against.
860 /// \param area Rectangle of pixel buffer to test.
861 /// \param plane Plane to start comparing.
862 /// \param planes Number of planes to compare.
863 /// \retval bool true if areas are equal, false otherwise.
864
865 bool EqualArea (const dng_pixel_buffer &rhs,
866 const dng_rect &area,
867 uint32 plane,
868 uint32 planes) const;
869
870 /// Return the absolute value of the maximum difference between two pixel buffers. Used for comparison testing with tolerance
871 /// \param rhs Buffer to compare against.
872 /// \param area Rectangle of pixel buffer to test.
873 /// \param plane Plane to start comparing.
874 /// \param planes Number of planes to compare.
875 /// \retval larges absolute value difference between the corresponding pixels each buffer across area.
876
877 real64 MaximumDifference (const dng_pixel_buffer &rhs,
878 const dng_rect &area,
879 uint32 plane,
880 uint32 planes) const;
881
882 };
883
884 /*****************************************************************************/
885
886 // Template versions of the DirtyPixel_xxx and ConstPixel_xxx methods.
887 // Facilitates use of those methods in templated functions.
888
889 /*****************************************************************************/
890
891 template <typename T>
892 inline T * DirtyPixel (dng_pixel_buffer & pixBuf,
893 const int32 row,
894 const int32 col,
895 const uint32 plane = 0) = delete;
896
897 #define DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE(T) \
898 template <> \
899 inline T * DirtyPixel (dng_pixel_buffer &pixBuf, \
900 const int32 row, \
901 const int32 col, \
902 const uint32 plane) \
903 { \
904 \
905 return pixBuf.DirtyPixel_ ## T (row, col, plane); \
906 \
907 }
908
909 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE (uint8 )
910 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE ( int8 )
911 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE (uint16)
912 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE ( int16)
913 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE (uint32)
914 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE ( int32)
915 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE (uint64)
916 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE ( int64)
917 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE (real32)
918 DEFINE_DIRTY_PIXEL_SPECIALIZATION_FOR_TYPE (real64)
919
920 /*****************************************************************************/
921
922 template <typename T>
923 inline const T * ConstPixel (const dng_pixel_buffer &pixBuf,
924 const int32 row,
925 const int32 col,
926 const uint32 plane = 0) = delete;
927
928 #define DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE(T) \
929 template <> \
930 inline const T * ConstPixel (const dng_pixel_buffer &pixBuf, \
931 const int32 row, \
932 const int32 col, \
933 const uint32 plane) \
934 { \
935 \
936 return pixBuf.ConstPixel_ ## T (row, col, plane); \
937 \
938 }
939
940 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE (uint8 )
941 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE ( int8 )
942 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE (uint16)
943 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE ( int16)
944 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE (uint32)
945 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE ( int32)
946 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE (uint64)
947 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE ( int64)
948 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE (real32)
949 DEFINE_CONST_PIXEL_SPECIALIZATION_FOR_TYPE (real64)
950
951 /*****************************************************************************/
952
953 template <typename T>
954 inline constexpr T SignBit () = delete;
955
956 template <> inline constexpr uint8 SignBit () { return (uint8)0x80; }
957 template <> inline constexpr int8 SignBit () { return (int8)0x80; }
958 template <> inline constexpr uint16 SignBit () { return (uint16)0x8000; }
959 template <> inline constexpr int16 SignBit () { return (int16)0x8000; }
960 template <> inline constexpr uint32 SignBit () { return (uint32)0x80000000; }
961 template <> inline constexpr int32 SignBit () { return (int32)0x80000000; }
962 template <> inline constexpr uint64 SignBit () { return (uint64)0x8000000000000000ULL; }
963 template <> inline constexpr int64 SignBit () { return (int64)0x8000000000000000ULL; }
964
965 /*****************************************************************************/
966
967 #endif
968
969 /*****************************************************************************/