% M M A A P %
% %
% %
-% Read/Write Image Colormaps As An Image File. %
+% Read/Write Image Colormaps as an Image File. %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2011 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");
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
/*
Read image pixels.
*/
p++;
}
SetPixelIndex(image,index,q);
- SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
+ SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
MagickInfo
*entry;
- entry=SetMagickInfo("MAP");
+ entry=AcquireMagickInfo("MAP","MAP","Colormap intensities and indices");
entry->decoder=(DecodeImageHandler *) ReadMAPImage;
entry->encoder=(EncodeImageHandler *) WriteMAPImage;
- entry->adjoin=MagickFalse;
+ entry->flags^=CoderAdjoinFlag;
entry->format_type=ExplicitFormatType;
- entry->raw=MagickTrue;
- entry->endian_support=MagickTrue;
- entry->description=ConstantString("Colormap intensities and indices");
- entry->module=ConstantString("MAP");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
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);
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,RGBColorspace,exception);
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
/*
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);