% M M A A P %
% %
% %
-% Read/Write Image Colormaps As An Image File. %
+% Read/Write Image Colormaps as an Image File. %
% %
% Software Design %
% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2017 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 %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
image=AcquireImage(image_info,exception);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
/*
Allocate colormap.
*/
- if (IsPaletteImage(image,exception) == MagickFalse)
- (void) SetImageType(image,PaletteType,exception);
+ if (SetImageType(image,PaletteType,exception) == MagickFalse)
+ ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
depth=GetImageQuantumDepth(image,MagickTrue);
packet_size=(size_t) (depth/8);
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
sizeof(*colormap));
if ((pixels == (unsigned char *) NULL) ||
(colormap == (unsigned char *) NULL))
- ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+ {
+ if (colormap != (unsigned char *) NULL)
+ colormap=(unsigned char *) RelinquishMagickMemory(colormap);
+ if (pixels != (unsigned char *) NULL)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+ }
/*
Write colormap to file.
*/
q=colormap;
- if (image->depth <= 8)
+ if (image->colors <= 256)
for (i=0; i < (ssize_t) image->colors; i++)
{
- *q++=(unsigned char) image->colormap[i].red;
- *q++=(unsigned char) image->colormap[i].green;
- *q++=(unsigned char) image->colormap[i].blue;
+ *q++=(unsigned char) ScaleQuantumToChar(image->colormap[i].red);
+ *q++=(unsigned char) ScaleQuantumToChar(image->colormap[i].green);
+ *q++=(unsigned char) ScaleQuantumToChar(image->colormap[i].blue);
}
else
for (i=0; i < (ssize_t) image->colors; i++)
{
- *q++=(unsigned char) ((size_t) image->colormap[i].red >> 8);
- *q++=(unsigned char) image->colormap[i].red;
- *q++=(unsigned char) ((size_t) image->colormap[i].green >> 8);
- *q++=(unsigned char) image->colormap[i].green;
- *q++=(unsigned char) ((size_t) image->colormap[i].blue >> 8);
- *q++=(unsigned char) image->colormap[i].blue;
+ *q++=(unsigned char) (ScaleQuantumToShort(image->colormap[i].red) >> 8);
+ *q++=(unsigned char) (ScaleQuantumToShort(image->colormap[i].red) & 0xff);
+ *q++=(unsigned char) (ScaleQuantumToShort(image->colormap[i].green) >> 8);
+ *q++=(unsigned char) (ScaleQuantumToShort(image->colormap[i].green) &
+ 0xff);
+ *q++=(unsigned char) (ScaleQuantumToShort(image->colormap[i].blue) >> 8);
+ *q++=(unsigned char) (ScaleQuantumToShort(image->colormap[i].blue) &
+ 0xff);
}
(void) WriteBlob(image,packet_size*image->colors,colormap);
colormap=(unsigned char *) RelinquishMagickMemory(colormap);