blob: 303ed18d3595bfe9b14ceb30a3e0d5787b98a164 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% SSSSS U U N N %
7% SS U U NN N %
8% SSS U U N N N %
9% SS U U N NN %
10% SSSSS UUU N N %
11% %
12% %
13% Read/Write Sun Rasterfile Image Format %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
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. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/attribute.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/color.h"
48#include "MagickCore/color-private.h"
49#include "MagickCore/colormap.h"
cristyced5eb72015-01-25 21:25:47 +000050#include "MagickCore/colormap-private.h"
cristy4c08aed2011-07-01 19:47:50 +000051#include "MagickCore/colorspace.h"
cristy510d06a2011-07-06 23:43:54 +000052#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000053#include "MagickCore/exception.h"
54#include "MagickCore/exception-private.h"
55#include "MagickCore/image.h"
56#include "MagickCore/image-private.h"
57#include "MagickCore/list.h"
58#include "MagickCore/magick.h"
59#include "MagickCore/memory_.h"
60#include "MagickCore/monitor.h"
61#include "MagickCore/monitor-private.h"
62#include "MagickCore/pixel-accessor.h"
63#include "MagickCore/quantum-private.h"
64#include "MagickCore/static.h"
65#include "MagickCore/string_.h"
66#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000067
68/*
69 Forward declarations.
70*/
71static MagickBooleanType
cristy3a37efd2011-08-28 20:31:03 +000072 WriteSUNImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000073
74/*
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76% %
77% %
78% %
79% I s S U N %
80% %
81% %
82% %
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84%
85% IsSUN() returns MagickTrue if the image format type, identified by the
86% magick string, is SUN.
87%
88% The format of the IsSUN method is:
89%
90% MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
91%
92% A description of each parameter follows:
93%
94% o magick: compare image format pattern against these bytes.
95%
96% o length: Specifies the length of the magick string.
97%
98*/
99static MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
100{
101 if (length < 4)
102 return(MagickFalse);
103 if (memcmp(magick,"\131\246\152\225",4) == 0)
104 return(MagickTrue);
105 return(MagickFalse);
106}
107
108/*
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110% %
111% %
112% %
113% D e c o d e I m a g e %
114% %
115% %
116% %
117%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118%
119% DecodeImage unpacks the packed image pixels into runlength-encoded pixel
120% packets.
121%
122% The format of the DecodeImage method is:
123%
124% MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
125% const size_t length,unsigned char *pixels)
126%
127% A description of each parameter follows:
128%
129% o compressed_pixels: The address of a byte (8 bits) array of compressed
130% pixel data.
131%
132% o length: An integer value that is the total number of bytes of the
133% source image (as just read by ReadBlob)
134%
135% o pixels: The address of a byte (8 bits) array of pixel data created by
136% the uncompression process. The number of bytes in this array
137% must be at least equal to the number columns times the number of rows
138% of the source pixels.
139%
140*/
141static MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
142 const size_t length,unsigned char *pixels,size_t maxpixels)
143{
144 register const unsigned char
cristyc6da28e2011-04-28 01:41:35 +0000145 *l,
146 *p;
cristy3ed852e2009-09-05 21:47:34 +0000147
148 register unsigned char
149 *q;
150
151 ssize_t
152 count;
153
154 unsigned char
155 byte;
156
157 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
158 assert(compressed_pixels != (unsigned char *) NULL);
159 assert(pixels != (unsigned char *) NULL);
160 p=compressed_pixels;
161 q=pixels;
162 l=q+maxpixels;
163 while (((size_t) (p-compressed_pixels) < length) && (q < l))
164 {
165 byte=(*p++);
166 if (byte != 128U)
167 *q++=byte;
168 else
169 {
170 /*
171 Runlength-encoded packet: <count><byte>
172 */
173 count=(ssize_t) (*p++);
174 if (count > 0)
175 byte=(*p++);
176 while ((count >= 0) && (q < l))
177 {
178 *q++=byte;
179 count--;
180 }
181 }
182 }
183 return(MagickTrue);
184}
185
186/*
187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188% %
189% %
190% %
191% R e a d S U N I m a g e %
192% %
193% %
194% %
195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196%
197% ReadSUNImage() reads a SUN image file and returns it. It allocates
198% the memory necessary for the new Image structure and returns a pointer to
199% the new image.
200%
201% The format of the ReadSUNImage method is:
202%
203% Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
204%
205% A description of each parameter follows:
206%
207% o image_info: the image info.
208%
209% o exception: return any errors or warnings in this structure.
210%
211*/
212static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
213{
214#define RMT_EQUAL_RGB 1
215#define RMT_NONE 0
216#define RMT_RAW 2
217#define RT_STANDARD 1
218#define RT_ENCODED 2
219#define RT_FORMAT_RGB 3
220
221 typedef struct _SUNInfo
222 {
223 unsigned int
224 magic,
225 width,
226 height,
227 depth,
228 length,
229 type,
230 maptype,
231 maplength;
232 } SUNInfo;
233
234 Image
235 *image;
236
237 int
238 bit;
239
cristy3ed852e2009-09-05 21:47:34 +0000240 MagickBooleanType
241 status;
242
243 MagickSizeType
244 number_pixels;
245
cristy4c08aed2011-07-01 19:47:50 +0000246 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000247 *q;
248
cristybb503372010-05-27 20:51:26 +0000249 register ssize_t
cristye13c3042011-03-03 01:30:05 +0000250 i,
251 x;
cristy3ed852e2009-09-05 21:47:34 +0000252
253 register unsigned char
254 *p;
255
256 size_t
cristy01daf942014-12-01 23:14:00 +0000257 bytes_per_line,
cristy754c2152014-12-07 18:17:41 +0000258 extent,
cristy8ea44b42015-01-13 13:31:27 +0000259 height;
cristy3ed852e2009-09-05 21:47:34 +0000260
261 ssize_t
cristyc6da28e2011-04-28 01:41:35 +0000262 count,
263 y;
cristy3ed852e2009-09-05 21:47:34 +0000264
265 SUNInfo
266 sun_info;
267
268 unsigned char
269 *sun_data,
270 *sun_pixels;
271
cristy3ed852e2009-09-05 21:47:34 +0000272 /*
273 Open image file.
274 */
275 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000276 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000277 if (image_info->debug != MagickFalse)
278 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
279 image_info->filename);
280 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000281 assert(exception->signature == MagickCoreSignature);
cristy9950d572011-10-01 18:22:35 +0000282 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000283 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
284 if (status == MagickFalse)
285 {
286 image=DestroyImageList(image);
287 return((Image *) NULL);
288 }
289 /*
290 Read SUN raster header.
291 */
292 (void) ResetMagickMemory(&sun_info,0,sizeof(sun_info));
293 sun_info.magic=ReadBlobMSBLong(image);
294 do
295 {
296 /*
297 Verify SUN identifier.
298 */
299 if (sun_info.magic != 0x59a66a95)
300 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
301 sun_info.width=ReadBlobMSBLong(image);
302 sun_info.height=ReadBlobMSBLong(image);
303 sun_info.depth=ReadBlobMSBLong(image);
304 sun_info.length=ReadBlobMSBLong(image);
305 sun_info.type=ReadBlobMSBLong(image);
306 sun_info.maptype=ReadBlobMSBLong(image);
307 sun_info.maplength=ReadBlobMSBLong(image);
cristy754c2152014-12-07 18:17:41 +0000308 extent=sun_info.height*sun_info.width;
cristy62a3eb72014-12-07 12:52:02 +0000309 if ((sun_info.height != 0) && (sun_info.width != extent/sun_info.height))
310 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristy22a6f212014-11-30 15:59:52 +0000311 if ((sun_info.type != RT_STANDARD) && (sun_info.type != RT_ENCODED) &&
312 (sun_info.type != RT_FORMAT_RGB))
cristy76d045a2014-12-02 02:12:04 +0000313 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristy22a6f212014-11-30 15:59:52 +0000314 if ((sun_info.maptype == RMT_NONE) && (sun_info.maplength != 0))
cristy76d045a2014-12-02 02:12:04 +0000315 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristy3ed852e2009-09-05 21:47:34 +0000316 if ((sun_info.depth == 0) || (sun_info.depth > 32))
317 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristy22a6f212014-11-30 15:59:52 +0000318 if ((sun_info.maptype != RMT_NONE) && (sun_info.maptype != RMT_EQUAL_RGB) &&
319 (sun_info.maptype != RMT_RAW))
320 ThrowReaderException(CoderError,"ColormapTypeNotSupported");
321 image->columns=sun_info.width;
322 image->rows=sun_info.height;
cristyacee8122009-11-19 02:04:10 +0000323 image->depth=sun_info.depth <= 8 ? sun_info.depth :
324 MAGICKCORE_QUANTUM_DEPTH;
cristy3ed852e2009-09-05 21:47:34 +0000325 if (sun_info.depth < 24)
326 {
cristyeaedf062010-05-29 22:36:02 +0000327 size_t
328 one;
329
cristy3ed852e2009-09-05 21:47:34 +0000330 image->colors=sun_info.maplength;
cristyeaedf062010-05-29 22:36:02 +0000331 one=1;
cristy3ed852e2009-09-05 21:47:34 +0000332 if (sun_info.maptype == RMT_NONE)
cristyeaedf062010-05-29 22:36:02 +0000333 image->colors=one << sun_info.depth;
cristy3ed852e2009-09-05 21:47:34 +0000334 if (sun_info.maptype == RMT_EQUAL_RGB)
335 image->colors=sun_info.maplength/3;
cristybd960742015-01-08 15:44:24 +0000336 if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
337 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +0000338 }
339 switch (sun_info.maptype)
340 {
cristy450bd712015-01-09 20:02:31 +0000341 case RMT_NONE:
342 break;
cristy3ed852e2009-09-05 21:47:34 +0000343 case RMT_EQUAL_RGB:
344 {
345 unsigned char
346 *sun_colormap;
347
348 /*
349 Read SUN raster colormap.
350 */
cristy3ed852e2009-09-05 21:47:34 +0000351 sun_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
352 sizeof(*sun_colormap));
353 if (sun_colormap == (unsigned char *) NULL)
354 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
355 count=ReadBlob(image,image->colors,sun_colormap);
cristy22a6f212014-11-30 15:59:52 +0000356 if (count != (ssize_t) image->colors)
357 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
cristybb503372010-05-27 20:51:26 +0000358 for (i=0; i < (ssize_t) image->colors; i++)
cristy22a6f212014-11-30 15:59:52 +0000359 image->colormap[i].red=(MagickRealType) ScaleCharToQuantum(
360 sun_colormap[i]);
cristy3ed852e2009-09-05 21:47:34 +0000361 count=ReadBlob(image,image->colors,sun_colormap);
cristy22a6f212014-11-30 15:59:52 +0000362 if (count != (ssize_t) image->colors)
363 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
cristybb503372010-05-27 20:51:26 +0000364 for (i=0; i < (ssize_t) image->colors; i++)
cristy22a6f212014-11-30 15:59:52 +0000365 image->colormap[i].green=(MagickRealType) ScaleCharToQuantum(
366 sun_colormap[i]);
cristy3ed852e2009-09-05 21:47:34 +0000367 count=ReadBlob(image,image->colors,sun_colormap);
cristy22a6f212014-11-30 15:59:52 +0000368 if (count != (ssize_t) image->colors)
369 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
cristybb503372010-05-27 20:51:26 +0000370 for (i=0; i < (ssize_t) image->colors; i++)
cristy22a6f212014-11-30 15:59:52 +0000371 image->colormap[i].blue=(MagickRealType) ScaleCharToQuantum(
372 sun_colormap[i]);
cristy3ed852e2009-09-05 21:47:34 +0000373 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
374 break;
375 }
376 case RMT_RAW:
377 {
378 unsigned char
379 *sun_colormap;
380
381 /*
382 Read SUN raster colormap.
383 */
384 sun_colormap=(unsigned char *) AcquireQuantumMemory(sun_info.maplength,
385 sizeof(*sun_colormap));
386 if (sun_colormap == (unsigned char *) NULL)
387 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
388 count=ReadBlob(image,sun_info.maplength,sun_colormap);
cristy22a6f212014-11-30 15:59:52 +0000389 if (count != (ssize_t) sun_info.maplength)
390 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
cristy3ed852e2009-09-05 21:47:34 +0000391 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
392 break;
393 }
394 default:
395 ThrowReaderException(CoderError,"ColormapTypeNotSupported");
396 }
cristy22a6f212014-11-30 15:59:52 +0000397 image->alpha_trait=sun_info.depth == 32 ? BlendPixelTrait :
cristyb0a657e2012-08-29 00:45:37 +0000398 UndefinedPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +0000399 image->columns=sun_info.width;
400 image->rows=sun_info.height;
401 if (image_info->ping != MagickFalse)
402 {
403 (void) CloseBlob(image);
404 return(GetFirstImageInList(image));
405 }
cristyacabb842014-12-14 23:36:33 +0000406 status=SetImageExtent(image,image->columns,image->rows,exception);
407 if (status == MagickFalse)
408 return(DestroyImageList(image));
cristy3ed852e2009-09-05 21:47:34 +0000409 if ((sun_info.length*sizeof(*sun_data))/sizeof(*sun_data) !=
410 sun_info.length || !sun_info.length)
cristy6b4aff02015-01-13 12:16:28 +0000411 ThrowReaderException(ResourceLimitError,"ImproperImageHeader");
cristy4662a132015-01-19 19:27:00 +0000412 number_pixels=(MagickSizeType) (image->columns*image->rows);
cristyb8f17d02015-01-10 14:10:16 +0000413 if ((sun_info.type != RT_ENCODED) &&
cristy386277a2015-01-21 20:38:39 +0000414 ((number_pixels*sun_info.depth) > (8UL*sun_info.length)))
cristy3ed852e2009-09-05 21:47:34 +0000415 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristy78f82d92015-01-06 12:13:31 +0000416 bytes_per_line=sun_info.width*sun_info.depth;
417 sun_data=(unsigned char *) AcquireQuantumMemory((size_t) MagickMax(
418 sun_info.length,bytes_per_line*sun_info.width),sizeof(*sun_data));
cristy3ed852e2009-09-05 21:47:34 +0000419 if (sun_data == (unsigned char *) NULL)
420 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
421 count=(ssize_t) ReadBlob(image,sun_info.length,sun_data);
cristy22a6f212014-11-30 15:59:52 +0000422 if (count != (ssize_t) sun_info.length)
cristy3ed852e2009-09-05 21:47:34 +0000423 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
cristy1aa0c6d2015-01-13 02:23:43 +0000424 height=sun_info.height;
425 if ((height == 0) || (sun_info.width == 0) || (sun_info.depth == 0) ||
426 ((bytes_per_line/sun_info.depth) != sun_info.width))
cristy6b4aff02015-01-13 12:16:28 +0000427 ThrowReaderException(ResourceLimitError,"ImproperImageHeader");
cristy1aa0c6d2015-01-13 02:23:43 +0000428 bytes_per_line+=15;
429 bytes_per_line<<=1;
430 if ((bytes_per_line >> 1) != (sun_info.width*sun_info.depth+15))
cristy6b4aff02015-01-13 12:16:28 +0000431 ThrowReaderException(ResourceLimitError,"ImproperImageHeader");
cristy1aa0c6d2015-01-13 02:23:43 +0000432 bytes_per_line>>=4;
433 sun_pixels=(unsigned char *) AcquireQuantumMemory(height,
Cristy21744842016-01-13 18:31:21 -0500434 MagickMax(image->columns,bytes_per_line)*sizeof(*sun_pixels));
cristy1aa0c6d2015-01-13 02:23:43 +0000435 if (sun_pixels == (unsigned char *) NULL)
436 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
Cristy21744842016-01-13 18:31:21 -0500437 ResetMagickMemory(sun_pixels,0,height*MagickMax(image->columns,
438 bytes_per_line)*sizeof(*sun_pixels));
cristy3ed852e2009-09-05 21:47:34 +0000439 if (sun_info.type == RT_ENCODED)
cristy1aa0c6d2015-01-13 02:23:43 +0000440 (void) DecodeImage(sun_data,sun_info.length,sun_pixels,bytes_per_line*
441 height);
cristy6b4aff02015-01-13 12:16:28 +0000442 else
443 {
444 if (sun_info.length > (height*bytes_per_line))
445 ThrowReaderException(ResourceLimitError,"ImproperImageHeader");
446 (void) CopyMagickMemory(sun_pixels,sun_data,sun_info.length);
447 }
cristy1aa0c6d2015-01-13 02:23:43 +0000448 sun_data=(unsigned char *) RelinquishMagickMemory(sun_data);
cristy3ed852e2009-09-05 21:47:34 +0000449 /*
450 Convert SUN raster image to pixel packets.
451 */
452 p=sun_pixels;
453 if (sun_info.depth == 1)
cristybb503372010-05-27 20:51:26 +0000454 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000455 {
456 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000457 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000458 break;
cristybb503372010-05-27 20:51:26 +0000459 for (x=0; x < ((ssize_t) image->columns-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +0000460 {
461 for (bit=7; bit >= 0; bit--)
cristy4c08aed2011-07-01 19:47:50 +0000462 {
cristy22a6f212014-11-30 15:59:52 +0000463 SetPixelIndex(image,(Quantum) ((*p) & (0x01 << bit) ? 0x00 : 0x01),
464 q);
cristyed231572011-07-14 02:18:59 +0000465 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000466 }
cristy3ed852e2009-09-05 21:47:34 +0000467 p++;
468 }
469 if ((image->columns % 8) != 0)
470 {
cristy22a6f212014-11-30 15:59:52 +0000471 for (bit=7; bit >= (int) (8-(image->columns % 8)); bit--)
cristy4c08aed2011-07-01 19:47:50 +0000472 {
cristy22a6f212014-11-30 15:59:52 +0000473 SetPixelIndex(image,(Quantum) ((*p) & (0x01 << bit) ? 0x00 :
474 0x01),q);
cristyed231572011-07-14 02:18:59 +0000475 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000476 }
cristy3ed852e2009-09-05 21:47:34 +0000477 p++;
478 }
479 if ((((image->columns/8)+(image->columns % 8 ? 1 : 0)) % 2) != 0)
480 p++;
481 if (SyncAuthenticPixels(image,exception) == MagickFalse)
482 break;
483 if (image->previous == (Image *) NULL)
484 {
cristycee97112010-05-28 00:44:52 +0000485 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
cristye13c3042011-03-03 01:30:05 +0000486 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000487 if (status == MagickFalse)
488 break;
489 }
490 }
491 else
492 if (image->storage_class == PseudoClass)
493 {
cristybb503372010-05-27 20:51:26 +0000494 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000495 {
496 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000497 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000498 break;
cristybb503372010-05-27 20:51:26 +0000499 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +0000500 {
cristyced5eb72015-01-25 21:25:47 +0000501 SetPixelIndex(image,ConstrainColormapIndex(image,*p,exception),q);
502 p++;
cristyed231572011-07-14 02:18:59 +0000503 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000504 }
cristy3ed852e2009-09-05 21:47:34 +0000505 if ((image->columns % 2) != 0)
506 p++;
507 if (SyncAuthenticPixels(image,exception) == MagickFalse)
508 break;
509 if (image->previous == (Image *) NULL)
510 {
cristycee97112010-05-28 00:44:52 +0000511 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
512 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000513 if (status == MagickFalse)
514 break;
515 }
516 }
517 }
518 else
519 {
cristyacee8122009-11-19 02:04:10 +0000520 size_t
521 bytes_per_pixel;
522
523 bytes_per_pixel=3;
cristy17f11b02014-12-20 19:37:04 +0000524 if (image->alpha_trait != UndefinedPixelTrait)
cristyacee8122009-11-19 02:04:10 +0000525 bytes_per_pixel++;
cristy1f30ce42014-12-04 00:59:05 +0000526 if (bytes_per_line == 0)
527 bytes_per_line=bytes_per_pixel*image->columns;
cristybb503372010-05-27 20:51:26 +0000528 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000529 {
530 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000531 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000532 break;
cristybb503372010-05-27 20:51:26 +0000533 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000534 {
cristy17f11b02014-12-20 19:37:04 +0000535 if (image->alpha_trait != UndefinedPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000536 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristy3ed852e2009-09-05 21:47:34 +0000537 if (sun_info.type == RT_STANDARD)
538 {
cristy4c08aed2011-07-01 19:47:50 +0000539 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
540 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
541 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
cristy3ed852e2009-09-05 21:47:34 +0000542 }
543 else
544 {
cristy4c08aed2011-07-01 19:47:50 +0000545 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
546 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
547 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
cristy3ed852e2009-09-05 21:47:34 +0000548 }
549 if (image->colors != 0)
550 {
cristy22a6f212014-11-30 15:59:52 +0000551 SetPixelRed(image,ClampToQuantum(image->colormap[(ssize_t)
552 GetPixelRed(image,q)].red),q);
553 SetPixelGreen(image,ClampToQuantum(image->colormap[(ssize_t)
554 GetPixelGreen(image,q)].green),q);
555 SetPixelBlue(image,ClampToQuantum(image->colormap[(ssize_t)
556 GetPixelBlue(image,q)].blue),q);
cristy3ed852e2009-09-05 21:47:34 +0000557 }
cristyed231572011-07-14 02:18:59 +0000558 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000559 }
cristyacee8122009-11-19 02:04:10 +0000560 if (((bytes_per_pixel*image->columns) % 2) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000561 p++;
562 if (SyncAuthenticPixels(image,exception) == MagickFalse)
563 break;
564 if (image->previous == (Image *) NULL)
565 {
cristycee97112010-05-28 00:44:52 +0000566 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
567 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000568 if (status == MagickFalse)
569 break;
570 }
571 }
572 }
573 if (image->storage_class == PseudoClass)
cristyea1a8aa2011-10-20 13:24:06 +0000574 (void) SyncImage(image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000575 sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
576 if (EOFBlob(image) != MagickFalse)
577 {
578 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
579 image->filename);
580 break;
581 }
582 /*
583 Proceed to next image.
584 */
585 if (image_info->number_scenes != 0)
586 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
587 break;
588 sun_info.magic=ReadBlobMSBLong(image);
589 if (sun_info.magic == 0x59a66a95)
590 {
591 /*
592 Allocate next image structure.
593 */
cristy9950d572011-10-01 18:22:35 +0000594 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000595 if (GetNextImageInList(image) == (Image *) NULL)
596 {
597 image=DestroyImageList(image);
598 return((Image *) NULL);
599 }
600 image=SyncNextImageInList(image);
601 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
602 GetBlobSize(image));
603 if (status == MagickFalse)
604 break;
605 }
606 } while (sun_info.magic == 0x59a66a95);
607 (void) CloseBlob(image);
608 return(GetFirstImageInList(image));
609}
610
611/*
612%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
613% %
614% %
615% %
616% R e g i s t e r S U N I m a g e %
617% %
618% %
619% %
620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621%
622% RegisterSUNImage() adds attributes for the SUN image format to
623% the list of supported formats. The attributes include the image format
624% tag, a method to read and/or write the format, whether the format
625% supports the saving of more than one frame to the same file or blob,
626% whether the format supports native in-memory I/O, and a brief
627% description of the format.
628%
629% The format of the RegisterSUNImage method is:
630%
cristybb503372010-05-27 20:51:26 +0000631% size_t RegisterSUNImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000632%
633*/
cristybb503372010-05-27 20:51:26 +0000634ModuleExport size_t RegisterSUNImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000635{
636 MagickInfo
637 *entry;
638
dirk06b627a2015-04-06 18:59:17 +0000639 entry=AcquireMagickInfo("SUN","RAS","SUN Rasterfile");
cristy3ed852e2009-09-05 21:47:34 +0000640 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
641 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
642 entry->magick=(IsImageFormatHandler *) IsSUN;
cristy3ed852e2009-09-05 21:47:34 +0000643 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +0000644 entry=AcquireMagickInfo("SUN","SUN","SUN Rasterfile");
cristy3ed852e2009-09-05 21:47:34 +0000645 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
646 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
cristy3ed852e2009-09-05 21:47:34 +0000647 (void) RegisterMagickInfo(entry);
648 return(MagickImageCoderSignature);
649}
650
651/*
652%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653% %
654% %
655% %
656% U n r e g i s t e r S U N I m a g e %
657% %
658% %
659% %
660%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661%
662% UnregisterSUNImage() removes format registrations made by the
663% SUN module from the list of supported formats.
664%
665% The format of the UnregisterSUNImage method is:
666%
667% UnregisterSUNImage(void)
668%
669*/
670ModuleExport void UnregisterSUNImage(void)
671{
672 (void) UnregisterMagickInfo("RAS");
673 (void) UnregisterMagickInfo("SUN");
674}
675
676/*
677%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678% %
679% %
680% %
681% W r i t e S U N I m a g e %
682% %
683% %
684% %
685%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
686%
687% WriteSUNImage() writes an image in the SUN rasterfile format.
688%
689% The format of the WriteSUNImage method is:
690%
cristy3a37efd2011-08-28 20:31:03 +0000691% MagickBooleanType WriteSUNImage(const ImageInfo *image_info,
692% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000693%
694% A description of each parameter follows.
695%
696% o image_info: the image info.
697%
698% o image: The image.
699%
cristy3a37efd2011-08-28 20:31:03 +0000700% o exception: return any errors or warnings in this structure.
701%
cristy3ed852e2009-09-05 21:47:34 +0000702*/
cristy3a37efd2011-08-28 20:31:03 +0000703static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image,
704 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000705{
706#define RMT_EQUAL_RGB 1
707#define RMT_NONE 0
708#define RMT_RAW 2
709#define RT_STANDARD 1
710#define RT_FORMAT_RGB 3
711
712 typedef struct _SUNInfo
713 {
714 unsigned int
715 magic,
716 width,
717 height,
718 depth,
719 length,
720 type,
721 maptype,
722 maplength;
723 } SUNInfo;
724
cristy3ed852e2009-09-05 21:47:34 +0000725 MagickBooleanType
726 status;
727
728 MagickOffsetType
729 scene;
730
731 MagickSizeType
732 number_pixels;
733
cristy4c08aed2011-07-01 19:47:50 +0000734 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000735 *p;
736
cristybb503372010-05-27 20:51:26 +0000737 register ssize_t
cristye13c3042011-03-03 01:30:05 +0000738 i,
cristy3ed852e2009-09-05 21:47:34 +0000739 x;
740
cristye13c3042011-03-03 01:30:05 +0000741 ssize_t
742 y;
cristy3ed852e2009-09-05 21:47:34 +0000743
744 SUNInfo
745 sun_info;
746
747 /*
748 Open output image file.
749 */
750 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000751 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000752 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000753 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000754 if (image->debug != MagickFalse)
755 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000756 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000757 assert(exception->signature == MagickCoreSignature);
cristy3a37efd2011-08-28 20:31:03 +0000758 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000759 if (status == MagickFalse)
760 return(status);
761 scene=0;
762 do
763 {
764 /*
765 Initialize SUN raster file header.
766 */
cristyaf8d3912014-02-21 14:50:33 +0000767 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000768 sun_info.magic=0x59a66a95;
769 if ((image->columns != (unsigned int) image->columns) ||
770 (image->rows != (unsigned int) image->rows))
771 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
772 sun_info.width=(unsigned int) image->columns;
773 sun_info.height=(unsigned int) image->rows;
cristy22a6f212014-11-30 15:59:52 +0000774 sun_info.type=(unsigned int)
cristy3ed852e2009-09-05 21:47:34 +0000775 (image->storage_class == DirectClass ? RT_FORMAT_RGB : RT_STANDARD);
776 sun_info.maptype=RMT_NONE;
777 sun_info.maplength=0;
778 number_pixels=(MagickSizeType) image->columns*image->rows;
779 if ((4*number_pixels) != (size_t) (4*number_pixels))
780 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
781 if (image->storage_class == DirectClass)
782 {
783 /*
784 Full color SUN raster.
785 */
cristy17f11b02014-12-20 19:37:04 +0000786 sun_info.depth=(unsigned int) image->alpha_trait != UndefinedPixelTrait ?
cristydc2d3272013-02-12 14:00:44 +0000787 32U : 24U;
cristy17f11b02014-12-20 19:37:04 +0000788 sun_info.length=(unsigned int) ((image->alpha_trait != UndefinedPixelTrait ?
cristydc2d3272013-02-12 14:00:44 +0000789 4 : 3)*number_pixels);
cristyeaedf062010-05-29 22:36:02 +0000790 sun_info.length+=sun_info.length & 0x01 ? (unsigned int) image->rows :
791 0;
cristy3ed852e2009-09-05 21:47:34 +0000792 }
793 else
dirkf1d85482015-04-06 00:36:00 +0000794 if (SetImageMonochrome(image,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000795 {
796 /*
797 Monochrome SUN raster.
798 */
799 sun_info.depth=1;
800 sun_info.length=(unsigned int) (((image->columns+7) >> 3)*
801 image->rows);
cristyf9cca6a2010-06-04 23:49:28 +0000802 sun_info.length+=(unsigned int) (((image->columns/8)+(image->columns %
803 8 ? 1 : 0)) % 2 ? image->rows : 0);
cristy3ed852e2009-09-05 21:47:34 +0000804 }
805 else
806 {
807 /*
808 Colormapped SUN raster.
809 */
810 sun_info.depth=8;
811 sun_info.length=(unsigned int) number_pixels;
cristyf9cca6a2010-06-04 23:49:28 +0000812 sun_info.length+=(unsigned int) (image->columns & 0x01 ? image->rows :
813 0);
cristy3ed852e2009-09-05 21:47:34 +0000814 sun_info.maptype=RMT_EQUAL_RGB;
815 sun_info.maplength=(unsigned int) (3*image->colors);
816 }
817 /*
818 Write SUN header.
819 */
820 (void) WriteBlobMSBLong(image,sun_info.magic);
821 (void) WriteBlobMSBLong(image,sun_info.width);
822 (void) WriteBlobMSBLong(image,sun_info.height);
823 (void) WriteBlobMSBLong(image,sun_info.depth);
824 (void) WriteBlobMSBLong(image,sun_info.length);
825 (void) WriteBlobMSBLong(image,sun_info.type);
826 (void) WriteBlobMSBLong(image,sun_info.maptype);
827 (void) WriteBlobMSBLong(image,sun_info.maplength);
828 /*
829 Convert MIFF to SUN raster pixels.
830 */
831 x=0;
832 y=0;
833 if (image->storage_class == DirectClass)
834 {
835 register unsigned char
836 *q;
837
838 size_t
cristyacee8122009-11-19 02:04:10 +0000839 bytes_per_pixel,
cristy3ed852e2009-09-05 21:47:34 +0000840 length;
841
842 unsigned char
843 *pixels;
844
845 /*
846 Allocate memory for pixels.
847 */
cristyacee8122009-11-19 02:04:10 +0000848 bytes_per_pixel=3;
cristy17f11b02014-12-20 19:37:04 +0000849 if (image->alpha_trait != UndefinedPixelTrait)
cristyacee8122009-11-19 02:04:10 +0000850 bytes_per_pixel++;
cristy3ed852e2009-09-05 21:47:34 +0000851 length=image->columns;
852 pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels));
853 if (pixels == (unsigned char *) NULL)
854 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
855 /*
856 Convert DirectClass packet to SUN RGB pixel.
857 */
cristybb503372010-05-27 20:51:26 +0000858 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000859 {
cristy3a37efd2011-08-28 20:31:03 +0000860 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000861 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000862 break;
863 q=pixels;
cristybb503372010-05-27 20:51:26 +0000864 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000865 {
cristy17f11b02014-12-20 19:37:04 +0000866 if (image->alpha_trait != UndefinedPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000867 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
868 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
869 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
870 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000871 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000872 }
cristyacee8122009-11-19 02:04:10 +0000873 if (((bytes_per_pixel*image->columns) & 0x01) != 0)
874 *q++='\0'; /* pad scanline */
cristy3ed852e2009-09-05 21:47:34 +0000875 (void) WriteBlob(image,(size_t) (q-pixels),pixels);
876 if (image->previous == (Image *) NULL)
877 {
cristycee97112010-05-28 00:44:52 +0000878 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
879 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000880 if (status == MagickFalse)
881 break;
882 }
883 }
884 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
885 }
886 else
dirkf1d85482015-04-06 00:36:00 +0000887 if (SetImageMonochrome(image,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000888 {
889 register unsigned char
890 bit,
891 byte;
892
893 /*
894 Convert PseudoClass image to a SUN monochrome image.
895 */
cristy018f07f2011-09-04 21:15:19 +0000896 (void) SetImageType(image,BilevelType,exception);
cristybb503372010-05-27 20:51:26 +0000897 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000898 {
cristy3a37efd2011-08-28 20:31:03 +0000899 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000900 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000901 break;
cristy3ed852e2009-09-05 21:47:34 +0000902 bit=0;
903 byte=0;
cristybb503372010-05-27 20:51:26 +0000904 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000905 {
906 byte<<=1;
cristyd0323222013-04-07 16:13:21 +0000907 if (GetPixelLuma(image,p) < (QuantumRange/2.0))
cristy3ed852e2009-09-05 21:47:34 +0000908 byte|=0x01;
909 bit++;
910 if (bit == 8)
911 {
912 (void) WriteBlobByte(image,byte);
913 bit=0;
914 byte=0;
915 }
cristyed231572011-07-14 02:18:59 +0000916 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000917 }
918 if (bit != 0)
919 (void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
920 if ((((image->columns/8)+
921 (image->columns % 8 ? 1 : 0)) % 2) != 0)
922 (void) WriteBlobByte(image,0); /* pad scanline */
923 if (image->previous == (Image *) NULL)
924 {
cristycee97112010-05-28 00:44:52 +0000925 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
926 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000927 if (status == MagickFalse)
928 break;
929 }
930 }
931 }
932 else
933 {
934 /*
935 Dump colormap to file.
936 */
cristybb503372010-05-27 20:51:26 +0000937 for (i=0; i < (ssize_t) image->colors; i++)
cristyc6da28e2011-04-28 01:41:35 +0000938 (void) WriteBlobByte(image,ScaleQuantumToChar(
cristy22a6f212014-11-30 15:59:52 +0000939 ClampToQuantum(image->colormap[i].red)));
cristybb503372010-05-27 20:51:26 +0000940 for (i=0; i < (ssize_t) image->colors; i++)
cristyc6da28e2011-04-28 01:41:35 +0000941 (void) WriteBlobByte(image,ScaleQuantumToChar(
cristy22a6f212014-11-30 15:59:52 +0000942 ClampToQuantum(image->colormap[i].green)));
cristybb503372010-05-27 20:51:26 +0000943 for (i=0; i < (ssize_t) image->colors; i++)
cristyc6da28e2011-04-28 01:41:35 +0000944 (void) WriteBlobByte(image,ScaleQuantumToChar(
cristy22a6f212014-11-30 15:59:52 +0000945 ClampToQuantum(image->colormap[i].blue)));
cristy3ed852e2009-09-05 21:47:34 +0000946 /*
947 Convert PseudoClass packet to SUN colormapped pixel.
948 */
cristybb503372010-05-27 20:51:26 +0000949 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000950 {
cristy3a37efd2011-08-28 20:31:03 +0000951 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000952 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000953 break;
cristybb503372010-05-27 20:51:26 +0000954 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000955 {
cristyc6da28e2011-04-28 01:41:35 +0000956 (void) WriteBlobByte(image,(unsigned char)
cristy4c08aed2011-07-01 19:47:50 +0000957 GetPixelIndex(image,p));
cristyed231572011-07-14 02:18:59 +0000958 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000959 }
cristyacee8122009-11-19 02:04:10 +0000960 if (image->columns & 0x01)
cristy3ed852e2009-09-05 21:47:34 +0000961 (void) WriteBlobByte(image,0); /* pad scanline */
962 if (image->previous == (Image *) NULL)
963 {
cristycee97112010-05-28 00:44:52 +0000964 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristyc6da28e2011-04-28 01:41:35 +0000965 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000966 if (status == MagickFalse)
967 break;
968 }
969 }
970 }
971 if (GetNextImageInList(image) == (Image *) NULL)
972 break;
973 image=SyncNextImageInList(image);
974 status=SetImageProgress(image,SaveImagesTag,scene++,
975 GetImageListLength(image));
976 if (status == MagickFalse)
977 break;
978 } while (image_info->adjoin != MagickFalse);
979 (void) CloseBlob(image);
980 return(MagickTrue);
981}