Coverage Report

Created: 2026-08-31 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dng_sdk/source/dng_pixel_buffer.cpp
Line
Count
Source
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_pixel_buffer.cpp#1 $ */ 
10
/* $DateTime: 2012/05/30 13:28:51 $ */
11
/* $Change: 832332 $ */
12
/* $Author: tknoll $ */
13
14
/*****************************************************************************/
15
16
#include "dng_pixel_buffer.h"
17
18
#include "dng_bottlenecks.h"
19
#include "dng_exceptions.h"
20
#include "dng_flags.h"
21
#include "dng_safe_arithmetic.h"
22
#include "dng_tag_types.h"
23
#include "dng_tag_values.h"
24
#include "dng_utils.h"
25
26
/*****************************************************************************/
27
28
namespace {
29
30
3.30M
bool SafeUint32ToInt32Mult(uint32 arg1, uint32 arg2, int32 *result) {
31
3.30M
  uint32 uint32_result;
32
3.30M
  return SafeUint32Mult(arg1, arg2, &uint32_result) &&
33
3.30M
    ConvertUint32ToInt32(uint32_result, result);
34
3.30M
}
35
36
} // namespace
37
38
/*****************************************************************************/
39
40
void OptimizeOrder (const void *&sPtr,
41
          void *&dPtr,
42
          uint32 sPixelSize,
43
          uint32 dPixelSize,
44
          uint32 &count0,
45
          uint32 &count1,
46
          uint32 &count2,
47
          int32 &sStep0,
48
          int32 &sStep1,
49
          int32 &sStep2,
50
          int32 &dStep0,
51
          int32 &dStep1,
52
          int32 &dStep2)
53
5.13M
  {
54
  
55
5.13M
  uint32 step0;
56
5.13M
  uint32 step1;
57
5.13M
  uint32 step2;
58
  
59
  // Optimize the order for the data that is most spread out.
60
                 
61
5.13M
  uint32 sRange = Abs_int32 (sStep0) * (count0 - 1) +
62
5.13M
          Abs_int32 (sStep1) * (count1 - 1) +
63
5.13M
          Abs_int32 (sStep2) * (count2 - 1);
64
                 
65
5.13M
  uint32 dRange = Abs_int32 (dStep0) * (count0 - 1) +
66
5.13M
          Abs_int32 (dStep1) * (count1 - 1) +
67
5.13M
          Abs_int32 (dStep2) * (count2 - 1);
68
                 
69
5.13M
  if (dRange >= sRange)
70
4.11M
    {           
71
  
72
4.11M
    if (dStep0 < 0)
73
0
      {
74
      
75
0
      sPtr = (const void *)
76
0
           (((const uint8 *) sPtr) + (int32)(count0 - 1) * sStep0 * (int32)sPixelSize);
77
           
78
0
      dPtr = (void *)
79
0
           (((uint8 *) dPtr) + (int32)(count0 - 1) * dStep0 * (int32)dPixelSize);
80
           
81
0
      sStep0 = -sStep0;
82
0
      dStep0 = -dStep0;
83
      
84
0
      }
85
    
86
4.11M
    if (dStep1 < 0)
87
0
      {
88
      
89
0
      sPtr = (const void *)
90
0
           (((const uint8 *) sPtr) + (int32)(count1 - 1) * sStep1 * (int32)sPixelSize);
91
           
92
0
      dPtr = (void *)
93
0
           (((uint8 *) dPtr) + (int32)(count1 - 1) * dStep1 * (int32)dPixelSize);
94
           
95
0
      sStep1 = -sStep1;
96
0
      dStep1 = -dStep1;
97
      
98
0
      }
99
    
100
4.11M
    if (dStep2 < 0)
101
0
      {
102
      
103
0
      sPtr = (const void *)
104
0
           (((const uint8 *) sPtr) + (int32)(count2 - 1) * sStep2 * (int32)sPixelSize);
105
           
106
0
      dPtr = (void *)
107
0
           (((uint8 *) dPtr) + (int32)(count2 - 1) * dStep2 * (int32)dPixelSize);
108
           
109
0
      sStep2 = -sStep2;
110
0
      dStep2 = -dStep2;
111
      
112
0
      }
113
    
114
4.11M
    step0 = (uint32) dStep0;
115
4.11M
    step1 = (uint32) dStep1;
116
4.11M
    step2 = (uint32) dStep2;
117
    
118
4.11M
    }
119
    
120
1.02M
  else
121
1.02M
    {           
122
  
123
1.02M
    if (sStep0 < 0)
124
3.48k
      {
125
      
126
3.48k
      sPtr = (const void *)
127
3.48k
           (((const uint8 *) sPtr) + (int32)(count0 - 1) * sStep0 * (int32)sPixelSize);
128
           
129
3.48k
      dPtr = (void *)
130
3.48k
           (((uint8 *) dPtr) + (int32)(count0 - 1) * dStep0 * (int32)dPixelSize);
131
           
132
3.48k
      sStep0 = -sStep0;
133
3.48k
      dStep0 = -dStep0;
134
      
135
3.48k
      }
136
    
137
1.02M
    if (sStep1 < 0)
138
952
      {
139
      
140
952
      sPtr = (const void *)
141
952
           (((const uint8 *) sPtr) + (int32)(count1 - 1) * sStep1 * (int32)sPixelSize);
142
           
143
952
      dPtr = (void *)
144
952
           (((uint8 *) dPtr) + (int32)(count1 - 1) * dStep1 * (int32)dPixelSize);
145
           
146
952
      sStep1 = -sStep1;
147
952
      dStep1 = -dStep1;
148
      
149
952
      }
150
    
151
1.02M
    if (sStep2 < 0)
152
0
      {
153
      
154
0
      sPtr = (const void *)
155
0
           (((const uint8 *) sPtr) + (int32)(count2 - 1) * sStep2 * (int32)sPixelSize);
156
           
157
0
      dPtr = (void *)
158
0
           (((uint8 *) dPtr) + (int32)(count2 - 1) * dStep2 * (int32)dPixelSize);
159
           
160
0
      sStep2 = -sStep2;
161
0
      dStep2 = -dStep2;
162
      
163
0
      }
164
    
165
1.02M
    step0 = (uint32) sStep0;
166
1.02M
    step1 = (uint32) sStep1;
167
1.02M
    step2 = (uint32) sStep2;
168
    
169
1.02M
    }
170
  
171
5.13M
  if (count0 == 1) step0 = 0xFFFFFFFF;
172
5.13M
  if (count1 == 1) step1 = 0xFFFFFFFF;
173
5.13M
  if (count2 == 1) step2 = 0xFFFFFFFF;
174
  
175
5.13M
  uint32 index0;
176
5.13M
  uint32 index1;
177
5.13M
  uint32 index2;
178
  
179
5.13M
  if (step0 >= step1)
180
4.55M
    {
181
    
182
4.55M
    if (step1 >= step2)
183
1.56M
      {
184
1.56M
      index0 = 0;
185
1.56M
      index1 = 1;
186
1.56M
      index2 = 2;
187
1.56M
      }
188
      
189
2.99M
    else if (step2 >= step0)
190
2.80M
      {
191
2.80M
      index0 = 2;
192
2.80M
      index1 = 0;
193
2.80M
      index2 = 1;
194
2.80M
      }
195
      
196
186k
    else
197
186k
      {
198
186k
      index0 = 0;
199
186k
      index1 = 2;
200
186k
      index2 = 1;
201
186k
      }
202
    
203
4.55M
    }
204
    
205
584k
  else
206
584k
    {
207
    
208
584k
    if (step0 >= step2)
209
85.1k
      {
210
85.1k
      index0 = 1;
211
85.1k
      index1 = 0;
212
85.1k
      index2 = 2;
213
85.1k
      }
214
      
215
499k
    else if (step2 >= step1)
216
494k
      {
217
494k
      index0 = 2;
218
494k
      index1 = 1;
219
494k
      index2 = 0;
220
494k
      }
221
      
222
4.75k
    else
223
4.75k
      {
224
4.75k
      index0 = 1;
225
4.75k
      index1 = 2;
226
4.75k
      index2 = 0;
227
4.75k
      }
228
    
229
584k
    }
230
    
231
5.13M
  uint32 count [3];
232
  
233
5.13M
  count [0] = count0;
234
5.13M
  count [1] = count1;
235
5.13M
  count [2] = count2;
236
  
237
5.13M
  count0 = count [index0];
238
5.13M
  count1 = count [index1];
239
5.13M
  count2 = count [index2];
240
  
241
5.13M
  int32 step [3];
242
  
243
5.13M
  step [0] = sStep0;
244
5.13M
  step [1] = sStep1;
245
5.13M
  step [2] = sStep2;
246
  
247
5.13M
  sStep0 = step [index0];
248
5.13M
  sStep1 = step [index1];
249
5.13M
  sStep2 = step [index2];
250
  
251
5.13M
  step [0] = dStep0;
252
5.13M
  step [1] = dStep1;
253
5.13M
  step [2] = dStep2;
254
  
255
5.13M
  dStep0 = step [index0];
256
5.13M
  dStep1 = step [index1];
257
5.13M
  dStep2 = step [index2];
258
  
259
5.13M
  if (sStep0 == ((int32) count1) * sStep1 &&
260
1.37M
    dStep0 == ((int32) count1) * dStep1)
261
985k
    {
262
985k
    count1 *= count0;
263
985k
    count0 = 1;
264
985k
    }
265
  
266
5.13M
  if (sStep1 == ((int32) count2) * sStep2 &&
267
2.50M
    dStep1 == ((int32) count2) * dStep2)
268
1.80M
    {
269
1.80M
    count2 *= count1;
270
1.80M
    count1 = 1;
271
1.80M
    }
272
  
273
5.13M
  }
