Coverage Report

Created: 2026-09-04 07:10

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
2.98M
bool SafeUint32ToInt32Mult(uint32 arg1, uint32 arg2, int32 *result) {
31
2.98M
  uint32 uint32_result;
32
2.98M
  return SafeUint32Mult(arg1, arg2, &uint32_result) &&
33
2.98M
    ConvertUint32ToInt32(uint32_result, result);
34
2.98M
}
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
4.89M
  {
54
  
55
4.89M
  uint32 step0;
56
4.89M
  uint32 step1;
57
4.89M
  uint32 step2;
58
  
59
  // Optimize the order for the data that is most spread out.
60
                 
61
4.89M
  uint32 sRange = Abs_int32 (sStep0) * (count0 - 1) +
62
4.89M
          Abs_int32 (sStep1) * (count1 - 1) +
63
4.89M
          Abs_int32 (sStep2) * (count2 - 1);
64
                 
65
4.89M
  uint32 dRange = Abs_int32 (dStep0) * (count0 - 1) +
66
4.89M
          Abs_int32 (dStep1) * (count1 - 1) +
67
4.89M
          Abs_int32 (dStep2) * (count2 - 1);
68
                 
69
4.89M
  if (dRange >= sRange)
70
3.82M
    {           
71
  
72
3.82M
    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
3.82M
    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
3.82M
    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
3.82M
    step0 = (uint32) dStep0;
115
3.82M
    step1 = (uint32) dStep1;
116
3.82M
    step2 = (uint32) dStep2;
117
    
118
3.82M
    }
119
    
120
1.06M
  else
121
1.06M
    {           
122
  
123
1.06M
    if (sStep0 < 0)
124
3.12k
      {
125
      
126
3.12k
      sPtr = (const void *)
127
3.12k
           (((const uint8 *) sPtr) + (int32)(count0 - 1) * sStep0 * (int32)sPixelSize);
128
           
129
3.12k
      dPtr = (void *)
130
3.12k
           (((uint8 *) dPtr) + (int32)(count0 - 1) * dStep0 * (int32)dPixelSize);
131
           
132
3.12k
      sStep0 = -sStep0;
133
3.12k
      dStep0 = -dStep0;
134
      
135
3.12k
      }
136
    
137
1.06M
    if (sStep1 < 0)
138
1.09k
      {
139
      
140
1.09k
      sPtr = (const void *)
141
1.09k
           (((const uint8 *) sPtr) + (int32)(count1 - 1) * sStep1 * (int32)sPixelSize);
142
           
143
1.09k
      dPtr = (void *)
144
1.09k
           (((uint8 *) dPtr) + (int32)(count1 - 1) * dStep1 * (int32)dPixelSize);
145
           
146
1.09k
      sStep1 = -sStep1;
147
1.09k
      dStep1 = -dStep1;
148
      
149
1.09k
      }
150
    
151
1.06M
    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.06M
    step0 = (uint32) sStep0;
166
1.06M
    step1 = (uint32) sStep1;
167
1.06M
    step2 = (uint32) sStep2;
168
    
169
1.06M
    }
170
  
171
4.89M
  if (count0 == 1) step0 = 0xFFFFFFFF;
172
4.89M
  if (count1 == 1) step1 = 0xFFFFFFFF;
173
4.89M
  if (count2 == 1) step2 = 0xFFFFFFFF;
174
  
175
4.89M
  uint32 index0;
176
4.89M
  uint32 index1;
177
4.89M
  uint32 index2;
178
  
179
4.89M
  if (step0 >= step1)
180
4.28M
    {
181
    
182
4.28M
    if (step1 >= step2)
183
1.49M
      {
184
1.49M
      index0 = 0;
185
1.49M
      index1 = 1;
186
1.49M
      index2 = 2;
187
1.49M
      }
188
      
189
2.78M
    else if (step2 >= step0)
190
2.61M
      {
191
2.61M
      index0 = 2;
192
2.61M
      index1 = 0;
193
2.61M
      index2 = 1;
194
2.61M
      }
195
      
196
176k
    else
197
176k
      {
198
176k
      index0 = 0;
199
176k
      index1 = 2;
200
176k
      index2 = 1;
201
176k
      }
202
    
203
4.28M
    }
204
    
205
602k
  else
206
602k
    {
207
    
208
602k
    if (step0 >= step2)
209
86.5k
      {
210
86.5k
      index0 = 1;
211
86.5k
      index1 = 0;
212
86.5k
      index2 = 2;
213
86.5k
      }
214
      
215
516k
    else if (step2 >= step1)
216
511k
      {
217
511k
      index0 = 2;
218
511k
      index1 = 1;
219
511k
      index2 = 0;
220
511k
      }
221
      
222
5.20k
    else
223
5.20k
      {
224
5.20k
      index0 = 1;
225
5.20k
      index1 = 2;
226
5.20k
      index2 = 0;
227
5.20k
      }
228
    
229
602k
    }
230
    
231
4.89M
  uint32 count [3];
232
  
233
4.89M
  count [0] = count0;
234
4.89M
  count [1] = count1;
235
4.89M
  count [2] = count2;
236
  
237
4.89M
  count0 = count [index0];
238
4.89M
  count1 = count [index1];
239
4.89M
  count2 = count [index2];
240
  
241
4.89M
  int32 step [3];
242
  
243
4.89M
  step [0] = sStep0;
244
4.89M
  step [1] = sStep1;
245
4.89M
  step [2] = sStep2;
246
  
247
4.89M
  sStep0 = step [index0];
248
4.89M
  sStep1 = step [index1];
249
4.89M
  sStep2 = step [index2];
250
  
251
4.89M
  step [0] = dStep0;
252
4.89M
  step [1] = dStep1;
253
4.89M
  step [2] = dStep2;
254
  
255
4.89M
  dStep0 = step [index0];
256
4.89M
  dStep1 = step [index1];
257
4.89M
  dStep2 = step [index2];
258
  
259
4.89M
  if (sStep0 == ((int32) count1) * sStep1 &&
260
1.35M
    dStep0 == ((int32) count1) * dStep1)
261
1.02M
    {
262
1.02M
    count1 *= count0;
263
1.02M
    count0 = 1;
264
1.02M
    }
265
  
266
4.89M
  if (sStep1 == ((int32) count2) * sStep2 &&
267
2.51M
    dStep1 == ((int32) count2) * dStep2)
268
1.87M
    {
269
1.87M
    count2 *= count1;
270
1.87M
    count1 = 1;
271
1.87M
    }
272
  
273
4.89M
  }
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.74k
  {
286
  
287
7.74k
  void *dPtr = NULL;
288
  
289
7.74k
  int32 dStep0 = sStep0;
290
7.74k
  int32 dStep1 = sStep1;
291
7.74k
  int32 dStep2 = sStep2;
292
  
293
7.74k
  OptimizeOrder (sPtr,
294
7.74k
           dPtr,
295
7.74k
           sPixelSize,
296
7.74k
           sPixelSize,
297
7.74k
           count0,
298
7.74k
           count1,
299
7.74k
           count2,
300
7.74k
           sStep0,
301
7.74k
           sStep1,
302
7.74k
           sStep2,
303
7.74k
           dStep0,
304
7.74k
           dStep1,
305
7.74k
           dStep2);
306
  
307
7.74k
  }
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
176k
  {
320
  
321
176k
  const void *sPtr = NULL;
322
  
323
176k
  int32 sStep0 = dStep0;
324
176k
  int32 sStep1 = dStep1;
325
176k
  int32 sStep2 = dStep2;
326
  
327
176k
  OptimizeOrder (sPtr,
328
176k
           dPtr,
329
176k
           dPixelSize,
330
176k
           dPixelSize,
331
176k
           count0,
332
176k
           count1,
333
176k
           count2,
334
176k
           sStep0,
335
176k
           sStep1,
336
176k
           sStep2,
337
176k
           dStep0,
338
176k
           dStep1,
339
176k
           dStep2);
340
  
341
176k
  }
