blob: 7941ab77898cc8e72274ca9ccb0a7ca370e364ed [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% RRRR GGGG BBBB %
7% R R G B B %
8% RRRR G GG BBBB %
9% R R G G B B %
10% R R GGG BBBB %
11% %
12% %
13% Read/Write Raw RGB Image Format %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/cache.h"
cristy6a2180c2013-05-27 10:28:36 +000046#include "MagickCore/channel.h"
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickCore/colorspace.h"
cristy510d06a2011-07-06 23:43:54 +000048#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000049#include "MagickCore/constitute.h"
50#include "MagickCore/exception.h"
51#include "MagickCore/exception-private.h"
52#include "MagickCore/image.h"
53#include "MagickCore/image-private.h"
54#include "MagickCore/list.h"
55#include "MagickCore/magick.h"
56#include "MagickCore/memory_.h"
57#include "MagickCore/monitor.h"
58#include "MagickCore/monitor-private.h"
59#include "MagickCore/pixel-accessor.h"
60#include "MagickCore/quantum-private.h"
61#include "MagickCore/static.h"
62#include "MagickCore/statistic.h"
63#include "MagickCore/string_.h"
64#include "MagickCore/module.h"
65#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68 Forward declarations.
69*/
70static MagickBooleanType
cristy3a37efd2011-08-28 20:31:03 +000071 WriteRGBImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000072
73/*
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75% %
76% %
77% %
78% R e a d R G B I m a g e %
79% %
80% %
81% %
82%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83%
cristy90dbac72010-08-22 15:08:40 +000084% ReadRGBImage() reads an image of raw RGB, RGBA, or RGBO samples and returns
85% it. It allocates the memory necessary for the new Image structure and
86% returns a pointer to the new image.
cristy3ed852e2009-09-05 21:47:34 +000087%
88% The format of the ReadRGBImage method is:
89%
cristy90dbac72010-08-22 15:08:40 +000090% Image *ReadRGBImage(const ImageInfo *image_info,
91% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000092%
93% A description of each parameter follows:
94%
95% o image_info: the image info.
96%
97% o exception: return any errors or warnings in this structure.
98%
99*/
cristyddacdd12012-05-07 23:08:14 +0000100static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000101{
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);
cristy387430f2012-02-07 13:09:46 +0000161 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
162 exception);
cristy5f766ef2014-12-14 21:12:47 +0000163 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
cristy3ed852e2009-09-05 21:47:34 +0000164 if (quantum_info == (QuantumInfo *) NULL)
165 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +0000166 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +0000167 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristya38675f2010-08-21 18:35:13 +0000168 {
cristy90dbac72010-08-22 15:08:40 +0000169 quantum_type=RGBAQuantum;
cristy8a46d822012-08-28 23:32:39 +0000170 image->alpha_trait=BlendPixelTrait;
171 canvas_image->alpha_trait=BlendPixelTrait;
cristya38675f2010-08-21 18:35:13 +0000172 }
cristy90dbac72010-08-22 15:08:40 +0000173 if (LocaleCompare(image_info->magick,"RGBO") == 0)
174 {
175 quantum_type=RGBOQuantum;
dirk7000aae2015-02-24 11:56:06 +0000176 image->alpha_trait=BlendPixelTrait;
cristy8a46d822012-08-28 23:32:39 +0000177 canvas_image->alpha_trait=BlendPixelTrait;
cristy90dbac72010-08-22 15:08:40 +0000178 }
cristyb3f97ae2015-05-18 12:29:32 +0000179 pixels=(const unsigned char *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000180 if (image_info->number_scenes != 0)
181 while (image->scene < image_info->scene)
182 {
183 /*
184 Skip to next image.
185 */
186 image->scene++;
187 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristybb503372010-05-27 20:51:26 +0000188 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000189 {
cristyb3f97ae2015-05-18 12:29:32 +0000190 pixels=(const unsigned char *) ReadBlobStream(image,length,
191 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000192 if (count != (ssize_t) length)
193 break;
194 }
195 }
cristy3ed852e2009-09-05 21:47:34 +0000196 count=0;
197 length=0;
198 scene=0;
199 do
200 {
201 /*
202 Read pixels to virtual canvas image then push to image.
203 */
204 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
205 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
206 break;
cristyacabb842014-12-14 23:36:33 +0000207 status=SetImageExtent(image,image->columns,image->rows,exception);
208 if (status == MagickFalse)
209 return(DestroyImageList(image));
cristy3ed852e2009-09-05 21:47:34 +0000210 switch (image_info->interlace)
211 {
212 case NoInterlace:
213 default:
214 {
215 /*
216 No interlacing: RGBRGBRGBRGBRGBRGB...
217 */
218 if (scene == 0)
219 {
220 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristyb3f97ae2015-05-18 12:29:32 +0000221 pixels=(const unsigned char *) ReadBlobStream(image,length,
222 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000223 }
cristybb503372010-05-27 20:51:26 +0000224 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000225 {
cristy4c08aed2011-07-01 19:47:50 +0000226 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000227 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000228
cristy4c08aed2011-07-01 19:47:50 +0000229 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000230 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000231
cristy90dbac72010-08-22 15:08:40 +0000232 register ssize_t
233 x;
234
cristy21da32d2009-09-12 14:56:09 +0000235 if (count != (ssize_t) length)
236 {
237 ThrowFileException(exception,CorruptImageError,
238 "UnexpectedEndOfFile",image->filename);
239 break;
240 }
cristy3ed852e2009-09-05 21:47:34 +0000241 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
242 exception);
cristyacd2ed22011-08-30 01:44:23 +0000243 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000244 break;
245 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
246 quantum_info,quantum_type,pixels,exception);
247 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
248 break;
cristy90dbac72010-08-22 15:08:40 +0000249 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000250 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000251 {
252 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
253 canvas_image->columns,1,exception);
254 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
255 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000256 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000257 break;
cristybb503372010-05-27 20:51:26 +0000258 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000259 {
cristy4c08aed2011-07-01 19:47:50 +0000260 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
261 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
262 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
263 SetPixelAlpha(image,OpaqueAlpha,q);
cristy17f11b02014-12-20 19:37:04 +0000264 if (image->alpha_trait != UndefinedPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000265 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000266 p+=GetPixelChannels(canvas_image);
267 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000268 }
269 if (SyncAuthenticPixels(image,exception) == MagickFalse)
270 break;
271 }
272 if (image->previous == (Image *) NULL)
273 {
cristycee97112010-05-28 00:44:52 +0000274 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
275 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000276 if (status == MagickFalse)
277 break;
278 }
cristyb3f97ae2015-05-18 12:29:32 +0000279 pixels=(const unsigned char *) ReadBlobStream(image,length,
280 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000281 }
282 break;
283 }
284 case LineInterlace:
285 {
cristy90dbac72010-08-22 15:08:40 +0000286 static QuantumType
287 quantum_types[4] =
288 {
289 RedQuantum,
290 GreenQuantum,
291 BlueQuantum,
292 AlphaQuantum
293 };
294
cristy3ed852e2009-09-05 21:47:34 +0000295 /*
296 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
297 */
cristy90dbac72010-08-22 15:08:40 +0000298 if (LocaleCompare(image_info->magick,"RGBO") == 0)
299 quantum_types[3]=OpacityQuantum;
cristy3ed852e2009-09-05 21:47:34 +0000300 if (scene == 0)
301 {
cristy90dbac72010-08-22 15:08:40 +0000302 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristyb3f97ae2015-05-18 12:29:32 +0000303 pixels=(const unsigned char *) ReadBlobStream(image,length,
304 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000305 }
cristybb503372010-05-27 20:51:26 +0000306 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000307 {
cristy4c08aed2011-07-01 19:47:50 +0000308 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000309 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000310
cristy4c08aed2011-07-01 19:47:50 +0000311 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000312 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000313
cristy90dbac72010-08-22 15:08:40 +0000314 register ssize_t
315 x;
316
cristy21da32d2009-09-12 14:56:09 +0000317 if (count != (ssize_t) length)
318 {
319 ThrowFileException(exception,CorruptImageError,
320 "UnexpectedEndOfFile",image->filename);
321 break;
322 }
cristy17f11b02014-12-20 19:37:04 +0000323 for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++)
cristy3ed852e2009-09-05 21:47:34 +0000324 {
cristy90dbac72010-08-22 15:08:40 +0000325 quantum_type=quantum_types[i];
cristy3ed852e2009-09-05 21:47:34 +0000326 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
327 exception);
cristyacd2ed22011-08-30 01:44:23 +0000328 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000329 break;
330 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
cristy90dbac72010-08-22 15:08:40 +0000331 quantum_info,quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000332 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
333 break;
cristy90dbac72010-08-22 15:08:40 +0000334 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000335 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000336 {
337 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
338 0,canvas_image->columns,1,exception);
339 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
340 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000341 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000342 break;
cristy90dbac72010-08-22 15:08:40 +0000343 for (x=0; x < (ssize_t) image->columns; x++)
344 {
345 switch (quantum_type)
cristy3ed852e2009-09-05 21:47:34 +0000346 {
cristy90dbac72010-08-22 15:08:40 +0000347 case RedQuantum:
348 {
cristy4c08aed2011-07-01 19:47:50 +0000349 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000350 break;
351 }
352 case GreenQuantum:
353 {
cristy4c08aed2011-07-01 19:47:50 +0000354 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000355 break;
356 }
357 case BlueQuantum:
358 {
cristy4c08aed2011-07-01 19:47:50 +0000359 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000360 break;
361 }
362 case OpacityQuantum:
363 {
cristy4c08aed2011-07-01 19:47:50 +0000364 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000365 break;
366 }
367 case AlphaQuantum:
368 {
cristy4c08aed2011-07-01 19:47:50 +0000369 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristy90dbac72010-08-22 15:08:40 +0000370 break;
371 }
372 default:
373 break;
cristy3ed852e2009-09-05 21:47:34 +0000374 }
cristyed231572011-07-14 02:18:59 +0000375 p+=GetPixelChannels(canvas_image);
376 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000377 }
cristy3ed852e2009-09-05 21:47:34 +0000378 if (SyncAuthenticPixels(image,exception) == MagickFalse)
379 break;
380 }
cristyb3f97ae2015-05-18 12:29:32 +0000381 pixels=(const unsigned char *) ReadBlobStream(image,length,
382 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000383 }
384 if (image->previous == (Image *) NULL)
385 {
cristycee97112010-05-28 00:44:52 +0000386 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
387 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000388 if (status == MagickFalse)
389 break;
390 }
391 }
392 break;
393 }
394 case PlaneInterlace:
395 {
396 /*
397 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
398 */
399 if (scene == 0)
400 {
cristy90dbac72010-08-22 15:08:40 +0000401 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
cristyb3f97ae2015-05-18 12:29:32 +0000402 pixels=(const unsigned char *) ReadBlobStream(image,length,
403 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000404 }
cristy90dbac72010-08-22 15:08:40 +0000405 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000406 {
cristy4c08aed2011-07-01 19:47:50 +0000407 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000408 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000409
cristy4c08aed2011-07-01 19:47:50 +0000410 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000411 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000412
cristy90dbac72010-08-22 15:08:40 +0000413 register ssize_t
414 x;
cristy3ed852e2009-09-05 21:47:34 +0000415
cristy90dbac72010-08-22 15:08:40 +0000416 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000417 {
cristy90dbac72010-08-22 15:08:40 +0000418 ThrowFileException(exception,CorruptImageError,
419 "UnexpectedEndOfFile",image->filename);
420 break;
421 }
422 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
423 exception);
cristyacd2ed22011-08-30 01:44:23 +0000424 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000425 break;
426 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
427 quantum_info,RedQuantum,pixels,exception);
428 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
429 break;
430 if (((y-image->extract_info.y) >= 0) &&
431 ((y-image->extract_info.y) < (ssize_t) image->rows))
432 {
433 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
434 canvas_image->columns,1,exception);
435 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
436 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000437 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000438 break;
439 for (x=0; x < (ssize_t) image->columns; x++)
440 {
cristy4c08aed2011-07-01 19:47:50 +0000441 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000442 p+=GetPixelChannels(canvas_image);
443 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000444 }
445 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000446 break;
447 }
cristyb3f97ae2015-05-18 12:29:32 +0000448 pixels=(const unsigned char *) ReadBlobStream(image,length,
449 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000450 }
451 if (image->previous == (Image *) NULL)
452 {
cristy90dbac72010-08-22 15:08:40 +0000453 status=SetImageProgress(image,LoadImageTag,1,6);
454 if (status == MagickFalse)
455 break;
456 }
457 for (y=0; y < (ssize_t) image->extract_info.height; y++)
458 {
cristy4c08aed2011-07-01 19:47:50 +0000459 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000460 *restrict p;
461
cristy4c08aed2011-07-01 19:47:50 +0000462 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000463 *restrict q;
464
465 register ssize_t
466 x;
467
468 if (count != (ssize_t) length)
469 {
470 ThrowFileException(exception,CorruptImageError,
471 "UnexpectedEndOfFile",image->filename);
472 break;
473 }
474 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
475 exception);
cristyacd2ed22011-08-30 01:44:23 +0000476 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000477 break;
478 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
479 quantum_info,GreenQuantum,pixels,exception);
480 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
481 break;
482 if (((y-image->extract_info.y) >= 0) &&
483 ((y-image->extract_info.y) < (ssize_t) image->rows))
484 {
485 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
486 canvas_image->columns,1,exception);
487 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
488 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000489 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000490 break;
491 for (x=0; x < (ssize_t) image->columns; x++)
492 {
cristyf27ee032011-09-29 17:51:41 +0000493 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000494 p+=GetPixelChannels(canvas_image);
495 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000496 }
497 if (SyncAuthenticPixels(image,exception) == MagickFalse)
498 break;
499 }
cristyb3f97ae2015-05-18 12:29:32 +0000500 pixels=(const unsigned char *) ReadBlobStream(image,length,
501 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000502 }
503 if (image->previous == (Image *) NULL)
504 {
505 status=SetImageProgress(image,LoadImageTag,2,6);
506 if (status == MagickFalse)
507 break;
508 }
509 for (y=0; y < (ssize_t) image->extract_info.height; y++)
510 {
cristy4c08aed2011-07-01 19:47:50 +0000511 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000512 *restrict p;
513
cristy4c08aed2011-07-01 19:47:50 +0000514 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000515 *restrict q;
516
517 register ssize_t
518 x;
519
520 if (count != (ssize_t) length)
521 {
522 ThrowFileException(exception,CorruptImageError,
523 "UnexpectedEndOfFile",image->filename);
524 break;
525 }
526 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
527 exception);
cristyacd2ed22011-08-30 01:44:23 +0000528 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000529 break;
530 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
531 quantum_info,BlueQuantum,pixels,exception);
532 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
533 break;
534 if (((y-image->extract_info.y) >= 0) &&
535 ((y-image->extract_info.y) < (ssize_t) image->rows))
536 {
537 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
538 canvas_image->columns,1,exception);
539 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
540 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000541 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000542 break;
543 for (x=0; x < (ssize_t) image->columns; x++)
544 {
cristyf27ee032011-09-29 17:51:41 +0000545 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000546 p+=GetPixelChannels(canvas_image);
547 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000548 }
549 if (SyncAuthenticPixels(image,exception) == MagickFalse)
550 break;
551 }
cristyb3f97ae2015-05-18 12:29:32 +0000552 pixels=(const unsigned char *) ReadBlobStream(image,length,
553 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000554 }
555 if (image->previous == (Image *) NULL)
556 {
557 status=SetImageProgress(image,LoadImageTag,3,6);
558 if (status == MagickFalse)
559 break;
560 }
561 if (image->previous == (Image *) NULL)
562 {
563 status=SetImageProgress(image,LoadImageTag,4,6);
564 if (status == MagickFalse)
565 break;
566 }
cristy17f11b02014-12-20 19:37:04 +0000567 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000568 {
569 for (y=0; y < (ssize_t) image->extract_info.height; y++)
570 {
cristy4c08aed2011-07-01 19:47:50 +0000571 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000572 *restrict p;
573
cristy4c08aed2011-07-01 19:47:50 +0000574 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000575 *restrict q;
576
577 register ssize_t
578 x;
579
580 if (count != (ssize_t) length)
581 {
582 ThrowFileException(exception,CorruptImageError,
583 "UnexpectedEndOfFile",image->filename);
584 break;
585 }
586 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
587 exception);
cristyacd2ed22011-08-30 01:44:23 +0000588 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000589 break;
590 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
591 quantum_info,AlphaQuantum,pixels,exception);
592 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
593 break;
594 if (((y-image->extract_info.y) >= 0) &&
595 ((y-image->extract_info.y) < (ssize_t) image->rows))
596 {
597 p=GetVirtualPixels(canvas_image,
598 canvas_image->extract_info.x,0,canvas_image->columns,1,
599 exception);
600 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
601 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000602 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000603 break;
604 for (x=0; x < (ssize_t) image->columns; x++)
605 {
cristyf27ee032011-09-29 17:51:41 +0000606 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000607 p+=GetPixelChannels(canvas_image);
608 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000609 }
610 if (SyncAuthenticPixels(image,exception) == MagickFalse)
611 break;
612 }
cristyb3f97ae2015-05-18 12:29:32 +0000613 pixels=(const unsigned char *) ReadBlobStream(image,length,
614 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000615 }
616 if (image->previous == (Image *) NULL)
617 {
618 status=SetImageProgress(image,LoadImageTag,5,6);
619 if (status == MagickFalse)
620 break;
621 }
622 }
623 if (image->previous == (Image *) NULL)
624 {
625 status=SetImageProgress(image,LoadImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +0000626 if (status == MagickFalse)
627 break;
628 }
629 break;
630 }
631 case PartitionInterlace:
632 {
633 /*
634 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
635 */
cristy90dbac72010-08-22 15:08:40 +0000636 AppendImageFormat("R",image->filename);
637 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
638 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000639 {
cristy90dbac72010-08-22 15:08:40 +0000640 canvas_image=DestroyImageList(canvas_image);
641 image=DestroyImageList(image);
642 return((Image *) NULL);
643 }
cristyd4297022010-09-16 22:59:09 +0000644 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
645 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
646 image->filename);
cristy90dbac72010-08-22 15:08:40 +0000647 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
648 for (i=0; i < (ssize_t) scene; i++)
649 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000650 {
cristyb3f97ae2015-05-18 12:29:32 +0000651 pixels=(const unsigned char *) ReadBlobStream(image,length,
652 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000653 if (count != (ssize_t) length)
cristy21da32d2009-09-12 14:56:09 +0000654 {
655 ThrowFileException(exception,CorruptImageError,
656 "UnexpectedEndOfFile",image->filename);
657 break;
658 }
cristybd797f12015-01-24 20:42:32 +0000659 }
cristyb3f97ae2015-05-18 12:29:32 +0000660 pixels=(const unsigned char *) ReadBlobStream(image,length,
661 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000662 for (y=0; y < (ssize_t) image->extract_info.height; y++)
663 {
cristy4c08aed2011-07-01 19:47:50 +0000664 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000665 *restrict p;
666
cristy4c08aed2011-07-01 19:47:50 +0000667 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000668 *restrict q;
669
670 register ssize_t
671 x;
672
673 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000674 {
cristy90dbac72010-08-22 15:08:40 +0000675 ThrowFileException(exception,CorruptImageError,
676 "UnexpectedEndOfFile",image->filename);
677 break;
678 }
679 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
680 exception);
cristyacd2ed22011-08-30 01:44:23 +0000681 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000682 break;
683 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
684 quantum_info,RedQuantum,pixels,exception);
685 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
686 break;
687 if (((y-image->extract_info.y) >= 0) &&
688 ((y-image->extract_info.y) < (ssize_t) image->rows))
689 {
690 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
691 canvas_image->columns,1,exception);
692 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
693 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000694 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000695 break;
696 for (x=0; x < (ssize_t) image->columns; x++)
697 {
cristy4c08aed2011-07-01 19:47:50 +0000698 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000699 p+=GetPixelChannels(canvas_image);
700 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000701 }
702 if (SyncAuthenticPixels(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000703 break;
704 }
cristyb3f97ae2015-05-18 12:29:32 +0000705 pixels=(const unsigned char *) ReadBlobStream(image,length,
706 GetQuantumPixels(quantum_info),&count);
cristy3ed852e2009-09-05 21:47:34 +0000707 }
708 if (image->previous == (Image *) NULL)
709 {
cristy90dbac72010-08-22 15:08:40 +0000710 status=SetImageProgress(image,LoadImageTag,1,5);
711 if (status == MagickFalse)
712 break;
713 }
714 (void) CloseBlob(image);
715 AppendImageFormat("G",image->filename);
716 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
717 if (status == MagickFalse)
718 {
719 canvas_image=DestroyImageList(canvas_image);
720 image=DestroyImageList(image);
721 return((Image *) NULL);
722 }
723 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
724 for (i=0; i < (ssize_t) scene; i++)
725 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000726 {
cristyb3f97ae2015-05-18 12:29:32 +0000727 pixels=(const unsigned char *) ReadBlobStream(image,length,
728 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000729 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000730 {
731 ThrowFileException(exception,CorruptImageError,
732 "UnexpectedEndOfFile",image->filename);
733 break;
734 }
cristybd797f12015-01-24 20:42:32 +0000735 }
cristyb3f97ae2015-05-18 12:29:32 +0000736 pixels=(const unsigned char *) ReadBlobStream(image,length,
737 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000738 for (y=0; y < (ssize_t) image->extract_info.height; y++)
739 {
cristy4c08aed2011-07-01 19:47:50 +0000740 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000741 *restrict p;
742
cristy4c08aed2011-07-01 19:47:50 +0000743 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000744 *restrict q;
745
746 register ssize_t
747 x;
748
749 if (count != (ssize_t) length)
750 {
751 ThrowFileException(exception,CorruptImageError,
752 "UnexpectedEndOfFile",image->filename);
753 break;
754 }
755 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
756 exception);
cristyacd2ed22011-08-30 01:44:23 +0000757 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000758 break;
759 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
760 quantum_info,GreenQuantum,pixels,exception);
761 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
762 break;
763 if (((y-image->extract_info.y) >= 0) &&
764 ((y-image->extract_info.y) < (ssize_t) image->rows))
765 {
766 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
767 canvas_image->columns,1,exception);
768 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
769 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000770 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000771 break;
772 for (x=0; x < (ssize_t) image->columns; x++)
773 {
cristyf27ee032011-09-29 17:51:41 +0000774 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000775 p+=GetPixelChannels(canvas_image);
776 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000777 }
778 if (SyncAuthenticPixels(image,exception) == MagickFalse)
779 break;
780 }
cristyb3f97ae2015-05-18 12:29:32 +0000781 pixels=(const unsigned char *) ReadBlobStream(image,length,
782 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000783 }
784 if (image->previous == (Image *) NULL)
785 {
786 status=SetImageProgress(image,LoadImageTag,2,5);
787 if (status == MagickFalse)
788 break;
789 }
790 (void) CloseBlob(image);
791 AppendImageFormat("B",image->filename);
792 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
793 if (status == MagickFalse)
794 {
795 canvas_image=DestroyImageList(canvas_image);
796 image=DestroyImageList(image);
797 return((Image *) NULL);
798 }
799 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
800 for (i=0; i < (ssize_t) scene; i++)
801 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000802 {
cristyb3f97ae2015-05-18 12:29:32 +0000803 pixels=(const unsigned char *) ReadBlobStream(image,length,
804 GetQuantumPixels(quantum_info),&count);
cristybd797f12015-01-24 20:42:32 +0000805 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000806 {
807 ThrowFileException(exception,CorruptImageError,
808 "UnexpectedEndOfFile",image->filename);
809 break;
810 }
cristybd797f12015-01-24 20:42:32 +0000811 }
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
cristy90dbac72010-08-22 15:08:40 +0000817 *restrict p;
818
cristy4c08aed2011-07-01 19:47:50 +0000819 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000820 *restrict q;
821
822 register ssize_t
823 x;
824
825 if (count != (ssize_t) length)
826 {
827 ThrowFileException(exception,CorruptImageError,
828 "UnexpectedEndOfFile",image->filename);
829 break;
830 }
831 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
832 exception);
cristyacd2ed22011-08-30 01:44:23 +0000833 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000834 break;
835 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
836 quantum_info,BlueQuantum,pixels,exception);
837 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
838 break;
839 if (((y-image->extract_info.y) >= 0) &&
840 ((y-image->extract_info.y) < (ssize_t) image->rows))
841 {
842 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
843 canvas_image->columns,1,exception);
844 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
845 image->columns,1,exception);
cristyddacdd12012-05-07 23:08:14 +0000846 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000847 break;
848 for (x=0; x < (ssize_t) image->columns; x++)
849 {
cristyf27ee032011-09-29 17:51:41 +0000850 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000851 p+=GetPixelChannels(canvas_image);
852 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000853 }
854 if (SyncAuthenticPixels(image,exception) == MagickFalse)
855 break;
856 }
cristyb3f97ae2015-05-18 12:29:32 +0000857 pixels=(const unsigned char *) ReadBlobStream(image,length,
858 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000859 }
860 if (image->previous == (Image *) NULL)
861 {
862 status=SetImageProgress(image,LoadImageTag,3,5);
863 if (status == MagickFalse)
864 break;
865 }
cristy17f11b02014-12-20 19:37:04 +0000866 if (image->alpha_trait != UndefinedPixelTrait)
cristy90dbac72010-08-22 15:08:40 +0000867 {
868 (void) CloseBlob(image);
869 AppendImageFormat("A",image->filename);
870 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
871 if (status == MagickFalse)
872 {
873 canvas_image=DestroyImageList(canvas_image);
874 image=DestroyImageList(image);
875 return((Image *) NULL);
876 }
877 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
878 for (i=0; i < (ssize_t) scene; i++)
879 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristybd797f12015-01-24 20:42:32 +0000880 {
cristyb3f97ae2015-05-18 12:29:32 +0000881 pixels=(const unsigned char *) ReadBlobStream(image,length,
cristybd797f12015-01-24 20:42:32 +0000882 GetQuantumPixels(quantum_info),&count);
883 if (count != (ssize_t) length)
cristy90dbac72010-08-22 15:08:40 +0000884 {
885 ThrowFileException(exception,CorruptImageError,
886 "UnexpectedEndOfFile",image->filename);
887 break;
888 }
cristybd797f12015-01-24 20:42:32 +0000889 }
cristyb3f97ae2015-05-18 12:29:32 +0000890 pixels=(const unsigned char *) ReadBlobStream(image,length,
891 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000892 for (y=0; y < (ssize_t) image->extract_info.height; y++)
893 {
cristy4c08aed2011-07-01 19:47:50 +0000894 register const Quantum
cristy90dbac72010-08-22 15:08:40 +0000895 *restrict p;
896
cristy4c08aed2011-07-01 19:47:50 +0000897 register Quantum
cristy90dbac72010-08-22 15:08:40 +0000898 *restrict q;
899
900 register ssize_t
901 x;
902
903 if (count != (ssize_t) length)
904 {
905 ThrowFileException(exception,CorruptImageError,
906 "UnexpectedEndOfFile",image->filename);
907 break;
908 }
909 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
910 exception);
cristyacd2ed22011-08-30 01:44:23 +0000911 if (q == (Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +0000912 break;
913 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
914 quantum_info,BlueQuantum,pixels,exception);
915 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
916 break;
917 if (((y-image->extract_info.y) >= 0) &&
918 ((y-image->extract_info.y) < (ssize_t) image->rows))
919 {
920 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
921 0,canvas_image->columns,1,exception);
922 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
923 image->columns,1,exception);
cristyc6aebff2012-05-07 23:24:35 +0000924 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy90dbac72010-08-22 15:08:40 +0000925 break;
926 for (x=0; x < (ssize_t) image->columns; x++)
927 {
cristyf27ee032011-09-29 17:51:41 +0000928 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000929 p+=GetPixelChannels(canvas_image);
930 q+=GetPixelChannels(image);
cristy90dbac72010-08-22 15:08:40 +0000931 }
932 if (SyncAuthenticPixels(image,exception) == MagickFalse)
933 break;
934 }
cristyb3f97ae2015-05-18 12:29:32 +0000935 pixels=(const unsigned char *) ReadBlobStream(image,length,
936 GetQuantumPixels(quantum_info),&count);
cristy90dbac72010-08-22 15:08:40 +0000937 }
938 if (image->previous == (Image *) NULL)
939 {
940 status=SetImageProgress(image,LoadImageTag,4,5);
941 if (status == MagickFalse)
942 break;
943 }
944 }
945 (void) CloseBlob(image);
946 if (image->previous == (Image *) NULL)
947 {
cristy3ed852e2009-09-05 21:47:34 +0000948 status=SetImageProgress(image,LoadImageTag,5,5);
949 if (status == MagickFalse)
950 break;
951 }
952 break;
953 }
954 }
955 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 {
970 image=DestroyImageList(image);
971 return((Image *) NULL);
972 }
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);
984 return(GetFirstImageInList(image));
985}
986
987/*
988%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989% %
990% %
991% %
992% R e g i s t e r R G B I m a g e %
993% %
994% %
995% %
996%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997%
cristy90dbac72010-08-22 15:08:40 +0000998% RegisterRGBImage() adds attributes for the RGB image format to
cristy3ed852e2009-09-05 21:47:34 +0000999% the list of supported formats. The attributes include the image format
1000% tag, a method to read and/or write the format, whether the format
1001% supports the saving of more than one frame to the same file or blob,
1002% whether the format supports native in-memory I/O, and a brief
1003% description of the format.
1004%
1005% The format of the RegisterRGBImage method is:
1006%
cristybb503372010-05-27 20:51:26 +00001007% size_t RegisterRGBImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001008%
1009*/
cristybb503372010-05-27 20:51:26 +00001010ModuleExport size_t RegisterRGBImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001011{
1012 MagickInfo
1013 *entry;
1014
dirk06b627a2015-04-06 18:59:17 +00001015 entry=AcquireMagickInfo("RGB","RGB",
1016 "Raw red, green, and blue samples");
cristy3ed852e2009-09-05 21:47:34 +00001017 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1018 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001019 entry->flags|=CoderRawSupportFlag;
1020 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001021 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +00001022 entry=AcquireMagickInfo("RGB","RGBA",
1023 "Raw red, green, blue, and alpha samples");
cristy3ed852e2009-09-05 21:47:34 +00001024 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1025 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001026 entry->flags|=CoderRawSupportFlag;
1027 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001028 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +00001029 entry=AcquireMagickInfo("RGB","RGBO",
1030 "Raw red, green, blue, and opacity samples");
cristy3ed852e2009-09-05 21:47:34 +00001031 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1032 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
dirk08e9a112015-02-22 01:51:41 +00001033 entry->flags|=CoderRawSupportFlag;
1034 entry->flags|=CoderEndianSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +00001035 (void) RegisterMagickInfo(entry);
1036 return(MagickImageCoderSignature);
1037}
1038
1039/*
1040%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041% %
1042% %
1043% %
1044% U n r e g i s t e r R G B I m a g e %
1045% %
1046% %
1047% %
1048%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049%
cristy90dbac72010-08-22 15:08:40 +00001050% UnregisterRGBImage() removes format registrations made by the RGB module
1051% from the list of supported formats.
cristy3ed852e2009-09-05 21:47:34 +00001052%
1053% The format of the UnregisterRGBImage method is:
1054%
1055% UnregisterRGBImage(void)
1056%
1057*/
1058ModuleExport void UnregisterRGBImage(void)
1059{
1060 (void) UnregisterMagickInfo("RGBO");
1061 (void) UnregisterMagickInfo("RGBA");
cristy3ed852e2009-09-05 21:47:34 +00001062 (void) UnregisterMagickInfo("RGB");
1063}
1064
1065/*
1066%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1067% %
1068% %
1069% %
1070% W r i t e R G B I m a g e %
1071% %
1072% %
1073% %
1074%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1075%
cristy90dbac72010-08-22 15:08:40 +00001076% WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO
1077% rasterfile format.
cristy3ed852e2009-09-05 21:47:34 +00001078%
1079% The format of the WriteRGBImage method is:
1080%
cristy90dbac72010-08-22 15:08:40 +00001081% MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
cristy3a37efd2011-08-28 20:31:03 +00001082% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001083%
1084% A description of each parameter follows.
1085%
1086% o image_info: the image info.
1087%
1088% o image: The image.
1089%
cristy3a37efd2011-08-28 20:31:03 +00001090% o exception: return any errors or warnings in this structure.
1091%
cristy3ed852e2009-09-05 21:47:34 +00001092*/
cristyc6aebff2012-05-07 23:24:35 +00001093static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1094 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001095{
cristy3ed852e2009-09-05 21:47:34 +00001096 MagickBooleanType
1097 status;
1098
1099 MagickOffsetType
1100 scene;
1101
1102 QuantumInfo
1103 *quantum_info;
1104
1105 QuantumType
cristy90dbac72010-08-22 15:08:40 +00001106 quantum_type;
cristy3ed852e2009-09-05 21:47:34 +00001107
cristyc6da28e2011-04-28 01:41:35 +00001108 size_t
1109 length;
1110
cristy3ed852e2009-09-05 21:47:34 +00001111 ssize_t
cristy90dbac72010-08-22 15:08:40 +00001112 count,
1113 y;
cristy3ed852e2009-09-05 21:47:34 +00001114
cristy3ed852e2009-09-05 21:47:34 +00001115 unsigned char
1116 *pixels;
1117
cristy3ed852e2009-09-05 21:47:34 +00001118 /*
1119 Allocate memory for pixels.
1120 */
1121 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001122 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001123 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001124 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001125 if (image->debug != MagickFalse)
1126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1127 if (image_info->interlace != PartitionInterlace)
1128 {
1129 /*
1130 Open output image file.
1131 */
cristyedf03fa2011-08-30 12:44:39 +00001132 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001133 if (status == MagickFalse)
1134 return(status);
1135 }
1136 quantum_type=RGBQuantum;
cristy90dbac72010-08-22 15:08:40 +00001137 if (LocaleCompare(image_info->magick,"RGBA") == 0)
cristyc6aebff2012-05-07 23:24:35 +00001138 quantum_type=RGBAQuantum;
cristy90dbac72010-08-22 15:08:40 +00001139 if (LocaleCompare(image_info->magick,"RGBO") == 0)
cristyc6aebff2012-05-07 23:24:35 +00001140 quantum_type=RGBOQuantum;
cristy3ed852e2009-09-05 21:47:34 +00001141 scene=0;
1142 do
1143 {
1144 /*
1145 Convert MIFF to RGB raster pixels.
1146 */
cristyaf8d3912014-02-21 14:50:33 +00001147 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00001148 if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
cristy17f11b02014-12-20 19:37:04 +00001149 (image->alpha_trait == UndefinedPixelTrait))
cristy3a37efd2011-08-28 20:31:03 +00001150 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy5f766ef2014-12-14 21:12:47 +00001151 quantum_info=AcquireQuantumInfo(image_info,image);
cristy3ed852e2009-09-05 21:47:34 +00001152 if (quantum_info == (QuantumInfo *) NULL)
1153 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
cristyb3f97ae2015-05-18 12:29:32 +00001154 pixels=(unsigned char *) GetQuantumPixels(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +00001155 switch (image_info->interlace)
1156 {
1157 case NoInterlace:
1158 default:
1159 {
cristy3ed852e2009-09-05 21:47:34 +00001160 /*
1161 No interlacing: RGBRGBRGBRGBRGBRGB...
1162 */
cristybb503372010-05-27 20:51:26 +00001163 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001164 {
cristy4c08aed2011-07-01 19:47:50 +00001165 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001166 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001167
cristy3a37efd2011-08-28 20:31:03 +00001168 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001169 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001170 break;
cristy4c08aed2011-07-01 19:47:50 +00001171 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001172 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001173 count=WriteBlob(image,length,pixels);
1174 if (count != (ssize_t) length)
1175 break;
1176 if (image->previous == (Image *) NULL)
1177 {
cristycee97112010-05-28 00:44:52 +00001178 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1179 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001180 if (status == MagickFalse)
1181 break;
1182 }
1183 }
cristy3ed852e2009-09-05 21:47:34 +00001184 break;
1185 }
1186 case LineInterlace:
1187 {
1188 /*
1189 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
1190 */
cristybb503372010-05-27 20:51:26 +00001191 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001192 {
cristy4c08aed2011-07-01 19:47:50 +00001193 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001194 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001195
cristy3a37efd2011-08-28 20:31:03 +00001196 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001197 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001198 break;
cristy4c08aed2011-07-01 19:47:50 +00001199 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001200 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001201 count=WriteBlob(image,length,pixels);
1202 if (count != (ssize_t) length)
1203 break;
cristy4c08aed2011-07-01 19:47:50 +00001204 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001205 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001206 count=WriteBlob(image,length,pixels);
1207 if (count != (ssize_t) length)
1208 break;
cristy4c08aed2011-07-01 19:47:50 +00001209 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001210 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001211 count=WriteBlob(image,length,pixels);
1212 if (count != (ssize_t) length)
1213 break;
1214 if (quantum_type == RGBAQuantum)
1215 {
cristy4c08aed2011-07-01 19:47:50 +00001216 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001217 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001218 count=WriteBlob(image,length,pixels);
1219 if (count != (ssize_t) length)
1220 break;
1221 }
1222 if (quantum_type == RGBOQuantum)
1223 {
cristy4c08aed2011-07-01 19:47:50 +00001224 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001225 OpacityQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001226 count=WriteBlob(image,length,pixels);
1227 if (count != (ssize_t) length)
1228 break;
1229 }
cristy3ed852e2009-09-05 21:47:34 +00001230 if (image->previous == (Image *) NULL)
1231 {
cristycee97112010-05-28 00:44:52 +00001232 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1233 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001234 if (status == MagickFalse)
1235 break;
1236 }
1237 }
1238 break;
1239 }
1240 case PlaneInterlace:
1241 {
1242 /*
1243 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
1244 */
cristy90dbac72010-08-22 15:08:40 +00001245 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001246 {
cristy4c08aed2011-07-01 19:47:50 +00001247 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001248 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001249
cristy3a37efd2011-08-28 20:31:03 +00001250 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001251 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001252 break;
cristy4c08aed2011-07-01 19:47:50 +00001253 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001254 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001255 count=WriteBlob(image,length,pixels);
1256 if (count != (ssize_t) length)
1257 break;
cristy3ed852e2009-09-05 21:47:34 +00001258 }
1259 if (image->previous == (Image *) NULL)
1260 {
cristy90dbac72010-08-22 15:08:40 +00001261 status=SetImageProgress(image,SaveImageTag,1,6);
1262 if (status == MagickFalse)
1263 break;
1264 }
1265 for (y=0; y < (ssize_t) image->rows; y++)
1266 {
cristy4c08aed2011-07-01 19:47:50 +00001267 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001268 *restrict p;
1269
cristy3a37efd2011-08-28 20:31:03 +00001270 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001271 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001272 break;
cristy4c08aed2011-07-01 19:47:50 +00001273 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001274 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001275 count=WriteBlob(image,length,pixels);
1276 if (count != (ssize_t) length)
1277 break;
1278 }
1279 if (image->previous == (Image *) NULL)
1280 {
1281 status=SetImageProgress(image,SaveImageTag,2,6);
1282 if (status == MagickFalse)
1283 break;
1284 }
1285 for (y=0; y < (ssize_t) image->rows; y++)
1286 {
cristy4c08aed2011-07-01 19:47:50 +00001287 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001288 *restrict p;
1289
cristy3a37efd2011-08-28 20:31:03 +00001290 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001291 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001292 break;
cristy4c08aed2011-07-01 19:47:50 +00001293 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001294 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001295 count=WriteBlob(image,length,pixels);
1296 if (count != (ssize_t) length)
1297 break;
1298 }
1299 if (image->previous == (Image *) NULL)
1300 {
1301 status=SetImageProgress(image,SaveImageTag,3,6);
1302 if (status == MagickFalse)
1303 break;
1304 }
1305 if (quantum_type == RGBAQuantum)
1306 {
1307 for (y=0; y < (ssize_t) image->rows; y++)
1308 {
cristy4c08aed2011-07-01 19:47:50 +00001309 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001310 *restrict p;
1311
cristy3a37efd2011-08-28 20:31:03 +00001312 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001313 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001314 break;
cristy4c08aed2011-07-01 19:47:50 +00001315 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001316 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001317 count=WriteBlob(image,length,pixels);
1318 if (count != (ssize_t) length)
1319 break;
1320 }
1321 if (image->previous == (Image *) NULL)
1322 {
1323 status=SetImageProgress(image,SaveImageTag,5,6);
1324 if (status == MagickFalse)
1325 break;
1326 }
1327 }
1328 if (image_info->interlace == PartitionInterlace)
1329 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00001330 MagickPathExtent);
cristy90dbac72010-08-22 15:08:40 +00001331 if (image->previous == (Image *) NULL)
1332 {
1333 status=SetImageProgress(image,SaveImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +00001334 if (status == MagickFalse)
1335 break;
1336 }
1337 break;
1338 }
1339 case PartitionInterlace:
1340 {
cristy3ed852e2009-09-05 21:47:34 +00001341 /*
1342 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
1343 */
cristy90dbac72010-08-22 15:08:40 +00001344 AppendImageFormat("R",image->filename);
1345 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001346 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001347 if (status == MagickFalse)
1348 return(status);
1349 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001350 {
cristy4c08aed2011-07-01 19:47:50 +00001351 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001352 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001353
cristy3a37efd2011-08-28 20:31:03 +00001354 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001355 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001356 break;
cristy4c08aed2011-07-01 19:47:50 +00001357 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001358 RedQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001359 count=WriteBlob(image,length,pixels);
1360 if (count != (ssize_t) length)
1361 break;
1362 }
1363 if (image->previous == (Image *) NULL)
1364 {
1365 status=SetImageProgress(image,SaveImageTag,1,6);
1366 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001367 break;
1368 }
cristy90dbac72010-08-22 15:08:40 +00001369 (void) CloseBlob(image);
1370 AppendImageFormat("G",image->filename);
1371 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001372 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001373 if (status == MagickFalse)
1374 return(status);
1375 for (y=0; y < (ssize_t) image->rows; y++)
1376 {
cristy4c08aed2011-07-01 19:47:50 +00001377 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001378 *restrict p;
1379
cristy3a37efd2011-08-28 20:31:03 +00001380 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001381 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001382 break;
cristy4c08aed2011-07-01 19:47:50 +00001383 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001384 GreenQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001385 count=WriteBlob(image,length,pixels);
1386 if (count != (ssize_t) length)
1387 break;
1388 }
1389 if (image->previous == (Image *) NULL)
1390 {
1391 status=SetImageProgress(image,SaveImageTag,2,6);
1392 if (status == MagickFalse)
1393 break;
1394 }
1395 (void) CloseBlob(image);
1396 AppendImageFormat("B",image->filename);
1397 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001398 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001399 if (status == MagickFalse)
1400 return(status);
1401 for (y=0; y < (ssize_t) image->rows; y++)
1402 {
cristy4c08aed2011-07-01 19:47:50 +00001403 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001404 *restrict p;
1405
cristy3a37efd2011-08-28 20:31:03 +00001406 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001407 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001408 break;
cristy4c08aed2011-07-01 19:47:50 +00001409 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001410 BlueQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001411 count=WriteBlob(image,length,pixels);
1412 if (count != (ssize_t) length)
1413 break;
1414 }
1415 if (image->previous == (Image *) NULL)
1416 {
1417 status=SetImageProgress(image,SaveImageTag,3,6);
1418 if (status == MagickFalse)
1419 break;
1420 }
cristy90dbac72010-08-22 15:08:40 +00001421 if (quantum_type == RGBAQuantum)
1422 {
1423 (void) CloseBlob(image);
1424 AppendImageFormat("A",image->filename);
1425 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy3a37efd2011-08-28 20:31:03 +00001426 AppendBinaryBlobMode,exception);
cristy90dbac72010-08-22 15:08:40 +00001427 if (status == MagickFalse)
1428 return(status);
1429 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001430 {
cristy4c08aed2011-07-01 19:47:50 +00001431 register const Quantum
cristy90dbac72010-08-22 15:08:40 +00001432 *restrict p;
1433
cristy3a37efd2011-08-28 20:31:03 +00001434 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001435 if (p == (const Quantum *) NULL)
cristy90dbac72010-08-22 15:08:40 +00001436 break;
cristy4c08aed2011-07-01 19:47:50 +00001437 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3a37efd2011-08-28 20:31:03 +00001438 AlphaQuantum,pixels,exception);
cristy90dbac72010-08-22 15:08:40 +00001439 count=WriteBlob(image,length,pixels);
1440 if (count != (ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +00001441 break;
1442 }
cristy90dbac72010-08-22 15:08:40 +00001443 if (image->previous == (Image *) NULL)
1444 {
1445 status=SetImageProgress(image,SaveImageTag,5,6);
1446 if (status == MagickFalse)
1447 break;
1448 }
1449 }
1450 (void) CloseBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001451 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00001452 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001453 if (image->previous == (Image *) NULL)
1454 {
cristy90dbac72010-08-22 15:08:40 +00001455 status=SetImageProgress(image,SaveImageTag,6,6);
cristy3ed852e2009-09-05 21:47:34 +00001456 if (status == MagickFalse)
1457 break;
1458 }
1459 break;
1460 }
1461 }
1462 quantum_info=DestroyQuantumInfo(quantum_info);
1463 if (GetNextImageInList(image) == (Image *) NULL)
1464 break;
1465 image=SyncNextImageInList(image);
1466 status=SetImageProgress(image,SaveImagesTag,scene++,
1467 GetImageListLength(image));
1468 if (status == MagickFalse)
1469 break;
1470 } while (image_info->adjoin != MagickFalse);
1471 (void) CloseBlob(image);
1472 return(MagickTrue);
1473}