From 2c8619a2dd04afdc0fec5dd8f0e0dd7d4ce79e47 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 4 Apr 2013 07:19:30 +0000 Subject: [PATCH] Adjustments of -sample sampling point, and user control of that point --- MagickCore/resize.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/MagickCore/resize.c b/MagickCore/resize.c index 40b8d78e1..f618e93d4 100644 --- a/MagickCore/resize.c +++ b/MagickCore/resize.c @@ -2761,6 +2761,9 @@ MagickExport Image *SampleImage(const Image *image,const size_t columns, *x_offset, y; + PointInfo + sample_offset; + /* Initialize sampled image attributes. */ @@ -2777,6 +2780,31 @@ MagickExport Image *SampleImage(const Image *image,const size_t columns, sample_image=CloneImage(image,columns,rows,MagickTrue,exception); if (sample_image == (Image *) NULL) return((Image *) NULL); + + /* + Check for posible user defined sampling offset Artifact + The default sampling offset is in the mid-point of sample regions. + */ + sample_offset.x=sample_offset.y=0.5-MagickEpsilon; + { + const char + *value; + + value=GetImageArtifact(image,"sample:offset"); + if (value != (char *) NULL) + { + GeometryInfo + geometry_info; + MagickStatusType + flags; + + (void) ParseGeometry(value,&geometry_info); + flags=ParseGeometry(value,&geometry_info); + sample_offset.x=sample_offset.y=geometry_info.rho/100.0-MagickEpsilon; + if ((flags & SigmaValue) != 0) + sample_offset.y=geometry_info.sigma/100.0-MagickEpsilon; + } + } /* Allocate scan line buffer and column offset buffers. */ @@ -2788,8 +2816,8 @@ MagickExport Image *SampleImage(const Image *image,const size_t columns, ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); } for (x=0; x < (ssize_t) sample_image->columns; x++) - x_offset[x]=(ssize_t) (((double) x*image->columns)/sample_image->columns+ - 0.5); + x_offset[x]=(ssize_t) ((((double) x+sample_offset.x)*image->columns)/ + sample_image->columns); /* Sample each row. */ @@ -2817,7 +2845,8 @@ MagickExport Image *SampleImage(const Image *image,const size_t columns, if (status == MagickFalse) continue; - y_offset=(ssize_t) (((double) y*image->rows)/sample_image->rows+0.5); + y_offset=(ssize_t) ((((double) y+sample_offset.y)*image->rows)/ + sample_image->rows); p=GetCacheViewVirtualPixels(image_view,0,y_offset,image->columns,1, exception); q=QueueCacheViewAuthenticPixels(sample_view,0,y,sample_image->columns,1, -- 2.40.0