blob: f93861b03ee0c771ccf3e6953d1ca3a963576cdb [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% RRRR GGGG BBBB %
7% R R G B B %
8% RRRR G GG BBBB %
9% R R G G B B %
10% R R GGG BBBB %
11% %
12% %
13% Read/Write Raw RGB 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% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 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/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/cache.h"
cristy6a2180c2013-05-27 10:28:36 +000046#include "MagickCore/channel.h"
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickCore/colorspace.h"
cristy510d06a2011-07-06 23:43:54 +000048#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000049#include "MagickCore/constitute.h"
50#include "MagickCore/exception.h"
51#include "MagickCore/exception-private.h"
52#include "MagickCore/image.h"
53#include "MagickCore/image-private.h"
54#include "MagickCore/list.h"
55#include "MagickCore/magick.h"
56#include "MagickCore/memory_.h"
57#include "MagickCore/monitor.h"
58#include "MagickCore/monitor-private.h"
59#include "MagickCore/pixel-accessor.h"
60#include "MagickCore/quantum-private.h"
61#include "MagickCore/static.h"
62#include "MagickCore/statistic.h"
63#include "MagickCore/string_.h"
64#include "MagickCore/module.h"
65#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68 Forward declarations.
69*/
70static MagickBooleanType
cristy3a37efd2011-08-28 20:31:03 +000071 WriteRGBImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000072
73/*
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75% %
76% %
77% %
78% R e a d R G B I m a g e %
79% %
80% %
81% %
82%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83%
cristy90dbac72010-08-22 15:08:40 +000084% ReadRGBImage() reads an image of raw RGB, RGBA, or RGBO samples and returns
85% it. It allocates the memory necessary for the new Image structure and
86% returns a pointer to the new image.
cristy3ed852e2009-09-05 21:47:34 +000087%
88% The format of the ReadRGBImage method is:
89%
cristy90dbac72010-08-22 15:08:40 +000090% Image *ReadRGBImage(const ImageInfo *image_info,
91% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000092%
93% A description of each parameter follows:
94%
95% o image_info: the image info.
96%
97% o exception: return any errors or warnings in this structure.
98%
99*/
cristyddacdd12012-05-07 23:08:14 +0000100static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000101{
cristybd797f12015-01-24 20:42:32 +0000102 const void
103 *pixels;
104
cristy3ed852e2009-09-05 21:47:34 +0000105 Image
106 *canvas_image,
107 *image;
108
cristy3ed852e2009-09-05 21:47:34 +0000109 MagickBooleanType
110 status;
111
112 MagickOffsetType
113 scene;
114
115 QuantumInfo
116 *quantum_info;
117
118 QuantumType
119 quantum_type;
120
cristybb503372010-05-27 20:51:26 +0000121 register ssize_t
cristy90dbac72010-08-22 15:08:40 +0000122 i;
cristy3ed852e2009-09-05 21:47:34 +0000123
cristyc6da28e2011-04-28 01:41:35 +0000124 size_t
125 length;
126
cristy3ed852e2009-09-05 21:47:34 +0000127 ssize_t
cristya38675f2010-08-21 18:35:13 +0000128 count,
129 y;
cristy3ed852e2009-09-05 21:47:34 +0000130
cristy3ed852e2009-09-05 21:47:34 +0000131 /*
132 Open image file.
133 */
134 assert(image_info != (const ImageInfo *) NULL);
135 assert(image_info->signature == MagickSignature);
136 if (image_info->debug != MagickFalse)
137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
138 image_info->filename);
139 assert(exception != (ExceptionInfo *) NULL);
140 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000141 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000142 if ((image->columns == 0) || (image->rows == 0))
143 ThrowReaderException(OptionError,"MustSpecifyImageSize");
144 if (image_info->interlace != PartitionInterlace)
145 {
146 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
147 if (status == MagickFalse)
148 {
149 image=DestroyImageList(image);
150 return((Image *) NULL);
151 }
cristyd4297022010-09-16 22:59:09 +0000152 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
153 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
154 image->filename);
cristy3ed852e2009-09-05 21:47:34 +0000155 }
156 /*
157 Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
158 */
159 canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
160 exception);
cristy387430f2012-02-07 13:09:46 +0000161 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
162 exception);
cristy5f766ef2014-12-14 21:12:47 +0000163 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
cristy3ed852e2009-09-05 21:47:34 +0000164 if (quantum_info == (QuantumInfo *) NULL)
165 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +0000166 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +0000167 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristya38675f2010-08-21 18:35:13 +0000168 {
cristy90dbac72010-08-22 15:08:40 +0000169 quantum_type=RGBAQuantum;
cristy8a46d822012-08-28 23:32:39 +0000170 image->alpha_trait=BlendPixelTrait;
171 canvas_image->alpha_trait=BlendPixelTrait;
cristya38675f2010-08-21 18:35:13 +0000172 }
cristy90dbac72010-08-22 15:08:40 +0000173 if (LocaleCompare(image_info->magick,"RGBO") == 0)
174 {
175 quantum_type=RGBOQuantum;
cristy8a46d822012-08-28 23:32:39 +0000176 canvas_image->alpha_trait=BlendPixelTrait;
cristy90dbac72010-08-22 15:08:40 +0000177 }
cristyf4b08ec2015-01-26 20:37:16 +0000178 pixels=(const void *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000179 if (image_info->number_scenes != 0)
180 while (image->scene < image_info->scene)
181 {
182 /*
183 Skip to next image.
184 */
185 image->scene++;
186 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristybb503372010-05-27 20:51:26 +0000187 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000188 {
cristybd797f12015-01-24 20:42:32 +0000189 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
190 &count);
cristy3ed852e2009-09-05 21:47:34 +0000191 if (count != (ssize_t) length)
192 break;
193 }
194 }
cristy3ed852e2009-09-05 21:47:34 +0000195 count=0;
196 length=0;
197 scene=0;
198 do
199 {
200 /*
201 Read pixels to virtual canvas image then push to image.
202 */
203 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
204 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
205 break;
cristyacabb842014-12-14 23:36:33 +0000206 status=SetImageExtent(image,image->columns,image->rows,exception);
207 if (status == MagickFalse)
208 return(DestroyImageList(image));
cristy3ed852e2009-09-05 21:47:34 +0000209 switch (image_info->interlace)
210 {
211 case NoInterlace:
212 default:
213 {
214 /*
215 No interlacing: RGBRGBRGBRGBRGBRGB...
216 */
217 if (scene == 0)
218 {
219 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristybd797f12015-01-24 20:42:32 +0000220 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
221 &count);
cristy3ed852e2009-09-05 21:47:34 +0000222 }
cristybb503372010-05-27 20:51:26 +0000223 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000224 {
cristy4c08aed2011-07-01 19:47:50 +0000225 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000226 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000227
cristy4c08aed2011-07-01 19:47:50 +0000228 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000229 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000230
cristy90dbac72010-08-22 15:08:40 +0000231 register ssize_t
232 x;
233
cristy21da32d2009-09-12 14:56:09 +0000234 if (count != (ssize_t) length)
235 {
236 ThrowFileException(exception,CorruptImageError,
237 "UnexpectedEndOfFile",image->filename);
238 break;
239 }
cristy3ed852e2009-09-05 21:47:34 +0000240 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
241 exception);
cristyacd2ed22011-08-30 01:44:23 +0000242 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000243 break;
244 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
245 quantum_info,quantum_type,pixels,exception);
246 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
247 break;
cristy90dbac72010-08-22 15:08:40 +0000248 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000249 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000250 {
251 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
252 canvas_image->columns,1,exception);
253 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
254 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000255 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000256 break;
cristybb503372010-05-27 20:51:26 +0000257 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000258 {
cristy4c08aed2011-07-01 19:47:50 +0000259 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
260 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
261 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
262 SetPixelAlpha(image,OpaqueAlpha,q);
cristy17f11b02014-12-20 19:37:04 +0000263 if (image->alpha_trait != UndefinedPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000264 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000265 p+=GetPixelChannels(canvas_image);
266 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000267 }
268 if (SyncAuthenticPixels(image,exception) == MagickFalse)
269 break;
270 }
271 if (image->previous == (Image *) NULL)
272 {
cristycee97112010-05-28 00:44:52 +0000273 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
274 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000275 if (status == MagickFalse)
276 break;
277 }
cristybd797f12015-01-24 20:42:32 +0000278 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
279 &count);
cristy3ed852e2009-09-05 21:47:34 +0000280 }
281 break;
282 }
283 case LineInterlace:
284 {
cristy90dbac72010-08-22 15:08:40 +0000285 static QuantumType
286 quantum_types[4] =
287 {
288 RedQuantum,
289 GreenQuantum,
290 BlueQuantum,
291 AlphaQuantum
292 };
293
cristy3ed852e2009-09-05 21:47:34 +0000294 /*
295 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
296 */
cristy90dbac72010-08-22 15:08:40 +0000297 if (LocaleCompare(image_info->magick,"RGBO") == 0)
298 quantum_types[3]=OpacityQuantum;
cristy3ed852e2009-09-05 21:47:34 +0000299 if (scene == 0)
300 {
cristy90dbac72010-08-22 15:08:40 +0000301 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristybd797f12015-01-24 20:42:32 +0000302 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
303 &count);
cristy3ed852e2009-09-05 21:47:34 +0000304 }
cristybb503372010-05-27 20:51:26 +0000305 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000306 {
cristy4c08aed2011-07-01 19:47:50 +0000307 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000308 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000309
cristy4c08aed2011-07-01 19:47:50 +0000310 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000311 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000312
cristy90dbac72010-08-22 15:08:40 +0000313 register ssize_t
314 x;
315
cristy21da32d2009-09-12 14:56:09 +0000316 if (count != (ssize_t) length)
317 {
318 ThrowFileException(exception,CorruptImageError,
319 "UnexpectedEndOfFile",image->filename);
320 break;
321 }
cristy17f11b02014-12-20 19:37:04 +0000322 for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++)
cristy3ed852e2009-09-05 21:47:34 +0000323 {
cristy90dbac72010-08-22 15:08:40 +0000324 quantum_type=quantum_types[i];
cristy3ed852e2009-09-05 21:47:34 +0000325 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
326 exception);
cristyacd2ed22011-08-30 01:44:23 +0000327 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000328 break;
329 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
cristy90dbac72010-08-22 15:08:40 +0000330 quantum_info,quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000331 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
332 break;
cristy90dbac72010-08-22 15:08:40 +0000333 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000334 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000335 {
336 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
337 0,canvas_image->columns,1,exception);
338 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
339 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000340 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000341 break;
cristy90dbac72010-08-22 15:08:40 +0000342 for (x=0; x < (ssize_t) image->columns; x++)
343 {
344 switch (quantum_type)
cristy3ed852e2009-09-05 21:47:34 +0000345 {
cristy90dbac72010-08-22 15:08:40 +0000346 case RedQuantum:
347 {
cristy4c08aed2011-07-01 19:47:50 +0000348 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000349 break;
350 }
351 case GreenQuantum:
352 {
cristy4c08aed2011-07-01 19:47:50 +0000353 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000354 break;
355 }
356 case BlueQuantum:
357 {
cristy4c08aed2011-07-01 19:47:50 +0000358 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000359 break;
360 }
361 case OpacityQuantum:
362 {
cristy4c08aed2011-07-01 19:47:50 +0000363 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000364 break;
365 }
366 case AlphaQuantum:
367 {
cristy4c08aed2011-07-01 19:47:50 +0000368 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000369 break;
370 }
371 default:
372 break;
cristy3ed852e2009-09-05 21:47:34 +0000373 }
cristyed231572011-07-14 02:18:59 +0000374 p+=GetPixelChannels(canvas_image);
375 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000376 }
cristy3ed852e2009-09-05 21:47:34 +0000377 if (SyncAuthenticPixels(image,exception) == MagickFalse)
378 break;
379 }
cristybd797f12015-01-24 20:42:32 +0000380 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
381 &count);
cristy3ed852e2009-09-05 21:47:34 +0000382 }
383 if (image->previous == (Image *) NULL)
384 {
cristycee97112010-05-28 00:44:52 +0000385 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
386 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000387 if (status == MagickFalse)
388 break;
389 }
390 }
391 break;
392 }
393 case PlaneInterlace:
394 {
395 /*
396 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
397 */
398 if (scene == 0)
399 {
cristy90dbac72010-08-22 15:08:40 +0000400 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristybd797f12015-01-24 20:42:32 +0000401 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
402 &count);
cristy3ed852e2009-09-05 21:47:34 +0000403 }
cristy90dbac72010-08-22 15:08:40 +0000404 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000405 {
cristy4c08aed2011-07-01 19:47:50 +0000406 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000407 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000408
cristy4c08aed2011-07-01 19:47:50 +0000409 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000410 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000411
cristy90dbac72010-08-22 15:08:40 +0000412 register ssize_t
413 x;
cristy3ed852e2009-09-05 21:47:34 +0000414
cristy90dbac72010-08-22 15:08:40 +0000415 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000416 {
cristy90dbac72010-08-22 15:08:40 +0000417 ThrowFileException(exception,CorruptImageError,
418 "UnexpectedEndOfFile",image->filename);
419 break;
420 }
421 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
422 exception);
cristyacd2ed22011-08-30 01:44:23 +0000423 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000424 break;
425 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
426 quantum_info,RedQuantum,pixels,exception);
427 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
428 break;
429 if (((y-image->extract_info.y) >= 0) &&
430 ((y-image->extract_info.y) < (ssize_t) image->rows))
431 {
432 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
433 canvas_image->columns,1,exception);
434 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
435 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000436 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000437 break;
438 for (x=0; x < (ssize_t) image->columns; x++)
439 {
cristy4c08aed2011-07-01 19:47:50 +0000440 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000441 p+=GetPixelChannels(canvas_image);
442 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000443 }
444 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000445 break;
446 }
cristybd797f12015-01-24 20:42:32 +0000447 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
448 &count);
cristy3ed852e2009-09-05 21:47:34 +0000449 }
450 if (image->previous == (Image *) NULL)
451 {
cristy90dbac72010-08-22 15:08:40 +0000452 status=SetImageProgress(image,LoadImageTag,1,6);
453 if (status == MagickFalse)
454 break;
455 }
456 for (y=0; y < (ssize_t) image->extract_info.height; y++)
457 {
cristy4c08aed2011-07-01 19:47:50 +0000458 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000459 *restrict p;
460
cristy4c08aed2011-07-01 19:47:50 +0000461 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000462 *restrict q;
463
464 register ssize_t
465 x;
466
467 if (count != (ssize_t) length)
468 {
469 ThrowFileException(exception,CorruptImageError,
470 "UnexpectedEndOfFile",image->filename);
471 break;
472 }
473 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
474 exception);
cristyacd2ed22011-08-30 01:44:23 +0000475 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000476 break;
477 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
478 quantum_info,GreenQuantum,pixels,exception);
479 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
480 break;
481 if (((y-image->extract_info.y) >= 0) &&
482 ((y-image->extract_info.y) < (ssize_t) image->rows))
483 {
484 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
485 canvas_image->columns,1,exception);
486 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
487 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000488 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000489 break;
490 for (x=0; x < (ssize_t) image->columns; x++)
491 {
cristyf27ee032011-09-29 17:51:41 +0000492 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000493 p+=GetPixelChannels(canvas_image);
494 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000495 }
496 if (SyncAuthenticPixels(image,exception) == MagickFalse)
497 break;
498 }
cristybd797f12015-01-24 20:42:32 +0000499 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
500 &count);
cristy90dbac72010-08-22 15:08:40 +0000501 }
502 if (image->previous == (Image *) NULL)
503 {
504 status=SetImageProgress(image,LoadImageTag,2,6);
505 if (status == MagickFalse)
506 break;
507 }
508 for (y=0; y < (ssize_t) image->extract_info.height; y++)
509 {
cristy4c08aed2011-07-01 19:47:50 +0000510 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000511 *restrict p;
512
cristy4c08aed2011-07-01 19:47:50 +0000513 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000514 *restrict q;
515
516 register ssize_t
517 x;
518
519 if (count != (ssize_t) length)
520 {
521 ThrowFileException(exception,CorruptImageError,
522 "UnexpectedEndOfFile",image->filename);
523 break;
524 }
525 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
526 exception);
cristyacd2ed22011-08-30 01:44:23 +0000527 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000528 break;
529 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
530 quantum_info,BlueQuantum,pixels,exception);
531 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
532 break;
533 if (((y-image->extract_info.y) >= 0) &&
534 ((y-image->extract_info.y) < (ssize_t) image->rows))
535 {
536 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
537 canvas_image->columns,1,exception);
538 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
539 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000540 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000541 break;
542 for (x=0; x < (ssize_t) image->columns; x++)
543 {
cristyf27ee032011-09-29 17:51:41 +0000544 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000545 p+=GetPixelChannels(canvas_image);
546 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000547 }
548 if (SyncAuthenticPixels(image,exception) == MagickFalse)
549 break;
550 }
cristybd797f12015-01-24 20:42:32 +0000551 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
552 &count);
cristy90dbac72010-08-22 15:08:40 +0000553 }
554 if (image->previous == (Image *) NULL)
555 {
556 status=SetImageProgress(image,LoadImageTag,3,6);
557 if (status == MagickFalse)
558 break;
559 }
560 if (image->previous == (Image *) NULL)
561 {
562 status=SetImageProgress(image,LoadImageTag,4,6);
563 if (status == MagickFalse)
564 break;
565 }
cristy17f11b02014-12-20 19:37:04 +0000566 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000567 {
568 for (y=0; y < (ssize_t) image->extract_info.height; y++)
569 {
cristy4c08aed2011-07-01 19:47:50 +0000570 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000571 *restrict p;
572
cristy4c08aed2011-07-01 19:47:50 +0000573 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000574 *restrict q;
575
576 register ssize_t
577 x;
578
579 if (count != (ssize_t) length)
580 {
581 ThrowFileException(exception,CorruptImageError,
582 "UnexpectedEndOfFile",image->filename);
583 break;
584 }
585 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
586 exception);
cristyacd2ed22011-08-30 01:44:23 +0000587 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000588 break;
589 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
590 quantum_info,AlphaQuantum,pixels,exception);
591 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
592 break;
593 if (((y-image->extract_info.y) >= 0) &&
594 ((y-image->extract_info.y) < (ssize_t) image->rows))
595 {
596 p=GetVirtualPixels(canvas_image,
597 canvas_image->extract_info.x,0,canvas_image->columns,1,
598 exception);
599 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
600 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000601 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000602 break;
603 for (x=0; x < (ssize_t) image->columns; x++)
604 {
cristyf27ee032011-09-29 17:51:41 +0000605 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000606 p+=GetPixelChannels(canvas_image);
607 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000608 }
609 if (SyncAuthenticPixels(image,exception) == MagickFalse)
610 break;
611 }
cristybd797f12015-01-24 20:42:32 +0000612 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
613 &count);
cristy90dbac72010-08-22 15:08:40 +0000614 }
615 if (image->previous == (Image *) NULL)
616 {
617 status=SetImageProgress(image,LoadImageTag,5,6);
618 if (status == MagickFalse)
619 break;
620 }
621 }
622 if (image->previous == (Image *) NULL)
623 {
624 status=SetImageProgress(image,LoadImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +0000625 if (status == MagickFalse)
626 break;
627 }
628 break;
629 }
630 case PartitionInterlace:
631 {
632 /*
633 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
634 */
cristy90dbac72010-08-22 15:08:40 +0000635 AppendImageFormat("R",image->filename);
636 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
637 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000638 {
cristy90dbac72010-08-22 15:08:40 +0000639 canvas_image=DestroyImageList(canvas_image);
640 image=DestroyImageList(image);
641 return((Image *) NULL);
642 }
cristyd4297022010-09-16 22:59:09 +0000643 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
644 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
645 image->filename);
cristy90dbac72010-08-22 15:08:40 +0000646 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
647 for (i=0; i < (ssize_t) scene; i++)
648 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000649 {
650 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
651 &count);
652 if (count != (ssize_t) length)
cristy21da32d2009-09-12 14:56:09 +0000653 {
654 ThrowFileException(exception,CorruptImageError,
655 "UnexpectedEndOfFile",image->filename);
656 break;
657 }
cristybd797f12015-01-24 20:42:32 +0000658 }
659 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
660 &count);
cristy90dbac72010-08-22 15:08:40 +0000661 for (y=0; y < (ssize_t) image->extract_info.height; y++)
662 {
cristy4c08aed2011-07-01 19:47:50 +0000663 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000664 *restrict p;
665
cristy4c08aed2011-07-01 19:47:50 +0000666 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000667 *restrict q;
668
669 register ssize_t
670 x;
671
672 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000673 {
cristy90dbac72010-08-22 15:08:40 +0000674 ThrowFileException(exception,CorruptImageError,
675 "UnexpectedEndOfFile",image->filename);
676 break;
677 }
678 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
679 exception);
cristyacd2ed22011-08-30 01:44:23 +0000680 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000681 break;
682 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
683 quantum_info,RedQuantum,pixels,exception);
684 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
685 break;
686 if (((y-image->extract_info.y) >= 0) &&
687 ((y-image->extract_info.y) < (ssize_t) image->rows))
688 {
689 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
690 canvas_image->columns,1,exception);
691 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
692 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000693 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000694 break;
695 for (x=0; x < (ssize_t) image->columns; x++)
696 {
cristy4c08aed2011-07-01 19:47:50 +0000697 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000698 p+=GetPixelChannels(canvas_image);
699 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000700 }
701 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000702 break;
703 }
cristybd797f12015-01-24 20:42:32 +0000704 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
705 &count);
cristy3ed852e2009-09-05 21:47:34 +0000706 }
707 if (image->previous == (Image *) NULL)
708 {
cristy90dbac72010-08-22 15:08:40 +0000709 status=SetImageProgress(image,LoadImageTag,1,5);
710 if (status == MagickFalse)
711 break;
712 }
713 (void) CloseBlob(image);
714 AppendImageFormat("G",image->filename);
715 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
716 if (status == MagickFalse)
717 {
718 canvas_image=DestroyImageList(canvas_image);
719 image=DestroyImageList(image);
720 return((Image *) NULL);
721 }
722 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
723 for (i=0; i < (ssize_t) scene; i++)
724 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000725 {
726 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
727 &count);
728 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000729 {
730 ThrowFileException(exception,CorruptImageError,
731 "UnexpectedEndOfFile",image->filename);
732 break;
733 }
cristybd797f12015-01-24 20:42:32 +0000734 }
735 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
736 &count);
cristy90dbac72010-08-22 15:08:40 +0000737 for (y=0; y < (ssize_t) image->extract_info.height; y++)
738 {
cristy4c08aed2011-07-01 19:47:50 +0000739 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000740 *restrict p;
741
cristy4c08aed2011-07-01 19:47:50 +0000742 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000743 *restrict q;
744
745 register ssize_t
746 x;
747
748 if (count != (ssize_t) length)
749 {
750 ThrowFileException(exception,CorruptImageError,
751 "UnexpectedEndOfFile",image->filename);
752 break;
753 }
754 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
755 exception);
cristyacd2ed22011-08-30 01:44:23 +0000756 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000757 break;
758 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
759 quantum_info,GreenQuantum,pixels,exception);
760 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
761 break;
762 if (((y-image->extract_info.y) >= 0) &&
763 ((y-image->extract_info.y) < (ssize_t) image->rows))
764 {
765 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
766 canvas_image->columns,1,exception);
767 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
768 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000769 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000770 break;
771 for (x=0; x < (ssize_t) image->columns; x++)
772 {
cristyf27ee032011-09-29 17:51:41 +0000773 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000774 p+=GetPixelChannels(canvas_image);
775 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000776 }
777 if (SyncAuthenticPixels(image,exception) == MagickFalse)
778 break;
779 }
cristybd797f12015-01-24 20:42:32 +0000780 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
781 &count);
cristy90dbac72010-08-22 15:08:40 +0000782 }
783 if (image->previous == (Image *) NULL)
784 {
785 status=SetImageProgress(image,LoadImageTag,2,5);
786 if (status == MagickFalse)
787 break;
788 }
789 (void) CloseBlob(image);
790 AppendImageFormat("B",image->filename);
791 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
792 if (status == MagickFalse)
793 {
794 canvas_image=DestroyImageList(canvas_image);
795 image=DestroyImageList(image);
796 return((Image *) NULL);
797 }
798 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
799 for (i=0; i < (ssize_t) scene; i++)
800 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000801 {
802 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
803 &count);
804 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000805 {
806 ThrowFileException(exception,CorruptImageError,
807 "UnexpectedEndOfFile",image->filename);
808 break;
809 }
cristybd797f12015-01-24 20:42:32 +0000810 }
811 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
812 &count);
cristy90dbac72010-08-22 15:08:40 +0000813 for (y=0; y < (ssize_t) image->extract_info.height; y++)
814 {
cristy4c08aed2011-07-01 19:47:50 +0000815 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000816 *restrict p;
817
cristy4c08aed2011-07-01 19:47:50 +0000818 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000819 *restrict q;
820
821 register ssize_t
822 x;
823
824 if (count != (ssize_t) length)
825 {
826 ThrowFileException(exception,CorruptImageError,
827 "UnexpectedEndOfFile",image->filename);
828 break;
829 }
830 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
831 exception);
cristyacd2ed22011-08-30 01:44:23 +0000832 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000833 break;
834 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
835 quantum_info,BlueQuantum,pixels,exception);
836 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
837 break;
838 if (((y-image->extract_info.y) >= 0) &&
839 ((y-image->extract_info.y) < (ssize_t) image->rows))
840 {
841 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
842 canvas_image->columns,1,exception);
843 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
844 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000845 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000846 break;
847 for (x=0; x < (ssize_t) image->columns; x++)
848 {
cristyf27ee032011-09-29 17:51:41 +0000849 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000850 p+=GetPixelChannels(canvas_image);
851 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000852 }
853 if (SyncAuthenticPixels(image,exception) == MagickFalse)
854 break;
855 }
cristybd797f12015-01-24 20:42:32 +0000856 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
857 &count);
cristy90dbac72010-08-22 15:08:40 +0000858 }
859 if (image->previous == (Image *) NULL)
860 {
861 status=SetImageProgress(image,LoadImageTag,3,5);
862 if (status == MagickFalse)
863 break;
864 }
cristy17f11b02014-12-20 19:37:04 +0000865 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000866 {
867 (void) CloseBlob(image);
868 AppendImageFormat("A",image->filename);
869 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
870 if (status == MagickFalse)
871 {
872 canvas_image=DestroyImageList(canvas_image);
873 image=DestroyImageList(image);
874 return((Image *) NULL);
875 }
876 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
877 for (i=0; i < (ssize_t) scene; i++)
878 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000879 {
880 pixels=ReadBlobStream(image,length,
881 GetQuantumPixels(quantum_info),&count);
882 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000883 {
884 ThrowFileException(exception,CorruptImageError,
885 "UnexpectedEndOfFile",image->filename);
886 break;
887 }
cristybd797f12015-01-24 20:42:32 +0000888 }
889 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
890 &count);
cristy90dbac72010-08-22 15:08:40 +0000891 for (y=0; y < (ssize_t) image->extract_info.height; y++)
892 {
cristy4c08aed2011-07-01 19:47:50 +0000893 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000894 *restrict p;
895
cristy4c08aed2011-07-01 19:47:50 +0000896 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000897 *restrict q;
898
899 register ssize_t
900 x;
901
902 if (count != (ssize_t) length)
903 {
904 ThrowFileException(exception,CorruptImageError,
905 "UnexpectedEndOfFile",image->filename);
906 break;
907 }
908 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
909 exception);
cristyacd2ed22011-08-30 01:44:23 +0000910 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000911 break;
912 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
913 quantum_info,BlueQuantum,pixels,exception);
914 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
915 break;
916 if (((y-image->extract_info.y) >= 0) &&
917 ((y-image->extract_info.y) < (ssize_t) image->rows))
918 {
919 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
920 0,canvas_image->columns,1,exception);
921 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
922 image->columns,1,exception);
cristyc6aebff2012-05-07 23:24:35 +0000923 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000924 break;
925 for (x=0; x < (ssize_t) image->columns; x++)
926 {
cristyf27ee032011-09-29 17:51:41 +0000927 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000928 p+=GetPixelChannels(canvas_image);
929 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000930 }
931 if (SyncAuthenticPixels(image,exception) == MagickFalse)
932 break;
933 }
cristybd797f12015-01-24 20:42:32 +0000934 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
935 &count);
cristy90dbac72010-08-22 15:08:40 +0000936 }
937 if (image->previous == (Image *) NULL)
938 {
939 status=SetImageProgress(image,LoadImageTag,4,5);
940 if (status == MagickFalse)
941 break;
942 }
943 }
944 (void) CloseBlob(image);
945 if (image->previous == (Image *) NULL)
946 {
cristy3ed852e2009-09-05 21:47:34 +0000947 status=SetImageProgress(image,LoadImageTag,5,5);
948 if (status == MagickFalse)
949 break;
950 }
951 break;
952 }
953 }
954 SetQuantumImageType(image,quantum_type);
cristy3ed852e2009-09-05 21:47:34 +0000955 /*
956 Proceed to next image.
957 */
958 if (image_info->number_scenes != 0)
959 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
960 break;
961 if (count == (ssize_t) length)
962 {
963 /*
964 Allocate next image structure.
965 */
cristy9950d572011-10-01 18:22:35 +0000966 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000967 if (GetNextImageInList(image) == (Image *) NULL)
968 {
969 image=DestroyImageList(image);
970 return((Image *) NULL);
971 }
972 image=SyncNextImageInList(image);
973 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
974 GetBlobSize(image));
975 if (status == MagickFalse)
976 break;
977 }
978 scene++;
979 } while (count == (ssize_t) length);
cristy3ed852e2009-09-05 21:47:34 +0000980 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000981 canvas_image=DestroyImage(canvas_image);
982 (void) CloseBlob(image);
983 return(GetFirstImageInList(image));
984}
985
986/*
987%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988% %
989% %
990% %
991% R e g i s t e r R G B I m a g e %
992% %
993% %
994% %
995%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
996%
cristy90dbac72010-08-22 15:08:40 +0000997% RegisterRGBImage() adds attributes for the RGB image format to
cristy3ed852e2009-09-05 21:47:34 +0000998% the list of supported formats. The attributes include the image format
999% tag, a method to read and/or write the format, whether the format
1000% supports the saving of more than one frame to the same file or blob,
1001% whether the format supports native in-memory I/O, and a brief
1002% description of the format.
1003%
1004% The format of the RegisterRGBImage method is:
1005%
cristybb503372010-05-27 20:51:26 +00001006% size_t RegisterRGBImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001007%
1008*/
cristybb503372010-05-27 20:51:26 +00001009ModuleExport size_t RegisterRGBImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001010{
1011 MagickInfo
1012 *entry;
1013
1014 entry=SetMagickInfo("RGB");
1015 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1016 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001017 entry->flags|=CoderRawSupportFlag;
1018 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001019 entry->description=ConstantString("Raw red, green, and blue samples");
1020 entry->module=ConstantString("RGB");
1021 (void) RegisterMagickInfo(entry);
cristy3ed852e2009-09-05 21:47:34 +00001022 entry=SetMagickInfo("RGBA");
1023 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1024 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001025 entry->flags|=CoderRawSupportFlag;
1026 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001027 entry->description=ConstantString("Raw red, green, blue, and alpha samples");
1028 entry->module=ConstantString("RGB");
1029 (void) RegisterMagickInfo(entry);
1030 entry=SetMagickInfo("RGBO");
1031 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1032 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001033 entry->flags|=CoderRawSupportFlag;
1034 entry->flags|=CoderEndianSupportFlag;
cristy90dbac72010-08-22 15:08:40 +00001035 entry->description=ConstantString("Raw red, green, blue, and opacity samples");
cristy3ed852e2009-09-05 21:47:34 +00001036 entry->module=ConstantString("RGB");
1037 (void) RegisterMagickInfo(entry);
1038 return(MagickImageCoderSignature);
1039}
1040
1041/*
1042%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043% %
1044% %
1045% %
1046% U n r e g i s t e r R G B I m a g e %
1047% %
1048% %
1049% %
1050%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051%
cristy90dbac72010-08-22 15:08:40 +00001052% UnregisterRGBImage() removes format registrations made by the RGB module
1053% from the list of supported formats.
cristy3ed852e2009-09-05 21:47:34 +00001054%
1055% The format of the UnregisterRGBImage method is:
1056%
1057% UnregisterRGBImage(void)
1058%
1059*/
1060ModuleExport void UnregisterRGBImage(void)
1061{
1062 (void) UnregisterMagickInfo("RGBO");
1063 (void) UnregisterMagickInfo("RGBA");
cristy3ed852e2009-09-05 21:47:34 +00001064 (void) UnregisterMagickInfo("RGB");
1065}
1066
1067/*
1068%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069% %
1070% %
1071% %
1072% W r i t e R G B I m a g e %
1073% %
1074% %
1075% %
1076%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077%
cristy90dbac72010-08-22 15:08:40 +00001078% WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO
1079% rasterfile format.
cristy3ed852e2009-09-05 21:47:34 +00001080%
1081% The format of the WriteRGBImage method is:
1082%
cristy90dbac72010-08-22 15:08:40 +00001083% MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
cristy3a37efd2011-08-28 20:31:03 +00001084% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001085%
1086% A description of each parameter follows.
1087%
1088% o image_info: the image info.
1089%
1090% o image: The image.
1091%
cristy3a37efd2011-08-28 20:31:03 +00001092% o exception: return any errors or warnings in this structure.
1093%
cristy3ed852e2009-09-05 21:47:34 +00001094*/
cristyc6aebff2012-05-07 23:24:35 +00001095static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1096 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001097{
cristy3ed852e2009-09-05 21:47:34 +00001098 MagickBooleanType
1099 status;
1100
1101 MagickOffsetType
1102 scene;
1103
1104 QuantumInfo
1105 *quantum_info;
1106
1107 QuantumType
cristy90dbac72010-08-22 15:08:40 +00001108 quantum_type;
cristy3ed852e2009-09-05 21:47:34 +00001109
cristyc6da28e2011-04-28 01:41:35 +00001110 size_t
1111 length;
1112
cristy3ed852e2009-09-05 21:47:34 +00001113 ssize_t
cristy90dbac72010-08-22 15:08:40 +00001114 count,
1115 y;
cristy3ed852e2009-09-05 21:47:34 +00001116
cristy3ed852e2009-09-05 21:47:34 +00001117 unsigned char
1118 *pixels;
1119
cristy3ed852e2009-09-05 21:47:34 +00001120 /*
1121 Allocate memory for pixels.
1122 */
1123 assert(image_info != (const ImageInfo *) NULL);
1124 assert(image_info->signature == MagickSignature);
1125 assert(image != (Image *) NULL);
1126 assert(image->signature == MagickSignature);
1127 if (image->debug != MagickFalse)
1128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1129 if (image_info->interlace != PartitionInterlace)
1130 {
1131 /*
1132 Open output image file.
1133 */
cristyedf03fa2011-08-30 12:44:39 +00001134 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001135 if (status == MagickFalse)
1136 return(status);
1137 }
1138 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +00001139 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristyc6aebff2012-05-07 23:24:35 +00001140 quantum_type=RGBAQuantum;
cristy90dbac72010-08-22 15:08:40 +00001141 if (LocaleCompare(image_info->magick,"RGBO") == 0)
cristyc6aebff2012-05-07 23:24:35 +00001142 quantum_type=RGBOQuantum;
cristy3ed852e2009-09-05 21:47:34 +00001143 scene=0;
1144 do
1145 {
1146 /*
1147 Convert MIFF to RGB raster pixels.
1148 */
cristyaf8d3912014-02-21 14:50:33 +00001149 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001150 if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
cristy17f11b02014-12-20 19:37:04 +00001151 (image->alpha_trait == UndefinedPixelTrait))
cristy3a37efd2011-08-28 20:31:03 +00001152 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy5f766ef2014-12-14 21:12:47 +00001153 quantum_info=AcquireQuantumInfo(image_info,image);
cristy3ed852e2009-09-05 21:47:34 +00001154 if (quantum_info == (QuantumInfo *) NULL)
1155 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1156 pixels=GetQuantumPixels(quantum_info);
1157 switch (image_info->interlace)
1158 {
1159 case NoInterlace:
1160 default:
1161 {
cristy3ed852e2009-09-05 21:47:34 +00001162 /*
1163 No interlacing: RGBRGBRGBRGBRGBRGB...
1164 */
cristybb503372010-05-27 20:51:26 +00001165 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001166 {
cristy4c08aed2011-07-01 19:47:50 +00001167 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001168 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001169
cristy3a37efd2011-08-28 20:31:03 +00001170 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001171 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001172 break;
cristy4c08aed2011-07-01 19:47:50 +00001173 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001174 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001175 count=WriteBlob(image,length,pixels);
1176 if (count != (ssize_t) length)
1177 break;
1178 if (image->previous == (Image *) NULL)
1179 {
cristycee97112010-05-28 00:44:52 +00001180 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1181 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001182 if (status == MagickFalse)
1183 break;
1184 }
1185 }
cristy3ed852e2009-09-05 21:47:34 +00001186 break;
1187 }
1188 case LineInterlace:
1189 {
1190 /*
1191 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
1192 */
cristybb503372010-05-27 20:51:26 +00001193 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001194 {
cristy4c08aed2011-07-01 19:47:50 +00001195 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001196 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001197
cristy3a37efd2011-08-28 20:31:03 +00001198 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001199 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001200 break;
cristy4c08aed2011-07-01 19:47:50 +00001201 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001202 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001203 count=WriteBlob(image,length,pixels);
1204 if (count != (ssize_t) length)
1205 break;
cristy4c08aed2011-07-01 19:47:50 +00001206 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001207 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001208 count=WriteBlob(image,length,pixels);
1209 if (count != (ssize_t) length)
1210 break;
cristy4c08aed2011-07-01 19:47:50 +00001211 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001212 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001213 count=WriteBlob(image,length,pixels);
1214 if (count != (ssize_t) length)
1215 break;
1216 if (quantum_type == RGBAQuantum)
1217 {
cristy4c08aed2011-07-01 19:47:50 +00001218 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001219 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001220 count=WriteBlob(image,length,pixels);
1221 if (count != (ssize_t) length)
1222 break;
1223 }
1224 if (quantum_type == RGBOQuantum)
1225 {
cristy4c08aed2011-07-01 19:47:50 +00001226 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001227 OpacityQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001228 count=WriteBlob(image,length,pixels);
1229 if (count != (ssize_t) length)
1230 break;
1231 }
cristy3ed852e2009-09-05 21:47:34 +00001232 if (image->previous == (Image *) NULL)
1233 {
cristycee97112010-05-28 00:44:52 +00001234 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1235 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001236 if (status == MagickFalse)
1237 break;
1238 }
1239 }
1240 break;
1241 }
1242 case PlaneInterlace:
1243 {
1244 /*
1245 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
1246 */
cristy90dbac72010-08-22 15:08:40 +00001247 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001248 {
cristy4c08aed2011-07-01 19:47:50 +00001249 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001250 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001251
cristy3a37efd2011-08-28 20:31:03 +00001252 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001253 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001254 break;
cristy4c08aed2011-07-01 19:47:50 +00001255 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001256 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001257 count=WriteBlob(image,length,pixels);
1258 if (count != (ssize_t) length)
1259 break;
cristy3ed852e2009-09-05 21:47:34 +00001260 }
1261 if (image->previous == (Image *) NULL)
1262 {
cristy90dbac72010-08-22 15:08:40 +00001263 status=SetImageProgress(image,SaveImageTag,1,6);
1264 if (status == MagickFalse)
1265 break;
1266 }
1267 for (y=0; y < (ssize_t) image->rows; y++)
1268 {
cristy4c08aed2011-07-01 19:47:50 +00001269 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001270 *restrict p;
1271
cristy3a37efd2011-08-28 20:31:03 +00001272 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001273 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001274 break;
cristy4c08aed2011-07-01 19:47:50 +00001275 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001276 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001277 count=WriteBlob(image,length,pixels);
1278 if (count != (ssize_t) length)
1279 break;
1280 }
1281 if (image->previous == (Image *) NULL)
1282 {
1283 status=SetImageProgress(image,SaveImageTag,2,6);
1284 if (status == MagickFalse)
1285 break;
1286 }
1287 for (y=0; y < (ssize_t) image->rows; y++)
1288 {
cristy4c08aed2011-07-01 19:47:50 +00001289 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001290 *restrict p;
1291
cristy3a37efd2011-08-28 20:31:03 +00001292 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001293 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001294 break;
cristy4c08aed2011-07-01 19:47:50 +00001295 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001296 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001297 count=WriteBlob(image,length,pixels);
1298 if (count != (ssize_t) length)
1299 break;
1300 }
1301 if (image->previous == (Image *) NULL)
1302 {
1303 status=SetImageProgress(image,SaveImageTag,3,6);
1304 if (status == MagickFalse)
1305 break;
1306 }
1307 if (quantum_type == RGBAQuantum)
1308 {
1309 for (y=0; y < (ssize_t) image->rows; y++)
1310 {
cristy4c08aed2011-07-01 19:47:50 +00001311 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001312 *restrict p;
1313
cristy3a37efd2011-08-28 20:31:03 +00001314 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001315 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001316 break;
cristy4c08aed2011-07-01 19:47:50 +00001317 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001318 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001319 count=WriteBlob(image,length,pixels);
1320 if (count != (ssize_t) length)
1321 break;
1322 }
1323 if (image->previous == (Image *) NULL)
1324 {
1325 status=SetImageProgress(image,SaveImageTag,5,6);
1326 if (status == MagickFalse)
1327 break;
1328 }
1329 }
1330 if (image_info->interlace == PartitionInterlace)
1331 (void) CopyMagickString(image->filename,image_info->filename,
1332 MaxTextExtent);
1333 if (image->previous == (Image *) NULL)
1334 {
1335 status=SetImageProgress(image,SaveImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +00001336 if (status == MagickFalse)
1337 break;
1338 }
1339 break;
1340 }
1341 case PartitionInterlace:
1342 {
cristy3ed852e2009-09-05 21:47:34 +00001343 /*
1344 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
1345 */
cristy90dbac72010-08-22 15:08:40 +00001346 AppendImageFormat("R",image->filename);
1347 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001348 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001349 if (status == MagickFalse)
1350 return(status);
1351 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001352 {
cristy4c08aed2011-07-01 19:47:50 +00001353 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001354 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001355
cristy3a37efd2011-08-28 20:31:03 +00001356 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001357 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001358 break;
cristy4c08aed2011-07-01 19:47:50 +00001359 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001360 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001361 count=WriteBlob(image,length,pixels);
1362 if (count != (ssize_t) length)
1363 break;
1364 }
1365 if (image->previous == (Image *) NULL)
1366 {
1367 status=SetImageProgress(image,SaveImageTag,1,6);
1368 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001369 break;
1370 }
cristy90dbac72010-08-22 15:08:40 +00001371 (void) CloseBlob(image);
1372 AppendImageFormat("G",image->filename);
1373 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001374 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001375 if (status == MagickFalse)
1376 return(status);
1377 for (y=0; y < (ssize_t) image->rows; y++)
1378 {
cristy4c08aed2011-07-01 19:47:50 +00001379 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001380 *restrict p;
1381
cristy3a37efd2011-08-28 20:31:03 +00001382 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001383 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001384 break;
cristy4c08aed2011-07-01 19:47:50 +00001385 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001386 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001387 count=WriteBlob(image,length,pixels);
1388 if (count != (ssize_t) length)
1389 break;
1390 }
1391 if (image->previous == (Image *) NULL)
1392 {
1393 status=SetImageProgress(image,SaveImageTag,2,6);
1394 if (status == MagickFalse)
1395 break;
1396 }
1397 (void) CloseBlob(image);
1398 AppendImageFormat("B",image->filename);
1399 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001400 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001401 if (status == MagickFalse)
1402 return(status);
1403 for (y=0; y < (ssize_t) image->rows; y++)
1404 {
cristy4c08aed2011-07-01 19:47:50 +00001405 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001406 *restrict p;
1407
cristy3a37efd2011-08-28 20:31:03 +00001408 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001409 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001410 break;
cristy4c08aed2011-07-01 19:47:50 +00001411 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001412 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001413 count=WriteBlob(image,length,pixels);
1414 if (count != (ssize_t) length)
1415 break;
1416 }
1417 if (image->previous == (Image *) NULL)
1418 {
1419 status=SetImageProgress(image,SaveImageTag,3,6);
1420 if (status == MagickFalse)
1421 break;
1422 }
cristy90dbac72010-08-22 15:08:40 +00001423 if (quantum_type == RGBAQuantum)
1424 {
1425 (void) CloseBlob(image);
1426 AppendImageFormat("A",image->filename);
1427 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001428 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001429 if (status == MagickFalse)
1430 return(status);
1431 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001432 {
cristy4c08aed2011-07-01 19:47:50 +00001433 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001434 *restrict p;
1435
cristy3a37efd2011-08-28 20:31:03 +00001436 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001437 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001438 break;
cristy4c08aed2011-07-01 19:47:50 +00001439 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001440 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001441 count=WriteBlob(image,length,pixels);
1442 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +00001443 break;
1444 }
cristy90dbac72010-08-22 15:08:40 +00001445 if (image->previous == (Image *) NULL)
1446 {
1447 status=SetImageProgress(image,SaveImageTag,5,6);
1448 if (status == MagickFalse)
1449 break;
1450 }
1451 }
1452 (void) CloseBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001453 (void) CopyMagickString(image->filename,image_info->filename,
1454 MaxTextExtent);
1455 if (image->previous == (Image *) NULL)
1456 {
cristy90dbac72010-08-22 15:08:40 +00001457 status=SetImageProgress(image,SaveImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +00001458 if (status == MagickFalse)
1459 break;
1460 }
1461 break;
1462 }
1463 }
1464 quantum_info=DestroyQuantumInfo(quantum_info);
1465 if (GetNextImageInList(image) == (Image *) NULL)
1466 break;
1467 image=SyncNextImageInList(image);
1468 status=SetImageProgress(image,SaveImagesTag,scene++,
1469 GetImageListLength(image));
1470 if (status == MagickFalse)
1471 break;
1472 } while (image_info->adjoin != MagickFalse);
1473 (void) CloseBlob(image);
1474 return(MagickTrue);
1475}