342
343
/*****************************************************************************/
344
345
dng_pixel_buffer::dng_pixel_buffer ()
346
347
5.18M
  : fArea       ()
348
5.18M
  , fPlane      (0)
349
5.18M
  , fPlanes     (1)
350
5.18M
  , fRowStep    (1)
351
5.18M
  , fColStep    (1)
352
5.18M
  , fPlaneStep  (1)
353
5.18M
  , fPixelType  (ttUndefined)
354
5.18M
  , fPixelSize  (0)
355
5.18M
  , fData       (NULL)
356
5.18M
  , fDirty      (true)
357
  
358
5.18M
  {
359
  
360
5.18M
  }
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
2.98M
  : fArea       (area)
372
2.98M
  , fPlane      (plane)
373
2.98M
  , fPlanes     (planes)
374
2.98M
  , fRowStep    (0)
375
2.98M
  , fColStep    (0)
376
2.98M
  , fPlaneStep  (0)
377
2.98M
  , fPixelType  (pixelType)
378
2.98M
  , fPixelSize  (TagTypeSize(pixelType))
379
2.98M
  , fData       (data)
380
2.98M
  , fDirty      (true)
381
  
382
2.98M
  {
383
  
384
2.98M
  const char *overflowMessage = "Arithmetic overflow in pixel buffer setup";
385
  
386
  // Initialize fRowStep, fColStep and fPlaneStep according to the desired
387
  // pixel layout.
388
2.98M
  switch (planarConfiguration)
389
2.98M
    {
390
512k
    case pcInterleaved:
391
512k
      fPlaneStep = 1;
392
512k
      if (!ConvertUint32ToInt32 (fPlanes, &fColStep) ||
393
512k
        !SafeUint32ToInt32Mult (fArea.W(), fPlanes, &fRowStep))
394
22
        {
395
22
        ThrowMemoryFull (overflowMessage);
396
22
        }
397
512k
      break;
398
227k
    case pcPlanar:
399
227k
      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
227k
      if (!ConvertUint32ToInt32 (fArea.W(), &fRowStep) ||
404
227k
        !SafeUint32ToInt32Mult (fArea.H(), fArea.W(), &fPlaneStep))
405
0
        {
406
0
        ThrowMemoryFull (overflowMessage);
407
0
        }
408
227k
      break;
409
1.74k
    case pcRowInterleaved:
410
2.24M
    case pcRowInterleavedAlign16:
411
2.24M
      {
412
2.24M
      fColStep = 1;
413
2.24M
      uint32 planeStepUint32;
414
2.24M
      if (planarConfiguration == pcRowInterleaved)
415
1.74k
        {
416
1.74k
        planeStepUint32 = fArea.W();
417
1.74k
        }
418
2.24M
      else
419
2.24M
        {
420
2.24M
        if (!RoundUpForPixelSize (fArea.W(), fPixelSize,
421
2.24M
                      &planeStepUint32))
422
0
          {
423
0
          ThrowMemoryFull (overflowMessage);
424
0
          }
425
2.24M
        }
426
2.24M
      if (!ConvertUint32ToInt32 (planeStepUint32, &fPlaneStep) ||
427
2.24M
        !SafeUint32ToInt32Mult (planeStepUint32, fPlanes, &fRowStep))
428
0
        {
429
0
        ThrowMemoryFull (overflowMessage);
430
0
        }
431
2.24M
      break;
432
1.74k
      }
433
0
    default:
434
0
      ThrowProgramError ("Invalid value for 'planarConfiguration'");
435
0
      break;
436
2.98M
    }
437
  
438
2.98M
  }