274
275
/*****************************************************************************/
276
277
void OptimizeOrder (const void *&sPtr,
278
          uint32 sPixelSize,
279
          uint32 &count0,
280
          uint32 &count1,
281
          uint32 &count2,
282
          int32 &sStep0,
283
          int32 &sStep1,
284
          int32 &sStep2)
285
7.37k
  {
286
  
287
7.37k
  void *dPtr = NULL;
288
  
289
7.37k
  int32 dStep0 = sStep0;
290
7.37k
  int32 dStep1 = sStep1;
291
7.37k
  int32 dStep2 = sStep2;
292
  
293
7.37k
  OptimizeOrder (sPtr,
294
7.37k
           dPtr,
295
7.37k
           sPixelSize,
296
7.37k
           sPixelSize,
297
7.37k
           count0,
298
7.37k
           count1,
299
7.37k
           count2,
300
7.37k
           sStep0,
301
7.37k
           sStep1,
302
7.37k
           sStep2,
303
7.37k
           dStep0,
304
7.37k
           dStep1,
305
7.37k
           dStep2);
306
  
307
7.37k
  }
308
309
/*****************************************************************************/
310
311
void OptimizeOrder (void *&dPtr,
312
          uint32 dPixelSize,
313
          uint32 &count0,
314
          uint32 &count1,
315
          uint32 &count2,
316
          int32 &dStep0,
317
          int32 &dStep1,
318
          int32 &dStep2)
319
172k
  {
320
  
321
172k
  const void *sPtr = NULL;
322
  
323
172k
  int32 sStep0 = dStep0;
324
172k
  int32 sStep1 = dStep1;
325
172k
  int32 sStep2 = dStep2;
326
  
327
172k
  OptimizeOrder (sPtr,
328
172k
           dPtr,
329
172k
           dPixelSize,
330
172k
           dPixelSize,
331
172k
           count0,
332
172k
           count1,
333
172k
           count2,
334
172k
           sStep0,
335
172k
           sStep1,
336
172k
           sStep2,
337
172k
           dStep0,
338
172k
           dStep1,
339
172k
           dStep2);
340
  
341
172k
  }
342
343
/*****************************************************************************/
344
345
dng_pixel_buffer::dng_pixel_buffer ()
346
347
5.40M
  : fArea       ()
348
5.40M
  , fPlane      (0)
349
5.40M
  , fPlanes     (1)
350
5.40M
  , fRowStep    (1)
351
5.40M
  , fColStep    (1)
352
5.40M
  , fPlaneStep  (1)
353
5.40M
  , fPixelType  (ttUndefined)
354
5.40M
  , fPixelSize  (0)
355
5.40M
  , fData       (NULL)
356
5.40M
  , fDirty      (true)
357
  
358
5.40M
  {
359
  
360
5.40M
  }
361
362
/*****************************************************************************/
363
364
dng_pixel_buffer::dng_pixel_buffer (const dng_rect &area,
365
                  uint32 plane,
366
                  uint32 planes,
367
                  uint32 pixelType,
368
                  uint32 planarConfiguration,
369
                  void *data)
370
371
3.30M
  : fArea       (area)
372
3.30M
  , fPlane      (plane)
373
3.30M
  , fPlanes     (planes)
374
3.30M
  , fRowStep    (0)
375
3.30M
  , fColStep    (0)
376
3.30M
  , fPlaneStep  (0)
377
3.30M
  , fPixelType  (pixelType)
378
3.30M
  , fPixelSize  (TagTypeSize(pixelType))
379
3.30M
  , fData       (data)
380
3.30M
  , fDirty      (true)
381
  
382
3.30M
  {
383
  
384
3.30M
  const char *overflowMessage = "Arithmetic overflow in pixel buffer setup";
385
  
386
  // Initialize fRowStep, fColStep and fPlaneStep according to the desired
387
  // pixel layout.
388
3.30M
  switch (planarConfiguration)
389
3.30M
    {
390
493k
    case pcInterleaved:
391
493k
      fPlaneStep = 1;
392
493k
      if (!ConvertUint32ToInt32 (fPlanes, &fColStep) ||
393
493k
        !SafeUint32ToInt32Mult (fArea.W(), fPlanes, &fRowStep))
394
23
        {
395
23
        ThrowMemoryFull (overflowMessage);
396
23
        }
397
493k
      break;
398
213k
    case pcPlanar:
399
213k
      fColStep = 1;
400
      // Even though we've hardened dng_rect::W() to guarantee that it
401
      // will never return a result that's out of range for an int32,
402
      // we still protect the conversion for defense in depth.
403
213k
      if (!ConvertUint32ToInt32 (fArea.W(), &fRowStep) ||
404
213k
        !SafeUint32ToInt32Mult (fArea.H(), fArea.W(), &fPlaneStep))
405
0
        {
406
0
        ThrowMemoryFull (overflowMessage);
407
0
        }
408
213k
      break;
409
1.58k
    case pcRowInterleaved:
410
2.60M
    case pcRowInterleavedAlign16:
411
2.60M
      {
412
2.60M
      fColStep = 1;
413
2.60M
      uint32 planeStepUint32;
414
2.60M
      if (planarConfiguration == pcRowInterleaved)
415
1.58k
        {
416
1.58k
        planeStepUint32 = fArea.W();
417
1.58k
        }
418
2.59M
      else
419
2.59M
        {
420
2.59M
        if (!RoundUpForPixelSize (fArea.W(), fPixelSize,
421
2.59M
                      &planeStepUint32))
422
0
          {
423
0
          ThrowMemoryFull (overflowMessage);
424
0
          }
425
2.59M
        }
426
2.60M
      if (!ConvertUint32ToInt32 (planeStepUint32, &fPlaneStep) ||
427
2.60M
        !SafeUint32ToInt32Mult (planeStepUint32, fPlanes, &fRowStep))
428
0
        {
429
0
        ThrowMemoryFull (overflowMessage);
430
0
        }
431
2.60M
      break;
432
1.58k
      }
433
0
    default:
434
0
      ThrowProgramError ("Invalid value for 'planarConfiguration'");
435
0
      break;
436
3.30M
    }
437
  
438
3.30M
  }
