cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % RRRR EEEEE SSSSS AAA M M PPPP L EEEEE % |
| 7 | % R R E SS A A MM MM P P L E % |
| 8 | % RRRR EEE SSS AAAAA M M M PPPP L EEE % |
| 9 | % R R E SS A A M M P L E % |
| 10 | % R R EEEEE SSSSS A A M M P LLLLL EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Pixel Resampling Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % Anthony Thyssen % |
| 18 | % August 2007 % |
| 19 | % % |
| 20 | % % |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 21 | % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 22 | % dedicated to making software imaging solutions freely available. % |
| 23 | % % |
| 24 | % You may not use this file except in compliance with the License. You may % |
| 25 | % obtain a copy of the License at % |
| 26 | % % |
| 27 | % http://www.imagemagick.org/script/license.php % |
| 28 | % % |
| 29 | % Unless required by applicable law or agreed to in writing, software % |
| 30 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 31 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 32 | % See the License for the specific language governing permissions and % |
| 33 | % limitations under the License. % |
| 34 | % % |
| 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
| 43 | #include "magick/studio.h" |
| 44 | #include "magick/artifact.h" |
| 45 | #include "magick/color-private.h" |
| 46 | #include "magick/cache.h" |
| 47 | #include "magick/draw.h" |
| 48 | #include "magick/exception-private.h" |
| 49 | #include "magick/gem.h" |
| 50 | #include "magick/image.h" |
| 51 | #include "magick/image-private.h" |
| 52 | #include "magick/log.h" |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 53 | #include "magick/magick.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 54 | #include "magick/memory_.h" |
| 55 | #include "magick/pixel-private.h" |
| 56 | #include "magick/quantum.h" |
| 57 | #include "magick/random_.h" |
| 58 | #include "magick/resample.h" |
| 59 | #include "magick/resize.h" |
| 60 | #include "magick/resize-private.h" |
| 61 | #include "magick/transform.h" |
| 62 | #include "magick/signature-private.h" |
| 63 | /* |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 64 | EWA Resampling Options |
| 65 | */ |
| 66 | #define WLUT_WIDTH 1024 /* size of the filter cache */ |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 67 | |
| 68 | /* select ONE resampling method */ |
| 69 | #define EWA 1 /* Normal EWA handling - raw or clamped */ |
| 70 | /* if 0 then use "High Quality EWA" */ |
| 71 | #define EWA_CLAMP 1 /* EWA Clamping from Nicolas Robidoux */ |
| 72 | |
| 73 | /* output debugging information */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 74 | #define DEBUG_ELLIPSE 0 /* output ellipse info for debug */ |
anthony | 2e6ab68 | 2010-09-28 12:02:25 +0000 | [diff] [blame] | 75 | #define DEBUG_HIT_MISS 0 /* output hit/miss pixels (as gnuplot commands) */ |
| 76 | #define DEBUG_NO_PIXEL_HIT 0 /* Make pixels that fail to hit anything - RED */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 77 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 78 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 79 | Typedef declarations. |
| 80 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 81 | struct _ResampleFilter |
| 82 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 83 | CacheView |
| 84 | *view; |
| 85 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 86 | Image |
| 87 | *image; |
| 88 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 89 | ExceptionInfo |
| 90 | *exception; |
| 91 | |
| 92 | MagickBooleanType |
| 93 | debug; |
| 94 | |
| 95 | /* Information about image being resampled */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 96 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 97 | image_area; |
| 98 | |
| 99 | InterpolatePixelMethod |
| 100 | interpolate; |
| 101 | |
| 102 | VirtualPixelMethod |
| 103 | virtual_pixel; |
| 104 | |
| 105 | FilterTypes |
| 106 | filter; |
| 107 | |
| 108 | /* processing settings needed */ |
| 109 | MagickBooleanType |
| 110 | limit_reached, |
| 111 | do_interpolate, |
| 112 | average_defined; |
| 113 | |
| 114 | MagickPixelPacket |
| 115 | average_pixel; |
| 116 | |
| 117 | /* current ellipitical area being resampled around center point */ |
| 118 | double |
| 119 | A, B, C, |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 120 | Vlimit, Ulimit, Uwidth, slope; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 121 | |
| 122 | /* LUT of weights for filtered average in elliptical area */ |
| 123 | double |
| 124 | filter_lut[WLUT_WIDTH], |
| 125 | support; |
| 126 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 127 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | signature; |
| 129 | }; |
| 130 | |
| 131 | /* |
| 132 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 133 | % % |
| 134 | % % |
| 135 | % % |
| 136 | % A c q u i r e R e s a m p l e I n f o % |
| 137 | % % |
| 138 | % % |
| 139 | % % |
| 140 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 141 | % |
| 142 | % AcquireResampleFilter() initializes the information resample needs do to a |
| 143 | % scaled lookup of a color from an image, using area sampling. |
| 144 | % |
| 145 | % The algorithm is based on a Elliptical Weighted Average, where the pixels |
| 146 | % found in a large elliptical area is averaged together according to a |
| 147 | % weighting (filter) function. For more details see "Fundamentals of Texture |
| 148 | % Mapping and Image Warping" a master's thesis by Paul.S.Heckbert, June 17, |
| 149 | % 1989. Available for free from, http://www.cs.cmu.edu/~ph/ |
| 150 | % |
| 151 | % As EWA resampling (or any sort of resampling) can require a lot of |
| 152 | % calculations to produce a distorted scaling of the source image for each |
| 153 | % output pixel, the ResampleFilter structure generated holds that information |
| 154 | % between individual image resampling. |
| 155 | % |
| 156 | % This function will make the appropriate AcquireCacheView() calls |
| 157 | % to view the image, calling functions do not need to open a cache view. |
| 158 | % |
| 159 | % Usage Example... |
| 160 | % resample_filter=AcquireResampleFilter(image,exception); |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 161 | % SetResampleFilter(resample_filter, GaussianFilter, 1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 162 | % for (y=0; y < (ssize_t) image->rows; y++) { |
| 163 | % for (x=0; x < (ssize_t) image->columns; x++) { |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 164 | % u= ....; v= ....; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | % ScaleResampleFilter(resample_filter, ... scaling vectors ...); |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 166 | % (void) ResamplePixelColor(resample_filter,u,v,&pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | % ... assign resampled pixel value ... |
| 168 | % } |
| 169 | % } |
| 170 | % DestroyResampleFilter(resample_filter); |
| 171 | % |
| 172 | % The format of the AcquireResampleFilter method is: |
| 173 | % |
| 174 | % ResampleFilter *AcquireResampleFilter(const Image *image, |
| 175 | % ExceptionInfo *exception) |
| 176 | % |
| 177 | % A description of each parameter follows: |
| 178 | % |
| 179 | % o image: the image. |
| 180 | % |
| 181 | % o exception: return any errors or warnings in this structure. |
| 182 | % |
| 183 | */ |
| 184 | MagickExport ResampleFilter *AcquireResampleFilter(const Image *image, |
| 185 | ExceptionInfo *exception) |
| 186 | { |
| 187 | register ResampleFilter |
| 188 | *resample_filter; |
| 189 | |
| 190 | assert(image != (Image *) NULL); |
| 191 | assert(image->signature == MagickSignature); |
| 192 | if (image->debug != MagickFalse) |
| 193 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 194 | assert(exception != (ExceptionInfo *) NULL); |
| 195 | assert(exception->signature == MagickSignature); |
| 196 | |
| 197 | resample_filter=(ResampleFilter *) AcquireMagickMemory( |
| 198 | sizeof(*resample_filter)); |
| 199 | if (resample_filter == (ResampleFilter *) NULL) |
| 200 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 201 | (void) ResetMagickMemory(resample_filter,0,sizeof(*resample_filter)); |
| 202 | |
| 203 | resample_filter->image=ReferenceImage((Image *) image); |
| 204 | resample_filter->view=AcquireCacheView(resample_filter->image); |
| 205 | resample_filter->exception=exception; |
| 206 | |
| 207 | resample_filter->debug=IsEventLogging(); |
| 208 | resample_filter->signature=MagickSignature; |
| 209 | |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 210 | resample_filter->image_area=(ssize_t) (resample_filter->image->columns* |
| 211 | resample_filter->image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 212 | resample_filter->average_defined = MagickFalse; |
| 213 | |
| 214 | /* initialise the resampling filter settings */ |
| 215 | SetResampleFilter(resample_filter, resample_filter->image->filter, |
| 216 | resample_filter->image->blur); |
anthony | 7294979 | 2010-10-08 04:44:56 +0000 | [diff] [blame] | 217 | SetResampleFilterInterpolateMethod(resample_filter, |
| 218 | resample_filter->image->interpolate); |
| 219 | SetResampleFilterVirtualPixelMethod(resample_filter, |
| 220 | GetImageVirtualPixelMethod(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 221 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 222 | return(resample_filter); |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 227 | % % |
| 228 | % % |
| 229 | % % |
| 230 | % D e s t r o y R e s a m p l e I n f o % |
| 231 | % % |
| 232 | % % |
| 233 | % % |
| 234 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 235 | % |
| 236 | % DestroyResampleFilter() finalizes and cleans up the resampling |
| 237 | % resample_filter as returned by AcquireResampleFilter(), freeing any memory |
| 238 | % or other information as needed. |
| 239 | % |
| 240 | % The format of the DestroyResampleFilter method is: |
| 241 | % |
| 242 | % ResampleFilter *DestroyResampleFilter(ResampleFilter *resample_filter) |
| 243 | % |
| 244 | % A description of each parameter follows: |
| 245 | % |
| 246 | % o resample_filter: resampling information structure |
| 247 | % |
| 248 | */ |
| 249 | MagickExport ResampleFilter *DestroyResampleFilter( |
| 250 | ResampleFilter *resample_filter) |
| 251 | { |
| 252 | assert(resample_filter != (ResampleFilter *) NULL); |
| 253 | assert(resample_filter->signature == MagickSignature); |
| 254 | assert(resample_filter->image != (Image *) NULL); |
| 255 | if (resample_filter->debug != MagickFalse) |
| 256 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 257 | resample_filter->image->filename); |
| 258 | resample_filter->view=DestroyCacheView(resample_filter->view); |
| 259 | resample_filter->image=DestroyImage(resample_filter->image); |
| 260 | resample_filter->signature=(~MagickSignature); |
| 261 | resample_filter=(ResampleFilter *) RelinquishMagickMemory(resample_filter); |
| 262 | return(resample_filter); |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 267 | % % |
| 268 | % % |
| 269 | % % |
| 270 | % I n t e r p o l a t e R e s a m p l e F i l t e r % |
| 271 | % % |
| 272 | % % |
| 273 | % % |
| 274 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 275 | % |
| 276 | % InterpolateResampleFilter() applies bi-linear or tri-linear interpolation |
| 277 | % between a floating point coordinate and the pixels surrounding that |
| 278 | % coordinate. No pixel area resampling, or scaling of the result is |
| 279 | % performed. |
| 280 | % |
| 281 | % The format of the InterpolateResampleFilter method is: |
| 282 | % |
| 283 | % MagickBooleanType InterpolateResampleFilter( |
| 284 | % ResampleInfo *resample_filter,const InterpolatePixelMethod method, |
| 285 | % const double x,const double y,MagickPixelPacket *pixel) |
| 286 | % |
| 287 | % A description of each parameter follows: |
| 288 | % |
| 289 | % o resample_filter: the resample filter. |
| 290 | % |
| 291 | % o method: the pixel clor interpolation method. |
| 292 | % |
| 293 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 294 | % |
| 295 | % o pixel: return the interpolated pixel here. |
| 296 | % |
| 297 | */ |
| 298 | |
| 299 | static inline double MagickMax(const double x,const double y) |
| 300 | { |
| 301 | if (x > y) |
| 302 | return(x); |
| 303 | return(y); |
| 304 | } |
| 305 | |
| 306 | static void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx, |
| 307 | MagickPixelPacket *pixel) |
| 308 | { |
| 309 | MagickRealType |
| 310 | dx2, |
| 311 | p, |
| 312 | q, |
| 313 | r, |
| 314 | s; |
| 315 | |
| 316 | dx2=dx*dx; |
| 317 | p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red); |
| 318 | q=(pixels[0].red-pixels[1].red)-p; |
| 319 | r=pixels[2].red-pixels[0].red; |
| 320 | s=pixels[1].red; |
| 321 | pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 322 | p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green); |
| 323 | q=(pixels[0].green-pixels[1].green)-p; |
| 324 | r=pixels[2].green-pixels[0].green; |
| 325 | s=pixels[1].green; |
| 326 | pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 327 | p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue); |
| 328 | q=(pixels[0].blue-pixels[1].blue)-p; |
| 329 | r=pixels[2].blue-pixels[0].blue; |
| 330 | s=pixels[1].blue; |
| 331 | pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 332 | p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity); |
| 333 | q=(pixels[0].opacity-pixels[1].opacity)-p; |
| 334 | r=pixels[2].opacity-pixels[0].opacity; |
| 335 | s=pixels[1].opacity; |
| 336 | pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 337 | if (pixel->colorspace == CMYKColorspace) |
| 338 | { |
| 339 | p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index); |
| 340 | q=(pixels[0].index-pixels[1].index)-p; |
| 341 | r=pixels[2].index-pixels[0].index; |
| 342 | s=pixels[1].index; |
| 343 | pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | static inline MagickRealType CubicWeightingFunction(const MagickRealType x) |
| 348 | { |
| 349 | MagickRealType |
| 350 | alpha, |
| 351 | gamma; |
| 352 | |
| 353 | alpha=MagickMax(x+2.0,0.0); |
| 354 | gamma=1.0*alpha*alpha*alpha; |
| 355 | alpha=MagickMax(x+1.0,0.0); |
| 356 | gamma-=4.0*alpha*alpha*alpha; |
| 357 | alpha=MagickMax(x+0.0,0.0); |
| 358 | gamma+=6.0*alpha*alpha*alpha; |
| 359 | alpha=MagickMax(x-1.0,0.0); |
| 360 | gamma-=4.0*alpha*alpha*alpha; |
| 361 | return(gamma/6.0); |
| 362 | } |
| 363 | |
| 364 | static inline double MeshInterpolate(const PointInfo *delta,const double p, |
| 365 | const double x,const double y) |
| 366 | { |
| 367 | return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); |
| 368 | } |
| 369 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 370 | static inline ssize_t NearestNeighbor(MagickRealType x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 371 | { |
| 372 | if (x >= 0.0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 373 | return((ssize_t) (x+0.5)); |
| 374 | return((ssize_t) (x-0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static MagickBooleanType InterpolateResampleFilter( |
| 378 | ResampleFilter *resample_filter,const InterpolatePixelMethod method, |
| 379 | const double x,const double y,MagickPixelPacket *pixel) |
| 380 | { |
| 381 | MagickBooleanType |
| 382 | status; |
| 383 | |
| 384 | register const IndexPacket |
| 385 | *indexes; |
| 386 | |
| 387 | register const PixelPacket |
| 388 | *p; |
| 389 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 390 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | i; |
| 392 | |
| 393 | assert(resample_filter != (ResampleFilter *) NULL); |
| 394 | assert(resample_filter->signature == MagickSignature); |
| 395 | status=MagickTrue; |
anthony | 2e6ab68 | 2010-09-28 12:02:25 +0000 | [diff] [blame] | 396 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 397 | switch (method) |
| 398 | { |
| 399 | case AverageInterpolatePixel: |
| 400 | { |
| 401 | MagickPixelPacket |
| 402 | pixels[16]; |
| 403 | |
| 404 | MagickRealType |
| 405 | alpha[16], |
| 406 | gamma; |
| 407 | |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 408 | p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x)-1, |
| 409 | (ssize_t) floor(y)-1,4,4,resample_filter->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 410 | if (p == (const PixelPacket *) NULL) |
| 411 | { |
| 412 | status=MagickFalse; |
| 413 | break; |
| 414 | } |
| 415 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 416 | for (i=0; i < 16L; i++) |
| 417 | { |
| 418 | GetMagickPixelPacket(resample_filter->image,pixels+i); |
| 419 | SetMagickPixelPacket(resample_filter->image,p,indexes+i,pixels+i); |
| 420 | alpha[i]=1.0; |
| 421 | if (resample_filter->image->matte != MagickFalse) |
| 422 | { |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 423 | alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 424 | pixels[i].red*=alpha[i]; |
| 425 | pixels[i].green*=alpha[i]; |
| 426 | pixels[i].blue*=alpha[i]; |
| 427 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 428 | pixels[i].index*=alpha[i]; |
| 429 | } |
| 430 | gamma=alpha[i]; |
| 431 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 432 | pixel->red+=gamma*0.0625*pixels[i].red; |
| 433 | pixel->green+=gamma*0.0625*pixels[i].green; |
| 434 | pixel->blue+=gamma*0.0625*pixels[i].blue; |
| 435 | pixel->opacity+=0.0625*pixels[i].opacity; |
| 436 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 437 | pixel->index+=gamma*0.0625*pixels[i].index; |
| 438 | p++; |
| 439 | } |
| 440 | break; |
| 441 | } |
| 442 | case BicubicInterpolatePixel: |
| 443 | { |
| 444 | MagickPixelPacket |
| 445 | pixels[16], |
| 446 | u[4]; |
| 447 | |
| 448 | MagickRealType |
| 449 | alpha[16]; |
| 450 | |
| 451 | PointInfo |
| 452 | delta; |
| 453 | |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 454 | p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x)-1, |
| 455 | (ssize_t) floor(y)-1,4,4,resample_filter->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 456 | if (p == (const PixelPacket *) NULL) |
| 457 | { |
| 458 | status=MagickFalse; |
| 459 | break; |
| 460 | } |
| 461 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 462 | for (i=0; i < 16L; i++) |
| 463 | { |
| 464 | GetMagickPixelPacket(resample_filter->image,pixels+i); |
| 465 | SetMagickPixelPacket(resample_filter->image,p,indexes+i,pixels+i); |
| 466 | alpha[i]=1.0; |
| 467 | if (resample_filter->image->matte != MagickFalse) |
| 468 | { |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 469 | alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 470 | pixels[i].red*=alpha[i]; |
| 471 | pixels[i].green*=alpha[i]; |
| 472 | pixels[i].blue*=alpha[i]; |
| 473 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 474 | pixels[i].index*=alpha[i]; |
| 475 | } |
| 476 | p++; |
| 477 | } |
| 478 | delta.x=x-floor(x); |
| 479 | for (i=0; i < 4L; i++) |
| 480 | BicubicInterpolate(pixels+4*i,delta.x,u+i); |
| 481 | delta.y=y-floor(y); |
| 482 | BicubicInterpolate(u,delta.y,pixel); |
| 483 | break; |
| 484 | } |
| 485 | case BilinearInterpolatePixel: |
| 486 | default: |
| 487 | { |
| 488 | MagickPixelPacket |
| 489 | pixels[4]; |
| 490 | |
| 491 | MagickRealType |
| 492 | alpha[4], |
| 493 | gamma; |
| 494 | |
| 495 | PointInfo |
| 496 | delta, |
| 497 | epsilon; |
| 498 | |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 499 | p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x), |
| 500 | (ssize_t) floor(y),2,2,resample_filter->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 501 | if (p == (const PixelPacket *) NULL) |
| 502 | { |
| 503 | status=MagickFalse; |
| 504 | break; |
| 505 | } |
| 506 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 507 | for (i=0; i < 4L; i++) |
| 508 | { |
| 509 | pixels[i].red=(MagickRealType) p[i].red; |
| 510 | pixels[i].green=(MagickRealType) p[i].green; |
| 511 | pixels[i].blue=(MagickRealType) p[i].blue; |
| 512 | pixels[i].opacity=(MagickRealType) p[i].opacity; |
| 513 | alpha[i]=1.0; |
| 514 | } |
| 515 | if (resample_filter->image->matte != MagickFalse) |
| 516 | for (i=0; i < 4L; i++) |
| 517 | { |
| 518 | alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p[i].opacity); |
| 519 | pixels[i].red*=alpha[i]; |
| 520 | pixels[i].green*=alpha[i]; |
| 521 | pixels[i].blue*=alpha[i]; |
| 522 | } |
| 523 | if (indexes != (IndexPacket *) NULL) |
| 524 | for (i=0; i < 4L; i++) |
| 525 | { |
| 526 | pixels[i].index=(MagickRealType) indexes[i]; |
| 527 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 528 | pixels[i].index*=alpha[i]; |
| 529 | } |
| 530 | delta.x=x-floor(x); |
| 531 | delta.y=y-floor(y); |
| 532 | epsilon.x=1.0-delta.x; |
| 533 | epsilon.y=1.0-delta.y; |
| 534 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 535 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 536 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 537 | pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x* |
| 538 | pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red)); |
| 539 | pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x* |
| 540 | pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x* |
| 541 | pixels[3].green)); |
| 542 | pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x* |
| 543 | pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x* |
| 544 | pixels[3].blue)); |
| 545 | pixel->opacity=(epsilon.y*(epsilon.x*pixels[0].opacity+delta.x* |
| 546 | pixels[1].opacity)+delta.y*(epsilon.x*pixels[2].opacity+delta.x* |
| 547 | pixels[3].opacity)); |
| 548 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 549 | pixel->index=gamma*(epsilon.y*(epsilon.x*pixels[0].index+delta.x* |
| 550 | pixels[1].index)+delta.y*(epsilon.x*pixels[2].index+delta.x* |
| 551 | pixels[3].index)); |
| 552 | break; |
| 553 | } |
| 554 | case FilterInterpolatePixel: |
| 555 | { |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 556 | CacheView |
| 557 | *filter_view; |
| 558 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | Image |
| 560 | *excerpt_image, |
| 561 | *filter_image; |
| 562 | |
| 563 | MagickPixelPacket |
| 564 | pixels[1]; |
| 565 | |
| 566 | RectangleInfo |
| 567 | geometry; |
| 568 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 569 | geometry.width=4L; |
| 570 | geometry.height=4L; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 571 | geometry.x=(ssize_t) floor(x)-1L; |
| 572 | geometry.y=(ssize_t) floor(y)-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 573 | excerpt_image=ExcerptImage(resample_filter->image,&geometry, |
| 574 | resample_filter->exception); |
| 575 | if (excerpt_image == (Image *) NULL) |
| 576 | { |
| 577 | status=MagickFalse; |
| 578 | break; |
| 579 | } |
| 580 | filter_image=ResizeImage(excerpt_image,1,1,resample_filter->image->filter, |
| 581 | resample_filter->image->blur,resample_filter->exception); |
| 582 | excerpt_image=DestroyImage(excerpt_image); |
| 583 | if (filter_image == (Image *) NULL) |
| 584 | break; |
| 585 | filter_view=AcquireCacheView(filter_image); |
| 586 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1, |
| 587 | resample_filter->exception); |
| 588 | if (p != (const PixelPacket *) NULL) |
| 589 | { |
| 590 | indexes=GetVirtualIndexQueue(filter_image); |
| 591 | GetMagickPixelPacket(resample_filter->image,pixels); |
| 592 | SetMagickPixelPacket(resample_filter->image,p,indexes,pixel); |
| 593 | } |
| 594 | filter_view=DestroyCacheView(filter_view); |
| 595 | filter_image=DestroyImage(filter_image); |
| 596 | break; |
| 597 | } |
| 598 | case IntegerInterpolatePixel: |
| 599 | { |
| 600 | MagickPixelPacket |
| 601 | pixels[1]; |
| 602 | |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 603 | p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x), |
| 604 | (ssize_t) floor(y),1,1,resample_filter->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | if (p == (const PixelPacket *) NULL) |
| 606 | { |
| 607 | status=MagickFalse; |
| 608 | break; |
| 609 | } |
| 610 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 611 | GetMagickPixelPacket(resample_filter->image,pixels); |
| 612 | SetMagickPixelPacket(resample_filter->image,p,indexes,pixel); |
| 613 | break; |
| 614 | } |
| 615 | case MeshInterpolatePixel: |
| 616 | { |
| 617 | MagickPixelPacket |
| 618 | pixels[4]; |
| 619 | |
| 620 | MagickRealType |
| 621 | alpha[4], |
| 622 | gamma; |
| 623 | |
| 624 | PointInfo |
| 625 | delta, |
| 626 | luminance; |
| 627 | |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 628 | p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x), |
| 629 | (ssize_t) floor(y),2,2,resample_filter->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 630 | if (p == (const PixelPacket *) NULL) |
| 631 | { |
| 632 | status=MagickFalse; |
| 633 | break; |
| 634 | } |
| 635 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 636 | for (i=0; i < 4L; i++) |
| 637 | { |
| 638 | GetMagickPixelPacket(resample_filter->image,pixels+i); |
| 639 | SetMagickPixelPacket(resample_filter->image,p,indexes+i,pixels+i); |
| 640 | alpha[i]=1.0; |
| 641 | if (resample_filter->image->matte != MagickFalse) |
| 642 | { |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 643 | alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | pixels[i].red*=alpha[i]; |
| 645 | pixels[i].green*=alpha[i]; |
| 646 | pixels[i].blue*=alpha[i]; |
| 647 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 648 | pixels[i].index*=alpha[i]; |
| 649 | } |
| 650 | p++; |
| 651 | } |
| 652 | delta.x=x-floor(x); |
| 653 | delta.y=y-floor(y); |
| 654 | luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3); |
| 655 | luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2); |
| 656 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 657 | { |
| 658 | /* |
| 659 | Diagonal 0-3 NW-SE. |
| 660 | */ |
| 661 | if (delta.x <= delta.y) |
| 662 | { |
| 663 | /* |
| 664 | Bottom-left triangle (pixel:2, diagonal: 0-3). |
| 665 | */ |
| 666 | delta.y=1.0-delta.y; |
| 667 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 668 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 669 | pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red, |
| 670 | pixels[3].red,pixels[0].red); |
| 671 | pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green, |
| 672 | pixels[3].green,pixels[0].green); |
| 673 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue, |
| 674 | pixels[3].blue,pixels[0].blue); |
| 675 | pixel->opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity, |
| 676 | pixels[3].opacity,pixels[0].opacity); |
| 677 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 678 | pixel->index=gamma*MeshInterpolate(&delta,pixels[2].index, |
| 679 | pixels[3].index,pixels[0].index); |
| 680 | } |
| 681 | else |
| 682 | { |
| 683 | /* |
| 684 | Top-right triangle (pixel:1, diagonal: 0-3). |
| 685 | */ |
| 686 | delta.x=1.0-delta.x; |
| 687 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 688 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 689 | pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red, |
| 690 | pixels[0].red,pixels[3].red); |
| 691 | pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green, |
| 692 | pixels[0].green,pixels[3].green); |
| 693 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue, |
| 694 | pixels[0].blue,pixels[3].blue); |
| 695 | pixel->opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity, |
| 696 | pixels[0].opacity,pixels[3].opacity); |
| 697 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 698 | pixel->index=gamma*MeshInterpolate(&delta,pixels[1].index, |
| 699 | pixels[0].index,pixels[3].index); |
| 700 | } |
| 701 | } |
| 702 | else |
| 703 | { |
| 704 | /* |
| 705 | Diagonal 1-2 NE-SW. |
| 706 | */ |
| 707 | if (delta.x <= (1.0-delta.y)) |
| 708 | { |
| 709 | /* |
| 710 | Top-left triangle (pixel 0, diagonal: 1-2). |
| 711 | */ |
| 712 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 713 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 714 | pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red, |
| 715 | pixels[1].red,pixels[2].red); |
| 716 | pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green, |
| 717 | pixels[1].green,pixels[2].green); |
| 718 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue, |
| 719 | pixels[1].blue,pixels[2].blue); |
| 720 | pixel->opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity, |
| 721 | pixels[1].opacity,pixels[2].opacity); |
| 722 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 723 | pixel->index=gamma*MeshInterpolate(&delta,pixels[0].index, |
| 724 | pixels[1].index,pixels[2].index); |
| 725 | } |
| 726 | else |
| 727 | { |
| 728 | /* |
| 729 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 730 | */ |
| 731 | delta.x=1.0-delta.x; |
| 732 | delta.y=1.0-delta.y; |
| 733 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 734 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 735 | pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red, |
| 736 | pixels[2].red,pixels[1].red); |
| 737 | pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green, |
| 738 | pixels[2].green,pixels[1].green); |
| 739 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue, |
| 740 | pixels[2].blue,pixels[1].blue); |
| 741 | pixel->opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity, |
| 742 | pixels[2].opacity,pixels[1].opacity); |
| 743 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 744 | pixel->index=gamma*MeshInterpolate(&delta,pixels[3].index, |
| 745 | pixels[2].index,pixels[1].index); |
| 746 | } |
| 747 | } |
| 748 | break; |
| 749 | } |
| 750 | case NearestNeighborInterpolatePixel: |
| 751 | { |
| 752 | MagickPixelPacket |
| 753 | pixels[1]; |
| 754 | |
| 755 | p=GetCacheViewVirtualPixels(resample_filter->view,NearestNeighbor(x), |
| 756 | NearestNeighbor(y),1,1,resample_filter->exception); |
| 757 | if (p == (const PixelPacket *) NULL) |
| 758 | { |
| 759 | status=MagickFalse; |
| 760 | break; |
| 761 | } |
| 762 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 763 | GetMagickPixelPacket(resample_filter->image,pixels); |
| 764 | SetMagickPixelPacket(resample_filter->image,p,indexes,pixel); |
| 765 | break; |
| 766 | } |
| 767 | case SplineInterpolatePixel: |
| 768 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 769 | MagickPixelPacket |
| 770 | pixels[16]; |
| 771 | |
| 772 | MagickRealType |
| 773 | alpha[16], |
| 774 | dx, |
| 775 | dy, |
| 776 | gamma; |
| 777 | |
| 778 | PointInfo |
| 779 | delta; |
| 780 | |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 781 | ssize_t |
| 782 | j, |
| 783 | n; |
| 784 | |
| 785 | p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x)-1, |
| 786 | (ssize_t) floor(y)-1,4,4,resample_filter->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 787 | if (p == (const PixelPacket *) NULL) |
| 788 | { |
| 789 | status=MagickFalse; |
| 790 | break; |
| 791 | } |
| 792 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 793 | n=0; |
| 794 | delta.x=x-floor(x); |
| 795 | delta.y=y-floor(y); |
| 796 | for (i=(-1); i < 3L; i++) |
| 797 | { |
| 798 | dy=CubicWeightingFunction((MagickRealType) i-delta.y); |
| 799 | for (j=(-1); j < 3L; j++) |
| 800 | { |
| 801 | GetMagickPixelPacket(resample_filter->image,pixels+n); |
| 802 | SetMagickPixelPacket(resample_filter->image,p,indexes+n,pixels+n); |
| 803 | alpha[n]=1.0; |
| 804 | if (resample_filter->image->matte != MagickFalse) |
| 805 | { |
cristy | 54ffe7c | 2010-07-04 23:54:03 +0000 | [diff] [blame] | 806 | alpha[n]=QuantumScale*((MagickRealType) |
| 807 | GetAlphaPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 808 | pixels[n].red*=alpha[n]; |
| 809 | pixels[n].green*=alpha[n]; |
| 810 | pixels[n].blue*=alpha[n]; |
| 811 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 812 | pixels[n].index*=alpha[n]; |
| 813 | } |
| 814 | dx=CubicWeightingFunction(delta.x-(MagickRealType) j); |
| 815 | gamma=alpha[n]; |
| 816 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 817 | pixel->red+=gamma*dx*dy*pixels[n].red; |
| 818 | pixel->green+=gamma*dx*dy*pixels[n].green; |
| 819 | pixel->blue+=gamma*dx*dy*pixels[n].blue; |
| 820 | if (resample_filter->image->matte != MagickFalse) |
| 821 | pixel->opacity+=dx*dy*pixels[n].opacity; |
| 822 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 823 | pixel->index+=gamma*dx*dy*pixels[n].index; |
| 824 | n++; |
| 825 | p++; |
| 826 | } |
| 827 | } |
| 828 | break; |
| 829 | } |
| 830 | } |
| 831 | return(status); |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 836 | % % |
| 837 | % % |
| 838 | % % |
| 839 | % R e s a m p l e P i x e l C o l o r % |
| 840 | % % |
| 841 | % % |
| 842 | % % |
| 843 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 844 | % |
| 845 | % ResamplePixelColor() samples the pixel values surrounding the location |
| 846 | % given using an elliptical weighted average, at the scale previously |
| 847 | % calculated, and in the most efficent manner possible for the |
| 848 | % VirtualPixelMethod setting. |
| 849 | % |
| 850 | % The format of the ResamplePixelColor method is: |
| 851 | % |
| 852 | % MagickBooleanType ResamplePixelColor(ResampleFilter *resample_filter, |
| 853 | % const double u0,const double v0,MagickPixelPacket *pixel) |
| 854 | % |
| 855 | % A description of each parameter follows: |
| 856 | % |
| 857 | % o resample_filter: the resample filter. |
| 858 | % |
| 859 | % o u0,v0: A double representing the center of the area to resample, |
| 860 | % The distortion transformed transformed x,y coordinate. |
| 861 | % |
| 862 | % o pixel: the resampled pixel is returned here. |
| 863 | % |
| 864 | */ |
| 865 | MagickExport MagickBooleanType ResamplePixelColor( |
| 866 | ResampleFilter *resample_filter,const double u0,const double v0, |
| 867 | MagickPixelPacket *pixel) |
| 868 | { |
| 869 | MagickBooleanType |
| 870 | status; |
| 871 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 872 | ssize_t u,v, v1, v2, uw, hit; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 873 | double u1; |
| 874 | double U,V,Q,DQ,DDQ; |
| 875 | double divisor_c,divisor_m; |
| 876 | register double weight; |
| 877 | register const PixelPacket *pixels; |
| 878 | register const IndexPacket *indexes; |
| 879 | assert(resample_filter != (ResampleFilter *) NULL); |
| 880 | assert(resample_filter->signature == MagickSignature); |
| 881 | |
| 882 | status=MagickTrue; |
| 883 | GetMagickPixelPacket(resample_filter->image,pixel); |
| 884 | if ( resample_filter->do_interpolate ) { |
| 885 | status=InterpolateResampleFilter(resample_filter, |
| 886 | resample_filter->interpolate,u0,v0,pixel); |
| 887 | return(status); |
| 888 | } |
| 889 | |
anthony | 2e6ab68 | 2010-09-28 12:02:25 +0000 | [diff] [blame] | 890 | #if DEBUG_ELLIPSE |
| 891 | fprintf(stderr, "u0=%lf; v0=%lf;\n", u0, v0); |
| 892 | #endif |
| 893 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 894 | /* |
| 895 | Does resample area Miss the image? |
| 896 | And is that area a simple solid color - then return that color |
| 897 | */ |
| 898 | hit = 0; |
| 899 | switch ( resample_filter->virtual_pixel ) { |
| 900 | case BackgroundVirtualPixelMethod: |
| 901 | case ConstantVirtualPixelMethod: |
| 902 | case TransparentVirtualPixelMethod: |
| 903 | case BlackVirtualPixelMethod: |
| 904 | case GrayVirtualPixelMethod: |
| 905 | case WhiteVirtualPixelMethod: |
| 906 | case MaskVirtualPixelMethod: |
| 907 | if ( resample_filter->limit_reached |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 908 | || u0 + resample_filter->Ulimit < 0.0 |
| 909 | || u0 - resample_filter->Ulimit > (double) resample_filter->image->columns |
| 910 | || v0 + resample_filter->Vlimit < 0.0 |
| 911 | || v0 - resample_filter->Vlimit > (double) resample_filter->image->rows |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 912 | ) |
| 913 | hit++; |
| 914 | break; |
| 915 | |
| 916 | case UndefinedVirtualPixelMethod: |
| 917 | case EdgeVirtualPixelMethod: |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 918 | if ( ( u0 + resample_filter->Ulimit < 0.0 && v0 + resample_filter->Vlimit < 0.0 ) |
| 919 | || ( u0 + resample_filter->Ulimit < 0.0 |
| 920 | && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows ) |
| 921 | || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns |
| 922 | && v0 + resample_filter->Vlimit < 0.0 ) |
| 923 | || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns |
| 924 | && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 925 | ) |
| 926 | hit++; |
| 927 | break; |
| 928 | case HorizontalTileVirtualPixelMethod: |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 929 | if ( v0 + resample_filter->Vlimit < 0.0 |
| 930 | || v0 - resample_filter->Vlimit > (double) resample_filter->image->rows |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 931 | ) |
| 932 | hit++; /* outside the horizontally tiled images. */ |
| 933 | break; |
| 934 | case VerticalTileVirtualPixelMethod: |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 935 | if ( u0 + resample_filter->Ulimit < 0.0 |
| 936 | || u0 - resample_filter->Ulimit > (double) resample_filter->image->columns |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 937 | ) |
| 938 | hit++; /* outside the vertically tiled images. */ |
| 939 | break; |
| 940 | case DitherVirtualPixelMethod: |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 941 | if ( ( u0 + resample_filter->Ulimit < -32.0 && v0 + resample_filter->Vlimit < -32.0 ) |
| 942 | || ( u0 + resample_filter->Ulimit < -32.0 |
| 943 | && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows+32.0 ) |
| 944 | || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns+32.0 |
| 945 | && v0 + resample_filter->Vlimit < -32.0 ) |
| 946 | || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns+32.0 |
| 947 | && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows+32.0 ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 948 | ) |
| 949 | hit++; |
| 950 | break; |
| 951 | case TileVirtualPixelMethod: |
| 952 | case MirrorVirtualPixelMethod: |
| 953 | case RandomVirtualPixelMethod: |
| 954 | case HorizontalTileEdgeVirtualPixelMethod: |
| 955 | case VerticalTileEdgeVirtualPixelMethod: |
| 956 | case CheckerTileVirtualPixelMethod: |
| 957 | /* resampling of area is always needed - no VP limits */ |
| 958 | break; |
| 959 | } |
| 960 | if ( hit ) { |
| 961 | /* whole area is a solid color -- just return that color */ |
| 962 | status=InterpolateResampleFilter(resample_filter,IntegerInterpolatePixel, |
| 963 | u0,v0,pixel); |
| 964 | return(status); |
| 965 | } |
| 966 | |
| 967 | /* |
| 968 | Scaling limits reached, return an 'averaged' result. |
| 969 | */ |
| 970 | if ( resample_filter->limit_reached ) { |
| 971 | switch ( resample_filter->virtual_pixel ) { |
| 972 | /* This is always handled by the above, so no need. |
| 973 | case BackgroundVirtualPixelMethod: |
| 974 | case ConstantVirtualPixelMethod: |
| 975 | case TransparentVirtualPixelMethod: |
| 976 | case GrayVirtualPixelMethod, |
| 977 | case WhiteVirtualPixelMethod |
| 978 | case MaskVirtualPixelMethod: |
| 979 | */ |
| 980 | case UndefinedVirtualPixelMethod: |
| 981 | case EdgeVirtualPixelMethod: |
| 982 | case DitherVirtualPixelMethod: |
| 983 | case HorizontalTileEdgeVirtualPixelMethod: |
| 984 | case VerticalTileEdgeVirtualPixelMethod: |
anthony | 9b8a528 | 2010-09-15 07:48:39 +0000 | [diff] [blame] | 985 | /* We need an average edge pixel, from the correct edge! |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 986 | How should I calculate an average edge color? |
| 987 | Just returning an averaged neighbourhood, |
| 988 | works well in general, but falls down for TileEdge methods. |
| 989 | This needs to be done properly!!!!!! |
| 990 | */ |
| 991 | status=InterpolateResampleFilter(resample_filter, |
| 992 | AverageInterpolatePixel,u0,v0,pixel); |
| 993 | break; |
| 994 | case HorizontalTileVirtualPixelMethod: |
| 995 | case VerticalTileVirtualPixelMethod: |
| 996 | /* just return the background pixel - Is there more direct way? */ |
| 997 | status=InterpolateResampleFilter(resample_filter, |
| 998 | IntegerInterpolatePixel,(double)-1,(double)-1,pixel); |
| 999 | break; |
| 1000 | case TileVirtualPixelMethod: |
| 1001 | case MirrorVirtualPixelMethod: |
| 1002 | case RandomVirtualPixelMethod: |
| 1003 | case CheckerTileVirtualPixelMethod: |
| 1004 | default: |
| 1005 | /* generate a average color of the WHOLE image */ |
| 1006 | if ( resample_filter->average_defined == MagickFalse ) { |
| 1007 | Image |
| 1008 | *average_image; |
| 1009 | |
| 1010 | CacheView |
| 1011 | *average_view; |
| 1012 | |
| 1013 | GetMagickPixelPacket(resample_filter->image, |
| 1014 | (MagickPixelPacket *)&(resample_filter->average_pixel)); |
| 1015 | resample_filter->average_defined = MagickTrue; |
| 1016 | |
| 1017 | /* Try to get an averaged pixel color of whole image */ |
| 1018 | average_image=ResizeImage(resample_filter->image,1,1,BoxFilter,1.0, |
| 1019 | resample_filter->exception); |
| 1020 | if (average_image == (Image *) NULL) |
| 1021 | { |
| 1022 | *pixel=resample_filter->average_pixel; /* FAILED */ |
| 1023 | break; |
| 1024 | } |
| 1025 | average_view=AcquireCacheView(average_image); |
| 1026 | pixels=(PixelPacket *)GetCacheViewVirtualPixels(average_view,0,0,1,1, |
| 1027 | resample_filter->exception); |
| 1028 | if (pixels == (const PixelPacket *) NULL) { |
| 1029 | average_view=DestroyCacheView(average_view); |
| 1030 | average_image=DestroyImage(average_image); |
| 1031 | *pixel=resample_filter->average_pixel; /* FAILED */ |
| 1032 | break; |
| 1033 | } |
| 1034 | indexes=(IndexPacket *) GetCacheViewAuthenticIndexQueue(average_view); |
| 1035 | SetMagickPixelPacket(resample_filter->image,pixels,indexes, |
| 1036 | &(resample_filter->average_pixel)); |
| 1037 | average_view=DestroyCacheView(average_view); |
| 1038 | average_image=DestroyImage(average_image); |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1039 | |
| 1040 | if ( resample_filter->virtual_pixel == CheckerTileVirtualPixelMethod ) |
| 1041 | { |
| 1042 | /* CheckerTile is avergae of image average half background */ |
| 1043 | /* FUTURE: replace with a 50% blend of both pixels */ |
| 1044 | |
| 1045 | weight = QuantumScale*((MagickRealType)(QuantumRange- |
| 1046 | resample_filter->average_pixel.opacity)); |
| 1047 | resample_filter->average_pixel.red *= weight; |
| 1048 | resample_filter->average_pixel.green *= weight; |
| 1049 | resample_filter->average_pixel.blue *= weight; |
| 1050 | divisor_c = weight; |
| 1051 | |
| 1052 | weight = QuantumScale*((MagickRealType)(QuantumRange- |
| 1053 | resample_filter->image->background_color.opacity)); |
| 1054 | resample_filter->average_pixel.red += |
| 1055 | weight*resample_filter->image->background_color.red; |
| 1056 | resample_filter->average_pixel.green += |
| 1057 | weight*resample_filter->image->background_color.green; |
| 1058 | resample_filter->average_pixel.blue += |
| 1059 | weight*resample_filter->image->background_color.blue; |
| 1060 | resample_filter->average_pixel.matte += |
| 1061 | resample_filter->image->background_color.opacity; |
| 1062 | divisor_c += weight; |
| 1063 | |
| 1064 | resample_filter->average_pixel.red /= divisor_c; |
| 1065 | resample_filter->average_pixel.green /= divisor_c; |
| 1066 | resample_filter->average_pixel.blue /= divisor_c; |
| 1067 | resample_filter->average_pixel.matte /= 2; |
| 1068 | |
| 1069 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1070 | } |
| 1071 | *pixel=resample_filter->average_pixel; |
| 1072 | break; |
| 1073 | } |
| 1074 | return(status); |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | Initialize weighted average data collection |
| 1079 | */ |
| 1080 | hit = 0; |
| 1081 | divisor_c = 0.0; |
| 1082 | divisor_m = 0.0; |
| 1083 | pixel->red = pixel->green = pixel->blue = 0.0; |
| 1084 | if (resample_filter->image->matte != MagickFalse) pixel->opacity = 0.0; |
| 1085 | if (resample_filter->image->colorspace == CMYKColorspace) pixel->index = 0.0; |
| 1086 | |
| 1087 | /* |
| 1088 | Determine the parellelogram bounding box fitted to the ellipse |
| 1089 | centered at u0,v0. This area is bounding by the lines... |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1090 | */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1091 | v1 = (ssize_t)ceil(v0 - resample_filter->Vlimit); /* range of scan lines */ |
| 1092 | v2 = (ssize_t)floor(v0 + resample_filter->Vlimit); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1093 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1094 | /* scan line start and width accross the parallelogram */ |
| 1095 | u1 = u0 + (v1-v0)*resample_filter->slope - resample_filter->Uwidth; |
| 1096 | uw = (ssize_t)(2.0*resample_filter->Uwidth)+1; |
| 1097 | |
| 1098 | #if DEBUG_ELLIPSE |
| 1099 | fprintf(stderr, "v1=%ld; v2=%ld\n", (long)v1, (long)v2); |
| 1100 | fprintf(stderr, "u1=%ld; uw=%ld\n", (long)u1, (long)uw); |
| 1101 | #else |
| 1102 | # define DEBUG_HIT_MISS 0 /* only valid if DEBUG_ELLIPSE is enabled */ |
| 1103 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1104 | |
| 1105 | /* |
| 1106 | Do weighted resampling of all pixels, within the scaled ellipse, |
| 1107 | bound by a Parellelogram fitted to the ellipse. |
| 1108 | */ |
| 1109 | DDQ = 2*resample_filter->A; |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1110 | for( v=v1; v<=v2; v++ ) { |
| 1111 | #if DEBUG_HIT_MISS |
| 1112 | long uu = ceil(u1); /* actual pixel location (for debug only) */ |
| 1113 | fprintf(stderr, "# scan line from pixel %ld, %ld\n", (long)uu, (long)v); |
| 1114 | #endif |
| 1115 | u = (ssize_t)ceil(u1); /* first pixel in scanline */ |
| 1116 | u1 += resample_filter->slope; /* start of next scan line */ |
| 1117 | |
| 1118 | |
| 1119 | /* location of this first pixel, relative to u0,v0 */ |
| 1120 | U = (double)u-u0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1121 | V = (double)v-v0; |
| 1122 | |
| 1123 | /* Q = ellipse quotent ( if Q<F then pixel is inside ellipse) */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1124 | Q = (resample_filter->A*U + resample_filter->B*V)*U + resample_filter->C*V*V; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1125 | DQ = resample_filter->A*(2.0*U+1) + resample_filter->B*V; |
| 1126 | |
| 1127 | /* get the scanline of pixels for this v */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1128 | pixels=GetCacheViewVirtualPixels(resample_filter->view,u,v,(size_t) uw, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1129 | 1,resample_filter->exception); |
| 1130 | if (pixels == (const PixelPacket *) NULL) |
| 1131 | return(MagickFalse); |
| 1132 | indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); |
| 1133 | |
| 1134 | /* count up the weighted pixel colors */ |
| 1135 | for( u=0; u<uw; u++ ) { |
| 1136 | /* Note that the ellipse has been pre-scaled so F = WLUT_WIDTH */ |
| 1137 | if ( Q < (double)WLUT_WIDTH ) { |
| 1138 | weight = resample_filter->filter_lut[(int)Q]; |
| 1139 | |
| 1140 | pixel->opacity += weight*pixels->opacity; |
| 1141 | divisor_m += weight; |
| 1142 | |
| 1143 | if (resample_filter->image->matte != MagickFalse) |
| 1144 | weight *= QuantumScale*((MagickRealType)(QuantumRange-pixels->opacity)); |
| 1145 | pixel->red += weight*pixels->red; |
| 1146 | pixel->green += weight*pixels->green; |
| 1147 | pixel->blue += weight*pixels->blue; |
| 1148 | if (resample_filter->image->colorspace == CMYKColorspace) |
| 1149 | pixel->index += weight*(*indexes); |
| 1150 | divisor_c += weight; |
| 1151 | |
| 1152 | hit++; |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1153 | #if DEBUG_HIT_MISS |
| 1154 | /* mark the pixel according to hit/miss of the ellipse */ |
| 1155 | fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 3\n", |
| 1156 | (long)uu-.1,(double)v-.1,(long)uu+.1,(long)v+.1); |
| 1157 | fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 3\n", |
| 1158 | (long)uu+.1,(double)v-.1,(long)uu-.1,(long)v+.1); |
| 1159 | } else { |
| 1160 | fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 1\n", |
| 1161 | (long)uu-.1,(double)v-.1,(long)uu+.1,(long)v+.1); |
| 1162 | fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 1\n", |
| 1163 | (long)uu+.1,(double)v-.1,(long)uu-.1,(long)v+.1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1164 | } |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1165 | uu++; |
| 1166 | #else |
| 1167 | } |
| 1168 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1169 | pixels++; |
| 1170 | indexes++; |
| 1171 | Q += DQ; |
| 1172 | DQ += DDQ; |
| 1173 | } |
| 1174 | } |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1175 | #if DEBUG_ELLIPSE |
| 1176 | fprintf(stderr, "Hit=%ld; Total=%ld;\n", (long)hit, (long)uw*(v2-v1) ); |
| 1177 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1178 | |
| 1179 | /* |
| 1180 | Result sanity check -- this should NOT happen |
| 1181 | */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1182 | if ( hit == 0 ) { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1183 | /* not enough pixels in resampling, resort to direct interpolation */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1184 | #if DEBUG_NO_PIXEL_HIT |
anthony | 9b8a528 | 2010-09-15 07:48:39 +0000 | [diff] [blame] | 1185 | pixel->opacity = pixel->red = pixel->green = pixel->blue = 0; |
| 1186 | pixel->red = QuantumRange; /* show pixels for which EWA fails */ |
| 1187 | #else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1188 | status=InterpolateResampleFilter(resample_filter, |
| 1189 | resample_filter->interpolate,u0,v0,pixel); |
anthony | 9b8a528 | 2010-09-15 07:48:39 +0000 | [diff] [blame] | 1190 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1191 | return status; |
| 1192 | } |
| 1193 | |
| 1194 | /* |
| 1195 | Finialize results of resampling |
| 1196 | */ |
| 1197 | divisor_m = 1.0/divisor_m; |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1198 | pixel->opacity = (MagickRealType) ClampToQuantum(divisor_m*pixel->opacity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 | divisor_c = 1.0/divisor_c; |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1200 | pixel->red = (MagickRealType) ClampToQuantum(divisor_c*pixel->red); |
| 1201 | pixel->green = (MagickRealType) ClampToQuantum(divisor_c*pixel->green); |
| 1202 | pixel->blue = (MagickRealType) ClampToQuantum(divisor_c*pixel->blue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1203 | if (resample_filter->image->colorspace == CMYKColorspace) |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1204 | pixel->index = (MagickRealType) ClampToQuantum(divisor_c*pixel->index); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1205 | return(MagickTrue); |
| 1206 | } |
| 1207 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1208 | #if EWA && EWA_CLAMP |
| 1209 | /* |
| 1210 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1211 | % % |
| 1212 | % % |
| 1213 | % % |
| 1214 | - C l a m p U p A x e s % |
| 1215 | % % |
| 1216 | % % |
| 1217 | % % |
| 1218 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1219 | % |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1220 | % ClampUpAxes() function converts the input vectors into a major and |
| 1221 | % minor axis unit vectors, and their magnatude. This form allows us |
| 1222 | % to ensure that the ellipse generated is never smaller than the unit |
| 1223 | % circle and thus never too small for use in EWA resampling. |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1224 | % |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1225 | % This purely mathematical 'magic' was provided by Professor Nicolas |
| 1226 | % Robidoux and his Masters student Chantal Racette. |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1227 | % |
| 1228 | % See Reference: "We Recommend Singular Value Decomposition", David Austin |
| 1229 | % http://www.ams.org/samplings/feature-column/fcarc-svd |
| 1230 | % |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1231 | % By generating Major and Minor Axis vectors, we can actually use the |
| 1232 | % ellipse in its "canonical form", by remapping the dx,dy of the |
| 1233 | % sampled point into distances along the major and minor axis unit |
| 1234 | % vectors. |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1235 | % http://en.wikipedia.org/wiki/Ellipse#Canonical_form |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1236 | */ |
nicolas | 15c331b | 2010-09-29 19:05:00 +0000 | [diff] [blame] | 1237 | static inline void ClampUpAxes(const double dux, |
| 1238 | const double dvx, |
| 1239 | const double duy, |
| 1240 | const double dvy, |
| 1241 | double *major_mag, |
| 1242 | double *minor_mag, |
| 1243 | double *major_unit_x, |
| 1244 | double *major_unit_y, |
| 1245 | double *minor_unit_x, |
| 1246 | double *minor_unit_y) |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1247 | { |
| 1248 | /* |
| 1249 | * ClampUpAxes takes an input 2x2 matrix |
| 1250 | * |
| 1251 | * [ a b ] = [ dux duy ] |
| 1252 | * [ c d ] = [ dvx dvy ] |
| 1253 | * |
| 1254 | * and computes from it the major and minor axis vectors [major_x, |
| 1255 | * major_y] and [minor_x,minor_y] of the smallest ellipse containing |
| 1256 | * both the unit disk and the ellipse which is the image of the unit |
| 1257 | * disk by the linear transformation |
| 1258 | * |
| 1259 | * [ dux duy ] [S] = [s] |
| 1260 | * [ dvx dvy ] [T] = [t] |
| 1261 | * |
| 1262 | * (The vector [S,T] is the difference between a position in output |
| 1263 | * space and [X,Y]; the vector [s,t] is the difference between a |
| 1264 | * position in input space and [x,y].) |
| 1265 | */ |
| 1266 | /* |
| 1267 | * Outputs: |
| 1268 | * |
| 1269 | * major_mag is the half-length of the major axis of the "new" |
| 1270 | * ellipse (in input space). |
| 1271 | * |
| 1272 | * minor_mag is the half-length of the minor axis of the "new" |
| 1273 | * ellipse (in input space). |
| 1274 | * |
| 1275 | * major_unit_x is the x-coordinate of the major axis direction vector |
| 1276 | * of both the "old" and "new" ellipses. |
| 1277 | * |
| 1278 | * major_unit_y is the y-coordinate of the major axis direction vector. |
| 1279 | * |
| 1280 | * minor_unit_x is the x-coordinate of the minor axis direction vector. |
| 1281 | * |
| 1282 | * minor_unit_y is the y-coordinate of the minor axis direction vector. |
| 1283 | * |
| 1284 | * Unit vectors are useful for computing projections, in particular, |
| 1285 | * to compute the distance between a point in output space and the |
| 1286 | * center (of a disk) from the position of the corresponding point |
| 1287 | * in input space. |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1288 | * |
| 1289 | * Now, if you want to modify the input pair of tangent vectors so |
| 1290 | * that it defines the modified ellipse, all you have to do is set |
| 1291 | * |
nicolas | 8b1d981 | 2010-09-29 18:41:55 +0000 | [diff] [blame] | 1292 | * newdux = major_mag * major_unit_x |
| 1293 | * newdvx = major_mag * major_unit_y |
| 1294 | * newduy = minor_mag * minor_unit_x = minor_mag * -major_unit_y |
| 1295 | * newdvy = minor_mag * minor_unit_y = minor_mag * major_unit_x |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1296 | * |
| 1297 | * and use these new tangent vectors "as if" they were the original |
| 1298 | * ones. Most of the time this is a rather drastic change in the |
| 1299 | * tangent vectors (even if the singular values are large enough not |
| 1300 | * to be clampled). A technical explanation of why things still work |
| 1301 | * is found at the end of the discussion below. |
| 1302 | * |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1303 | */ |
| 1304 | /* |
| 1305 | * Discussion: |
| 1306 | * |
| 1307 | * GOAL: Fix things so that the pullback, in input space, of a disk |
| 1308 | * of radius r in output space is an ellipse which contains, at |
| 1309 | * least, a disc of radius r. (Make this hold for any r>0.) |
| 1310 | * |
| 1311 | * METHOD: Find the singular values and (unit) left singular vectors |
| 1312 | * of Jinv, clampling up the singular values to 1, and multiplying |
| 1313 | * the unit left singular vectors by the new singular values in |
| 1314 | * order to get the minor and major ellipse axis vectors. |
| 1315 | * |
| 1316 | * Inputs: |
| 1317 | * |
| 1318 | * The Jacobian matrix of the transformation at the output point |
| 1319 | * under consideration is defined as follows: |
| 1320 | * |
| 1321 | * Consider the transformation (x,y) -> (X,Y) from input locations |
nicolas | 8b1d981 | 2010-09-29 18:41:55 +0000 | [diff] [blame] | 1322 | * to output locations. (Anthony Thyssen, elsewhere in resample.c, |
| 1323 | * uses the notation (u,v) -> (x,y) instead of (x,y) -> (X,Y).) |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1324 | * |
| 1325 | * The Jacobian matrix J is equal to |
| 1326 | * |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1327 | * [ A, B ] = [ dX/dx, dX/dy ] |
| 1328 | * [ C, D ] = [ dY/dx, dY/dy ] |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1329 | * |
| 1330 | * Consequently, the vector [A,C] is the tangent vector |
| 1331 | * corresponding to input changes in the horizontal direction, and |
| 1332 | * the vector [B,D] is the tangent vector corresponding to input |
| 1333 | * changes in the vertical direction. |
| 1334 | * |
| 1335 | * In the context of resampling, it is more natural to use the |
| 1336 | * inverse Jacobian matrix Jinv. Jinv is |
| 1337 | * |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1338 | * [ a, b ] = [ dx/dX, dx/dY ] |
| 1339 | * [ c, d ] = [ dy/dX, dy/dY ] |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1340 | * |
| 1341 | * Note: Jinv can be computed from J with the following matrix |
| 1342 | * formula: |
| 1343 | * |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1344 | * Jinv = 1/(A*D-B*C) [ D, -B ] |
| 1345 | * [ -C, A ] |
| 1346 | * |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1347 | * What we (implicitly) want to do is replace Jinv by a new Jinv |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1348 | * which generates an ellipse which is as close as possible to the |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1349 | * original but which contains the unit disk. This is accomplished |
| 1350 | * as follows: |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1351 | * |
| 1352 | * Let |
| 1353 | * |
| 1354 | * Jinv = U Sigma V^T |
| 1355 | * |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1356 | * be an SVD decomposition of Jinv. (The SVD is not unique. The |
| 1357 | * final ellipse does not depend on the particular SVD.) In |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1358 | * principle, what we want is to clamp up the entries of the |
| 1359 | * diagonal matrix Sigma so that they are at least 1, and then set |
| 1360 | * |
| 1361 | * Jinv = U newSigma V^T. |
| 1362 | * |
| 1363 | * However, we do not need to compute V^T for the following reason: |
| 1364 | * V is an orthogonal matrix (that is, it represents a combination |
| 1365 | * of a rotation and a reflexion). Consequently, V maps the unit |
| 1366 | * circle to itself. For this reason, the exact value of V does not |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1367 | * affect the final ellipse, and we choose the identity matrix. |
| 1368 | * That is, we simply set |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1369 | * |
| 1370 | * Jinv = U newSigma, |
| 1371 | * |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1372 | * omitting the V^T factor altogether. In the end, we return the two |
| 1373 | * diagonal entries of newSigma together with the two columns of U, |
| 1374 | * for a total of six returned quantities. |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1375 | */ |
| 1376 | /* |
| 1377 | * ClampUpAxes was written by Nicolas Robidoux and Chantal Racette |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1378 | * of Laurentian University with funding from the National Science |
| 1379 | * and Engineering Research Council of Canada. |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1380 | * |
nicolas | 553b36e | 2010-09-27 18:23:16 +0000 | [diff] [blame] | 1381 | * The idea of using the SVD to clamp the singular values of the |
| 1382 | * linear part of the affine approximation of the pullback |
| 1383 | * transformation comes from the astrophysicist Craig DeForest, who |
| 1384 | * implemented it for use with (approximate) Gaussian filtering in |
nicolas | 8b1d981 | 2010-09-29 18:41:55 +0000 | [diff] [blame] | 1385 | * his PDL::Transform code (PDL = Perl Data Language). |
nicolas | 703291a | 2010-09-27 18:21:32 +0000 | [diff] [blame] | 1386 | * |
| 1387 | * The only (possibly) new math in the following is the selection of |
| 1388 | * the largest row of the eigen matrix system in order to stabilize |
| 1389 | * the computation in near rank-deficient cases, and the |
| 1390 | * corresponding efficient repair of degenerate cases using the norm |
| 1391 | * of this largest row. Omitting the "V^T" factor of the SVD may |
| 1392 | * also be a new "trick." |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1393 | */ |
| 1394 | const double a = dux; |
| 1395 | const double b = duy; |
| 1396 | const double c = dvx; |
| 1397 | const double d = dvy; |
| 1398 | /* |
| 1399 | * n is the matrix Jinv * transpose(Jinv). Eigenvalues of n are the |
| 1400 | * squares of the singular values of Jinv. |
| 1401 | */ |
| 1402 | const double aa = a*a; |
| 1403 | const double bb = b*b; |
| 1404 | const double cc = c*c; |
| 1405 | const double dd = d*d; |
| 1406 | /* |
| 1407 | * Eigenvectors of n are left singular vectors of Jinv. |
| 1408 | */ |
| 1409 | const double n11 = aa+bb; |
| 1410 | const double n12 = a*c+b*d; |
| 1411 | const double n21 = n12; |
| 1412 | const double n22 = cc+dd; |
| 1413 | const double det = a*d-b*c; |
| 1414 | const double twice_det = det+det; |
| 1415 | const double frobenius_squared = n11+n22; |
| 1416 | const double discriminant = |
| 1417 | (frobenius_squared+twice_det)*(frobenius_squared-twice_det); |
| 1418 | const double sqrt_discriminant = sqrt(discriminant); |
| 1419 | /* |
| 1420 | * s1 is the largest singular value of the inverse Jacobian |
| 1421 | * matrix. In other words, its reciprocal is the smallest singular |
| 1422 | * value of the Jacobian matrix itself. |
| 1423 | * If s1 = 0, both singular values are 0, and any orthogonal pair of |
| 1424 | * left and right factors produces a singular decomposition of Jinv. |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1425 | */ |
| 1426 | /* |
nicolas | 8b1d981 | 2010-09-29 18:41:55 +0000 | [diff] [blame] | 1427 | * Initially, we only compute the squares of the singular values. |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1428 | */ |
| 1429 | const double s1s1 = 0.5*(frobenius_squared+sqrt_discriminant); |
| 1430 | /* |
| 1431 | * s2 the smallest singular value of the inverse Jacobian |
| 1432 | * matrix. Its reciprocal is the largest singular value of the |
| 1433 | * Jacobian matrix itself. |
| 1434 | */ |
| 1435 | const double s2s2 = 0.5*(frobenius_squared-sqrt_discriminant); |
| 1436 | const double s1s1minusn11 = s1s1-n11; |
| 1437 | const double s1s1minusn22 = s1s1-n22; |
| 1438 | /* |
| 1439 | * u1, the first column of the U factor of a singular decomposition |
| 1440 | * of Jinv, is a (non-normalized) left singular vector corresponding |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1441 | * to s1. It has entries u11 and u21. We compute u1 from the fact |
| 1442 | * that it is an eigenvector of n corresponding to the eigenvalue |
| 1443 | * s1^2. |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1444 | */ |
| 1445 | const double s1s1minusn11_squared = s1s1minusn11*s1s1minusn11; |
| 1446 | const double s1s1minusn22_squared = s1s1minusn22*s1s1minusn22; |
| 1447 | /* |
| 1448 | * The following selects the largest row of n-s1^2 I as the one |
| 1449 | * which is used to find the eigenvector. If both s1^2-n11 and |
| 1450 | * s1^2-n22 are zero, n-s1^2 I is the zero matrix. In that case, |
| 1451 | * any vector is an eigenvector; in addition, norm below is equal to |
| 1452 | * zero, and, in exact arithmetic, this is the only case in which |
| 1453 | * norm = 0. So, setting u1 to the simple but arbitrary vector [1,0] |
| 1454 | * if norm = 0 safely takes care of all cases. |
| 1455 | */ |
| 1456 | const double temp_u11 = |
| 1457 | ( (s1s1minusn11_squared>=s1s1minusn22_squared) ? n12 : s1s1minusn22 ); |
| 1458 | const double temp_u21 = |
| 1459 | ( (s1s1minusn11_squared>=s1s1minusn22_squared) ? s1s1minusn11 : n21 ); |
| 1460 | const double norm = sqrt(temp_u11*temp_u11+temp_u21*temp_u21); |
| 1461 | /* |
| 1462 | * Finalize the entries of first left singular vector (associated |
| 1463 | * with the largest singular value). |
| 1464 | */ |
| 1465 | const double u11 = ( (norm>0.0) ? temp_u11/norm : 1.0 ); |
| 1466 | const double u21 = ( (norm>0.0) ? temp_u21/norm : 0.0 ); |
| 1467 | /* |
| 1468 | * Clamp the singular values up to 1. |
| 1469 | */ |
nicolas | ed22721 | 2010-09-27 17:24:57 +0000 | [diff] [blame] | 1470 | *major_mag = ( (s1s1<=1.0) ? 1.0 : sqrt(s1s1) ); |
| 1471 | *minor_mag = ( (s2s2<=1.0) ? 1.0 : sqrt(s2s2) ); |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1472 | /* |
| 1473 | * Return the unit major and minor axis direction vectors. |
| 1474 | */ |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1475 | *major_unit_x = u11; |
| 1476 | *major_unit_y = u21; |
nicolas | c90935c | 2010-09-27 16:47:39 +0000 | [diff] [blame] | 1477 | *minor_unit_x = -u21; |
| 1478 | *minor_unit_y = u11; |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1482 | /* |
| 1483 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1484 | % % |
| 1485 | % % |
| 1486 | % % |
| 1487 | % S c a l e R e s a m p l e F i l t e r % |
| 1488 | % % |
| 1489 | % % |
| 1490 | % % |
| 1491 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1492 | % |
| 1493 | % ScaleResampleFilter() does all the calculations needed to resample an image |
| 1494 | % at a specific scale, defined by two scaling vectors. This not using |
| 1495 | % a orthogonal scaling, but two distorted scaling vectors, to allow the |
| 1496 | % generation of a angled ellipse. |
| 1497 | % |
| 1498 | % As only two deritive scaling vectors are used the center of the ellipse |
| 1499 | % must be the center of the lookup. That is any curvature that the |
| 1500 | % distortion may produce is discounted. |
| 1501 | % |
| 1502 | % The input vectors are produced by either finding the derivitives of the |
| 1503 | % distortion function, or the partial derivitives from a distortion mapping. |
| 1504 | % They do not need to be the orthogonal dx,dy scaling vectors, but can be |
| 1505 | % calculated from other derivatives. For example you could use dr,da/r |
| 1506 | % polar coordinate vector scaling vectors |
| 1507 | % |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1508 | % If u,v = DistortEquation(x,y) OR u = Fu(x,y); v = Fv(x,y) |
| 1509 | % Then the scaling vectors are determined from the deritives... |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1510 | % du/dx, dv/dx and du/dy, dv/dy |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1511 | % If the resulting scaling vectors is othogonally aligned then... |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 | % dv/dx = 0 and du/dy = 0 |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1513 | % Producing an othogonally alligned ellipse in source space for the area to |
| 1514 | % be resampled. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1515 | % |
| 1516 | % Note that scaling vectors are different to argument order. Argument order |
| 1517 | % is the general order the deritives are extracted from the distortion |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1518 | % equations, and not the scaling vectors. As such the middle two vaules |
| 1519 | % may be swapped from what you expect. Caution is advised. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1520 | % |
anthony | 3ebea1e | 2010-09-27 13:29:00 +0000 | [diff] [blame] | 1521 | % WARNING: It is assumed that any SetResampleFilter() method call will |
| 1522 | % always be performed before the ScaleResampleFilter() method, so that the |
| 1523 | % size of the ellipse will match the support for the resampling filter being |
| 1524 | % used. |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1525 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1526 | % The format of the ScaleResampleFilter method is: |
| 1527 | % |
| 1528 | % void ScaleResampleFilter(const ResampleFilter *resample_filter, |
| 1529 | % const double dux,const double duy,const double dvx,const double dvy) |
| 1530 | % |
| 1531 | % A description of each parameter follows: |
| 1532 | % |
| 1533 | % o resample_filter: the resampling resample_filterrmation defining the |
| 1534 | % image being resampled |
| 1535 | % |
| 1536 | % o dux,duy,dvx,dvy: |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1537 | % The deritives or scaling vectors defining the EWA ellipse. |
| 1538 | % NOTE: watch the order, which is based on the order deritives |
| 1539 | % are usally determined from distortion equations (see above). |
| 1540 | % The middle two values may need to be swapped if you are thinking |
| 1541 | % in terms of scaling vectors. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1542 | % |
| 1543 | */ |
| 1544 | MagickExport void ScaleResampleFilter(ResampleFilter *resample_filter, |
| 1545 | const double dux,const double duy,const double dvx,const double dvy) |
| 1546 | { |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1547 | double A,B,C,F; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1548 | |
| 1549 | assert(resample_filter != (ResampleFilter *) NULL); |
| 1550 | assert(resample_filter->signature == MagickSignature); |
| 1551 | |
| 1552 | resample_filter->limit_reached = MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1553 | |
anthony | b821aaf | 2010-09-27 13:21:08 +0000 | [diff] [blame] | 1554 | /* A 'point' filter forces use of interpolation instead of area sampling */ |
| 1555 | if ( resample_filter->filter == PointFilter ) |
| 1556 | return; /* EWA turned off - nothing to do */ |
| 1557 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1558 | #if DEBUG_ELLIPSE |
| 1559 | fprintf(stderr, "# -----\n" ); |
| 1560 | fprintf(stderr, "dux=%lf; dvx=%lf; duy=%lf; dvy=%lf;\n", |
| 1561 | dux, dvx, duy, dvy); |
| 1562 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1563 | |
| 1564 | /* Find Ellipse Coefficents such that |
| 1565 | A*u^2 + B*u*v + C*v^2 = F |
| 1566 | With u,v relative to point around which we are resampling. |
| 1567 | And the given scaling dx,dy vectors in u,v space |
| 1568 | du/dx,dv/dx and du/dy,dv/dy |
| 1569 | */ |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1570 | #if EWA |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1571 | /* Direct conversion of derivatives into elliptical coefficients |
anthony | b821aaf | 2010-09-27 13:21:08 +0000 | [diff] [blame] | 1572 | However when magnifying images, the scaling vectors will be small |
| 1573 | resulting in a ellipse that is too small to sample properly. |
| 1574 | As such we need to clamp the major/minor axis to a minumum of 1.0 |
| 1575 | to prevent it getting too small. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1576 | */ |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1577 | #if EWA_CLAMP |
| 1578 | { double major_mag, |
| 1579 | minor_mag, |
| 1580 | major_x, |
| 1581 | major_y, |
| 1582 | minor_x, |
| 1583 | minor_y; |
| 1584 | |
| 1585 | ClampUpAxes(dux,dvx,duy,dvy, &major_mag, &minor_mag, |
| 1586 | &major_x, &major_y, &minor_x, &minor_y); |
anthony | bdfddb0 | 2010-10-05 00:06:45 +0000 | [diff] [blame] | 1587 | major_x *= major_mag; major_y *= major_mag; |
| 1588 | minor_x *= minor_mag; minor_y *= minor_mag; |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1589 | #if DEBUG_ELLIPSE |
| 1590 | fprintf(stderr, "major_x=%lf; major_y=%lf; minor_x=%lf; minor_y=%lf;\n", |
| 1591 | major_x, major_y, minor_x, minor_y); |
| 1592 | #endif |
| 1593 | A = major_y*major_y+minor_y*minor_y; |
| 1594 | B = -2.0*(major_x*major_y+minor_x*minor_y); |
| 1595 | C = major_x*major_x+minor_x*minor_x; |
nicolas | eaa0862 | 2010-09-27 17:06:09 +0000 | [diff] [blame] | 1596 | F = major_mag*minor_mag; |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1597 | F *= F; /* square it */ |
| 1598 | } |
| 1599 | #else /* raw EWA */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1600 | A = dvx*dvx+dvy*dvy; |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1601 | B = -2.0*(dux*dvx+duy*dvy); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1602 | C = dux*dux+duy*duy; |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1603 | F = dux*dvy-duy*dvx; |
anthony | 5708fc6 | 2010-09-14 13:52:50 +0000 | [diff] [blame] | 1604 | F *= F; /* square it */ |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1605 | #endif |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1606 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1607 | #else /* HQ_EWA */ |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1608 | /* |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1609 | This Paul Heckbert's "Higher Quality EWA" formula, from page 60 in his |
| 1610 | thesis, which adds a unit circle to the elliptical area so as to do both |
| 1611 | Reconstruction and Prefiltering of the pixels in the resampling. It also |
| 1612 | means it is always likely to have at least 4 pixels within the area of the |
| 1613 | ellipse, for weighted averaging. No scaling will result with F == 4.0 and |
| 1614 | a circle of radius 2.0, and F smaller than this means magnification is |
| 1615 | being used. |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1616 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1617 | NOTE: This method produces a very blury result at near unity scale while |
anthony | bdfddb0 | 2010-10-05 00:06:45 +0000 | [diff] [blame] | 1618 | producing perfect results for strong minitification and magnifications. |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1619 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1620 | However filter support is fixed to 2.0 (no good for Windowed Sinc filters) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1621 | */ |
| 1622 | A = dvx*dvx+dvy*dvy+1; |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1623 | B = -2.0*(dux*dvx+duy*dvy); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1624 | C = dux*dux+duy*duy+1; |
| 1625 | F = A*C - B*B/4; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1626 | #endif |
| 1627 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1628 | #if DEBUG_ELLIPSE |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1629 | fprintf(stderr, "A=%lf; B=%lf; C=%lf; F=%lf\n", A,B,C,F); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1630 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1631 | /* Figure out the various information directly about the ellipse. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1632 | This information currently not needed at this time, but may be |
| 1633 | needed later for better limit determination. |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1634 | |
| 1635 | It is also good to have as a record for future debugging |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1636 | */ |
| 1637 | { double alpha, beta, gamma, Major, Minor; |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1638 | double Eccentricity, Ellipse_Area, Ellipse_Angle; |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1639 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1640 | alpha = A+C; |
| 1641 | beta = A-C; |
| 1642 | gamma = sqrt(beta*beta + B*B ); |
| 1643 | |
| 1644 | if ( alpha - gamma <= MagickEpsilon ) |
| 1645 | Major = MagickHuge; |
| 1646 | else |
| 1647 | Major = sqrt(2*F/(alpha - gamma)); |
| 1648 | Minor = sqrt(2*F/(alpha + gamma)); |
| 1649 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1650 | fprintf(stderr, "# Major=%lf; Minor=%lf\n", Major, Minor ); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1651 | |
| 1652 | /* other information about ellipse include... */ |
| 1653 | Eccentricity = Major/Minor; |
| 1654 | Ellipse_Area = MagickPI*Major*Minor; |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1655 | Ellipse_Angle = atan2(B, A-C); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1656 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1657 | fprintf(stderr, "# Angle=%lf Area=%lf\n", |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1658 | RadiansToDegrees(Ellipse_Angle), Ellipse_Area); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1659 | } |
| 1660 | #endif |
| 1661 | |
nicolas | 15c331b | 2010-09-29 19:05:00 +0000 | [diff] [blame] | 1662 | /* If one or both of the scaling vectors is impossibly large |
| 1663 | (producing a very large raw F value), we may as well not bother |
| 1664 | doing any form of resampling since resampled area is very large. |
| 1665 | In this case some alternative means of pixel sampling, such as |
| 1666 | the average of the whole image is needed to get a reasonable |
| 1667 | result. Calculate only as needed. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1668 | */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1669 | if ( (4*A*C - B*B) > MagickHuge ) { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1670 | resample_filter->limit_reached = MagickTrue; |
| 1671 | return; |
| 1672 | } |
| 1673 | |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1674 | /* Scale ellipse by the support (that is, multiply F by the square |
| 1675 | of the support). |
| 1676 | */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1677 | F *= resample_filter->support; |
| 1678 | F *= resample_filter->support; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1679 | |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1680 | /* Orthogonal bounds of the ellipse */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1681 | resample_filter->Ulimit = sqrt(4*C*F/(4*A*C-B*B)); |
| 1682 | resample_filter->Vlimit = sqrt(4*A*F/(4*A*C-B*B)); |
| 1683 | |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1684 | /* Horizontally aligned parallelogram fitted to Ellipse */ |
| 1685 | resample_filter->Uwidth = sqrt(F/A); /* Half of the parallelogram width */ |
| 1686 | resample_filter->slope = -B/(2*A); /* Reciprocal slope of the parallelogram */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1687 | |
| 1688 | #if DEBUG_ELLIPSE |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1689 | fprintf(stderr, "Ulimit=%lf; Vlimit=%lf; UWidth=%lf; Slope=%lf;\n", |
| 1690 | resample_filter->Ulimit, resample_filter->Vlimit, |
| 1691 | resample_filter->Uwidth, resample_filter->slope ); |
| 1692 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1693 | |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1694 | /* Check the absolute area of the parallelogram involved. |
| 1695 | * This limit needs more work, as it is too slow for larger images |
| 1696 | * with tiled views of the horizon. |
| 1697 | */ |
cristy | 39f347a | 2010-09-20 00:29:31 +0000 | [diff] [blame] | 1698 | if ( (resample_filter->Uwidth * resample_filter->Vlimit) |
| 1699 | > (4.0*resample_filter->image_area)) { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1700 | resample_filter->limit_reached = MagickTrue; |
| 1701 | return; |
| 1702 | } |
| 1703 | |
anthony | 5708fc6 | 2010-09-14 13:52:50 +0000 | [diff] [blame] | 1704 | /* Scale ellipse formula to directly index the Filter Lookup Table */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1705 | { register double scale; |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1706 | scale = (double)WLUT_WIDTH/F; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1707 | resample_filter->A = A*scale; |
| 1708 | resample_filter->B = B*scale; |
| 1709 | resample_filter->C = C*scale; |
nicolas | e2ecb24 | 2010-09-29 20:02:24 +0000 | [diff] [blame] | 1710 | /* resample_filter->F = WLUT_WIDTH; -- hardcoded */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1716 | % % |
| 1717 | % % |
| 1718 | % % |
| 1719 | % S e t R e s a m p l e F i l t e r % |
| 1720 | % % |
| 1721 | % % |
| 1722 | % % |
| 1723 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1724 | % |
| 1725 | % SetResampleFilter() set the resampling filter lookup table based on a |
| 1726 | % specific filter. Note that the filter is used as a radial filter not as a |
| 1727 | % two pass othogonally aligned resampling filter. |
| 1728 | % |
| 1729 | % The default Filter, is Gaussian, which is the standard filter used by the |
| 1730 | % original paper on the Elliptical Weighted Everage Algorithm. However other |
| 1731 | % filters can also be used. |
| 1732 | % |
| 1733 | % The format of the SetResampleFilter method is: |
| 1734 | % |
| 1735 | % void SetResampleFilter(ResampleFilter *resample_filter, |
| 1736 | % const FilterTypes filter,const double blur) |
| 1737 | % |
| 1738 | % A description of each parameter follows: |
| 1739 | % |
| 1740 | % o resample_filter: resampling resample_filterrmation structure |
| 1741 | % |
| 1742 | % o filter: the resize filter for elliptical weighting LUT |
| 1743 | % |
| 1744 | % o blur: filter blur factor (radial scaling) for elliptical weighting LUT |
| 1745 | % |
| 1746 | */ |
| 1747 | MagickExport void SetResampleFilter(ResampleFilter *resample_filter, |
| 1748 | const FilterTypes filter,const double blur) |
| 1749 | { |
| 1750 | register int |
| 1751 | Q; |
| 1752 | |
| 1753 | double |
| 1754 | r_scale; |
| 1755 | |
| 1756 | ResizeFilter |
| 1757 | *resize_filter; |
| 1758 | |
| 1759 | assert(resample_filter != (ResampleFilter *) NULL); |
| 1760 | assert(resample_filter->signature == MagickSignature); |
| 1761 | |
anthony | 2e6ab68 | 2010-09-28 12:02:25 +0000 | [diff] [blame] | 1762 | resample_filter->do_interpolate = MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1763 | resample_filter->filter = filter; |
| 1764 | |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1765 | if ( filter == PointFilter ) |
anthony | b821aaf | 2010-09-27 13:21:08 +0000 | [diff] [blame] | 1766 | { |
| 1767 | resample_filter->do_interpolate = MagickTrue; |
| 1768 | return; /* EWA turned off - nothing more to do */ |
| 1769 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1770 | |
anthony | 61b5ddd | 2010-10-05 02:33:31 +0000 | [diff] [blame] | 1771 | /* Set a default cylindrical filter of a 'low blur' Jinc windowed Jinc */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1772 | if ( filter == UndefinedFilter ) |
anthony | 853d697 | 2010-10-08 06:01:31 +0000 | [diff] [blame^] | 1773 | resample_filter->filter = RobidouxFilter; |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1774 | |
| 1775 | resize_filter = AcquireResizeFilter(resample_filter->image, |
| 1776 | resample_filter->filter,blur,MagickTrue,resample_filter->exception); |
anthony | bdfddb0 | 2010-10-05 00:06:45 +0000 | [diff] [blame] | 1777 | if (resize_filter == (ResizeFilter *) NULL) |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1778 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1779 | (void) ThrowMagickException(resample_filter->exception,GetMagickModule(), |
| 1780 | ModuleError, "UnableToSetFilteringValue", |
| 1781 | "Fall back to default EWA gaussian filter"); |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1782 | resample_filter->filter = PointFilter; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1783 | } |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1784 | |
anthony | 10b8bc8 | 2010-10-02 12:48:46 +0000 | [diff] [blame] | 1785 | /* Get the practical working support for the filter, |
| 1786 | * after any API call blur factors have been accoded for. |
| 1787 | */ |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1788 | #if EWA |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1789 | resample_filter->support = GetResizeFilterSupport(resize_filter); |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1790 | #else |
| 1791 | resample_filter->support = 2.0; /* fixed support size for HQ-EWA */ |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1792 | #endif |
| 1793 | |
| 1794 | /* Scale radius so the filter LUT covers the full support range */ |
| 1795 | r_scale = resample_filter->support*sqrt(1.0/(double)WLUT_WIDTH); |
| 1796 | |
| 1797 | /* Fill the LUT with a 1D resize filter function */ |
| 1798 | for(Q=0; Q<WLUT_WIDTH; Q++) |
| 1799 | resample_filter->filter_lut[Q] = (double) |
| 1800 | GetResizeFilterWeight(resize_filter,sqrt((double)Q)*r_scale); |
| 1801 | |
| 1802 | /* finished with the resize filter */ |
| 1803 | resize_filter = DestroyResizeFilter(resize_filter); |
| 1804 | |
anthony | 3ebea1e | 2010-09-27 13:29:00 +0000 | [diff] [blame] | 1805 | /* |
| 1806 | Adjust the scaling of the default unit circle |
| 1807 | This assumes that any real scaling changes will always |
| 1808 | take place AFTER the filter method has been initialized. |
| 1809 | */ |
| 1810 | |
| 1811 | ScaleResampleFilter(resample_filter, 1.0, 0.0, 0.0, 1.0); |
| 1812 | |
anthony | 5708fc6 | 2010-09-14 13:52:50 +0000 | [diff] [blame] | 1813 | #if 0 |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1814 | This is old code kept for reference only. It is very wrong. |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1815 | /* |
| 1816 | Create Normal Gaussian 2D Filter Weighted Lookup Table. |
| 1817 | A normal EWA guassual lookup would use exp(Q*ALPHA) |
| 1818 | where Q = distance squared from 0.0 (center) to 1.0 (edge) |
| 1819 | and ALPHA = -4.0*ln(2.0) ==> -2.77258872223978123767 |
| 1820 | However the table is of length 1024, and equates to a radius of 2px |
| 1821 | thus needs to be scaled by ALPHA*4/1024 and any blur factor squared |
anthony | 5708fc6 | 2010-09-14 13:52:50 +0000 | [diff] [blame] | 1822 | |
anthony | c7b82f2 | 2010-09-27 10:42:29 +0000 | [diff] [blame] | 1823 | The above came from some reference code provided by Fred Weinhaus |
| 1824 | and seems to have been a guess that was appropriate for its use |
| 1825 | in a 3d perspective landscape mapping program. |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1826 | */ |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1827 | r_scale = -2.77258872223978123767/(WLUT_WIDTH*blur*blur); |
| 1828 | for(Q=0; Q<WLUT_WIDTH; Q++) |
| 1829 | resample_filter->filter_lut[Q] = exp((double)Q*r_scale); |
| 1830 | resample_filter->support = WLUT_WIDTH; |
| 1831 | break; |
anthony | 5708fc6 | 2010-09-14 13:52:50 +0000 | [diff] [blame] | 1832 | #endif |
anthony | 490ab03 | 2010-09-20 00:02:08 +0000 | [diff] [blame] | 1833 | |
anthony | e06e4c1 | 2010-09-15 04:03:52 +0000 | [diff] [blame] | 1834 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
anthony | 7294979 | 2010-10-08 04:44:56 +0000 | [diff] [blame] | 1835 | #pragma omp single |
| 1836 | { |
anthony | e06e4c1 | 2010-09-15 04:03:52 +0000 | [diff] [blame] | 1837 | #endif |
| 1838 | if (GetImageArtifact(resample_filter->image,"resample:verbose") |
| 1839 | != (const char *) NULL) |
| 1840 | { |
| 1841 | /* Debug output of the filter weighting LUT |
| 1842 | Gnuplot the LUT with hoizontal adjusted to 'r' using... |
| 1843 | plot [0:2][-.2:1] "lut.dat" using (sqrt($0/1024)*2):1 with lines |
| 1844 | The filter values is normalized for comparision |
| 1845 | */ |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1846 | printf("#\n"); |
anthony | e06e4c1 | 2010-09-15 04:03:52 +0000 | [diff] [blame] | 1847 | printf("# Resampling Filter LUT (%d values)\n", WLUT_WIDTH); |
| 1848 | printf("#\n"); |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1849 | printf("# Note: values in table are using a squared radius lookup.\n"); |
| 1850 | printf("# And the whole table represents the filters support.\n"); |
anthony | 61b5ddd | 2010-10-05 02:33:31 +0000 | [diff] [blame] | 1851 | printf("\n"); /* generates a 'break' in gnuplot if multiple outputs */ |
anthony | e06e4c1 | 2010-09-15 04:03:52 +0000 | [diff] [blame] | 1852 | for(Q=0; Q<WLUT_WIDTH; Q++) |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1853 | printf("%8.*g %.*g\n", |
| 1854 | GetMagickPrecision(),sqrt((double)Q)*r_scale, |
| 1855 | GetMagickPrecision(),resample_filter->filter_lut[Q] ); |
anthony | e06e4c1 | 2010-09-15 04:03:52 +0000 | [diff] [blame] | 1856 | } |
anthony | 7294979 | 2010-10-08 04:44:56 +0000 | [diff] [blame] | 1857 | /* output the above once only for each image, and each setting */ |
| 1858 | (void) DeleteImageArtifact(resample_filter->image,"resample:verbose"); |
| 1859 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 1860 | } |
| 1861 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1862 | return; |
| 1863 | } |
| 1864 | |
| 1865 | /* |
| 1866 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1867 | % % |
| 1868 | % % |
| 1869 | % % |
| 1870 | % S e t R e s a m p l e F i l t e r I n t e r p o l a t e M e t h o d % |
| 1871 | % % |
| 1872 | % % |
| 1873 | % % |
| 1874 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1875 | % |
| 1876 | % SetResampleFilterInterpolateMethod() changes the interpolation method |
| 1877 | % associated with the specified resample filter. |
| 1878 | % |
| 1879 | % The format of the SetResampleFilterInterpolateMethod method is: |
| 1880 | % |
| 1881 | % MagickBooleanType SetResampleFilterInterpolateMethod( |
| 1882 | % ResampleFilter *resample_filter,const InterpolateMethod method) |
| 1883 | % |
| 1884 | % A description of each parameter follows: |
| 1885 | % |
| 1886 | % o resample_filter: the resample filter. |
| 1887 | % |
| 1888 | % o method: the interpolation method. |
| 1889 | % |
| 1890 | */ |
| 1891 | MagickExport MagickBooleanType SetResampleFilterInterpolateMethod( |
| 1892 | ResampleFilter *resample_filter,const InterpolatePixelMethod method) |
| 1893 | { |
| 1894 | assert(resample_filter != (ResampleFilter *) NULL); |
| 1895 | assert(resample_filter->signature == MagickSignature); |
| 1896 | assert(resample_filter->image != (Image *) NULL); |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1897 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1898 | if (resample_filter->debug != MagickFalse) |
| 1899 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1900 | resample_filter->image->filename); |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1901 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1902 | resample_filter->interpolate=method; |
anthony | d638d31 | 2010-09-15 13:13:01 +0000 | [diff] [blame] | 1903 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1904 | return(MagickTrue); |
| 1905 | } |
| 1906 | |
| 1907 | /* |
| 1908 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1909 | % % |
| 1910 | % % |
| 1911 | % % |
| 1912 | % S e t R e s a m p l e F i l t e r V i r t u a l P i x e l M e t h o d % |
| 1913 | % % |
| 1914 | % % |
| 1915 | % % |
| 1916 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1917 | % |
| 1918 | % SetResampleFilterVirtualPixelMethod() changes the virtual pixel method |
| 1919 | % associated with the specified resample filter. |
| 1920 | % |
| 1921 | % The format of the SetResampleFilterVirtualPixelMethod method is: |
| 1922 | % |
| 1923 | % MagickBooleanType SetResampleFilterVirtualPixelMethod( |
| 1924 | % ResampleFilter *resample_filter,const VirtualPixelMethod method) |
| 1925 | % |
| 1926 | % A description of each parameter follows: |
| 1927 | % |
| 1928 | % o resample_filter: the resample filter. |
| 1929 | % |
| 1930 | % o method: the virtual pixel method. |
| 1931 | % |
| 1932 | */ |
| 1933 | MagickExport MagickBooleanType SetResampleFilterVirtualPixelMethod( |
| 1934 | ResampleFilter *resample_filter,const VirtualPixelMethod method) |
| 1935 | { |
| 1936 | assert(resample_filter != (ResampleFilter *) NULL); |
| 1937 | assert(resample_filter->signature == MagickSignature); |
| 1938 | assert(resample_filter->image != (Image *) NULL); |
| 1939 | if (resample_filter->debug != MagickFalse) |
| 1940 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1941 | resample_filter->image->filename); |
| 1942 | resample_filter->virtual_pixel=method; |
cristy | 2d5e44d | 2010-03-12 01:56:29 +0000 | [diff] [blame] | 1943 | if (method != UndefinedVirtualPixelMethod) |
| 1944 | (void) SetCacheViewVirtualPixelMethod(resample_filter->view,method); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1945 | return(MagickTrue); |
| 1946 | } |