439
440
/*****************************************************************************/
441
442
dng_pixel_buffer::dng_pixel_buffer (const dng_pixel_buffer &buffer)
443
444
4.80M
  : fArea       (buffer.fArea)
445
4.80M
  , fPlane      (buffer.fPlane)
446
4.80M
  , fPlanes     (buffer.fPlanes)
447
4.80M
  , fRowStep    (buffer.fRowStep)
448
4.80M
  , fColStep    (buffer.fColStep)
449
4.80M
  , fPlaneStep  (buffer.fPlaneStep)
450
4.80M
  , fPixelType  (buffer.fPixelType)
451
4.80M
  , fPixelSize  (buffer.fPixelSize)
452
4.80M
  , fData       (buffer.fData)
453
4.80M
  , fDirty      (buffer.fDirty)
454
  
455
4.80M
  {
456
  
457
4.80M
  }
458
              
459
/*****************************************************************************/
460
461
dng_pixel_buffer & dng_pixel_buffer::operator= (const dng_pixel_buffer &buffer)
462
106k
  {
463
  
464
106k
  fArea       = buffer.fArea;
465
106k
  fPlane      = buffer.fPlane;
466
106k
  fPlanes     = buffer.fPlanes;
467
106k
  fRowStep    = buffer.fRowStep;
468
106k
  fColStep    = buffer.fColStep;
469
106k
  fPlaneStep  = buffer.fPlaneStep;
470
106k
  fPixelType  = buffer.fPixelType;
471
106k
  fPixelSize  = buffer.fPixelSize;
472
106k
  fPixelType  = buffer.fPixelType;
473
106k
  fData       = buffer.fData;
474
106k
  fDirty      = buffer.fDirty;
475
  
476
106k
  return *this;
477
  
478
106k
  }
