resample.c revision 3ebea1e232532895681cd50101ddad0856e9a1d3
13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% RRRR EEEEE SSSSS AAA M M PPPP L EEEEE % 73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R R E SS A A MM MM P P L E % 83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% RRRR EEE SSS AAAAA M M M PPPP L EEE % 93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R R E SS A A M M P L E % 103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R R EEEEE SSSSS A A M M P LLLLL EEEEE % 113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickCore Pixel Resampling Methods % 143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Software Design % 163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% John Cristy % 173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Anthony Thyssen % 183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% August 2007 % 193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2116af1cbdffcc02e7239d432e5fb51734fcf9f9ffcristy% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization % 223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% dedicated to making software imaging solutions freely available. % 233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% You may not use this file except in compliance with the License. You may % 253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% obtain a copy of the License at % 263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% http://www.imagemagick.org/script/license.php % 283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Unless required by applicable law or agreed to in writing, software % 303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% distributed under the License is distributed on an "AS IS" BASIS, % 313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% See the License for the specific language governing permissions and % 333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% limitations under the License. % 343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Include declarations. 423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/studio.h" 443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/artifact.h" 453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/color-private.h" 463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/cache.h" 473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/draw.h" 483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/exception-private.h" 493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/gem.h" 503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/image.h" 513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/image-private.h" 523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/log.h" 53d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony#include "magick/magick.h" 543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/memory_.h" 553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/pixel-private.h" 563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/quantum.h" 573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/random_.h" 583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/resample.h" 593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/resize.h" 603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/resize-private.h" 613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/transform.h" 623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "magick/signature-private.h" 633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 64490ab03a4e81aa0943087243055c77e3794d75d9anthony EWA Resampling Options 65490ab03a4e81aa0943087243055c77e3794d75d9anthony*/ 66490ab03a4e81aa0943087243055c77e3794d75d9anthony#define WLUT_WIDTH 1024 /* size of the filter cache */ 67c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony 68c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony/* select ONE resampling method */ 69c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#define EWA 1 /* Normal EWA handling - raw or clamped */ 70c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* if 0 then use "High Quality EWA" */ 71c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#define EWA_CLAMP 1 /* EWA Clamping from Nicolas Robidoux */ 72c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony 73c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony/* output debugging information */ 74c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#define DEBUG_NO_HIT_PIXELS 1 /* Make pixels that fail to 'hit' anything red */ 75490ab03a4e81aa0943087243055c77e3794d75d9anthony#define DEBUG_ELLIPSE 0 /* output ellipse info for debug */ 76490ab03a4e81aa0943087243055c77e3794d75d9anthony#define DEBUG_HIT_MISS 0 /* output hit/miss pixels with above switch */ 77490ab03a4e81aa0943087243055c77e3794d75d9anthony 78490ab03a4e81aa0943087243055c77e3794d75d9anthony/* 793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Typedef declarations. 803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 813ed852eea50f9d4cd633efb8c2b054b8e33c253cristystruct _ResampleFilter 823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CacheView 843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *view; 853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 86c4c8d13c0996fea659ce63c682c803e74c1abc8acristy Image 87c4c8d13c0996fea659ce63c682c803e74c1abc8acristy *image; 88c4c8d13c0996fea659ce63c682c803e74c1abc8acristy 893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ExceptionInfo 903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *exception; 913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy debug; 943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Information about image being resampled */ 96bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy ssize_t 973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy image_area; 983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy InterpolatePixelMethod 1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy interpolate; 1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy VirtualPixelMethod 1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy virtual_pixel; 1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy FilterTypes 1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter; 1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* processing settings needed */ 1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy limit_reached, 1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy do_interpolate, 1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_defined; 1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 1153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_pixel; 1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* current ellipitical area being resampled around center point */ 1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy double 1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy A, B, C, 120d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony Vlimit, Ulimit, Uwidth, slope; 1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* LUT of weights for filtered average in elliptical area */ 1233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy double 1243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter_lut[WLUT_WIDTH], 1253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy support; 1263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 127bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy size_t 1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy signature; 1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}; 1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A c q u i r e R e s a m p l e I n f o % 1373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 1403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% AcquireResampleFilter() initializes the information resample needs do to a 1433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% scaled lookup of a color from an image, using area sampling. 1443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The algorithm is based on a Elliptical Weighted Average, where the pixels 1463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% found in a large elliptical area is averaged together according to a 1473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% weighting (filter) function. For more details see "Fundamentals of Texture 1483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Mapping and Image Warping" a master's thesis by Paul.S.Heckbert, June 17, 1493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1989. Available for free from, http://www.cs.cmu.edu/~ph/ 1503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% As EWA resampling (or any sort of resampling) can require a lot of 1523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% calculations to produce a distorted scaling of the source image for each 1533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% output pixel, the ResampleFilter structure generated holds that information 1543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% between individual image resampling. 1553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% This function will make the appropriate AcquireCacheView() calls 1573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% to view the image, calling functions do not need to open a cache view. 1583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Usage Example... 1603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% resample_filter=AcquireResampleFilter(image,exception); 161c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% SetResampleFilter(resample_filter, GaussianFilter, 1.0); 162bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy% for (y=0; y < (ssize_t) image->rows; y++) { 163bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy% for (x=0; x < (ssize_t) image->columns; x++) { 164c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% u= ....; v= ....; 1653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ScaleResampleFilter(resample_filter, ... scaling vectors ...); 166c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% (void) ResamplePixelColor(resample_filter,u,v,&pixel); 1673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ... assign resampled pixel value ... 1683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% } 1693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% } 1703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% DestroyResampleFilter(resample_filter); 1713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the AcquireResampleFilter method is: 1733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ResampleFilter *AcquireResampleFilter(const Image *image, 1753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ExceptionInfo *exception) 1763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 1783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o image: the image. 1803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o exception: return any errors or warnings in this structure. 1823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 1843ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport ResampleFilter *AcquireResampleFilter(const Image *image, 1853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ExceptionInfo *exception) 1863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 1873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register ResampleFilter 1883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *resample_filter; 1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image != (Image *) NULL); 1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(image->signature == MagickSignature); 1923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (image->debug != MagickFalse) 1933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 1943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception != (ExceptionInfo *) NULL); 1953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(exception->signature == MagickSignature); 1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter=(ResampleFilter *) AcquireMagickMemory( 1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy sizeof(*resample_filter)); 1993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter == (ResampleFilter *) NULL) 2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); 2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ResetMagickMemory(resample_filter,0,sizeof(*resample_filter)); 2023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image=ReferenceImage((Image *) image); 2043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->view=AcquireCacheView(resample_filter->image); 2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->exception=exception; 2063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->debug=IsEventLogging(); 2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->signature=MagickSignature; 2093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 210eaedf06777741da32408da72c1e512975c600c48cristy resample_filter->image_area=(ssize_t) (resample_filter->image->columns* 211eaedf06777741da32408da72c1e512975c600c48cristy resample_filter->image->rows); 2123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->average_defined = MagickFalse; 2133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* initialise the resampling filter settings */ 2153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetResampleFilter(resample_filter, resample_filter->image->filter, 2163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image->blur); 2173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->interpolate = resample_filter->image->interpolate; 2183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->virtual_pixel=GetImageVirtualPixelMethod(image); 2193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(resample_filter); 2213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 2223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 2243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% D e s t r o y R e s a m p l e I n f o % 2293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% DestroyResampleFilter() finalizes and cleans up the resampling 2353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% resample_filter as returned by AcquireResampleFilter(), freeing any memory 2363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% or other information as needed. 2373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the DestroyResampleFilter method is: 2393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ResampleFilter *DestroyResampleFilter(ResampleFilter *resample_filter) 2413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 2433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: resampling information structure 2453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 2473ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport ResampleFilter *DestroyResampleFilter( 2483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResampleFilter *resample_filter) 2493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 2503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 2513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 2523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->image != (Image *) NULL); 2533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->debug != MagickFalse) 2543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 2553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image->filename); 2563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->view=DestroyCacheView(resample_filter->view); 2573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image=DestroyImage(resample_filter->image); 2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->signature=(~MagickSignature); 2593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter=(ResampleFilter *) RelinquishMagickMemory(resample_filter); 2603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(resample_filter); 2613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 2623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 2643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 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 % 2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 2723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% InterpolateResampleFilter() applies bi-linear or tri-linear interpolation 2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% between a floating point coordinate and the pixels surrounding that 2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% coordinate. No pixel area resampling, or scaling of the result is 2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% performed. 2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the InterpolateResampleFilter method is: 2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType InterpolateResampleFilter( 2823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ResampleInfo *resample_filter,const InterpolatePixelMethod method, 2833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% const double x,const double y,MagickPixelPacket *pixel) 2843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: the resample filter. 2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o method: the pixel clor interpolation method. 2903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o x,y: A double representing the current (x,y) position of the pixel. 2923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o pixel: return the interpolated pixel here. 2943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline double MagickMax(const double x,const double y) 2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 2993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (x > y) 3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(x); 3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(y); 3023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 3033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3043ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx, 3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket *pixel) 3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dx2, 3093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p, 3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q, 3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r, 3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s; 3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dx2=dx*dx; 3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red); 3163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=(pixels[0].red-pixels[1].red)-p; 3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=pixels[2].red-pixels[0].red; 3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=pixels[1].red; 3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s; 3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green); 3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=(pixels[0].green-pixels[1].green)-p; 3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=pixels[2].green-pixels[0].green; 3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=pixels[1].green; 3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s; 3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue); 3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=(pixels[0].blue-pixels[1].blue)-p; 3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=pixels[2].blue-pixels[0].blue; 3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=pixels[1].blue; 3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s; 3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity); 3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=(pixels[0].opacity-pixels[1].opacity)-p; 3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=pixels[2].opacity-pixels[0].opacity; 3333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=pixels[1].opacity; 3343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s; 3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (pixel->colorspace == CMYKColorspace) 3363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index); 3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy q=(pixels[0].index-pixels[1].index)-p; 3393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r=pixels[2].index-pixels[0].index; 3403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy s=pixels[1].index; 3413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s; 3423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 3433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3453ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline MagickRealType CubicWeightingFunction(const MagickRealType x) 3463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 3473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 3483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha, 3493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma; 3503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha=MagickMax(x+2.0,0.0); 3523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0*alpha*alpha*alpha; 3533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha=MagickMax(x+1.0,0.0); 3543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma-=4.0*alpha*alpha*alpha; 3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha=MagickMax(x+0.0,0.0); 3563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma+=6.0*alpha*alpha*alpha; 3573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha=MagickMax(x-1.0,0.0); 3583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma-=4.0*alpha*alpha*alpha; 3593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(gamma/6.0); 3603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 3613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3623ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline double MeshInterpolate(const PointInfo *delta,const double p, 3633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const double x,const double y) 3643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 3653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); 3663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 3673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 368bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic inline ssize_t NearestNeighbor(MagickRealType x) 3693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 3703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (x >= 0.0) 371bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy return((ssize_t) (x+0.5)); 372bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy return((ssize_t) (x-0.5)); 3733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 3743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3753ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType InterpolateResampleFilter( 3763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResampleFilter *resample_filter,const InterpolatePixelMethod method, 3773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const double x,const double y,MagickPixelPacket *pixel) 3783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 3793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 3803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 3813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register const IndexPacket 3833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *indexes; 3843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register const PixelPacket 3863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *p; 3873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 388bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy register ssize_t 3893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy i; 3903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 3923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 3933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickTrue; 3943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy switch (method) 3953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case AverageInterpolatePixel: 3973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 3983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 3993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[16]; 4003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 4023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[16], 4033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma; 4043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 40554ffe7c6780ec1e33f8707e228b962d1accf58f8cristy p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x)-1, 40654ffe7c6780ec1e33f8707e228b962d1accf58f8cristy (ssize_t) floor(y)-1,4,4,resample_filter->exception); 4073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 4083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 4103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 4113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 4133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 16L; i++) 4143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels+i); 4163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes+i,pixels+i); 4173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[i]=1.0; 4183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 4193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 42046f08209f719f4adeea742c45873c2714e80cdb9cristy alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p)); 4213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].red*=alpha[i]; 4223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].green*=alpha[i]; 4233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].blue*=alpha[i]; 4243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 4253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].index*=alpha[i]; 4263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=alpha[i]; 4283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 4293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red+=gamma*0.0625*pixels[i].red; 4303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green+=gamma*0.0625*pixels[i].green; 4313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue+=gamma*0.0625*pixels[i].blue; 4323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity+=0.0625*pixels[i].opacity; 4333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 4343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index+=gamma*0.0625*pixels[i].index; 4353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; 4363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 4383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case BicubicInterpolatePixel: 4403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 4423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[16], 4433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy u[4]; 4443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 4463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[16]; 4473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PointInfo 4493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta; 4503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 45154ffe7c6780ec1e33f8707e228b962d1accf58f8cristy p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x)-1, 45254ffe7c6780ec1e33f8707e228b962d1accf58f8cristy (ssize_t) floor(y)-1,4,4,resample_filter->exception); 4533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 4543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 4563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 4573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 4593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 16L; i++) 4603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels+i); 4623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes+i,pixels+i); 4633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[i]=1.0; 4643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 4653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 46646f08209f719f4adeea742c45873c2714e80cdb9cristy alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p)); 4673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].red*=alpha[i]; 4683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].green*=alpha[i]; 4693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].blue*=alpha[i]; 4703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 4713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].index*=alpha[i]; 4723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; 4743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.x=x-floor(x); 4763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 4L; i++) 4773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy BicubicInterpolate(pixels+4*i,delta.x,u+i); 4783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.y=y-floor(y); 4793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy BicubicInterpolate(u,delta.y,pixel); 4803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 4813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 4823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case BilinearInterpolatePixel: 4833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default: 4843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 4853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 4863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[4]; 4873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 4893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[4], 4903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma; 4913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 4923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PointInfo 4933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta, 4943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy epsilon; 4953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 49654ffe7c6780ec1e33f8707e228b962d1accf58f8cristy p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x), 49754ffe7c6780ec1e33f8707e228b962d1accf58f8cristy (ssize_t) floor(y),2,2,resample_filter->exception); 4983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 4993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 5013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 5023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 5043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 4L; i++) 5053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].red=(MagickRealType) p[i].red; 5073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].green=(MagickRealType) p[i].green; 5083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].blue=(MagickRealType) p[i].blue; 5093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].opacity=(MagickRealType) p[i].opacity; 5103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[i]=1.0; 5113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 5133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 4L; i++) 5143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p[i].opacity); 5163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].red*=alpha[i]; 5173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].green*=alpha[i]; 5183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].blue*=alpha[i]; 5193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (indexes != (IndexPacket *) NULL) 5213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 4L; i++) 5223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].index=(MagickRealType) indexes[i]; 5243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 5253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].index*=alpha[i]; 5263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.x=x-floor(x); 5283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.y=y-floor(y); 5293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy epsilon.x=1.0-delta.x; 5303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy epsilon.y=1.0-delta.y; 5313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* 5323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (epsilon.x*alpha[2]+delta.x*alpha[3]))); 5333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 5343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x* 5353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red)); 5363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x* 5373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x* 5383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].green)); 5393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x* 5403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x* 5413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].blue)); 5423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity=(epsilon.y*(epsilon.x*pixels[0].opacity+delta.x* 5433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].opacity)+delta.y*(epsilon.x*pixels[2].opacity+delta.x* 5443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].opacity)); 5453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 5463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index=gamma*(epsilon.y*(epsilon.x*pixels[0].index+delta.x* 5473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].index)+delta.y*(epsilon.x*pixels[2].index+delta.x* 5483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].index)); 5493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 5503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case FilterInterpolatePixel: 5523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 55354ffe7c6780ec1e33f8707e228b962d1accf58f8cristy CacheView 55454ffe7c6780ec1e33f8707e228b962d1accf58f8cristy *filter_view; 55554ffe7c6780ec1e33f8707e228b962d1accf58f8cristy 5563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 5573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *excerpt_image, 5583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *filter_image; 5593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 5613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1]; 5623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy RectangleInfo 5643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy geometry; 5653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 5663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy geometry.width=4L; 5673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy geometry.height=4L; 568bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy geometry.x=(ssize_t) floor(x)-1L; 569bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy geometry.y=(ssize_t) floor(y)-1L; 5703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy excerpt_image=ExcerptImage(resample_filter->image,&geometry, 5713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->exception); 5723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (excerpt_image == (Image *) NULL) 5733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 5753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter_image=ResizeImage(excerpt_image,1,1,resample_filter->image->filter, 5783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image->blur,resample_filter->exception); 5793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy excerpt_image=DestroyImage(excerpt_image); 5803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (filter_image == (Image *) NULL) 5813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 5823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter_view=AcquireCacheView(filter_image); 5833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=GetCacheViewVirtualPixels(filter_view,0,0,1,1, 5843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->exception); 5853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p != (const PixelPacket *) NULL) 5863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetVirtualIndexQueue(filter_image); 5883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels); 5893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes,pixel); 5903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter_view=DestroyCacheView(filter_view); 5923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy filter_image=DestroyImage(filter_image); 5933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 5953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case IntegerInterpolatePixel: 5963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 5973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 5983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1]; 5993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 60054ffe7c6780ec1e33f8707e228b962d1accf58f8cristy p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x), 60154ffe7c6780ec1e33f8707e228b962d1accf58f8cristy (ssize_t) floor(y),1,1,resample_filter->exception); 6023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 6033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 6053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 6083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels); 6093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes,pixel); 6103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 6113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case MeshInterpolatePixel: 6133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 6153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[4]; 6163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 6183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[4], 6193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma; 6203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 6213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PointInfo 6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta, 6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy luminance; 6243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 62554ffe7c6780ec1e33f8707e228b962d1accf58f8cristy p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x), 62654ffe7c6780ec1e33f8707e228b962d1accf58f8cristy (ssize_t) floor(y),2,2,resample_filter->exception); 6273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 6283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 6313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 6333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=0; i < 4L; i++) 6343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels+i); 6363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes+i,pixels+i); 6373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[i]=1.0; 6383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 6393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 64046f08209f719f4adeea742c45873c2714e80cdb9cristy alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p)); 6413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].red*=alpha[i]; 6423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].green*=alpha[i]; 6433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].blue*=alpha[i]; 6443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 6453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[i].index*=alpha[i]; 6463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; 6483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.x=x-floor(x); 6503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.y=y-floor(y); 6513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3); 6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2); 6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (fabs(luminance.x) < fabs(luminance.y)) 6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Diagonal 0-3 NW-SE. 6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 6583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (delta.x <= delta.y) 6593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Bottom-left triangle (pixel:2, diagonal: 0-3). 6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.y=1.0-delta.y; 6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); 6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red, 6673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].red,pixels[0].red); 6683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green, 6693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].green,pixels[0].green); 6703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue, 6713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].blue,pixels[0].blue); 6723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity, 6733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].opacity,pixels[0].opacity); 6743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 6753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index=gamma*MeshInterpolate(&delta,pixels[2].index, 6763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[3].index,pixels[0].index); 6773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 6793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 6803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 6813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Top-right triangle (pixel:1, diagonal: 0-3). 6823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 6833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.x=1.0-delta.x; 6843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); 6853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 6863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red, 6873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[0].red,pixels[3].red); 6883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green, 6893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[0].green,pixels[3].green); 6903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue, 6913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[0].blue,pixels[3].blue); 6923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity, 6933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[0].opacity,pixels[3].opacity); 6943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 6953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index=gamma*MeshInterpolate(&delta,pixels[1].index, 6963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[0].index,pixels[3].index); 6973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 6993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 7003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 7023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Diagonal 1-2 NE-SW. 7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 7043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (delta.x <= (1.0-delta.y)) 7053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Top-left triangle (pixel 0, diagonal: 1-2). 7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); 7103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 7113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red, 7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].red,pixels[2].red); 7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green, 7143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].green,pixels[2].green); 7153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue, 7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].blue,pixels[2].blue); 7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity, 7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].opacity,pixels[2].opacity); 7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index=gamma*MeshInterpolate(&delta,pixels[0].index, 7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1].index,pixels[2].index); 7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Bottom-right triangle (pixel: 3, diagonal: 1-2). 7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.x=1.0-delta.x; 7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.y=1.0-delta.y; 7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); 7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red, 7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[2].red,pixels[1].red); 7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green, 7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[2].green,pixels[1].green); 7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue, 7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[2].blue,pixels[1].blue); 7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity, 7393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[2].opacity,pixels[1].opacity); 7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index=gamma*MeshInterpolate(&delta,pixels[3].index, 7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[2].index,pixels[1].index); 7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 7463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case NearestNeighborInterpolatePixel: 7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[1]; 7513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p=GetCacheViewVirtualPixels(resample_filter->view,NearestNeighbor(x), 7533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy NearestNeighbor(y),1,1,resample_filter->exception); 7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 7553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels); 7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes,pixel); 7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case SplineInterpolatePixel: 7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket 7673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[16]; 7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickRealType 7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[16], 7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dx, 7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dy, 7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma; 7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy PointInfo 7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta; 7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 77854ffe7c6780ec1e33f8707e228b962d1accf58f8cristy ssize_t 77954ffe7c6780ec1e33f8707e228b962d1accf58f8cristy j, 78054ffe7c6780ec1e33f8707e228b962d1accf58f8cristy n; 78154ffe7c6780ec1e33f8707e228b962d1accf58f8cristy 78254ffe7c6780ec1e33f8707e228b962d1accf58f8cristy p=GetCacheViewVirtualPixels(resample_filter->view,(ssize_t) floor(x)-1, 78354ffe7c6780ec1e33f8707e228b962d1accf58f8cristy (ssize_t) floor(y)-1,4,4,resample_filter->exception); 7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (p == (const PixelPacket *) NULL) 7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickFalse; 7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 7903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy n=0; 7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.x=x-floor(x); 7923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy delta.y=y-floor(y); 7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (i=(-1); i < 3L; i++) 7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dy=CubicWeightingFunction((MagickRealType) i-delta.y); 7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for (j=(-1); j < 3L; j++) 7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixels+n); 7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,p,indexes+n,pixels+n); 8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha[n]=1.0; 8013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 8023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 80354ffe7c6780ec1e33f8707e228b962d1accf58f8cristy alpha[n]=QuantumScale*((MagickRealType) 80454ffe7c6780ec1e33f8707e228b962d1accf58f8cristy GetAlphaPixelComponent(p)); 8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[n].red*=alpha[n]; 8063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[n].green*=alpha[n]; 8073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[n].blue*=alpha[n]; 8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels[n].index*=alpha[n]; 8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy dx=CubicWeightingFunction(delta.x-(MagickRealType) j); 8123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=alpha[n]; 8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); 8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red+=gamma*dx*dy*pixels[n].red; 8153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green+=gamma*dx*dy*pixels[n].green; 8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue+=gamma*dx*dy*pixels[n].blue; 8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity+=dx*dy*pixels[n].opacity; 8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index+=gamma*dx*dy*pixels[n].index; 8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy n++; 8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy p++; 8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 8353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% R e s a m p l e P i x e l C o l o r % 8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 8383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 8393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ResamplePixelColor() samples the pixel values surrounding the location 8433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% given using an elliptical weighted average, at the scale previously 8443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% calculated, and in the most efficent manner possible for the 8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% VirtualPixelMethod setting. 8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the ResamplePixelColor method is: 8483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType ResamplePixelColor(ResampleFilter *resample_filter, 8503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% const double u0,const double v0,MagickPixelPacket *pixel) 8513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: the resample filter. 8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o u0,v0: A double representing the center of the area to resample, 8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The distortion transformed transformed x,y coordinate. 8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o pixel: the resampled pixel is returned here. 8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType ResamplePixelColor( 8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResampleFilter *resample_filter,const double u0,const double v0, 8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickPixelPacket *pixel) 8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MagickBooleanType 8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status; 8683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 869490ab03a4e81aa0943087243055c77e3794d75d9anthony ssize_t u,v, v1, v2, uw, hit; 8703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy double u1; 8713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy double U,V,Q,DQ,DDQ; 8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy double divisor_c,divisor_m; 8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register double weight; 8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register const PixelPacket *pixels; 8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register const IndexPacket *indexes; 8763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 879490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_ELLIPSE 880490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "u0=%lf; v0=%lf;\n", u0, v0); 881490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 882490ab03a4e81aa0943087243055c77e3794d75d9anthony 8833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=MagickTrue; 8843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image,pixel); 8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( resample_filter->do_interpolate ) { 8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=InterpolateResampleFilter(resample_filter, 8873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->interpolate,u0,v0,pixel); 8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 8913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 8923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Does resample area Miss the image? 8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy And is that area a simple solid color - then return that color 8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit = 0; 8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy switch ( resample_filter->virtual_pixel ) { 8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case BackgroundVirtualPixelMethod: 8983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case ConstantVirtualPixelMethod: 8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case TransparentVirtualPixelMethod: 9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case BlackVirtualPixelMethod: 9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case GrayVirtualPixelMethod: 9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case WhiteVirtualPixelMethod: 9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case MaskVirtualPixelMethod: 9043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( resample_filter->limit_reached 905d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || u0 + resample_filter->Ulimit < 0.0 906d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || u0 - resample_filter->Ulimit > (double) resample_filter->image->columns 907d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || v0 + resample_filter->Vlimit < 0.0 908d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || v0 - resample_filter->Vlimit > (double) resample_filter->image->rows 9093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ) 9103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit++; 9113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case UndefinedVirtualPixelMethod: 9143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case EdgeVirtualPixelMethod: 915d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony if ( ( u0 + resample_filter->Ulimit < 0.0 && v0 + resample_filter->Vlimit < 0.0 ) 916d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || ( u0 + resample_filter->Ulimit < 0.0 917d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows ) 918d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns 919d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony && v0 + resample_filter->Vlimit < 0.0 ) 920d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns 921d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows ) 9223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ) 9233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit++; 9243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case HorizontalTileVirtualPixelMethod: 926d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony if ( v0 + resample_filter->Vlimit < 0.0 927d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || v0 - resample_filter->Vlimit > (double) resample_filter->image->rows 9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ) 9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit++; /* outside the horizontally tiled images. */ 9303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case VerticalTileVirtualPixelMethod: 932d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony if ( u0 + resample_filter->Ulimit < 0.0 933d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || u0 - resample_filter->Ulimit > (double) resample_filter->image->columns 9343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ) 9353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit++; /* outside the vertically tiled images. */ 9363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case DitherVirtualPixelMethod: 938d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony if ( ( u0 + resample_filter->Ulimit < -32.0 && v0 + resample_filter->Vlimit < -32.0 ) 939d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || ( u0 + resample_filter->Ulimit < -32.0 940d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows+32.0 ) 941d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns+32.0 942d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony && v0 + resample_filter->Vlimit < -32.0 ) 943d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony || ( u0 - resample_filter->Ulimit > (double) resample_filter->image->columns+32.0 944d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony && v0 - resample_filter->Vlimit > (double) resample_filter->image->rows+32.0 ) 9453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ) 9463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit++; 9473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case TileVirtualPixelMethod: 9493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case MirrorVirtualPixelMethod: 9503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case RandomVirtualPixelMethod: 9513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case HorizontalTileEdgeVirtualPixelMethod: 9523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case VerticalTileEdgeVirtualPixelMethod: 9533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case CheckerTileVirtualPixelMethod: 9543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* resampling of area is always needed - no VP limits */ 9553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 9573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( hit ) { 9583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* whole area is a solid color -- just return that color */ 9593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=InterpolateResampleFilter(resample_filter,IntegerInterpolatePixel, 9603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy u0,v0,pixel); 9613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 9623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 9633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 9643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 9653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Scaling limits reached, return an 'averaged' result. 9663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 9673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( resample_filter->limit_reached ) { 9683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy switch ( resample_filter->virtual_pixel ) { 9693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* This is always handled by the above, so no need. 9703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case BackgroundVirtualPixelMethod: 9713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case ConstantVirtualPixelMethod: 9723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case TransparentVirtualPixelMethod: 9733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case GrayVirtualPixelMethod, 9743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case WhiteVirtualPixelMethod 9753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case MaskVirtualPixelMethod: 9763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 9773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case UndefinedVirtualPixelMethod: 9783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case EdgeVirtualPixelMethod: 9793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case DitherVirtualPixelMethod: 9803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case HorizontalTileEdgeVirtualPixelMethod: 9813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case VerticalTileEdgeVirtualPixelMethod: 9829b8a528e6cd0d30f4cde233b09ae22b9d108a441anthony /* We need an average edge pixel, from the correct edge! 9833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy How should I calculate an average edge color? 9843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Just returning an averaged neighbourhood, 9853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy works well in general, but falls down for TileEdge methods. 9863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy This needs to be done properly!!!!!! 9873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 9883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=InterpolateResampleFilter(resample_filter, 9893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy AverageInterpolatePixel,u0,v0,pixel); 9903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case HorizontalTileVirtualPixelMethod: 9923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case VerticalTileVirtualPixelMethod: 9933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* just return the background pixel - Is there more direct way? */ 9943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=InterpolateResampleFilter(resample_filter, 9953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy IntegerInterpolatePixel,(double)-1,(double)-1,pixel); 9963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 9973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case TileVirtualPixelMethod: 9983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case MirrorVirtualPixelMethod: 9993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case RandomVirtualPixelMethod: 10003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy case CheckerTileVirtualPixelMethod: 10013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy default: 10023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* generate a average color of the WHOLE image */ 10033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( resample_filter->average_defined == MagickFalse ) { 10043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Image 10053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *average_image; 10063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy CacheView 10083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *average_view; 10093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy GetMagickPixelPacket(resample_filter->image, 10113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (MagickPixelPacket *)&(resample_filter->average_pixel)); 10123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->average_defined = MagickTrue; 10133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Try to get an averaged pixel color of whole image */ 10153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_image=ResizeImage(resample_filter->image,1,1,BoxFilter,1.0, 10163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->exception); 10173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (average_image == (Image *) NULL) 10183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 10193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *pixel=resample_filter->average_pixel; /* FAILED */ 10203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 10213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_view=AcquireCacheView(average_image); 10233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels=(PixelPacket *)GetCacheViewVirtualPixels(average_view,0,0,1,1, 10243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->exception); 10253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (pixels == (const PixelPacket *) NULL) { 10263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_view=DestroyCacheView(average_view); 10273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_image=DestroyImage(average_image); 10283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *pixel=resample_filter->average_pixel; /* FAILED */ 10293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 10303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=(IndexPacket *) GetCacheViewAuthenticIndexQueue(average_view); 10323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SetMagickPixelPacket(resample_filter->image,pixels,indexes, 10333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy &(resample_filter->average_pixel)); 10343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_view=DestroyCacheView(average_view); 10353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy average_image=DestroyImage(average_image); 1036490ab03a4e81aa0943087243055c77e3794d75d9anthony 1037490ab03a4e81aa0943087243055c77e3794d75d9anthony if ( resample_filter->virtual_pixel == CheckerTileVirtualPixelMethod ) 1038490ab03a4e81aa0943087243055c77e3794d75d9anthony { 1039490ab03a4e81aa0943087243055c77e3794d75d9anthony /* CheckerTile is avergae of image average half background */ 1040490ab03a4e81aa0943087243055c77e3794d75d9anthony /* FUTURE: replace with a 50% blend of both pixels */ 1041490ab03a4e81aa0943087243055c77e3794d75d9anthony 1042490ab03a4e81aa0943087243055c77e3794d75d9anthony weight = QuantumScale*((MagickRealType)(QuantumRange- 1043490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.opacity)); 1044490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.red *= weight; 1045490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.green *= weight; 1046490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.blue *= weight; 1047490ab03a4e81aa0943087243055c77e3794d75d9anthony divisor_c = weight; 1048490ab03a4e81aa0943087243055c77e3794d75d9anthony 1049490ab03a4e81aa0943087243055c77e3794d75d9anthony weight = QuantumScale*((MagickRealType)(QuantumRange- 1050490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->image->background_color.opacity)); 1051490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.red += 1052490ab03a4e81aa0943087243055c77e3794d75d9anthony weight*resample_filter->image->background_color.red; 1053490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.green += 1054490ab03a4e81aa0943087243055c77e3794d75d9anthony weight*resample_filter->image->background_color.green; 1055490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.blue += 1056490ab03a4e81aa0943087243055c77e3794d75d9anthony weight*resample_filter->image->background_color.blue; 1057490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.matte += 1058490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->image->background_color.opacity; 1059490ab03a4e81aa0943087243055c77e3794d75d9anthony divisor_c += weight; 1060490ab03a4e81aa0943087243055c77e3794d75d9anthony 1061490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.red /= divisor_c; 1062490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.green /= divisor_c; 1063490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.blue /= divisor_c; 1064490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->average_pixel.matte /= 2; 1065490ab03a4e81aa0943087243055c77e3794d75d9anthony 1066490ab03a4e81aa0943087243055c77e3794d75d9anthony } 10673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *pixel=resample_filter->average_pixel; 10693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy break; 10703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(status); 10723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 10733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 10753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Initialize weighted average data collection 10763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 10773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit = 0; 10783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy divisor_c = 0.0; 10793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy divisor_m = 0.0; 10803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red = pixel->green = pixel->blue = 0.0; 10813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) pixel->opacity = 0.0; 10823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) pixel->index = 0.0; 10833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 10843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 10853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Determine the parellelogram bounding box fitted to the ellipse 10863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy centered at u0,v0. This area is bounding by the lines... 10873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 1088490ab03a4e81aa0943087243055c77e3794d75d9anthony v1 = (ssize_t)ceil(v0 - resample_filter->Vlimit); /* range of scan lines */ 1089490ab03a4e81aa0943087243055c77e3794d75d9anthony v2 = (ssize_t)floor(v0 + resample_filter->Vlimit); 1090490ab03a4e81aa0943087243055c77e3794d75d9anthony 1091490ab03a4e81aa0943087243055c77e3794d75d9anthony /* scan line start and width accross the parallelogram */ 1092490ab03a4e81aa0943087243055c77e3794d75d9anthony u1 = u0 + (v1-v0)*resample_filter->slope - resample_filter->Uwidth; 1093490ab03a4e81aa0943087243055c77e3794d75d9anthony uw = (ssize_t)(2.0*resample_filter->Uwidth)+1; 10943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1095490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_ELLIPSE 1096490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "v1=%ld; v2=%ld\n", (long)v1, (long)v2); 1097490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "u1=%ld; uw=%ld\n", (long)u1, (long)uw); 1098490ab03a4e81aa0943087243055c77e3794d75d9anthony#else 1099490ab03a4e81aa0943087243055c77e3794d75d9anthony# define DEBUG_HIT_MISS 0 /* only valid if DEBUG_ELLIPSE is enabled */ 1100490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 11013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 11033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Do weighted resampling of all pixels, within the scaled ellipse, 11043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bound by a Parellelogram fitted to the ellipse. 11053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 11063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DDQ = 2*resample_filter->A; 1107490ab03a4e81aa0943087243055c77e3794d75d9anthony for( v=v1; v<=v2; v++ ) { 1108490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_HIT_MISS 1109490ab03a4e81aa0943087243055c77e3794d75d9anthony long uu = ceil(u1); /* actual pixel location (for debug only) */ 1110490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "# scan line from pixel %ld, %ld\n", (long)uu, (long)v); 1111490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 1112490ab03a4e81aa0943087243055c77e3794d75d9anthony u = (ssize_t)ceil(u1); /* first pixel in scanline */ 1113490ab03a4e81aa0943087243055c77e3794d75d9anthony u1 += resample_filter->slope; /* start of next scan line */ 1114490ab03a4e81aa0943087243055c77e3794d75d9anthony 1115490ab03a4e81aa0943087243055c77e3794d75d9anthony 1116490ab03a4e81aa0943087243055c77e3794d75d9anthony /* location of this first pixel, relative to u0,v0 */ 1117490ab03a4e81aa0943087243055c77e3794d75d9anthony U = (double)u-u0; 11183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy V = (double)v-v0; 11193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Q = ellipse quotent ( if Q<F then pixel is inside ellipse) */ 1121490ab03a4e81aa0943087243055c77e3794d75d9anthony Q = (resample_filter->A*U + resample_filter->B*V)*U + resample_filter->C*V*V; 11223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DQ = resample_filter->A*(2.0*U+1) + resample_filter->B*V; 11233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* get the scanline of pixels for this v */ 1125bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy pixels=GetCacheViewVirtualPixels(resample_filter->view,u,v,(size_t) uw, 11263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1,resample_filter->exception); 11273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (pixels == (const PixelPacket *) NULL) 11283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickFalse); 11293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes=GetCacheViewVirtualIndexQueue(resample_filter->view); 11303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* count up the weighted pixel colors */ 11323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy for( u=0; u<uw; u++ ) { 11333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Note that the ellipse has been pre-scaled so F = WLUT_WIDTH */ 11343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( Q < (double)WLUT_WIDTH ) { 11353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy weight = resample_filter->filter_lut[(int)Q]; 11363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->opacity += weight*pixels->opacity; 11383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy divisor_m += weight; 11393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->matte != MagickFalse) 11413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy weight *= QuantumScale*((MagickRealType)(QuantumRange-pixels->opacity)); 11423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->red += weight*pixels->red; 11433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->green += weight*pixels->green; 11443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->blue += weight*pixels->blue; 11453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 11463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixel->index += weight*(*indexes); 11473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy divisor_c += weight; 11483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy hit++; 1150490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_HIT_MISS 1151490ab03a4e81aa0943087243055c77e3794d75d9anthony /* mark the pixel according to hit/miss of the ellipse */ 1152490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 3\n", 1153490ab03a4e81aa0943087243055c77e3794d75d9anthony (long)uu-.1,(double)v-.1,(long)uu+.1,(long)v+.1); 1154490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 3\n", 1155490ab03a4e81aa0943087243055c77e3794d75d9anthony (long)uu+.1,(double)v-.1,(long)uu-.1,(long)v+.1); 1156490ab03a4e81aa0943087243055c77e3794d75d9anthony } else { 1157490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 1\n", 1158490ab03a4e81aa0943087243055c77e3794d75d9anthony (long)uu-.1,(double)v-.1,(long)uu+.1,(long)v+.1); 1159490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "set arrow from %lf,%lf to %lf,%lf nohead ls 1\n", 1160490ab03a4e81aa0943087243055c77e3794d75d9anthony (long)uu+.1,(double)v-.1,(long)uu-.1,(long)v+.1); 1161490ab03a4e81aa0943087243055c77e3794d75d9anthony } 1162490ab03a4e81aa0943087243055c77e3794d75d9anthony uu++; 1163490ab03a4e81aa0943087243055c77e3794d75d9anthony#else 11643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1165490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 11663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy pixels++; 11673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy indexes++; 11683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Q += DQ; 11693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DQ += DDQ; 11703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 11713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1172490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_ELLIPSE 1173490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "Hit=%ld; Total=%ld;\n", (long)hit, (long)uw*(v2-v1) ); 1174490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 11753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 11773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Result sanity check -- this should NOT happen 11783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 1179490ab03a4e81aa0943087243055c77e3794d75d9anthony if ( hit == 0 ) { 11803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* not enough pixels in resampling, resort to direct interpolation */ 1181490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_NO_PIXEL_HIT 11829b8a528e6cd0d30f4cde233b09ae22b9d108a441anthony pixel->opacity = pixel->red = pixel->green = pixel->blue = 0; 11839b8a528e6cd0d30f4cde233b09ae22b9d108a441anthony pixel->red = QuantumRange; /* show pixels for which EWA fails */ 11849b8a528e6cd0d30f4cde233b09ae22b9d108a441anthony#else 11853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy status=InterpolateResampleFilter(resample_filter, 11863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->interpolate,u0,v0,pixel); 11879b8a528e6cd0d30f4cde233b09ae22b9d108a441anthony#endif 11883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return status; 11893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 11903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 11913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* 11923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Finialize results of resampling 11933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 11943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy divisor_m = 1.0/divisor_m; 1195ce70c17bb6433add2eb069515a4f3105989e0662cristy pixel->opacity = (MagickRealType) ClampToQuantum(divisor_m*pixel->opacity); 11963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy divisor_c = 1.0/divisor_c; 1197ce70c17bb6433add2eb069515a4f3105989e0662cristy pixel->red = (MagickRealType) ClampToQuantum(divisor_c*pixel->red); 1198ce70c17bb6433add2eb069515a4f3105989e0662cristy pixel->green = (MagickRealType) ClampToQuantum(divisor_c*pixel->green); 1199ce70c17bb6433add2eb069515a4f3105989e0662cristy pixel->blue = (MagickRealType) ClampToQuantum(divisor_c*pixel->blue); 12003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->image->colorspace == CMYKColorspace) 1201ce70c17bb6433add2eb069515a4f3105989e0662cristy pixel->index = (MagickRealType) ClampToQuantum(divisor_c*pixel->index); 12023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 12033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 12043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1205c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#if EWA && EWA_CLAMP 1206c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony/* 1207c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1208c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% % 1209c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% % 1210c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% % 1211c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony- C l a m p U p A x e s % 1212c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% % 1213c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% % 1214c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% % 1215c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1216c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% 1217c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% ClampUpAxes() function converts the input vectors into a major and minor 1218c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% axis unit vectors, and their magnatude. This form allows us to ensure that 1219c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% the ellipse generated is never smaller than the unit circle and thus never 1220c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% too small for use in EWA resampling. 1221c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% 1222c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% This is purely mathematical 'magic' that was provided by Professor 1223c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% Nicolas Robidoux, in conjunction with his Phd student Chantal Racette. 1224c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% 1225c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% See Reference: "We Recommend Singular Value Decomposition", David Austin 1226c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% http://www.ams.org/samplings/feature-column/fcarc-svd 1227c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% 1228c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% By generating Major and Minor Axis vectors, we can actually use the ellipse 1229c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% in its "canonical form", by remapping the dx,dy of the sampled point into 1230c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% distances along the major and minor axis unit vectors. 1231c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% http://en.wikipedia.org/wiki/Ellipse#Canonical_form 1232c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% 1233c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony*/ 1234c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthonystatic void ClampUpAxes(const double dux, 1235c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double dvx, 1236c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double duy, 1237c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double dvy, 1238c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony double *major_mag, 1239c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony double *minor_mag, 1240c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony double *major_unit_x, 1241c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony double *major_unit_y, 1242c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony double *minor_unit_x, 1243c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony double *minor_unit_y) 1244c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony{ 1245c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1246c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * ClampUpAxes takes an input 2x2 matrix 1247c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1248c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ a b ] = [ dux duy ] 1249c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ c d ] = [ dvx dvy ] 1250c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1251c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * and computes from it the major and minor axis vectors [major_x, 1252c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * major_y] and [minor_x,minor_y] of the smallest ellipse containing 1253c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * both the unit disk and the ellipse which is the image of the unit 1254c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * disk by the linear transformation 1255c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1256c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ dux duy ] [S] = [s] 1257c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ dvx dvy ] [T] = [t] 1258c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1259c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * (The vector [S,T] is the difference between a position in output 1260c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * space and [X,Y]; the vector [s,t] is the difference between a 1261c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * position in input space and [x,y].) 1262c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1263c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1264c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Outputs: 1265c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1266c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * major_mag is the half-length of the major axis of the "new" 1267c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * ellipse (in input space). 1268c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1269c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * minor_mag is the half-length of the minor axis of the "new" 1270c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * ellipse (in input space). 1271c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1272c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * major_unit_x is the x-coordinate of the major axis direction vector 1273c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * of both the "old" and "new" ellipses. 1274c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1275c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * major_unit_y is the y-coordinate of the major axis direction vector. 1276c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1277c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * minor_unit_x is the x-coordinate of the minor axis direction vector. 1278c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1279c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * minor_unit_y is the y-coordinate of the minor axis direction vector. 1280c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1281c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Unit vectors are useful for computing projections, in particular, 1282c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * to compute the distance between a point in output space and the 1283c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * center (of a disk) from the position of the corresponding point 1284c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * in input space. 1285c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1286c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1287c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Discussion: 1288c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1289c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * GOAL: Fix things so that the pullback, in input space, of a disk 1290c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * of radius r in output space is an ellipse which contains, at 1291c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * least, a disc of radius r. (Make this hold for any r>0.) 1292c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1293c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * METHOD: Find the singular values and (unit) left singular vectors 1294c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * of Jinv, clampling up the singular values to 1, and multiplying 1295c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * the unit left singular vectors by the new singular values in 1296c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * order to get the minor and major ellipse axis vectors. 1297c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1298c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Inputs: 1299c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1300c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * The Jacobian matrix of the transformation at the output point 1301c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * under consideration is defined as follows: 1302c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1303c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Consider the transformation (x,y) -> (X,Y) from input locations 1304c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * to output locations. 1305c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1306c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * The Jacobian matrix J is equal to 1307c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1308c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ A, B ] = [ dX/dx, dX/dy ] 1309c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ C, D ] = [ dY/dx, dY/dy ] 1310c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1311c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Consequently, the vector [A,C] is the tangent vector 1312c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * corresponding to input changes in the horizontal direction, and 1313c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * the vector [B,D] is the tangent vector corresponding to input 1314c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * changes in the vertical direction. 1315c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1316c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * In the context of resampling, it is more natural to use the 1317c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * inverse Jacobian matrix Jinv. Jinv is 1318c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1319c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ a, b ] = [ dx/dX, dx/dY ] 1320c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ c, d ] = [ dy/dX, dy/dY ] 1321c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1322c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Note: Jinv can be computed from J with the following matrix 1323c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * formula: 1324c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1325c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Jinv = 1/(A*D-B*C) [ D, -B ] 1326c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * [ -C, A ] 1327c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1328c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1329c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * ClampUpAxes was written by Nicolas Robidoux and Chantal Racette 1330c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * of Laurentian University. The only (possibly) new math in it is 1331c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * the selection of the largest row of the eigen matrix system in 1332c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * order to stabilize the computation in near rank-deficient cases, 1333c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * and the corresponding efficient repair of degenerate cases using 1334c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * the norm of this largest row. 1335c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1336c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double a = dux; 1337c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double b = duy; 1338c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double c = dvx; 1339c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double d = dvy; 1340c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1341c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * n is the matrix Jinv * transpose(Jinv). Eigenvalues of n are the 1342c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * squares of the singular values of Jinv. 1343c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1344c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double aa = a*a; 1345c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double bb = b*b; 1346c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double cc = c*c; 1347c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double dd = d*d; 1348c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1349c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Eigenvectors of n are left singular vectors of Jinv. 1350c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1351c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double n11 = aa+bb; 1352c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double n12 = a*c+b*d; 1353c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double n21 = n12; 1354c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double n22 = cc+dd; 1355c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double det = a*d-b*c; 1356c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double twice_det = det+det; 1357c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double frobenius_squared = n11+n22; 1358c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double discriminant = 1359c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony (frobenius_squared+twice_det)*(frobenius_squared-twice_det); 1360c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double sqrt_discriminant = sqrt(discriminant); 1361c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1362c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * s1 is the largest singular value of the inverse Jacobian 1363c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * matrix. In other words, its reciprocal is the smallest singular 1364c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * value of the Jacobian matrix itself. 1365c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * If s1 = 0, both singular values are 0, and any orthogonal pair of 1366c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * left and right factors produces a singular decomposition of Jinv. 1367c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * 1368c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * At first, we only compute the squares of the singular values. 1369c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1370c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double s1s1 = 0.5*(frobenius_squared+sqrt_discriminant); 1371c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1372c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * s2 the smallest singular value of the inverse Jacobian 1373c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * matrix. Its reciprocal is the largest singular value of the 1374c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Jacobian matrix itself. 1375c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1376c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double s2s2 = 0.5*(frobenius_squared-sqrt_discriminant); 1377c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double s1s1minusn11 = s1s1-n11; 1378c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double s1s1minusn22 = s1s1-n22; 1379c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1380c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * u1, the first column of the U factor of a singular decomposition 1381c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * of Jinv, is a (non-normalized) left singular vector corresponding 1382c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * to s1. It has entries u11 and u21. u1 is an eigenvector of n 1383c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * corresponding to the eigenvalue s1^2. 1384c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1385c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double s1s1minusn11_squared = s1s1minusn11*s1s1minusn11; 1386c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double s1s1minusn22_squared = s1s1minusn22*s1s1minusn22; 1387c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1388c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * The following selects the largest row of n-s1^2 I as the one 1389c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * which is used to find the eigenvector. If both s1^2-n11 and 1390c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * s1^2-n22 are zero, n-s1^2 I is the zero matrix. In that case, 1391c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * any vector is an eigenvector; in addition, norm below is equal to 1392c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * zero, and, in exact arithmetic, this is the only case in which 1393c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * norm = 0. So, setting u1 to the simple but arbitrary vector [1,0] 1394c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * if norm = 0 safely takes care of all cases. 1395c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1396c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double temp_u11 = 1397c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony ( (s1s1minusn11_squared>=s1s1minusn22_squared) ? n12 : s1s1minusn22 ); 1398c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double temp_u21 = 1399c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony ( (s1s1minusn11_squared>=s1s1minusn22_squared) ? s1s1minusn11 : n21 ); 1400c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double norm = sqrt(temp_u11*temp_u11+temp_u21*temp_u21); 1401c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1402c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Finalize the entries of first left singular vector (associated 1403c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * with the largest singular value). 1404c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1405c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double u11 = ( (norm>0.0) ? temp_u11/norm : 1.0 ); 1406c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony const double u21 = ( (norm>0.0) ? temp_u21/norm : 0.0 ); 1407c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* 1408c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony * Clamp the singular values up to 1. 1409c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony */ 1410c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony *major_mag = ( (s1s1<1.0) ? 1.0 : sqrt(s1s1) ); 1411c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony *minor_mag = ( (s2s2<1.0) ? 1.0 : sqrt(s2s2) ); 1412c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony *major_unit_x = u11; 1413c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony *major_unit_y = u21; 1414c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony *minor_unit_x = u21; 1415c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony *minor_unit_y = -u11; 1416c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony} 1417c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony 1418c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#endif 14193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 14203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 14223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 14233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 14243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% S c a l e R e s a m p l e F i l t e r % 14253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 14263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 14273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 14283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ScaleResampleFilter() does all the calculations needed to resample an image 14313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% at a specific scale, defined by two scaling vectors. This not using 14323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% a orthogonal scaling, but two distorted scaling vectors, to allow the 14333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% generation of a angled ellipse. 14343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% As only two deritive scaling vectors are used the center of the ellipse 14363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% must be the center of the lookup. That is any curvature that the 14373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% distortion may produce is discounted. 14383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The input vectors are produced by either finding the derivitives of the 14403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% distortion function, or the partial derivitives from a distortion mapping. 14413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% They do not need to be the orthogonal dx,dy scaling vectors, but can be 14423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% calculated from other derivatives. For example you could use dr,da/r 14433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% polar coordinate vector scaling vectors 14443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 1445c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% If u,v = DistortEquation(x,y) OR u = Fu(x,y); v = Fv(x,y) 1446c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% Then the scaling vectors are determined from the deritives... 14473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% du/dx, dv/dx and du/dy, dv/dy 1448c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% If the resulting scaling vectors is othogonally aligned then... 14493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% dv/dx = 0 and du/dy = 0 1450c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% Producing an othogonally alligned ellipse in source space for the area to 1451c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% be resampled. 14523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% Note that scaling vectors are different to argument order. Argument order 14543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% is the general order the deritives are extracted from the distortion 1455c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% equations, and not the scaling vectors. As such the middle two vaules 1456c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% may be swapped from what you expect. Caution is advised. 14573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14583ebea1e232532895681cd50101ddad0856e9a1d3anthony% WARNING: It is assumed that any SetResampleFilter() method call will 14593ebea1e232532895681cd50101ddad0856e9a1d3anthony% always be performed before the ScaleResampleFilter() method, so that the 14603ebea1e232532895681cd50101ddad0856e9a1d3anthony% size of the ellipse will match the support for the resampling filter being 14613ebea1e232532895681cd50101ddad0856e9a1d3anthony% used. 1462490ab03a4e81aa0943087243055c77e3794d75d9anthony% 14633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the ScaleResampleFilter method is: 14643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% void ScaleResampleFilter(const ResampleFilter *resample_filter, 14663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% const double dux,const double duy,const double dvx,const double dvy) 14673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 14693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: the resampling resample_filterrmation defining the 14713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% image being resampled 14723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o dux,duy,dvx,dvy: 1474c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% The deritives or scaling vectors defining the EWA ellipse. 1475c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% NOTE: watch the order, which is based on the order deritives 1476c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% are usally determined from distortion equations (see above). 1477c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% The middle two values may need to be swapped if you are thinking 1478c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony% in terms of scaling vectors. 14793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 14803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 14813ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void ScaleResampleFilter(ResampleFilter *resample_filter, 14823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const double dux,const double duy,const double dvx,const double dvy) 14833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 1484d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony double A,B,C,F; 14853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1486c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony 14873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 14883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 14893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 14903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->limit_reached = MagickFalse; 14913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->do_interpolate = MagickFalse; 14923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1493b821aafe132291d46e0fb0c2b24e6e467aa17640anthony /* A 'point' filter forces use of interpolation instead of area sampling */ 1494b821aafe132291d46e0fb0c2b24e6e467aa17640anthony if ( resample_filter->filter == PointFilter ) 1495b821aafe132291d46e0fb0c2b24e6e467aa17640anthony return; /* EWA turned off - nothing to do */ 1496b821aafe132291d46e0fb0c2b24e6e467aa17640anthony 1497c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#if DEBUG_ELLIPSE 1498c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony fprintf(stderr, "# -----\n" ); 1499c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony fprintf(stderr, "dux=%lf; dvx=%lf; duy=%lf; dvy=%lf;\n", 1500c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony dux, dvx, duy, dvy); 1501c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#endif 15023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* Find Ellipse Coefficents such that 15043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy A*u^2 + B*u*v + C*v^2 = F 15053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy With u,v relative to point around which we are resampling. 15063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy And the given scaling dx,dy vectors in u,v space 15073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy du/dx,dv/dx and du/dy,dv/dy 15083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 1509c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#if EWA 1510d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony /* Direct conversion of derivatives into elliptical coefficients 1511b821aafe132291d46e0fb0c2b24e6e467aa17640anthony However when magnifying images, the scaling vectors will be small 1512b821aafe132291d46e0fb0c2b24e6e467aa17640anthony resulting in a ellipse that is too small to sample properly. 1513b821aafe132291d46e0fb0c2b24e6e467aa17640anthony As such we need to clamp the major/minor axis to a minumum of 1.0 1514b821aafe132291d46e0fb0c2b24e6e467aa17640anthony to prevent it getting too small. 15153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 1516c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#if EWA_CLAMP 1517c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony { double major_mag, 1518c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony minor_mag, 1519c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony major_x, 1520c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony major_y, 1521c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony minor_x, 1522c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony minor_y; 1523c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony 1524c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony ClampUpAxes(dux,dvx,duy,dvy, &major_mag, &minor_mag, 1525c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony &major_x, &major_y, &minor_x, &minor_y); 1526c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony major_x *= major_mag; major_y *= major_mag; 1527c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony minor_x *= minor_mag; minor_y *= minor_mag; 1528c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#if DEBUG_ELLIPSE 1529c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony fprintf(stderr, "major_x=%lf; major_y=%lf; minor_x=%lf; minor_y=%lf;\n", 1530c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony major_x, major_y, minor_x, minor_y); 1531c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#endif 1532c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony A = major_y*major_y+minor_y*minor_y; 1533c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony B = -2.0*(major_x*major_y+minor_x*minor_y); 1534c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony C = major_x*major_x+minor_x*minor_x; 1535c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony F = major_x*minor_y-minor_x*major_y; 1536c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony F *= F; /* square it */ 1537c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony } 1538c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#else /* raw EWA */ 15393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy A = dvx*dvx+dvy*dvy; 1540d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony B = -2.0*(dux*dvx+duy*dvy); 15413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy C = dux*dux+duy*duy; 1542c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony F = dux*dvy-duy*dvx; 15435708fc6b0e0f06db8096b93f8c0f7eefe2346e32anthony F *= F; /* square it */ 1544c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#endif 1545d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 1546490ab03a4e81aa0943087243055c77e3794d75d9anthony#else /* HQ_EWA */ 1547d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony /* 1548c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony This Paul Heckbert's "Higher Quality EWA" formula, from page 60 in his 1549c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony thesis, which adds a unit circle to the elliptical area so as to do both 1550c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony Reconstruction and Prefiltering of the pixels in the resampling. It also 1551c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony means it is always likely to have at least 4 pixels within the area of the 1552c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony ellipse, for weighted averaging. No scaling will result with F == 4.0 and 1553c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony a circle of radius 2.0, and F smaller than this means magnification is 1554c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony being used. 1555c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony 1556c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony NOTE: This method produces a very blury result at near unity scale while 1557490ab03a4e81aa0943087243055c77e3794d75d9anthony producing perfect results for string minitification and magnifications. 1558490ab03a4e81aa0943087243055c77e3794d75d9anthony 1559c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony However filter support is fixed to 2.0 (no good for Windowed Sinc filters) 15603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 15613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy A = dvx*dvx+dvy*dvy+1; 1562d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony B = -2.0*(dux*dvx+duy*dvy); 15633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy C = dux*dux+duy*duy+1; 15643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy F = A*C - B*B/4; 15653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 15663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1567490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_ELLIPSE 15683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy fprintf(stderr, "A=%lf; B=%lf; C=%lf; F=%lf\n", A,B,C,F); 15693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1570c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony /* Figure out the various information directly about the ellipse. 15713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy This information currently not needed at this time, but may be 15723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy needed later for better limit determination. 1573d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 1574d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony It is also good to have as a record for future debugging 15753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 15763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { double alpha, beta, gamma, Major, Minor; 1577490ab03a4e81aa0943087243055c77e3794d75d9anthony double Eccentricity, Ellipse_Area, Ellipse_Angle; 1578d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 15793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy alpha = A+C; 15803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy beta = A-C; 15813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy gamma = sqrt(beta*beta + B*B ); 15823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if ( alpha - gamma <= MagickEpsilon ) 15843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Major = MagickHuge; 15853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy else 15863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Major = sqrt(2*F/(alpha - gamma)); 15873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Minor = sqrt(2*F/(alpha + gamma)); 15883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1589490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "# Major=%lf; Minor=%lf\n", Major, Minor ); 15903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 15913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* other information about ellipse include... */ 15923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Eccentricity = Major/Minor; 15933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Ellipse_Area = MagickPI*Major*Minor; 1594490ab03a4e81aa0943087243055c77e3794d75d9anthony Ellipse_Angle = atan2(B, A-C); 15953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1596c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony fprintf(stderr, "# Angle=%lf Area=%lf\n", 1597490ab03a4e81aa0943087243055c77e3794d75d9anthony RadiansToDegrees(Ellipse_Angle), Ellipse_Area ); 15983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 15993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif 16003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1601490ab03a4e81aa0943087243055c77e3794d75d9anthony /* The scaling vectors is impossibly large (producing a very large raw F 1602490ab03a4e81aa0943087243055c77e3794d75d9anthony value), we may as well not bother doing any form of resampling, as you 1603490ab03a4e81aa0943087243055c77e3794d75d9anthony risk an near infinite resampled area. In this case some alturnative 1604490ab03a4e81aa0943087243055c77e3794d75d9anthony means of pixel sampling, such as the average of the whole image is needed 1605c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony to get a reasonable result. Calculate only as needed. 16063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy */ 1607490ab03a4e81aa0943087243055c77e3794d75d9anthony if ( (4*A*C - B*B) > MagickHuge ) { 16083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->limit_reached = MagickTrue; 16093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return; 16103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1612490ab03a4e81aa0943087243055c77e3794d75d9anthony /* Scale ellipse by the appropriate size */ 1613490ab03a4e81aa0943087243055c77e3794d75d9anthony F *= resample_filter->support; 1614490ab03a4e81aa0943087243055c77e3794d75d9anthony F *= resample_filter->support; 16153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1616490ab03a4e81aa0943087243055c77e3794d75d9anthony /* Othogonal bounds of the Ellipse */ 1617490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->Ulimit = sqrt(4*C*F/(4*A*C-B*B)); 1618490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->Vlimit = sqrt(4*A*F/(4*A*C-B*B)); 16193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1620490ab03a4e81aa0943087243055c77e3794d75d9anthony /* Horizontally aligned Parallelogram fitted to Ellipse */ 1621490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->Uwidth = sqrt(F/A); /* Parallelogram Width / 2 */ 1622490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->slope = -B/(2*A); /* Slope of the parallelogram */ 1623490ab03a4e81aa0943087243055c77e3794d75d9anthony 1624490ab03a4e81aa0943087243055c77e3794d75d9anthony#if DEBUG_ELLIPSE 1625490ab03a4e81aa0943087243055c77e3794d75d9anthony fprintf(stderr, "Ulimit=%lf; Vlimit=%lf; UWidth=%lf; Slope=%lf;\n", 1626490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->Ulimit, resample_filter->Vlimit, 1627490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->Uwidth, resample_filter->slope ); 1628490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 16293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1630d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony /* Check the absolute area of the Parallogram involved... 16313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * This limit needs more work, as it gets too slow for 16323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy * larger images involved with tiled views of the horizon. */ 163339f347aa142535ededfff86309cc2bb4cf222373cristy if ( (resample_filter->Uwidth * resample_filter->Vlimit) 163439f347aa142535ededfff86309cc2bb4cf222373cristy > (4.0*resample_filter->image_area)) { 16353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->limit_reached = MagickTrue; 16363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return; 16373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16395708fc6b0e0f06db8096b93f8c0f7eefe2346e32anthony /* Scale ellipse formula to directly index the Filter Lookup Table */ 16403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { register double scale; 1641490ab03a4e81aa0943087243055c77e3794d75d9anthony scale = (double)WLUT_WIDTH/F; 16423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->A = A*scale; 16433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->B = B*scale; 16443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->C = C*scale; 16453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /* ..ple_filter->F = WLUT_WIDTH; -- hardcoded */ 16463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 16473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 16483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 16503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 16523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 16533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 16543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% S e t R e s a m p l e F i l t e r % 16553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 16563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 16573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 16583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% SetResampleFilter() set the resampling filter lookup table based on a 16613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% specific filter. Note that the filter is used as a radial filter not as a 16623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% two pass othogonally aligned resampling filter. 16633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The default Filter, is Gaussian, which is the standard filter used by the 16653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% original paper on the Elliptical Weighted Everage Algorithm. However other 16663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% filters can also be used. 16673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the SetResampleFilter method is: 16693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% void SetResampleFilter(ResampleFilter *resample_filter, 16713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% const FilterTypes filter,const double blur) 16723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 16743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: resampling resample_filterrmation structure 16763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o filter: the resize filter for elliptical weighting LUT 16783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o blur: filter blur factor (radial scaling) for elliptical weighting LUT 16803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 16813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 16823ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void SetResampleFilter(ResampleFilter *resample_filter, 16833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const FilterTypes filter,const double blur) 16843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 16853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy register int 16863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Q; 16873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy double 16893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy r_scale; 16903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResizeFilter 16923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy *resize_filter; 16933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 16953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 16963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 16973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->filter = filter; 16983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1699490ab03a4e81aa0943087243055c77e3794d75d9anthony if ( filter == PointFilter ) 1700b821aafe132291d46e0fb0c2b24e6e467aa17640anthony { 1701b821aafe132291d46e0fb0c2b24e6e467aa17640anthony resample_filter->do_interpolate = MagickTrue; 1702b821aafe132291d46e0fb0c2b24e6e467aa17640anthony return; /* EWA turned off - nothing more to do */ 1703b821aafe132291d46e0fb0c2b24e6e467aa17640anthony } 17043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1705490ab03a4e81aa0943087243055c77e3794d75d9anthony if ( filter == UndefinedFilter ) 1706b821aafe132291d46e0fb0c2b24e6e467aa17640anthony resample_filter->filter = LanczosFilter; 1707490ab03a4e81aa0943087243055c77e3794d75d9anthony 1708490ab03a4e81aa0943087243055c77e3794d75d9anthony resize_filter = AcquireResizeFilter(resample_filter->image, 1709490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->filter,blur,MagickTrue,resample_filter->exception); 1710490ab03a4e81aa0943087243055c77e3794d75d9anthony if (resize_filter == (ResizeFilter *) NULL) 1711490ab03a4e81aa0943087243055c77e3794d75d9anthony { 17123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) ThrowMagickException(resample_filter->exception,GetMagickModule(), 17133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ModuleError, "UnableToSetFilteringValue", 17143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy "Fall back to default EWA gaussian filter"); 1715490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->filter = PointFilter; 17163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1717490ab03a4e81aa0943087243055c77e3794d75d9anthony 1718c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#if EWA 1719490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->support = GetResizeFilterSupport(resize_filter); 1720490ab03a4e81aa0943087243055c77e3794d75d9anthony if ( resample_filter->filter == GaussianFilter ) 1721c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony resample_filter->support = 2.0; /* larger gaussian support */ 1722c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony#else 1723c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony resample_filter->support = 2.0; /* fixed support size for HQ-EWA */ 1724490ab03a4e81aa0943087243055c77e3794d75d9anthony#endif 1725490ab03a4e81aa0943087243055c77e3794d75d9anthony 1726490ab03a4e81aa0943087243055c77e3794d75d9anthony /* Scale radius so the filter LUT covers the full support range */ 1727490ab03a4e81aa0943087243055c77e3794d75d9anthony r_scale = resample_filter->support*sqrt(1.0/(double)WLUT_WIDTH); 1728490ab03a4e81aa0943087243055c77e3794d75d9anthony 1729490ab03a4e81aa0943087243055c77e3794d75d9anthony /* Fill the LUT with a 1D resize filter function */ 1730490ab03a4e81aa0943087243055c77e3794d75d9anthony for(Q=0; Q<WLUT_WIDTH; Q++) 1731490ab03a4e81aa0943087243055c77e3794d75d9anthony resample_filter->filter_lut[Q] = (double) 1732490ab03a4e81aa0943087243055c77e3794d75d9anthony GetResizeFilterWeight(resize_filter,sqrt((double)Q)*r_scale); 1733490ab03a4e81aa0943087243055c77e3794d75d9anthony 1734490ab03a4e81aa0943087243055c77e3794d75d9anthony /* finished with the resize filter */ 1735490ab03a4e81aa0943087243055c77e3794d75d9anthony resize_filter = DestroyResizeFilter(resize_filter); 1736490ab03a4e81aa0943087243055c77e3794d75d9anthony 17373ebea1e232532895681cd50101ddad0856e9a1d3anthony /* 17383ebea1e232532895681cd50101ddad0856e9a1d3anthony Adjust the scaling of the default unit circle 17393ebea1e232532895681cd50101ddad0856e9a1d3anthony This assumes that any real scaling changes will always 17403ebea1e232532895681cd50101ddad0856e9a1d3anthony take place AFTER the filter method has been initialized. 17413ebea1e232532895681cd50101ddad0856e9a1d3anthony */ 17423ebea1e232532895681cd50101ddad0856e9a1d3anthony 17433ebea1e232532895681cd50101ddad0856e9a1d3anthony ScaleResampleFilter(resample_filter, 1.0, 0.0, 0.0, 1.0); 17443ebea1e232532895681cd50101ddad0856e9a1d3anthony 17455708fc6b0e0f06db8096b93f8c0f7eefe2346e32anthony#if 0 1746490ab03a4e81aa0943087243055c77e3794d75d9anthony This is old code kept for reference only. It is very wrong. 1747d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony /* 1748d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony Create Normal Gaussian 2D Filter Weighted Lookup Table. 1749d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony A normal EWA guassual lookup would use exp(Q*ALPHA) 1750d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony where Q = distance squared from 0.0 (center) to 1.0 (edge) 1751d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony and ALPHA = -4.0*ln(2.0) ==> -2.77258872223978123767 1752d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony However the table is of length 1024, and equates to a radius of 2px 1753d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony thus needs to be scaled by ALPHA*4/1024 and any blur factor squared 1754d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 1755c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony The above came from some reference code provided by Fred Weinhaus 1756c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony and seems to have been a guess that was appropriate for its use 1757c7b82f23bddac7a7ced841ae4fdc225b8e4763afanthony in a 3d perspective landscape mapping program. 1758d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony */ 1759d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony r_scale = -2.77258872223978123767/(WLUT_WIDTH*blur*blur); 1760d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony for(Q=0; Q<WLUT_WIDTH; Q++) 1761d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony resample_filter->filter_lut[Q] = exp((double)Q*r_scale); 1762d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony resample_filter->support = WLUT_WIDTH; 1763d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony break; 17645708fc6b0e0f06db8096b93f8c0f7eefe2346e32anthony#endif 1765490ab03a4e81aa0943087243055c77e3794d75d9anthony 1766e06e4c180324bebbd41bce9ea4898642f380b614anthony#if defined(MAGICKCORE_OPENMP_SUPPORT) 17679b8a528e6cd0d30f4cde233b09ae22b9d108a441anthony /* if( GetOpenMPThreadId() == 0 ) */ 1768e06e4c180324bebbd41bce9ea4898642f380b614anthony#endif 1769e06e4c180324bebbd41bce9ea4898642f380b614anthony if (GetImageArtifact(resample_filter->image,"resample:verbose") 1770e06e4c180324bebbd41bce9ea4898642f380b614anthony != (const char *) NULL) 1771e06e4c180324bebbd41bce9ea4898642f380b614anthony { 1772e06e4c180324bebbd41bce9ea4898642f380b614anthony /* Debug output of the filter weighting LUT 1773e06e4c180324bebbd41bce9ea4898642f380b614anthony Gnuplot the LUT with hoizontal adjusted to 'r' using... 1774e06e4c180324bebbd41bce9ea4898642f380b614anthony plot [0:2][-.2:1] "lut.dat" using (sqrt($0/1024)*2):1 with lines 1775e06e4c180324bebbd41bce9ea4898642f380b614anthony The filter values is normalized for comparision 1776e06e4c180324bebbd41bce9ea4898642f380b614anthony */ 1777d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony printf("#\n"); 1778e06e4c180324bebbd41bce9ea4898642f380b614anthony printf("# Resampling Filter LUT (%d values)\n", WLUT_WIDTH); 1779e06e4c180324bebbd41bce9ea4898642f380b614anthony printf("#\n"); 1780d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony printf("# Note: values in table are using a squared radius lookup.\n"); 1781d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony printf("# And the whole table represents the filters support.\n"); 1782e06e4c180324bebbd41bce9ea4898642f380b614anthony printf("#\n"); 1783e06e4c180324bebbd41bce9ea4898642f380b614anthony for(Q=0; Q<WLUT_WIDTH; Q++) 1784d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony printf("%8.*g %.*g\n", 1785d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony GetMagickPrecision(),sqrt((double)Q)*r_scale, 1786d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony GetMagickPrecision(),resample_filter->filter_lut[Q] ); 1787e06e4c180324bebbd41bce9ea4898642f380b614anthony } 17883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return; 17893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 17903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 17913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 17923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 17943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 17953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 17963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 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 % 17973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 17983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 17993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% SetResampleFilterInterpolateMethod() changes the interpolation method 18033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% associated with the specified resample filter. 18043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the SetResampleFilterInterpolateMethod method is: 18063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType SetResampleFilterInterpolateMethod( 18083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ResampleFilter *resample_filter,const InterpolateMethod method) 18093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 18113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: the resample filter. 18133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o method: the interpolation method. 18153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 18173ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType SetResampleFilterInterpolateMethod( 18183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResampleFilter *resample_filter,const InterpolatePixelMethod method) 18193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 18203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 18213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 18223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->image != (Image *) NULL); 1823d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 18243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->debug != MagickFalse) 18253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 18263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image->filename); 1827d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 18283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->interpolate=method; 1829d638d31054aa44f6f9ea9507d23eca8e29414bd1anthony 18303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 18313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 18323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 18333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/* 18343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 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 % 18393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% % 18423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% SetResampleFilterVirtualPixelMethod() changes the virtual pixel method 18453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% associated with the specified resample filter. 18463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% The format of the SetResampleFilterVirtualPixelMethod method is: 18483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% MagickBooleanType SetResampleFilterVirtualPixelMethod( 18503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% ResampleFilter *resample_filter,const VirtualPixelMethod method) 18513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% A description of each parameter follows: 18533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o resample_filter: the resample filter. 18553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% o method: the virtual pixel method. 18573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy% 18583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/ 18593ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType SetResampleFilterVirtualPixelMethod( 18603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy ResampleFilter *resample_filter,const VirtualPixelMethod method) 18613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 18623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter != (ResampleFilter *) NULL); 18633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->signature == MagickSignature); 18643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy assert(resample_filter->image != (Image *) NULL); 18653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (resample_filter->debug != MagickFalse) 18663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 18673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->image->filename); 18683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy resample_filter->virtual_pixel=method; 18692d5e44dc510676c5dd9c2a3abefcd5e2556b0fe4cristy if (method != UndefinedVirtualPixelMethod) 18702d5e44dc510676c5dd9c2a3abefcd5e2556b0fe4cristy (void) SetCacheViewVirtualPixelMethod(resample_filter->view,method); 18713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return(MagickTrue); 18723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} 1873