1 | /*****************************************************************************/ |
2 | // Copyright 2008-2009 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_gain_map.h#2 $ */ |
10 | /* $DateTime: 2012/07/31 22:04:34 $ */ |
11 | /* $Change: 840853 $ */ |
12 | /* $Author: tknoll $ */ |
13 | |
14 | /** \file |
15 | * Opcode to fix 2D uniformity defects, such as shading. |
16 | */ |
17 | |
18 | /*****************************************************************************/ |
19 | |
20 | #ifndef __dng_gain_map__ |
21 | #define __dng_gain_map__ |
22 | |
23 | /*****************************************************************************/ |
24 | |
25 | #include "dng_memory.h" |
26 | #include "dng_misc_opcodes.h" |
27 | #include "dng_tag_types.h" |
28 | |
29 | /*****************************************************************************/ |
30 | |
31 | /// \brief Holds a discrete (i.e., sampled) 2D representation of a gain map. This is |
32 | /// effectively an image containing scale factors. |
33 | |
34 | class dng_gain_map |
35 | { |
36 | |
37 | private: |
38 | |
39 | dng_point fPoints; |
40 | |
41 | dng_point_real64 fSpacing; |
42 | |
43 | dng_point_real64 fOrigin; |
44 | |
45 | uint32 fPlanes; |
46 | |
47 | uint32 fRowStep; |
48 | |
49 | AutoPtr<dng_memory_block> fBuffer; |
50 | |
51 | public: |
52 | |
53 | /// Construct a gain map with the specified memory allocator, number of |
54 | /// samples (points), sample spacing, origin, and number of color planes. |
55 | |
56 | dng_gain_map (dng_memory_allocator &allocator, |
57 | const dng_point &points, |
58 | const dng_point_real64 &spacing, |
59 | const dng_point_real64 &origin, |
60 | uint32 planes); |
61 | |
62 | /// The number of samples in the horizontal and vertical directions. |
63 | |
64 | const dng_point & Points () const |
65 | { |
66 | return fPoints; |
67 | } |
68 | |
69 | /// The space between adjacent samples in the horizontal and vertical |
70 | /// directions. |
71 | |
72 | const dng_point_real64 & Spacing () const |
73 | { |
74 | return fSpacing; |
75 | } |
76 | |
77 | /// The 2D coordinate for the first (i.e., top-left-most) sample. |
78 | |
79 | const dng_point_real64 & Origin () const |
80 | { |
81 | return fOrigin; |
82 | } |
83 | |
84 | /// The number of color planes. |
85 | |
86 | uint32 Planes () const |
87 | { |
88 | return fPlanes; |
89 | } |
90 | |
91 | /// Getter for a gain map sample (specified by row, column, and plane). |
92 | |
93 | real32 & Entry (uint32 rowIndex, |
94 | uint32 colIndex, |
95 | uint32 plane) |
96 | { |
97 | |
98 | return *(fBuffer->Buffer_real32 () + |
99 | rowIndex * fRowStep + |
100 | colIndex * fPlanes + |
101 | plane); |
102 | |
103 | } |
104 | |
105 | /// Getter for a gain map sample (specified by row index, column index, and |
106 | /// plane index). |
107 | |
108 | const real32 & Entry (uint32 rowIndex, |
109 | uint32 colIndex, |
110 | uint32 plane) const |
111 | { |
112 | |
113 | return *(fBuffer->Buffer_real32 () + |
114 | rowIndex * fRowStep + |
115 | colIndex * fPlanes + |
116 | plane); |
117 | |
118 | } |
119 | |
120 | /// Compute the interpolated gain (i.e., scale factor) at the specified pixel |
121 | /// position and color plane, within the specified image bounds (in pixels). |
122 | |
123 | real32 Interpolate (int32 row, |
124 | int32 col, |
125 | uint32 plane, |
126 | const dng_rect &bounds) const; |
127 | |
128 | /// The number of bytes needed to hold the gain map data. |
129 | |
130 | uint32 PutStreamSize () const; |
131 | |
132 | /// Write the gain map to the specified stream. |
133 | |
134 | void PutStream (dng_stream &stream) const; |
135 | |
136 | /// Read a gain map from the specified stream. |
137 | |
138 | static dng_gain_map * GetStream (dng_host &host, |
139 | dng_stream &stream); |
140 | |
141 | private: |
142 | |
143 | // Hidden copy constructor and assignment operator. |
144 | |
145 | dng_gain_map (const dng_gain_map &map); |
146 | |
147 | dng_gain_map & operator= (const dng_gain_map &map); |
148 | |
149 | }; |
150 | |
151 | /*****************************************************************************/ |
152 | |
153 | /// \brief An opcode to fix 2D spatially-varying light falloff or color casts (i.e., |
154 | /// uniformity issues). This is commonly due to shading. |
155 | |
156 | class dng_opcode_GainMap: public dng_inplace_opcode |
157 | { |
158 | |
159 | private: |
160 | |
161 | dng_area_spec fAreaSpec; |
162 | |
163 | AutoPtr<dng_gain_map> fGainMap; |
164 | |
165 | public: |
166 | |
167 | /// Construct a GainMap opcode for the specified image area and the specified |
168 | /// gain map. |
169 | |
170 | dng_opcode_GainMap (const dng_area_spec &areaSpec, |
171 | AutoPtr<dng_gain_map> &gainMap); |
172 | |
173 | /// Construct a GainMap opcode from the specified stream. |
174 | |
175 | dng_opcode_GainMap (dng_host &host, |
176 | dng_stream &stream); |
177 | |
178 | /// Write the opcode to the specified stream. |
179 | |
180 | virtual void PutData (dng_stream &stream) const; |
181 | |
182 | /// The pixel data type of this opcode. |
183 | |
184 | virtual uint32 BufferPixelType (uint32 /* imagePixelType */) |
185 | { |
186 | return ttFloat; |
187 | } |
188 | |
189 | /// The adjusted bounds (processing area) of this opcode. It is limited to |
190 | /// the intersection of the specified image area and the GainMap area. |
191 | |
192 | virtual dng_rect ModifiedBounds (const dng_rect &imageBounds) |
193 | { |
194 | return fAreaSpec.Overlap (imageBounds); |
195 | } |
196 | |
197 | /// Apply the gain map. |
198 | |
199 | virtual void ProcessArea (dng_negative &negative, |
200 | uint32 threadIndex, |
201 | dng_pixel_buffer &buffer, |
202 | const dng_rect &dstArea, |
203 | const dng_rect &imageBounds); |
204 | |
205 | private: |
206 | |
207 | // Hidden copy constructor and assignment operator. |
208 | |
209 | dng_opcode_GainMap (const dng_opcode_GainMap &opcode); |
210 | |
211 | dng_opcode_GainMap & operator= (const dng_opcode_GainMap &opcode); |
212 | |
213 | }; |
214 | |
215 | /*****************************************************************************/ |
216 | |
217 | #endif |
218 | |
219 | /*****************************************************************************/ |
220 | |