blob: 2c9dd7151b9775a88a9ecba260510d4d5a1a69a9 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC M M Y Y K K %
7% C MM MM Y Y K K %
8% C M M M Y KKK %
9% C M M Y K K %
10% CCCC M M Y K K %
11% %
12% %
13% Read/Write RAW CMYK Image Format %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy45ef08f2012-12-07 13:13:34 +000020% Copyright 1999-2013 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"
48#include "MagickCore/constitute.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/image.h"
52#include "MagickCore/image-private.h"
53#include "MagickCore/list.h"
54#include "MagickCore/magick.h"
55#include "MagickCore/memory_.h"
56#include "MagickCore/monitor.h"
57#include "MagickCore/monitor-private.h"
58#include "MagickCore/pixel-accessor.h"
59#include "MagickCore/quantum-private.h"
60#include "MagickCore/static.h"
61#include "MagickCore/statistic.h"
62#include "MagickCore/string_.h"
63#include "MagickCore/module.h"
64#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000065
66/*
67 Forward declarations.
68*/
69static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000070 WriteCMYKImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000071
72/*
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74% %
75% %
76% %
77% R e a d C M Y K I m a g e %
78% %
79% %
80% %
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82%
83% ReadCMYKImage() reads an image of raw CMYK or CMYKA samples and returns it.
84% It allocates the memory necessary for the new Image structure and returns a
85% pointer to the new image.
86%
87% The format of the ReadCMYKImage method is:
88%
89% Image *ReadCMYKImage(const ImageInfo *image_info,
90% ExceptionInfo *exception)
91%
92% A description of each parameter follows:
93%
94% o image_info: the image info.
95%
96% o exception: return any errors or warnings in this structure.
97%
98*/
99static Image *ReadCMYKImage(const ImageInfo *image_info,
100 ExceptionInfo *exception)
101{
102 Image
103 *canvas_image,
104 *image;
105
cristy3ed852e2009-09-05 21:47:34 +0000106 MagickBooleanType
107 status;
108
109 MagickOffsetType
110 scene;
111
112 QuantumInfo
113 *quantum_info;
114
115 QuantumType
116 quantum_type;
117
cristybb503372010-05-27 20:51:26 +0000118 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000119 i;
120
cristy4e82e512011-04-24 01:33:42 +0000121 size_t
122 length;
123
cristy3ed852e2009-09-05 21:47:34 +0000124 ssize_t
cristy90dbac72010-08-22 15:08:40 +0000125 count,
126 y;
cristy3ed852e2009-09-05 21:47:34 +0000127
cristy3ed852e2009-09-05 21:47:34 +0000128 unsigned char
129 *pixels;
130
131 /*
132 Open image file.
133 */
134 assert(image_info != (const ImageInfo *) NULL);
135 assert(image_info->signature == MagickSignature);
136 if (image_info->debug != MagickFalse)
137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
138 image_info->filename);
139 assert(exception != (ExceptionInfo *) NULL);
140 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000141 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000142 if ((image->columns == 0) || (image->rows == 0))
143 ThrowReaderException(OptionError,"MustSpecifyImageSize");
cristye2c4f182012-05-12 14:11:53 +0000144 SetImageColorspace(image,CMYKColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000145 if (image_info->interlace != PartitionInterlace)
146 {
147 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
148 if (status == MagickFalse)
149 {
150 image=DestroyImageList(image);
151 return((Image *) NULL);
152 }
cristyd4297022010-09-16 22:59:09 +0000153 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
154 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
155 image->filename);
cristy3ed852e2009-09-05 21:47:34 +0000156 }
157 /*
158 Create virtual canvas to support cropping (i.e. image.cmyk[100x100+10+20]).
159 */
160 canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
161 exception);
cristy387430f2012-02-07 13:09:46 +0000162 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
163 exception);
cristy3ed852e2009-09-05 21:47:34 +0000164 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
165 if (quantum_info == (QuantumInfo *) NULL)
166 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
167 pixels=GetQuantumPixels(quantum_info);
168 quantum_type=CMYKQuantum;
169 if (LocaleCompare(image_info->magick,"CMYKA") == 0)
170 {
171 quantum_type=CMYKAQuantum;
cristy8a46d822012-08-28 23:32:39 +0000172 image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +0000173 }
174 if (image_info->number_scenes != 0)
175 while (image->scene < image_info->scene)
176 {
177 /*
178 Skip to next image.
179 */
180 image->scene++;
181 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
cristybb503372010-05-27 20:51:26 +0000182 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000183 {
184 count=ReadBlob(image,length,pixels);
185 if (count != (ssize_t) length)
186 break;
187 }
188 }
189 count=0;
190 length=0;
191 scene=0;
192 do
193 {
194 /*
195 Read pixels to virtual canvas image then push to image.
196 */
197 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
198 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
199 break;
cristye2c4f182012-05-12 14:11:53 +0000200 SetImageColorspace(image,CMYKColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000201 switch (image_info->interlace)
202 {
203 case NoInterlace:
204 default:
205 {
206 /*
207 No interlacing: CMYKCMYKCMYKCMYKCMYKCMYK...
208 */
209 if (scene == 0)
210 {
211 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
212 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000213 }
cristybb503372010-05-27 20:51:26 +0000214 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000215 {
cristy4c08aed2011-07-01 19:47:50 +0000216 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000217 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000218
cristy4c08aed2011-07-01 19:47:50 +0000219 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000220 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000221
cristy90dbac72010-08-22 15:08:40 +0000222 register ssize_t
223 x;
224
cristy21da32d2009-09-12 14:56:09 +0000225 if (count != (ssize_t) length)
226 {
227 ThrowFileException(exception,CorruptImageError,
228 "UnexpectedEndOfFile",image->filename);
229 break;
230 }
cristy3ed852e2009-09-05 21:47:34 +0000231 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
232 exception);
cristyacd2ed22011-08-30 01:44:23 +0000233 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000234 break;
235 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
236 quantum_info,quantum_type,pixels,exception);
237 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
238 break;
239 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000240 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000241 {
242 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
243 canvas_image->columns,1,exception);
244 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
245 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000246 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000247 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000248 break;
cristybb503372010-05-27 20:51:26 +0000249 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000250 {
cristy4c08aed2011-07-01 19:47:50 +0000251 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
252 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
253 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
254 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
255 SetPixelAlpha(image,OpaqueAlpha,q);
cristy8a46d822012-08-28 23:32:39 +0000256 if (image->alpha_trait == BlendPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +0000257 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000258 p+=GetPixelChannels(canvas_image);
259 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000260 }
261 if (SyncAuthenticPixels(image,exception) == MagickFalse)
262 break;
263 }
264 if (image->previous == (Image *) NULL)
265 {
cristycee97112010-05-28 00:44:52 +0000266 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
267 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000268 if (status == MagickFalse)
269 break;
270 }
271 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000272 }
273 break;
274 }
275 case LineInterlace:
276 {
277 static QuantumType
278 quantum_types[5] =
279 {
280 CyanQuantum,
281 MagentaQuantum,
282 YellowQuantum,
283 BlackQuantum,
284 OpacityQuantum
285 };
286
287 /*
288 Line interlacing: CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK...
289 */
290 if (scene == 0)
291 {
292 length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
293 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000294 }
cristybb503372010-05-27 20:51:26 +0000295 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000296 {
cristy4c08aed2011-07-01 19:47:50 +0000297 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000298 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000299
cristy4c08aed2011-07-01 19:47:50 +0000300 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000301 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000302
cristy90dbac72010-08-22 15:08:40 +0000303 register ssize_t
304 x;
305
cristy21da32d2009-09-12 14:56:09 +0000306 if (count != (ssize_t) length)
307 {
308 ThrowFileException(exception,CorruptImageError,
309 "UnexpectedEndOfFile",image->filename);
310 break;
311 }
cristy8a46d822012-08-28 23:32:39 +0000312 for (i=0; i < (image->alpha_trait == BlendPixelTrait ? 5 : 4); i++)
cristy3ed852e2009-09-05 21:47:34 +0000313 {
314 quantum_type=quantum_types[i];
315 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
316 exception);
cristyacd2ed22011-08-30 01:44:23 +0000317 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000318 break;
319 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
320 quantum_info,quantum_type,pixels,exception);
321 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
322 break;
323 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000324 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000325 {
326 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
327 0,canvas_image->columns,1,exception);
328 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
329 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000330 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000331 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000332 break;
cristybb503372010-05-27 20:51:26 +0000333 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000334 {
335 switch (quantum_type)
336 {
cristydd5f5912010-07-31 23:37:23 +0000337 case CyanQuantum:
338 {
cristy4c08aed2011-07-01 19:47:50 +0000339 SetPixelCyan(image,GetPixelCyan(canvas_image,p),q);
cristydd5f5912010-07-31 23:37:23 +0000340 break;
341 }
342 case MagentaQuantum:
343 {
cristy4c08aed2011-07-01 19:47:50 +0000344 SetPixelMagenta(image,GetPixelMagenta(canvas_image,p),q);
cristydd5f5912010-07-31 23:37:23 +0000345 break;
346 }
347 case YellowQuantum:
348 {
cristy4c08aed2011-07-01 19:47:50 +0000349 SetPixelYellow(image,GetPixelYellow(canvas_image,p),q);
cristydd5f5912010-07-31 23:37:23 +0000350 break;
351 }
352 case BlackQuantum:
353 {
cristy4c08aed2011-07-01 19:47:50 +0000354 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
cristydd5f5912010-07-31 23:37:23 +0000355 break;
356 }
357 case OpacityQuantum:
358 {
cristy4c08aed2011-07-01 19:47:50 +0000359 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristydd5f5912010-07-31 23:37:23 +0000360 break;
361 }
362 default:
363 break;
cristy3ed852e2009-09-05 21:47:34 +0000364 }
cristyed231572011-07-14 02:18:59 +0000365 p+=GetPixelChannels(canvas_image);
366 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000367 }
368 if (SyncAuthenticPixels(image,exception) == MagickFalse)
369 break;
370 }
371 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000372 }
373 if (image->previous == (Image *) NULL)
374 {
cristycee97112010-05-28 00:44:52 +0000375 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
376 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000377 if (status == MagickFalse)
378 break;
379 }
380 }
381 break;
382 }
383 case PlaneInterlace:
384 {
385 /*
386 Plane interlacing: CCCCCC...MMMMMM...YYYYYY...KKKKKK...
387 */
388 if (scene == 0)
389 {
390 length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
391 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000392 }
cristybb503372010-05-27 20:51:26 +0000393 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000394 {
cristy4c08aed2011-07-01 19:47:50 +0000395 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000396 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000397
cristy4c08aed2011-07-01 19:47:50 +0000398 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000399 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000400
cristy90dbac72010-08-22 15:08:40 +0000401 register ssize_t
402 x;
403
cristy21da32d2009-09-12 14:56:09 +0000404 if (count != (ssize_t) length)
405 {
406 ThrowFileException(exception,CorruptImageError,
407 "UnexpectedEndOfFile",image->filename);
408 break;
409 }
cristy3ed852e2009-09-05 21:47:34 +0000410 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
411 exception);
cristyacd2ed22011-08-30 01:44:23 +0000412 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000413 break;
414 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
415 quantum_info,CyanQuantum,pixels,exception);
416 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
417 break;
418 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000419 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000420 {
421 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
422 canvas_image->columns,1,exception);
423 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
424 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000425 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000426 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000427 break;
cristybb503372010-05-27 20:51:26 +0000428 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000429 {
cristy4c08aed2011-07-01 19:47:50 +0000430 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000431 p+=GetPixelChannels(canvas_image);
432 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000433 }
434 if (SyncAuthenticPixels(image,exception) == MagickFalse)
435 break;
436 }
437 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000438 }
439 if (image->previous == (Image *) NULL)
440 {
441 status=SetImageProgress(image,LoadImageTag,1,6);
442 if (status == MagickFalse)
443 break;
444 }
cristybb503372010-05-27 20:51:26 +0000445 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000446 {
cristy4c08aed2011-07-01 19:47:50 +0000447 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000448 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000449
cristy4c08aed2011-07-01 19:47:50 +0000450 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000451 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000452
cristy90dbac72010-08-22 15:08:40 +0000453 register ssize_t
454 x;
455
cristy21da32d2009-09-12 14:56:09 +0000456 if (count != (ssize_t) length)
457 {
458 ThrowFileException(exception,CorruptImageError,
459 "UnexpectedEndOfFile",image->filename);
460 break;
461 }
cristy3ed852e2009-09-05 21:47:34 +0000462 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
463 exception);
cristyacd2ed22011-08-30 01:44:23 +0000464 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000465 break;
466 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
467 quantum_info,MagentaQuantum,pixels,exception);
468 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
469 break;
470 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000471 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000472 {
473 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
474 canvas_image->columns,1,exception);
475 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
476 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000477 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000478 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000479 break;
cristybb503372010-05-27 20:51:26 +0000480 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000481 {
cristy4c08aed2011-07-01 19:47:50 +0000482 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000483 p+=GetPixelChannels(canvas_image);
484 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000485 }
486 if (SyncAuthenticPixels(image,exception) == MagickFalse)
487 break;
488 }
489 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000490 }
491 if (image->previous == (Image *) NULL)
492 {
493 status=SetImageProgress(image,LoadImageTag,2,6);
494 if (status == MagickFalse)
495 break;
496 }
cristybb503372010-05-27 20:51:26 +0000497 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000498 {
cristy4c08aed2011-07-01 19:47:50 +0000499 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000500 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000501
cristy4c08aed2011-07-01 19:47:50 +0000502 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000503 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000504
cristy90dbac72010-08-22 15:08:40 +0000505 register ssize_t
506 x;
507
cristy21da32d2009-09-12 14:56:09 +0000508 if (count != (ssize_t) length)
509 {
510 ThrowFileException(exception,CorruptImageError,
511 "UnexpectedEndOfFile",image->filename);
512 break;
513 }
cristy3ed852e2009-09-05 21:47:34 +0000514 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
515 exception);
cristyacd2ed22011-08-30 01:44:23 +0000516 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000517 break;
518 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
519 quantum_info,YellowQuantum,pixels,exception);
520 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
521 break;
522 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000523 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000524 {
525 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
526 canvas_image->columns,1,exception);
527 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
528 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000529 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000530 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000531 break;
cristybb503372010-05-27 20:51:26 +0000532 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000533 {
cristy4c08aed2011-07-01 19:47:50 +0000534 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000535 p+=GetPixelChannels(canvas_image);
536 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000537 }
538 if (SyncAuthenticPixels(image,exception) == MagickFalse)
539 break;
540 }
541 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000542 }
543 if (image->previous == (Image *) NULL)
544 {
545 status=SetImageProgress(image,LoadImageTag,3,6);
546 if (status == MagickFalse)
547 break;
548 }
cristybb503372010-05-27 20:51:26 +0000549 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000550 {
cristy4c08aed2011-07-01 19:47:50 +0000551 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000552 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000553
cristy4c08aed2011-07-01 19:47:50 +0000554 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000555 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000556
cristy90dbac72010-08-22 15:08:40 +0000557 register ssize_t
558 x;
559
cristy21da32d2009-09-12 14:56:09 +0000560 if (count != (ssize_t) length)
561 {
562 ThrowFileException(exception,CorruptImageError,
563 "UnexpectedEndOfFile",image->filename);
564 break;
565 }
cristy3ed852e2009-09-05 21:47:34 +0000566 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
567 exception);
cristyacd2ed22011-08-30 01:44:23 +0000568 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000569 break;
570 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
571 quantum_info,BlackQuantum,pixels,exception);
572 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
573 break;
574 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000575 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000576 {
577 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
578 canvas_image->columns,1,exception);
579 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
580 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000581 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000582 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000583 break;
cristybb503372010-05-27 20:51:26 +0000584 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000585 {
cristy4c08aed2011-07-01 19:47:50 +0000586 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000587 p+=GetPixelChannels(canvas_image);
588 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000589 }
590 if (SyncAuthenticPixels(image,exception) == MagickFalse)
591 break;
592 }
593 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000594 }
595 if (image->previous == (Image *) NULL)
596 {
597 status=SetImageProgress(image,LoadImageTag,4,6);
598 if (status == MagickFalse)
599 break;
600 }
cristy8a46d822012-08-28 23:32:39 +0000601 if (image->alpha_trait == BlendPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000602 {
cristybb503372010-05-27 20:51:26 +0000603 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000604 {
cristy4c08aed2011-07-01 19:47:50 +0000605 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000606 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000607
cristy4c08aed2011-07-01 19:47:50 +0000608 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000609 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000610
cristy90dbac72010-08-22 15:08:40 +0000611 register ssize_t
612 x;
613
cristy21da32d2009-09-12 14:56:09 +0000614 if (count != (ssize_t) length)
615 {
616 ThrowFileException(exception,CorruptImageError,
617 "UnexpectedEndOfFile",image->filename);
618 break;
619 }
cristy3ed852e2009-09-05 21:47:34 +0000620 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
621 exception);
cristyacd2ed22011-08-30 01:44:23 +0000622 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000623 break;
624 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
625 quantum_info,AlphaQuantum,pixels,exception);
626 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
627 break;
628 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000629 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000630 {
631 p=GetVirtualPixels(canvas_image,
632 canvas_image->extract_info.x,0,canvas_image->columns,1,
633 exception);
634 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
635 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000636 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000637 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000638 break;
cristybb503372010-05-27 20:51:26 +0000639 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000640 {
cristy4c08aed2011-07-01 19:47:50 +0000641 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000642 p+=GetPixelChannels(canvas_image);
643 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000644 }
645 if (SyncAuthenticPixels(image,exception) == MagickFalse)
646 break;
647 }
648 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000649 }
650 if (image->previous == (Image *) NULL)
651 {
652 status=SetImageProgress(image,LoadImageTag,5,6);
653 if (status == MagickFalse)
654 break;
655 }
656 }
657 if (image->previous == (Image *) NULL)
658 {
659 status=SetImageProgress(image,LoadImageTag,6,6);
660 if (status == MagickFalse)
661 break;
662 }
663 break;
664 }
665 case PartitionInterlace:
666 {
667 /*
668 Partition interlacing: CCCCCC..., MMMMMM..., YYYYYY..., KKKKKK...
669 */
670 AppendImageFormat("C",image->filename);
671 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
672 if (status == MagickFalse)
673 {
674 canvas_image=DestroyImageList(canvas_image);
675 image=DestroyImageList(image);
676 return((Image *) NULL);
677 }
cristyd4297022010-09-16 22:59:09 +0000678 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
679 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
680 image->filename);
cristy3ed852e2009-09-05 21:47:34 +0000681 length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
cristybb503372010-05-27 20:51:26 +0000682 for (i=0; i < (ssize_t) scene; i++)
683 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000684 if (ReadBlob(image,length,pixels) != (ssize_t) length)
685 {
686 ThrowFileException(exception,CorruptImageError,
687 "UnexpectedEndOfFile",image->filename);
688 break;
689 }
690 count=ReadBlob(image,length,pixels);
cristybb503372010-05-27 20:51:26 +0000691 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000692 {
cristy4c08aed2011-07-01 19:47:50 +0000693 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000694 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000695
cristy4c08aed2011-07-01 19:47:50 +0000696 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000697 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000698
cristy90dbac72010-08-22 15:08:40 +0000699 register ssize_t
700 x;
701
cristy21da32d2009-09-12 14:56:09 +0000702 if (count != (ssize_t) length)
703 {
704 ThrowFileException(exception,CorruptImageError,
705 "UnexpectedEndOfFile",image->filename);
706 break;
707 }
cristy3ed852e2009-09-05 21:47:34 +0000708 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
709 exception);
cristyacd2ed22011-08-30 01:44:23 +0000710 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000711 break;
712 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
713 quantum_info,CyanQuantum,pixels,exception);
714 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
715 break;
716 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000717 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000718 {
719 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
720 canvas_image->columns,1,exception);
721 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
722 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000723 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000724 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000725 break;
cristybb503372010-05-27 20:51:26 +0000726 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000727 {
cristy4c08aed2011-07-01 19:47:50 +0000728 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000729 p+=GetPixelChannels(canvas_image);
730 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000731 }
732 if (SyncAuthenticPixels(image,exception) == MagickFalse)
733 break;
734 }
735 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000736 }
737 if (image->previous == (Image *) NULL)
738 {
739 status=SetImageProgress(image,LoadImageTag,1,5);
740 if (status == MagickFalse)
741 break;
742 }
743 (void) CloseBlob(image);
744 AppendImageFormat("M",image->filename);
745 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
746 if (status == MagickFalse)
747 {
748 canvas_image=DestroyImageList(canvas_image);
749 image=DestroyImageList(image);
750 return((Image *) NULL);
751 }
752 length=GetQuantumExtent(canvas_image,quantum_info,MagentaQuantum);
cristybb503372010-05-27 20:51:26 +0000753 for (i=0; i < (ssize_t) scene; i++)
754 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000755 if (ReadBlob(image,length,pixels) != (ssize_t) length)
756 {
757 ThrowFileException(exception,CorruptImageError,
758 "UnexpectedEndOfFile",image->filename);
759 break;
760 }
761 count=ReadBlob(image,length,pixels);
cristybb503372010-05-27 20:51:26 +0000762 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000763 {
cristy4c08aed2011-07-01 19:47:50 +0000764 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000765 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000766
cristy4c08aed2011-07-01 19:47:50 +0000767 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000768 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000769
cristy90dbac72010-08-22 15:08:40 +0000770 register ssize_t
771 x;
772
cristy21da32d2009-09-12 14:56:09 +0000773 if (count != (ssize_t) length)
774 {
775 ThrowFileException(exception,CorruptImageError,
776 "UnexpectedEndOfFile",image->filename);
777 break;
778 }
cristy3ed852e2009-09-05 21:47:34 +0000779 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
780 exception);
cristyacd2ed22011-08-30 01:44:23 +0000781 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000782 break;
783 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
784 quantum_info,MagentaQuantum,pixels,exception);
785 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
786 break;
787 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000788 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000789 {
790 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
791 canvas_image->columns,1,exception);
792 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
793 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000794 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000795 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000796 break;
cristybb503372010-05-27 20:51:26 +0000797 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000798 {
cristy4c08aed2011-07-01 19:47:50 +0000799 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000800 p+=GetPixelChannels(canvas_image);
801 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000802 }
803 if (SyncAuthenticPixels(image,exception) == MagickFalse)
804 break;
805 }
806 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000807 }
808 if (image->previous == (Image *) NULL)
809 {
810 status=SetImageProgress(image,LoadImageTag,2,5);
811 if (status == MagickFalse)
812 break;
813 }
814 (void) CloseBlob(image);
815 AppendImageFormat("Y",image->filename);
816 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
817 if (status == MagickFalse)
818 {
819 canvas_image=DestroyImageList(canvas_image);
820 image=DestroyImageList(image);
821 return((Image *) NULL);
822 }
823 length=GetQuantumExtent(canvas_image,quantum_info,YellowQuantum);
cristybb503372010-05-27 20:51:26 +0000824 for (i=0; i < (ssize_t) scene; i++)
825 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000826 if (ReadBlob(image,length,pixels) != (ssize_t) length)
827 {
828 ThrowFileException(exception,CorruptImageError,
829 "UnexpectedEndOfFile",image->filename);
830 break;
831 }
832 count=ReadBlob(image,length,pixels);
cristybb503372010-05-27 20:51:26 +0000833 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000834 {
cristy4c08aed2011-07-01 19:47:50 +0000835 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000836 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000837
cristy4c08aed2011-07-01 19:47:50 +0000838 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000839 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000840
cristy90dbac72010-08-22 15:08:40 +0000841 register ssize_t
842 x;
843
cristy21da32d2009-09-12 14:56:09 +0000844 if (count != (ssize_t) length)
845 {
846 ThrowFileException(exception,CorruptImageError,
847 "UnexpectedEndOfFile",image->filename);
848 break;
849 }
cristy3ed852e2009-09-05 21:47:34 +0000850 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
851 exception);
cristyacd2ed22011-08-30 01:44:23 +0000852 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000853 break;
854 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
855 quantum_info,YellowQuantum,pixels,exception);
856 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
857 break;
858 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000859 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000860 {
861 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
862 canvas_image->columns,1,exception);
863 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
864 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000865 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000866 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000867 break;
cristybb503372010-05-27 20:51:26 +0000868 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000869 {
cristy4c08aed2011-07-01 19:47:50 +0000870 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000871 p+=GetPixelChannels(canvas_image);
872 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000873 }
874 if (SyncAuthenticPixels(image,exception) == MagickFalse)
875 break;
876 }
877 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000878 }
879 if (image->previous == (Image *) NULL)
880 {
881 status=SetImageProgress(image,LoadImageTag,3,5);
882 if (status == MagickFalse)
883 break;
884 }
885 (void) CloseBlob(image);
886 AppendImageFormat("K",image->filename);
887 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
888 if (status == MagickFalse)
889 {
890 canvas_image=DestroyImageList(canvas_image);
891 image=DestroyImageList(image);
892 return((Image *) NULL);
893 }
894 length=GetQuantumExtent(canvas_image,quantum_info,BlackQuantum);
cristybb503372010-05-27 20:51:26 +0000895 for (i=0; i < (ssize_t) scene; i++)
896 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000897 if (ReadBlob(image,length,pixels) != (ssize_t) length)
898 {
899 ThrowFileException(exception,CorruptImageError,
900 "UnexpectedEndOfFile",image->filename);
901 break;
902 }
903 count=ReadBlob(image,length,pixels);
cristybb503372010-05-27 20:51:26 +0000904 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000905 {
cristy4c08aed2011-07-01 19:47:50 +0000906 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000907 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000908
cristy4c08aed2011-07-01 19:47:50 +0000909 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000910 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000911
cristy90dbac72010-08-22 15:08:40 +0000912 register ssize_t
913 x;
914
cristy21da32d2009-09-12 14:56:09 +0000915 if (count != (ssize_t) length)
916 {
917 ThrowFileException(exception,CorruptImageError,
918 "UnexpectedEndOfFile",image->filename);
919 break;
920 }
cristy3ed852e2009-09-05 21:47:34 +0000921 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
922 exception);
cristyacd2ed22011-08-30 01:44:23 +0000923 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000924 break;
925 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
926 quantum_info,BlackQuantum,pixels,exception);
927 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
928 break;
929 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +0000930 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +0000931 {
932 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
933 canvas_image->columns,1,exception);
934 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
935 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000936 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +0000937 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000938 break;
cristybb503372010-05-27 20:51:26 +0000939 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000940 {
cristy4c08aed2011-07-01 19:47:50 +0000941 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +0000942 p+=GetPixelChannels(canvas_image);
943 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000944 }
945 if (SyncAuthenticPixels(image,exception) == MagickFalse)
946 break;
947 }
948 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +0000949 }
950 if (image->previous == (Image *) NULL)
951 {
952 status=SetImageProgress(image,LoadImageTag,3,5);
953 if (status == MagickFalse)
954 break;
955 }
cristy8a46d822012-08-28 23:32:39 +0000956 if (image->alpha_trait == BlendPixelTrait)
cristy3ed852e2009-09-05 21:47:34 +0000957 {
958 (void) CloseBlob(image);
959 AppendImageFormat("A",image->filename);
960 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
961 if (status == MagickFalse)
962 {
963 canvas_image=DestroyImageList(canvas_image);
964 image=DestroyImageList(image);
965 return((Image *) NULL);
966 }
967 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
cristybb503372010-05-27 20:51:26 +0000968 for (i=0; i < (ssize_t) scene; i++)
969 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000970 if (ReadBlob(image,length,pixels) != (ssize_t) length)
971 {
972 ThrowFileException(exception,CorruptImageError,
973 "UnexpectedEndOfFile",image->filename);
974 break;
975 }
976 count=ReadBlob(image,length,pixels);
cristybb503372010-05-27 20:51:26 +0000977 for (y=0; y < (ssize_t) image->extract_info.height; y++)
cristy3ed852e2009-09-05 21:47:34 +0000978 {
cristy4c08aed2011-07-01 19:47:50 +0000979 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000980 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000981
cristy4c08aed2011-07-01 19:47:50 +0000982 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000983 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000984
cristy90dbac72010-08-22 15:08:40 +0000985 register ssize_t
986 x;
987
cristy21da32d2009-09-12 14:56:09 +0000988 if (count != (ssize_t) length)
989 {
990 ThrowFileException(exception,CorruptImageError,
991 "UnexpectedEndOfFile",image->filename);
992 break;
993 }
cristy3ed852e2009-09-05 21:47:34 +0000994 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
995 exception);
cristyacd2ed22011-08-30 01:44:23 +0000996 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000997 break;
998 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
999 quantum_info,YellowQuantum,pixels,exception);
1000 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
1001 break;
1002 if (((y-image->extract_info.y) >= 0) &&
cristybb503372010-05-27 20:51:26 +00001003 ((y-image->extract_info.y) < (ssize_t) image->rows))
cristy3ed852e2009-09-05 21:47:34 +00001004 {
1005 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
1006 0,canvas_image->columns,1,exception);
1007 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
1008 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001009 if ((p == (const Quantum *) NULL) ||
cristyacd2ed22011-08-30 01:44:23 +00001010 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00001011 break;
cristybb503372010-05-27 20:51:26 +00001012 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001013 {
cristy4c08aed2011-07-01 19:47:50 +00001014 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
cristyed231572011-07-14 02:18:59 +00001015 p+=GetPixelChannels(canvas_image);
1016 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00001017 }
1018 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1019 break;
1020 }
1021 count=ReadBlob(image,length,pixels);
cristy3ed852e2009-09-05 21:47:34 +00001022 }
1023 if (image->previous == (Image *) NULL)
1024 {
1025 status=SetImageProgress(image,LoadImageTag,4,5);
1026 if (status == MagickFalse)
1027 break;
1028 }
1029 }
1030 if (image->previous == (Image *) NULL)
1031 {
1032 status=SetImageProgress(image,LoadImageTag,5,5);
1033 if (status == MagickFalse)
1034 break;
1035 }
1036 break;
1037 }
1038 }
1039 SetQuantumImageType(image,quantum_type);
1040 /*
1041 Proceed to next image.
1042 */
1043 if (image_info->number_scenes != 0)
1044 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1045 break;
1046 if (count == (ssize_t) length)
1047 {
1048 /*
1049 Allocate next image structure.
1050 */
cristy9950d572011-10-01 18:22:35 +00001051 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001052 if (GetNextImageInList(image) == (Image *) NULL)
1053 {
1054 image=DestroyImageList(image);
1055 return((Image *) NULL);
1056 }
1057 image=SyncNextImageInList(image);
1058 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1059 GetBlobSize(image));
1060 if (status == MagickFalse)
1061 break;
1062 }
1063 scene++;
1064 } while (count == (ssize_t) length);
cristy3ed852e2009-09-05 21:47:34 +00001065 quantum_info=DestroyQuantumInfo(quantum_info);
cristy3ed852e2009-09-05 21:47:34 +00001066 canvas_image=DestroyImage(canvas_image);
1067 (void) CloseBlob(image);
1068 return(GetFirstImageInList(image));
1069}
1070
1071/*
1072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1073% %
1074% %
1075% %
1076% R e g i s t e r C M Y K I m a g e %
1077% %
1078% %
1079% %
1080%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081%
1082% RegisterCMYKImage() adds attributes for the CMYK image format to
1083% the list of supported formats. The attributes include the image format
1084% tag, a method to read and/or write the format, whether the format
1085% supports the saving of more than one frame to the same file or blob,
1086% whether the format supports native in-memory I/O, and a brief
1087% description of the format.
1088%
1089% The format of the RegisterCMYKImage method is:
1090%
cristybb503372010-05-27 20:51:26 +00001091% size_t RegisterCMYKImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001092%
1093*/
cristybb503372010-05-27 20:51:26 +00001094ModuleExport size_t RegisterCMYKImage(void)
cristy3ed852e2009-09-05 21:47:34 +00001095{
1096 MagickInfo
1097 *entry;
1098
1099 entry=SetMagickInfo("CMYK");
1100 entry->decoder=(DecodeImageHandler *) ReadCMYKImage;
1101 entry->encoder=(EncodeImageHandler *) WriteCMYKImage;
1102 entry->raw=MagickTrue;
1103 entry->endian_support=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001104 entry->description=ConstantString("Raw cyan, magenta, yellow, and black "
1105 "samples");
1106 entry->module=ConstantString("CMYK");
1107 (void) RegisterMagickInfo(entry);
1108 entry=SetMagickInfo("CMYKA");
1109 entry->decoder=(DecodeImageHandler *) ReadCMYKImage;
1110 entry->encoder=(EncodeImageHandler *) WriteCMYKImage;
1111 entry->raw=MagickTrue;
1112 entry->endian_support=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001113 entry->description=ConstantString("Raw cyan, magenta, yellow, black, and "
1114 "alpha samples");
1115 entry->module=ConstantString("CMYK");
1116 (void) RegisterMagickInfo(entry);
1117 return(MagickImageCoderSignature);
1118}
1119
1120/*
1121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1122% %
1123% %
1124% %
1125% U n r e g i s t e r C M Y K I m a g e %
1126% %
1127% %
1128% %
1129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1130%
1131% UnregisterCMYKImage() removes format registrations made by the
1132% CMYK module from the list of supported formats.
1133%
1134% The format of the UnregisterCMYKImage method is:
1135%
1136% UnregisterCMYKImage(void)
1137%
1138*/
1139ModuleExport void UnregisterCMYKImage(void)
1140{
1141 (void) UnregisterMagickInfo("CMYK");
1142 (void) UnregisterMagickInfo("CMYKA");
1143}
1144
1145/*
1146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147% %
1148% %
1149% %
1150% W r i t e C M Y K I m a g e %
1151% %
1152% %
1153% %
1154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1155%
1156% WriteCMYKImage() writes an image to a file in cyan, magenta, yellow, and
1157% black,rasterfile format.
1158%
1159% The format of the WriteCMYKImage method is:
1160%
1161% MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +00001162% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001163%
1164% A description of each parameter follows.
1165%
1166% o image_info: the image info.
1167%
1168% o image: The image.
1169%
cristy1e178e72011-08-28 19:44:34 +00001170% o exception: return any errors or warnings in this structure.
1171%
cristy3ed852e2009-09-05 21:47:34 +00001172*/
1173static MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +00001174 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001175{
cristy3ed852e2009-09-05 21:47:34 +00001176 MagickBooleanType
1177 status;
1178
1179 MagickOffsetType
1180 scene;
1181
1182 QuantumInfo
1183 *quantum_info;
1184
1185 QuantumType
1186 quantum_type;
1187
cristy1e178e72011-08-28 19:44:34 +00001188 size_t
1189 length;
1190
cristy3ed852e2009-09-05 21:47:34 +00001191 ssize_t
cristy90dbac72010-08-22 15:08:40 +00001192 count,
1193 y;
cristy3ed852e2009-09-05 21:47:34 +00001194
cristy3ed852e2009-09-05 21:47:34 +00001195 unsigned char
1196 *pixels;
1197
1198 /*
1199 Allocate memory for pixels.
1200 */
1201 assert(image_info != (const ImageInfo *) NULL);
1202 assert(image_info->signature == MagickSignature);
1203 assert(image != (Image *) NULL);
1204 assert(image->signature == MagickSignature);
1205 if (image->debug != MagickFalse)
1206 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1207 if (image_info->interlace != PartitionInterlace)
1208 {
1209 /*
1210 Open output image file.
1211 */
cristyedf03fa2011-08-30 12:44:39 +00001212 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001213 if (status == MagickFalse)
1214 return(status);
1215 }
cristy3ed852e2009-09-05 21:47:34 +00001216 scene=0;
1217 do
1218 {
1219 /*
1220 Convert MIFF to CMYK raster pixels.
1221 */
1222 if (image->colorspace != CMYKColorspace)
cristye941a752011-10-15 01:52:48 +00001223 (void) TransformImageColorspace(image,CMYKColorspace,exception);
cristy286596b2012-01-08 00:58:30 +00001224 quantum_type=CMYKQuantum;
1225 if (LocaleCompare(image_info->magick,"CMYKA") == 0)
1226 {
1227 quantum_type=CMYKAQuantum;
cristy8a46d822012-08-28 23:32:39 +00001228 if (image->alpha_trait != BlendPixelTrait)
cristy286596b2012-01-08 00:58:30 +00001229 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1230 }
cristy3ed852e2009-09-05 21:47:34 +00001231 quantum_info=AcquireQuantumInfo(image_info,image);
1232 if (quantum_info == (QuantumInfo *) NULL)
1233 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1234 pixels=GetQuantumPixels(quantum_info);
1235 switch (image_info->interlace)
1236 {
1237 case NoInterlace:
1238 default:
1239 {
1240 /*
1241 No interlacing: CMYKCMYKCMYKCMYKCMYKCMYK...
1242 */
cristybb503372010-05-27 20:51:26 +00001243 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001244 {
cristy4c08aed2011-07-01 19:47:50 +00001245 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001246 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001247
cristy1e178e72011-08-28 19:44:34 +00001248 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001249 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001250 break;
cristy4c08aed2011-07-01 19:47:50 +00001251 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001252 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001253 count=WriteBlob(image,length,pixels);
1254 if (count != (ssize_t) length)
1255 break;
1256 if (image->previous == (Image *) NULL)
1257 {
cristycee97112010-05-28 00:44:52 +00001258 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1259 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001260 if (status == MagickFalse)
1261 break;
1262 }
1263 }
1264 break;
1265 }
1266 case LineInterlace:
1267 {
1268 /*
1269 Line interlacing: CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK...
1270 */
cristybb503372010-05-27 20:51:26 +00001271 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001272 {
cristy4c08aed2011-07-01 19:47:50 +00001273 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001274 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001275
cristy1e178e72011-08-28 19:44:34 +00001276 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001277 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001278 break;
cristy4c08aed2011-07-01 19:47:50 +00001279 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001280 CyanQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001281 count=WriteBlob(image,length,pixels);
1282 if (count != (ssize_t) length)
1283 break;
cristy4c08aed2011-07-01 19:47:50 +00001284 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001285 MagentaQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001286 count=WriteBlob(image,length,pixels);
1287 if (count != (ssize_t) length)
1288 break;
cristy4c08aed2011-07-01 19:47:50 +00001289 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001290 YellowQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001291 count=WriteBlob(image,length,pixels);
1292 if (count != (ssize_t) length)
1293 break;
cristy4c08aed2011-07-01 19:47:50 +00001294 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001295 BlackQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001296 count=WriteBlob(image,length,pixels);
1297 if (count != (ssize_t) length)
1298 break;
1299 if (quantum_type == CMYKAQuantum)
1300 {
cristy4c08aed2011-07-01 19:47:50 +00001301 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001302 AlphaQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001303 count=WriteBlob(image,length,pixels);
1304 if (count != (ssize_t) length)
1305 break;
1306 }
1307 if (image->previous == (Image *) NULL)
1308 {
cristycee97112010-05-28 00:44:52 +00001309 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1310 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001311 if (status == MagickFalse)
1312 break;
1313 }
1314 }
1315 break;
1316 }
1317 case PlaneInterlace:
1318 {
1319 /*
1320 Plane interlacing: CCCCCC...MMMMMM...YYYYYY...KKKKKK...
1321 */
cristybb503372010-05-27 20:51:26 +00001322 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001323 {
cristy4c08aed2011-07-01 19:47:50 +00001324 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001325 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001326
cristy1e178e72011-08-28 19:44:34 +00001327 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001328 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001329 break;
cristy4c08aed2011-07-01 19:47:50 +00001330 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001331 CyanQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001332 count=WriteBlob(image,length,pixels);
1333 if (count != (ssize_t) length)
1334 break;
1335 }
1336 if (image->previous == (Image *) NULL)
1337 {
1338 status=SetImageProgress(image,SaveImageTag,1,6);
1339 if (status == MagickFalse)
1340 break;
1341 }
cristybb503372010-05-27 20:51:26 +00001342 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001343 {
cristy4c08aed2011-07-01 19:47:50 +00001344 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001345 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001346
cristy1e178e72011-08-28 19:44:34 +00001347 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001348 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001349 break;
cristy4c08aed2011-07-01 19:47:50 +00001350 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001351 MagentaQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001352 count=WriteBlob(image,length,pixels);
1353 if (count != (ssize_t) length)
1354 break;
1355 }
1356 if (image->previous == (Image *) NULL)
1357 {
1358 status=SetImageProgress(image,SaveImageTag,2,6);
1359 if (status == MagickFalse)
1360 break;
1361 }
cristybb503372010-05-27 20:51:26 +00001362 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001363 {
cristy4c08aed2011-07-01 19:47:50 +00001364 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001365 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001366
cristy1e178e72011-08-28 19:44:34 +00001367 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001368 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001369 break;
cristy4c08aed2011-07-01 19:47:50 +00001370 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001371 YellowQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001372 count=WriteBlob(image,length,pixels);
1373 if (count != (ssize_t) length)
1374 break;
1375 }
1376 if (image->previous == (Image *) NULL)
1377 {
1378 status=SetImageProgress(image,SaveImageTag,3,6);
1379 if (status == MagickFalse)
1380 break;
1381 }
cristybb503372010-05-27 20:51:26 +00001382 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001383 {
cristy4c08aed2011-07-01 19:47:50 +00001384 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001385 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001386
cristy1e178e72011-08-28 19:44:34 +00001387 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001388 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001389 break;
cristy4c08aed2011-07-01 19:47:50 +00001390 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001391 BlackQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001392 count=WriteBlob(image,length,pixels);
1393 if (count != (ssize_t) length)
1394 break;
1395 }
1396 if (image->previous == (Image *) NULL)
1397 {
1398 status=SetImageProgress(image,SaveImageTag,4,6);
1399 if (status == MagickFalse)
1400 break;
1401 }
1402 if (quantum_type == CMYKAQuantum)
1403 {
cristybb503372010-05-27 20:51:26 +00001404 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001405 {
cristy4c08aed2011-07-01 19:47:50 +00001406 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001407 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001408
cristy1e178e72011-08-28 19:44:34 +00001409 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001410 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001411 break;
cristy4c08aed2011-07-01 19:47:50 +00001412 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001413 AlphaQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001414 count=WriteBlob(image,length,pixels);
1415 if (count != (ssize_t) length)
1416 break;
1417 }
1418 if (image->previous == (Image *) NULL)
1419 {
1420 status=SetImageProgress(image,SaveImageTag,5,6);
1421 if (status == MagickFalse)
1422 break;
1423 }
1424 }
1425 if (image_info->interlace == PartitionInterlace)
1426 (void) CopyMagickString(image->filename,image_info->filename,
1427 MaxTextExtent);
1428 if (image->previous == (Image *) NULL)
1429 {
1430 status=SetImageProgress(image,SaveImageTag,6,6);
1431 if (status == MagickFalse)
1432 break;
1433 }
1434 break;
1435 }
1436 case PartitionInterlace:
1437 {
1438 /*
1439 Partition interlacing: CCCCCC..., MMMMMM..., YYYYYY..., KKKKKK...
1440 */
1441 AppendImageFormat("C",image->filename);
1442 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy1e178e72011-08-28 19:44:34 +00001443 AppendBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001444 if (status == MagickFalse)
1445 return(status);
cristybb503372010-05-27 20:51:26 +00001446 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001447 {
cristy4c08aed2011-07-01 19:47:50 +00001448 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001449 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001450
cristy1e178e72011-08-28 19:44:34 +00001451 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001452 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001453 break;
cristy4c08aed2011-07-01 19:47:50 +00001454 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001455 CyanQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001456 count=WriteBlob(image,length,pixels);
1457 if (count != (ssize_t) length)
1458 break;
1459 }
1460 if (image->previous == (Image *) NULL)
1461 {
1462 status=SetImageProgress(image,SaveImageTag,1,6);
1463 if (status == MagickFalse)
1464 break;
1465 }
1466 (void) CloseBlob(image);
1467 AppendImageFormat("M",image->filename);
1468 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy1e178e72011-08-28 19:44:34 +00001469 AppendBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001470 if (status == MagickFalse)
1471 return(status);
cristybb503372010-05-27 20:51:26 +00001472 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001473 {
cristy4c08aed2011-07-01 19:47:50 +00001474 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001475 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001476
cristy1e178e72011-08-28 19:44:34 +00001477 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001478 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001479 break;
cristy4c08aed2011-07-01 19:47:50 +00001480 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001481 MagentaQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001482 count=WriteBlob(image,length,pixels);
1483 if (count != (ssize_t) length)
1484 break;
1485 }
1486 if (image->previous == (Image *) NULL)
1487 {
1488 status=SetImageProgress(image,SaveImageTag,2,6);
1489 if (status == MagickFalse)
1490 break;
1491 }
1492 (void) CloseBlob(image);
1493 AppendImageFormat("Y",image->filename);
1494 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy1e178e72011-08-28 19:44:34 +00001495 AppendBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001496 if (status == MagickFalse)
1497 return(status);
cristybb503372010-05-27 20:51:26 +00001498 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001499 {
cristy4c08aed2011-07-01 19:47:50 +00001500 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001501 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001502
cristy1e178e72011-08-28 19:44:34 +00001503 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001504 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001505 break;
cristy4c08aed2011-07-01 19:47:50 +00001506 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001507 YellowQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001508 count=WriteBlob(image,length,pixels);
1509 if (count != (ssize_t) length)
1510 break;
1511 }
1512 if (image->previous == (Image *) NULL)
1513 {
1514 status=SetImageProgress(image,SaveImageTag,3,6);
1515 if (status == MagickFalse)
1516 break;
1517 }
1518 (void) CloseBlob(image);
1519 AppendImageFormat("K",image->filename);
1520 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy1e178e72011-08-28 19:44:34 +00001521 AppendBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001522 if (status == MagickFalse)
1523 return(status);
cristybb503372010-05-27 20:51:26 +00001524 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001525 {
cristy4c08aed2011-07-01 19:47:50 +00001526 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001527 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001528
cristy1e178e72011-08-28 19:44:34 +00001529 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001530 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001531 break;
cristy4c08aed2011-07-01 19:47:50 +00001532 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001533 BlackQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001534 count=WriteBlob(image,length,pixels);
1535 if (count != (ssize_t) length)
1536 break;
1537 }
1538 if (image->previous == (Image *) NULL)
1539 {
1540 status=SetImageProgress(image,SaveImageTag,4,6);
1541 if (status == MagickFalse)
1542 break;
1543 }
1544 if (quantum_type == CMYKAQuantum)
1545 {
1546 (void) CloseBlob(image);
1547 AppendImageFormat("A",image->filename);
1548 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
cristy1e178e72011-08-28 19:44:34 +00001549 AppendBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +00001550 if (status == MagickFalse)
1551 return(status);
cristybb503372010-05-27 20:51:26 +00001552 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001553 {
cristy4c08aed2011-07-01 19:47:50 +00001554 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001555 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001556
cristy1e178e72011-08-28 19:44:34 +00001557 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001558 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001559 break;
cristy4c08aed2011-07-01 19:47:50 +00001560 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001561 AlphaQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001562 count=WriteBlob(image,length,pixels);
1563 if (count != (ssize_t) length)
1564 break;
1565 }
1566 if (image->previous == (Image *) NULL)
1567 {
1568 status=SetImageProgress(image,SaveImageTag,5,6);
1569 if (status == MagickFalse)
1570 break;
1571 }
1572 }
1573 (void) CloseBlob(image);
1574 (void) CopyMagickString(image->filename,image_info->filename,
1575 MaxTextExtent);
1576 if (image->previous == (Image *) NULL)
1577 {
1578 status=SetImageProgress(image,SaveImageTag,6,6);
1579 if (status == MagickFalse)
1580 break;
1581 }
1582 break;
1583 }
1584 }
1585 quantum_info=DestroyQuantumInfo(quantum_info);
1586 if (GetNextImageInList(image) == (Image *) NULL)
1587 break;
1588 image=SyncNextImageInList(image);
1589 status=SetImageProgress(image,SaveImagesTag,scene++,
1590 GetImageListLength(image));
1591 if (status == MagickFalse)
1592 break;
1593 } while (image_info->adjoin != MagickFalse);
1594 (void) CloseBlob(image);
1595 return(MagickTrue);
1596}