2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Alias/Wavefront 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/property.h"
44 #include "magick/blob.h"
45 #include "magick/blob-private.h"
46 #include "magick/cache.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 R L A I m a g e %
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % ReadRLAImage() reads a run-length encoded Wavefront RLA image file
73 % and returns it. It allocates the memory necessary for the new Image
74 % structure and returns a pointer to the new image.
76 % Note: This module was contributed by Lester Vecsey (master@internexus.net).
78 % The format of the ReadRLAImage method is:
80 % Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
82 % A description of each parameter follows:
84 % o image_info: the image info.
86 % o exception: return any errors or warnings in this structure.
89 static Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
91 typedef struct _WindowFrame
100 typedef struct _RLAInfo
110 number_matte_channels,
111 number_auxiliary_channels,
196 assert(image_info != (const ImageInfo *) NULL);
197 assert(image_info->signature == MagickSignature);
198 if (image_info->debug != MagickFalse)
199 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
200 image_info->filename);
201 assert(exception != (ExceptionInfo *) NULL);
202 assert(exception->signature == MagickSignature);
203 image=AcquireImage(image_info);
204 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
205 if (status == MagickFalse)
207 image=DestroyImageList(image);
208 return((Image *) NULL);
210 rla_info.window.left=(short) ReadBlobMSBShort(image);
211 rla_info.window.right=(short) ReadBlobMSBShort(image);
212 rla_info.window.bottom=(short) ReadBlobMSBShort(image);
213 rla_info.window.top=(short) ReadBlobMSBShort(image);
214 rla_info.active_window.left=(short) ReadBlobMSBShort(image);
215 rla_info.active_window.right=(short) ReadBlobMSBShort(image);
216 rla_info.active_window.bottom=(short) ReadBlobMSBShort(image);
217 rla_info.active_window.top=(short) ReadBlobMSBShort(image);
218 rla_info.frame=(short) ReadBlobMSBShort(image);
219 rla_info.storage_type=(short) ReadBlobMSBShort(image);
220 rla_info.number_channels=(short) ReadBlobMSBShort(image);
221 rla_info.number_matte_channels=(short) ReadBlobMSBShort(image);
222 if (rla_info.number_channels == 0)
223 rla_info.number_channels=3;
224 rla_info.number_channels+=rla_info.number_matte_channels;
225 rla_info.number_auxiliary_channels=(short) ReadBlobMSBShort(image);
226 rla_info.revision=(short) ReadBlobMSBShort(image);
227 count=ReadBlob(image,16,(unsigned char *) rla_info.gamma);
228 count=ReadBlob(image,24,(unsigned char *) rla_info.red_primary);
229 count=ReadBlob(image,24,(unsigned char *) rla_info.green_primary);
230 count=ReadBlob(image,24,(unsigned char *) rla_info.blue_primary);
231 count=ReadBlob(image,24,(unsigned char *) rla_info.white_point);
232 rla_info.job_number=(int) ReadBlobMSBLong(image);
233 count=ReadBlob(image,128,(unsigned char *) rla_info.name);
234 count=ReadBlob(image,128,(unsigned char *) rla_info.description);
235 count=ReadBlob(image,64,(unsigned char *) rla_info.program);
236 count=ReadBlob(image,32,(unsigned char *) rla_info.machine);
237 count=ReadBlob(image,32,(unsigned char *) rla_info.user);
238 count=ReadBlob(image,20,(unsigned char *) rla_info.date);
239 count=ReadBlob(image,24,(unsigned char *) rla_info.aspect);
240 count=ReadBlob(image,8,(unsigned char *) rla_info.aspect_ratio);
241 count=ReadBlob(image,32,(unsigned char *) rla_info.chan);
242 rla_info.field=(short) ReadBlobMSBShort(image);
243 count=ReadBlob(image,12,(unsigned char *) rla_info.time);
244 count=ReadBlob(image,32,(unsigned char *) rla_info.filter);
245 rla_info.bits_per_channel=(short) ReadBlobMSBShort(image);
246 rla_info.matte_type=(short) ReadBlobMSBShort(image);
247 rla_info.matte_bits=(short) ReadBlobMSBShort(image);
248 rla_info.auxiliary_type=(short) ReadBlobMSBShort(image);
249 rla_info.auxiliary_bits=(short) ReadBlobMSBShort(image);
250 count=ReadBlob(image,32,(unsigned char *) rla_info.auxiliary);
251 count=ReadBlob(image,36,(unsigned char *) rla_info.space);
252 if ((size_t) count != 36)
253 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
254 rla_info.next=(int) ReadBlobMSBLong(image);
256 Initialize image structure.
258 image->matte=rla_info.number_matte_channels != 0 ? MagickTrue : MagickFalse;
259 image->columns=1UL*rla_info.active_window.right-rla_info.active_window.left+1;
260 image->rows=1UL*rla_info.active_window.top-rla_info.active_window.bottom+1;
261 if (image_info->ping != MagickFalse)
263 (void) CloseBlob(image);
264 return(GetFirstImageInList(image));
266 scanlines=(ssize_t *) AcquireQuantumMemory(image->rows,sizeof(*scanlines));
267 if (scanlines == (ssize_t *) NULL)
268 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
269 if (*rla_info.description != '\0')
270 (void) SetImageProperty(image,"comment",rla_info.description);
272 Read offsets to each scanline data.
274 for (i=0; i < (ssize_t) image->rows; i++)
275 scanlines[i]=(int) ReadBlobMSBLong(image);
280 for (y=0; y < (ssize_t) image->rows; y++)
282 offset=SeekBlob(image,scanlines[image->rows-y-1],SEEK_SET);
284 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
285 for (channel=0; channel < (int) rla_info.number_channels; channel++)
287 length=(int) ReadBlobMSBShort(image);
290 byte=(unsigned char) ReadBlobByte(image);
299 while (runlength < 0)
301 q=GetAuthenticPixels(image,(ssize_t) (x % image->columns),
302 (ssize_t) (y % image->rows),1,1,exception);
303 if (q == (PixelPacket *) NULL)
305 byte=(unsigned char) ReadBlobByte(image);
311 q->red=ScaleCharToQuantum(byte);
316 q->green=ScaleCharToQuantum(byte);
321 q->blue=ScaleCharToQuantum(byte);
327 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(byte));
331 if (SyncAuthenticPixels(image,exception) == MagickFalse)
338 byte=(unsigned char) ReadBlobByte(image);
343 q=GetAuthenticPixels(image,(ssize_t) (x % image->columns),
344 (ssize_t) (y % image->rows),1,1,exception);
345 if (q == (PixelPacket *) NULL)
351 q->red=ScaleCharToQuantum(byte);
356 q->green=ScaleCharToQuantum(byte);
361 q->blue=ScaleCharToQuantum(byte);
367 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(byte));
371 if (SyncAuthenticPixels(image,exception) == MagickFalse)
376 while (runlength > 0);
379 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
381 if (status == MagickFalse)
384 if (EOFBlob(image) != MagickFalse)
385 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
387 (void) CloseBlob(image);
388 return(GetFirstImageInList(image));
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 % R e g i s t e r R L A I m a g e %
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % RegisterRLAImage() adds attributes for the RLA image format to
403 % the list of supported formats. The attributes include the image format
404 % tag, a method to read and/or write the format, whether the format
405 % supports the saving of more than one frame to the same file or blob,
406 % whether the format supports native in-memory I/O, and a brief
407 % description of the format.
409 % The format of the RegisterRLAImage method is:
411 % size_t RegisterRLAImage(void)
414 ModuleExport size_t RegisterRLAImage(void)
419 entry=SetMagickInfo("RLA");
420 entry->decoder=(DecodeImageHandler *) ReadRLAImage;
421 entry->adjoin=MagickFalse;
422 entry->description=ConstantString("Alias/Wavefront image");
423 entry->module=ConstantString("RLA");
424 (void) RegisterMagickInfo(entry);
425 return(MagickImageCoderSignature);
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 % U n r e g i s t e r R L A I m a g e %
437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439 % UnregisterRLAImage() removes format registrations made by the
440 % RLA module from the list of supported formats.
442 % The format of the UnregisterRLAImage method is:
444 % UnregisterRLAImage(void)
447 ModuleExport void UnregisterRLAImage(void)
449 (void) UnregisterMagickInfo("RLA");