% July 1992 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2013 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 %
Include declarations.
*/
#include "MagickCore/studio.h"
+#include "MagickCore/artifact.h"
#include "MagickCore/blob.h"
#include "MagickCore/blob-private.h"
#include "MagickCore/cache.h"
#include "MagickCore/colormap.h"
#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
#include "MagickCore/image.h"
#include "MagickCore/memory_.h"
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
-#include "MagickCore/nt-feature.h"
+#include "MagickCore/nt-base-private.h"
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/quantize.h"
#include "MagickCore/quantum-private.h"
/*
Define declarations.
*/
-#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__) || defined(__MINGW64__)
#define BI_RGB 0
#define BI_RLE8 1
#define BI_BITFIELDS 3
bit,
byte,
bytes_per_line,
- length,
one,
scanline_pad;
offset,
y;
- unsigned char
- *pixels;
-
/*
Open image file.
*/
icon_info.height=(unsigned char) ((int) ReadBlobLSBLong(image)/2);
icon_info.planes=ReadBlobLSBShort(image);
icon_info.bits_per_pixel=ReadBlobLSBShort(image);
- if (icon_info.bits_per_pixel > 32)
- ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- icon_info.compression=ReadBlobLSBLong(image);
- icon_info.image_size=ReadBlobLSBLong(image);
- icon_info.x_pixels=ReadBlobLSBLong(image);
- icon_info.y_pixels=ReadBlobLSBLong(image);
- icon_info.number_colors=ReadBlobLSBLong(image);
- icon_info.colors_important=ReadBlobLSBLong(image);
- image->matte=MagickTrue;
- image->columns=(size_t) icon_file.directory[i].width;
- if ((ssize_t) image->columns > icon_info.width)
- image->columns=(size_t) icon_info.width;
- if (image->columns == 0)
- image->columns=256;
- image->rows=(size_t) icon_file.directory[i].height;
- if ((ssize_t) image->rows > icon_info.height)
- image->rows=(size_t) icon_info.height;
- if (image->rows == 0)
- image->rows=256;
- image->depth=icon_info.bits_per_pixel;
- if (image->debug != MagickFalse)
- {
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " scene = %.20g",(double) i);
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " size = %.20g",(double) icon_info.size);
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " width = %.20g",(double) icon_file.directory[i].width);
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " height = %.20g",(double) icon_file.directory[i].height);
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " colors = %.20g",(double ) icon_info.number_colors);
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " planes = %.20g",(double) icon_info.planes);
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " bpp = %.20g",(double) icon_info.bits_per_pixel);
- }
- if ((icon_info.number_colors != 0) || (icon_info.bits_per_pixel <= 16))
- {
- image->storage_class=PseudoClass;
- image->colors=icon_info.number_colors;
- if (image->colors == 0)
- image->colors=one << icon_info.bits_per_pixel;
- }
- if (image->storage_class == PseudoClass)
- {
- register ssize_t
- i;
-
- size_t
- number_colors,
- one;
-
- unsigned char
- *icon_colormap;
-
- /*
- Read Icon raster colormap.
- */
- one=1;
- number_colors=one << icon_info.bits_per_pixel;
- if (AcquireImageColormap(image,number_colors,exception) == MagickFalse)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- icon_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
- image->colors,4UL*sizeof(*icon_colormap));
- if (icon_colormap == (unsigned char *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- count=ReadBlob(image,(size_t) (4*image->colors),icon_colormap);
- if (count != (ssize_t) (4*image->colors))
- ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
- p=icon_colormap;
- for (i=0; i < (ssize_t) image->colors; i++)
- {
- image->colormap[i].blue=(Quantum) ScaleCharToQuantum(*p++);
- image->colormap[i].green=(Quantum) ScaleCharToQuantum(*p++);
- image->colormap[i].red=(Quantum) ScaleCharToQuantum(*p++);
- p++;
- }
- icon_colormap=(unsigned char *) RelinquishMagickMemory(icon_colormap);
- }
- if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
- if (image->scene >= (image_info->scene+image_info->number_scenes-1))
- break;
- length=icon_file.directory[i].size-40;
- pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
- if (pixels == (unsigned char *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- {
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
- ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
- }
- if (memcmp(pixels,"\211PNG\r\n\032\n",8) == 0)
+ if ((icon_info.planes == 18505) && (icon_info.bits_per_pixel == 21060))
{
Image
*icon_image;
ImageInfo
*read_info;
+ size_t
+ length;
+
+ unsigned char
+ *png;
+
/*
Icon image encoded as a compressed PNG image.
*/
+ length=icon_file.directory[i].size;
+ png=(unsigned char *) AcquireQuantumMemory(length+16,sizeof(*png));
+ if (png == (unsigned char *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ (void) CopyMagickMemory(png,"\211PNG\r\n\032\n\000\000\000\015",12);
+ png[12]=(unsigned char) icon_info.planes;
+ png[13]=(unsigned char) (icon_info.planes >> 8);
+ png[14]=(unsigned char) icon_info.bits_per_pixel;
+ png[15]=(unsigned char) (icon_info.bits_per_pixel >> 8);
+ count=ReadBlob(image,length-16,png+16);
+ if (count != (ssize_t) (length-16))
+ {
+ png=(unsigned char *) RelinquishMagickMemory(png);
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ }
read_info=CloneImageInfo(image_info);
(void) CopyMagickString(read_info->magick,"PNG",MaxTextExtent);
- icon_image=BlobToImage(read_info,pixels,length,exception);
+ icon_image=BlobToImage(read_info,png,length+16,exception);
read_info=DestroyImageInfo(read_info);
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ png=(unsigned char *) RelinquishMagickMemory(png);
if (icon_image == (Image *) NULL)
{
image=DestroyImageList(image);
}
else
{
- register unsigned char
- *p;
+ if (icon_info.bits_per_pixel > 32)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+ icon_info.compression=ReadBlobLSBLong(image);
+ icon_info.image_size=ReadBlobLSBLong(image);
+ icon_info.x_pixels=ReadBlobLSBLong(image);
+ icon_info.y_pixels=ReadBlobLSBLong(image);
+ icon_info.number_colors=ReadBlobLSBLong(image);
+ icon_info.colors_important=ReadBlobLSBLong(image);
+ image->alpha_trait=BlendPixelTrait;
+ image->columns=(size_t) icon_file.directory[i].width;
+ if ((ssize_t) image->columns > icon_info.width)
+ image->columns=(size_t) icon_info.width;
+ if (image->columns == 0)
+ image->columns=256;
+ image->rows=(size_t) icon_file.directory[i].height;
+ if ((ssize_t) image->rows > icon_info.height)
+ image->rows=(size_t) icon_info.height;
+ if (image->rows == 0)
+ image->rows=256;
+ image->depth=icon_info.bits_per_pixel;
+ if (image->debug != MagickFalse)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " scene = %.20g",(double) i);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " size = %.20g",(double) icon_info.size);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " width = %.20g",(double) icon_file.directory[i].width);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " height = %.20g",(double) icon_file.directory[i].height);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " colors = %.20g",(double ) icon_info.number_colors);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " planes = %.20g",(double) icon_info.planes);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " bpp = %.20g",(double) icon_info.bits_per_pixel);
+ }
+ if ((icon_info.number_colors != 0) || (icon_info.bits_per_pixel <= 16))
+ {
+ image->storage_class=PseudoClass;
+ image->colors=icon_info.number_colors;
+ if (image->colors == 0)
+ image->colors=one << icon_info.bits_per_pixel;
+ }
+ if (image->storage_class == PseudoClass)
+ {
+ register ssize_t
+ i;
+
+ size_t
+ number_colors,
+ one;
+ unsigned char
+ *icon_colormap;
+
+ /*
+ Read Icon raster colormap.
+ */
+ one=1;
+ number_colors=one << icon_info.bits_per_pixel;
+ if (AcquireImageColormap(image,number_colors,exception) == MagickFalse)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ icon_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
+ image->colors,4UL*sizeof(*icon_colormap));
+ if (icon_colormap == (unsigned char *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ count=ReadBlob(image,(size_t) (4*image->colors),icon_colormap);
+ if (count != (ssize_t) (4*image->colors))
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ p=icon_colormap;
+ for (i=0; i < (ssize_t) image->colors; i++)
+ {
+ image->colormap[i].blue=(Quantum) ScaleCharToQuantum(*p++);
+ image->colormap[i].green=(Quantum) ScaleCharToQuantum(*p++);
+ image->colormap[i].red=(Quantum) ScaleCharToQuantum(*p++);
+ p++;
+ }
+ icon_colormap=(unsigned char *) RelinquishMagickMemory(icon_colormap);
+ }
/*
Convert Icon raster image to pixel packets.
*/
+ if ((image_info->ping != MagickFalse) &&
+ (image_info->number_scenes != 0))
+ if (image->scene >= (image_info->scene+image_info->number_scenes-1))
+ break;
bytes_per_line=(((image->columns*icon_info.bits_per_pixel)+31) &
~31) >> 3;
(void) bytes_per_line;
scanline_pad=((((image->columns*icon_info.bits_per_pixel)+31) & ~31)-
(image->columns*icon_info.bits_per_pixel)) >> 3;
- p=pixels;
switch (icon_info.bits_per_pixel)
{
case 1:
break;
for (x=0; x < (ssize_t) (image->columns-7); x+=8)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
for (bit=0; bit < 8; bit++)
{
SetPixelIndex(image,((byte & (0x80 >> bit)) != 0 ? 0x01 :
}
if ((image->columns % 8) != 0)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
for (bit=0; bit < (image->columns % 8); bit++)
{
SetPixelIndex(image,((byte & (0x80 >> bit)) != 0 ? 0x01 :
}
}
for (x=0; x < (ssize_t) scanline_pad; x++)
- (void) *p++;
+ (void) ReadBlobByte(image);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
break;
for (x=0; x < ((ssize_t) image->columns-1); x+=2)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
SetPixelIndex(image,((byte >> 4) & 0xf),q);
q+=GetPixelChannels(image);
SetPixelIndex(image,((byte) & 0xf),q);
}
if ((image->columns % 2) != 0)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
SetPixelIndex(image,((byte >> 4) & 0xf),q);
q+=GetPixelChannels(image);
}
for (x=0; x < (ssize_t) scanline_pad; x++)
- (void) *p++;
+ (void) ReadBlobByte(image);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
SetPixelIndex(image,byte,q);
q+=GetPixelChannels(image);
}
for (x=0; x < (ssize_t) scanline_pad; x++)
- (void) *p++;
+ (void) ReadBlobByte(image);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- byte=(size_t) *p++;
- byte|=(size_t) (*p++ << 8);
+ byte=(size_t) ReadBlobByte(image);
+ byte|=(size_t) (ReadBlobByte(image) << 8);
SetPixelIndex(image,byte,q);
q+=GetPixelChannels(image);
}
for (x=0; x < (ssize_t) scanline_pad; x++)
- (void) *p++;
+ (void) ReadBlobByte(image);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
- SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
- SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+ SetPixelBlue(image,ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image)),q);
+ SetPixelGreen(image,ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image)),q);
+ SetPixelRed(image,ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image)),q);
if (icon_info.bits_per_pixel == 32)
- SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+ SetPixelAlpha(image,ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image)),q);
q+=GetPixelChannels(image);
}
if (icon_info.bits_per_pixel == 24)
for (x=0; x < (ssize_t) scanline_pad; x++)
- (void) *p++;
+ (void) ReadBlobByte(image);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
if (image_info->ping == MagickFalse)
- (void) SyncImage(image);
+ (void) SyncImage(image,exception);
if (icon_info.bits_per_pixel != 32)
{
/*
break;
for (x=0; x < ((ssize_t) image->columns-7); x+=8)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
for (bit=0; bit < 8; bit++)
{
SetPixelAlpha(image,(((byte & (0x80 >> bit)) != 0) ?
}
if ((image->columns % 8) != 0)
{
- byte=(size_t) *p++;
+ byte=(size_t) ReadBlobByte(image);
for (bit=0; bit < (image->columns % 8); bit++)
{
SetPixelAlpha(image,(((byte & (0x80 >> bit)) != 0) ?
}
if ((image->columns % 32) != 0)
for (x=0; x < (ssize_t) ((32-(image->columns % 32))/8); x++)
- (void) *p++;
+ (void) ReadBlobByte(image);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
break;
}
}
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
/*
Proceed to next image.
*/
% image format, version 3 for Windows or (if the image has a matte channel)
% version 4.
%
+% It encodes any subimage as a compressed PNG image ("BI_PNG)", only when its
+% dimensions are 256x256 and image->compression is undefined or is defined as
+% ZipCompression.
+%
% The format of the WriteICONImage method is:
%
% MagickBooleanType WriteICONImage(const ImageInfo *image_info,
next=image;
do
{
- if ((next->columns == 256) && (next->rows == 256))
+ if ((next->columns > 255L) && (next->rows > 255L) &&
+ ((next->compression == UndefinedCompression) ||
+ (next->compression == ZipCompression)))
{
Image
*write_image;
unsigned char
*png;
- /*
- Icon image encoded as a compressed PNG image.
- */
write_image=CloneImage(next,0,0,MagickTrue,exception);
if (write_image == (Image *) NULL)
return(MagickFalse);
write_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->filename,"PNG:",MaxTextExtent);
+
+ /* Don't write any ancillary chunks except for gAMA */
+ (void) SetImageArtifact(write_image,"png:include-chunk","none,gama");
+
+ /* Only write PNG32 formatted PNG (32-bit RGBA), 8 bits per channel */
+ (void) SetImageArtifact(write_image,"png:format","png32");
+
png=(unsigned char *) ImageToBlob(write_info,write_image,&length,
exception);
write_image=DestroyImage(write_image);
/*
Initialize ICON raster file header.
*/
- if (next->colorspace != RGBColorspace)
- (void) TransformImageColorspace(next,RGBColorspace);
+ if (IssRGBCompatibleColorspace(next->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(next,sRGBColorspace,exception);
icon_info.file_size=14+12+28;
icon_info.offset_bits=icon_info.file_size;
icon_info.compression=BI_RGB;
case UndefinedResolution:
case PixelsPerInchResolution:
{
- icon_info.x_pixels=(size_t) (100.0*next->x_resolution/2.54);
- icon_info.y_pixels=(size_t) (100.0*next->y_resolution/2.54);
+ icon_info.x_pixels=(size_t) (100.0*next->resolution.x/2.54);
+ icon_info.y_pixels=(size_t) (100.0*next->resolution.y/2.54);
break;
}
case PixelsPerCentimeterResolution:
{
- icon_info.x_pixels=(size_t) (100.0*next->x_resolution);
- icon_info.y_pixels=(size_t) (100.0*next->y_resolution);
+ icon_info.x_pixels=(size_t) (100.0*next->resolution.x);
+ icon_info.y_pixels=(size_t) (100.0*next->resolution.y);
break;
}
}
*q++=ScaleQuantumToChar(GetPixelBlue(next,p));
*q++=ScaleQuantumToChar(GetPixelGreen(next,p));
*q++=ScaleQuantumToChar(GetPixelRed(next,p));
- if (next->matte == MagickFalse)
+ if (next->alpha_trait != BlendPixelTrait)
*q++=ScaleQuantumToChar(QuantumRange);
else
*q++=ScaleQuantumToChar(GetPixelAlpha(next,p));
for (x=0; x < (ssize_t) next->columns; x++)
{
byte<<=1;
- if ((next->matte == MagickTrue) &&
+ if ((next->alpha_trait == BlendPixelTrait) &&
(GetPixelAlpha(next,p) == (Quantum) TransparentAlpha))
byte|=0x01;
bit++;