479
480
/*****************************************************************************/
481
482
dng_pixel_buffer::~dng_pixel_buffer ()
483
12.9M
  {
484
  
485
12.9M
  }
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
871k
  {
509
  
510
871k
  switch (fPixelType)
511
871k
    {
512
    
513
520k
    case ttByte:
514
520k
    case ttSByte:
515
520k
      {
516
520k
      return 0x0FF;
517
520k
      }
518
      
519
351k
    case ttShort:
520
351k
    case ttSShort:
521
351k
      {
522
351k
      return 0x0FFFF;
523
351k
      }
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
871k
    }
535
  
536
0
  return 0;
537
  
538
871k
  }
539
              
540
/*****************************************************************************/
541
542
void dng_pixel_buffer::SetConstant (const dng_rect &area,
543
                  uint32 plane,
544
                  uint32 planes,
545
                  uint32 value)
546
176k
  {
547
  
548
176k
  uint32 rows = area.H ();
549
176k
  uint32 cols = area.W ();
550
  
551
176k
  void *dPtr = DirtyPixel (area.t,
552
176k
                 area.l,
553
176k
                 plane);
554
              
555
176k
  int32 dRowStep   = fRowStep;
556
176k
  int32 dColStep   = fColStep;
557
176k
  int32 dPlaneStep = fPlaneStep;
558
  
559
176k
  OptimizeOrder (dPtr,
560
176k
           fPixelSize,
561
176k
           rows,
562
176k
           cols,
563
176k
           planes,
564
176k
           dRowStep,
565
176k
           dColStep,
566
176k
           dPlaneStep);
567
           
568
176k
  switch (fPixelSize)
569
176k
    {
570
    
571
22.4k
    case 1:
572
22.4k
      {
573
      
574
22.4k
      if (rows == 1 && cols == 1 && dPlaneStep == 1 && value == 0)
575
11.9k
        {
576
        
577
11.9k
        DoZeroBytes (dPtr, planes);
578
        
579
11.9k
        }
580
        
581
10.5k
      else
582
10.5k
        {
583
        
584
10.5k
        DoSetArea8 ((uint8 *) dPtr,
585
10.5k
              (uint8) value,
586
10.5k
              rows,
587
10.5k
              cols,
588
10.5k
              planes,
589
10.5k
              dRowStep,
590
10.5k
              dColStep,
591
10.5k
              dPlaneStep);
592
             
593
10.5k
        }
594
        
595
22.4k
      break;
596
      
597
0
      }
598
           
599
133k
    case 2:
600
133k
      {
601
      
602
133k
      if (rows == 1 && cols == 1 && dPlaneStep == 1 && value == 0)
603
106k
        {
604
        
605
106k
        DoZeroBytes (dPtr, planes << 1);
606
        
607
106k
        }
608
        
609
27.2k
      else
610
27.2k
        {
611
        
612
27.2k
        DoSetArea16 ((uint16 *) dPtr,
613
27.2k
               (uint16) value,
614
27.2k
               rows,
615
27.2k
               cols,
616
27.2k
               planes,
617
27.2k
               dRowStep,
618
27.2k
               dColStep,
619
27.2k
               dPlaneStep);
620
             
621
27.2k
        }
622
        
623
133k
      break;
624
      
625
0
      }
626
           
627
20.9k
    case 4:
628
20.9k
      {
629
      
630
20.9k
      if (rows == 1 && cols == 1 && dPlaneStep == 1 && value == 0)
631
9.99k
        {
632
        
633
9.99k
        DoZeroBytes (dPtr, planes << 2);
634
        
635
9.99k
        }
636
        
637
11.0k
      else
638
11.0k
        {
639
        
640
11.0k
        DoSetArea32 ((uint32 *) dPtr,
641
11.0k
               value,
642
11.0k
               rows,
643
11.0k
               cols,
644
11.0k
               planes,
645
11.0k
               dRowStep,
646
11.0k
               dColStep,
647
11.0k
               dPlaneStep);
648
             
649
11.0k
        }
650
        
651
20.9k
      break;
652
      
653
0
      }
654
      
655
0
    default:
656
0
      {
657
      
658
0
      ThrowNotYetImplemented ();
659
      
660
0
      }
661
      
662
176k
    }
663
           
664
176k
  }
