diff options
Diffstat (limited to 'coders/identity.c')
-rw-r--r-- | coders/identity.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/coders/identity.c b/coders/identity.c index e6569a3..3a59beb 100644 --- a/coders/identity.c +++ b/coders/identity.c @@ -1,5 +1,5 @@ /* -% Copyright (C) 2009-2020 GraphicsMagick Group +% Copyright (C) 2009-2023 GraphicsMagick Group % % This program is covered by multiple licenses, which are described in % Copyright.txt. You should have received a copy of Copyright.txt with this @@ -12,6 +12,7 @@ */ #include "magick/studio.h" #include "magick/blob.h" +#include "magick/colormap.h" #include "magick/pixel_cache.h" #include "magick/constitute.h" #include "magick/magick.h" @@ -34,7 +35,8 @@ % identity image. The minimum order which may be specified is 2. Higher % order LUTs contain more colors and are therefore more accurate, but consume % more memory. Typical Hald CLUT identity images have an order of between 8 -% (512x512) and 16 (4096x4096). The default order is 8. +% (512x512) and 16 (4096x4096). An arbitrary maximum order of 40 (a +% 64000x64000 image) is enforced. The default order is 8. % % The format of the ReadIdentityImage method is: % @@ -63,15 +65,13 @@ static Image *ReadIdentityImage(const ImageInfo *image_info, *image; unsigned long - cube_size; + cube_size, + order, + row_count=0; long - order, y; - unsigned long - row_count=0; - unsigned int status=MagickPass; @@ -83,17 +83,23 @@ static Image *ReadIdentityImage(const ImageInfo *image_info, assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); - image=(Image *) NULL; + image=AllocateImage(image_info); order=8; if (image_info->filename[0] != '\0') - order=MagickAtoL(image_info->filename); + if ((status &= MagickAtoULChk(image_info->filename, &order)) != MagickPass) + ThrowReaderException(FileOpenError,UnableToOpenFile,image); + if (order > 40) + ThrowReaderException(FileOpenError,UnableToOpenFile,image); if (order < 2) order=8; - image=AllocateImage(image_info); cube_size=order*order; image->columns=image->rows=order*order*order; + if (image->columns*image->rows <= MaxColormapSize) + if (!AllocateImageColormap(image,(const unsigned long) image->columns*image->rows)) + ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); + #if defined(HAVE_OPENMP) # if defined(TUNE_OPENMP) # pragma omp parallel for schedule(runtime) shared(row_count, status) @@ -109,6 +115,12 @@ static Image *ReadIdentityImage(const ImageInfo *image_info, register PixelPacket *q; + register IndexPacket + *indexes = (IndexPacket *) NULL; + + register unsigned int + index = (unsigned int) y*image->columns; + #if defined(HAVE_OPENMP) # pragma omp critical (GM_IdentityImage) #endif @@ -120,6 +132,9 @@ static Image *ReadIdentityImage(const ImageInfo *image_info, if (q == (PixelPacket *) NULL) thread_status=MagickFail; + if (image->storage_class == PseudoClass) + indexes=AccessMutableIndexes(image); + if (q != (PixelPacket *) NULL) { double @@ -131,9 +146,9 @@ static Image *ReadIdentityImage(const ImageInfo *image_info, blue; blue=y/order; - for(green = 0; green < cube_size; green++) + for (green = 0; green < cube_size; green++) { - for(red = 0; red < cube_size; red++) + for (red = 0; red < cube_size; red++) { value=MaxRGBDouble * (double)red / (double)(cube_size - 1); q->red = RoundDoubleToQuantum(value); @@ -142,6 +157,11 @@ static Image *ReadIdentityImage(const ImageInfo *image_info, value = MaxRGBDouble * (double)blue / (double)(cube_size - 1); q->blue = RoundDoubleToQuantum(value); q->opacity = OpaqueOpacity; + if (indexes != (IndexPacket *) NULL) + { + image->colormap[index]=*q; + *indexes++=index++; + } q++; } } |