2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Alias/Wavefront Image Format %
20 % Copyright 1999-2014 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/property.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.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 R L A I m a g e %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % ReadRLAImage() reads a run-length encoded Wavefront RLA image file
74 % and returns it. It allocates the memory necessary for the new Image
75 % structure and returns a pointer to the new image.
77 % Note: This module was contributed by Lester Vecsey (master@internexus.net).
79 % The format of the ReadRLAImage method is:
81 % Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
83 % A description of each parameter follows:
85 % o image_info: the image info.
87 % o exception: return any errors or warnings in this structure.
90 static Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
92 typedef struct _WindowFrame
101 typedef struct _RLAInfo
111 number_matte_channels,
112 number_auxiliary_channels,
193 assert(image_info != (const ImageInfo *) NULL);
194 assert(image_info->signature == MagickSignature);
195 if (image_info->debug != MagickFalse)
196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
197 image_info->filename);
198 assert(exception != (ExceptionInfo *) NULL);
199 assert(exception->signature == MagickSignature);
200 image=AcquireImage(image_info,exception);
201 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
202 if (status == MagickFalse)
204 image=DestroyImageList(image);
205 return((Image *) NULL);
207 rla_info.window.left=(short) ReadBlobMSBShort(image);
208 rla_info.window.right=(short) ReadBlobMSBShort(image);
209 rla_info.window.bottom=(short) ReadBlobMSBShort(image);
210 rla_info.window.top=(short) ReadBlobMSBShort(image);
211 rla_info.active_window.left=(short) ReadBlobMSBShort(image);
212 rla_info.active_window.right=(short) ReadBlobMSBShort(image);
213 rla_info.active_window.bottom=(short) ReadBlobMSBShort(image);
214 rla_info.active_window.top=(short) ReadBlobMSBShort(image);
215 rla_info.frame=(short) ReadBlobMSBShort(image);
216 rla_info.storage_type=(short) ReadBlobMSBShort(image);
217 rla_info.number_channels=(short) ReadBlobMSBShort(image);
218 rla_info.number_matte_channels=(short) ReadBlobMSBShort(image);
219 if (rla_info.number_channels == 0)
220 rla_info.number_channels=3;
221 rla_info.number_channels+=rla_info.number_matte_channels;
222 rla_info.number_auxiliary_channels=(short) ReadBlobMSBShort(image);
223 rla_info.revision=(short) ReadBlobMSBShort(image);
224 count=ReadBlob(image,16,(unsigned char *) rla_info.gamma);
225 count=ReadBlob(image,24,(unsigned char *) rla_info.red_primary);
226 count=ReadBlob(image,24,(unsigned char *) rla_info.green_primary);
227 count=ReadBlob(image,24,(unsigned char *) rla_info.blue_primary);
228 count=ReadBlob(image,24,(unsigned char *) rla_info.white_point);
229 rla_info.job_number=(int) ReadBlobMSBLong(image);
230 count=ReadBlob(image,128,(unsigned char *) rla_info.name);
231 (void) ResetMagickMemory(value,0,sizeof(rla_info.description));
232 count=ReadBlob(image,128,(unsigned char *) rla_info.description);
233 count=ReadBlob(image,64,(unsigned char *) rla_info.program);
234 count=ReadBlob(image,32,(unsigned char *) rla_info.machine);
235 count=ReadBlob(image,32,(unsigned char *) rla_info.user);
236 count=ReadBlob(image,20,(unsigned char *) rla_info.date);
237 count=ReadBlob(image,24,(unsigned char *) rla_info.aspect);
238 count=ReadBlob(image,8,(unsigned char *) rla_info.aspect_ratio);
239 count=ReadBlob(image,32,(unsigned char *) rla_info.chan);
240 rla_info.field=(short) ReadBlobMSBShort(image);
241 count=ReadBlob(image,12,(unsigned char *) rla_info.time);
242 count=ReadBlob(image,32,(unsigned char *) rla_info.filter);
243 rla_info.bits_per_channel=(short) ReadBlobMSBShort(image);
244 rla_info.matte_type=(short) ReadBlobMSBShort(image);
245 rla_info.matte_bits=(short) ReadBlobMSBShort(image);
246 rla_info.auxiliary_type=(short) ReadBlobMSBShort(image);
247 rla_info.auxiliary_bits=(short) ReadBlobMSBShort(image);
248 count=ReadBlob(image,32,(unsigned char *) rla_info.auxiliary);
249 count=ReadBlob(image,36,(unsigned char *) rla_info.space);
250 if ((size_t) count != 36)
251 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
252 rla_info.next=(int) ReadBlobMSBLong(image);
254 Initialize image structure.
256 image->alpha_trait=rla_info.number_matte_channels != 0 ? BlendPixelTrait :
258 image->columns=1UL*rla_info.active_window.right-rla_info.active_window.left+1;
259 image->rows=1UL*rla_info.active_window.top-rla_info.active_window.bottom+1;
260 if (image_info->ping != MagickFalse)
262 (void) CloseBlob(image);
263 return(GetFirstImageInList(image));
265 scanlines=(ssize_t *) AcquireQuantumMemory(image->rows,sizeof(*scanlines));
266 if (scanlines == (ssize_t *) NULL)
267 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
268 if (*rla_info.description != '\0')
269 (void) SetImageProperty(image,"comment",rla_info.description,exception);
271 Read offsets to each scanline data.
273 for (i=0; i < (ssize_t) image->rows; i++)
274 scanlines[i]=(int) ReadBlobMSBLong(image);
279 for (y=0; y < (ssize_t) image->rows; y++)
281 offset=SeekBlob(image,scanlines[image->rows-y-1],SEEK_SET);
283 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
284 for (channel=0; channel < (int) rla_info.number_channels; channel++)
286 length=(int) ReadBlobMSBShort(image);
289 byte=(unsigned char) ReadBlobByte(image);
298 while (runlength < 0)
300 q=GetAuthenticPixels(image,(ssize_t) (x % image->columns),
301 (ssize_t) (y % image->rows),1,1,exception);
302 if (q == (Quantum *) NULL)
304 byte=(unsigned char) ReadBlobByte(image);
310 SetPixelRed(image,ScaleCharToQuantum(byte),q);
315 SetPixelGreen(image,ScaleCharToQuantum(byte),q);
320 SetPixelBlue(image,ScaleCharToQuantum(byte),q);
326 SetPixelAlpha(image,ScaleCharToQuantum(byte),q);
330 if (SyncAuthenticPixels(image,exception) == MagickFalse)
337 byte=(unsigned char) ReadBlobByte(image);
342 q=GetAuthenticPixels(image,(ssize_t) (x % image->columns),
343 (ssize_t) (y % image->rows),1,1,exception);
344 if (q == (Quantum *) NULL)
350 SetPixelRed(image,ScaleCharToQuantum(byte),q);
355 SetPixelGreen(image,ScaleCharToQuantum(byte),q);
360 SetPixelBlue(image,ScaleCharToQuantum(byte),q);
366 SetPixelAlpha(image,ScaleCharToQuantum(byte),q);
370 if (SyncAuthenticPixels(image,exception) == MagickFalse)
375 while (runlength > 0);
378 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
380 if (status == MagickFalse)
383 if (EOFBlob(image) != MagickFalse)
384 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
386 (void) CloseBlob(image);
387 return(GetFirstImageInList(image));
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 % R e g i s t e r R L A I m a g e %
399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 % RegisterRLAImage() adds attributes for the RLA image format to
402 % the list of supported formats. The attributes include the image format
403 % tag, a method to read and/or write the format, whether the format
404 % supports the saving of more than one frame to the same file or blob,
405 % whether the format supports native in-memory I/O, and a brief
406 % description of the format.
408 % The format of the RegisterRLAImage method is:
410 % size_t RegisterRLAImage(void)
413 ModuleExport size_t RegisterRLAImage(void)
418 entry=SetMagickInfo("RLA");
419 entry->decoder=(DecodeImageHandler *) ReadRLAImage;
420 entry->adjoin=MagickFalse;
421 entry->seekable_stream=MagickTrue;
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");