439
440
/*****************************************************************************/
441
442
dng_pixel_buffer::dng_pixel_buffer (const dng_pixel_buffer &buffer)
443
444
5.05M
  : fArea       (buffer.fArea)
445
5.05M
  , fPlane      (buffer.fPlane)
446
5.05M
  , fPlanes     (buffer.fPlanes)
447
5.05M
  , fRowStep    (buffer.fRowStep)
448
5.05M
  , fColStep    (buffer.fColStep)
449
5.05M
  , fPlaneStep  (buffer.fPlaneStep)
450
5.05M
  , fPixelType  (buffer.fPixelType)
451
5.05M
  , fPixelSize  (buffer.fPixelSize)
452
5.05M
  , fData       (buffer.fData)
453
5.05M
  , fDirty      (buffer.fDirty)
454
  
455
5.05M
  {
456
  
457
5.05M
  }
458
              
459
/*****************************************************************************/
460
461
dng_pixel_buffer & dng_pixel_buffer::operator= (const dng_pixel_buffer &buffer)
462
103k
  {
463
  
464
103k
  fArea       = buffer.fArea;
465
103k
  fPlane      = buffer.fPlane;
466
103k
  fPlanes     = buffer.fPlanes;
467
103k
  fRowStep    = buffer.fRowStep;
468
103k
  fColStep    = buffer.fColStep;
469
103k
  fPlaneStep  = buffer.fPlaneStep;
470
103k
  fPixelType  = buffer.fPixelType;
471
103k
  fPixelSize  = buffer.fPixelSize;
472
103k
  fPixelType  = buffer.fPixelType;
473
103k
  fData       = buffer.fData;
474
103k
  fDirty      = buffer.fDirty;
475
  
476
103k
  return *this;
477
  
478
103k
  }
479
480
/*****************************************************************************/
481
482
dng_pixel_buffer::~dng_pixel_buffer ()
483
13.7M
  {
484
  
485
13.7M
  }
486
              
487
/*****************************************************************************/
488
489
#if qDebugPixelType
490
491
void dng_pixel_buffer::CheckPixelType (uint32 pixelType) const
492
  {
493
  
494
  if (fPixelType != pixelType)
495
    {
496
    
497
    DNG_REPORT ("Pixel type access mismatch");
498
    
499
    }
500
  
501
  }
502
503
#endif
504
505
/*****************************************************************************/
506
507
uint32 dng_pixel_buffer::PixelRange () const
508
1.04M
  {
509
  
510
1.04M
  switch (fPixelType)
511
1.04M
    {
512
    
513
608k
    case ttByte:
514
608k
    case ttSByte:
515
608k
      {
516
608k
      return 0x0FF;
517
608k
      }
518
      
519
438k
    case ttShort:
520
438k
    case ttSShort:
521
438k
      {
522
438k
      return 0x0FFFF;
523
438k
      }
524
      
525
0
    case ttLong:
526
0
    case ttSLong:
527
0
      {
528
0
      return 0xFFFFFFFF;
529
0
      }
530
      
531
0
    default:
532
0
      break;
533
      
534
1.04M
    }
535
  
536
0
  return 0;
537
  
538
1.04M
  }
539
              
540
/*****************************************************************************/
541
542
void dng_pixel_buffer::SetConstant (const dng_rect &area,
543
                  uint32 plane,
544
                  uint32 planes,
545
                  uint32 value)
546
172k
  {
547
  
548
172k
  uint32 rows = area.H ();
549
172k
  uint32 cols = area.W ();
550
  
551
172k
  void *dPtr = DirtyPixel (area.t,
552
172k
                 area.l,
553
172k
                 plane);
554
              
555
172k
  int32 dRowStep   = fRowStep;
556
172k
  int32 dColStep   = fColStep;
557
172k
  int32 dPlaneStep = fPlaneStep;
558
  
559
172k
  OptimizeOrder (dPtr,
560
172k
           fPixelSize,
561
172k
           rows,
562
172k
           cols,
563
172k
           planes,
564
172k
           dRowStep,
565
172k
           dColStep,
566
172k
           dPlaneStep);
567
           
568
172k
  switch (fPixelSize)
569
172k
    {
570
    
571
20.9k
    case 1:
572
20.9k
      {
573
      
574
20.9k
      if (rows == 1 && cols == 1 && dPlaneStep == 1 && value == 0)
575
10.6k
        {
576
        
577
10.6k
        DoZeroBytes (dPtr, planes);
578
        
579
10.6k
        }
580
        
581
10.3k
      else
582
10.3k
        {
583
        
584
10.3k
        DoSetArea8 ((uint8 *) dPtr,
585
10.3k
              (uint8) value,
586
10.3k
              rows,
587
10.3k
              cols,
588
10.3k
              planes,
589
10.3k
              dRowStep,
590
10.3k
              dColStep,
591
10.3k
              dPlaneStep);
592
             
593
10.3k
        }
594
        
595
20.9k
      break;
596
      
597
0
      }
598
           
599
130k
    case 2:
600
130k
      {
601
      
602
130k
      if (rows == 1 && cols == 1 && dPlaneStep == 1 && value == 0)
603
103k
        {
604
        
605
103k
        DoZeroBytes (dPtr, planes << 1);
606
        
607
103k
        }
608
        
609
27.0k
      else
610
27.0k
        {
611
        
612
27.0k
        DoSetArea16 ((uint16 *) dPtr,
613
27.0k
               (uint16) value,
614
27.0k
               rows,
615
27.0k
               cols,
616
27.0k
               planes,
617
27.0k
               dRowStep,
618
27.0k
               dColStep,
619
27.0k
               dPlaneStep);
620
             
621
27.0k
        }
622
        
623
130k
      break;
624
      
625
0
      }
626
           
627
21.4k
    case 4:
628
21.4k
      {
629
      
630
21.4k
      if (rows == 1 && cols == 1 && dPlaneStep == 1 && value == 0)
631
10.5k
        {
632
        
633
10.5k
        DoZeroBytes (dPtr, planes << 2);
634
        
635
10.5k
        }
636
        
637
10.9k
      else
638
10.9k
        {
639
        
640
10.9k
        DoSetArea32 ((uint32 *) dPtr,
641
10.9k
               value,
642
10.9k
               rows,
643
10.9k
               cols,
644
10.9k
               planes,
645
10.9k
               dRowStep,
646
10.9k
               dColStep,
647
10.9k
               dPlaneStep);
648
             
649
10.9k
        }
650
        
651
21.4k
      break;
652
      
653
0
      }
654
      
655
0
    default:
656
0
      {
657
      
658
0
      ThrowNotYetImplemented ();
659
      
660
0
      }
661
      
662
172k
    }
663
           
664
172k
  }
665
    
666
/*****************************************************************************/
667
668
void dng_pixel_buffer::SetZero (const dng_rect &area,
669
                  uint32 plane,
670
                  uint32 planes)
671
172k
  {
672
             
673
172k
  uint32 value = 0;
674
           
675
172k
  switch (fPixelType)
676
172k
    {
677
    
678
20.9k
    case ttByte:
679
151k
    case ttShort:
680
152k
    case ttLong:
681
172k
    case ttFloat:
682
172k
      {
683
172k
      break;
684
152k
      }
685
      
686
0
    case ttSShort:
687
0
      {
688
0
      value = 0x8000;
689
0
      break;
690
152k
      }
691
692
0
    default:
693
0
      {
694
      
695
0
      ThrowNotYetImplemented ();
696
      
697
0
      }
698
      
699
172k
    }
700
    
701
172k
  SetConstant (area,
702
172k
         plane,
703
172k
         planes,
704
172k
         value);
705
           
706
172k
  }
