% 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 "MagickCore/colormap.h"
#include "MagickCore/colormap-private.h"
#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
#include "MagickCore/constitute.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
Forward declarations.
*/
static MagickBooleanType
- WriteMIFFImage(const ImageInfo *,Image *);
+ WriteMIFFImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}
static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
- size_t *length,PixelInfo *pixel)
+ size_t *length,PixelInfo *pixel,ExceptionInfo *exception)
{
const unsigned char
*p;
case 32:
{
pixel->index=ConstrainColormapIndex(image,
- (*p << 24) | (*(p+1) << 16) | (*(p+2) << 8) | *(p+3));
+ (*p << 24) | (*(p+1) << 16) | (*(p+2) << 8) | *(p+3),exception);
p+=4;
break;
}
case 16:
{
- pixel->index=ConstrainColormapIndex(image,(*p << 8) | *(p+1));
+ pixel->index=ConstrainColormapIndex(image,(*p << 8) | *(p+1),
+ exception);
p+=2;
break;
}
case 8:
{
- pixel->index=ConstrainColormapIndex(image,*p);
+ pixel->index=ConstrainColormapIndex(image,*p,exception);
p++;
break;
}
default:
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
+ (void) ThrowMagickException(exception,GetMagickModule(),
CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
}
switch (image->depth)
unsigned char
quantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
p=PushCharPixel(p,&quantum);
pixel->alpha=ScaleCharToQuantum(quantum);
unsigned short
quantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
p=PushShortPixel(MSBEndian,p,&quantum);
pixel->alpha=(Quantum) (quantum >> (image->depth-
unsigned int
quantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
p=PushLongPixel(MSBEndian,p,&quantum);
pixel->alpha=(Quantum) (quantum >> (image->depth-
break;
}
default:
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
+ (void) ThrowMagickException(exception,GetMagickModule(),
CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
}
*length=(size_t) (*p++)+1;
p=PushCharPixel(p,&quantum);
pixel->red=ScaleCharToQuantum(quantum);
- p=PushCharPixel(p,&quantum);
- pixel->green=ScaleCharToQuantum(quantum);
- p=PushCharPixel(p,&quantum);
- pixel->blue=ScaleCharToQuantum(quantum);
+ pixel->green=pixel->red;
+ pixel->blue=pixel->red;
+ if (IsGrayColorspace(image->colorspace) == MagickFalse)
+ {
+ p=PushCharPixel(p,&quantum);
+ pixel->green=ScaleCharToQuantum(quantum);
+ p=PushCharPixel(p,&quantum);
+ pixel->blue=ScaleCharToQuantum(quantum);
+ }
if (image->colorspace == CMYKColorspace)
{
p=PushCharPixel(p,&quantum);
pixel->black=ScaleCharToQuantum(quantum);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
p=PushCharPixel(p,&quantum);
pixel->alpha=ScaleCharToQuantum(quantum);
p=PushShortPixel(MSBEndian,p,&quantum);
pixel->red=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
- p=PushShortPixel(MSBEndian,p,&quantum);
- pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
- p=PushShortPixel(MSBEndian,p,&quantum);
- pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+ pixel->green=pixel->red;
+ pixel->blue=pixel->red;
+ if (IsGrayColorspace(image->colorspace) == MagickFalse)
+ {
+ p=PushShortPixel(MSBEndian,p,&quantum);
+ pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+ p=PushShortPixel(MSBEndian,p,&quantum);
+ pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+ }
if (image->colorspace == CMYKColorspace)
{
p=PushShortPixel(MSBEndian,p,&quantum);
pixel->black=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
p=PushShortPixel(MSBEndian,p,&quantum);
pixel->alpha=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
p=PushLongPixel(MSBEndian,p,&quantum);
pixel->red=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
- p=PushLongPixel(MSBEndian,p,&quantum);
- pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
- p=PushLongPixel(MSBEndian,p,&quantum);
- pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+ pixel->green=pixel->red;
+ pixel->blue=pixel->red;
+ if (IsGrayColorspace(image->colorspace) == MagickFalse)
+ {
+ p=PushLongPixel(MSBEndian,p,&quantum);
+ pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+ p=PushLongPixel(MSBEndian,p,&quantum);
+ pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+ }
if (image->colorspace == CMYKColorspace)
{
p=PushLongPixel(MSBEndian,p,&quantum);
pixel->black=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
p=PushLongPixel(MSBEndian,p,&quantum);
pixel->alpha=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
break;
}
default:
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
- CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
+ (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
+ "ImageDepthNotSupported","`%s'",image->filename);
}
*length=(size_t) (*p++)+1;
}
*image;
int
- c,
- code;
+ c;
+
+ LinkedListInfo
+ *profiles;
#if defined(MAGICKCORE_LZMA_DELEGATE)
lzma_stream
allocator;
#endif
- LinkedListInfo
- *profiles;
-
MagickBooleanType
status;
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
- image=AcquireImage(image_info);
+ image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
c=ReadBlobByte(image);
if (c == EOF)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- code=0;
*id='\0';
(void) ResetMagickMemory(keyword,0,sizeof(keyword));
version=0.0;
+ (void) version;
do
{
/*
for (p=comment; comment != (char *) NULL; p++)
{
c=ReadBlobByte(image);
- if ((c == EOF) || (c == (int) '}'))
- break;
+ if (c == (int) '\\')
+ c=ReadBlobByte(image);
+ else
+ if ((c == EOF) || (c == (int) '}'))
+ break;
if ((size_t) (p-comment+1) >= length)
{
*p='\0';
if (comment == (char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
*p='\0';
- (void) SetImageProperty(image,"comment",comment);
+ (void) SetImageProperty(image,"comment",comment,exception);
comment=DestroyString(comment);
c=ReadBlobByte(image);
}
"MemoryAllocationFailed");
*p++=(char) c;
c=ReadBlobByte(image);
+ if (c == '\\')
+ {
+ c=ReadBlobByte(image);
+ if (c == (int) '}')
+ {
+ *p++=(char) c;
+ c=ReadBlobByte(image);
+ }
+ }
if (*options != '{')
if (isspace((int) ((unsigned char) c)) != 0)
break;
- }
- }
+ } }
*p='\0';
if (*options == '{')
- (void) CopyMagickString(options,options+1,MaxTextExtent);
+ (void) CopyMagickString(options,options+1,strlen(options));
/*
Assign a value to the specified keyword.
*/
switch (*keyword)
{
+ case 'a':
+ case 'A':
+ {
+ if (LocaleCompare(keyword,"alpha-trait") == 0)
+ {
+ ssize_t
+ alpha_trait;
+
+ alpha_trait=ParseCommandOption(MagickPixelTraitOptions,
+ MagickFalse,options);
+ if (alpha_trait < 0)
+ break;
+ image->alpha_trait=(PixelTrait) alpha_trait;
+ break;
+ }
+ (void) SetImageProperty(image,keyword,options,exception);
+ break;
+ }
case 'b':
case 'B':
{
if (LocaleCompare(keyword,"background-color") == 0)
{
- (void) QueryColorDatabase(options,&image->background_color,
- exception);
+ (void) QueryColorCompliance(options,AllCompliance,
+ &image->background_color,exception);
break;
}
if (LocaleCompare(keyword,"blue-primary") == 0)
}
if (LocaleCompare(keyword,"border-color") == 0)
{
- (void) QueryColorDatabase(options,&image->border_color,
- exception);
+ (void) QueryColorCompliance(options,AllCompliance,
+ &image->border_color,exception);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'c':
MagickFalse,options);
if (colorspace < 0)
break;
- image->colorspace=(ColorspaceType) colorspace;
+ (void) SetImageColorspace(image,(ColorspaceType) colorspace, exception);
break;
}
if (LocaleCompare(keyword,"compression") == 0)
image->columns=StringToUnsignedLong(options);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'd':
image->dispose=(DisposeType) dispose;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'e':
image->endian=(EndianType) endian;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'g':
{
if (LocaleCompare(keyword,"gamma") == 0)
{
- image->gamma=InterpretLocaleValue(options,(char **) NULL);
+ image->gamma=StringToDouble(options,(char **) NULL);
break;
}
if (LocaleCompare(keyword,"gravity") == 0)
image->chromaticity.green_primary.x;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'i':
image->iterations=StringToUnsignedLong(options);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'm':
options);
if (matte < 0)
break;
- image->matte=(MagickBooleanType) matte;
+ image->alpha_trait=matte == 0 ? UndefinedPixelTrait :
+ BlendPixelTrait;
break;
}
if (LocaleCompare(keyword,"matte-color") == 0)
{
- (void) QueryColorDatabase(options,&image->matte_color,
- exception);
+ (void) QueryColorCompliance(options,AllCompliance,
+ &image->matte_color,exception);
break;
}
if (LocaleCompare(keyword,"montage") == 0)
(void) CloneString(&image->montage,options);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'o':
case 'O':
{
- if (LocaleCompare(keyword,"opaque") == 0)
- {
- ssize_t
- matte;
-
- matte=ParseCommandOption(MagickBooleanOptions,MagickFalse,
- options);
- if (matte < 0)
- break;
- image->matte=(MagickBooleanType) matte;
- break;
- }
if (LocaleCompare(keyword,"orientation") == 0)
{
ssize_t
image->orientation=(OrientationType) orientation;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'p':
profiles=NewLinkedList(0);
(void) AppendValueToLinkedList(profiles,
AcquireString(keyword+8));
- profile=AcquireStringInfo((size_t) StringToLong(options));
- (void) SetImageProfile(image,keyword+8,profile);
+ profile=BlobToStringInfo((const void *) NULL,(size_t)
+ StringToLong(options));
+ if (profile == (StringInfo *) NULL)
+ ThrowReaderException(ResourceLimitError,
+ "MemoryAllocationFailed");
+ (void) SetImageProfile(image,keyword+8,profile,exception);
profile=DestroyStringInfo(profile);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'q':
quantum_format=(QuantumFormatType) format;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'r':
if (LocaleCompare(keyword,"resolution") == 0)
{
flags=ParseGeometry(options,&geometry_info);
- image->x_resolution=geometry_info.rho;
- image->y_resolution=geometry_info.sigma;
+ image->resolution.x=geometry_info.rho;
+ image->resolution.y=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
- image->y_resolution=image->x_resolution;
+ image->resolution.y=image->resolution.x;
break;
}
if (LocaleCompare(keyword,"rows") == 0)
image->rows=StringToUnsignedLong(options);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 's':
image->scene=StringToUnsignedLong(options);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 't':
image->type=(ImageType) type;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'u':
image->units=(ResolutionType) units;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'v':
{
if (LocaleCompare(keyword,"version") == 0)
{
- version=InterpretLocaleValue(options,(char **) NULL);
+ version=StringToDouble(options,(char **) NULL);
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
case 'w':
{
flags=ParseGeometry(options,&geometry_info);
image->chromaticity.white_point.x=geometry_info.rho;
- image->chromaticity.white_point.y=geometry_info.rho;
- if ((flags & SigmaValue) != 0)
+ image->chromaticity.white_point.y=geometry_info.sigma;
+ if ((flags & SigmaValue) == 0)
image->chromaticity.white_point.y=
image->chromaticity.white_point.x;
break;
}
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
default:
{
- (void) SetImageProperty(image,keyword,options);
+ (void) SetImageProperty(image,keyword,options,exception);
break;
}
}
/*
Create image colormap.
*/
- status=AcquireImageColormap(image,colors != 0 ? colors : 256);
+ status=AcquireImageColormap(image,colors != 0 ? colors : 256,exception);
if (status == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (colors != 0)
packet_size=(size_t) (quantum_info->depth/8);
if (image->storage_class == DirectClass)
packet_size=(size_t) (3*quantum_info->depth/8);
- if (image->matte != MagickFalse)
+ if (IsGrayColorspace(image->colorspace) != MagickFalse)
+ packet_size=quantum_info->depth/8;
+ if (image->alpha_trait == BlendPixelTrait)
packet_size+=quantum_info->depth/8;
if (image->colorspace == CMYKColorspace)
packet_size+=quantum_info->depth/8;
Read image pixels.
*/
quantum_type=RGBQuantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
quantum_type=RGBAQuantum;
if (image->colorspace == CMYKColorspace)
{
quantum_type=CMYKQuantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
quantum_type=CMYKAQuantum;
}
+ if (IsGrayColorspace(image->colorspace) != MagickFalse)
+ {
+ quantum_type=GrayQuantum;
+ if (image->alpha_trait == BlendPixelTrait)
+ quantum_type=GrayAlphaQuantum;
+ }
if (image->storage_class == PseudoClass)
{
quantum_type=IndexQuantum;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
quantum_type=IndexAlphaQuantum;
}
- if (image->colorspace == GRAYColorspace)
- {
- quantum_type=GrayQuantum;
- if (image->matte != MagickFalse)
- quantum_type=GrayAlphaQuantum;
- }
status=MagickTrue;
switch (image->compression)
{
#if defined(MAGICKCORE_BZLIB_DELEGATE)
case BZipCompression:
{
+ int
+ code;
+
(void) ResetMagickMemory(&bzip_info,0,sizeof(bzip_info));
bzip_info.bzalloc=AcquireBZIPMemory;
bzip_info.bzfree=RelinquishBZIPMemory;
#if defined(MAGICKCORE_LZMA_DELEGATE)
case LZMACompression:
{
+ int
+ code;
+
(void) ResetMagickMemory(&allocator,0,sizeof(allocator));
allocator.alloc=AcquireLZMAMemory;
allocator.free=RelinquishLZMAMemory;
case LZWCompression:
case ZipCompression:
{
+ int
+ code;
+
(void) ResetMagickMemory(&zip_info,0,sizeof(zip_info));
zip_info.zalloc=AcquireZIPMemory;
zip_info.zfree=RelinquishZIPMemory;
if (status == MagickFalse)
break;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (const Quantum *) NULL)
+ if (q == (Quantum *) NULL)
break;
switch (image->compression)
{
{
bzip_info.next_in=(char *) compress_pixels;
length=(size_t) BZipMaxExtent(packet_size*image->columns);
- if (version != 0)
+ if (version != 0.0)
length=(size_t) ReadBlobMSBLong(image);
bzip_info.avail_in=(unsigned int) ReadBlob(image,length,
(unsigned char *) bzip_info.next_in);
lzma_info.avail_out=packet_size*image->columns;
do
{
+ int
+ code;
+
if (lzma_info.avail_in == 0)
{
lzma_info.next_in=compress_pixels;
{
zip_info.next_in=compress_pixels;
length=(size_t) ZipMaxExtent(packet_size*image->columns);
- if (version != 0)
+ if (version != 0.0)
length=(size_t) ReadBlobMSBLong(image);
zip_info.avail_in=(unsigned int) ReadBlob(image,length,
zip_info.next_in);
if (length == 0)
{
count=ReadBlob(image,packet_size,pixels);
- PushRunlengthPacket(image,pixels,&length,&pixel);
+ PushRunlengthPacket(image,pixels,&length,&pixel,exception);
}
length--;
if (image->storage_class == PseudoClass)
- SetPixelIndex(image,pixel.index,q);
+ SetPixelIndex(image,ClampToQuantum(pixel.index),q);
else
{
- SetPixelRed(image,pixel.red,q);
- SetPixelGreen(image,pixel.green,q);
- SetPixelBlue(image,pixel.blue,q);
+ SetPixelRed(image,ClampToQuantum(pixel.red),q);
+ SetPixelGreen(image,ClampToQuantum(pixel.green),q);
+ SetPixelBlue(image,ClampToQuantum(pixel.blue),q);
if (image->colorspace == CMYKColorspace)
- SetPixelBlack(image,pixel.black,q);
+ SetPixelBlack(image,ClampToQuantum(pixel.black),q);
}
- if (image->matte != MagickFalse)
- SetPixelAlpha(image,pixel.alpha,q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
q+=GetPixelChannels(image);
}
break;
#if defined(MAGICKCORE_BZLIB_DELEGATE)
case BZipCompression:
{
- if (version == 0)
+ int
+ code;
+
+ if (version == 0.0)
{
MagickOffsetType
offset;
#if defined(MAGICKCORE_LZMA_DELEGATE)
case LZMACompression:
{
+ int
+ code;
+
code=lzma_code(&lzma_info,LZMA_FINISH);
if ((code != LZMA_STREAM_END) && (code != LZMA_OK))
status=MagickFalse;
case LZWCompression:
case ZipCompression:
{
- if (version == 0)
+ int
+ code;
+
+ if (version == 0.0)
{
MagickOffsetType
offset;
/*
Allocate next image structure.
*/
- AcquireNextImage(image_info,image);
+ AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
% The format of the WriteMIFFImage method is:
%
% MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
-% Image *image)
+% Image *image,ExceptionInfo *exception)
%
% Compression code contributed by Kyle Shorter.
%
%
% o image: the image.
%
+% o exception: return any errors or warnings in this structure.
+%
*/
static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
- size_t length,PixelInfo *pixel)
+ size_t length,PixelInfo *pixel,ExceptionInfo *exception)
{
if (image->storage_class != DirectClass)
{
break;
}
default:
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
+ (void) ThrowMagickException(exception,GetMagickModule(),
CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
}
switch (image->depth)
unsigned int
value;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
- value=ScaleQuantumToLong(pixel->alpha);
+ value=ScaleQuantumToLong(ClampToQuantum(pixel->alpha));
pixels=PopLongPixel(MSBEndian,value,pixels);
}
break;
unsigned short
value;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
- value=ScaleQuantumToShort(pixel->alpha);
+ value=ScaleQuantumToShort(ClampToQuantum(pixel->alpha));
pixels=PopShortPixel(MSBEndian,value,pixels);
}
break;
unsigned char
value;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
- value=(unsigned char) ScaleQuantumToChar(pixel->alpha);
+ value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
+ pixel->alpha));
pixels=PopCharPixel(value,pixels);
}
break;
}
default:
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
+ (void) ThrowMagickException(exception,GetMagickModule(),
CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
}
*pixels++=(unsigned char) length;
unsigned int
value;
- value=ScaleQuantumToLong(pixel->red);
- pixels=PopLongPixel(MSBEndian,value,pixels);
- value=ScaleQuantumToLong(pixel->green);
- pixels=PopLongPixel(MSBEndian,value,pixels);
- value=ScaleQuantumToLong(pixel->blue);
+ value=ScaleQuantumToLong(ClampToQuantum(pixel->red));
pixels=PopLongPixel(MSBEndian,value,pixels);
+ if (IsGrayColorspace(image->colorspace) == MagickFalse)
+ {
+ value=ScaleQuantumToLong(ClampToQuantum(pixel->green));
+ pixels=PopLongPixel(MSBEndian,value,pixels);
+ value=ScaleQuantumToLong(ClampToQuantum(pixel->blue));
+ pixels=PopLongPixel(MSBEndian,value,pixels);
+ }
if (image->colorspace == CMYKColorspace)
{
- value=ScaleQuantumToLong(pixel->black);
+ value=ScaleQuantumToLong(ClampToQuantum(pixel->black));
pixels=PopLongPixel(MSBEndian,value,pixels);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
- value=ScaleQuantumToLong(pixel->alpha);
+ value=ScaleQuantumToLong(ClampToQuantum(pixel->alpha));
pixels=PopLongPixel(MSBEndian,value,pixels);
}
break;
unsigned short
value;
- value=ScaleQuantumToShort(pixel->red);
- pixels=PopShortPixel(MSBEndian,value,pixels);
- value=ScaleQuantumToShort(pixel->green);
- pixels=PopShortPixel(MSBEndian,value,pixels);
- value=ScaleQuantumToShort(pixel->blue);
+ value=ScaleQuantumToShort(ClampToQuantum(pixel->red));
pixels=PopShortPixel(MSBEndian,value,pixels);
+ if (IsGrayColorspace(image->colorspace) == MagickFalse)
+ {
+ value=ScaleQuantumToShort(ClampToQuantum(pixel->green));
+ pixels=PopShortPixel(MSBEndian,value,pixels);
+ value=ScaleQuantumToShort(ClampToQuantum(pixel->blue));
+ pixels=PopShortPixel(MSBEndian,value,pixels);
+ }
if (image->colorspace == CMYKColorspace)
{
- value=ScaleQuantumToShort(pixel->black);
+ value=ScaleQuantumToShort(ClampToQuantum(pixel->black));
pixels=PopShortPixel(MSBEndian,value,pixels);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
- value=ScaleQuantumToShort(pixel->alpha);
+ value=ScaleQuantumToShort(ClampToQuantum(pixel->alpha));
pixels=PopShortPixel(MSBEndian,value,pixels);
}
break;
unsigned char
value;
- value=(unsigned char) ScaleQuantumToChar(pixel->red);
- pixels=PopCharPixel(value,pixels);
- value=(unsigned char) ScaleQuantumToChar(pixel->green);
- pixels=PopCharPixel(value,pixels);
- value=(unsigned char) ScaleQuantumToChar(pixel->blue);
+ value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->red));
pixels=PopCharPixel(value,pixels);
+ if (IsGrayColorspace(image->colorspace) == MagickFalse)
+ {
+ value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
+ pixel->green));
+ pixels=PopCharPixel(value,pixels);
+ value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->blue));
+ pixels=PopCharPixel(value,pixels);
+ }
if (image->colorspace == CMYKColorspace)
{
- value=(unsigned char) ScaleQuantumToChar(pixel->black);
+ value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
+ pixel->black));
pixels=PopCharPixel(value,pixels);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
- value=(unsigned char) ScaleQuantumToChar(pixel->alpha);
+ value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
+ pixel->alpha));
pixels=PopCharPixel(value,pixels);
}
break;
}
default:
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
- CorruptImageError,"ImageDepthNotSupported","`%s'",image->filename);
+ (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
+ "ImageDepthNotSupported","`%s'",image->filename);
}
*pixels++=(unsigned char) length;
return(pixels);
}
static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
- Image *image)
+ Image *image,ExceptionInfo *exception)
{
#if defined(MAGICKCORE_BZLIB_DELEGATE)
bz_stream
*property,
*value;
- int
- code;
-
#if defined(MAGICKCORE_LZMA_DELEGATE)
lzma_allocator
allocator;
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickSignature);
+ status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
- code=0;
scene=0;
do
{
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
if ((image->storage_class != PseudoClass) && (image->depth >= 32) &&
(quantum_info->format == UndefinedQuantumFormat) &&
- (IsHighDynamicRangeImage(image,&image->exception) != MagickFalse))
+ (IsHighDynamicRangeImage(image,exception) != MagickFalse))
{
status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
if (status == MagickFalse)
}
if ((image->storage_class == PseudoClass) &&
(image->colors > (size_t) (GetQuantumRange(image->depth)+1)))
- (void) SetImageStorageClass(image,DirectClass,&image->exception);
- if (IsImageGray(image,&image->exception) != MagickFalse)
- {
- (void) SetImageStorageClass(image,DirectClass,&image->exception);
- (void) SetImageColorspace(image,GRAYColorspace,&image->exception);
- }
+ (void) SetImageStorageClass(image,DirectClass,exception);
+ if (IsImageGray(image,exception) != MagickFalse)
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
compression=image->compression;
if (image_info->compression != UndefinedCompression)
compression=image_info->compression;
packet_size=(size_t) (quantum_info->depth/8);
if (image->storage_class == DirectClass)
packet_size=(size_t) (3*quantum_info->depth/8);
- if (image->matte != MagickFalse)
+ if (IsGrayColorspace(image->colorspace) != MagickFalse)
+ packet_size=(size_t) (quantum_info->depth/8);
+ if (image->alpha_trait == BlendPixelTrait)
packet_size+=quantum_info->depth/8;
if (image->colorspace == CMYKColorspace)
packet_size+=quantum_info->depth/8;
*/
(void) WriteBlobString(image,"id=ImageMagick version=1.0\n");
(void) FormatLocaleString(buffer,MaxTextExtent,
- "class=%s colors=%.20g matte=%s\n",CommandOptionToMnemonic(
+ "class=%s colors=%.20g alpha-trait=%s\n",CommandOptionToMnemonic(
MagickClassOptions,image->storage_class),(double) image->colors,
- CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
+ CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
+ image->alpha_trait));
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"columns=%.20g rows=%.20g "
"depth=%.20g\n",(double) image->columns,(double) image->rows,(double)
CommandOptionToMnemonic(MagickResolutionOptions,image->units));
(void) WriteBlobString(image,buffer);
}
- if ((image->x_resolution != 0) || (image->y_resolution != 0))
+ if ((image->resolution.x != 0) || (image->resolution.y != 0))
{
(void) FormatLocaleString(buffer,MaxTextExtent,
- "resolution=%gx%g\n",image->x_resolution,image->y_resolution);
+ "resolution=%gx%g\n",image->resolution.x,image->resolution.y);
(void) WriteBlobString(image,buffer);
}
if ((image->page.width != 0) || (image->page.height != 0))
}
if (image->rendering_intent != UndefinedIntent)
{
- (void) FormatLocaleString(buffer,MaxTextExtent,
- "rendering-intent=%s\n",
- CommandOptionToMnemonic(MagickIntentOptions,image->rendering_intent));
+ (void) FormatLocaleString(buffer,MaxTextExtent,"rendering-intent=%s\n",
+ CommandOptionToMnemonic(MagickIntentOptions,image->rendering_intent));
(void) WriteBlobString(image,buffer);
}
if (image->gamma != 0.0)
(void) WriteBlobString(image,buffer);
}
if (quantum_info->format == FloatingPointQuantumFormat)
- (void) SetImageProperty(image,"quantum:format","floating-point");
+ (void) SetImageProperty(image,"quantum:format","floating-point",
+ exception);
ResetImagePropertyIterator(image);
property=GetNextImageProperty(image);
while (property != (const char *) NULL)
{
(void) FormatLocaleString(buffer,MaxTextExtent,"%s=",property);
(void) WriteBlobString(image,buffer);
- value=GetImageProperty(image,property);
+ value=GetImageProperty(image,property,exception);
if (value != (const char *) NULL)
{
- for (i=0; i < (ssize_t) strlen(value); i++)
+ size_t
+ length;
+
+ length=strlen(value);
+ for (i=0; i < (ssize_t) length; i++)
if (isspace((int) ((unsigned char) value[i])) != 0)
break;
- if (i <= (ssize_t) strlen(value))
- (void) WriteBlobByte(image,'{');
- (void) WriteBlob(image,strlen(value),(const unsigned char *) value);
- if (i <= (ssize_t) strlen(value))
- (void) WriteBlobByte(image,'}');
+ if (i == (ssize_t) length)
+ (void) WriteBlob(image,length,(const unsigned char *) value);
+ else
+ {
+ (void) WriteBlobByte(image,'{');
+ if (strchr(value,'}') == (char *) NULL)
+ (void) WriteBlob(image,length,(const unsigned char *) value);
+ else
+ for (i=0; i < (ssize_t) length; i++)
+ {
+ if (value[i] == (int) '}')
+ (void) WriteBlobByte(image,'\\');
+ (void) WriteBlobByte(image,value[i]);
+ }
+ (void) WriteBlobByte(image,'}');
+ }
}
(void) WriteBlobByte(image,'\n');
property=GetNextImageProperty(image);
#if defined(MAGICKCORE_BZLIB_DELEGATE)
case BZipCompression:
{
+ int
+ code;
+
(void) ResetMagickMemory(&bzip_info,0,sizeof(bzip_info));
bzip_info.bzalloc=AcquireBZIPMemory;
bzip_info.bzfree=RelinquishBZIPMemory;
#if defined(MAGICKCORE_LZMA_DELEGATE)
case LZMACompression:
{
+ int
+ code;
+
(void) ResetMagickMemory(&allocator,0,sizeof(allocator));
allocator.alloc=AcquireLZMAMemory;
allocator.free=RelinquishLZMAMemory;
case LZWCompression:
case ZipCompression:
{
+ int
+ code;
+
(void) ResetMagickMemory(&zip_info,0,sizeof(zip_info));
zip_info.zalloc=AcquireZIPMemory;
zip_info.zfree=RelinquishZIPMemory;
default:
break;
}
- quantum_type=GetQuantumType(image,&image->exception);
+ quantum_type=GetQuantumType(image,exception);
pixels=GetQuantumPixels(quantum_info);
for (y=0; y < (ssize_t) image->rows; y++)
{
if (status == MagickFalse)
break;
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
break;
q=pixels;
bzip_info.next_in=(char *) pixels;
bzip_info.avail_in=(unsigned int) (packet_size*image->columns);
(void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- quantum_type,pixels,&image->exception);
+ quantum_type,pixels,exception);
do
{
+ int
+ code;
+
bzip_info.next_out=(char *) compress_pixels;
bzip_info.avail_out=(unsigned int) BZipMaxExtent(packet_size*
image->columns);
lzma_info.next_in=pixels;
lzma_info.avail_in=packet_size*image->columns;
(void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- quantum_type,pixels,&image->exception);
+ quantum_type,pixels,exception);
do
{
+ int
+ code;
+
lzma_info.next_out=compress_pixels;
lzma_info.avail_out=packet_size*image->columns;
code=lzma_code(&lzma_info,LZMA_RUN);
zip_info.next_in=pixels;
zip_info.avail_in=(uInt) (packet_size*image->columns);
(void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- quantum_type,pixels,&image->exception);
+ quantum_type,pixels,exception);
do
{
+ int
+ code;
+
zip_info.next_out=compress_pixels;
zip_info.avail_out=(uInt) ZipMaxExtent(packet_size*image->columns);
code=deflate(&zip_info,Z_SYNC_FLUSH);
case RLECompression:
{
length=0;
- SetPixelInfo(image,p,&pixel);
+ GetPixelInfoPixel(image,p,&pixel);
p+=GetPixelChannels(image);
for (x=1; x < (ssize_t) image->columns; x++)
{
- SetPixelInfo(image,p,&target);
+ GetPixelInfoPixel(image,p,&target);
if ((length < 255) &&
(IsPixelInfoEquivalent(&pixel,&target) != MagickFalse))
length++;
else
{
- q=PopRunlengthPacket(image,q,length,&pixel);
+ q=PopRunlengthPacket(image,q,length,&pixel,exception);
length=0;
}
- SetPixelInfo(image,p,&pixel);
+ GetPixelInfoPixel(image,p,&pixel);
p+=GetPixelChannels(image);
}
- q=PopRunlengthPacket(image,q,length,&pixel);
+ q=PopRunlengthPacket(image,q,length,&pixel,exception);
(void) WriteBlob(image,(size_t) (q-pixels),pixels);
break;
}
default:
{
(void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- quantum_type,pixels,&image->exception);
+ quantum_type,pixels,exception);
(void) WriteBlob(image,packet_size*image->columns,pixels);
break;
}
#if defined(MAGICKCORE_BZLIB_DELEGATE)
case BZipCompression:
{
+ int
+ code;
+
for ( ; ; )
{
if (status == MagickFalse)
#if defined(MAGICKCORE_LZMA_DELEGATE)
case LZMACompression:
{
+ int
+ code;
+
for ( ; ; )
{
if (status == MagickFalse)
case LZWCompression:
case ZipCompression:
{
+ int
+ code;
+
for ( ; ; )
{
if (status == MagickFalse)
break;
zip_info.next_out=compress_pixels;
- zip_info.avail_out=(uInt) ZipMaxExtent(packet_size*
- image->columns);
+ zip_info.avail_out=(uInt) ZipMaxExtent(packet_size*image->columns);
code=deflate(&zip_info,Z_FINISH);
length=(size_t) (zip_info.next_out-compress_pixels);
if (length > 6)