2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Alias/Wavefront RLE Image Format %
20 % Copyright 1999-2009 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/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/image.h"
49 #include "magick/image-private.h"
50 #include "magick/list.h"
51 #include "magick/magick.h"
52 #include "magick/memory_.h"
53 #include "magick/monitor.h"
54 #include "magick/monitor-private.h"
55 #include "magick/quantum-private.h"
56 #include "magick/static.h"
57 #include "magick/string_.h"
58 #include "magick/module.h"
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 % R e a d P I X I m a g e %
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % ReadPIXImage() reads a Alias/Wavefront RLE image file and returns it.
72 % It allocates the memory necessary for the new Image structure and returns a
73 % pointer to the new image.
75 % The format of the ReadPIXImage method is:
77 % Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
79 % A description of each parameter follows:
81 % o image_info: the image info.
83 % o exception: return any errors or warnings in this structure.
87 static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
126 assert(image_info != (const ImageInfo *) NULL);
127 assert(image_info->signature == MagickSignature);
128 if (image_info->debug != MagickFalse)
129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
130 image_info->filename);
131 assert(exception != (ExceptionInfo *) NULL);
132 assert(exception->signature == MagickSignature);
133 image=AcquireImage(image_info);
134 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
135 if (status == MagickFalse)
137 image=DestroyImageList(image);
138 return((Image *) NULL);
143 width=ReadBlobMSBShort(image);
144 height=ReadBlobMSBShort(image);
145 (void) ReadBlobMSBShort(image); /* x-offset */
146 (void) ReadBlobMSBShort(image); /* y-offset */
147 bits_per_pixel=ReadBlobMSBShort(image);
148 if ((width == 0UL) || (height == 0UL) || ((bits_per_pixel != 8) &&
149 (bits_per_pixel != 24)))
150 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
154 Initialize image structure.
156 image->columns=width;
158 if (bits_per_pixel == 8)
159 if (AcquireImageColormap(image,256) == MagickFalse)
160 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
161 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
162 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
165 Convert PIX raster image to pixel packets.
170 index=(IndexPacket) 0;
172 for (y=0; y < (long) image->rows; y++)
174 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
175 if (q == (PixelPacket *) NULL)
177 indexes=GetAuthenticIndexQueue(image);
178 for (x=0; x < (long) image->columns; x++)
182 length=(size_t) ReadBlobByte(image);
183 if (bits_per_pixel == 8)
184 index=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
187 blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
188 green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
189 red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
192 if (image->storage_class == PseudoClass)
200 if (SyncAuthenticPixels(image,exception) == MagickFalse)
202 if (image->previous == (Image *) NULL)
204 status=SetImageProgress(image,LoadImageTag,y,image->rows);
205 if (status == MagickFalse)
209 if (image->storage_class == PseudoClass)
210 (void) SyncImage(image);
211 if (EOFBlob(image) != MagickFalse)
213 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
218 Proceed to next image.
220 if (image_info->number_scenes != 0)
221 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
223 width=ReadBlobMSBLong(image);
224 height=ReadBlobMSBLong(image);
225 (void) ReadBlobMSBShort(image);
226 (void) ReadBlobMSBShort(image);
227 bits_per_pixel=ReadBlobMSBShort(image);
228 status=(width != 0UL) && (height == 0UL) && ((bits_per_pixel == 8) ||
229 (bits_per_pixel == 24)) ? MagickTrue : MagickFalse;
230 if (status == MagickTrue)
233 Allocate next image structure.
235 AcquireNextImage(image_info,image);
236 if (GetNextImageInList(image) == (Image *) NULL)
238 image=DestroyImageList(image);
239 return((Image *) NULL);
241 image=SyncNextImageInList(image);
242 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
244 if (status == MagickFalse)
247 } while (status == MagickTrue);
248 (void) CloseBlob(image);
249 return(GetFirstImageInList(image));
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % R e g i s t e r P I X I m a g e %
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 % RegisterPIXImage() adds attributes for the PIX image format to
264 % the list of supported formats. The attributes include the image format
265 % tag, a method to read and/or write the format, whether the format
266 % supports the saving of more than one frame to the same file or blob,
267 % whether the format supports native in-memory I/O, and a brief
268 % description of the format.
270 % The format of the RegisterPIXImage method is:
272 % unsigned long RegisterPIXImage(void)
275 ModuleExport unsigned long RegisterPIXImage(void)
280 entry=SetMagickInfo("PIX");
281 entry->decoder=(DecodeImageHandler *) ReadPIXImage;
282 entry->description=ConstantString("Alias/Wavefront RLE image format");
283 entry->module=ConstantString("PIX");
284 (void) RegisterMagickInfo(entry);
285 return(MagickImageCoderSignature);
289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 % U n r e g i s t e r P I X I m a g e %
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 % UnregisterPIXImage() removes format registrations made by the
300 % PIX module from the list of supported formats.
302 % The format of the UnregisterPIXImage method is:
304 % UnregisterPIXImage(void)
307 ModuleExport void UnregisterPIXImage(void)
309 (void) UnregisterMagickInfo("PIX");