Coverage Report

Created: 2021-08-22 09:07

/src/skia/third_party/externals/dng_sdk/source/dng_negative.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************/
2
// Copyright 2006-2012 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_negative.h#4 $ */ 
10
/* $DateTime: 2012/08/02 06:09:06 $ */
11
/* $Change: 841096 $ */
12
/* $Author: erichan $ */
13
14
/** \file
15
 * Functions and classes for working with a digital negative (image data and
16
 * corresponding metadata).
17
 */
18
19
/*****************************************************************************/
20
21
#ifndef __dng_negative__
22
#define __dng_negative__
23
24
/*****************************************************************************/
25
26
#include "dng_1d_function.h"
27
#include "dng_auto_ptr.h"
28
#include "dng_classes.h"
29
#include "dng_fingerprint.h"
30
#include "dng_image.h"
31
#include "dng_linearization_info.h"
32
#include "dng_matrix.h"
33
#include "dng_memory.h"
34
#include "dng_mosaic_info.h"
35
#include "dng_opcode_list.h"
36
#include "dng_orientation.h"
37
#include "dng_rational.h"
38
#include "dng_sdk_limits.h"
39
#include "dng_string.h"
40
#include "dng_tag_types.h"
41
#include "dng_tag_values.h"
42
#include "dng_types.h"
43
#include "dng_utils.h"
44
#include "dng_xy_coord.h"
45
46
#include <vector>
47
48
/*****************************************************************************/
49
50
// To prevent using the internal metadata when we meant to use override
51
// metadata, the following definitions allow us to only allow access to
52
// the internal metadata on non-const negatives. This allows the old API
53
// to keep working essentially unchanged provided one does not use const
54
// negatives, but will prevent access to the embedded data on const
55
// negatives.
56
57
#if 1
58
59
#define qMetadataOnConst 0
60
#define METACONST
61
62
#else
63
64
#define qMetadataOnConst 1
65
#define METACONST const
66
67
#endif
68
69
/*****************************************************************************/
70
71
/// \brief Noise model for photon and sensor read noise, assuming that they are
72
/// independent random variables and spatially invariant.
73
///
74
/// The noise model is N (x) = sqrt (scale*x + offset), where x represents a linear
75
/// signal value in the range [0,1], and N (x) is the standard deviation (i.e.,
76
/// noise). The parameters scale and offset are both sensor-dependent and
77
/// ISO-dependent. scale must be positive, and offset must be non-negative.
78
79
class dng_noise_function: public dng_1d_function
80
  {
81
    
82
  protected:
83
84
    real64 fScale;
85
    real64 fOffset;
86
87
  public:
88
89
    /// Create empty and invalid noise function.
90
91
    dng_noise_function ()
92
93
      : fScale  (0.0)
94
      , fOffset (0.0)
95
96
0
      {
97
0
98
0
      }
99
100
    /// Create noise function with the specified scale and offset.
101
102
    dng_noise_function (real64 scale,
103
              real64 offset)
104
105
      : fScale  (scale)
106
      , fOffset (offset)
107
108
1.02k
      {
109
110
1.02k
      }
111
112
    /// Compute noise (standard deviation) at the specified average signal level
113
    /// x.
114
115
    virtual real64 Evaluate (real64 x) const
116
0
      {
117
0
      return sqrt (fScale * x + fOffset);
118
0
      }
119
120
    /// The scale (slope, gain) of the noise function.
121
122
    real64 Scale () const 
123
0
      { 
124
0
      return fScale; 
125
0
      }
126
127
    /// The offset (square of the noise floor) of the noise function.
128
129
    real64 Offset () const 
130
0
      { 
131
0
      return fOffset; 
132
0
      }
133
134
    /// Set the scale (slope, gain) of the noise function.
135
136
    void SetScale (real64 scale)
137
0
      {
138
0
      fScale = scale;
139
0
      }
140
141
    /// Set the offset (square of the noise floor) of the noise function.
142
143
    void SetOffset (real64 offset)
144
0
      {
145
0
      fOffset = offset;
146
0
      }
147
148
    /// Is the noise function valid?
149
150
    bool IsValid () const
151
48
      {
152
48
      return (fScale > 0.0 && fOffset >= 0.0);
153
48
      }
154
    
155
  };
156
157
/*****************************************************************************/
158
159
/// \brief Noise profile for a negative.
160
///
161
/// For mosaiced negatives, the noise profile describes the approximate noise
162
/// characteristics of a mosaic negative after linearization, but prior to
163
/// demosaicing. For demosaiced negatives (i.e., linear DNGs), the noise profile
164
/// describes the approximate noise characteristics of the image data immediately
165
/// following the demosaic step, prior to the processing of opcode list 3.
166
///
167
/// A noise profile may contain 1 or N noise functions, where N is the number of
168
/// color planes for the negative. Otherwise the noise profile is considered to be
169
/// invalid for that negative. If the noise profile contains 1 noise function, then
170
/// it is assumed that this single noise function applies to all color planes of the
171
/// negative. Otherwise, the N noise functions map to the N planes of the negative in
172
/// order specified in the CFAPlaneColor tag.
173
174
class dng_noise_profile
175
  {
176
    
177
  protected:
178
179
    dng_std_vector<dng_noise_function> fNoiseFunctions;
180
181
  public:
182
183
    /// Create empty (invalid) noise profile.
184
185
    dng_noise_profile ();
186
187
    /// Create noise profile with the specified noise functions (1 per plane).
188
189
    explicit dng_noise_profile (const dng_std_vector<dng_noise_function> &functions);
190
191
    /// Is the noise profile valid?
192
193
    bool IsValid () const;
194
195
    /// Is the noise profile valid for the specified negative?
196
197
    bool IsValidForNegative (const dng_negative &negative) const;
198
199
    /// The noise function for the specified plane.
200
201
    const dng_noise_function & NoiseFunction (uint32 plane) const;
202
203
    /// The number of noise functions in this profile.
204
205
    uint32 NumFunctions () const;
206
    
207
  };
208
209
/*****************************************************************************/
210
211
/// \brief Main class for holding metadata.
212
213
class dng_metadata
214
  {
215
  
216
  private:
217
    
218
    // Base orientation of both the thumbnail and raw data. This is
219
    // generally based on the EXIF values.
220
    
221
    bool fHasBaseOrientation;
222
  
223
    dng_orientation fBaseOrientation;
224
    
225
    // Is the maker note safe to copy from file to file? Defaults to false
226
    // because many maker notes are not safe.
227
    
228
    bool fIsMakerNoteSafe;
229
    
230
    // MakerNote binary data block.
231
    
232
    AutoPtr<dng_memory_block> fMakerNote;
233
    
234
    // EXIF data.
235
    
236
    AutoPtr<dng_exif> fExif;
237
    
238
    // A copy of the EXIF data before is was synchronized with other metadata sources.
239
    
240
    AutoPtr<dng_exif> fOriginalExif;
241
    
242
    // IPTC binary data block and offset in original file.
243
    
244
    AutoPtr<dng_memory_block> fIPTCBlock;
245
    
246
    uint64 fIPTCOffset;
247
    
248
    // XMP data.
249
    
250
    #if qDNGUseXMP
251
    
252
    AutoPtr<dng_xmp> fXMP;
253
    
254
    #endif
255
    
256
    // If there a valid embedded XMP block, has is its digest?  NULL if no valid
257
    // embedded XMP.
258
    
259
    dng_fingerprint fEmbeddedXMPDigest;
260
    
261
    // Is the XMP data from a sidecar file?
262
    
263
    bool fXMPinSidecar;
264
    
265
    // If the XMP data is from a sidecar file, is the sidecar file newer
266
    // than the raw file?
267
    
268
    bool fXMPisNewer;
269
    
270
    // Source file mimi-type, if known.
271
    
272
    dng_string fSourceMIMI;
273
    
274
  public:
275
276
    dng_metadata (dng_host &host);
277
    
278
    dng_metadata (const dng_metadata &rhs,
279
            dng_memory_allocator &allocator);
280
    
281
    virtual ~dng_metadata ();
282
283
    /// Copy this metadata.
284
    
285
    virtual dng_metadata * Clone (dng_memory_allocator &allocator) const;
286
    
287
    /// Setter for BaseOrientation.
288
      
289
    void SetBaseOrientation (const dng_orientation &orientation);
290
    
291
    /// Has BaseOrientation been set?
292
293
    bool HasBaseOrientation () const
294
0
      {
295
0
      return fHasBaseOrientation;
296
0
      }
297
    
298
    /// Getter for BaseOrientation.
299
      
300
    const dng_orientation & BaseOrientation () const
301
0
      {
302
0
      return fBaseOrientation;
303
0
      }
304
      
305
    /// Logically rotates the image by changing the orientation values.
306
    /// This will also update the XMP data.
307
    
308
    void ApplyOrientation (const dng_orientation &orientation);
309
310
    // API for IPTC metadata:
311
      
312
    void SetIPTC (AutoPtr<dng_memory_block> &block,
313
            uint64 offset);
314
    
315
    void SetIPTC (AutoPtr<dng_memory_block> &block);
316
    
317
    void ClearIPTC ();
318
    
319
    const void * IPTCData () const;
320
    
321
    uint32 IPTCLength () const;
322
    
323
    uint64 IPTCOffset () const;
324
    
325
    dng_fingerprint IPTCDigest (bool includePadding = true) const;
326
    
327
    void RebuildIPTC (dng_memory_allocator &allocator,
328
              bool padForTIFF);
329
    
330
    // API for MakerNote data:
331
    
332
    void SetMakerNoteSafety (bool safe)
333
0
      {
334
0
      fIsMakerNoteSafe = safe;
335
0
      }
336
    
337
    bool IsMakerNoteSafe () const
338
0
      {
339
0
      return fIsMakerNoteSafe;
340
0
      }
341
    
342
    void SetMakerNote (AutoPtr<dng_memory_block> &block)
343
0
      {
344
0
      fMakerNote.Reset (block.Release ());
345
0
      }
346
    
347
    void ClearMakerNote ()
348
0
      {
349
0
      fIsMakerNoteSafe = false;
350
0
      fMakerNote.Reset ();
351
0
      }
352
    
353
    const void * MakerNoteData () const
354
0
      {
355
0
      return fMakerNote.Get () ? fMakerNote->Buffer ()
356
0
                   : NULL;
357
0
      }
358
    
359
    uint32 MakerNoteLength () const
360
0
      {
361
0
      return fMakerNote.Get () ? fMakerNote->LogicalSize ()
362
0
                   : 0;
363
0
      }
364
    
365
    // API for EXIF metadata:
366
    
367
    dng_exif * GetExif ()
368
0
      {
369
0
      return fExif.Get ();
370
0
      }
371
      
372
    const dng_exif * GetExif () const
373
0
      {
374
0
      return fExif.Get ();
375
0
      }
376
      
377
    template< class E >
378
    E & Exif ();
379
      
380
    template< class E >
381
    const E & Exif () const;
382
          
383
    void ResetExif (dng_exif * newExif);
384
      
385
    dng_memory_block * BuildExifBlock (dng_memory_allocator &allocator,
386
                       const dng_resolution *resolution = NULL,
387
                       bool includeIPTC = false,
388
                       const dng_jpeg_preview *thumbnail = NULL) const;
389
                           
390
    // API for original EXIF metadata.
391
    
392
    dng_exif * GetOriginalExif ()
393
0
      {
394
0
      return fOriginalExif.Get ();
395
0
      }
396
      
397
    const dng_exif * GetOriginalExif () const
398
0
      {
399
0
      return fOriginalExif.Get ();
400
0
      }
401
      
402
    // API for XMP metadata:
403
    
404
    #if qDNGUseXMP
405
    
406
    bool SetXMP (dng_host &host,
407
           const void *buffer,
408
           uint32 count,
409
           bool xmpInSidecar = false,
410
           bool xmpIsNewer = false);
411
           
412
    void SetEmbeddedXMP (dng_host &host,
413
               const void *buffer,
414
               uint32 count);
415
           
416
    dng_xmp * GetXMP ()
417
      {
418
      return fXMP.Get ();
419
      }
420
      
421
    const dng_xmp * GetXMP () const
422
      {
423
      return fXMP.Get ();
424
      }
425
426
    template< class X >
427
    X & XMP ();
428
429
    template< class X >
430
    const X & XMP () const;
431
432
    bool XMPinSidecar () const
433
      {
434
      return fXMPinSidecar;
435
      }
436
      
437
    const dng_fingerprint & EmbeddedXMPDigest () const
438
      {
439
      return fEmbeddedXMPDigest;
440
      }
441
            
442
    bool HaveValidEmbeddedXMP () const
443
      {
444
      return fEmbeddedXMPDigest.IsValid ();
445
      }
446
    
447
    void ResetXMP (dng_xmp * newXMP);
448
  
449
    void ResetXMPSidecarNewer (dng_xmp * newXMP, bool inSidecar, bool isNewer );
450
      
451
    #endif
452
    
453
    // Synchronize metadata sources.
454
    
455
    void SynchronizeMetadata ();
456
    
457
    // Routines to update the date/time field in the EXIF and XMP
458
    // metadata.
459
    
460
    void UpdateDateTime (const dng_date_time_info &dt);
461
               
462
    void UpdateDateTimeToNow ();
463
    
464
    void UpdateMetadataDateTimeToNow ();
465
    
466
    // Routines to set and get the source file MIMI type.
467
    
468
    void SetSourceMIMI (const char *s)
469
0
      {
470
0
      fSourceMIMI.Set (s);
471
0
      }
472
      
473
    const dng_string & SourceMIMI () const
474
0
      {
475
0
      return fSourceMIMI;
476
0
      }
477
      
478
  };
