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_ifd.h#3 $ */
10 /* $DateTime: 2012/06/05 11:05:39 $ */
11 /* $Change: 833352 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  *  DNG image file directory support.
16  */
17 
18 /*****************************************************************************/
19 
20 #ifndef __dng_ifd__
21 #define __dng_ifd__
22 
23 /*****************************************************************************/
24 
25 #include "dng_fingerprint.h"
26 #include "dng_rect.h"
27 #include "dng_shared.h"
28 #include "dng_stream.h"
29 #include "dng_string.h"
30 #include "dng_sdk_limits.h"
31 #include "dng_tag_values.h"
32 
33 /*****************************************************************************/
34 
35 class dng_preview_info
36 	{
37 
38 	public:
39 
40 		bool fIsPrimary;
41 
42 		dng_string fApplicationName;
43 
44 		dng_string fApplicationVersion;
45 
46 		dng_string fSettingsName;
47 
48 		dng_fingerprint fSettingsDigest;
49 
50 		PreviewColorSpaceEnum fColorSpace;
51 
52 		dng_string fDateTime;
53 
54 		real64 fRawToPreviewGain;
55 
56 		uint32 fCacheVersion;
57 
58 	public:
59 
60 		dng_preview_info ();
61 
62 		~dng_preview_info ();
63 
64 	};
65 
66 /*****************************************************************************/
67 
68 /// \brief Container for a single image file directory of a digital negative.
69 ///
70 /// See \ref spec_dng "DNG 1.1.0 specification" for documentation of specific tags.
71 
72 class dng_ifd
73 	{
74 
75 	public:
76 
77 		bool fUsesNewSubFileType;
78 
79 		uint32 fNewSubFileType;
80 
81 		uint32 fImageWidth;
82 		uint32 fImageLength;
83 
84 		uint32 fBitsPerSample [kMaxSamplesPerPixel];
85 
86 		uint32 fCompression;
87 
88 		uint32 fPredictor;
89 
90 		uint32 fPhotometricInterpretation;
91 
92 		uint32 fFillOrder;
93 
94 		uint32 fOrientation;
95 		uint32 fOrientationType;
96 		uint64 fOrientationOffset;
97 		bool   fOrientationBigEndian;
98 
99 		uint32 fSamplesPerPixel;
100 
101 		uint32 fPlanarConfiguration;
102 
103 		real64 fXResolution;
104 		real64 fYResolution;
105 
106 		uint32 fResolutionUnit;
107 
108 		bool fUsesStrips;
109 		bool fUsesTiles;
110 
111 		uint32 fTileWidth;
112 		uint32 fTileLength;
113 
114 		enum
115 			{
116 			kMaxTileInfo = 32
117 			};
118 
119 		uint32 fTileOffsetsType;
120 		uint32 fTileOffsetsCount;
121 		uint64 fTileOffsetsOffset;
122 		uint64 fTileOffset [kMaxTileInfo];
123 
124 		uint32 fTileByteCountsType;
125 		uint32 fTileByteCountsCount;
126 		uint64 fTileByteCountsOffset;
127 		uint32 fTileByteCount [kMaxTileInfo];
128 
129 		uint32 fSubIFDsCount;
130 		uint64 fSubIFDsOffset;
131 
132 		uint32 fExtraSamplesCount;
133 		uint32 fExtraSamples [kMaxSamplesPerPixel];
134 
135 		uint32 fSampleFormat [kMaxSamplesPerPixel];
136 
137 		uint32 fJPEGTablesCount;
138 		uint64 fJPEGTablesOffset;
139 
140 		uint64 fJPEGInterchangeFormat;
141 		uint32 fJPEGInterchangeFormatLength;
142 
143 		real64 fYCbCrCoefficientR;
144 		real64 fYCbCrCoefficientG;
145 		real64 fYCbCrCoefficientB;
146 
147 		uint32 fYCbCrSubSampleH;
148 		uint32 fYCbCrSubSampleV;
149 
150 		uint32 fYCbCrPositioning;
151 
152 		real64 fReferenceBlackWhite [6];
153 
154 		uint32 fCFARepeatPatternRows;
155 		uint32 fCFARepeatPatternCols;
156 
157 		uint8 fCFAPattern [kMaxCFAPattern] [kMaxCFAPattern];
158 
159 		uint8 fCFAPlaneColor [kMaxColorPlanes];
160 
161 		uint32 fCFALayout;
162 
163 		uint32 fLinearizationTableType;
164 		uint32 fLinearizationTableCount;
165 		uint64 fLinearizationTableOffset;
166 
167 		uint32 fBlackLevelRepeatRows;
168 		uint32 fBlackLevelRepeatCols;
169 
170 		real64 fBlackLevel [kMaxBlackPattern] [kMaxBlackPattern] [kMaxSamplesPerPixel];
171 
172 		uint32 fBlackLevelDeltaHType;
173 		uint32 fBlackLevelDeltaHCount;
174 		uint64 fBlackLevelDeltaHOffset;
175 
176 		uint32 fBlackLevelDeltaVType;
177 		uint32 fBlackLevelDeltaVCount;
178 		uint64 fBlackLevelDeltaVOffset;
179 
180 		real64 fWhiteLevel [kMaxSamplesPerPixel];
181 
182 		dng_urational fDefaultScaleH;
183 		dng_urational fDefaultScaleV;
184 
185 		dng_urational fBestQualityScale;
186 
187 		dng_urational fDefaultCropOriginH;
188 		dng_urational fDefaultCropOriginV;
189 
190 		dng_urational fDefaultCropSizeH;
191 		dng_urational fDefaultCropSizeV;
192 
193 		dng_urational fDefaultUserCropT;
194 		dng_urational fDefaultUserCropL;
195 		dng_urational fDefaultUserCropB;
196 		dng_urational fDefaultUserCropR;
197 
198 		uint32 fBayerGreenSplit;
199 
200 		dng_urational fChromaBlurRadius;
201 
202 		dng_urational fAntiAliasStrength;
203 
204 		dng_rect fActiveArea;
205 
206 		uint32   fMaskedAreaCount;
207 		dng_rect fMaskedArea [kMaxMaskedAreas];
208 
209 		uint32 fRowInterleaveFactor;
210 
211 		uint32 fSubTileBlockRows;
212 		uint32 fSubTileBlockCols;
213 
214 		dng_preview_info fPreviewInfo;
215 
216 		uint32 fOpcodeList1Count;
217 		uint64 fOpcodeList1Offset;
218 
219 		uint32 fOpcodeList2Count;
220 		uint64 fOpcodeList2Offset;
221 
222 		uint32 fOpcodeList3Count;
223 		uint64 fOpcodeList3Offset;
224 
225 		bool fLosslessJPEGBug16;
226 
227 		uint32 fSampleBitShift;
228 
229 		uint64 fThisIFD;
230 		uint64 fNextIFD;
231 
232 		int32 fCompressionQuality;
233 
234 		bool fPatchFirstJPEGByte;
235 
236 	public:
237 
238 		dng_ifd ();
239 
240 		virtual ~dng_ifd ();
241 
242 		virtual bool ParseTag (dng_stream &stream,
243 							   uint32 parentCode,
244 							   uint32 tagCode,
245 							   uint32 tagType,
246 							   uint32 tagCount,
247 							   uint64 tagOffset);
248 
249 		virtual void PostParse ();
250 
251 		virtual bool IsValidDNG (dng_shared &shared,
252 								 uint32 parentCode);
253 
Bounds()254 		dng_rect Bounds () const
255 			{
256 			return dng_rect (0,
257 							 0,
258 							 fImageLength,
259 							 fImageWidth);
260 			}
261 
262 		uint32 TilesAcross () const;
263 
264 		uint32 TilesDown () const;
265 
266 		uint32 TilesPerImage () const;
267 
268 		dng_rect TileArea (uint32 rowIndex,
269 						   uint32 colIndex) const;
270 
271 		virtual uint32 TileByteCount (const dng_rect &tile) const;
272 
273 		void SetSingleStrip ();
274 
275 		void FindTileSize (uint32 bytesPerTile = 128 * 1024,
276 						   uint32 cellH = 16,
277 						   uint32 cellV = 16);
278 
279 		void FindStripSize (uint32 bytesPerStrip = 128 * 1024,
280 						    uint32 cellV = 16);
281 
282 		virtual uint32 PixelType () const;
283 
284 		virtual bool IsBaselineJPEG () const;
285 
286 		virtual bool CanRead () const;
287 
288 		virtual void ReadImage (dng_host &host,
289 								dng_stream &stream,
290 								dng_image &image,
291 								dng_jpeg_image *jpegImage = NULL,
292 								dng_fingerprint *jpegDigest = NULL) const;
293 
294 	protected:
295 
296 		virtual bool IsValidCFA (dng_shared &shared,
297 					      		 uint32 parentCode);
298 
299 	};
300 
301 /*****************************************************************************/
302 
303 #endif
304 
305 /*****************************************************************************/
306