% Read URT RLE Image Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 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/property.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/cache.h"
-#include "magick/colormap.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/property.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/colormap.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/pixel.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
operand,
status;
- long
- y;
-
MagickStatusType
flags;
MagickSizeType
number_pixels;
- register IndexPacket
- *indexes;
+ MemoryInfo
+ *pixel_info;
- register long
+ register ssize_t
x;
- register PixelPacket
+ register Quantum
*q;
- register long
+ register ssize_t
i;
register unsigned char
*p;
+ size_t
+ bits_per_pixel,
+ map_length,
+ number_colormaps,
+ number_planes,
+ one;
+
ssize_t
- count;
+ count,
+ y;
unsigned char
background_color[256],
*colormap,
pixel,
plane,
- *rle_pixels;
-
- unsigned long
- bits_per_pixel,
- map_length,
- number_colormaps,
- number_planes;
+ *pixels;
/*
Open image file.
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->columns=ReadBlobLSBShort(image);
image->rows=ReadBlobLSBShort(image);
flags=(MagickStatusType) ReadBlobByte(image);
- image->matte=flags & 0x04 ? MagickTrue : MagickFalse;
+ image->alpha_trait=flags & 0x04 ? BlendPixelTrait : UndefinedPixelTrait;
number_planes=1UL*ReadBlobByte(image);
bits_per_pixel=1UL*ReadBlobByte(image);
number_colormaps=1UL*ReadBlobByte(image);
- map_length=1UL << ReadBlobByte(image);
+ one=1;
+ map_length=one << (unsigned char) ReadBlobByte(image);
if ((number_planes == 0) || (number_planes == 2) || (bits_per_pixel != 8) ||
(image->columns == 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*
No background color-- initialize to black.
*/
- for (i=0; i < (long) number_planes; i++)
+ for (i=0; i < (ssize_t) number_planes; i++)
background_color[i]=0;
(void) ReadBlobByte(image);
}
Initialize background color.
*/
p=background_color;
- for (i=0; i < (long) number_planes; i++)
+ for (i=0; i < (ssize_t) number_planes; i++)
*p++=(unsigned char) ReadBlobByte(image);
}
if ((number_planes & 0x01) == 0)
if (colormap == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
p=colormap;
- for (i=0; i < (long) number_colormaps; i++)
- for (x=0; x < (long) map_length; x++)
+ for (i=0; i < (ssize_t) number_colormaps; i++)
+ for (x=0; x < (ssize_t) map_length; x++)
*p++=(unsigned char) ScaleShortToQuantum(ReadBlobLSBShort(image));
}
if ((flags & 0x08) != 0)
char
*comment;
- unsigned long
+ size_t
length;
/*
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,length-1,(unsigned char *) comment);
comment[length-1]='\0';
- (void) SetImageProperty(image,"comment",comment);
+ (void) SetImageProperty(image,"comment",comment,exception);
comment=DestroyString(comment);
if ((length & 0x01) == 0)
(void) ReadBlobByte(image);
/*
Allocate RLE pixels.
*/
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
number_planes++;
number_pixels=(MagickSizeType) image->columns*image->rows;
if ((number_pixels*number_planes) != (size_t) (number_pixels*number_planes))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- rle_pixels=(unsigned char *) AcquireQuantumMemory(image->columns,
- image->rows*number_planes*sizeof(*rle_pixels));
- if (rle_pixels == (unsigned char *) NULL)
+ pixel_info=AcquireVirtualMemory(image->columns,image->rows*number_planes*
+ sizeof(*pixels));
+ if (pixel_info == (MemoryInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info);
if ((flags & 0x01) && !(flags & 0x02))
{
- long
+ ssize_t
j;
/*
Set background color.
*/
- p=rle_pixels;
- for (i=0; i < (long) number_pixels; i++)
+ p=pixels;
+ for (i=0; i < (ssize_t) number_pixels; i++)
{
- if (image->matte == MagickFalse)
- for (j=0; j < (long) number_planes; j++)
+ if (image->alpha_trait != BlendPixelTrait)
+ for (j=0; j < (ssize_t) number_planes; j++)
*p++=background_color[j];
else
{
- for (j=0; j < (long) (number_planes-1); j++)
+ for (j=0; j < (ssize_t) (number_planes-1); j++)
*p++=background_color[j];
*p++=0; /* initialize matte channel */
}
operand=ReadBlobByte(image);
if (opcode & 0x40)
operand=(int) ReadBlobLSBShort(image);
- p=rle_pixels+((image->rows-y-1)*image->columns*number_planes)+
+ p=pixels+((image->rows-y-1)*image->columns*number_planes)+
x*number_planes+plane;
operand++;
- for (i=0; i < (long) operand; i++)
+ for (i=0; i < (ssize_t) operand; i++)
{
pixel=(unsigned char) ReadBlobByte(image);
- if ((y < (long) image->rows) && ((x+i) < (long) image->columns))
+ if ((y < (ssize_t) image->rows) &&
+ ((x+i) < (ssize_t) image->columns))
*p=pixel;
p+=number_planes;
}
pixel=(unsigned char) ReadBlobByte(image);
(void) ReadBlobByte(image);
operand++;
- p=rle_pixels+((image->rows-y-1)*image->columns*number_planes)+
+ p=pixels+((image->rows-y-1)*image->columns*number_planes)+
x*number_planes+plane;
- for (i=0; i < (long) operand; i++)
+ for (i=0; i < (ssize_t) operand; i++)
{
- if ((y < (long) image->rows) && ((x+i) < (long) image->columns))
+ if ((y < (ssize_t) image->rows) &&
+ ((x+i) < (ssize_t) image->columns))
*p=pixel;
p+=number_planes;
}
Apply colormap affineation to image.
*/
mask=(MagickStatusType) (map_length-1);
- p=rle_pixels;
+ p=pixels;
if (number_colormaps == 1)
- for (i=0; i < (long) number_pixels; i++)
+ for (i=0; i < (ssize_t) number_pixels; i++)
{
*p=colormap[*p & mask];
p++;
}
else
if ((number_planes >= 3) && (number_colormaps >= 3))
- for (i=0; i < (long) number_pixels; i++)
- for (x=0; x < (long) number_planes; x++)
+ for (i=0; i < (ssize_t) number_pixels; i++)
+ for (x=0; x < (ssize_t) number_planes; x++)
{
*p=colormap[x*map_length+(*p & mask)];
p++;
/*
Convert raster image to DirectClass pixel packets.
*/
- p=rle_pixels;
- for (y=0; y < (long) image->rows; y++)
+ p=pixels;
+ 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++)
{
- q->red=ScaleCharToQuantum(*p++);
- q->green=ScaleCharToQuantum(*p++);
- q->blue=ScaleCharToQuantum(*p++);
- if (image->matte != MagickFalse)
- q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++));
- q++;
+ SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+ SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+ SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+ q+=GetPixelChannels(image);
}
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 (number_colormaps == 0)
map_length=256;
- if (AcquireImageColormap(image,map_length) == MagickFalse)
+ if (AcquireImageColormap(image,map_length,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
p=colormap;
if (number_colormaps == 1)
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
/*
Pseudocolor.
}
else
if (number_colormaps > 1)
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[i].red=ScaleCharToQuantum(*p);
image->colormap[i].green=ScaleCharToQuantum(*(p+map_length));
image->colormap[i].blue=ScaleCharToQuantum(*(p+map_length*2));
p++;
}
- p=rle_pixels;
- if (image->matte == MagickFalse)
+ p=pixels;
+ if (image->alpha_trait != BlendPixelTrait)
{
/*
Convert raster image to PseudoClass pixel packets.
*/
- 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 (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;
}
}
- (void) SyncImage(image);
+ (void) SyncImage(image,exception);
}
else
{
/*
Image has a matte channel-- promote to DirectClass.
*/
- 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++)
{
- q->red=image->colormap[*p++].red;
- q->green=image->colormap[*p++].green;
- q->blue=image->colormap[*p++].blue;
- q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++));
- q++;
+ SetPixelRed(image,image->colormap[*p++].red,q);
+ SetPixelGreen(image,image->colormap[*p++].green,q);
+ SetPixelBlue(image,image->colormap[*p++].blue,q);
+ SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+ q+=GetPixelChannels(image);
}
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;
}
}
- image->colormap=(PixelPacket *)
- RelinquishMagickMemory(image->colormap);
+ image->colormap=(PixelInfo *) RelinquishMagickMemory(
+ image->colormap);
image->storage_class=DirectClass;
image->colors=0;
}
}
if (number_colormaps != 0)
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
- rle_pixels=(unsigned char *) RelinquishMagickMemory(rle_pixels);
+ pixel_info=RelinquishVirtualMemory(pixel_info);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
/*
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 RegisterRLEImage method is:
%
-% unsigned long RegisterRLEImage(void)
+% size_t RegisterRLEImage(void)
%
*/
-ModuleExport unsigned long RegisterRLEImage(void)
+ModuleExport size_t RegisterRLEImage(void)
{
MagickInfo
*entry;