665
    
666
/*****************************************************************************/
667
668
void dng_pixel_buffer::SetZero (const dng_rect &area,
669
                  uint32 plane,
670
                  uint32 planes)
671
176k
  {
672
             
673
176k
  uint32 value = 0;
674
           
675
176k
  switch (fPixelType)
676
176k
    {
677
    
678
22.4k
    case ttByte:
679
155k
    case ttShort:
680
157k
    case ttLong:
681
176k
    case ttFloat:
682
176k
      {
683
176k
      break;
684
157k
      }
685
      
686
0
    case ttSShort:
687
0
      {
688
0
      value = 0x8000;
689
0
      break;
690
157k
      }
691
692
0
    default:
693
0
      {
694
      
695
0
      ThrowNotYetImplemented ();
696
      
697
0
      }
698
      
699
176k
    }
700
    
701
176k
  SetConstant (area,
702
176k
         plane,
703
176k
         planes,
704
176k
         value);
705
           
706
176k
  }
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.68M
  {
716
  
717
4.68M
  uint32 rows = area.H ();
718
4.68M
  uint32 cols = area.W ();
719
  
720
4.68M
  const void *sPtr = src.ConstPixel (area.t,
721
4.68M
                       area.l,
722
4.68M
                       srcPlane);
723
                  
724
4.68M
  void *dPtr = DirtyPixel (area.t,
725
4.68M
                 area.l,
726
4.68M
                 dstPlane);
727
  
728
4.68M
  int32 sRowStep   = src.fRowStep;
729
4.68M
  int32 sColStep   = src.fColStep;
730
4.68M
  int32 sPlaneStep = src.fPlaneStep;
731
  
732
4.68M
  int32 dRowStep   = fRowStep;
733
4.68M
  int32 dColStep   = fColStep;
734
4.68M
  int32 dPlaneStep = fPlaneStep;
735
  
736
4.68M
  OptimizeOrder (sPtr,
737
4.68M
           dPtr,
738
4.68M
           src.fPixelSize,
739
4.68M
           fPixelSize,
740
4.68M
           rows,
741
4.68M
           cols,
742
4.68M
           planes,
743
4.68M
           sRowStep,
744
4.68M
           sColStep,
745
4.68M
           sPlaneStep,
746
4.68M
           dRowStep,
747
4.68M
           dColStep,
748
4.68M
           dPlaneStep);
749
           
750
4.68M
  if (fPixelType == src.fPixelType)
751
3.80M
    {
752
    
753
3.80M
    if (rows == 1 && cols == 1 && sPlaneStep == 1 && dPlaneStep == 1)
754
2.26M
      {
755
      
756
2.26M
      DoCopyBytes (sPtr,
757
2.26M
             dPtr, 
758
2.26M
             planes * fPixelSize);
759
      
760
2.26M
      }
761
      
762
1.53M
    else switch (fPixelSize)
763
1.53M
      {
764
      
765
36.5k
      case 1:
766
36.5k
        {
767
        
768
36.5k
        DoCopyArea8 ((const uint8 *) sPtr,
769
36.5k
               (uint8 *) dPtr,
770
36.5k
               rows,
771
36.5k
               cols,
772
36.5k
               planes,
773
36.5k
               sRowStep,
774
36.5k
               sColStep,
775
36.5k
               sPlaneStep,
776
36.5k
               dRowStep,
777
36.5k
               dColStep,
778
36.5k
               dPlaneStep);
779
        
780
36.5k
        break;
781
        
782
0
        }
783
        
784
841k
      case 2:
785
841k
        {
786
        
787
841k
        DoCopyArea16 ((const uint16 *) sPtr,
788
841k
                (uint16 *) dPtr,
789
841k
                rows,
790
841k
                cols,
791
841k
                planes,
792
841k
                sRowStep,
793
841k
                sColStep,
794
841k
                sPlaneStep,
795
841k
                dRowStep,
796
841k
                dColStep,
797
841k
                dPlaneStep);
798
        
799
841k
        break;
800
        
801
0
        }
802
        
803
658k
      case 4:
804
658k
        {
805
        
806
658k
        DoCopyArea32 ((const uint32 *) sPtr,
807
658k
                (uint32 *) dPtr,
808
658k
                rows,
809
658k
                cols,
810
658k
                planes,
811
658k
                sRowStep,
812
658k
                sColStep,
813
658k
                sPlaneStep,
814
658k
                dRowStep,
815
658k
                dColStep,
816
658k
                dPlaneStep);
817
        
818
658k
        break;
819
        
820
0
        }
821
        
822
0
      default:
823
0
        {
824
        
825
0
        ThrowNotYetImplemented ();
826
        
827
0
        }
828
        
829
1.53M
      }
830
    
831
3.80M
    }
832
    
833
883k
  else if (src.fPixelType == ttByte)
834
9.31k
    {
835
    
836
9.31k
    switch (fPixelType)
837
9.31k
      {
838
      
839
9.31k
      case ttShort:
840
9.31k
        {
841
        
842
9.31k
        DoCopyArea8_16 ((const uint8 *) sPtr,
843
9.31k
                  (uint16 *) dPtr,
844
9.31k
                  rows,
845
9.31k
                  cols,
846
9.31k
                  planes,
847
9.31k
                  sRowStep,
848
9.31k
                  sColStep,
849
9.31k
                  sPlaneStep,
850
9.31k
                  dRowStep,
851
9.31k
                  dColStep,
852
9.31k
                  dPlaneStep);
853
        
854
9.31k
        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
9.31k
      }
924
    
925
9.31k
    }
926
    
927
874k
  else if (src.fPixelType == ttShort)
928
316k
    {
929
    
930
316k
    switch (fPixelType)
931
316k
      {
932
      
933
3.05k
      case ttByte:
934
3.05k
        {
935
        
936
3.05k
        DoCopyArea8 (((const uint8 *) sPtr) + (qDNGBigEndian ? 1 : 0),
937
3.05k
               (uint8 *) dPtr,
938
3.05k
               rows,
939
3.05k
               cols,
940
3.05k
               planes,
941
3.05k
               sRowStep << 1,
942
3.05k
               sColStep << 1,
943
3.05k
               sPlaneStep << 1,
944
3.05k
               dRowStep,
945
3.05k
               dColStep,
946
3.05k
               dPlaneStep);
947
            
948
3.05k
        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
313k
      case ttFloat:
991
313k
        {
992
        
993
313k
        DoCopyArea16_R32 ((const uint16 *) sPtr,
994
313k
                    (real32 *) dPtr,
995
313k
                  rows,
996
313k
                    cols,
997
313k
                    planes,
998
313k
                    sRowStep,
999
313k
                    sColStep,
1000
313k
                    sPlaneStep,
1001
313k
                    dRowStep,
1002
313k
                    dColStep,
1003
313k
                    dPlaneStep,
1004
313k
                  src.PixelRange ());
1005
        
1006
313k
        break;
1007
        
1008
0
        }
1009
        
1010
0
      default:
1011
0
        {
1012
        
1013
0
        ThrowNotYetImplemented ();
1014
        
1015
0
        }
1016
        
1017
316k
      }
1018
      
1019
316k
    }
1020
    
1021
558k
  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
558k
  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
558k
  else if (src.fPixelType == ttFloat)
1156
558k
    {
1157
    
1158
558k
    switch (fPixelType)
1159
558k
      {
1160
      
1161
520k
      case ttByte:
1162
520k
        {
1163
        
1164
520k
        DoCopyAreaR32_8 ((const real32 *) sPtr,
1165
520k
                   (uint8 *) dPtr,
1166
520k
                   rows,
1167
520k
                   cols,
1168
520k
                   planes,
1169
520k
                   sRowStep,
1170
520k
                   sColStep,
1171
520k
                   sPlaneStep,
1172
520k
                   dRowStep,
1173
520k
                   dColStep,
1174
520k
                   dPlaneStep,
1175
520k
                 PixelRange ());
1176
            
1177
520k
        break;
1178
        
1179
0
        }
1180
1181
37.9k
      case ttShort:
1182
37.9k
        {
1183
        
1184
37.9k
        DoCopyAreaR32_16 ((const real32 *) sPtr,
1185
37.9k
                    (uint16 *) dPtr,
1186
37.9k
                    rows,
1187
37.9k
                    cols,
1188
37.9k
                    planes,
1189
37.9k
                    sRowStep,
1190
37.9k
                    sColStep,
1191
37.9k
                    sPlaneStep,
1192
37.9k
                    dRowStep,
1193
37.9k
                    dColStep,
1194
37.9k
                    dPlaneStep,
1195
37.9k
                  PixelRange ());
1196
        
1197
37.9k
        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
558k
      }
1229
    
1230
558k
    }
1231
    
1232
0
  else
1233
0
    {
1234
    
1235
0
    ThrowNotYetImplemented ();
1236
    
1237
0
    }
1238
    
1239
4.68M
  }
1240
    
1241
/*****************************************************************************/
1242
1243
dng_point dng_pixel_buffer::RepeatPhase (const dng_rect &srcArea,
1244
                         const dng_rect &dstArea)
1245
1.92M
  {
1246
  
1247
1.92M
  int32 repeatV = srcArea.H ();
1248
1.92M
  int32 repeatH = srcArea.W ();
1249
  
1250
1.92M
  int32 phaseV;
1251
1.92M
  int32 phaseH;
1252
  
1253
1.92M
  if (srcArea.t >= dstArea.t)
1254
1.19M
    {
1255
1.19M
    phaseV = (repeatV - ((srcArea.t - dstArea.t) % repeatV)) % repeatV;
1256
1.19M
    }
1257
737k
  else
1258
737k
    {
1259
737k
    phaseV = (dstArea.t - srcArea.t) % repeatV;
1260
737k
    }
1261
    
1262
1.92M
  if (srcArea.l >= dstArea.l)
1263
1.47M
    {
1264
1.47M
    phaseH = (repeatH - ((srcArea.l - dstArea.l) % repeatH)) % repeatH;
1265
1.47M
    }
1266
453k
  else
1267
453k
    {
1268
453k
    phaseH = (dstArea.l - srcArea.l) % repeatH;
1269
453k
    }
1270
    
1271
1.92M
  return dng_point (phaseV, phaseH);
1272
  
1273
1.92M
  }
1274
  
1275
/*****************************************************************************/
1276
1277
void dng_pixel_buffer::RepeatArea (const dng_rect &srcArea,
1278
                     const dng_rect &dstArea)
1279
1.92M
  {
1280
  
1281
1.92M
  dng_point repeat = srcArea.Size ();
1282
  
1283
1.92M
  dng_point phase = RepeatPhase (srcArea,
1284
1.92M
                   dstArea);
1285
      
1286
1.92M
  const void *sPtr = ConstPixel (srcArea.t,
1287
1.92M
                     srcArea.l,
1288
1.92M
                     fPlane);
1289
                     
1290
1.92M
  void *dPtr = DirtyPixel (dstArea.t,
1291
1.92M
               dstArea.l,
1292
1.92M
               fPlane);
1293
               
1294
1.92M
  uint32 rows = dstArea.H ();
1295
1.92M
  uint32 cols = dstArea.W ();
1296
    
1297
1.92M
  switch (fPixelSize)
1298
1.92M
    {
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.08M
    case 2:
1321
1.08M
      {
1322
      
1323
1.08M
      DoRepeatArea16 ((const uint16 *) sPtr,
1324
1.08M
                (uint16 *) dPtr,
1325
1.08M
                rows,
1326
1.08M
                cols,
1327
1.08M
                fPlanes,
1328
1.08M
                fRowStep,
1329
1.08M
                fColStep,
1330
1.08M
                fPlaneStep,
1331
1.08M
                repeat.v,
1332
1.08M
                repeat.h,
1333
1.08M
                phase.v,
1334
1.08M
                phase.h);
1335
      
1336
1.08M
      break;
1337
      
1338
0
      }
1339
        
1340
838k
    case 4:
1341
838k
      {
1342
      
1343
838k
      DoRepeatArea32 ((const uint32 *) sPtr,
1344
838k
                (uint32 *) dPtr,
1345
838k
                rows,
1346
838k
                cols,
1347
838k
                fPlanes,
1348
838k
                fRowStep,
1349
838k
                fColStep,
1350
838k
                fPlaneStep,
1351
838k
                repeat.v,
1352
838k
                repeat.h,
1353
838k
                phase.v,
1354
838k
                phase.h);
1355
      
1356
838k
      break;
1357
      
1358
0
      }
1359
      
1360
0
    default:
1361
0
      {
1362
      
1363
0
      ThrowNotYetImplemented ();
1364
      
1365
0
      }
1366
      
1367
1.92M
    }
1368
        
1369
1.92M
  }
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
/*****************************************************************************/