2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Alias/Wavefront RLE Image Format %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/colormap.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/image.h"
50 #include "magick/image-private.h"
51 #include "magick/list.h"
52 #include "magick/magick.h"
53 #include "magick/memory_.h"
54 #include "magick/monitor.h"
55 #include "magick/monitor-private.h"
56 #include "magick/quantum-private.h"
57 #include "magick/static.h"
58 #include "magick/string_.h"
59 #include "magick/module.h"
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 % R e a d P I X I m a g e %
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % ReadPIXImage() reads a Alias/Wavefront RLE image file and returns it.
73 % It allocates the memory necessary for the new Image structure and returns a
74 % pointer to the new image.
76 % The format of the ReadPIXImage method is:
78 % Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
80 % A description of each parameter follows:
82 % o image_info: the image info.
84 % o exception: return any errors or warnings in this structure.
88 static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
127 assert(image_info != (const ImageInfo *) NULL);
128 assert(image_info->signature == MagickSignature);
129 if (image_info->debug != MagickFalse)
130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
131 image_info->filename);
132 assert(exception != (ExceptionInfo *) NULL);
133 assert(exception->signature == MagickSignature);
134 image=AcquireImage(image_info);
135 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
136 if (status == MagickFalse)
138 image=DestroyImageList(image);
139 return((Image *) NULL);
144 width=ReadBlobMSBShort(image);
145 height=ReadBlobMSBShort(image);
146 (void) ReadBlobMSBShort(image); /* x-offset */
147 (void) ReadBlobMSBShort(image); /* y-offset */
148 bits_per_pixel=ReadBlobMSBShort(image);
149 if ((width == 0UL) || (height == 0UL) || ((bits_per_pixel != 8) &&
150 (bits_per_pixel != 24)))
151 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
155 Initialize image structure.
157 image->columns=width;
159 if (bits_per_pixel == 8)
160 if (AcquireImageColormap(image,256) == MagickFalse)
161 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
162 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
163 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
166 Convert PIX raster image to pixel packets.
171 index=(IndexPacket) 0;
173 for (y=0; y < (ssize_t) image->rows; y++)
175 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
176 if (q == (PixelPacket *) NULL)
178 indexes=GetAuthenticIndexQueue(image);
179 for (x=0; x < (ssize_t) image->columns; x++)
183 length=(size_t) ReadBlobByte(image);
184 if (bits_per_pixel == 8)
185 index=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
188 blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
189 green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
190 red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
193 if (image->storage_class == PseudoClass)
201 if (SyncAuthenticPixels(image,exception) == MagickFalse)
203 if (image->previous == (Image *) NULL)
205 status=SetImageProgress(image,LoadImageTag,y,image->rows);
206 if (status == MagickFalse)
210 if (image->storage_class == PseudoClass)
211 (void) SyncImage(image);
212 if (EOFBlob(image) != MagickFalse)
214 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
219 Proceed to next image.
221 if (image_info->number_scenes != 0)
222 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
224 width=ReadBlobMSBLong(image);
225 height=ReadBlobMSBLong(image);
226 (void) ReadBlobMSBShort(image);
227 (void) ReadBlobMSBShort(image);
228 bits_per_pixel=ReadBlobMSBShort(image);
229 status=(width != 0UL) && (height == 0UL) && ((bits_per_pixel == 8) ||
230 (bits_per_pixel == 24)) ? MagickTrue : MagickFalse;
231 if (status == MagickTrue)
234 Allocate next image structure.
236 AcquireNextImage(image_info,image);
237 if (GetNextImageInList(image) == (Image *) NULL)
239 image=DestroyImageList(image);
240 return((Image *) NULL);
242 image=SyncNextImageInList(image);
243 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
245 if (status == MagickFalse)
248 } while (status == MagickTrue);
249 (void) CloseBlob(image);
250 return(GetFirstImageInList(image));
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % R e g i s t e r P I X I m a g e %
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 % RegisterPIXImage() adds attributes for the PIX image format to
265 % the list of supported formats. The attributes include the image format
266 % tag, a method to read and/or write the format, whether the format
267 % supports the saving of more than one frame to the same file or blob,
268 % whether the format supports native in-memory I/O, and a brief
269 % description of the format.
271 % The format of the RegisterPIXImage method is:
273 % size_t RegisterPIXImage(void)
276 ModuleExport size_t RegisterPIXImage(void)
281 entry=SetMagickInfo("PIX");
282 entry->decoder=(DecodeImageHandler *) ReadPIXImage;
283 entry->description=ConstantString("Alias/Wavefront RLE image format");
284 entry->module=ConstantString("PIX");
285 (void) RegisterMagickInfo(entry);
286 return(MagickImageCoderSignature);
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 % U n r e g i s t e r P I X I m a g e %
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % UnregisterPIXImage() removes format registrations made by the
301 % PIX module from the list of supported formats.
303 % The format of the UnregisterPIXImage method is:
305 % UnregisterPIXImage(void)
308 ModuleExport void UnregisterPIXImage(void)
310 (void) UnregisterMagickInfo("PIX");