707
    
708
/*****************************************************************************/
709
710
void dng_pixel_buffer::CopyArea (const dng_pixel_buffer &src,
711
                   const dng_rect &area,
712
                   uint32 srcPlane,
713
                   uint32 dstPlane,
714
                   uint32 planes)
715
4.93M
  {
716
  
717
4.93M
  uint32 rows = area.H ();
718
4.93M
  uint32 cols = area.W ();
719
  
720
4.93M
  const void *sPtr = src.ConstPixel (area.t,
721
4.93M
                       area.l,
722
4.93M
                       srcPlane);
723
                  
724
4.93M
  void *dPtr = DirtyPixel (area.t,
725
4.93M
                 area.l,
726
4.93M
                 dstPlane);
727
  
728
4.93M
  int32 sRowStep   = src.fRowStep;
729
4.93M
  int32 sColStep   = src.fColStep;
730
4.93M
  int32 sPlaneStep = src.fPlaneStep;
731
  
732
4.93M
  int32 dRowStep   = fRowStep;
733
4.93M
  int32 dColStep   = fColStep;
734
4.93M
  int32 dPlaneStep = fPlaneStep;
735
  
736
4.93M
  OptimizeOrder (sPtr,
737
4.93M
           dPtr,
738
4.93M
           src.fPixelSize,
739
4.93M
           fPixelSize,
740
4.93M
           rows,
741
4.93M
           cols,
742
4.93M
           planes,
743
4.93M
           sRowStep,
744
4.93M
           sColStep,
745
4.93M
           sPlaneStep,
746
4.93M
           dRowStep,
747
4.93M
           dColStep,
748
4.93M
           dPlaneStep);
749
           
750
4.93M
  if (fPixelType == src.fPixelType)
751
3.87M
    {
752
    
753
3.87M
    if (rows == 1 && cols == 1 && sPlaneStep == 1 && dPlaneStep == 1)
754
2.36M
      {
755
      
756
2.36M
      DoCopyBytes (sPtr,
757
2.36M
             dPtr, 
758
2.36M
             planes * fPixelSize);
759
      
760
2.36M
      }
761
      
762
1.51M
    else switch (fPixelSize)
763
1.51M
      {
764
      
765
26.3k
      case 1:
766
26.3k
        {
767
        
768
26.3k
        DoCopyArea8 ((const uint8 *) sPtr,
769
26.3k
               (uint8 *) dPtr,
770
26.3k
               rows,
771
26.3k
               cols,
772
26.3k
               planes,
773
26.3k
               sRowStep,
774
26.3k
               sColStep,
775
26.3k
               sPlaneStep,
776
26.3k
               dRowStep,
777
26.3k
               dColStep,
778
26.3k
               dPlaneStep);
779
        
780
26.3k
        break;
781
        
782
0
        }
783
        
784
824k
      case 2:
785
824k
        {
786
        
787
824k
        DoCopyArea16 ((const uint16 *) sPtr,
788
824k
                (uint16 *) dPtr,
789
824k
                rows,
790
824k
                cols,
791
824k
                planes,
792
824k
                sRowStep,
793
824k
                sColStep,
794
824k
                sPlaneStep,
795
824k
                dRowStep,
796
824k
                dColStep,
797
824k
                dPlaneStep);
798
        
799
824k
        break;
800
        
801
0
        }
802
        
803
662k
      case 4:
804
662k
        {
805
        
806
662k
        DoCopyArea32 ((const uint32 *) sPtr,
807
662k
                (uint32 *) dPtr,
808
662k
                rows,
809
662k
                cols,
810
662k
                planes,
811
662k
                sRowStep,
812
662k
                sColStep,
813
662k
                sPlaneStep,
814
662k
                dRowStep,
815
662k
                dColStep,
816
662k
                dPlaneStep);
817
        
818
662k
        break;
819
        
820
0
        }
821
        
822
0
      default:
823
0
        {
824
        
825
0
        ThrowNotYetImplemented ();
826
        
827
0
        }
828
        
829
1.51M
      }
830
    
831
3.87M
    }
832
    
833
1.05M
  else if (src.fPixelType == ttByte)
834
8.69k
    {
835
    
836
8.69k
    switch (fPixelType)
837
8.69k
      {
838
      
839
8.69k
      case ttShort:
840
8.69k
        {
841
        
842
8.69k
        DoCopyArea8_16 ((const uint8 *) sPtr,
843
8.69k
                  (uint16 *) dPtr,
844
8.69k
                  rows,
845
8.69k
                  cols,
846
8.69k
                  planes,
847
8.69k
                  sRowStep,
848
8.69k
                  sColStep,
849
8.69k
                  sPlaneStep,
850
8.69k
                  dRowStep,
851
8.69k
                  dColStep,
852
8.69k
                  dPlaneStep);
853
        
854
8.69k
        break;
855
        
856
0
        }
857
        
858
0
      case ttSShort:
859
0
        {
860
        
861
0
        DoCopyArea8_S16 ((const uint8 *) sPtr,
862
0
                   (int16 *) dPtr,
863
0
                   rows,
864
0
                   cols,
865
0
                   planes,
866
0
                   sRowStep,
867
0
                   sColStep,
868
0
                   sPlaneStep,
869
0
                   dRowStep,
870
0
                   dColStep,
871
0
                   dPlaneStep);
872
        
873
0
        break;
874
        
875
0
        }
876
        
877
0
      case ttLong:
878
0
        {
879
        
880
0
        DoCopyArea8_32 ((const uint8 *) sPtr,
881
0
                  (uint32 *) dPtr,
882
0
                  rows,
883
0
                  cols,
884
0
                  planes,
885
0
                  sRowStep,
886
0
                  sColStep,
887
0
                  sPlaneStep,
888
0
                  dRowStep,
889
0
                  dColStep,
890
0
                  dPlaneStep);
891
        
892
0
        break;
893
        
894
0
        }
895
        
896
0
      case ttFloat:
897
0
        {
898
        
899
0
        DoCopyArea8_R32 ((const uint8 *) sPtr,
900
0
                   (real32 *) dPtr,
901
0
                   rows,
902
0
                   cols,
903
0
                   planes,
904
0
                   sRowStep,
905
0
                   sColStep,
906
0
                   sPlaneStep,
907
0
                   dRowStep,
908
0
                   dColStep,
909
0
                   dPlaneStep,
910
0
                 src.PixelRange ());
911
        
912
0
        break;
913
        
914
0
        }
915
        
916
0
      default:
917
0
        {
918
        
919
0
        ThrowNotYetImplemented ();
920
        
921
0
        }
922
        
923
8.69k
      }
924
    
925
8.69k
    }
926
    
927
1.05M
  else if (src.fPixelType == ttShort)
928
403k
    {
929
    
930
403k
    switch (fPixelType)
931
403k
      {
932
      
933
3.20k
      case ttByte:
934
3.20k
        {
935
        
936
3.20k
        DoCopyArea8 (((const uint8 *) sPtr) + (qDNGBigEndian ? 1 : 0),
937
3.20k
               (uint8 *) dPtr,
938
3.20k
               rows,
939
3.20k
               cols,
940
3.20k
               planes,
941
3.20k
               sRowStep << 1,
942
3.20k
               sColStep << 1,
943
3.20k
               sPlaneStep << 1,
944
3.20k
               dRowStep,
945
3.20k
               dColStep,
946
3.20k
               dPlaneStep);
947
            
948
3.20k
        break;
949
        
950
0
        }
951
952
0
      case ttSShort:
953
0
        {
954
        
955
0
        DoCopyArea16_S16 ((const uint16 *) sPtr,
956
0
                    (int16 *) dPtr,
957
0
                    rows,
958
0
                    cols,
959
0
                    planes,
960
0
                    sRowStep,
961
0
                    sColStep,
962
0
                    sPlaneStep,
963
0
                    dRowStep,
964
0
                    dColStep,
965
0
                    dPlaneStep);
966
        
967
0
        break;
968
        
969
0
        }
970
        
971
0
      case ttLong:
972
0
        {
973
        
974
0
        DoCopyArea16_32 ((const uint16 *) sPtr,
975
0
                   (uint32 *) dPtr,
976
0
                   rows,
977
0
                   cols,
978
0
                   planes,
979
0
                   sRowStep,
980
0
                   sColStep,
981
0
                   sPlaneStep,
982
0
                   dRowStep,
983
0
                   dColStep,
984
0
                   dPlaneStep);
985
        
986
0
        break;
987
        
988
0
        }
989
        
990
400k
      case ttFloat:
991
400k
        {
992
        
993
400k
        DoCopyArea16_R32 ((const uint16 *) sPtr,
994
400k
                    (real32 *) dPtr,
995
400k
                  rows,
996
400k
                    cols,
997
400k
                    planes,
998
400k
                    sRowStep,
999
400k
                    sColStep,
1000
400k
                    sPlaneStep,
1001
400k
                    dRowStep,
1002
400k
                    dColStep,
1003
400k
                    dPlaneStep,
1004
400k
                  src.PixelRange ());
1005
        
1006
400k
        break;
1007
        
1008
0
        }
1009
        
1010
0
      default:
1011
0
        {
1012
        
1013
0
        ThrowNotYetImplemented ();
1014
        
1015
0
        }
1016
        
1017
403k
      }
1018
      
1019
403k
    }
1020
    
1021
646k
  else if (src.fPixelType == ttSShort)
1022
0
    {
1023
    
1024
0
    switch (fPixelType)
1025
0
      {
1026
      
1027
0
      case ttByte:
1028
0
        {
1029
        
1030
0
        DoCopyArea8 (((const uint8 *) sPtr) + (qDNGBigEndian ? 1 : 0),
1031
0
               (uint8 *) dPtr,
1032
0
               rows,
1033
0
               cols,
1034
0
               planes,
1035
0
               sRowStep << 1,
1036
0
               sColStep << 1,
1037
0
               sPlaneStep << 1,
1038
0
               dRowStep,
1039
0
               dColStep,
1040
0
               dPlaneStep);
1041
            
1042
0
        break;
1043
        
1044
0
        }
1045
1046
0
      case ttShort:
1047
0
        {
1048
        
1049
        // Moving between signed 16 bit values and unsigned 16
1050
        // bit values just requires toggling the sign bit.  So
1051
        // we can use the "backwards" bottleneck.
1052
        
1053
0
        DoCopyArea16_S16 ((const uint16 *) sPtr,
1054
0
                    (int16 *) dPtr,
1055
0
                    rows,
1056
0
                    cols,
1057
0
                    planes,
1058
0
                    sRowStep,
1059
0
                    sColStep,
1060
0
                    sPlaneStep,
1061
0
                    dRowStep,
1062
0
                    dColStep,
1063
0
                    dPlaneStep);
1064
        
1065
0
        break;
1066
        
1067
0
        }
1068
        
1069
0
      case ttFloat:
1070
0
        {
1071
        
1072
0
        DoCopyAreaS16_R32 ((const int16 *) sPtr,
1073
0
                   (real32 *) dPtr,
1074
0
                   rows,
1075
0
                     cols,
1076
0
                     planes,
1077
0
                   sRowStep,
1078
0
                     sColStep,
1079
0
                   sPlaneStep,
1080
0
                     dRowStep,
1081
0
                     dColStep,
1082
0
                     dPlaneStep,
1083
0
                   src.PixelRange ());
1084
        
1085
0
        break;
1086
        
1087
0
        }
1088
        
1089
0
      default:
1090
0
        {
1091
        
1092
0
        ThrowNotYetImplemented ();
1093
        
1094
0
        }
1095
        
1096
0
      }
1097
      
1098
0
    }
1099
    
1100
646k
  else if (src.fPixelType == ttLong)
1101
0
    {
1102
    
1103
0
    switch (fPixelType)
1104
0
      {
1105
      
1106
0
      case ttByte:
1107
0
        {
1108
        
1109
0
        DoCopyArea8 (((const uint8 *) sPtr) + (qDNGBigEndian ? 3 : 0),
1110
0
               (uint8 *) dPtr,
1111
0
               rows,
1112
0
               cols,
1113
0
               planes,
1114
0
               sRowStep << 2,
1115
0
               sColStep << 2,
1116
0
               sPlaneStep << 2,
1117
0
               dRowStep,
1118
0
               dColStep,
1119
0
               dPlaneStep);
1120
            
1121
0
        break;
1122
        
1123
0
        }
1124
1125
0
      case ttShort:
1126
0
        {
1127
        
1128
0
        DoCopyArea16 (((const uint16 *) sPtr) + (qDNGBigEndian ? 1 : 0),
1129
0
                (uint16 *) dPtr,
1130
0
                rows,
1131
0
                cols,
1132
0
                planes,
1133
0
                sRowStep << 1,
1134
0
                sColStep << 1,
1135
0
                sPlaneStep << 1,
1136
0
                dRowStep,
1137
0
                dColStep,
1138
0
                dPlaneStep);
1139
        
1140
0
        break;
1141
        
1142
0
        }
1143
        
1144
0
      default:
1145
0
        {
1146
        
1147
0
        ThrowNotYetImplemented ();
1148
        
1149
0
        }
1150
        
1151
0
      }
1152
      
1153
0
    }
1154
    
1155
646k
  else if (src.fPixelType == ttFloat)
1156
646k
    {
1157
    
1158
646k
    switch (fPixelType)
1159
646k
      {
1160
      
1161
608k
      case ttByte:
1162
608k
        {
1163
        
1164
608k
        DoCopyAreaR32_8 ((const real32 *) sPtr,
1165
608k
                   (uint8 *) dPtr,
1166
608k
                   rows,
1167
608k
                   cols,
1168
608k
                   planes,
1169
608k
                   sRowStep,
1170
608k
                   sColStep,
1171
608k
                   sPlaneStep,
1172
608k
                   dRowStep,
1173
608k
                   dColStep,
1174
608k
                   dPlaneStep,
1175
608k
                 PixelRange ());
1176
            
1177
608k
        break;
1178
        
1179
0
        }
1180
1181
38.0k
      case ttShort:
1182
38.0k
        {
1183
        
1184
38.0k
        DoCopyAreaR32_16 ((const real32 *) sPtr,
1185
38.0k
                    (uint16 *) dPtr,
1186
38.0k
                    rows,
1187
38.0k
                    cols,
1188
38.0k
                    planes,
1189
38.0k
                    sRowStep,
1190
38.0k
                    sColStep,
1191
38.0k
                    sPlaneStep,
1192
38.0k
                    dRowStep,
1193
38.0k
                    dColStep,
1194
38.0k
                    dPlaneStep,
1195
38.0k
                  PixelRange ());
1196
        
1197
38.0k
        break;
1198
        
1199
0
        }
1200
        
1201
0
      case ttSShort:
1202
0
        {
1203
        
1204
0
        DoCopyAreaR32_S16 ((const real32 *) sPtr,
1205
0
                     (int16 *) dPtr,
1206
0
                     rows,
1207
0
                     cols,
1208
0
                     planes,
1209
0
                     sRowStep,
1210
0
                     sColStep,
1211
0
                     sPlaneStep,
1212
0
                     dRowStep,
1213
0
                     dColStep,
1214
0
                     dPlaneStep,
1215
0
                   PixelRange ());
1216
        
1217
0
        break;
1218
        
1219
0
        }
1220
        
1221
0
      default:
1222
0
        {
1223
        
1224
0
        ThrowNotYetImplemented ();
1225
        
1226
0
        }
1227
        
1228
646k
      }
1229
    
1230
646k
    }
1231
    
1232
0
  else
1233
0
    {
1234
    
1235
0
    ThrowNotYetImplemented ();
1236
    
1237
0
    }
1238
    
1239
4.93M
  }
