% July 1992 %
% %
% %
-% Copyright 1999-2009 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 "magick/studio.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/cache.h"
-#include "magick/color.h"
-#include "magick/color-private.h"
-#include "magick/colorspace.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/image.h"
-#include "magick/image-private.h"
-#include "magick/list.h"
-#include "magick/magick.h"
-#include "magick/memory_.h"
-#include "magick/monitor.h"
-#include "magick/monitor-private.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/color.h"
+#include "MagickCore/color-private.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/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/monitor.h"
+#include "MagickCore/monitor-private.h"
+#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
\f
/*
Forward declarations.
*/
static MagickBooleanType
- WriteSUNImage(const ImageInfo *,Image *);
+ WriteSUNImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
const size_t length,unsigned char *pixels,size_t maxpixels)
{
register const unsigned char
- *p, *l;
+ *l,
+ *p;
register unsigned char
*q;
int
bit;
- long
- y;
-
MagickBooleanType
status;
MagickSizeType
number_pixels;
- register IndexPacket
- *indexes;
-
- register long
- x;
-
- register PixelPacket
+ register Quantum
*q;
- register long
- i;
+ register ssize_t
+ i,
+ x;
register unsigned char
*p;
length;
ssize_t
- count;
+ count,
+ y;
SUNInfo
sun_info;
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)
{
image->rows=sun_info.height;
if ((sun_info.depth == 0) || (sun_info.depth > 32))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- image->depth=sun_info.depth <= 8 ? sun_info.depth : MAGICKCORE_QUANTUM_DEPTH;
+ image->depth=sun_info.depth <= 8 ? sun_info.depth :
+ MAGICKCORE_QUANTUM_DEPTH;
if (sun_info.depth < 24)
{
+ size_t
+ one;
+
image->storage_class=PseudoClass;
image->colors=sun_info.maplength;
+ one=1;
if (sun_info.maptype == RMT_NONE)
- image->colors=1 << sun_info.depth;
+ image->colors=one << sun_info.depth;
if (sun_info.maptype == RMT_EQUAL_RGB)
image->colors=sun_info.maplength/3;
}
/*
Create linear color ramp.
*/
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
break;
/*
Read SUN raster colormap.
*/
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
sun_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
sizeof(*sun_colormap));
if (sun_colormap == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,image->colors,sun_colormap);
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);
count=ReadBlob(image,image->colors,sun_colormap);
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);
count=ReadBlob(image,image->colors,sun_colormap);
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);
sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
break;
default:
ThrowReaderException(CoderError,"ColormapTypeNotSupported");
}
- image->matte=sun_info.depth == 32 ? MagickTrue : MagickFalse;
+ image->alpha_trait=sun_info.depth == 32 ? BlendPixelTrait :
+ UndefinedPixelTrait;
image->columns=sun_info.width;
image->rows=sun_info.height;
if (image_info->ping != MagickFalse)
sun_info.length || !sun_info.length)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
number_pixels=(MagickSizeType) image->columns*image->rows;
- if ((sun_info.depth >= 8) &&
+ if ((sun_info.type != RT_ENCODED) && (sun_info.depth >= 8) &&
((number_pixels*((sun_info.depth+7)/8)) > sun_info.length))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
sun_data=(unsigned char *) AcquireQuantumMemory((size_t) sun_info.length,
bytes_per_line=0;
if (sun_info.type == RT_ENCODED)
{
- unsigned long
+ size_t
height;
/*
*/
p=sun_pixels;
if (sun_info.depth == 1)
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < ((long) image->columns-7); x+=8)
+ for (x=0; x < ((ssize_t) image->columns-7); x+=8)
{
for (bit=7; bit >= 0; bit--)
- indexes[x+7-bit]=(IndexPacket) ((*p) & (0x01 << bit) ? 0x00 : 0x01);
+ {
+ SetPixelIndex(image,((*p) & (0x01 << bit) ? 0x00 : 0x01),q);
+ q+=GetPixelChannels(image);
+ }
p++;
}
if ((image->columns % 8) != 0)
{
- for (bit=7; bit >= (long) (8-(image->columns % 8)); bit--)
- indexes[x+7-bit]=(IndexPacket)
- ((*p) & (0x01 << bit) ? 0x00 : 0x01);
+ for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--)
+ {
+ SetPixelIndex(image,(*p) & (0x01 << bit) ? 0x00 : 0x01,q);
+ q+=GetPixelChannels(image);
+ }
p++;
}
if ((((image->columns/8)+(image->columns % 8 ? 1 : 0)) % 2) != 0)
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
(length > (bytes_per_line*image->rows))) ||
((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < (long) image->columns; x++)
- indexes[x]=(IndexPacket) (*p++);
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ SetPixelIndex(image,*p++,q);
+ q+=GetPixelChannels(image);
+ }
if ((image->columns % 2) != 0)
p++;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
}
else
{
- length=image->rows*((image->columns*(image->matte != MagickFalse ? 4 :
- 3))+image->columns % 2);
+ size_t
+ bytes_per_pixel;
+
+ bytes_per_pixel=3;
+ if (image->alpha_trait == BlendPixelTrait)
+ bytes_per_pixel++;
+ length=image->rows*((bytes_per_line*image->columns)+
+ image->columns % 2);
if (((sun_info.type == RT_ENCODED) &&
(length > (bytes_per_line*image->rows))) ||
((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- if (image->matte != MagickFalse)
- q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++));
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
if (sun_info.type == RT_STANDARD)
{
- q->blue=ScaleCharToQuantum(*p++);
- q->green=ScaleCharToQuantum(*p++);
- q->red=ScaleCharToQuantum(*p++);
+ SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+ SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+ SetPixelRed(image,ScaleCharToQuantum(*p++),q);
}
else
{
- q->red=ScaleCharToQuantum(*p++);
- q->green=ScaleCharToQuantum(*p++);
- q->blue=ScaleCharToQuantum(*p++);
+ SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+ SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+ SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
}
if (image->colors != 0)
{
- q->red=image->colormap[(long) q->red].red;
- q->green=image->colormap[(long) q->green].green;
- q->blue=image->colormap[(long) q->blue].blue;
+ SetPixelRed(image,image->colormap[(ssize_t)
+ GetPixelRed(image,q)].red,q);
+ SetPixelGreen(image,image->colormap[(ssize_t)
+ GetPixelGreen(image,q)].green,q);
+ SetPixelBlue(image,image->colormap[(ssize_t)
+ GetPixelBlue(image,q)].blue,q);
}
- q++;
+ q+=GetPixelChannels(image);
}
- if ((image->columns % 2) != 0)
+ if (((bytes_per_pixel*image->columns) % 2) != 0)
p++;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
}
}
if (image->storage_class == PseudoClass)
- (void) SyncImage(image);
+ (void) SyncImage(image,exception);
sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
if (EOFBlob(image) != MagickFalse)
{
/*
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 RegisterSUNImage method is:
%
-% unsigned long RegisterSUNImage(void)
+% size_t RegisterSUNImage(void)
%
*/
-ModuleExport unsigned long RegisterSUNImage(void)
+ModuleExport size_t RegisterSUNImage(void)
{
MagickInfo
*entry;
%
% The format of the WriteSUNImage method is:
%
-% MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WriteSUNImage(const ImageInfo *image_info,
+% Image *image,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
%
% o image: The image.
%
+% o exception: return any errors or warnings in this structure.
+%
*/
-static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
{
#define RMT_EQUAL_RGB 1
#define RMT_NONE 0
maplength;
} SUNInfo;
- long
- y;
-
MagickBooleanType
status;
MagickSizeType
number_pixels;
- register const IndexPacket
- *indexes;
-
- register const PixelPacket
+ register const Quantum
*p;
- register long
+ register ssize_t
+ i,
x;
- register long
- i;
+ ssize_t
+ y;
SUNInfo
sun_info;
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);
scene=0;
/*
Initialize SUN raster file header.
*/
- if (image->colorspace != RGBColorspace)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
sun_info.magic=0x59a66a95;
if ((image->columns != (unsigned int) image->columns) ||
(image->rows != (unsigned int) image->rows))
/*
Full color SUN raster.
*/
- sun_info.depth=(image->matte ? 32U : 24U);
- sun_info.length=(unsigned int) ((image->matte ? 4 : 3)*number_pixels);
- sun_info.length+=image->columns & 0x01 ? image->rows : 0;
+ sun_info.depth=(unsigned int) image->alpha_trait ? 32U : 24U;
+ sun_info.length=(unsigned int) ((image->alpha_trait ? 4 : 3)*number_pixels);
+ sun_info.length+=sun_info.length & 0x01 ? (unsigned int) image->rows :
+ 0;
}
else
- if (IsMonochromeImage(image,&image->exception))
+ if (IsImageMonochrome(image,exception) != MagickFalse)
{
/*
Monochrome SUN raster.
sun_info.depth=1;
sun_info.length=(unsigned int) (((image->columns+7) >> 3)*
image->rows);
- sun_info.length+=((image->columns/8)+(image->columns % 8 ? 1 : 0)) %
- 2 ? image->rows : 0;
+ sun_info.length+=(unsigned int) (((image->columns/8)+(image->columns %
+ 8 ? 1 : 0)) % 2 ? image->rows : 0);
}
else
{
*/
sun_info.depth=8;
sun_info.length=(unsigned int) number_pixels;
- sun_info.length+=image->columns & 0x01 ? image->rows : 0;
+ sun_info.length+=(unsigned int) (image->columns & 0x01 ? image->rows :
+ 0);
sun_info.maptype=RMT_EQUAL_RGB;
sun_info.maplength=(unsigned int) (3*image->colors);
}
*q;
size_t
+ bytes_per_pixel,
length;
unsigned char
/*
Allocate memory for pixels.
*/
+ bytes_per_pixel=3;
+ if (image->alpha_trait == BlendPixelTrait)
+ bytes_per_pixel++;
length=image->columns;
pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
/*
Convert DirectClass packet to SUN RGB pixel.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
q=pixels;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- if (image->matte != MagickFalse)
- *q++=ScaleQuantumToChar((Quantum) (QuantumRange-p->opacity));
- *q++=ScaleQuantumToChar(p->red);
- *q++=ScaleQuantumToChar(p->green);
- *q++=ScaleQuantumToChar(p->blue);
- p++;
+ if (image->alpha_trait == BlendPixelTrait)
+ *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
+ *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+ *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+ *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+ p+=GetPixelChannels(image);
}
- if (image->columns & 0x01)
- *q++=0; /* pad scanline */
+ if (((bytes_per_pixel*image->columns) & 0x01) != 0)
+ *q++='\0'; /* pad scanline */
(void) WriteBlob(image,(size_t) (q-pixels),pixels);
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
}
else
- if (IsMonochromeImage(image,&image->exception))
+ if (IsImageMonochrome(image,exception) != MagickFalse)
{
register unsigned char
bit,
/*
Convert PseudoClass image to a SUN monochrome image.
*/
- (void) SetImageType(image,BilevelType);
- for (y=0; y < (long) image->rows; y++)
+ (void) SetImageType(image,BilevelType,exception);
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
- indexes=GetVirtualIndexQueue(image);
bit=0;
byte=0;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=1;
- if (PixelIntensity(p) < (MagickRealType) (QuantumRange/2.0))
+ if (GetPixelIntensity(image,p) < (double) (QuantumRange/2.0))
byte|=0x01;
bit++;
if (bit == 8)
bit=0;
byte=0;
}
- p++;
+ p+=GetPixelChannels(image);
}
if (bit != 0)
(void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
(void) WriteBlobByte(image,0); /* pad scanline */
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
/*
Dump colormap to file.
*/
- for (i=0; i < (long) image->colors; i++)
- (void) WriteBlobByte(image,
- ScaleQuantumToChar(image->colormap[i].red));
- for (i=0; i < (long) image->colors; i++)
- (void) WriteBlobByte(image,
- ScaleQuantumToChar(image->colormap[i].green));
- for (i=0; i < (long) image->colors; i++)
- (void) WriteBlobByte(image,
- ScaleQuantumToChar(image->colormap[i].blue));
+ for (i=0; i < (ssize_t) image->colors; i++)
+ (void) WriteBlobByte(image,ScaleQuantumToChar(
+ image->colormap[i].red));
+ for (i=0; i < (ssize_t) image->colors; i++)
+ (void) WriteBlobByte(image,ScaleQuantumToChar(
+ image->colormap[i].green));
+ for (i=0; i < (ssize_t) image->colors; i++)
+ (void) WriteBlobByte(image,ScaleQuantumToChar(
+ image->colormap[i].blue));
/*
Convert PseudoClass packet to SUN colormapped pixel.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
- indexes=GetVirtualIndexQueue(image);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- (void) WriteBlobByte(image,(unsigned char) indexes[x]);
- p++;
+ (void) WriteBlobByte(image,(unsigned char)
+ GetPixelIndex(image,p));
+ p+=GetPixelChannels(image);
}
if (image->columns & 0x01)
(void) WriteBlobByte(image,0); /* pad scanline */
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}