479
480
/*****************************************************************************/
481
482
template< class E >
483
E & dng_metadata::Exif ()
484
  {
485
  dng_exif * exif = GetExif ();
486
  if (!exif) ThrowProgramError ("EXIF object is NULL.");
487
  return dynamic_cast< E & > (*exif);
488
  }
489
490
/*****************************************************************************/
491
492
template< class E >
493
const E & dng_metadata::Exif () const
494
  {
495
  const dng_exif * exif = GetExif ();
496
  if (!exif) ThrowProgramError ("EXIF object is NULL.");
497
  return dynamic_cast< const E & > (*exif);
498
  }
499
500
/*****************************************************************************/
501
502
#if qDNGUseXMP
503
504
template< class X >
505
X & dng_metadata::XMP ()
506
  {
507
  dng_xmp * xmp = GetXMP ();
508
  if (!xmp) ThrowProgramError ("XMP object is NULL.");
509
  return dynamic_cast< X & > (*xmp);
510
  }
511
512
/*****************************************************************************/
513
514
template< class X >
515
const X & dng_metadata::XMP () const
516
  {
517
  const dng_xmp * xmp = GetXMP ();
518
  if (!xmp) ThrowProgramError ("XMP object is NULL.");
519
  return dynamic_cast< const X & > (*xmp);
520
  }