1240
    
1241
/*****************************************************************************/
1242
1243
dng_point dng_pixel_buffer::RepeatPhase (const dng_rect &srcArea,
1244
                         const dng_rect &dstArea)
1245
2.22M
  {
1246
  
1247
2.22M
  int32 repeatV = srcArea.H ();
1248
2.22M
  int32 repeatH = srcArea.W ();
1249
  
1250
2.22M
  int32 phaseV;
1251
2.22M
  int32 phaseH;
1252
  
1253
2.22M
  if (srcArea.t >= dstArea.t)
1254
1.34M
    {
1255
1.34M
    phaseV = (repeatV - ((srcArea.t - dstArea.t) % repeatV)) % repeatV;
1256
1.34M
    }
1257
877k
  else
1258
877k
    {
1259
877k
    phaseV = (dstArea.t - srcArea.t) % repeatV;
1260
877k
    }
1261
    
1262
2.22M
  if (srcArea.l >= dstArea.l)
1263
1.71M
    {
1264
1.71M
    phaseH = (repeatH - ((srcArea.l - dstArea.l) % repeatH)) % repeatH;
1265
1.71M
    }
1266
503k
  else
1267
503k
    {
1268
503k
    phaseH = (dstArea.l - srcArea.l) % repeatH;
1269
503k
    }
1270
    
1271
2.22M
  return dng_point (phaseV, phaseH);
1272
  
1273
2.22M
  }
