blob: 15759f916ca44fba03f6072854f55671739eb913 [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% %
Cristy252dd2c2018-12-02 09:42:06 -050020% Copyright 1999-2019 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% %
Cristy83d74de2018-10-13 10:17:25 -040026% https://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 }
Cristyb2d24412018-03-09 19:41:19 -0500152 if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
cristyd4297022010-09-16 22:59:09 +0000153 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)
Dirk Lemstradede8402018-03-24 17:51:58 +0100167 {
168 canvas_image=DestroyImage(canvas_image);
169 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
170 }
cristy3ed852e2009-09-05 21:47:34 +0000171 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +0000172 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristya38675f2010-08-21 18:35:13 +0000173 {
cristy90dbac72010-08-22 15:08:40 +0000174 quantum_type=RGBAQuantum;
cristy8a46d822012-08-28 23:32:39 +0000175 image->alpha_trait=BlendPixelTrait;
176 canvas_image->alpha_trait=BlendPixelTrait;
cristya38675f2010-08-21 18:35:13 +0000177 }
cristy90dbac72010-08-22 15:08:40 +0000178 if (LocaleCompare(image_info->magick,"RGBO") == 0)
179 {
180 quantum_type=RGBOQuantum;
dirk7000aae2015-02-24 11:56:06 +0000181 image->alpha_trait=BlendPixelTrait;
cristy8a46d822012-08-28 23:32:39 +0000182 canvas_image->alpha_trait=BlendPixelTrait;
cristy90dbac72010-08-22 15:08:40 +0000183 }
cristyb3f97ae2015-05-18 12:29:32 +0000184 pixels=(const unsigned char *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000185 if (image_info->number_scenes != 0)
186 while (image->scene < image_info->scene)
187 {
188 /*
189 Skip to next image.
190 */
191 image->scene++;
192 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristybb503372010-05-27 20:51:26 +0000193 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000194 {
cristyb3f97ae2015-05-18 12:29:32 +0000195 pixels=(const unsigned char *) ReadBlobStream(image,length,
196 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000197 if (count != (ssize_t) length)
198 break;
199 }
200 }
cristy3ed852e2009-09-05 21:47:34 +0000201 count=0;
202 length=0;
203 scene=0;
Dirk Lemstradede8402018-03-24 17:51:58 +0100204 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +0000205 do
206 {
207 /*
208 Read pixels to virtual canvas image then push to image.
209 */
210 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
211 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
212 break;
cristyacabb842014-12-14 23:36:33 +0000213 status=SetImageExtent(image,image->columns,image->rows,exception);
214 if (status == MagickFalse)
Dirk Lemstradede8402018-03-24 17:51:58 +0100215 break;
cristy3ed852e2009-09-05 21:47:34 +0000216 switch (image_info->interlace)
217 {
218 case NoInterlace:
219 default:
220 {
221 /*
222 No interlacing: RGBRGBRGBRGBRGBRGB...
223 */
224 if (scene == 0)
225 {
226 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristyb3f97ae2015-05-18 12:29:32 +0000227 pixels=(const unsigned char *) ReadBlobStream(image,length,
228 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000229 }
cristybb503372010-05-27 20:51:26 +0000230 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000231 {
cristy4c08aed2011-07-01 19:47:50 +0000232 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100233 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000234
cristy4c08aed2011-07-01 19:47:50 +0000235 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100236 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000237
cristy90dbac72010-08-22 15:08:40 +0000238 register ssize_t
239 x;
240
cristy21da32d2009-09-12 14:56:09 +0000241 if (count != (ssize_t) length)
242 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100243 status=MagickFalse;
cristy21da32d2009-09-12 14:56:09 +0000244 ThrowFileException(exception,CorruptImageError,
245 "UnexpectedEndOfFile",image->filename);
246 break;
247 }
cristy3ed852e2009-09-05 21:47:34 +0000248 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
249 exception);
cristyacd2ed22011-08-30 01:44:23 +0000250 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000251 break;
252 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
253 quantum_info,quantum_type,pixels,exception);
254 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
255 break;
cristy90dbac72010-08-22 15:08:40 +0000256 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000257 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000258 {
259 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
260 canvas_image->columns,1,exception);
261 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
262 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000263 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000264 break;
cristybb503372010-05-27 20:51:26 +0000265 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000266 {
cristy4c08aed2011-07-01 19:47:50 +0000267 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
268 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
269 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
270 SetPixelAlpha(image,OpaqueAlpha,q);
cristy17f11b02014-12-20 19:37:04 +0000271 if (image->alpha_trait != UndefinedPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000272 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000273 p+=GetPixelChannels(canvas_image);
274 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000275 }
276 if (SyncAuthenticPixels(image,exception) == MagickFalse)
277 break;
278 }
279 if (image->previous == (Image *) NULL)
280 {
cristycee97112010-05-28 00:44:52 +0000281 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
282 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000283 if (status == MagickFalse)
284 break;
285 }
cristyb3f97ae2015-05-18 12:29:32 +0000286 pixels=(const unsigned char *) ReadBlobStream(image,length,
287 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000288 }
289 break;
290 }
291 case LineInterlace:
292 {
cristy90dbac72010-08-22 15:08:40 +0000293 static QuantumType
294 quantum_types[4] =
295 {
296 RedQuantum,
297 GreenQuantum,
298 BlueQuantum,
299 AlphaQuantum
300 };
301
cristy3ed852e2009-09-05 21:47:34 +0000302 /*
303 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
304 */
cristy90dbac72010-08-22 15:08:40 +0000305 if (LocaleCompare(image_info->magick,"RGBO") == 0)
306 quantum_types[3]=OpacityQuantum;
cristy3ed852e2009-09-05 21:47:34 +0000307 if (scene == 0)
308 {
cristy90dbac72010-08-22 15:08:40 +0000309 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristyb3f97ae2015-05-18 12:29:32 +0000310 pixels=(const unsigned char *) ReadBlobStream(image,length,
311 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000312 }
cristybb503372010-05-27 20:51:26 +0000313 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000314 {
cristy17f11b02014-12-20 19:37:04 +0000315 for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++)
cristy3ed852e2009-09-05 21:47:34 +0000316 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100317 register const Quantum
318 *magick_restrict p;
319
320 register Quantum
321 *magick_restrict q;
322
323 register ssize_t
324 x;
325
326 if (count != (ssize_t) length)
327 {
328 status=MagickFalse;
329 ThrowFileException(exception,CorruptImageError,
330 "UnexpectedEndOfFile",image->filename);
331 break;
332 }
cristy90dbac72010-08-22 15:08:40 +0000333 quantum_type=quantum_types[i];
cristy3ed852e2009-09-05 21:47:34 +0000334 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
335 exception);
cristyacd2ed22011-08-30 01:44:23 +0000336 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000337 break;
338 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
cristy90dbac72010-08-22 15:08:40 +0000339 quantum_info,quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000340 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
341 break;
cristy90dbac72010-08-22 15:08:40 +0000342 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000343 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000344 {
345 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
346 0,canvas_image->columns,1,exception);
347 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
348 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000349 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000350 break;
cristy90dbac72010-08-22 15:08:40 +0000351 for (x=0; x < (ssize_t) image->columns; x++)
352 {
353 switch (quantum_type)
cristy3ed852e2009-09-05 21:47:34 +0000354 {
cristy90dbac72010-08-22 15:08:40 +0000355 case RedQuantum:
356 {
cristy4c08aed2011-07-01 19:47:50 +0000357 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000358 break;
359 }
360 case GreenQuantum:
361 {
cristy4c08aed2011-07-01 19:47:50 +0000362 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000363 break;
364 }
365 case BlueQuantum:
366 {
cristy4c08aed2011-07-01 19:47:50 +0000367 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000368 break;
369 }
370 case OpacityQuantum:
371 {
Cristyc7737122018-03-09 20:01:16 -0500372 SetPixelOpacity(image,GetPixelOpacity(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000373 break;
374 }
375 case AlphaQuantum:
376 {
cristy4c08aed2011-07-01 19:47:50 +0000377 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000378 break;
379 }
380 default:
381 break;
cristy3ed852e2009-09-05 21:47:34 +0000382 }
cristyed231572011-07-14 02:18:59 +0000383 p+=GetPixelChannels(canvas_image);
384 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000385 }
cristy3ed852e2009-09-05 21:47:34 +0000386 if (SyncAuthenticPixels(image,exception) == MagickFalse)
387 break;
388 }
cristyb3f97ae2015-05-18 12:29:32 +0000389 pixels=(const unsigned char *) ReadBlobStream(image,length,
390 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000391 }
392 if (image->previous == (Image *) NULL)
393 {
cristycee97112010-05-28 00:44:52 +0000394 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
395 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000396 if (status == MagickFalse)
397 break;
398 }
399 }
400 break;
401 }
402 case PlaneInterlace:
403 {
404 /*
405 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
406 */
407 if (scene == 0)
408 {
cristy90dbac72010-08-22 15:08:40 +0000409 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristyb3f97ae2015-05-18 12:29:32 +0000410 pixels=(const unsigned char *) ReadBlobStream(image,length,
411 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000412 }
cristy90dbac72010-08-22 15:08:40 +0000413 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000414 {
cristy4c08aed2011-07-01 19:47:50 +0000415 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100416 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000417
cristy4c08aed2011-07-01 19:47:50 +0000418 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100419 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000420
cristy90dbac72010-08-22 15:08:40 +0000421 register ssize_t
422 x;
cristy3ed852e2009-09-05 21:47:34 +0000423
cristy90dbac72010-08-22 15:08:40 +0000424 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000425 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100426 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000427 ThrowFileException(exception,CorruptImageError,
428 "UnexpectedEndOfFile",image->filename);
429 break;
430 }
431 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
432 exception);
cristyacd2ed22011-08-30 01:44:23 +0000433 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000434 break;
435 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
436 quantum_info,RedQuantum,pixels,exception);
437 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
438 break;
439 if (((y-image->extract_info.y) >= 0) &&
440 ((y-image->extract_info.y) < (ssize_t) image->rows))
441 {
442 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
443 canvas_image->columns,1,exception);
444 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
445 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000446 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000447 break;
448 for (x=0; x < (ssize_t) image->columns; x++)
449 {
cristy4c08aed2011-07-01 19:47:50 +0000450 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000451 p+=GetPixelChannels(canvas_image);
452 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000453 }
454 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000455 break;
456 }
cristyb3f97ae2015-05-18 12:29:32 +0000457 pixels=(const unsigned char *) ReadBlobStream(image,length,
458 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000459 }
460 if (image->previous == (Image *) NULL)
461 {
cristy90dbac72010-08-22 15:08:40 +0000462 status=SetImageProgress(image,LoadImageTag,1,6);
463 if (status == MagickFalse)
464 break;
465 }
466 for (y=0; y < (ssize_t) image->extract_info.height; y++)
467 {
cristy4c08aed2011-07-01 19:47:50 +0000468 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100469 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000470
cristy4c08aed2011-07-01 19:47:50 +0000471 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100472 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000473
474 register ssize_t
475 x;
476
477 if (count != (ssize_t) length)
478 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100479 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000480 ThrowFileException(exception,CorruptImageError,
481 "UnexpectedEndOfFile",image->filename);
482 break;
483 }
484 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
485 exception);
cristyacd2ed22011-08-30 01:44:23 +0000486 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000487 break;
488 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
489 quantum_info,GreenQuantum,pixels,exception);
490 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
491 break;
492 if (((y-image->extract_info.y) >= 0) &&
493 ((y-image->extract_info.y) < (ssize_t) image->rows))
494 {
495 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
496 canvas_image->columns,1,exception);
497 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
498 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000499 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000500 break;
501 for (x=0; x < (ssize_t) image->columns; x++)
502 {
cristyf27ee032011-09-29 17:51:41 +0000503 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000504 p+=GetPixelChannels(canvas_image);
505 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000506 }
507 if (SyncAuthenticPixels(image,exception) == MagickFalse)
508 break;
509 }
cristyb3f97ae2015-05-18 12:29:32 +0000510 pixels=(const unsigned char *) ReadBlobStream(image,length,
511 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000512 }
513 if (image->previous == (Image *) NULL)
514 {
515 status=SetImageProgress(image,LoadImageTag,2,6);
516 if (status == MagickFalse)
517 break;
518 }
519 for (y=0; y < (ssize_t) image->extract_info.height; y++)
520 {
cristy4c08aed2011-07-01 19:47:50 +0000521 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100522 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000523
cristy4c08aed2011-07-01 19:47:50 +0000524 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100525 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000526
527 register ssize_t
528 x;
529
530 if (count != (ssize_t) length)
531 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100532 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000533 ThrowFileException(exception,CorruptImageError,
534 "UnexpectedEndOfFile",image->filename);
535 break;
536 }
537 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
538 exception);
cristyacd2ed22011-08-30 01:44:23 +0000539 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000540 break;
541 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
542 quantum_info,BlueQuantum,pixels,exception);
543 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
544 break;
545 if (((y-image->extract_info.y) >= 0) &&
546 ((y-image->extract_info.y) < (ssize_t) image->rows))
547 {
548 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
549 canvas_image->columns,1,exception);
550 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
551 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000552 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000553 break;
554 for (x=0; x < (ssize_t) image->columns; x++)
555 {
cristyf27ee032011-09-29 17:51:41 +0000556 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000557 p+=GetPixelChannels(canvas_image);
558 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000559 }
560 if (SyncAuthenticPixels(image,exception) == MagickFalse)
561 break;
562 }
cristyb3f97ae2015-05-18 12:29:32 +0000563 pixels=(const unsigned char *) ReadBlobStream(image,length,
564 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000565 }
566 if (image->previous == (Image *) NULL)
567 {
cristy90dbac72010-08-22 15:08:40 +0000568 status=SetImageProgress(image,LoadImageTag,4,6);
569 if (status == MagickFalse)
570 break;
571 }
cristy17f11b02014-12-20 19:37:04 +0000572 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000573 {
574 for (y=0; y < (ssize_t) image->extract_info.height; y++)
575 {
cristy4c08aed2011-07-01 19:47:50 +0000576 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100577 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000578
cristy4c08aed2011-07-01 19:47:50 +0000579 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100580 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000581
582 register ssize_t
583 x;
584
585 if (count != (ssize_t) length)
586 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100587 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000588 ThrowFileException(exception,CorruptImageError,
589 "UnexpectedEndOfFile",image->filename);
590 break;
591 }
592 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
593 exception);
cristyacd2ed22011-08-30 01:44:23 +0000594 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000595 break;
596 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
597 quantum_info,AlphaQuantum,pixels,exception);
598 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
599 break;
600 if (((y-image->extract_info.y) >= 0) &&
601 ((y-image->extract_info.y) < (ssize_t) image->rows))
602 {
603 p=GetVirtualPixels(canvas_image,
604 canvas_image->extract_info.x,0,canvas_image->columns,1,
605 exception);
606 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
607 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000608 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000609 break;
610 for (x=0; x < (ssize_t) image->columns; x++)
611 {
cristyf27ee032011-09-29 17:51:41 +0000612 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000613 p+=GetPixelChannels(canvas_image);
614 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000615 }
616 if (SyncAuthenticPixels(image,exception) == MagickFalse)
617 break;
618 }
cristyb3f97ae2015-05-18 12:29:32 +0000619 pixels=(const unsigned char *) ReadBlobStream(image,length,
620 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000621 }
622 if (image->previous == (Image *) NULL)
623 {
624 status=SetImageProgress(image,LoadImageTag,5,6);
625 if (status == MagickFalse)
626 break;
627 }
628 }
629 if (image->previous == (Image *) NULL)
630 {
631 status=SetImageProgress(image,LoadImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +0000632 if (status == MagickFalse)
633 break;
634 }
635 break;
636 }
637 case PartitionInterlace:
638 {
639 /*
640 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
641 */
cristy90dbac72010-08-22 15:08:40 +0000642 AppendImageFormat("R",image->filename);
643 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
644 if (status == MagickFalse)
Dirk Lemstradede8402018-03-24 17:51:58 +0100645 break;
Cristyb2d24412018-03-09 19:41:19 -0500646 if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
Dirk Lemstradede8402018-03-24 17:51:58 +0100647 {
648 status=MagickFalse;
649 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
650 image->filename);
651 break;
652 }
cristy90dbac72010-08-22 15:08:40 +0000653 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
654 for (i=0; i < (ssize_t) scene; i++)
Dirk Lemstradede8402018-03-24 17:51:58 +0100655 {
cristy90dbac72010-08-22 15:08:40 +0000656 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000657 {
cristyb3f97ae2015-05-18 12:29:32 +0000658 pixels=(const unsigned char *) ReadBlobStream(image,length,
659 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000660 if (count != (ssize_t) length)
Dirk Lemstradede8402018-03-24 17:51:58 +0100661 break;
cristybd797f12015-01-24 20:42:32 +0000662 }
Dirk Lemstradede8402018-03-24 17:51:58 +0100663 if (count != (ssize_t) length)
664 break;
665 }
cristyb3f97ae2015-05-18 12:29:32 +0000666 pixels=(const unsigned char *) ReadBlobStream(image,length,
667 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000668 for (y=0; y < (ssize_t) image->extract_info.height; y++)
669 {
cristy4c08aed2011-07-01 19:47:50 +0000670 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100671 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000672
cristy4c08aed2011-07-01 19:47:50 +0000673 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100674 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000675
676 register ssize_t
677 x;
678
679 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000680 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100681 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000682 ThrowFileException(exception,CorruptImageError,
683 "UnexpectedEndOfFile",image->filename);
684 break;
685 }
686 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
687 exception);
cristyacd2ed22011-08-30 01:44:23 +0000688 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000689 break;
690 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
691 quantum_info,RedQuantum,pixels,exception);
692 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
693 break;
694 if (((y-image->extract_info.y) >= 0) &&
695 ((y-image->extract_info.y) < (ssize_t) image->rows))
696 {
697 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
698 canvas_image->columns,1,exception);
699 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
700 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000701 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000702 break;
703 for (x=0; x < (ssize_t) image->columns; x++)
704 {
cristy4c08aed2011-07-01 19:47:50 +0000705 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000706 p+=GetPixelChannels(canvas_image);
707 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000708 }
709 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000710 break;
711 }
cristyb3f97ae2015-05-18 12:29:32 +0000712 pixels=(const unsigned char *) ReadBlobStream(image,length,
713 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000714 }
715 if (image->previous == (Image *) NULL)
716 {
cristy90dbac72010-08-22 15:08:40 +0000717 status=SetImageProgress(image,LoadImageTag,1,5);
718 if (status == MagickFalse)
719 break;
720 }
721 (void) CloseBlob(image);
722 AppendImageFormat("G",image->filename);
723 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
724 if (status == MagickFalse)
Dirk Lemstradede8402018-03-24 17:51:58 +0100725 break;
cristy90dbac72010-08-22 15:08:40 +0000726 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
727 for (i=0; i < (ssize_t) scene; i++)
Dirk Lemstradede8402018-03-24 17:51:58 +0100728 {
cristy90dbac72010-08-22 15:08:40 +0000729 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000730 {
cristyb3f97ae2015-05-18 12:29:32 +0000731 pixels=(const unsigned char *) ReadBlobStream(image,length,
732 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000733 if (count != (ssize_t) length)
Dirk Lemstradede8402018-03-24 17:51:58 +0100734 break;
cristybd797f12015-01-24 20:42:32 +0000735 }
Dirk Lemstradede8402018-03-24 17:51:58 +0100736 if (count != (ssize_t) length)
737 break;
738 }
cristyb3f97ae2015-05-18 12:29:32 +0000739 pixels=(const unsigned char *) ReadBlobStream(image,length,
740 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000741 for (y=0; y < (ssize_t) image->extract_info.height; y++)
742 {
cristy4c08aed2011-07-01 19:47:50 +0000743 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100744 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000745
cristy4c08aed2011-07-01 19:47:50 +0000746 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100747 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000748
749 register ssize_t
750 x;
751
752 if (count != (ssize_t) length)
753 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100754 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000755 ThrowFileException(exception,CorruptImageError,
756 "UnexpectedEndOfFile",image->filename);
757 break;
758 }
759 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
760 exception);
cristyacd2ed22011-08-30 01:44:23 +0000761 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000762 break;
763 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
764 quantum_info,GreenQuantum,pixels,exception);
765 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
766 break;
767 if (((y-image->extract_info.y) >= 0) &&
768 ((y-image->extract_info.y) < (ssize_t) image->rows))
769 {
770 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
771 canvas_image->columns,1,exception);
772 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
773 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000774 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000775 break;
776 for (x=0; x < (ssize_t) image->columns; x++)
777 {
cristyf27ee032011-09-29 17:51:41 +0000778 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000779 p+=GetPixelChannels(canvas_image);
780 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000781 }
782 if (SyncAuthenticPixels(image,exception) == MagickFalse)
783 break;
784 }
cristyb3f97ae2015-05-18 12:29:32 +0000785 pixels=(const unsigned char *) ReadBlobStream(image,length,
786 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000787 }
788 if (image->previous == (Image *) NULL)
789 {
790 status=SetImageProgress(image,LoadImageTag,2,5);
791 if (status == MagickFalse)
792 break;
793 }
794 (void) CloseBlob(image);
795 AppendImageFormat("B",image->filename);
796 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
797 if (status == MagickFalse)
Dirk Lemstradede8402018-03-24 17:51:58 +0100798 break;
cristy90dbac72010-08-22 15:08:40 +0000799 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
800 for (i=0; i < (ssize_t) scene; i++)
Dirk Lemstradede8402018-03-24 17:51:58 +0100801 {
cristy90dbac72010-08-22 15:08:40 +0000802 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000803 {
cristyb3f97ae2015-05-18 12:29:32 +0000804 pixels=(const unsigned char *) ReadBlobStream(image,length,
805 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000806 if (count != (ssize_t) length)
Dirk Lemstradede8402018-03-24 17:51:58 +0100807 break;
808 }
809 if (count != (ssize_t) length)
810 break;
811 }
cristyb3f97ae2015-05-18 12:29:32 +0000812 pixels=(const unsigned char *) ReadBlobStream(image,length,
813 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000814 for (y=0; y < (ssize_t) image->extract_info.height; y++)
815 {
cristy4c08aed2011-07-01 19:47:50 +0000816 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100817 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000818
cristy4c08aed2011-07-01 19:47:50 +0000819 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100820 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000821
822 register ssize_t
823 x;
824
825 if (count != (ssize_t) length)
826 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100827 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000828 ThrowFileException(exception,CorruptImageError,
829 "UnexpectedEndOfFile",image->filename);
830 break;
831 }
832 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
833 exception);
cristyacd2ed22011-08-30 01:44:23 +0000834 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000835 break;
836 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
837 quantum_info,BlueQuantum,pixels,exception);
838 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
839 break;
840 if (((y-image->extract_info.y) >= 0) &&
841 ((y-image->extract_info.y) < (ssize_t) image->rows))
842 {
843 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
844 canvas_image->columns,1,exception);
845 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
846 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000847 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000848 break;
849 for (x=0; x < (ssize_t) image->columns; x++)
850 {
cristyf27ee032011-09-29 17:51:41 +0000851 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000852 p+=GetPixelChannels(canvas_image);
853 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000854 }
855 if (SyncAuthenticPixels(image,exception) == MagickFalse)
856 break;
857 }
cristyb3f97ae2015-05-18 12:29:32 +0000858 pixels=(const unsigned char *) ReadBlobStream(image,length,
859 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000860 }
861 if (image->previous == (Image *) NULL)
862 {
863 status=SetImageProgress(image,LoadImageTag,3,5);
864 if (status == MagickFalse)
865 break;
866 }
cristy17f11b02014-12-20 19:37:04 +0000867 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000868 {
869 (void) CloseBlob(image);
870 AppendImageFormat("A",image->filename);
871 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
872 if (status == MagickFalse)
Dirk Lemstradede8402018-03-24 17:51:58 +0100873 break;
cristy90dbac72010-08-22 15:08:40 +0000874 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
875 for (i=0; i < (ssize_t) scene; i++)
Dirk Lemstradede8402018-03-24 17:51:58 +0100876 {
cristy90dbac72010-08-22 15:08:40 +0000877 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000878 {
cristyb3f97ae2015-05-18 12:29:32 +0000879 pixels=(const unsigned char *) ReadBlobStream(image,length,
cristybd797f12015-01-24 20:42:32 +0000880 GetQuantumPixels(quantum_info),&count);
881 if (count != (ssize_t) length)
Dirk Lemstradede8402018-03-24 17:51:58 +0100882 break;
cristybd797f12015-01-24 20:42:32 +0000883 }
Dirk Lemstradede8402018-03-24 17:51:58 +0100884 if (count != (ssize_t) length)
885 break;
886 }
cristyb3f97ae2015-05-18 12:29:32 +0000887 pixels=(const unsigned char *) ReadBlobStream(image,length,
888 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000889 for (y=0; y < (ssize_t) image->extract_info.height; y++)
890 {
cristy4c08aed2011-07-01 19:47:50 +0000891 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100892 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +0000893
cristy4c08aed2011-07-01 19:47:50 +0000894 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100895 *magick_restrict q;
cristy90dbac72010-08-22 15:08:40 +0000896
897 register ssize_t
898 x;
899
900 if (count != (ssize_t) length)
901 {
Dirk Lemstradede8402018-03-24 17:51:58 +0100902 status=MagickFalse;
cristy90dbac72010-08-22 15:08:40 +0000903 ThrowFileException(exception,CorruptImageError,
904 "UnexpectedEndOfFile",image->filename);
905 break;
906 }
907 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
908 exception);
cristyacd2ed22011-08-30 01:44:23 +0000909 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000910 break;
911 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
912 quantum_info,BlueQuantum,pixels,exception);
913 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
914 break;
915 if (((y-image->extract_info.y) >= 0) &&
916 ((y-image->extract_info.y) < (ssize_t) image->rows))
917 {
918 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
919 0,canvas_image->columns,1,exception);
920 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
921 image->columns,1,exception);
cristyc6aebff2012-05-07 23:24:35 +0000922 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000923 break;
924 for (x=0; x < (ssize_t) image->columns; x++)
925 {
cristyf27ee032011-09-29 17:51:41 +0000926 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000927 p+=GetPixelChannels(canvas_image);
928 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000929 }
930 if (SyncAuthenticPixels(image,exception) == MagickFalse)
931 break;
932 }
cristyb3f97ae2015-05-18 12:29:32 +0000933 pixels=(const unsigned char *) ReadBlobStream(image,length,
934 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000935 }
936 if (image->previous == (Image *) NULL)
937 {
938 status=SetImageProgress(image,LoadImageTag,4,5);
939 if (status == MagickFalse)
940 break;
941 }
942 }
943 (void) CloseBlob(image);
944 if (image->previous == (Image *) NULL)
945 {
cristy3ed852e2009-09-05 21:47:34 +0000946 status=SetImageProgress(image,LoadImageTag,5,5);
947 if (status == MagickFalse)
948 break;
949 }
950 break;
951 }
952 }
Dirk Lemstradede8402018-03-24 17:51:58 +0100953 if (status == MagickFalse)
954 break;
cristy3ed852e2009-09-05 21:47:34 +0000955 SetQuantumImageType(image,quantum_type);
cristy3ed852e2009-09-05 21:47:34 +0000956 /*
957 Proceed to next image.
958 */
959 if (image_info->number_scenes != 0)
960 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
961 break;
962 if (count == (ssize_t) length)
963 {
964 /*
965 Allocate next image structure.
966 */
cristy9950d572011-10-01 18:22:35 +0000967 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000968 if (GetNextImageInList(image) == (Image *) NULL)
969 {
Cristy5ff0db92018-06-20 18:04:36 -0400970 status=MagickFalse;
971 break;
cristy3ed852e2009-09-05 21:47:34 +0000972 }
973 image=SyncNextImageInList(image);
974 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
975 GetBlobSize(image));
976 if (status == MagickFalse)
977 break;
978 }
979 scene++;
980 } while (count == (ssize_t) length);
cristy3ed852e2009-09-05 21:47:34 +0000981 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +0000982 canvas_image=DestroyImage(canvas_image);
983 (void) CloseBlob(image);
Dirk Lemstradede8402018-03-24 17:51:58 +0100984 if (status == MagickFalse)
Cristy3b48d202018-07-01 17:11:51 -0400985 return(DestroyImageList(image));
cristy3ed852e2009-09-05 21:47:34 +0000986 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
Cristyc45b2bb2018-04-07 12:32:12 -04001111 imageListLength,
cristyc6da28e2011-04-28 01:41:35 +00001112 length;
1113
cristy3ed852e2009-09-05 21:47:34 +00001114 ssize_t
cristy90dbac72010-08-22 15:08:40 +00001115 count,
1116 y;
cristy3ed852e2009-09-05 21:47:34 +00001117
cristy3ed852e2009-09-05 21:47:34 +00001118 unsigned char
1119 *pixels;
1120
cristy3ed852e2009-09-05 21:47:34 +00001121 /*
1122 Allocate memory for pixels.
1123 */
1124 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001125 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001126 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001127 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001128 if (image->debug != MagickFalse)
1129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1130 if (image_info->interlace != PartitionInterlace)
1131 {
1132 /*
1133 Open output image file.
1134 */
cristyedf03fa2011-08-30 12:44:39 +00001135 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001136 if (status == MagickFalse)
1137 return(status);
1138 }
1139 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +00001140 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristyc6aebff2012-05-07 23:24:35 +00001141 quantum_type=RGBAQuantum;
cristy90dbac72010-08-22 15:08:40 +00001142 if (LocaleCompare(image_info->magick,"RGBO") == 0)
cristyc6aebff2012-05-07 23:24:35 +00001143 quantum_type=RGBOQuantum;
cristy3ed852e2009-09-05 21:47:34 +00001144 scene=0;
Cristyc45b2bb2018-04-07 12:32:12 -04001145 imageListLength=GetImageListLength(image);
cristy3ed852e2009-09-05 21:47:34 +00001146 do
1147 {
1148 /*
1149 Convert MIFF to RGB raster pixels.
1150 */
cristyaf8d3912014-02-21 14:50:33 +00001151 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001152 if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
cristy17f11b02014-12-20 19:37:04 +00001153 (image->alpha_trait == UndefinedPixelTrait))
cristy3a37efd2011-08-28 20:31:03 +00001154 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy5f766ef2014-12-14 21:12:47 +00001155 quantum_info=AcquireQuantumInfo(image_info,image);
cristy3ed852e2009-09-05 21:47:34 +00001156 if (quantum_info == (QuantumInfo *) NULL)
1157 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
cristyb3f97ae2015-05-18 12:29:32 +00001158 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +00001159 switch (image_info->interlace)
1160 {
1161 case NoInterlace:
1162 default:
1163 {
cristy3ed852e2009-09-05 21:47:34 +00001164 /*
1165 No interlacing: RGBRGBRGBRGBRGBRGB...
1166 */
cristybb503372010-05-27 20:51:26 +00001167 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001168 {
cristy4c08aed2011-07-01 19:47:50 +00001169 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001170 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001171
cristy3a37efd2011-08-28 20:31:03 +00001172 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001173 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001174 break;
cristy4c08aed2011-07-01 19:47:50 +00001175 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001176 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001177 count=WriteBlob(image,length,pixels);
1178 if (count != (ssize_t) length)
1179 break;
1180 if (image->previous == (Image *) NULL)
1181 {
cristycee97112010-05-28 00:44:52 +00001182 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1183 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001184 if (status == MagickFalse)
1185 break;
1186 }
1187 }
cristy3ed852e2009-09-05 21:47:34 +00001188 break;
1189 }
1190 case LineInterlace:
1191 {
1192 /*
1193 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
1194 */
cristybb503372010-05-27 20:51:26 +00001195 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001196 {
cristy4c08aed2011-07-01 19:47:50 +00001197 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001198 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001199
cristy3a37efd2011-08-28 20:31:03 +00001200 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001201 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001202 break;
cristy4c08aed2011-07-01 19:47:50 +00001203 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001204 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001205 count=WriteBlob(image,length,pixels);
1206 if (count != (ssize_t) length)
1207 break;
cristy4c08aed2011-07-01 19:47:50 +00001208 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001209 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001210 count=WriteBlob(image,length,pixels);
1211 if (count != (ssize_t) length)
1212 break;
cristy4c08aed2011-07-01 19:47:50 +00001213 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001214 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001215 count=WriteBlob(image,length,pixels);
1216 if (count != (ssize_t) length)
1217 break;
1218 if (quantum_type == RGBAQuantum)
1219 {
cristy4c08aed2011-07-01 19:47:50 +00001220 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001221 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001222 count=WriteBlob(image,length,pixels);
1223 if (count != (ssize_t) length)
1224 break;
1225 }
1226 if (quantum_type == RGBOQuantum)
1227 {
cristy4c08aed2011-07-01 19:47:50 +00001228 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001229 OpacityQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001230 count=WriteBlob(image,length,pixels);
1231 if (count != (ssize_t) length)
1232 break;
1233 }
cristy3ed852e2009-09-05 21:47:34 +00001234 if (image->previous == (Image *) NULL)
1235 {
cristycee97112010-05-28 00:44:52 +00001236 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1237 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001238 if (status == MagickFalse)
1239 break;
1240 }
1241 }
1242 break;
1243 }
1244 case PlaneInterlace:
1245 {
1246 /*
1247 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
1248 */
cristy90dbac72010-08-22 15:08:40 +00001249 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001250 {
cristy4c08aed2011-07-01 19:47:50 +00001251 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001252 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001253
cristy3a37efd2011-08-28 20:31:03 +00001254 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001255 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001256 break;
cristy4c08aed2011-07-01 19:47:50 +00001257 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001258 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001259 count=WriteBlob(image,length,pixels);
1260 if (count != (ssize_t) length)
1261 break;
cristy3ed852e2009-09-05 21:47:34 +00001262 }
1263 if (image->previous == (Image *) NULL)
1264 {
cristy90dbac72010-08-22 15:08:40 +00001265 status=SetImageProgress(image,SaveImageTag,1,6);
1266 if (status == MagickFalse)
1267 break;
1268 }
1269 for (y=0; y < (ssize_t) image->rows; y++)
1270 {
cristy4c08aed2011-07-01 19:47:50 +00001271 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001272 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001273
cristy3a37efd2011-08-28 20:31:03 +00001274 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001275 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001276 break;
cristy4c08aed2011-07-01 19:47:50 +00001277 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001278 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001279 count=WriteBlob(image,length,pixels);
1280 if (count != (ssize_t) length)
1281 break;
1282 }
1283 if (image->previous == (Image *) NULL)
1284 {
1285 status=SetImageProgress(image,SaveImageTag,2,6);
1286 if (status == MagickFalse)
1287 break;
1288 }
1289 for (y=0; y < (ssize_t) image->rows; y++)
1290 {
cristy4c08aed2011-07-01 19:47:50 +00001291 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001292 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001293
cristy3a37efd2011-08-28 20:31:03 +00001294 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001295 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001296 break;
cristy4c08aed2011-07-01 19:47:50 +00001297 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001298 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001299 count=WriteBlob(image,length,pixels);
1300 if (count != (ssize_t) length)
1301 break;
1302 }
1303 if (image->previous == (Image *) NULL)
1304 {
1305 status=SetImageProgress(image,SaveImageTag,3,6);
1306 if (status == MagickFalse)
1307 break;
1308 }
1309 if (quantum_type == RGBAQuantum)
1310 {
1311 for (y=0; y < (ssize_t) image->rows; y++)
1312 {
cristy4c08aed2011-07-01 19:47:50 +00001313 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001314 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001315
cristy3a37efd2011-08-28 20:31:03 +00001316 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001317 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001318 break;
cristy4c08aed2011-07-01 19:47:50 +00001319 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001320 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001321 count=WriteBlob(image,length,pixels);
1322 if (count != (ssize_t) length)
1323 break;
1324 }
1325 if (image->previous == (Image *) NULL)
1326 {
1327 status=SetImageProgress(image,SaveImageTag,5,6);
1328 if (status == MagickFalse)
1329 break;
1330 }
1331 }
1332 if (image_info->interlace == PartitionInterlace)
1333 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00001334 MagickPathExtent);
cristy90dbac72010-08-22 15:08:40 +00001335 if (image->previous == (Image *) NULL)
1336 {
1337 status=SetImageProgress(image,SaveImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +00001338 if (status == MagickFalse)
1339 break;
1340 }
1341 break;
1342 }
1343 case PartitionInterlace:
1344 {
cristy3ed852e2009-09-05 21:47:34 +00001345 /*
1346 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
1347 */
cristy90dbac72010-08-22 15:08:40 +00001348 AppendImageFormat("R",image->filename);
1349 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001350 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001351 if (status == MagickFalse)
1352 return(status);
1353 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001354 {
cristy4c08aed2011-07-01 19:47:50 +00001355 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001356 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001357
cristy3a37efd2011-08-28 20:31:03 +00001358 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001359 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001360 break;
cristy4c08aed2011-07-01 19:47:50 +00001361 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001362 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001363 count=WriteBlob(image,length,pixels);
1364 if (count != (ssize_t) length)
1365 break;
1366 }
1367 if (image->previous == (Image *) NULL)
1368 {
1369 status=SetImageProgress(image,SaveImageTag,1,6);
1370 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001371 break;
1372 }
cristy90dbac72010-08-22 15:08:40 +00001373 (void) CloseBlob(image);
1374 AppendImageFormat("G",image->filename);
1375 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001376 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001377 if (status == MagickFalse)
1378 return(status);
1379 for (y=0; y < (ssize_t) image->rows; y++)
1380 {
cristy4c08aed2011-07-01 19:47:50 +00001381 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001382 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001383
cristy3a37efd2011-08-28 20:31:03 +00001384 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001385 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001386 break;
cristy4c08aed2011-07-01 19:47:50 +00001387 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001388 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001389 count=WriteBlob(image,length,pixels);
1390 if (count != (ssize_t) length)
1391 break;
1392 }
1393 if (image->previous == (Image *) NULL)
1394 {
1395 status=SetImageProgress(image,SaveImageTag,2,6);
1396 if (status == MagickFalse)
1397 break;
1398 }
1399 (void) CloseBlob(image);
1400 AppendImageFormat("B",image->filename);
1401 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001402 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001403 if (status == MagickFalse)
1404 return(status);
1405 for (y=0; y < (ssize_t) image->rows; y++)
1406 {
cristy4c08aed2011-07-01 19:47:50 +00001407 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001408 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001409
cristy3a37efd2011-08-28 20:31:03 +00001410 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001411 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001412 break;
cristy4c08aed2011-07-01 19:47:50 +00001413 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001414 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001415 count=WriteBlob(image,length,pixels);
1416 if (count != (ssize_t) length)
1417 break;
1418 }
1419 if (image->previous == (Image *) NULL)
1420 {
1421 status=SetImageProgress(image,SaveImageTag,3,6);
1422 if (status == MagickFalse)
1423 break;
1424 }
cristy90dbac72010-08-22 15:08:40 +00001425 if (quantum_type == RGBAQuantum)
1426 {
1427 (void) CloseBlob(image);
1428 AppendImageFormat("A",image->filename);
1429 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001430 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001431 if (status == MagickFalse)
1432 return(status);
1433 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001434 {
cristy4c08aed2011-07-01 19:47:50 +00001435 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001436 *magick_restrict p;
cristy90dbac72010-08-22 15:08:40 +00001437
cristy3a37efd2011-08-28 20:31:03 +00001438 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001439 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001440 break;
cristy4c08aed2011-07-01 19:47:50 +00001441 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001442 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001443 count=WriteBlob(image,length,pixels);
1444 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +00001445 break;
1446 }
cristy90dbac72010-08-22 15:08:40 +00001447 if (image->previous == (Image *) NULL)
1448 {
1449 status=SetImageProgress(image,SaveImageTag,5,6);
1450 if (status == MagickFalse)
1451 break;
1452 }
1453 }
1454 (void) CloseBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001455 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00001456 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001457 if (image->previous == (Image *) NULL)
1458 {
cristy90dbac72010-08-22 15:08:40 +00001459 status=SetImageProgress(image,SaveImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +00001460 if (status == MagickFalse)
1461 break;
1462 }
1463 break;
1464 }
1465 }
1466 quantum_info=DestroyQuantumInfo(quantum_info);
1467 if (GetNextImageInList(image) == (Image *) NULL)
1468 break;
1469 image=SyncNextImageInList(image);
Cristyc45b2bb2018-04-07 12:32:12 -04001470 status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength);
cristy3ed852e2009-09-05 21:47:34 +00001471 if (status == MagickFalse)
1472 break;
1473 } while (image_info->adjoin != MagickFalse);
1474 (void) CloseBlob(image);
1475 return(MagickTrue);
1476}