2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Alias/Wavefront RLE Image Format %
20 % Copyright 1999-2017 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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/colormap.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/monitor.h"
55 #include "MagickCore/monitor-private.h"
56 #include "MagickCore/pixel-accessor.h"
57 #include "MagickCore/quantum-private.h"
58 #include "MagickCore/static.h"
59 #include "MagickCore/string_.h"
60 #include "MagickCore/module.h"
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 % R e a d P I X I m a g e %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % ReadPIXImage() reads a Alias/Wavefront RLE image file and returns it.
74 % It allocates the memory necessary for the new Image structure and returns a
75 % pointer to the new image.
77 % The format of the ReadPIXImage method is:
79 % Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
81 % A description of each parameter follows:
83 % o image_info: the image info.
85 % o exception: return any errors or warnings in this structure.
89 static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
121 assert(image_info != (const ImageInfo *) NULL);
122 assert(image_info->signature == MagickCoreSignature);
123 if (image_info->debug != MagickFalse)
124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
125 image_info->filename);
126 assert(exception != (ExceptionInfo *) NULL);
127 assert(exception->signature == MagickCoreSignature);
128 image=AcquireImage(image_info,exception);
129 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
130 if (status == MagickFalse)
132 image=DestroyImageList(image);
133 return((Image *) NULL);
138 width=ReadBlobMSBShort(image);
139 height=ReadBlobMSBShort(image);
140 (void) ReadBlobMSBShort(image); /* x-offset */
141 (void) ReadBlobMSBShort(image); /* y-offset */
142 bits_per_pixel=ReadBlobMSBShort(image);
143 if ((width == 0UL) || (height == 0UL) || ((bits_per_pixel != 8) &&
144 (bits_per_pixel != 24)))
145 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
149 Initialize image structure.
151 image->columns=width;
153 if (bits_per_pixel == 8)
154 if (AcquireImageColormap(image,256,exception) == MagickFalse)
155 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
156 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
157 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
159 status=SetImageExtent(image,image->columns,image->rows,exception);
160 if (status == MagickFalse)
161 return(DestroyImageList(image));
163 Convert PIX raster image to pixel packets.
170 for (y=0; y < (ssize_t) image->rows; y++)
172 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
173 if (q == (Quantum *) NULL)
175 for (x=0; x < (ssize_t) image->columns; x++)
179 length=(size_t) ReadBlobByte(image);
180 if (bits_per_pixel == 8)
181 index=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
184 blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
185 green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
186 red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
189 if (image->storage_class == PseudoClass)
190 SetPixelIndex(image,index,q);
191 SetPixelBlue(image,blue,q);
192 SetPixelGreen(image,green,q);
193 SetPixelRed(image,red,q);
195 q+=GetPixelChannels(image);
197 if (SyncAuthenticPixels(image,exception) == MagickFalse)
199 if (image->previous == (Image *) NULL)
201 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
203 if (status == MagickFalse)
207 if (image->storage_class == PseudoClass)
208 (void) SyncImage(image,exception);
209 if (EOFBlob(image) != MagickFalse)
211 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
216 Proceed to next image.
218 if (image_info->number_scenes != 0)
219 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
221 width=ReadBlobMSBLong(image);
222 height=ReadBlobMSBLong(image);
223 (void) ReadBlobMSBShort(image);
224 (void) ReadBlobMSBShort(image);
225 bits_per_pixel=ReadBlobMSBShort(image);
226 status=(width != 0UL) && (height == 0UL) && ((bits_per_pixel == 8) ||
227 (bits_per_pixel == 24)) ? MagickTrue : MagickFalse;
228 if (status != MagickFalse)
231 Allocate next image structure.
233 AcquireNextImage(image_info,image,exception);
234 if (GetNextImageInList(image) == (Image *) NULL)
236 image=DestroyImageList(image);
237 return((Image *) NULL);
239 image=SyncNextImageInList(image);
240 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
242 if (status == MagickFalse)
245 } while (status != MagickFalse);
246 (void) CloseBlob(image);
247 return(GetFirstImageInList(image));
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 % R e g i s t e r P I X I m a g e %
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 % RegisterPIXImage() adds attributes for the PIX image format to
262 % the list of supported formats. The attributes include the image format
263 % tag, a method to read and/or write the format, whether the format
264 % supports the saving of more than one frame to the same file or blob,
265 % whether the format supports native in-memory I/O, and a brief
266 % description of the format.
268 % The format of the RegisterPIXImage method is:
270 % size_t RegisterPIXImage(void)
273 ModuleExport size_t RegisterPIXImage(void)
278 entry=AcquireMagickInfo("PIX","PIX","Alias/Wavefront RLE image format");
279 entry->decoder=(DecodeImageHandler *) ReadPIXImage;
280 (void) RegisterMagickInfo(entry);
281 return(MagickImageCoderSignature);
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 % U n r e g i s t e r P I X I m a g e %
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % UnregisterPIXImage() removes format registrations made by the
296 % PIX module from the list of supported formats.
298 % The format of the UnregisterPIXImage method is:
300 % UnregisterPIXImage(void)
303 ModuleExport void UnregisterPIXImage(void)
305 (void) UnregisterMagickInfo("PIX");