1274
  
1275
/*****************************************************************************/
1276
1277
void dng_pixel_buffer::RepeatArea (const dng_rect &srcArea,
1278
                     const dng_rect &dstArea)
1279
2.22M
  {
1280
  
1281
2.22M
  dng_point repeat = srcArea.Size ();
1282
  
1283
2.22M
  dng_point phase = RepeatPhase (srcArea,
1284
2.22M
                   dstArea);
1285
      
1286
2.22M
  const void *sPtr = ConstPixel (srcArea.t,
1287
2.22M
                     srcArea.l,
1288
2.22M
                     fPlane);
1289
                     
1290
2.22M
  void *dPtr = DirtyPixel (dstArea.t,
1291
2.22M
               dstArea.l,
1292
2.22M
               fPlane);
1293
               
1294
2.22M
  uint32 rows = dstArea.H ();
1295
2.22M
  uint32 cols = dstArea.W ();
1296
    
1297
2.22M
  switch (fPixelSize)
1298
2.22M
    {
1299
      
1300
0
    case 1:
1301
0
      {
1302
      
1303
0
      DoRepeatArea8 ((const uint8 *) sPtr,
1304
0
               (uint8 *) dPtr,
1305
0
               rows,
1306
0
               cols,
1307
0
               fPlanes,
1308
0
               fRowStep,
1309
0
               fColStep,
1310
0
               fPlaneStep,
1311
0
               repeat.v,
1312
0
               repeat.h,
1313
0
               phase.v,
1314
0
               phase.h);
1315
      
1316
0
      break;
1317
      
1318
0
      }
1319
      
1320
1.40M
    case 2:
1321
1.40M
      {
1322
      
1323
1.40M
      DoRepeatArea16 ((const uint16 *) sPtr,
1324
1.40M
                (uint16 *) dPtr,
1325
1.40M
                rows,
1326
1.40M
                cols,
1327
1.40M
                fPlanes,
1328
1.40M
                fRowStep,
1329
1.40M
                fColStep,
1330
1.40M
                fPlaneStep,
1331
1.40M
                repeat.v,
1332
1.40M
                repeat.h,
1333
1.40M
                phase.v,
1334
1.40M
                phase.h);
1335
      
1336
1.40M
      break;
1337
      
1338
0
      }
1339
        
1340
819k
    case 4:
1341
819k
      {
1342
      
1343
819k
      DoRepeatArea32 ((const uint32 *) sPtr,
1344
819k
                (uint32 *) dPtr,
1345
819k
                rows,
1346
819k
                cols,
1347
819k
                fPlanes,
1348
819k
                fRowStep,
1349
819k
                fColStep,
1350
819k
                fPlaneStep,
1351
819k
                repeat.v,
1352
819k
                repeat.h,
1353
819k
                phase.v,
1354
819k
                phase.h);
1355
      
1356
819k
      break;
1357
      
1358
0
      }
1359
      
1360
0
    default:
1361
0
      {
1362
      
1363
0
      ThrowNotYetImplemented ();
1364
      
1365
0
      }
1366
      
1367
2.22M
    }
1368
        
1369
2.22M
  }
1370
1371
/*****************************************************************************/
1372
1373
void dng_pixel_buffer::RepeatSubArea (const dng_rect subArea,
1374
                    uint32 repeatV,
1375
                    uint32 repeatH)
1376
0
  {
1377
  
1378
0
  if (fArea.t < subArea.t)
1379
0
    {
1380
    
1381
0
    RepeatArea (dng_rect (subArea.t          , fArea.l,
1382
0
                subArea.t + repeatV, fArea.r),
1383
0
          dng_rect (fArea.t            , fArea.l,
1384
0
                subArea.t          , fArea.r));
1385
                
1386
0
    }
1387
  
1388
0
  if (fArea.b > subArea.b)
1389
0
    {
1390
    
1391
0
    RepeatArea (dng_rect (subArea.b - repeatV, fArea.l,
1392
0
                subArea.b          , fArea.r),
1393
0
          dng_rect (subArea.b          , fArea.l,
1394
0
                fArea.b            , fArea.r));
1395
                
1396
0
    }
1397
    
1398
0
  if (fArea.l < subArea.l)
1399
0
    {
1400
    
1401
0
    RepeatArea (dng_rect (fArea.t, subArea.l          ,
1402
0
                fArea.b, subArea.l + repeatH),
1403
0
          dng_rect (fArea.t, fArea.l            ,
1404
0
                fArea.b, subArea.l          ));
1405
1406
0
    }
1407
  
1408
0
  if (fArea.r > subArea.r)
1409
0
    {
1410
    
1411
0
    RepeatArea (dng_rect (fArea.t, subArea.r - repeatH,
1412
0
                fArea.b, subArea.r          ),
1413
0
          dng_rect (fArea.t, subArea.r          ,
1414
0
                fArea.b, fArea.r            ));
1415
1416
0
    }
1417
  
1418
0
  }
