diff options
Diffstat (limited to 'MagickCore/stream.c')
-rw-r--r-- | MagickCore/stream.c | 105 |
1 files changed, 70 insertions, 35 deletions
diff --git a/MagickCore/stream.c b/MagickCore/stream.c index f7fd20033..28fa0f25b 100644 --- a/MagickCore/stream.c +++ b/MagickCore/stream.c @@ -17,7 +17,7 @@ % March 2000 % % % % % -% Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization % +% Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization % % dedicated to making software imaging solutions freely available. % % % % You may not use this file except in compliance with the License. You may % @@ -448,10 +448,10 @@ static Quantum *GetAuthenticPixelsFromStream(const Image *image) static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image, const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) { - register Quantum + Quantum *p; - register ssize_t + ssize_t i; assert(image != (Image *) NULL); @@ -515,7 +515,7 @@ static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image, const Quantum *p; - register ssize_t + ssize_t i; assert(image != (Image *) NULL); @@ -881,6 +881,37 @@ MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info, % pixels. % */ + +static inline MagickBooleanType ValidatePixelCacheMorphology( + const Image *magick_restrict image) +{ + const CacheInfo + *magick_restrict cache_info; + + const PixelChannelMap + *magick_restrict p, + *magick_restrict q; + + /* + Does the image match the pixel cache morphology? + */ + cache_info=(CacheInfo *) image->cache; + p=image->channel_map; + q=cache_info->channel_map; + if ((image->storage_class != cache_info->storage_class) || + (image->colorspace != cache_info->colorspace) || + (image->alpha_trait != cache_info->alpha_trait) || + (image->channels != cache_info->channels) || + (image->columns != cache_info->columns) || + (image->rows != cache_info->rows) || + (image->number_channels != cache_info->number_channels) || + (memcmp(p,q,image->number_channels*sizeof(*p)) != 0) || + (image->metacontent_extent != cache_info->metacontent_extent) || + (cache_info->nexus_info == (NexusInfo **) NULL)) + return(MagickFalse); + return(MagickTrue); +} + static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, const ssize_t y,const size_t columns,const size_t rows, ExceptionInfo *exception) @@ -922,16 +953,20 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, } cache_info=(CacheInfo *) image->cache; assert(cache_info->signature == MagickCoreSignature); - if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) || - (image->colorspace != GetPixelCacheColorspace(image->cache))) + if (ValidatePixelCacheMorphology(image) == MagickFalse) { - if (GetPixelCacheStorageClass(image->cache) == UndefinedClass) + if (cache_info->storage_class == UndefinedClass) (void) stream_handler(image,(const void *) NULL,(size_t) cache_info->columns); cache_info->storage_class=image->storage_class; cache_info->colorspace=image->colorspace; + cache_info->alpha_trait=image->alpha_trait; + cache_info->channels=image->channels; cache_info->columns=image->columns; cache_info->rows=image->rows; + cache_info->number_channels=image->number_channels; + InitializePixelChannelMap(image); + ResetPixelCacheChannels(image); image->cache=cache_info; } /* @@ -1370,10 +1405,10 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, QuantumType *quantum_map; - register const Quantum + const Quantum *p; - register ssize_t + ssize_t i, x; @@ -1499,7 +1534,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, { case CharPixel: { - register unsigned char + unsigned char *q; q=(unsigned char *) stream_info->pixels; @@ -1583,7 +1618,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=ScaleQuantumToChar(GetPixelRed(image,p)); *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); - *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p))); + *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); p+=GetPixelChannels(image); } break; @@ -1633,12 +1668,12 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case AlphaQuantum: { - *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p))); + *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); break; } case OpacityQuantum: { - *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); + *q=ScaleQuantumToChar(GetPixelOpacity(image,p)); break; } case BlackQuantum: @@ -1663,7 +1698,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case DoublePixel: { - register double + double *q; q=(double *) stream_info->pixels; @@ -1827,7 +1862,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case OpacityQuantum: { - *q=(double) ((QuantumScale*GetPixelAlpha(image,p))* + *q=(double) ((QuantumScale*GetPixelOpacity(image,p))* quantum_info->scale+quantum_info->minimum); break; } @@ -1855,7 +1890,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case FloatPixel: { - register float + float *q; q=(float *) stream_info->pixels; @@ -1889,7 +1924,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, quantum_info->scale+quantum_info->minimum); *q++=(float) ((QuantumScale*GetPixelRed(image,p))* quantum_info->scale+quantum_info->minimum); - *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))* + *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))* quantum_info->scale+quantum_info->minimum); p+=GetPixelChannels(image); } @@ -2019,7 +2054,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case OpacityQuantum: { - *q=(float) ((QuantumScale*GetPixelAlpha(image,p))* + *q=(float) ((QuantumScale*GetPixelOpacity(image,p))* quantum_info->scale+quantum_info->minimum); break; } @@ -2047,7 +2082,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case LongPixel: { - register unsigned int + unsigned int *q; q=(unsigned int *) stream_info->pixels; @@ -2075,7 +2110,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); *q++=ScaleQuantumToLong(GetPixelRed(image,p)); - *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p))); + *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); p+=GetPixelChannels(image); } break; @@ -2131,7 +2166,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=ScaleQuantumToLong(GetPixelRed(image,p)); *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); - *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p))); + *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); p+=GetPixelChannels(image); } break; @@ -2181,12 +2216,12 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case AlphaQuantum: { - *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p))); + *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); break; } case OpacityQuantum: { - *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); + *q=ScaleQuantumToLong(GetPixelOpacity(image,p)); break; } case BlackQuantum: @@ -2211,7 +2246,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case LongLongPixel: { - register MagickSizeType + MagickSizeType *q; q=(MagickSizeType *) stream_info->pixels; @@ -2351,7 +2386,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case OpacityQuantum: { - *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); + *q=ScaleQuantumToLongLong(GetPixelOpacity(image,p)); break; } case BlackQuantum: @@ -2377,7 +2412,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case QuantumPixel: { - register Quantum + Quantum *q; q=(Quantum *) stream_info->pixels; @@ -2420,7 +2455,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=GetPixelBlue(image,p); *q++=GetPixelGreen(image,p); *q++=GetPixelRed(image,p); - *q++=0; + *q++=(Quantum) 0; p+=GetPixelChannels(image); } break; @@ -2476,7 +2511,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=GetPixelRed(image,p); *q++=GetPixelGreen(image,p); *q++=GetPixelBlue(image,p); - *q++=0U; + *q++=(Quantum) 0; p+=GetPixelChannels(image); } break; @@ -2511,12 +2546,12 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case AlphaQuantum: { - *q=(Quantum) (GetPixelAlpha(image,p)); + *q=GetPixelAlpha(image,p); break; } case OpacityQuantum: { - *q=GetPixelAlpha(image,p); + *q=GetPixelOpacity(image,p); break; } case BlackQuantum: @@ -2531,7 +2566,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, break; } default: - *q=0; + *q=(Quantum) 0; } q++; } @@ -2541,7 +2576,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case ShortPixel: { - register unsigned short + unsigned short *q; q=(unsigned short *) stream_info->pixels; @@ -2569,7 +2604,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); *q++=ScaleQuantumToShort(GetPixelRed(image,p)); - *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p))); + *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); p+=GetPixelChannels(image); } break; @@ -2626,7 +2661,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, *q++=ScaleQuantumToShort(GetPixelRed(image,p)); *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); - *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p))); + *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); p+=GetPixelChannels(image); } break; @@ -2681,7 +2716,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, } case OpacityQuantum: { - *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); + *q=ScaleQuantumToShort(GetPixelOpacity(image,p)); break; } case BlackQuantum: |