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
30class dng_resample_function
31 {
32
33 public:
34
35 dng_resample_function ()
36 {
37 }
38
39 virtual ~dng_resample_function ()
40 {
41 }
42
43 virtual real64 Extent () const = 0;
44
45 virtual real64 Evaluate (real64 x) const = 0;
46
47 };
48
49/*****************************************************************************/
50
51class 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
66const uint32 kResampleSubsampleBits = 7;
67const uint32 kResampleSubsampleCount = 1 << kResampleSubsampleBits;
68const uint32 kResampleSubsampleMask = kResampleSubsampleCount - 1;
69
70/*****************************************************************************/
71
72class 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 {
95 return fCoords->Buffer_int32 () + (index - fOrigin);
96 }
97
98 const int32 Pixel (int32 index) const
99 {
100 return Coords (index) [0] >> kResampleSubsampleBits;
101 }
102
103 };
104
105/*****************************************************************************/
106
107class 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 {
131 return fRadius;
132 }
133
134 uint32 Width () const
135 {
136 return fRadius * 2;
137 }
138
139 int32 Offset () const
140 {
141 return 1 - (int32) fRadius;
142 }
143
144 uint32 Step () const
145 {
146 return fWeightStep;
147 }
148
149 const real32 *Weights32 (uint32 fract) const
150 {
151
152 DNG_ASSERT (fWeights32->Buffer (), "Weights32 is NULL");
153
154 if (fract >= kResampleSubsampleCount)
155 {
156
157 ThrowBadFormat ();
158
159 }
160
161 return fWeights32->Buffer_real32 () + fract * fWeightStep;
162
163 }
164
165 const int16 *Weights16 (uint32 fract) const
166 {
167
168 DNG_ASSERT (fWeights16->Buffer (), "Weights16 is NULL");
169
170 if (fract >= kResampleSubsampleCount)
171 {
172
173 ThrowBadFormat ();
174
175 }
176
177 return fWeights16->Buffer_int16 () + fract * fWeightStep;
178
179 }
180
181 };
182
183/*****************************************************************************/
184
185const uint32 kResampleSubsampleBits2D = 5;
186const uint32 kResampleSubsampleCount2D = 1 << kResampleSubsampleBits2D;
187const uint32 kResampleSubsampleMask2D = kResampleSubsampleCount2D - 1;
188
189/*****************************************************************************/
190
191class 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 {
215 return fRadius;
216 }
217
218 uint32 Width () const
219 {
220 return fRadius * 2;
221 }
222
223 int32 Offset () const
224 {
225 return 1 - (int32) fRadius;
226 }
227
228 uint32 RowStep () const
229 {
230 return fRowStep;
231 }
232
233 uint32 ColStep () const
234 {
235 return fColStep;
236 }
237
238 const real32 *Weights32 (dng_point fract) const
239 {
240
241 DNG_ASSERT (fWeights32->Buffer (), "Weights32 is NULL");
242
243 if (fract.v < 0 || fract.h < 0
244 || fract.v >= static_cast<int32>(kResampleSubsampleCount2D)
245 || fract.h >= static_cast<int32>(kResampleSubsampleCount2D))
246 {
247
248 ThrowBadFormat ();
249
250 }
251
252 const uint32 offset = fract.v * fRowStep + fract.h * fColStep;
253
254 return fWeights32->Buffer_real32 () + offset;
255
256 }
257
258 const int16 *Weights16 (dng_point fract) const
259 {
260
261 DNG_ASSERT (fWeights16->Buffer (), "Weights16 is NULL");
262
263 if (fract.v < 0 || fract.h < 0
264 || fract.v >= static_cast<int32>(kResampleSubsampleCount2D)
265 || fract.h >= static_cast<int32>(kResampleSubsampleCount2D))
266 {
267
268 ThrowBadFormat ();
269
270 }
271
272 const uint32 offset = fract.v * fRowStep + fract.h * fColStep;
273
274 return fWeights16->Buffer_int16 () + offset;
275
276 }
277
278 };
279
280/*****************************************************************************/
281
282void 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/*****************************************************************************/
294