blob: a81789a6306f36db5c6b0747c186a78d745715e8 [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% %
Cristyf6ff9ea2016-12-05 09:53:35 -050020% Copyright 1999-2017 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% %
Cristyf19d4142017-04-24 11:34:30 -040026% https://www.imagemagick.org/script/license.php %
cristy3ed852e2009-09-05 21:47:34 +000027% %
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{
cristyb3f97ae2015-05-18 12:29:32 +0000102 const unsigned char
cristybd797f12015-01-24 20:42:32 +0000103 *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);
cristye1c94d92015-06-28 12:16:33 +0000135 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000136 if (image_info->debug != MagickFalse)
137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
138 image_info->filename);
139 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000140 assert(exception->signature == MagickCoreSignature);
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);
root7a851d32017-09-28 17:39:04 +0000161 if(canvas_image == (Image *) NULL)
root67c24572017-09-28 16:57:54 +0000162 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy387430f2012-02-07 13:09:46 +0000163 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
164 exception);
cristy5f766ef2014-12-14 21:12:47 +0000165 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
cristy3ed852e2009-09-05 21:47:34 +0000166 if (quantum_info == (QuantumInfo *) NULL)
167 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +0000168 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +0000169 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristya38675f2010-08-21 18:35:13 +0000170 {
cristy90dbac72010-08-22 15:08:40 +0000171 quantum_type=RGBAQuantum;
cristy8a46d822012-08-28 23:32:39 +0000172 image->alpha_trait=BlendPixelTrait;
173 canvas_image->alpha_trait=BlendPixelTrait;
cristya38675f2010-08-21 18:35:13 +0000174 }
cristy90dbac72010-08-22 15:08:40 +0000175 if (LocaleCompare(image_info->magick,"RGBO") == 0)
176 {
177 quantum_type=RGBOQuantum;
dirk7000aae2015-02-24 11:56:06 +0000178 image->alpha_trait=BlendPixelTrait;
cristy8a46d822012-08-28 23:32:39 +0000179 canvas_image->alpha_trait=BlendPixelTrait;
cristy90dbac72010-08-22 15:08:40 +0000180 }
cristyb3f97ae2015-05-18 12:29:32 +0000181 pixels=(const unsigned char *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000182 if (image_info->number_scenes != 0)
183 while (image->scene < image_info->scene)
184 {
185 /*
186 Skip to next image.
187 */
188 image->scene++;
189 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristybb503372010-05-27 20:51:26 +0000190 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000191 {
cristyb3f97ae2015-05-18 12:29:32 +0000192 pixels=(const unsigned char *) ReadBlobStream(image,length,
193 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000194 if (count != (ssize_t) length)
195 break;
196 }
197 }
cristy3ed852e2009-09-05 21:47:34 +0000198 count=0;
199 length=0;
200 scene=0;
201 do
202 {
203 /*
204 Read pixels to virtual canvas image then push to image.
205 */
206 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
207 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
208 break;
cristyacabb842014-12-14 23:36:33 +0000209 status=SetImageExtent(image,image->columns,image->rows,exception);
210 if (status == MagickFalse)
211 return(DestroyImageList(image));
cristy3ed852e2009-09-05 21:47:34 +0000212 switch (image_info->interlace)
213 {
214 case NoInterlace:
215 default:
216 {
217 /*
218 No interlacing: RGBRGBRGBRGBRGBRGB...
219 */
220 if (scene == 0)
221 {
222 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristyb3f97ae2015-05-18 12:29:32 +0000223 pixels=(const unsigned char *) ReadBlobStream(image,length,
224 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000225 }
cristybb503372010-05-27 20:51:26 +0000226 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000227 {
cristy4c08aed2011-07-01 19:47:50 +0000228 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100229 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000230
cristy4c08aed2011-07-01 19:47:50 +0000231 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100232 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000233
cristy90dbac72010-08-22 15:08:40 +0000234 register ssize_t
235 x;
236
cristy21da32d2009-09-12 14:56:09 +0000237 if (count != (ssize_t) length)
238 {
239 ThrowFileException(exception,CorruptImageError,
240 "UnexpectedEndOfFile",image->filename);
241 break;
242 }
cristy3ed852e2009-09-05 21:47:34 +0000243 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
244 exception);
cristyacd2ed22011-08-30 01:44:23 +0000245 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000246 break;
247 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
248 quantum_info,quantum_type,pixels,exception);
249 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
250 break;
cristy90dbac72010-08-22 15:08:40 +0000251 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000252 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000253 {
254 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
255 canvas_image->columns,1,exception);
256 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
257 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000258 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000259 break;
cristybb503372010-05-27 20:51:26 +0000260 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000261 {
cristy4c08aed2011-07-01 19:47:50 +0000262 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
263 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
264 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
265 SetPixelAlpha(image,OpaqueAlpha,q);
cristy17f11b02014-12-20 19:37:04 +0000266 if (image->alpha_trait != UndefinedPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000267 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000268 p+=GetPixelChannels(canvas_image);
269 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000270 }
271 if (SyncAuthenticPixels(image,exception) == MagickFalse)
272 break;
273 }
274 if (image->previous == (Image *) NULL)
275 {
cristycee97112010-05-28 00:44:52 +0000276 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
277 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000278 if (status == MagickFalse)
279 break;
280 }
cristyb3f97ae2015-05-18 12:29:32 +0000281 pixels=(const unsigned char *) ReadBlobStream(image,length,
282 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000283 }
284 break;
285 }
286 case LineInterlace:
287 {
cristy90dbac72010-08-22 15:08:40 +0000288 static QuantumType
289 quantum_types[4] =
290 {
291 RedQuantum,
292 GreenQuantum,
293 BlueQuantum,
294 AlphaQuantum
295 };
296
cristy3ed852e2009-09-05 21:47:34 +0000297 /*
298 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
299 */
cristy90dbac72010-08-22 15:08:40 +0000300 if (LocaleCompare(image_info->magick,"RGBO") == 0)
301 quantum_types[3]=OpacityQuantum;
cristy3ed852e2009-09-05 21:47:34 +0000302 if (scene == 0)
303 {
cristy90dbac72010-08-22 15:08:40 +0000304 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristyb3f97ae2015-05-18 12:29:32 +0000305 pixels=(const unsigned char *) ReadBlobStream(image,length,
306 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000307 }
cristybb503372010-05-27 20:51:26 +0000308 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000309 {
cristy4c08aed2011-07-01 19:47:50 +0000310 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100311 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000312
cristy4c08aed2011-07-01 19:47:50 +0000313 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100314 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000315
cristy90dbac72010-08-22 15:08:40 +0000316 register ssize_t
317 x;
318
cristy21da32d2009-09-12 14:56:09 +0000319 if (count != (ssize_t) length)
320 {
321 ThrowFileException(exception,CorruptImageError,
322 "UnexpectedEndOfFile",image->filename);
323 break;
324 }
cristy17f11b02014-12-20 19:37:04 +0000325 for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++)
cristy3ed852e2009-09-05 21:47:34 +0000326 {
cristy90dbac72010-08-22 15:08:40 +0000327 quantum_type=quantum_types[i];
cristy3ed852e2009-09-05 21:47:34 +0000328 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
329 exception);
cristyacd2ed22011-08-30 01:44:23 +0000330 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000331 break;
332 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
cristy90dbac72010-08-22 15:08:40 +0000333 quantum_info,quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000334 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
335 break;
cristy90dbac72010-08-22 15:08:40 +0000336 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000337 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000338 {
339 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
340 0,canvas_image->columns,1,exception);
341 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
342 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000343 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000344 break;
cristy90dbac72010-08-22 15:08:40 +0000345 for (x=0; x < (ssize_t) image->columns; x++)
346 {
347 switch (quantum_type)
cristy3ed852e2009-09-05 21:47:34 +0000348 {
cristy90dbac72010-08-22 15:08:40 +0000349 case RedQuantum:
350 {
cristy4c08aed2011-07-01 19:47:50 +0000351 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000352 break;
353 }
354 case GreenQuantum:
355 {
cristy4c08aed2011-07-01 19:47:50 +0000356 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000357 break;
358 }
359 case BlueQuantum:
360 {
cristy4c08aed2011-07-01 19:47:50 +0000361 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000362 break;
363 }
364 case OpacityQuantum:
365 {
cristy4c08aed2011-07-01 19:47:50 +0000366 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000367 break;
368 }
369 case AlphaQuantum:
370 {
cristy4c08aed2011-07-01 19:47:50 +0000371 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000372 break;
373 }
374 default:
375 break;
cristy3ed852e2009-09-05 21:47:34 +0000376 }
cristyed231572011-07-14 02:18:59 +0000377 p+=GetPixelChannels(canvas_image);
378 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000379 }
cristy3ed852e2009-09-05 21:47:34 +0000380 if (SyncAuthenticPixels(image,exception) == MagickFalse)
381 break;
382 }
cristyb3f97ae2015-05-18 12:29:32 +0000383 pixels=(const unsigned char *) ReadBlobStream(image,length,
384 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000385 }
386 if (image->previous == (Image *) NULL)
387 {
cristycee97112010-05-28 00:44:52 +0000388 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
389 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000390 if (status == MagickFalse)
391 break;
392 }
393 }
394 break;
395 }
396 case PlaneInterlace:
397 {
398 /*
399 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
400 */
401 if (scene == 0)
402 {
cristy90dbac72010-08-22 15:08:40 +0000403 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristyb3f97ae2015-05-18 12:29:32 +0000404 pixels=(const unsigned char *) ReadBlobStream(image,length,
405 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000406 }
cristy90dbac72010-08-22 15:08:40 +0000407 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000408 {
cristy4c08aed2011-07-01 19:47:50 +0000409 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100410 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000411
cristy4c08aed2011-07-01 19:47:50 +0000412 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100413 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000414
cristy90dbac72010-08-22 15:08:40 +0000415 register ssize_t
416 x;
cristy3ed852e2009-09-05 21:47:34 +0000417
cristy90dbac72010-08-22 15:08:40 +0000418 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000419 {
cristy90dbac72010-08-22 15:08:40 +0000420 ThrowFileException(exception,CorruptImageError,
421 "UnexpectedEndOfFile",image->filename);
422 break;
423 }
424 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
425 exception);
cristyacd2ed22011-08-30 01:44:23 +0000426 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000427 break;
428 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
429 quantum_info,RedQuantum,pixels,exception);
430 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
431 break;
432 if (((y-image->extract_info.y) >= 0) &&
433 ((y-image->extract_info.y) < (ssize_t) image->rows))
434 {
435 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
436 canvas_image->columns,1,exception);
437 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
438 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000439 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000440 break;
441 for (x=0; x < (ssize_t) image->columns; x++)
442 {
cristy4c08aed2011-07-01 19:47:50 +0000443 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000444 p+=GetPixelChannels(canvas_image);
445 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000446 }
447 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000448 break;
449 }
cristyb3f97ae2015-05-18 12:29:32 +0000450 pixels=(const unsigned char *) ReadBlobStream(image,length,
451 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000452 }
453 if (image->previous == (Image *) NULL)
454 {
cristy90dbac72010-08-22 15:08:40 +0000455 status=SetImageProgress(image,LoadImageTag,1,6);
456 if (status == MagickFalse)
457 break;
458 }
459 for (y=0; y < (ssize_t) image->extract_info.height; y++)
460 {
cristy4c08aed2011-07-01 19:47:50 +0000461 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100462 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000463
cristy4c08aed2011-07-01 19:47:50 +0000464 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100465 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000466
467 register ssize_t
468 x;
469
470 if (count != (ssize_t) length)
471 {
472 ThrowFileException(exception,CorruptImageError,
473 "UnexpectedEndOfFile",image->filename);
474 break;
475 }
476 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
477 exception);
cristyacd2ed22011-08-30 01:44:23 +0000478 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000479 break;
480 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
481 quantum_info,GreenQuantum,pixels,exception);
482 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
483 break;
484 if (((y-image->extract_info.y) >= 0) &&
485 ((y-image->extract_info.y) < (ssize_t) image->rows))
486 {
487 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
488 canvas_image->columns,1,exception);
489 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
490 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000491 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000492 break;
493 for (x=0; x < (ssize_t) image->columns; x++)
494 {
cristyf27ee032011-09-29 17:51:41 +0000495 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000496 p+=GetPixelChannels(canvas_image);
497 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000498 }
499 if (SyncAuthenticPixels(image,exception) == MagickFalse)
500 break;
501 }
cristyb3f97ae2015-05-18 12:29:32 +0000502 pixels=(const unsigned char *) ReadBlobStream(image,length,
503 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000504 }
505 if (image->previous == (Image *) NULL)
506 {
507 status=SetImageProgress(image,LoadImageTag,2,6);
508 if (status == MagickFalse)
509 break;
510 }
511 for (y=0; y < (ssize_t) image->extract_info.height; y++)
512 {
cristy4c08aed2011-07-01 19:47:50 +0000513 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100514 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000515
cristy4c08aed2011-07-01 19:47:50 +0000516 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100517 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000518
519 register ssize_t
520 x;
521
522 if (count != (ssize_t) length)
523 {
524 ThrowFileException(exception,CorruptImageError,
525 "UnexpectedEndOfFile",image->filename);
526 break;
527 }
528 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
529 exception);
cristyacd2ed22011-08-30 01:44:23 +0000530 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000531 break;
532 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
533 quantum_info,BlueQuantum,pixels,exception);
534 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
535 break;
536 if (((y-image->extract_info.y) >= 0) &&
537 ((y-image->extract_info.y) < (ssize_t) image->rows))
538 {
539 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
540 canvas_image->columns,1,exception);
541 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
542 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000543 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000544 break;
545 for (x=0; x < (ssize_t) image->columns; x++)
546 {
cristyf27ee032011-09-29 17:51:41 +0000547 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000548 p+=GetPixelChannels(canvas_image);
549 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000550 }
551 if (SyncAuthenticPixels(image,exception) == MagickFalse)
552 break;
553 }
cristyb3f97ae2015-05-18 12:29:32 +0000554 pixels=(const unsigned char *) ReadBlobStream(image,length,
555 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000556 }
557 if (image->previous == (Image *) NULL)
558 {
559 status=SetImageProgress(image,LoadImageTag,3,6);
560 if (status == MagickFalse)
561 break;
562 }
563 if (image->previous == (Image *) NULL)
564 {
565 status=SetImageProgress(image,LoadImageTag,4,6);
566 if (status == MagickFalse)
567 break;
568 }
cristy17f11b02014-12-20 19:37:04 +0000569 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000570 {
571 for (y=0; y < (ssize_t) image->extract_info.height; y++)
572 {
cristy4c08aed2011-07-01 19:47:50 +0000573 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100574 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000575
cristy4c08aed2011-07-01 19:47:50 +0000576 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100577 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000578
579 register ssize_t
580 x;
581
582 if (count != (ssize_t) length)
583 {
584 ThrowFileException(exception,CorruptImageError,
585 "UnexpectedEndOfFile",image->filename);
586 break;
587 }
588 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
589 exception);
cristyacd2ed22011-08-30 01:44:23 +0000590 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000591 break;
592 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
593 quantum_info,AlphaQuantum,pixels,exception);
594 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
595 break;
596 if (((y-image->extract_info.y) >= 0) &&
597 ((y-image->extract_info.y) < (ssize_t) image->rows))
598 {
599 p=GetVirtualPixels(canvas_image,
600 canvas_image->extract_info.x,0,canvas_image->columns,1,
601 exception);
602 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
603 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000604 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000605 break;
606 for (x=0; x < (ssize_t) image->columns; x++)
607 {
cristyf27ee032011-09-29 17:51:41 +0000608 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000609 p+=GetPixelChannels(canvas_image);
610 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000611 }
612 if (SyncAuthenticPixels(image,exception) == MagickFalse)
613 break;
614 }
cristyb3f97ae2015-05-18 12:29:32 +0000615 pixels=(const unsigned char *) ReadBlobStream(image,length,
616 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000617 }
618 if (image->previous == (Image *) NULL)
619 {
620 status=SetImageProgress(image,LoadImageTag,5,6);
621 if (status == MagickFalse)
622 break;
623 }
624 }
625 if (image->previous == (Image *) NULL)
626 {
627 status=SetImageProgress(image,LoadImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +0000628 if (status == MagickFalse)
629 break;
630 }
631 break;
632 }
633 case PartitionInterlace:
634 {
635 /*
636 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
637 */
cristy90dbac72010-08-22 15:08:40 +0000638 AppendImageFormat("R",image->filename);
639 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
640 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000641 {
cristy90dbac72010-08-22 15:08:40 +0000642 canvas_image=DestroyImageList(canvas_image);
643 image=DestroyImageList(image);
644 return((Image *) NULL);
645 }
cristyd4297022010-09-16 22:59:09 +0000646 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
647 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
648 image->filename);
cristy90dbac72010-08-22 15:08:40 +0000649 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
650 for (i=0; i < (ssize_t) scene; i++)
651 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000652 {
cristyb3f97ae2015-05-18 12:29:32 +0000653 pixels=(const unsigned char *) ReadBlobStream(image,length,
654 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000655 if (count != (ssize_t) length)
cristy21da32d2009-09-12 14:56:09 +0000656 {
657 ThrowFileException(exception,CorruptImageError,
658 "UnexpectedEndOfFile",image->filename);
659 break;
660 }
cristybd797f12015-01-24 20:42:32 +0000661 }
cristyb3f97ae2015-05-18 12:29:32 +0000662 pixels=(const unsigned char *) ReadBlobStream(image,length,
663 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000664 for (y=0; y < (ssize_t) image->extract_info.height; y++)
665 {
cristy4c08aed2011-07-01 19:47:50 +0000666 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100667 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000668
cristy4c08aed2011-07-01 19:47:50 +0000669 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100670 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000671
672 register ssize_t
673 x;
674
675 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000676 {
cristy90dbac72010-08-22 15:08:40 +0000677 ThrowFileException(exception,CorruptImageError,
678 "UnexpectedEndOfFile",image->filename);
679 break;
680 }
681 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
682 exception);
cristyacd2ed22011-08-30 01:44:23 +0000683 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000684 break;
685 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
686 quantum_info,RedQuantum,pixels,exception);
687 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
688 break;
689 if (((y-image->extract_info.y) >= 0) &&
690 ((y-image->extract_info.y) < (ssize_t) image->rows))
691 {
692 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
693 canvas_image->columns,1,exception);
694 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
695 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000696 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000697 break;
698 for (x=0; x < (ssize_t) image->columns; x++)
699 {
cristy4c08aed2011-07-01 19:47:50 +0000700 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000701 p+=GetPixelChannels(canvas_image);
702 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000703 }
704 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000705 break;
706 }
cristyb3f97ae2015-05-18 12:29:32 +0000707 pixels=(const unsigned char *) ReadBlobStream(image,length,
708 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000709 }
710 if (image->previous == (Image *) NULL)
711 {
cristy90dbac72010-08-22 15:08:40 +0000712 status=SetImageProgress(image,LoadImageTag,1,5);
713 if (status == MagickFalse)
714 break;
715 }
716 (void) CloseBlob(image);
717 AppendImageFormat("G",image->filename);
718 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
719 if (status == MagickFalse)
720 {
721 canvas_image=DestroyImageList(canvas_image);
722 image=DestroyImageList(image);
723 return((Image *) NULL);
724 }
725 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
726 for (i=0; i < (ssize_t) scene; i++)
727 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000728 {
cristyb3f97ae2015-05-18 12:29:32 +0000729 pixels=(const unsigned char *) ReadBlobStream(image,length,
730 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000731 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000732 {
733 ThrowFileException(exception,CorruptImageError,
734 "UnexpectedEndOfFile",image->filename);
735 break;
736 }
cristybd797f12015-01-24 20:42:32 +0000737 }
cristyb3f97ae2015-05-18 12:29:32 +0000738 pixels=(const unsigned char *) ReadBlobStream(image,length,
739 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000740 for (y=0; y < (ssize_t) image->extract_info.height; y++)
741 {
cristy4c08aed2011-07-01 19:47:50 +0000742 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100743 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000744
cristy4c08aed2011-07-01 19:47:50 +0000745 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100746 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000747
748 register ssize_t
749 x;
750
751 if (count != (ssize_t) length)
752 {
753 ThrowFileException(exception,CorruptImageError,
754 "UnexpectedEndOfFile",image->filename);
755 break;
756 }
757 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
758 exception);
cristyacd2ed22011-08-30 01:44:23 +0000759 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000760 break;
761 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
762 quantum_info,GreenQuantum,pixels,exception);
763 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
764 break;
765 if (((y-image->extract_info.y) >= 0) &&
766 ((y-image->extract_info.y) < (ssize_t) image->rows))
767 {
768 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
769 canvas_image->columns,1,exception);
770 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
771 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000772 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000773 break;
774 for (x=0; x < (ssize_t) image->columns; x++)
775 {
cristyf27ee032011-09-29 17:51:41 +0000776 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000777 p+=GetPixelChannels(canvas_image);
778 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000779 }
780 if (SyncAuthenticPixels(image,exception) == MagickFalse)
781 break;
782 }
cristyb3f97ae2015-05-18 12:29:32 +0000783 pixels=(const unsigned char *) ReadBlobStream(image,length,
784 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000785 }
786 if (image->previous == (Image *) NULL)
787 {
788 status=SetImageProgress(image,LoadImageTag,2,5);
789 if (status == MagickFalse)
790 break;
791 }
792 (void) CloseBlob(image);
793 AppendImageFormat("B",image->filename);
794 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
795 if (status == MagickFalse)
796 {
797 canvas_image=DestroyImageList(canvas_image);
798 image=DestroyImageList(image);
799 return((Image *) NULL);
800 }
801 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
802 for (i=0; i < (ssize_t) scene; i++)
803 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000804 {
cristyb3f97ae2015-05-18 12:29:32 +0000805 pixels=(const unsigned char *) ReadBlobStream(image,length,
806 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000807 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000808 {
809 ThrowFileException(exception,CorruptImageError,
810 "UnexpectedEndOfFile",image->filename);
811 break;
812 }
cristybd797f12015-01-24 20:42:32 +0000813 }
cristyb3f97ae2015-05-18 12:29:32 +0000814 pixels=(const unsigned char *) ReadBlobStream(image,length,
815 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000816 for (y=0; y < (ssize_t) image->extract_info.height; y++)
817 {
cristy4c08aed2011-07-01 19:47:50 +0000818 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100819 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000820
cristy4c08aed2011-07-01 19:47:50 +0000821 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100822 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000823
824 register ssize_t
825 x;
826
827 if (count != (ssize_t) length)
828 {
829 ThrowFileException(exception,CorruptImageError,
830 "UnexpectedEndOfFile",image->filename);
831 break;
832 }
833 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
834 exception);
cristyacd2ed22011-08-30 01:44:23 +0000835 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000836 break;
837 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
838 quantum_info,BlueQuantum,pixels,exception);
839 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
840 break;
841 if (((y-image->extract_info.y) >= 0) &&
842 ((y-image->extract_info.y) < (ssize_t) image->rows))
843 {
844 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
845 canvas_image->columns,1,exception);
846 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
847 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000848 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000849 break;
850 for (x=0; x < (ssize_t) image->columns; x++)
851 {
cristyf27ee032011-09-29 17:51:41 +0000852 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000853 p+=GetPixelChannels(canvas_image);
854 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000855 }
856 if (SyncAuthenticPixels(image,exception) == MagickFalse)
857 break;
858 }
cristyb3f97ae2015-05-18 12:29:32 +0000859 pixels=(const unsigned char *) ReadBlobStream(image,length,
860 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000861 }
862 if (image->previous == (Image *) NULL)
863 {
864 status=SetImageProgress(image,LoadImageTag,3,5);
865 if (status == MagickFalse)
866 break;
867 }
cristy17f11b02014-12-20 19:37:04 +0000868 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000869 {
870 (void) CloseBlob(image);
871 AppendImageFormat("A",image->filename);
872 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
873 if (status == MagickFalse)
874 {
875 canvas_image=DestroyImageList(canvas_image);
876 image=DestroyImageList(image);
877 return((Image *) NULL);
878 }
879 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
880 for (i=0; i < (ssize_t) scene; i++)
881 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000882 {
cristyb3f97ae2015-05-18 12:29:32 +0000883 pixels=(const unsigned char *) ReadBlobStream(image,length,
cristybd797f12015-01-24 20:42:32 +0000884 GetQuantumPixels(quantum_info),&count);
885 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000886 {
887 ThrowFileException(exception,CorruptImageError,
888 "UnexpectedEndOfFile",image->filename);
889 break;
890 }
cristybd797f12015-01-24 20:42:32 +0000891 }
cristyb3f97ae2015-05-18 12:29:32 +0000892 pixels=(const unsigned char *) ReadBlobStream(image,length,
893 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000894 for (y=0; y < (ssize_t) image->extract_info.height; y++)
895 {
cristy4c08aed2011-07-01 19:47:50 +0000896 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100897 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000898
cristy4c08aed2011-07-01 19:47:50 +0000899 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100900 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000901
902 register ssize_t
903 x;
904
905 if (count != (ssize_t) length)
906 {
907 ThrowFileException(exception,CorruptImageError,
908 "UnexpectedEndOfFile",image->filename);
909 break;
910 }
911 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
912 exception);
cristyacd2ed22011-08-30 01:44:23 +0000913 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000914 break;
915 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
916 quantum_info,BlueQuantum,pixels,exception);
917 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
918 break;
919 if (((y-image->extract_info.y) >= 0) &&
920 ((y-image->extract_info.y) < (ssize_t) image->rows))
921 {
922 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
923 0,canvas_image->columns,1,exception);
924 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
925 image->columns,1,exception);
cristyc6aebff2012-05-07 23:24:35 +0000926 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000927 break;
928 for (x=0; x < (ssize_t) image->columns; x++)
929 {
cristyf27ee032011-09-29 17:51:41 +0000930 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000931 p+=GetPixelChannels(canvas_image);
932 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000933 }
934 if (SyncAuthenticPixels(image,exception) == MagickFalse)
935 break;
936 }
cristyb3f97ae2015-05-18 12:29:32 +0000937 pixels=(const unsigned char *) ReadBlobStream(image,length,
938 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000939 }
940 if (image->previous == (Image *) NULL)
941 {
942 status=SetImageProgress(image,LoadImageTag,4,5);
943 if (status == MagickFalse)
944 break;
945 }
946 }
947 (void) CloseBlob(image);
948 if (image->previous == (Image *) NULL)
949 {
cristy3ed852e2009-09-05 21:47:34 +0000950 status=SetImageProgress(image,LoadImageTag,5,5);
951 if (status == MagickFalse)
952 break;
953 }
954 break;
955 }
956 }
957 SetQuantumImageType(image,quantum_type);
cristy3ed852e2009-09-05 21:47:34 +0000958 /*
959 Proceed to next image.
960 */
961 if (image_info->number_scenes != 0)
962 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
963 break;
964 if (count == (ssize_t) length)
965 {
966 /*
967 Allocate next image structure.
968 */
cristy9950d572011-10-01 18:22:35 +0000969 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000970 if (GetNextImageInList(image) == (Image *) NULL)
971 {
972 image=DestroyImageList(image);
973 return((Image *) NULL);
974 }
975 image=SyncNextImageInList(image);
976 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
977 GetBlobSize(image));
978 if (status == MagickFalse)
979 break;
980 }
981 scene++;
982 } while (count == (ssize_t) length);
cristy3ed852e2009-09-05 21:47:34 +0000983 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000984 canvas_image=DestroyImage(canvas_image);
985 (void) CloseBlob(image);
986 return(GetFirstImageInList(image));
987}
988
989/*
990%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991% %
992% %
993% %
994% R e g i s t e r R G B I m a g e %
995% %
996% %
997% %
998%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999%
cristy90dbac72010-08-22 15:08:40 +00001000% RegisterRGBImage() adds attributes for the RGB image format to
cristy3ed852e2009-09-05 21:47:34 +00001001% the list of supported formats. The attributes include the image format
1002% tag, a method to read and/or write the format, whether the format
1003% supports the saving of more than one frame to the same file or blob,
1004% whether the format supports native in-memory I/O, and a brief
1005% description of the format.
1006%
1007% The format of the RegisterRGBImage method is:
1008%
cristybb503372010-05-27 20:51:26 +00001009% size_t RegisterRGBImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001010%
1011*/
cristybb503372010-05-27 20:51:26 +00001012ModuleExport size_t RegisterRGBImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001013{
1014 MagickInfo
1015 *entry;
1016
dirk06b627a2015-04-06 18:59:17 +00001017 entry=AcquireMagickInfo("RGB","RGB",
1018 "Raw red, green, and blue samples");
cristy3ed852e2009-09-05 21:47:34 +00001019 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1020 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001021 entry->flags|=CoderRawSupportFlag;
1022 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001023 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +00001024 entry=AcquireMagickInfo("RGB","RGBA",
1025 "Raw red, green, blue, and alpha samples");
cristy3ed852e2009-09-05 21:47:34 +00001026 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1027 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001028 entry->flags|=CoderRawSupportFlag;
1029 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001030 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +00001031 entry=AcquireMagickInfo("RGB","RGBO",
1032 "Raw red, green, blue, and opacity samples");
cristy3ed852e2009-09-05 21:47:34 +00001033 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1034 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001035 entry->flags|=CoderRawSupportFlag;
1036 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001037 (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);
cristye1c94d92015-06-28 12:16:33 +00001124 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001125 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001126 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001127 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");
cristyb3f97ae2015-05-18 12:29:32 +00001156 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +00001157 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
dirk05d2ff72015-11-18 23:13:43 +01001168 *magick_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
dirk05d2ff72015-11-18 23:13:43 +01001196 *magick_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
dirk05d2ff72015-11-18 23:13:43 +01001250 *magick_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
dirk05d2ff72015-11-18 23:13:43 +01001270 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001271
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
dirk05d2ff72015-11-18 23:13:43 +01001290 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001291
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
dirk05d2ff72015-11-18 23:13:43 +01001312 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001313
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,
cristy151b66d2015-04-15 10:50:31 +00001332 MagickPathExtent);
cristy90dbac72010-08-22 15:08:40 +00001333 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
dirk05d2ff72015-11-18 23:13:43 +01001354 *magick_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
dirk05d2ff72015-11-18 23:13:43 +01001380 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001381
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
dirk05d2ff72015-11-18 23:13:43 +01001406 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001407
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
dirk05d2ff72015-11-18 23:13:43 +01001434 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001435
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,
cristy151b66d2015-04-15 10:50:31 +00001454 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001455 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}