/src/dng_sdk/source/dng_resample.h
Line | Count | Source |
1 | | /*****************************************************************************/ |
2 | | // Copyright 2006-2007 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_resample.h#1 $ */ |
10 | | /* $DateTime: 2012/05/30 13:28:51 $ */ |
11 | | /* $Change: 832332 $ */ |
12 | | /* $Author: tknoll $ */ |
13 | | |
14 | | /*****************************************************************************/ |
15 | | |
16 | | #ifndef __dng_resample__ |
17 | | #define __dng_resample__ |
18 | | |
19 | | /*****************************************************************************/ |
20 | | |
21 | | #include "dng_assertions.h" |
22 | | #include "dng_auto_ptr.h" |
23 | | #include "dng_classes.h" |
24 | | #include "dng_memory.h" |
25 | | #include "dng_point.h" |
26 | | #include "dng_types.h" |
27 | | |
28 | | /*****************************************************************************/ |
29 | | |
30 | | class dng_resample_function |
31 | | { |
32 | | |
33 | | public: |
34 | | |
35 | | dng_resample_function () |
36 | 3 | { |
37 | 3 | } |
38 | | |
39 | | virtual ~dng_resample_function () |
40 | 3 | { |
41 | 3 | } |
42 | | |
43 | | virtual real64 Extent () const = 0; |
44 | | |
45 | | virtual real64 Evaluate (real64 x) const = 0; |
46 | | |
47 | | }; |
48 | | |
49 | | /*****************************************************************************/ |
50 | | |
51 | | class dng_resample_bicubic: public dng_resample_function |
52 | | { |
53 | | |
54 | | public: |
55 | | |
56 | | virtual real64 Extent () const; |
57 | | |
58 | | virtual real64 Evaluate (real64 x) const; |
59 | | |
60 | | static const dng_resample_function & Get (); |
61 | | |
62 | | }; |
63 | | |
64 | | /******************************************************************************/ |
65 | | |
66 | | const uint32 kResampleSubsampleBits = 7; |
67 | | const uint32 kResampleSubsampleCount = 1 << kResampleSubsampleBits; |
68 | | const uint32 kResampleSubsampleMask = kResampleSubsampleCount - 1; |
69 | | |
70 | | /*****************************************************************************/ |
71 | | |
72 | | class dng_resample_coords |
73 | | { |
74 | | |
75 | | protected: |
76 | | |
77 | | int32 fOrigin; |
78 | | |
79 | | AutoPtr<dng_memory_block> fCoords; |
80 | | |
81 | | public: |
82 | | |
83 | | dng_resample_coords (); |
84 | | |
85 | | virtual ~dng_resample_coords (); |
86 | | |
87 | | void Initialize (int32 srcOrigin, |
88 | | int32 dstOrigin, |
89 | | uint32 srcCount, |
90 | | uint32 dstCount, |
91 | | dng_memory_allocator &allocator); |
92 | | |
93 | | const int32 * Coords (int32 index) const |
94 | 5.02M | { |
95 | 5.02M | return fCoords->Buffer_int32 () + (index - fOrigin); |
96 | 5.02M | } |
97 | | |
98 | | const int32 Pixel (int32 index) const |
99 | 3.35M | { |
100 | 3.35M | return Coords (index) [0] >> kResampleSubsampleBits; |
101 | 3.35M | } |
102 | | |
103 | | }; |
104 | | |
105 | | /*****************************************************************************/ |
106 | | |
107 | | class dng_resample_weights |
108 | | { |
109 | | |
110 | | protected: |
111 | | |
112 | | uint32 fRadius; |
113 | | |
114 | | uint32 fWeightStep; |
115 | | |
116 | | AutoPtr<dng_memory_block> fWeights32; |
117 | | AutoPtr<dng_memory_block> fWeights16; |
118 | | |
119 | | public: |
120 | | |
121 | | dng_resample_weights (); |
122 | | |
123 | | virtual ~dng_resample_weights (); |
124 | | |
125 | | void Initialize (real64 scale, |
126 | | const dng_resample_function &kernel, |
127 | | dng_memory_allocator &allocator); |
128 | | |
129 | | uint32 Radius () const |
130 | 0 | { |
131 | 0 | return fRadius; |
132 | 0 | } |
133 | | |
134 | | uint32 Width () const |
135 | 3.36M | { |
136 | 3.36M | return fRadius * 2; |
137 | 3.36M | } |
138 | | |
139 | | int32 Offset () const |
140 | 3.35M | { |
141 | 3.35M | return 1 - (int32) fRadius; |
142 | 3.35M | } |
143 | | |
144 | | uint32 Step () const |
145 | 837k | { |
146 | 837k | return fWeightStep; |
147 | 837k | } |
148 | | |
149 | | const real32 *Weights32 (uint32 fract) const |
150 | 22.1M | { |
151 | | |
152 | 22.1M | DNG_ASSERT (fWeights32->Buffer (), "Weights32 is NULL"); |
153 | | |
154 | 22.1M | if (fract >= kResampleSubsampleCount) |
155 | 0 | { |
156 | | |
157 | 0 | ThrowBadFormat (); |
158 | | |
159 | 0 | } |
160 | | |
161 | 22.1M | return fWeights32->Buffer_real32 () + fract * fWeightStep; |
162 | | |
163 | 22.1M | } |
164 | | |
165 | | const int16 *Weights16 (uint32 fract) const |
166 | 27.7M | { |
167 | | |
168 | 27.7M | DNG_ASSERT (fWeights16->Buffer (), "Weights16 is NULL"); |
169 | | |
170 | 27.7M | if (fract >= kResampleSubsampleCount) |
171 | 0 | { |
172 | | |
173 | 0 | ThrowBadFormat (); |
174 | | |
175 | 0 | } |
176 | | |
177 | 27.7M | return fWeights16->Buffer_int16 () + fract * fWeightStep; |
178 | | |
179 | 27.7M | } |
180 | | |
181 | | }; |
182 | | |
183 | | /*****************************************************************************/ |
184 | | |
185 | | const uint32 kResampleSubsampleBits2D = 5; |
186 | | const uint32 kResampleSubsampleCount2D = 1 << kResampleSubsampleBits2D; |
187 | | const uint32 kResampleSubsampleMask2D = kResampleSubsampleCount2D - 1; |
188 | | |
189 | | /*****************************************************************************/ |
190 | | |
191 | | class dng_resample_weights_2d |
192 | | { |
193 | | |
194 | | protected: |
195 | | |
196 | | uint32 fRadius; |
197 | | |
198 | | uint32 fRowStep; |
199 | | uint32 fColStep; |
200 | | |
201 | | AutoPtr<dng_memory_block> fWeights32; |
202 | | AutoPtr<dng_memory_block> fWeights16; |
203 | | |
204 | | public: |
205 | | |
206 | | dng_resample_weights_2d (); |
207 | | |
208 | | virtual ~dng_resample_weights_2d (); |
209 | | |
210 | | void Initialize (const dng_resample_function &kernel, |
211 | | dng_memory_allocator &allocator); |
212 | | |
213 | | uint32 Radius () const |
214 | 0 | { |
215 | 0 | return fRadius; |
216 | 0 | } |
217 | | |
218 | | uint32 Width () const |
219 | 0 | { |
220 | 0 | return fRadius * 2; |
221 | 0 | } |
222 | | |
223 | | int32 Offset () const |
224 | 0 | { |
225 | 0 | return 1 - (int32) fRadius; |
226 | 0 | } |
227 | | |
228 | | uint32 RowStep () const |
229 | 0 | { |
230 | 0 | return fRowStep; |
231 | 0 | } |
232 | | |
233 | | uint32 ColStep () const |
234 | 0 | { |
235 | 0 | return fColStep; |
236 | 0 | } |
237 | | |
238 | | const real32 *Weights32 (dng_point fract) const |
239 | 0 | { |
240 | | |
241 | 0 | DNG_ASSERT (fWeights32->Buffer (), "Weights32 is NULL"); |
242 | | |
243 | 0 | if (fract.v < 0 || fract.h < 0 |
244 | 0 | || fract.v >= static_cast<int32>(kResampleSubsampleCount2D) |
245 | 0 | || fract.h >= static_cast<int32>(kResampleSubsampleCount2D)) |
246 | 0 | { |
247 | | |
248 | 0 | ThrowBadFormat (); |
249 | | |
250 | 0 | } |
251 | | |
252 | 0 | const uint32 offset = fract.v * fRowStep + fract.h * fColStep; |
253 | | |
254 | 0 | return fWeights32->Buffer_real32 () + offset; |
255 | | |
256 | 0 | } |
257 | | |
258 | | const int16 *Weights16 (dng_point fract) const |
259 | 0 | { |
260 | | |
261 | 0 | DNG_ASSERT (fWeights16->Buffer (), "Weights16 is NULL"); |
262 | | |
263 | 0 | if (fract.v < 0 || fract.h < 0 |
264 | 0 | || fract.v >= static_cast<int32>(kResampleSubsampleCount2D) |
265 | 0 | || fract.h >= static_cast<int32>(kResampleSubsampleCount2D)) |
266 | 0 | { |
267 | | |
268 | 0 | ThrowBadFormat (); |
269 | | |
270 | 0 | } |
271 | | |
272 | 0 | const uint32 offset = fract.v * fRowStep + fract.h * fColStep; |
273 | | |
274 | 0 | return fWeights16->Buffer_int16 () + offset; |
275 | | |
276 | 0 | } |
277 | | |
278 | | }; |
279 | | |
280 | | /*****************************************************************************/ |
281 | | |
282 | | void ResampleImage (dng_host &host, |
283 | | const dng_image &srcImage, |
284 | | dng_image &dstImage, |
285 | | const dng_rect &srcBounds, |
286 | | const dng_rect &dstBounds, |
287 | | const dng_resample_function &kernel); |
288 | | |
289 | | /*****************************************************************************/ |
290 | | |
291 | | #endif |
292 | | |
293 | | /*****************************************************************************/ |