1419
1420
/*****************************************************************************/
1421
1422
void dng_pixel_buffer::ShiftRight (uint32 shift)
1423
0
  {
1424
  
1425
0
  if (fPixelType != ttShort)
1426
0
    {
1427
    
1428
0
    ThrowNotYetImplemented ();
1429
    
1430
0
    }
1431
  
1432
0
  uint32 rows = fArea.H ();
1433
0
  uint32 cols = fArea.W ();
1434
  
1435
0
  uint32 planes = fPlanes;
1436
  
1437
0
  void *dPtr = DirtyPixel (fArea.t,
1438
0
               fArea.l,
1439
0
               fPlane);
1440
  
1441
0
  const void *sPtr = dPtr;
1442
  
1443
0
  int32 sRowStep   = fRowStep;
1444
0
  int32 sColStep   = fColStep;
1445
0
  int32 sPlaneStep = fPlaneStep;
1446
  
1447
0
  int32 dRowStep   = fRowStep;
1448
0
  int32 dColStep   = fColStep;
1449
0
  int32 dPlaneStep = fPlaneStep;
1450
  
1451
0
  OptimizeOrder (sPtr,
1452
0
           dPtr,
1453
0
           fPixelSize,
1454
0
           fPixelSize,
1455
0
           rows,
1456
0
           cols,
1457
0
           planes,
1458
0
           sRowStep,
1459
0
           sColStep,
1460
0
           sPlaneStep,
1461
0
           dRowStep,
1462
0
           dColStep,
1463
0
           dPlaneStep);
1464
           
1465
0
  DoShiftRight16 ((uint16 *) dPtr,
1466
0
            rows,
1467
0
            cols,
1468
0
            planes,
1469
0
            dRowStep,
1470
0
            dColStep,
1471
0
            dPlaneStep,
1472
0
            shift);
1473
  
1474
0
  }
1475
    
1476
/*****************************************************************************/
1477
1478
void dng_pixel_buffer::FlipH ()
1479
0
  {
1480
1481
0
  fData = InternalPixel (fArea.t, fArea.r - 1);
1482
1483
0
  fColStep = -fColStep;
1484
1485
0
  }
1486
1487
/*****************************************************************************/
1488
1489
void dng_pixel_buffer::FlipV ()
1490
0
  {
1491
  
1492
0
  fData = InternalPixel (fArea.b - 1, fArea.l);
1493
1494
0
  fRowStep = -fRowStep;
1495
1496
0
  }
1497
1498
/*****************************************************************************/
1499
1500
void dng_pixel_buffer::FlipZ ()
1501
0
  {
1502
1503
0
  fData = InternalPixel (fArea.t, fArea.l, fPlanes - 1);
1504
1505
0
  fPlaneStep = -fPlaneStep;
1506
1507
0
  }
1508
1509
/*****************************************************************************/
1510
1511
bool dng_pixel_buffer::EqualArea (const dng_pixel_buffer &src,
1512
                  const dng_rect &area,
1513
                  uint32 plane,
1514
                  uint32 planes) const
1515
0
  {
1516
  
1517
0
  uint32 rows = area.H ();
1518
0
  uint32 cols = area.W ();
1519
  
1520
0
  const void *sPtr = src.ConstPixel (area.t,
1521
0
                       area.l,
1522
0
                       plane);
1523
                  
1524
0
  const void *dPtr = ConstPixel (area.t,
1525
0
                   area.l,
1526
0
                   plane);
1527
  
1528
0
  int32 sRowStep   = src.fRowStep;
1529
0
  int32 sColStep   = src.fColStep;
1530
0
  int32 sPlaneStep = src.fPlaneStep;
1531
  
1532
0
  int32 dRowStep   = fRowStep;
1533
0
  int32 dColStep   = fColStep;
1534
0
  int32 dPlaneStep = fPlaneStep;
1535
1536
0
  if (fPixelType == src.fPixelType)
1537
0
    {
1538
    
1539
0
    if (rows == 1 && cols == 1 && sPlaneStep == 1 && dPlaneStep == 1)
1540
0
      {
1541
      
1542
0
      return DoEqualBytes (sPtr,
1543
0
                 dPtr, 
1544
0
                 planes * fPixelSize);
1545
      
1546
0
      }
1547
      
1548
0
    else switch (fPixelSize)
1549
0
      {
1550
      
1551
0
      case 1:
1552
0
        {
1553
        
1554
0
        return DoEqualArea8 ((const uint8 *) sPtr,
1555
0
                   (const uint8 *) dPtr,
1556
0
                   rows,
1557
0
                   cols,
1558
0
                   planes,
1559
0
                   sRowStep,
1560
0
                   sColStep,
1561
0
                   sPlaneStep,
1562
0
                   dRowStep,
1563
0
                   dColStep,
1564
0
                   dPlaneStep);
1565
        
1566
0
        break;
1567
        
1568
0
        }
1569
        
1570
0
      case 2:
1571
0
        {
1572
        
1573
0
        return DoEqualArea16 ((const uint16 *) sPtr,
1574
0
                    (const uint16 *) dPtr,
1575
0
                    rows,
1576
0
                    cols,
1577
0
                    planes,
1578
0
                    sRowStep,
1579
0
                    sColStep,
1580
0
                    sPlaneStep,
1581
0
                    dRowStep,
1582
0
                    dColStep,
1583
0
                    dPlaneStep);
1584
1585
0
        break;
1586
        
1587
0
        }
1588
        
1589
0
      case 4:
1590
0
        {
1591
        
1592
0
        return DoEqualArea32 ((const uint32 *) sPtr,
1593
0
                    (const uint32 *) dPtr,
1594
0
                    rows,
1595
0
                    cols,
1596
0
                    planes,
1597
0
                    sRowStep,
1598
0
                    sColStep,
1599
0
                    sPlaneStep,
1600
0
                    dRowStep,
1601
0
                    dColStep,
1602
0
                    dPlaneStep);
1603
        
1604
0
        break;
1605
        
1606
0
        }
1607
        
1608
0
      default:
1609
0
        {
1610
        
1611
0
        ThrowNotYetImplemented ();
1612
1613
0
        return false;
1614
1615
0
        }
1616
        
1617
0
      }
1618
    
1619
0
    }
1620
    
1621
0
  else
1622
0
    return false;
1623
1624
0
  }
