diff options
Diffstat (limited to 'magick/resize.c')
-rw-r--r-- | magick/resize.c | 165 |
1 files changed, 108 insertions, 57 deletions
diff --git a/magick/resize.c b/magick/resize.c index 57f1de2..66c2a84 100644 --- a/magick/resize.c +++ b/magick/resize.c @@ -1,5 +1,5 @@ /* -% Copyright (C) 2003 - 2019 GraphicsMagick Group +% Copyright (C) 2003 - 2022 GraphicsMagick Group % Copyright (C) 2002 ImageMagick Studio % % This program is covered by multiple licenses, which are described in @@ -849,10 +849,13 @@ HorizontalFilter(const Image * restrict source,Image * restrict destination, MagickBool monitor_active; + const MagickBool + matte = ((destination->matte) || (destination->colorspace == CMYKColorspace)); + MagickPassFail status=MagickPass; - if (IsEventLogging()) + if (IsEventLogged(TransformEvent)) (void) LogMagickEvent(TransformEvent,GetMagickModule(), "Horizontal Filter: %lux%lu => %lux%lu " "(x_factor %g, blur %g, span %"MAGICK_SIZE_T_F"u) ...", @@ -966,27 +969,25 @@ HorizontalFilter(const Image * restrict source,Image * restrict destination, { source_indexes=AccessImmutableIndexes(source); indexes=AccessMutableIndexes(destination); - for (y=0; y < (long) destination->rows; y++) + if (matte) { - double - weight; - - DoublePixelPacket - pixel; - - long - j; - - register long - i; - - pixel=zero; - if ((destination->matte) || (destination->colorspace == CMYKColorspace)) + for (y=0; y < (long) destination->rows; y++) { double transparency_coeff, - normalize; + normalize, + weight; + + DoublePixelPacket + pixel; + + long + j; + register long + i; + + pixel=zero; normalize=0.0; for (i=0; i < n; i++) { @@ -1008,9 +1009,33 @@ HorizontalFilter(const Image * restrict source,Image * restrict destination, q[y].green=RoundDoubleToQuantum(pixel.green); q[y].blue=RoundDoubleToQuantum(pixel.blue); q[y].opacity=RoundDoubleToQuantum(pixel.opacity); + + if ((indexes != (IndexPacket *) NULL) && + (source_indexes != (IndexPacket *) NULL)) + { + i=Min(Max((long) (center+0.5),start),stop-1); + j=y*(contribution[n-1].pixel-contribution[0].pixel+1)+ + (contribution[i-start].pixel-contribution[0].pixel); + indexes[y]=source_indexes[j]; + } } - else + } + else + { + for (y=0; y < (long) destination->rows; y++) { + double + weight; + + DoublePixelPacket + pixel=zero; + + long + j; + + register long + i; + for (i=0; i < n; i++) { j=(long) (y*(contribution[n-1].pixel-contribution[0].pixel+1)+ @@ -1024,15 +1049,15 @@ HorizontalFilter(const Image * restrict source,Image * restrict destination, q[y].green=RoundDoubleToQuantum(pixel.green); q[y].blue=RoundDoubleToQuantum(pixel.blue); q[y].opacity=OpaqueOpacity; - } - if ((indexes != (IndexPacket *) NULL) && - (source_indexes != (IndexPacket *) NULL)) - { - i=Min(Max((long) (center+0.5),start),stop-1); - j=y*(contribution[n-1].pixel-contribution[0].pixel+1)+ - (contribution[i-start].pixel-contribution[0].pixel); - indexes[y]=source_indexes[j]; + if ((indexes != (IndexPacket *) NULL) && + (source_indexes != (IndexPacket *) NULL)) + { + i=Min(Max((long) (center+0.5),start),stop-1); + j=y*(contribution[n-1].pixel-contribution[0].pixel+1)+ + (contribution[i-start].pixel-contribution[0].pixel); + indexes[y]=source_indexes[j]; + } } } if (!SyncImagePixelsEx(destination,exception)) @@ -1068,7 +1093,7 @@ HorizontalFilter(const Image * restrict source,Image * restrict destination, } } - if (IsEventLogging()) + if (IsEventLogged(TransformEvent)) (void) LogMagickEvent(TransformEvent,GetMagickModule(), "%s exit Horizontal Filter", (status == MagickFail ? "Error" : "Normal")); @@ -1101,10 +1126,13 @@ VerticalFilter(const Image * restrict source,Image * restrict destination, MagickBool monitor_active; + const MagickBool + matte = ((destination->matte) || (destination->colorspace == CMYKColorspace)); + MagickPassFail status=MagickPass; - if (IsEventLogging()) + if (IsEventLogged(TransformEvent)) (void) LogMagickEvent(TransformEvent,GetMagickModule(), "Vertical Filter: %lux%lu => %lux%lu " "(y_factor %g, blur %g, span %"MAGICK_SIZE_T_F"u) ...", @@ -1220,26 +1248,23 @@ VerticalFilter(const Image * restrict source,Image * restrict destination, { source_indexes=AccessImmutableIndexes(source); indexes=AccessMutableIndexes(destination); - for (x=0; x < (long) destination->columns; x++) + if (matte) { - double - weight; - - DoublePixelPacket - pixel; - - long - j; - - register long - i; - - pixel=zero; - if ((source->matte) || (source->colorspace == CMYKColorspace)) + for (x=0; x < (long) destination->columns; x++) { double transparency_coeff, - normalize; + normalize, + weight; + + DoublePixelPacket + pixel=zero; + + long + j; + + register long + i; normalize=0.0; for (i=0; i < n; i++) @@ -1263,9 +1288,34 @@ VerticalFilter(const Image * restrict source,Image * restrict destination, q[x].green=RoundDoubleToQuantum(pixel.green); q[x].blue=RoundDoubleToQuantum(pixel.blue); q[x].opacity=RoundDoubleToQuantum(pixel.opacity); + + if ((indexes != (IndexPacket *) NULL) && + (source_indexes != (IndexPacket *) NULL)) + { + i=Min(Max((long) (center+0.5),start),stop-1); + j=(long) ((contribution[i-start].pixel-contribution[0].pixel)* + source->columns+x); + indexes[x]=source_indexes[j]; + } } - else + } + else + { + for (x=0; x < (long) destination->columns; x++) { + double + weight; + + DoublePixelPacket + pixel; + + long + j; + + register long + i; + + pixel=zero; for (i=0; i < n; i++) { j=(long) ((contribution[i].pixel-contribution[0].pixel)* @@ -1279,15 +1329,15 @@ VerticalFilter(const Image * restrict source,Image * restrict destination, q[x].green=RoundDoubleToQuantum(pixel.green); q[x].blue=RoundDoubleToQuantum(pixel.blue); q[x].opacity=OpaqueOpacity; - } - if ((indexes != (IndexPacket *) NULL) && - (source_indexes != (IndexPacket *) NULL)) - { - i=Min(Max((long) (center+0.5),start),stop-1); - j=(long) ((contribution[i-start].pixel-contribution[0].pixel)* - source->columns+x); - indexes[x]=source_indexes[j]; + if ((indexes != (IndexPacket *) NULL) && + (source_indexes != (IndexPacket *) NULL)) + { + i=Min(Max((long) (center+0.5),start),stop-1); + j=(long) ((contribution[i-start].pixel-contribution[0].pixel)* + source->columns+x); + indexes[x]=source_indexes[j]; + } } } if (!SyncImagePixelsEx(destination,exception)) @@ -1324,7 +1374,7 @@ VerticalFilter(const Image * restrict source,Image * restrict destination, } } - if (IsEventLogging()) + if (IsEventLogged(TransformEvent)) (void) LogMagickEvent(TransformEvent,GetMagickModule(), "%s exit Vertical Filter", (status == MagickFail ? "Error" : "Normal")); @@ -1435,7 +1485,7 @@ MagickExport Image *ResizeImage(const Image *image,const unsigned long columns, ((x_factor*y_factor) > 1.0)) i=(long) MitchellFilter; - if (IsEventLogging()) + if (IsEventLogged(TransformEvent)) (void) LogMagickEvent(TransformEvent,GetMagickModule(), "Resizing image of size %lux%lu to %lux%lu using %s filter", image->columns,image->rows,columns,rows, @@ -1464,7 +1514,7 @@ MagickExport Image *ResizeImage(const Image *image,const unsigned long columns, */ status=MagickPass; quantum=0; - if (IsEventLogging()) + if (IsEventLogged(TransformEvent)) (void) LogMagickEvent(TransformEvent,GetMagickModule(), "Resize filter order: %s", order ? "Horizontal/Vertical" : "Vertical/Horizontal"); @@ -1805,6 +1855,7 @@ MagickExport Image *ScaleImage(const Image *image,const unsigned long columns, MagickFreeMemory(scale_scanline); MagickFreeMemory(x_vector); MagickFreeMemory(y_vector); + MagickFreeMemory(y_volumes); DestroyImage(scale_image); ThrowImageException3(ResourceLimitError,MemoryAllocationFailed, UnableToScaleImage); |