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