1625
1626
/*****************************************************************************/
1627
1628
namespace
1629
  {
1630
1631
  template <typename T>
1632
  real64 MaxDiff (const T *src1,
1633
          int32 s1RowStep,
1634
          int32 s1PlaneStep,
1635
          const T *src2,
1636
          int32 s2RowStep,
1637
          int32 s2PlaneStep,
1638
          uint32 rows,
1639
          uint32 cols,
1640
          uint32 planes)
1641
0
    {
1642
1643
0
    real64 result = 0.0;
1644
1645
0
    for (uint32 plane = 0; plane < planes; plane++)
1646
0
      {
1647
1648
0
      const T *src1Save = src1;
1649
0
      const T *src2Save = src2;
1650
1651
0
      for (uint32 row = 0; row < rows; row++)
1652
0
        {
1653
1654
0
        for (uint32 col = 0; col < cols; col++)
1655
0
          {
1656
0
          real64 diff = fabs ((real64)src1 [col] - src2 [col]);
1657
1658
0
          if (diff > result)
1659
0
            result = diff;
1660
1661
0
          }
1662
1663
0
        src1 += s1RowStep;
1664
0
        src2 += s2RowStep;
1665
1666
0
        }
1667
1668
0
      src1 = src1Save + s1PlaneStep;
1669
0
      src2 = src2Save + s2PlaneStep;
1670
1671
0
      }
1672
1673
0
    return result;
1674
1675
0
    }
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<unsigned char>(unsigned char const*, int, int, unsigned char const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<unsigned short>(unsigned short const*, int, int, unsigned short const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<unsigned int>(unsigned int const*, int, int, unsigned int const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<signed char>(signed char const*, int, int, signed char const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<short>(short const*, int, int, short const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<int>(int const*, int, int, int const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<float>(float const*, int, int, float const*, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<double>(double const*, int, int, double const*, int, int, unsigned int, unsigned int, unsigned int)
1676
1677
  template <typename T>
1678
  real64 MaxDiff (const T *src1,
1679
          int32 s1ColStep,
1680
          int32 s1RowStep,
1681
          int32 s1PlaneStep,
1682
          const T *src2,
1683
          int32 s2ColStep,
1684
          int32 s2RowStep,
1685
          int32 s2PlaneStep,
1686
          uint32 rows,
1687
          uint32 cols,
1688
          uint32 planes)
1689
0
    {
1690
1691
0
    if (s1ColStep == s2ColStep &&
1692
0
      s1ColStep == 1)
1693
0
      return MaxDiff (src1,
1694
0
              s1RowStep,
1695
0
              s1PlaneStep,
1696
0
              src2,
1697
0
              s2RowStep,
1698
0
              s2PlaneStep,
1699
0
              rows,
1700
0
              cols,
1701
0
              planes);
1702
1703
0
    real64 result = 0.0;
1704
1705
0
    for (uint32 plane = 0; plane < planes; plane++)
1706
0
      {
1707
1708
0
      const T *src1Save = src1;
1709
0
      const T *src2Save = src2;
1710
1711
0
      for (uint32 row = 0; row < rows; row++)
1712
0
        {
1713
1714
0
        for (uint32 col = 0; col < cols; col++)
1715
0
          {
1716
0
          real64 diff = fabs ((real64)src1 [col * s1ColStep] - src2 [col * s2ColStep]);
1717
1718
0
          if (diff > result)
1719
0
            result = diff;
1720
1721
0
          }
1722
1723
0
        src1 += s1RowStep;
1724
0
        src2 += s2RowStep;
1725
1726
0
        }
1727
1728
0
      src1 = src1Save + s1PlaneStep;
1729
0
      src2 = src2Save + s2PlaneStep;
1730
1731
0
      }
1732
1733
1734
0
    return result;
1735
1736
0
    }
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<unsigned char>(unsigned char const*, int, int, int, unsigned char const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<unsigned short>(unsigned short const*, int, int, int, unsigned short const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<unsigned int>(unsigned int const*, int, int, int, unsigned int const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<signed char>(signed char const*, int, int, int, signed char const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<short>(short const*, int, int, int, short const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<int>(int const*, int, int, int, int const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<float>(float const*, int, int, int, float const*, int, int, int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: dng_pixel_buffer.cpp:double (anonymous namespace)::MaxDiff<double>(double const*, int, int, int, double const*, int, int, int, unsigned int, unsigned int, unsigned int)
1737
  }
1738
1739
real64 dng_pixel_buffer::MaximumDifference (const dng_pixel_buffer &rhs,
1740
                      const dng_rect &area,
1741
                      uint32 plane,
1742
                      uint32 planes) const
1743
0
  {
1744
  
1745
0
  uint32 rows = area.H ();
1746
0
  uint32 cols = area.W ();
1747
  
1748
0
  const void *s1Ptr = rhs.ConstPixel (area.t,
1749
0
                        area.l,
1750
0
                        plane);
1751
                  
1752
0
  const void *s2Ptr = ConstPixel (area.t,
1753
0
                    area.l,
1754
0
                    plane);
1755
  
1756
0
  int32 s1RowStep   = rhs.fRowStep;
1757
0
  int32 s1ColStep   = rhs.fColStep;
1758
0
  int32 s1PlaneStep = rhs.fPlaneStep;
1759
  
1760
0
  int32 s2RowStep   = fRowStep;
1761
0
  int32 s2ColStep   = fColStep;
1762
0
  int32 s2PlaneStep = fPlaneStep;
1763
1764
0
  if (fPixelType == rhs.fPixelType)
1765
0
    {
1766
1767
0
    switch (fPixelType)
1768
0
      {
1769
1770
0
      case ttByte:
1771
0
        return MaxDiff ((const uint8 *)s1Ptr,
1772
0
                s1ColStep,
1773
0
                s1RowStep,
1774
0
                s1PlaneStep,
1775
0
                (const uint8 *)s2Ptr,
1776
0
                s2ColStep,
1777
0
                s2RowStep,
1778
0
                s2PlaneStep,
1779
0
                rows,
1780
0
                cols,
1781
0
                planes);
1782
1783
0
        break;
1784
1785
0
      case ttShort:
1786
0
        return MaxDiff ((const uint16 *)s1Ptr,
1787
0
                s1ColStep,
1788
0
                s1RowStep,
1789
0
                s1PlaneStep,
1790
0
                (const uint16 *)s2Ptr,
1791
0
                s2ColStep,
1792
0
                s2RowStep,
1793
0
                s2PlaneStep,
1794
0
                rows,
1795
0
                cols,
1796
0
                planes);
1797
1798
0
        break;
1799
1800
0
      case ttLong:
1801
0
        return MaxDiff ((const uint32 *)s1Ptr,
1802
0
                s1ColStep,
1803
0
                s1RowStep,
1804
0
                s1PlaneStep,
1805
0
                (const uint32 *)s2Ptr,
1806
0
                s2ColStep,
1807
0
                s2RowStep,
1808
0
                s2PlaneStep,
1809
0
                rows,
1810
0
                cols,
1811
0
                planes);
1812
1813
0
        break;
1814
1815
0
      case ttSByte:
1816
0
        return MaxDiff ((const int8 *)s1Ptr,
1817
0
                s1ColStep,
1818
0
                s1RowStep,
1819
0
                s1PlaneStep,
1820
0
                (const int8 *)s2Ptr,
1821
0
                s2ColStep,
1822
0
                s2RowStep,
1823
0
                s2PlaneStep,
1824
0
                rows,
1825
0
                cols,
1826
0
                planes);
1827
1828
0
        break;
1829
1830
0
      case ttSShort:
1831
0
        return MaxDiff ((const int16 *)s1Ptr,
1832
0
                s1ColStep,
1833
0
                s1RowStep,
1834
0
                s1PlaneStep,
1835
0
                (const int16 *)s2Ptr,
1836
0
                s2ColStep,
1837
0
                s2RowStep,
1838
0
                s2PlaneStep,
1839
0
                rows,
1840
0
                cols,
1841
0
                planes);
1842
1843
0
        break;
1844
1845
0
      case ttSLong:
1846
0
        return MaxDiff ((const int32 *)s1Ptr,
1847
0
                s1ColStep,
1848
0
                s1RowStep,
1849
0
                s1PlaneStep,
1850
0
                (const int32 *)s2Ptr,
1851
0
                s2ColStep,
1852
0
                s2RowStep,
1853
0
                s2PlaneStep,
1854
0
                rows,
1855
0
                cols,
1856
0
                planes);
1857
1858
0
        break;
1859
1860
0
      case ttFloat:
1861
0
        return MaxDiff ((const real32 *)s1Ptr,
1862
0
                s1ColStep,
1863
0
                s1RowStep,
1864
0
                s1PlaneStep,
1865
0
                (const real32 *)s2Ptr,
1866
0
                s2ColStep,
1867
0
                s2RowStep,
1868
0
                s2PlaneStep,
1869
0
                rows,
1870
0
                cols,
1871
0
                planes);
1872
1873
0
        break;
1874
1875
0
      case ttDouble:
1876
0
        return MaxDiff ((const real64 *)s1Ptr,
1877
0
                s1ColStep,
1878
0
                s1RowStep,
1879
0
                s1PlaneStep,
1880
0
                (const real64 *)s2Ptr,
1881
0
                s2ColStep,
1882
0
                s2RowStep,
1883
0
                s2PlaneStep,
1884
0
                rows,
1885
0
                cols,
1886
0
                planes);
1887
1888
0
        break;
1889
1890
1891
0
      default:
1892
0
        {
1893
        
1894
0
        ThrowNotYetImplemented ();
1895
1896
0
        return 0.0;
1897
1898
0
        }
1899
        
1900
0
      }
1901
    
1902
0
    }
1903
    
1904
0
  else
1905
0
    ThrowProgramError ("attempt to difference pixel buffers of different formats.");
1906
1907
0
  return 0.0;
1908
1909
0
  }
1910
1911
/*****************************************************************************/