Coverage Report

Created: 2025-07-12 06:56

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