521
522
#endif
523
524
/*****************************************************************************/
525
526
/// \brief Main class for holding DNG image data and associated metadata.
527
528
class dng_negative
529
  {
530
  
531
  public:
532
  
533
    enum RawImageStageEnum
534
      {
535
      rawImageStagePreOpcode1,
536
      rawImageStagePostOpcode1,
537
      rawImageStagePostOpcode2,
538
      rawImageStagePreOpcode3,
539
      rawImageStagePostOpcode3,
540
      rawImageStageNone
541
      };
542
      
543
  protected:
544
  
545
    // The negative stores an associated allocator. It does not do
546
    // anything to keep it alive or to release it when the object destructs.
547
    // Hence, clients will need to make sure that the allocator's lifespan
548
    // encompasses that of the dng_factory object which is generally
549
    // directly bound to the dng_negative object.
550
  
551
    dng_memory_allocator &fAllocator;
552
      
553
    // Non-localized ASCII model name.
554
    
555
    dng_string fModelName;
556
    
557
    // Localized UTF-8 model name.
558
    
559
    dng_string fLocalName;
560
    
561
    // The area of raw image that should be included in the final converted
562
    // image. This stems from extra pixels around the edges of the sensor
563
    // including both the black mask and some additional padding.
564
    
565
    // The default crop can be smaller than the "active" area which includes
566
    // the padding but not the black masked pixels.
567
    
568
    dng_urational fDefaultCropSizeH;
569
    dng_urational fDefaultCropSizeV;
570
    
571
    dng_urational fDefaultCropOriginH;
572
    dng_urational fDefaultCropOriginV;
573
574
    // Default user crop, in relative coordinates.
575
576
    dng_urational fDefaultUserCropT;
577
    dng_urational fDefaultUserCropL;
578
    dng_urational fDefaultUserCropB;
579
    dng_urational fDefaultUserCropR;
580
    
581
    // Default scale factors. Generally, 1.0 for square pixel cameras. They
582
    // can compensate for non-square pixels. The choice of exact values will
583
    // generally depend on what the camera does. These are particularly
584
    // interesting for the Nikon D1X and the Fuji diamond mosaic.
585
    
586
    dng_urational fDefaultScaleH;
587
    dng_urational fDefaultScaleV;
588
    
589
    // Best quality scale factor. Used for the Nikon D1X and Fuji cameras
590
    // to force everything to be a scale up rather than scale down. So,
591
    // generally this is 1.0 / min (fDefaultScaleH, fDefaultScaleV) but
592
    // this isn't used if the scale factors are only slightly different
593
    // from 1.0.
594
    
595
    dng_urational fBestQualityScale;
596
    
597
    // Proxy image support.  Remember certain sizes for the original image
598
    // this proxy was derived from.
599
        
600
    dng_point fOriginalDefaultFinalSize;
601
    dng_point fOriginalBestQualityFinalSize;
602
    
603
    dng_urational fOriginalDefaultCropSizeH;
604
    dng_urational fOriginalDefaultCropSizeV;
605
    
606
    // Scale factors used in demosaic algorithm (calculated).
607
    // Maps raw image coordinates to full image coordinates -- i.e.,
608
    // original image coordinates on raw sensor data to coordinates
609
    // in fStage3Image which is the output of the interpolation step.
610
    // So, if we downsample when interpolating, these numbers get
611
    // smaller.
612
    
613
    real64 fRawToFullScaleH;
614
    real64 fRawToFullScaleV;
615
    
616
    // Relative amount of noise at ISO 100. This is measured per camera model
617
    // based on looking at flat areas of color.
618
    
619
    dng_urational fBaselineNoise;
620
    
621
    // How much noise reduction has already been applied (0.0 to 1.0) to the
622
    // the raw image data?  0.0 = none, 1.0 = "ideal" amount--i.e. don't apply any
623
    // more by default.  0/0 for unknown.
624
    
625
    dng_urational fNoiseReductionApplied;
626
627
    // Amount of noise for this negative (see dng_noise_profile for details).
628
629
    dng_noise_profile fNoiseProfile;
630
    
631
    // Zero point for the exposure compensation slider. This reflects how
632
    // the manufacturer sets up the camera and its conversions.
633
    
634
    dng_srational fBaselineExposure;
635
    
636
    // Relative amount of sharpening required. This is chosen per camera
637
    // model based on how strong the anti-alias filter is on the camera
638
    // and the quality of the lenses. This scales the sharpness slider
639
    // value.
640
  
641
    dng_urational fBaselineSharpness;
642
    
643
    // Chroma blur radius (or 0/0 for auto). Set to 0/1 to disable
644
    // chroma blurring.
645
    
646
    dng_urational fChromaBlurRadius;
647
    
648
    // Anti-alias filter strength (0.0 to 1.0).  Used as a hint
649
    // to the demosaic algorithms.
650
    
651
    dng_urational fAntiAliasStrength;
652
    
653
    // Linear response limit. The point at which the sensor goes
654
    // non-linear and color information becomes unreliable. Used in
655
    // the highlight-recovery logic.
656
    
657
    dng_urational fLinearResponseLimit;
658
    
659
    // Scale factor for shadows slider. The Fuji HDR cameras, for example,
660
    // need a more sensitive shadow slider.
661
    
662
    dng_urational fShadowScale;
663
    
664
    // Colormetric reference.
665
    
666
    uint32 fColorimetricReference;
667
    
668
    // Number of color channels for this image (e.g. 1, 3, or 4).
669
    
670
    uint32 fColorChannels;
671
    
672
    // Amount by which each channel has already been scaled. Some cameras
673
    // have analog amplifiers on the color channels and these can result
674
    // in different scalings per channel. This provides some level of
675
    // analog white balancing. The Nikon D1 also did digital scaling but
676
    // this caused problems with highlight recovery. 
677
    
678
    dng_vector fAnalogBalance;
679
    
680
    // The "As Shot" neutral color coordinates in native camera space.
681
    // This overrides fCameraWhiteXY if both are specified. This
682
    // specifies the values per channel that would result in a neutral
683
    // color for the "As Shot" case. This is generally supplied by
684
    // the camera.
685
    
686
    dng_vector fCameraNeutral;
687
    
688
    // The "As Shot" white balance xy coordinates. Sometimes this is
689
    // supplied by the camera. Sometimes the camera just supplies a name
690
    // for the white balance.
691
    
692
    dng_xy_coord fCameraWhiteXY;
693
    
694
    // Individual camera calibrations.
695
    
696
    // Camera data --> camera calibration --> "inverse" of color matrix
697
    
698
    // This will be a 4x4 matrix for a 4-color camera. The defaults are
699
    // almost always the identity matrix and for the cases where they
700
    // aren't, they are diagonal matrices.
701
    
702
    dng_matrix fCameraCalibration1;
703
    dng_matrix fCameraCalibration2;
704
    
705
    // Signature which allows a profile to announce that it is compatible
706
    // with these calibration matrices.
707
708
    dng_string fCameraCalibrationSignature;
709
    
710
    // List of camera profiles.
711
    
712
    dng_std_vector<dng_camera_profile *> fCameraProfile;
713
    
714
    // "As shot" camera profile name.
715
    
716
    dng_string fAsShotProfileName;
717
    
718
    // Raw image data digests. These are MD5 fingerprints of the raw image data
719
    // in the file, computed using a specific algorithms.  They can be used
720
    // verify the raw data has not been corrupted.  The new version is faster
721
    // to compute on MP machines, and is used starting with DNG version 1.4. 
722
    
723
    mutable dng_fingerprint fRawImageDigest;
724
    
725
    mutable dng_fingerprint fNewRawImageDigest;
726
727
    // Raw data unique ID.  This is an unique identifer for the actual
728
    // raw image data in the file.  It can be used to index into caches
729
    // for this data.
730
    
731
    mutable dng_fingerprint fRawDataUniqueID;
732
    
733
    // Original raw file name.  Just the file name, not the full path.
734
    
735
    dng_string fOriginalRawFileName;
736
    
737
    // Is the original raw file data availaible?
738
    
739
    bool fHasOriginalRawFileData;
740
    
741
    // The compressed original raw file data.
742
    
743
    AutoPtr<dng_memory_block> fOriginalRawFileData;
744
    
745
    // MD5 digest of original raw file data block.
746
    
747
    mutable dng_fingerprint fOriginalRawFileDigest;
748
    
749
    // DNG private data block.
750
    
751
    AutoPtr<dng_memory_block> fDNGPrivateData;
752
    
753
    // Metadata information (XMP, IPTC, EXIF, orientation)
754
  
755
    dng_metadata fMetadata;
756
    
757
    // Information required to linearize and range map the raw data.
758
    
759
    AutoPtr<dng_linearization_info> fLinearizationInfo;
760
    
761
    // Information required to demoasic the raw data.
762
    
763
    AutoPtr<dng_mosaic_info> fMosaicInfo;
764
    
765
    // Opcode list 1. (Applied to stored data)
766
    
767
    dng_opcode_list fOpcodeList1;
768
    
769
    // Opcode list 2. (Applied to range mapped data)
770
    
771
    dng_opcode_list fOpcodeList2;
772
    
773
    // Opcode list 3. (Post demosaic)
774
    
775
    dng_opcode_list fOpcodeList3;
776
    
777
    // Stage 1 image, which is image data stored in a DNG file.
778
    
779
    AutoPtr<dng_image> fStage1Image;
780
    
781
    // Stage 2 image, which is the stage 1 image after it has been
782
    // linearized and range mapped.
783
    
784
    AutoPtr<dng_image> fStage2Image;
785
    
786
    // Stage 3 image, which is the stage 2 image after it has been
787
    // demosaiced.
788
    
789
    AutoPtr<dng_image> fStage3Image;
790
    
791
    // Additiona gain applied when building the stage 3 image. 
792
    
793
    real64 fStage3Gain;
794
795
    // Were any approximations (e.g. downsampling, etc.) applied
796
    // file reading this image?
797
    
798
    bool fIsPreview;
799
    
800
    // Does the file appear to be damaged?
801
    
802
    bool fIsDamaged;
803
    
804
    // At what processing stage did we grab a copy of raw image data?
805
    
806
    RawImageStageEnum fRawImageStage;
807
    
808
    // The raw image data that we grabbed, if any.
809
    
810
    AutoPtr<dng_image> fRawImage;
811
    
812
    // The floating point bit depth of the raw file, if any.
813
    
814
    uint32 fRawFloatBitDepth;
815
    
816
    // The raw image JPEG data that we grabbed, if any.
817
    
818
    AutoPtr<dng_jpeg_image> fRawJPEGImage;
819
    
820
    // Keep a separate digest for the compressed JPEG data, if any.
821
    
822
    mutable dng_fingerprint fRawJPEGImageDigest;
823
    
824
    // Transparency mask image, if any.
825
    
826
    AutoPtr<dng_image> fTransparencyMask;
827
    
828
    // Grabbed transparency mask, if we are not saving the current mask.
829
    
830
    AutoPtr<dng_image> fRawTransparencyMask;
831
    
832
    // The bit depth for the raw transparancy mask, if known.
833
    
834
    uint32 fRawTransparencyMaskBitDepth;
835
    
836
    // We sometimes need to keep of copy of the stage3 image before
837
    // flattening the transparency.
838
    
839
    AutoPtr<dng_image> fUnflattenedStage3Image;
840
    
841
  public:
842
  
843
    virtual ~dng_negative ();
844
    
845
    static dng_negative * Make (dng_host &host);
846
    
847
    /// Provide access to the memory allocator used for this object.
848
    
849
    dng_memory_allocator & Allocator () const
850
0
      {
851
0
      return fAllocator;
852
0
      }
853
      
854
    /// Getter for ModelName.
855
    
856
    void SetModelName (const char *name)
857
0
      {
858
0
      fModelName.Set_ASCII (name);
859
0
      }
860
    
861
    /// Setter for ModelName.
862
863
    const dng_string & ModelName () const
864
0
      {
865
0
      return fModelName;
866
0
      }
867
868
    /// Setter for LocalName.
869
      
870
    void SetLocalName (const char *name)
871
0
      {
872
0
      fLocalName.Set (name);
873
0
      }
874
  
875
    /// Getter for LocalName.
876
877
    const dng_string & LocalName () const
878
0
      {
879
0
      return fLocalName;
880
0
      }
881
      
882
    /// Getter for metadata
883
      
884
    dng_metadata &Metadata ()
885
0
      {
886
0
      return fMetadata;
887
0
      }
888
      
889
    #if qMetadataOnConst
890
      
891
    const dng_metadata &Metadata () const
892
      {
893
      return fMetadata;
894
      }
895
      
896
    #endif // qMetadataOnConst
897
898
    /// Make a copy of the internal metadata generally as a basis for further
899
    /// changes.
900
901
    dng_metadata * CloneInternalMetadata () const;
902
    
903
  protected:
904
905
    /// An accessor for the internal metadata that works even when we
906
    /// have general access turned off. This is needed to provide
907
    /// access to EXIF ISO information.
908
909
    const dng_metadata &InternalMetadata () const
910
0
      {
911
0
      return fMetadata;
912
0
      }
913
      
914
  public:
915
        
916
    /// Setter for BaseOrientation.
917
      
918
    void SetBaseOrientation (const dng_orientation &orientation)
919
0
      {
920
0
      Metadata ().SetBaseOrientation (orientation);
921
0
      }
922
    
923
    /// Has BaseOrientation been set?
924
925
    bool HasBaseOrientation () METACONST
926
0
      {
927
0
      return Metadata ().HasBaseOrientation ();
928
0
      }
929
    
930
    /// Getter for BaseOrientation.
931
      
932
    const dng_orientation & BaseOrientation () METACONST
933
0
      {
934
0
      return Metadata ().BaseOrientation ();
935
0
      }
936
      
937
    /// Hook to allow SDK host code to add additional rotations.
938
      
939
    virtual dng_orientation ComputeOrientation (const dng_metadata &metadata) const;
940
    
941
    /// For non-const negatives, we simply default to using the metadata attached to the negative.
942
    
943
    dng_orientation Orientation ()
944
0
      {
945
0
      return ComputeOrientation (Metadata ());
946
0
      }
947
    
948
    /// Logically rotates the image by changing the orientation values.
949
    /// This will also update the XMP data.
950
    
951
    void ApplyOrientation (const dng_orientation &orientation)
952
0
      {
953
0
      Metadata ().ApplyOrientation (orientation);
954
0
      }
955
    
956
    /// Setter for DefaultCropSize.
957
    
958
    void SetDefaultCropSize (const dng_urational &sizeH,
959
                     const dng_urational &sizeV)
960
0
      {
961
0
      fDefaultCropSizeH = sizeH;
962
0
      fDefaultCropSizeV = sizeV;
963
0
      }
964
              
965
    /// Setter for DefaultCropSize.
966
    
967
    void SetDefaultCropSize (uint32 sizeH,
968
                     uint32 sizeV)
969
0
      {
970
0
      SetDefaultCropSize (dng_urational (sizeH, 1),
971
0
                    dng_urational (sizeV, 1));
972
0
      }
973
              
974
    /// Getter for DefaultCropSize horizontal.
975
    
976
    const dng_urational & DefaultCropSizeH () const
977
0
      {
978
0
      return fDefaultCropSizeH;
979
0
      }
980
    
981
    /// Getter for DefaultCropSize vertical.
982
    
983
    const dng_urational & DefaultCropSizeV () const
984
0
      {
985
0
      return fDefaultCropSizeV;
986
0
      }
987
988
    /// Setter for DefaultCropOrigin.
989
    
990
    void SetDefaultCropOrigin (const dng_urational &originH,
991
                     const dng_urational &originV)
992
0
      {
993
0
      fDefaultCropOriginH = originH;
994
0
      fDefaultCropOriginV = originV;
995
0
      }
996
    
997
    /// Setter for DefaultCropOrigin.
998
999
    void SetDefaultCropOrigin (uint32 originH,
1000
                     uint32 originV)
1001
0
      {
1002
0
      SetDefaultCropOrigin (dng_urational (originH, 1),
1003
0
                    dng_urational (originV, 1));
1004
0
      }
1005
      
1006
    /// Set default crop around center of image.
1007
1008
    void SetDefaultCropCentered (const dng_point &rawSize)
1009
0
      {
1010
0
      
1011
0
      uint32 sizeH = Round_uint32 (fDefaultCropSizeH.As_real64 ());
1012
0
      uint32 sizeV = Round_uint32 (fDefaultCropSizeV.As_real64 ());
1013
0
      
1014
0
      SetDefaultCropOrigin ((rawSize.h - sizeH) >> 1,
1015
0
                  (rawSize.v - sizeV) >> 1);
1016
0
      
1017
0
      }
1018
                    
1019
    /// Get default crop origin horizontal value.
1020
1021
    const dng_urational & DefaultCropOriginH () const
1022
0
      {
1023
0
      return fDefaultCropOriginH;
1024
0
      }
1025
    
1026
    /// Get default crop origin vertical value.
1027
1028
    const dng_urational & DefaultCropOriginV () const
1029
0
      {
1030
0
      return fDefaultCropOriginV;
1031
0
      }
1032
1033
    /// Getter for top coordinate of default user crop.
1034
1035
    const dng_urational & DefaultUserCropT () const
1036
0
      {
1037
0
      return fDefaultUserCropT;
1038
0
      }
1039
                
1040
    /// Getter for left coordinate of default user crop.
1041
1042
    const dng_urational & DefaultUserCropL () const
1043
0
      {
1044
0
      return fDefaultUserCropL;
1045
0
      }
1046
                
1047
    /// Getter for bottom coordinate of default user crop.
1048
1049
    const dng_urational & DefaultUserCropB () const
1050
0
      {
1051
0
      return fDefaultUserCropB;
1052
0
      }
1053
                
1054
    /// Getter for right coordinate of default user crop.
1055
1056
    const dng_urational & DefaultUserCropR () const
1057
0
      {
1058
0
      return fDefaultUserCropR;
1059
0
      }
1060
1061
    /// Reset default user crop to default crop area.
1062
1063
    void ResetDefaultUserCrop ()
1064
0
      {
1065
0
      fDefaultUserCropT = dng_urational (0, 1);
1066
0
      fDefaultUserCropL = dng_urational (0, 1);
1067
0
      fDefaultUserCropB = dng_urational (1, 1);
1068
0
      fDefaultUserCropR = dng_urational (1, 1);
1069
0
      }
1070
1071
    /// Setter for all 4 coordinates of default user crop.
1072
                
1073
    void SetDefaultUserCrop (const dng_urational &t,
1074
                 const dng_urational &l,
1075
                 const dng_urational &b,
1076
                 const dng_urational &r)
1077
0
      {
1078
0
      fDefaultUserCropT = t;
1079
0
      fDefaultUserCropL = l;
1080
0
      fDefaultUserCropB = b;
1081
0
      fDefaultUserCropR = r;
1082
0
      }
1083
1084
    /// Setter for top coordinate of default user crop.
1085
                
1086
    void SetDefaultUserCropT (const dng_urational &value)
1087
0
      {
1088
0
      fDefaultUserCropT = value;
1089
0
      }
1090
1091
    /// Setter for left coordinate of default user crop.
1092
                
1093
    void SetDefaultUserCropL (const dng_urational &value)
1094
0
      {
1095
0
      fDefaultUserCropL = value;
1096
0
      }
1097
1098
    /// Setter for bottom coordinate of default user crop.
1099
                
1100
    void SetDefaultUserCropB (const dng_urational &value)
1101
0
      {
1102
0
      fDefaultUserCropB = value;
1103
0
      }
1104
1105
    /// Setter for right coordinate of default user crop.
1106
                
1107
    void SetDefaultUserCropR (const dng_urational &value)
1108
0
      {
1109
0
      fDefaultUserCropR = value;
1110
0
      }
1111
1112
    /// Setter for DefaultScale.
1113
    
1114
    void SetDefaultScale (const dng_urational &scaleH,
1115
                const dng_urational &scaleV)
1116
0
      {
1117
0
      fDefaultScaleH = scaleH;
1118
0
      fDefaultScaleV = scaleV;
1119
0
      }
1120
                
1121
    /// Get default scale horizontal value.
1122
1123
    const dng_urational & DefaultScaleH () const
1124
0
      {
1125
0
      return fDefaultScaleH;
1126
0
      }
1127
    
1128
    /// Get default scale vertical value.
1129
1130
    const dng_urational & DefaultScaleV () const
1131
0
      {
1132
0
      return fDefaultScaleV;
1133
0
      }
1134
    
1135
    /// Setter for BestQualityScale.
1136
    
1137
    void SetBestQualityScale (const dng_urational &scale)
1138
0
      {
1139
0
      fBestQualityScale = scale;
1140
0
      }
1141
                
1142
    /// Getter for BestQualityScale.
1143
    
1144
    const dng_urational & BestQualityScale () const
1145
0
      {
1146
0
      return fBestQualityScale;
1147
0
      }
1148
      
1149
    /// API for raw to full image scaling factors horizontal.
1150
    
1151
    real64 RawToFullScaleH () const
1152
0
      {
1153
0
      return fRawToFullScaleH;
1154
0
      }
1155
      
1156
    /// API for raw to full image scaling factors vertical.
1157
    
1158
    real64 RawToFullScaleV () const
1159
0
      {
1160
0
      return fRawToFullScaleV;
1161
0
      }
1162
      
1163
    /// Setter for raw to full scales.
1164
    
1165
    void SetRawToFullScale (real64 scaleH,
1166
                  real64 scaleV)
1167
0
      {
1168
0
      fRawToFullScaleH = scaleH;
1169
0
      fRawToFullScaleV = scaleV;
1170
0
      }
1171
      
1172
    /// Get default scale factor.
1173
    /// When specifing a single scale factor, we use the horizontal
1174
    /// scale factor,  and let the vertical scale factor be calculated
1175
    /// based on the pixel aspect ratio.
1176
    
1177
    real64 DefaultScale () const
1178
0
      {
1179
0
      return DefaultScaleH ().As_real64 ();
1180
0
      }
1181
    
1182
    /// Default cropped image size (at scale == 1.0) width.
1183
    
1184
    real64 SquareWidth () const
1185
0
      {
1186
0
      return DefaultCropSizeH ().As_real64 ();
1187
0
      }
1188
    
1189
    /// Default cropped image size (at scale == 1.0) height.
1190
    
1191
    real64 SquareHeight () const
1192
0
      {
1193
0
      return DefaultCropSizeV ().As_real64 () *
1194
0
           DefaultScaleV    ().As_real64 () /
1195
0
           DefaultScaleH    ().As_real64 ();
1196
0
      }
1197
    
1198
    /// Default cropped image aspect ratio.
1199
    
1200
    real64 AspectRatio () const
1201
0
      {
1202
0
      return SquareWidth  () /
1203
0
           SquareHeight ();
1204
0
      }
1205
      
1206
    /// Pixel aspect ratio of stage 3 image.
1207
    
1208
    real64 PixelAspectRatio () const
1209
0
      {
1210
0
      return (DefaultScaleH ().As_real64 () / RawToFullScaleH ()) /
1211
0
           (DefaultScaleV ().As_real64 () / RawToFullScaleV ());
1212
0
      }
1213
    
1214
    /// Default cropped image size at given scale factor width.
1215
    
1216
    uint32 FinalWidth (real64 scale) const
1217
0
      {
1218
0
      return Round_uint32 (SquareWidth () * scale);
1219
0
      }
1220
    
1221
    /// Default cropped image size at given scale factor height.
1222
    
1223
    uint32 FinalHeight (real64 scale) const
1224
0
      {
1225
0
      return Round_uint32 (SquareHeight () * scale);
1226
0
      }
1227
    
1228
    /// Default cropped image size at default scale factor width.
1229
    
1230
    uint32 DefaultFinalWidth () const
1231
0
      {
1232
0
      return FinalWidth (DefaultScale ());
1233
0
      }
1234
    
1235
    /// Default cropped image size at default scale factor height.
1236
    
1237
    uint32 DefaultFinalHeight () const
1238
0
      {
1239
0
      return FinalHeight (DefaultScale ());
1240
0
      }
1241
    
1242
    /// Get best quality width.
1243
    /// For a naive conversion, one could use either the default size,
1244
    /// or the best quality size.
1245
    
1246
    uint32 BestQualityFinalWidth () const
1247
0
      {
1248
0
      return FinalWidth (DefaultScale () * BestQualityScale ().As_real64 ());
1249
0
      }
1250
    
1251
    /// Get best quality height.
1252
    /// For a naive conversion, one could use either the default size,
1253
    /// or the best quality size.
1254
    
1255
    uint32 BestQualityFinalHeight () const
1256
0
      {
1257
0
      return FinalHeight (DefaultScale () * BestQualityScale ().As_real64 ());
1258
0
      }
1259
      
1260
    /// Default size of original (non-proxy) image.  For non-proxy images, this
1261
    /// is equal to DefaultFinalWidth/DefaultFinalHight.  For proxy images, this
1262
    /// is equal to the DefaultFinalWidth/DefaultFinalHeight of the image this
1263
    /// proxy was derived from.
1264
    
1265
    const dng_point & OriginalDefaultFinalSize () const
1266
0
      {
1267
0
      return fOriginalDefaultFinalSize;
1268
0
      }
1269
      
1270
    /// Setter for OriginalDefaultFinalSize.
1271
    
1272
    void SetOriginalDefaultFinalSize (const dng_point &size)
1273
0
      {
1274
0
      fOriginalDefaultFinalSize = size;
1275
0
      }
1276
    
1277
    /// Best quality size of original (non-proxy) image.  For non-proxy images, this
1278
    /// is equal to BestQualityFinalWidth/BestQualityFinalHeight.  For proxy images, this
1279
    /// is equal to the BestQualityFinalWidth/BestQualityFinalHeight of the image this
1280
    /// proxy was derived from.
1281
    
1282
    const dng_point & OriginalBestQualityFinalSize () const
1283
0
      {
1284
0
      return fOriginalBestQualityFinalSize;
1285
0
      }
1286
      
1287
    /// Setter for OriginalBestQualityFinalSize.
1288
    
1289
    void SetOriginalBestQualityFinalSize (const dng_point &size)
1290
0
      {
1291
0
      fOriginalBestQualityFinalSize = size;
1292
0
      }
1293
      
1294
    /// DefaultCropSize for original (non-proxy) image.  For non-proxy images,
1295
    /// this is equal to the DefaultCropSize.  for proxy images, this is
1296
    /// equal size of the DefaultCropSize of the image this proxy was derived from.
1297
    
1298
    const dng_urational & OriginalDefaultCropSizeH () const
1299
0
      {
1300
0
      return fOriginalDefaultCropSizeH;
1301
0
      }
1302
      
1303
    const dng_urational & OriginalDefaultCropSizeV () const
1304
0
      {
1305
0
      return fOriginalDefaultCropSizeV;
1306
0
      }
1307
      
1308
    /// Setter for OriginalDefaultCropSize.
1309
    
1310
    void SetOriginalDefaultCropSize (const dng_urational &sizeH,
1311
                     const dng_urational &sizeV)
1312
0
      {
1313
0
      fOriginalDefaultCropSizeH = sizeH;
1314
0
      fOriginalDefaultCropSizeV = sizeV;
1315
0
      }
1316
      
1317
    /// If the original size fields are undefined, set them to the
1318
    /// current sizes.
1319
    
1320
    void SetDefaultOriginalSizes ();
1321
1322
    /// The default crop area in the stage 3 image coordinates.
1323
              
1324
    dng_rect DefaultCropArea () const;
1325
                    
1326
    /// Setter for BaselineNoise.
1327
    
1328
    void SetBaselineNoise (real64 noise)
1329
0
      {
1330
0
      fBaselineNoise.Set_real64 (noise, 100);
1331
0
      }
1332
            
1333
    /// Getter for BaselineNoise as dng_urational.
1334
1335
    const dng_urational & BaselineNoiseR () const
1336
0
      {
1337
0
      return fBaselineNoise;
1338
0
      }
1339
    
1340
    /// Getter for BaselineNoise as real64.
1341
1342
    real64 BaselineNoise () const
1343
0
      {
1344
0
      return fBaselineNoise.As_real64 ();
1345
0
      }
1346
      
1347
    /// Setter for NoiseReductionApplied.
1348
    
1349
    void SetNoiseReductionApplied (const dng_urational &value)
1350
0
      {
1351
0
      fNoiseReductionApplied = value;
1352
0
      }
1353
      
1354
    /// Getter for NoiseReductionApplied.
1355
    
1356
    const dng_urational & NoiseReductionApplied () const
1357
0
      {
1358
0
      return fNoiseReductionApplied;
1359
0
      }
1360
1361
    /// Setter for noise profile.
1362
1363
    void SetNoiseProfile (const dng_noise_profile &noiseProfile)
1364
0
      {
1365
0
      fNoiseProfile = noiseProfile;
1366
0
      }
1367
1368
    /// Does this negative have a valid noise profile?
1369
1370
    bool HasNoiseProfile () const
1371
0
      {
1372
0
      return fNoiseProfile.IsValidForNegative (*this);
1373
0
      }
1374
1375
    /// Getter for noise profile.
1376
1377
    const dng_noise_profile & NoiseProfile () const
1378
0
      {
1379
0
      return fNoiseProfile;
1380
0
      }
1381
      
1382
    /// Setter for BaselineExposure.
1383
    
1384
    void SetBaselineExposure (real64 exposure)
1385
0
      {
1386
0
      fBaselineExposure.Set_real64 (exposure, 100);
1387
0
      }
1388
            
1389
    /// Getter for BaselineExposure as dng_urational.
1390
1391
    const dng_srational & BaselineExposureR () const
1392
0
      {
1393
0
      return fBaselineExposure;
1394
0
      }
1395
    
1396
    /// Getter for BaselineExposure as real64.
1397
1398
    real64 BaselineExposure () const
1399
0
      {
1400
0
      return BaselineExposureR ().As_real64 ();
1401
0
      }
1402
1403
    /// Compute total baseline exposure (sum of negative's BaselineExposure and
1404
    /// profile's BaselineExposureOffset).
1405
1406
    real64 TotalBaselineExposure (const dng_camera_profile_id &profileID) const;
1407
1408
    /// Setter for BaselineSharpness.
1409
    
1410
    void SetBaselineSharpness (real64 sharpness)
1411
0
      {
1412
0
      fBaselineSharpness.Set_real64 (sharpness, 100);
1413
0
      }
1414
    
1415
    /// Getter for BaselineSharpness as dng_urational.
1416
1417
    const dng_urational & BaselineSharpnessR () const
1418
0
      {
1419
0
      return fBaselineSharpness;
1420
0
      }
1421
    
1422
    /// Getter for BaselineSharpness as real64.
1423
1424
    real64 BaselineSharpness () const
1425
0
      {
1426
0
      return BaselineSharpnessR ().As_real64 ();
1427
0
      }
1428
    
1429
    /// Setter for ChromaBlurRadius.
1430
    
1431
    void SetChromaBlurRadius (const dng_urational &radius)
1432
0
      {
1433
0
      fChromaBlurRadius = radius;
1434
0
      }
1435
    
1436
    /// Getter for ChromaBlurRadius as dng_urational.
1437
1438
    const dng_urational & ChromaBlurRadius () const
1439
0
      {
1440
0
      return fChromaBlurRadius;
1441
0
      }
1442
    
1443
    /// Setter for AntiAliasStrength.
1444
    
1445
    void SetAntiAliasStrength (const dng_urational &strength)
1446
0
      {
1447
0
      fAntiAliasStrength = strength;
1448
0
      }
1449
            
1450
    /// Getter for AntiAliasStrength as dng_urational.
1451
1452
    const dng_urational & AntiAliasStrength () const
1453
0
      {
1454
0
      return fAntiAliasStrength;
1455
0
      }
1456
    
1457
    /// Setter for LinearResponseLimit.
1458
    
1459
    void SetLinearResponseLimit (real64 limit)
1460
0
      {
1461
0
      fLinearResponseLimit.Set_real64 (limit, 100);
1462
0
      }
1463
    
1464
    /// Getter for LinearResponseLimit as dng_urational.
1465
1466
    const dng_urational & LinearResponseLimitR () const
1467
0
      {
1468
0
      return fLinearResponseLimit;
1469
0
      }
1470
    
1471
    /// Getter for LinearResponseLimit as real64.
1472
1473
    real64 LinearResponseLimit () const
1474
0
      {
1475
0
      return LinearResponseLimitR ().As_real64 ();
1476
0
      }
1477
    
1478
    /// Setter for ShadowScale.
1479
    
1480
    void SetShadowScale (const dng_urational &scale);
1481
    
1482
    /// Getter for ShadowScale as dng_urational.
1483
1484
    const dng_urational & ShadowScaleR () const
1485
0
      {
1486
0
      return fShadowScale;
1487
0
      }
1488
    
1489
    /// Getter for ShadowScale as real64.
1490
1491
    real64 ShadowScale () const
1492
0
      {
1493
0
      return ShadowScaleR ().As_real64 ();
1494
0
      }
1495
      
1496
    // API for ColorimetricReference.
1497
    
1498
    void SetColorimetricReference (uint32 ref)
1499
0
      {
1500
0
      fColorimetricReference = ref;
1501
0
      }
1502
      
1503
    uint32 ColorimetricReference () const
1504
0
      {
1505
0
      return fColorimetricReference;
1506
0
      }
1507
    
1508
    /// Setter for ColorChannels.
1509
      
1510
    void SetColorChannels (uint32 channels)
1511
0
      {
1512
0
      fColorChannels = channels;
1513
0
      }
1514
    
1515
    /// Getter for ColorChannels.
1516
      
1517
    uint32 ColorChannels () const
1518
0
      {
1519
0
      return fColorChannels;
1520
0
      }
1521
    
1522
    /// Setter for Monochrome.
1523
      
1524
    void SetMonochrome ()
1525
0
      {
1526
0
      SetColorChannels (1);
1527
0
      }
1528
1529
    /// Getter for Monochrome.
1530
      
1531
    bool IsMonochrome () const
1532
0
      {
1533
0
      return ColorChannels () == 1;
1534
0
      }
1535
    
1536
    /// Setter for AnalogBalance.
1537
1538
    void SetAnalogBalance (const dng_vector &b);
1539
    
1540
    /// Getter for AnalogBalance as dng_urational.
1541
1542
    dng_urational AnalogBalanceR (uint32 channel) const;
1543
    
1544
    /// Getter for AnalogBalance as real64.
1545
1546
    real64 AnalogBalance (uint32 channel) const;
1547
    
1548
    /// Setter for CameraNeutral.
1549
1550
    void SetCameraNeutral (const dng_vector &n);
1551
            
1552
    /// Clear CameraNeutral.
1553
1554
    void ClearCameraNeutral ()
1555
0
      {
1556
0
      fCameraNeutral.Clear ();
1557
0
      }
1558
    
1559
    /// Determine if CameraNeutral has been set but not cleared.
1560
1561
    bool HasCameraNeutral () const
1562
0
      {
1563
0
      return fCameraNeutral.NotEmpty ();
1564
0
      }
1565
      
1566
    /// Getter for CameraNeutral.
1567
1568
    const dng_vector & CameraNeutral () const
1569
0
      {
1570
0
      return fCameraNeutral;
1571
0
      }
1572
    
1573
    dng_urational CameraNeutralR (uint32 channel) const;
1574
    
1575
    /// Setter for CameraWhiteXY.
1576
1577
    void SetCameraWhiteXY (const dng_xy_coord &coord);
1578
    
1579
    bool HasCameraWhiteXY () const
1580
0
      {
1581
0
      return fCameraWhiteXY.IsValid ();
1582
0
      }
1583
    
1584
    const dng_xy_coord & CameraWhiteXY () const;
1585
    
1586
    void GetCameraWhiteXY (dng_urational &x,
1587
                 dng_urational &y) const;
1588
                 
1589
    // API for camera calibration:
1590
    
1591
    /// Setter for first of up to two color matrices used for individual camera calibrations.
1592
    /// 
1593
    /// The sequence of matrix transforms is:
1594
    /// Camera data --> camera calibration --> "inverse" of color matrix
1595
    ///
1596
    /// This will be a 4x4 matrix for a four-color camera. The defaults are
1597
    /// almost always the identity matrix, and for the cases where they
1598
    /// aren't, they are diagonal matrices.
1599
1600
    void SetCameraCalibration1 (const dng_matrix &m);
1601
1602
    /// Setter for second of up to two color matrices used for individual camera calibrations.
1603
    /// 
1604
    /// The sequence of matrix transforms is:
1605
    /// Camera data --> camera calibration --> "inverse" of color matrix
1606
    ///
1607
    /// This will be a 4x4 matrix for a four-color camera. The defaults are
1608
    /// almost always the identity matrix, and for the cases where they
1609
    /// aren't, they are diagonal matrices.
1610
1611
    void SetCameraCalibration2 (const dng_matrix &m);
1612
    
1613
    /// Getter for first of up to two color matrices used for individual camera calibrations.
1614
1615
    const dng_matrix & CameraCalibration1 () const
1616
0
      {
1617
0
      return fCameraCalibration1;
1618
0
      }
1619
  
1620
    /// Getter for second of up to two color matrices used for individual camera calibrations.
1621
1622
    const dng_matrix & CameraCalibration2 () const
1623
0
      {
1624
0
      return fCameraCalibration2;
1625
0
      }
1626
    
1627
    void SetCameraCalibrationSignature (const char *signature)
1628
0
      {
1629
0
      fCameraCalibrationSignature.Set (signature);
1630
0
      }
1631
1632
    const dng_string & CameraCalibrationSignature () const
1633
0
      {
1634
0
      return fCameraCalibrationSignature;
1635
0
      }
1636
      
1637
    // Camera Profile API:
1638
    
1639
    void AddProfile (AutoPtr<dng_camera_profile> &profile);
1640
    
1641
    void ClearProfiles ();
1642
      
1643
    void ClearProfiles (bool clearBuiltinMatrixProfiles,
1644
              bool clearReadFromDisk);
1645
      
1646
    uint32 ProfileCount () const;
1647
    
1648
    const dng_camera_profile & ProfileByIndex (uint32 index) const;
1649
    
1650
    virtual const dng_camera_profile * ProfileByID (const dng_camera_profile_id &id,
1651
                            bool useDefaultIfNoMatch = true) const;
1652
    
1653
    bool HasProfileID (const dng_camera_profile_id &id) const
1654
0
      {
1655
0
      return ProfileByID (id, false) != NULL;
1656
0
      }
1657
    
1658
    // Returns the camera profile to embed when saving to DNG: 
1659
    
1660
    virtual const dng_camera_profile * ComputeCameraProfileToEmbed
1661
                          (const dng_metadata &metadata) const;
1662
                          
1663
    // For non-const negatives, we can use the embedded metadata.
1664
    
1665
    const dng_camera_profile * CameraProfileToEmbed ()
1666
0
      {
1667
0
      return ComputeCameraProfileToEmbed (Metadata ());
1668
0
      }
1669
    
1670
    // API for AsShotProfileName.
1671
      
1672
    void SetAsShotProfileName (const char *name)
1673
0
      {
1674
0
      fAsShotProfileName.Set (name);
1675
0
      }
1676
1677
    const dng_string & AsShotProfileName () const
1678
0
      {
1679
0
      return fAsShotProfileName;
1680
0
      }
1681
      
1682
    // Makes a dng_color_spec object for this negative.
1683
    
1684
    virtual dng_color_spec * MakeColorSpec (const dng_camera_profile_id &id) const;
1685
    
1686
    // Compute a MD5 hash on an image, using a fixed algorithm.
1687
    // The results must be stable across different hardware, OSes,
1688
    // and software versions.
1689
      
1690
    dng_fingerprint FindImageDigest (dng_host &host,
1691
                     const dng_image &image) const;
1692
      
1693
    // API for RawImageDigest and NewRawImageDigest:
1694
    
1695
    void SetRawImageDigest (const dng_fingerprint &digest)
1696
0
      {
1697
0
      fRawImageDigest = digest;
1698
0
      }
1699
      
1700
    void SetNewRawImageDigest (const dng_fingerprint &digest)
1701
0
      {
1702
0
      fNewRawImageDigest = digest;
1703
0
      }
1704
      
1705
    void ClearRawImageDigest () const
1706
0
      {
1707
0
      fRawImageDigest   .Clear ();
1708
0
      fNewRawImageDigest.Clear ();
1709
0
      }
1710
      
1711
    const dng_fingerprint & RawImageDigest () const
1712
0
      {
1713
0
      return fRawImageDigest;
1714
0
      }
1715
      
1716
    const dng_fingerprint & NewRawImageDigest () const
1717
0
      {
1718
0
      return fNewRawImageDigest;
1719
0
      }
1720
      
1721
    void FindRawImageDigest (dng_host &host) const;
1722
    
1723
    void FindNewRawImageDigest (dng_host &host) const;
1724
    
1725
    void ValidateRawImageDigest (dng_host &host);
1726
    
1727
    // API for RawDataUniqueID:
1728
1729
    void SetRawDataUniqueID (const dng_fingerprint &id)
1730
0
      {
1731
0
      fRawDataUniqueID = id;
1732
0
      }
1733
    
1734
    const dng_fingerprint & RawDataUniqueID () const
1735
0
      {
1736
0
      return fRawDataUniqueID;
1737
0
      }
1738
    
1739
    void FindRawDataUniqueID (dng_host &host) const;
1740
    
1741
    void RecomputeRawDataUniqueID (dng_host &host);
1742
1743
    // API for original raw file name:
1744
    
1745
    void SetOriginalRawFileName (const char *name)
1746
0
      {
1747
0
      fOriginalRawFileName.Set (name);
1748
0
      }
1749
      
1750
    bool HasOriginalRawFileName () const
1751
0
      {
1752
0
      return fOriginalRawFileName.NotEmpty ();
1753
0
      }
1754
    
1755
    const dng_string & OriginalRawFileName () const
1756
0
      {
1757
0
      return fOriginalRawFileName;
1758
0
      }
1759
    
1760
    // API for original raw file data:
1761
    
1762
    void SetHasOriginalRawFileData (bool hasData)
1763
0
      {
1764
0
      fHasOriginalRawFileData = hasData;
1765
0
      }
1766
    
1767
    bool CanEmbedOriginalRaw () const
1768
0
      {
1769
0
      return fHasOriginalRawFileData && HasOriginalRawFileName ();
1770
0
      }
1771
    
1772
    void SetOriginalRawFileData (AutoPtr<dng_memory_block> &data)
1773
0
      {
1774
0
      fOriginalRawFileData.Reset (data.Release ());
1775
0
      }
1776
    
1777
    const void * OriginalRawFileData () const
1778
0
      {
1779
0
      return fOriginalRawFileData.Get () ? fOriginalRawFileData->Buffer ()
1780
0
                         : NULL;
1781
0
      }
1782
    
1783
    uint32 OriginalRawFileDataLength () const
1784
0
      {
1785
0
      return fOriginalRawFileData.Get () ? fOriginalRawFileData->LogicalSize ()
1786
0
                         : 0;
1787
0
      }
1788
      
1789
    // API for original raw file data digest.
1790
    
1791
    void SetOriginalRawFileDigest (const dng_fingerprint &digest)
1792
0
      {
1793
0
      fOriginalRawFileDigest = digest;
1794
0
      }
1795
      
1796
    const dng_fingerprint & OriginalRawFileDigest () const
1797
0
      {
1798
0
      return fOriginalRawFileDigest;
1799
0
      }
1800
      
1801
    void FindOriginalRawFileDigest () const;
1802
    
1803
    void ValidateOriginalRawFileDigest ();
1804
    
1805
    // API for DNG private data:
1806
    
1807
    void SetPrivateData (AutoPtr<dng_memory_block> &block)
1808
0
      {
1809
0
      fDNGPrivateData.Reset (block.Release ());
1810
0
      }
1811
    
1812
    void ClearPrivateData ()
1813
0
      {
1814
0
      fDNGPrivateData.Reset ();
1815
0
      }
1816
    
1817
    const uint8 * PrivateData () const
1818
0
      {
1819
0
      return fDNGPrivateData.Get () ? fDNGPrivateData->Buffer_uint8 ()
1820
0
                      : NULL;
1821
0
      }
1822
    
1823
    uint32 PrivateLength () const
1824
0
      {
1825
0
      return fDNGPrivateData.Get () ? fDNGPrivateData->LogicalSize ()
1826
0
                      : 0;
1827
0
      }
1828
    
1829
    // API for MakerNote data:
1830
    
1831
    void SetMakerNoteSafety (bool safe)
1832
0
      {
1833
0
      Metadata ().SetMakerNoteSafety (safe);
1834
0
      }
1835
    
1836
    bool IsMakerNoteSafe () METACONST
1837
0
      {
1838
0
      return Metadata ().IsMakerNoteSafe ();
1839
0
      }
1840
    
1841
    void SetMakerNote (AutoPtr<dng_memory_block> &block)
1842
0
      {
1843
0
      Metadata ().SetMakerNote (block);
1844
0
      }
1845
    
1846
    void ClearMakerNote ()
1847
0
      {
1848
0
      Metadata ().ClearMakerNote ();
1849
0
      }
1850
    
1851
    const void * MakerNoteData () METACONST
1852
0
      {
1853
0
      return Metadata ().MakerNoteData ();
1854
0
      }
1855
    
1856
    uint32 MakerNoteLength () METACONST
1857
0
      {
1858
0
      return Metadata ().MakerNoteLength ();
1859
0
      }
1860
    
1861
    // API for EXIF metadata:
1862
    
1863
    dng_exif * GetExif ()
1864
0
      {
1865
0
      return Metadata ().GetExif ();
1866
0
      }
1867
      
1868
    #if qMetadataOnConst
1869
      
1870
    const dng_exif * GetExif () const
1871
      {
1872
      return Metadata ().GetExif ();
1873
      }
1874
      
1875
    #endif // qMetadataOnConst
1876
      
1877
    void ResetExif (dng_exif * newExif)
1878
0
      {
1879
0
      Metadata ().ResetExif (newExif);
1880
0
      }
1881
      
1882
    // API for original EXIF metadata.
1883
    
1884
    dng_exif * GetOriginalExif ()
1885
0
      {
1886
0
      return Metadata ().GetOriginalExif ();
1887
0
      }
1888
      
1889
    #if qMetadataOnConst
1890
      
1891
    const dng_exif * GetOriginalExif () const
1892
      {
1893
      return Metadata ().GetOriginalExif ();
1894
      }
1895
      
1896
    #endif // qMetadataOnConst
1897
      
1898
    // API for IPTC metadata:
1899
      
1900
    void SetIPTC (AutoPtr<dng_memory_block> &block,
1901
            uint64 offset)
1902
0
      {
1903
0
      Metadata ().SetIPTC (block, offset);
1904
0
      }
1905
    
1906
    void SetIPTC (AutoPtr<dng_memory_block> &block)
1907
0
      {
1908
0
      Metadata ().SetIPTC (block);
1909
0
      }
1910
    
1911
    void ClearIPTC ()
1912
0
      {
1913
0
      Metadata ().ClearIPTC ();
1914
0
      }
1915
    
1916
    const void * IPTCData () METACONST
1917
0
      {
1918
0
      return Metadata ().IPTCData ();
1919
0
      }
1920
    
1921
    uint32 IPTCLength () METACONST
1922
0
      {
1923
0
      return Metadata ().IPTCLength ();
1924
0
      }
1925
    
1926
    uint64 IPTCOffset () METACONST
1927
0
      {
1928
0
      return Metadata ().IPTCOffset ();
1929
0
      }
1930
    
1931
    dng_fingerprint IPTCDigest (bool includePadding = true) METACONST
1932
0
      {
1933
0
      return Metadata ().IPTCDigest (includePadding);
1934
0
      }
1935
    
1936
    void RebuildIPTC (bool padForTIFF)
1937
0
      {
1938
0
      Metadata ().RebuildIPTC (Allocator (), padForTIFF);
1939
0
      }
1940
    
1941
    // API for XMP metadata:
1942
    
1943
    #if qDNGUseXMP
1944
    
1945
    bool SetXMP (dng_host &host,
1946
           const void *buffer,
1947
           uint32 count,
1948
           bool xmpInSidecar = false,
1949
           bool xmpIsNewer = false)
1950
      {
1951
      return Metadata ().SetXMP (host,
1952
                     buffer,
1953
                     count,
1954
                     xmpInSidecar,
1955
                     xmpIsNewer);
1956
      }
1957
           
1958
    dng_xmp * GetXMP ()
1959
      {
1960
      return Metadata ().GetXMP ();
1961
      }
1962
      
1963
    #if qMetadataOnConst
1964
      
1965
    const dng_xmp * GetXMP () const
1966
      {
1967
      return Metadata ().GetXMP ();
1968
      }
1969
      
1970
    #endif // qMetadataOnConst
1971
      
1972
    bool XMPinSidecar () METACONST
1973
      {
1974
      return Metadata ().XMPinSidecar ();
1975
      }
1976
      
1977
    void ResetXMP (dng_xmp * newXMP)
1978
      {
1979
      Metadata ().ResetXMP (newXMP);
1980
      }
1981
  
1982
    void ResetXMPSidecarNewer (dng_xmp * newXMP, bool inSidecar, bool isNewer )
1983
      {
1984
      Metadata ().ResetXMPSidecarNewer (newXMP, inSidecar, isNewer);
1985
      }
1986
    
1987
    bool HaveValidEmbeddedXMP () METACONST
1988
      {
1989
      return Metadata ().HaveValidEmbeddedXMP ();
1990
      }
1991
      
1992
    #endif
1993
    
1994
    // API for source MIMI type.
1995
    
1996
    void SetSourceMIMI (const char *s)
1997
0
      {
1998
0
      Metadata ().SetSourceMIMI (s);
1999
0
      }
2000
    
2001
    // API for linearization information:
2002
      
2003
    const dng_linearization_info * GetLinearizationInfo () const
2004
0
      {
2005
0
      return fLinearizationInfo.Get ();
2006
0
      }
2007
      
2008
    void ClearLinearizationInfo ()
2009
0
      {
2010
0
      fLinearizationInfo.Reset ();
2011
0
      }
2012
      
2013
    // Linearization curve.  Usually used to increase compression ratios
2014
    // by storing the compressed data in a more visually uniform space.
2015
    // This is a 16-bit LUT that maps the stored data back to linear.
2016
    
2017
    void SetLinearization (AutoPtr<dng_memory_block> &curve);
2018
    
2019
    // Active area (non-black masked pixels).  These pixels are trimmed
2020
    // during linearization step.
2021
    
2022
    void SetActiveArea (const dng_rect &area);
2023
    
2024
    // Areas that are known to contain black masked pixels that can
2025
    // be used to estimate black levels.
2026
    
2027
    void SetMaskedAreas (uint32 count,
2028
               const dng_rect *area);
2029
               
2030
    void SetMaskedArea (const dng_rect &area)
2031
0
      {
2032
0
      SetMaskedAreas (1, &area);
2033
0
      }
2034
2035
    // Sensor black level information.
2036
    
2037
    void SetBlackLevel (real64 black,
2038
              int32 plane = -1);
2039
              
2040
    void SetQuadBlacks (real64 black0,
2041
                real64 black1,
2042
                real64 black2,
2043
                real64 black3,
2044
              int32 plane = -1);
2045
                
2046
    void SetRowBlacks (const real64 *blacks,
2047
               uint32 count);
2048
               
2049
    void SetColumnBlacks (const real64 *blacks,
2050
                uint32 count);
2051
                
2052
    // Sensor white level information.
2053
    
2054
    uint32 WhiteLevel (uint32 plane = 0) const;
2055
      
2056
    void SetWhiteLevel (uint32 white,
2057
              int32 plane = -1);
2058
2059
    // API for mosaic information:
2060
    
2061
    const dng_mosaic_info * GetMosaicInfo () const
2062
0
      {
2063
0
      return fMosaicInfo.Get ();
2064
0
      }
2065
      
2066
    void ClearMosaicInfo ()
2067
0
      {
2068
0
      fMosaicInfo.Reset ();
2069
0
      }
2070
    
2071
    // ColorKeys APIs:
2072
              
2073
    void SetColorKeys (ColorKeyCode color0,
2074
               ColorKeyCode color1,
2075
               ColorKeyCode color2,
2076
               ColorKeyCode color3 = colorKeyMaxEnum);
2077
2078
    void SetRGB ()
2079
0
      {
2080
0
      
2081
0
      SetColorChannels (3);
2082
0
      
2083
0
      SetColorKeys (colorKeyRed,
2084
0
              colorKeyGreen,
2085
0
              colorKeyBlue);
2086
0
              
2087
0
      }
2088
      
2089
    void SetCMY ()
2090
0
      {
2091
0
      
2092
0
      SetColorChannels (3);
2093
0
      
2094
0
      SetColorKeys (colorKeyCyan,
2095
0
              colorKeyMagenta,
2096
0
              colorKeyYellow);
2097
0
              
2098
0
      }
2099
      
2100
    void SetGMCY ()
2101
0
      {
2102
0
      
2103
0
      SetColorChannels (4);
2104
0
      
2105
0
      SetColorKeys (colorKeyGreen,
2106
0
              colorKeyMagenta,
2107
0
                colorKeyCyan,
2108
0
              colorKeyYellow);
2109
0
              
2110
0
      }
2111
      
2112
    // APIs to set mosaic patterns.
2113
      
2114
    void SetBayerMosaic (uint32 phase);
2115
2116
    void SetFujiMosaic (uint32 phase);
2117
2118
    void SetFujiMosaic6x6 (uint32 phase);
2119
2120
    void SetQuadMosaic (uint32 pattern);
2121
      
2122
    // BayerGreenSplit.
2123
              
2124
    void SetGreenSplit (uint32 split);
2125
    
2126
    // APIs for opcode lists.
2127
    
2128
    const dng_opcode_list & OpcodeList1 () const
2129
0
      {
2130
0
      return fOpcodeList1;
2131
0
      }
2132
      
2133
    dng_opcode_list & OpcodeList1 ()
2134
0
      {
2135
0
      return fOpcodeList1;
2136
0
      }
2137
      
2138
    const dng_opcode_list & OpcodeList2 () const
2139
0
      {
2140
0
      return fOpcodeList2;
2141
0
      }
2142
      
2143
    dng_opcode_list & OpcodeList2 ()
2144
0
      {
2145
0
      return fOpcodeList2;
2146
0
      }
2147
      
2148
    const dng_opcode_list & OpcodeList3 () const
2149
0
      {
2150
0
      return fOpcodeList3;
2151
0
      }
2152
      
2153
    dng_opcode_list & OpcodeList3 ()
2154
0
      {
2155
0
      return fOpcodeList3;
2156
0
      }
2157
    
2158
    // First part of parsing logic.
2159
    
2160
    virtual void Parse (dng_host &host,
2161
              dng_stream &stream,
2162
              dng_info &info);
2163
              
2164
    // Second part of parsing logic.  This is split off from the
2165
    // first part because these operations are useful when extending
2166
    // this sdk to support non-DNG raw formats.
2167
              
2168
    virtual void PostParse (dng_host &host,
2169
                dng_stream &stream,
2170
                dng_info &info);
2171
                
2172
    // Synchronize metadata sources.
2173
    
2174
    void SynchronizeMetadata ()
2175
0
      {
2176
0
      Metadata ().SynchronizeMetadata ();
2177
0
      }
2178
    
2179
    // Routines to update the date/time field in the EXIF and XMP
2180
    // metadata.
2181
    
2182
    void UpdateDateTime (const dng_date_time_info &dt)
2183
0
      {
2184
0
      Metadata ().UpdateDateTime (dt);
2185
0
      }
2186
               
2187
    void UpdateDateTimeToNow ()
2188
0
      {
2189
0
      Metadata ().UpdateDateTimeToNow ();
2190
0
      }
2191
    
2192
    // Developer's utility function to switch to four color Bayer
2193
    // interpolation.  This is useful for evaluating how much green
2194
    // split a Bayer pattern sensor has.
2195
      
2196
    virtual bool SetFourColorBayer ();
2197
    
2198
    // Access routines for the image stages.
2199
              
2200
    const dng_image * Stage1Image () const
2201
0
      {
2202
0
      return fStage1Image.Get ();
2203
0
      }
2204
      
2205
    const dng_image * Stage2Image () const
2206
0
      {
2207
0
      return fStage2Image.Get ();
2208
0
      }
2209
      
2210
    const dng_image * Stage3Image () const
2211
0
      {
2212
0
      return fStage3Image.Get ();
2213
0
      }
2214
      
2215
    // Returns the processing stage of the raw image data.
2216
    
2217
    RawImageStageEnum RawImageStage () const
2218
0
      {
2219
0
      return fRawImageStage;
2220
0
      }
2221
      
2222
    // Returns the raw image data.
2223
    
2224
    const dng_image & RawImage () const;
2225
    
2226
    // API for raw floating point bit depth.
2227
    
2228
    uint32 RawFloatBitDepth () const
2229
0
      {
2230
0
      return fRawFloatBitDepth;
2231
0
      }
2232
      
2233
    void SetRawFloatBitDepth (uint32 bitDepth)
2234
0
      {
2235
0
      fRawFloatBitDepth = bitDepth;
2236
0
      }
2237
    
2238
    // API for raw jpeg image.
2239
    
2240
    const dng_jpeg_image * RawJPEGImage () const;
2241
2242
    void SetRawJPEGImage (AutoPtr<dng_jpeg_image> &jpegImage);
2243
      
2244
    void ClearRawJPEGImage ();
2245
      
2246
    // API for RawJPEGImageDigest:
2247
    
2248
    void SetRawJPEGImageDigest (const dng_fingerprint &digest)
2249
0
      {
2250
0
      fRawJPEGImageDigest = digest;
2251
0
      }
2252
      
2253
    void ClearRawJPEGImageDigest () const
2254
0
      {
2255
0
      fRawJPEGImageDigest.Clear ();
2256
0
      }
2257
      
2258
    const dng_fingerprint & RawJPEGImageDigest () const
2259
0
      {
2260
0
      return fRawJPEGImageDigest;
2261
0
      }
2262
      
2263
    void FindRawJPEGImageDigest (dng_host &host) const;
2264
    
2265
    // Read the stage 1 image.
2266
      
2267
    virtual void ReadStage1Image (dng_host &host,
2268
                    dng_stream &stream,
2269
                    dng_info &info);
2270
                    
2271
    // Assign the stage 1 image.
2272
    
2273
    void SetStage1Image (AutoPtr<dng_image> &image);
2274
    
2275
    // Assign the stage 2 image.
2276
    
2277
    void SetStage2Image (AutoPtr<dng_image> &image);
2278
                    
2279
    // Assign the stage 3 image.
2280
    
2281
    void SetStage3Image (AutoPtr<dng_image> &image);
2282
    
2283
    // Build the stage 2 (linearized and range mapped) image.
2284
    
2285
    void BuildStage2Image (dng_host &host);
2286
                     
2287
    // Build the stage 3 (demosaiced) image.
2288
                     
2289
    void BuildStage3Image (dng_host &host,
2290
                 int32 srcPlane = -1);
2291
                     
2292
    // Additional gain applied when building the stage 3 image.
2293
    
2294
    void SetStage3Gain (real64 gain)
2295
0
      {
2296
0
      fStage3Gain = gain;
2297
0
      }
2298
    
2299
    real64 Stage3Gain () const
2300
0
      {
2301
0
      return fStage3Gain;
2302
0
      }
2303
      
2304
    // Adaptively encode a proxy image down to 8-bits/channel.
2305
2306
    dng_image * EncodeRawProxy (dng_host &host,
2307
                  const dng_image &srcImage,
2308
                  dng_opcode_list &opcodeList) const;
2309
2310
    // Convert to a proxy negative.
2311
2312
    void ConvertToProxy (dng_host &host,
2313
               dng_image_writer &writer,
2314
               uint32 proxySize = 0,
2315
               uint64 proxyCount = 0);
2316
               
2317
    // IsPreview API:
2318
      
2319
    void SetIsPreview (bool preview)
2320
0
      {
2321
0
      fIsPreview = preview;
2322
0
      }
2323
    
2324
    bool IsPreview () const
2325
0
      {
2326
0
      return fIsPreview;
2327
0
      }
2328
      
2329
    // IsDamaged API:
2330
    
2331
    void SetIsDamaged (bool damaged)
2332
0
      {
2333
0
      fIsDamaged = damaged;
2334
0
      }
2335
      
2336
    bool IsDamaged () const
2337
0
      {
2338
0
      return fIsDamaged;
2339
0
      }
2340
      
2341
    // Transparancy Mask API:
2342
    
2343
    void SetTransparencyMask (AutoPtr<dng_image> &image,
2344
                  uint32 bitDepth = 0);
2345
    
2346
    const dng_image * TransparencyMask () const;
2347
    
2348
    const dng_image * RawTransparencyMask () const;
2349
    
2350
    uint32 RawTransparencyMaskBitDepth () const;
2351
    
2352
    void ReadTransparencyMask (dng_host &host,
2353
                   dng_stream &stream,
2354
                   dng_info &info);
2355
                   
2356
    virtual bool NeedFlattenTransparency (dng_host &host);
2357
    
2358
    virtual void FlattenTransparency (dng_host &host);
2359
    
2360
    const dng_image * UnflattenedStage3Image () const;
2361
2362
  protected:
2363
  
2364
    dng_negative (dng_host &host);
2365
    
2366
    virtual void Initialize ();
2367
    
2368
    virtual dng_linearization_info * MakeLinearizationInfo ();
2369
    
2370
    void NeedLinearizationInfo ();
2371
    
2372
    virtual dng_mosaic_info * MakeMosaicInfo ();
2373
    
2374
    void NeedMosaicInfo ();
2375
    
2376
    virtual void DoBuildStage2 (dng_host &host);
2377
    
2378
    virtual void DoPostOpcodeList2 (dng_host &host);
2379
                     
2380
    virtual bool NeedDefloatStage2 (dng_host &host);
2381
    
2382
    virtual void DefloatStage2 (dng_host &host);
2383
    
2384
    virtual void DoInterpolateStage3 (dng_host &host,
2385
                        int32 srcPlane);
2386
                  
2387
    virtual void DoMergeStage3 (dng_host &host);
2388
                     
2389
    virtual void DoBuildStage3 (dng_host &host,
2390
                  int32 srcPlane);
2391
                     
2392
    virtual void AdjustProfileForStage3 ();
2393
                    
2394
    virtual void ResizeTransparencyToMatchStage3 (dng_host &host,
2395
                            bool convertTo8Bit = false);
2396
                            
2397
  };
2398
2399
/*****************************************************************************/
2400
2401
#endif
2402
  
2403
/*****************************************************************************/