1 /*****************************************************************************/
2 // Copyright 2006-2011 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_linearization_info.h#1 $ */
10 /* $DateTime: 2012/05/30 13:28:51 $ */
11 /* $Change: 832332 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  * Support for linearization table and black level tags.
16  */
17 
18 /*****************************************************************************/
19 
20 #ifndef __dng_linearization_info__
21 #define __dng_linearization_info__
22 
23 /*****************************************************************************/
24 
25 #include "dng_auto_ptr.h"
26 #include "dng_classes.h"
27 #include "dng_memory.h"
28 #include "dng_rational.h"
29 #include "dng_rect.h"
30 #include "dng_sdk_limits.h"
31 
32 /*****************************************************************************/
33 
34 /// \brief Class for managing data values related to DNG linearization.
35 ///
36 /// See LinearizationTable, BlackLevel, BlackLevelRepeatDim, BlackLevelDeltaH,
37 /// BlackLevelDeltaV and WhiteLevel tags in the \ref spec_dng "DNG 1.1.0 specification".
38 
39 class dng_linearization_info
40 	{
41 
42 	public:
43 
44 		/// This rectangle defines the active (non-masked) pixels of the sensor.
45 		/// The order of the rectangle coordinates is: top, left, bottom, right.
46 
47 		dng_rect fActiveArea;
48 
49 		/// Number of rectangles in fMaskedArea
50 
51 		uint32 fMaskedAreaCount;
52 
53 		/// List of non-overlapping rectangle coordinates of fully masked pixels.
54 		/// Can be optionally used by DNG readers to measure the black encoding level.
55 		/// The order of each rectangle's coordinates is: top, left, bottom, right.
56 		/// If the raw image data has already had its black encoding level subtracted, then this tag should
57 		/// not be used, since the masked pixels are no longer useful.
58 		/// Note that DNG writers are still required to include an estimate and store the black encoding level
59 		/// using the black level DNG tags. Support for the MaskedAreas tag is not required of DNG
60 		/// readers.
61 
62 		dng_rect fMaskedArea [kMaxMaskedAreas];
63 
64 		/// A lookup table that maps stored values into linear values.
65 		/// This tag is typically used to increase compression ratios by storing the raw data in a non-linear, more
66 		/// visually uniform space with fewer total encoding levels.
67 		/// If SamplesPerPixel is not equal to one, e.g. Fuji S3 type sensor, this single table applies to all the samples for each
68 		/// pixel.
69 
70 		AutoPtr<dng_memory_block> fLinearizationTable;
71 
72 		/// Actual number of rows in fBlackLevel pattern
73 
74 		uint32 fBlackLevelRepeatRows;
75 
76 		/// Actual number of columns in fBlackLevel pattern
77 
78 		uint32 fBlackLevelRepeatCols;
79 
80 		/// Repeating pattern of black level deltas fBlackLevelRepeatRows by fBlackLevelRepeatCols in size.
81 
82 		real64 fBlackLevel [kMaxBlackPattern] [kMaxBlackPattern] [kMaxSamplesPerPixel];
83 
84 		/// Memory block of double-precision floating point deltas between baseline black level and a given column's black level
85 
86 		AutoPtr<dng_memory_block> fBlackDeltaH;
87 
88 		/// Memory block of double-precision floating point deltas between baseline black level and a given row's black level
89 
90 		AutoPtr<dng_memory_block> fBlackDeltaV;
91 
92 		/// Single white level (maximum sensor value) for each sample plane.
93 
94 		real64 fWhiteLevel [kMaxSamplesPerPixel];
95 
96 	protected:
97 
98 		int32 fBlackDenom;
99 
100 	public:
101 
102 		dng_linearization_info ();
103 
104 		virtual ~dng_linearization_info ();
105 
106 		void RoundBlacks ();
107 
108 		virtual void Parse (dng_host &host,
109 						    dng_stream &stream,
110 						    dng_info &info);
111 
112 		virtual void PostParse (dng_host &host,
113 								dng_negative &negative);
114 
115 		/// Compute the maximum black level for a given sample plane taking into account base
116 		/// black level, repeated black level patter, and row/column delta maps.
117 
118 		real64 MaxBlackLevel (uint32 plane) const;
119 
120 		/// Convert raw data from in-file format to a true linear image using linearization data from DNG.
121 		/// \param host Used to allocate buffers, check for aborts, and post progress updates.
122 		/// \param srcImage Input pre-linearization RAW samples.
123 		/// \param dstImage Output linearized image.
124 
125 		virtual void Linearize (dng_host &host,
126 								const dng_image &srcImage,
127 								dng_image &dstImage);
128 
129 		/// Compute black level for one coordinate and sample plane in the image.
130 		/// \param row Row to compute black level for.
131 		/// \param col Column to compute black level for.
132 		/// \param plane Sample plane to compute black level for.
133 
134 		dng_urational BlackLevel (uint32 row,
135 								  uint32 col,
136 								  uint32 plane) const;
137 
138 		/// Number of per-row black level deltas in fBlackDeltaV.
139 
140 		uint32 RowBlackCount () const;
141 
142 		/// Lookup black level delta for a given row.
143 		/// \param row Row to get black level for.
144 		/// \retval black level for indicated row.
145 
146 		dng_srational RowBlack (uint32 row) const;
147 
148 		/// Number of per-column black level deltas in fBlackDeltaV.
149 
150 		uint32 ColumnBlackCount () const;
151 
152 		/// Lookup black level delta for a given column.
153 		/// \param col Column to get black level for.
154 		/// \retval black level for indicated column.
155 
156 		dng_srational ColumnBlack (uint32 col) const;
157 
158 	};
159 
160 /*****************************************************************************/
161 
162 #endif
163 
164 /*****************************************************************************/
165