]> granicus.if.org Git - imagemagick/blob - coders/cmyk.c
(no commit message)
[imagemagick] / coders / cmyk.c
1 /*
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 %                                   Cristy                                    %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
21 %  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 \f
39 /*
40   Include declarations.
41 */
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/channel.h"
47 #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"
65 \f
66 /*
67   Forward declarations.
68 */
69 static MagickBooleanType
70   WriteCMYKImage(const ImageInfo *,Image *,ExceptionInfo *);
71 \f
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 */
99 static Image *ReadCMYKImage(const ImageInfo *image_info,
100   ExceptionInfo *exception)
101 {
102   const void
103     *pixels;
104
105   Image
106     *canvas_image,
107     *image;
108
109   MagickBooleanType
110     status;
111
112   MagickOffsetType
113     scene;
114
115   QuantumInfo
116     *quantum_info;
117
118   QuantumType
119     quantum_type;
120
121   register ssize_t
122     i;
123
124   size_t
125     length;
126
127   ssize_t
128     count,
129     y;
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);
141   image=AcquireImage(image_info,exception);
142   if ((image->columns == 0) || (image->rows == 0))
143     ThrowReaderException(OptionError,"MustSpecifyImageSize");
144   SetImageColorspace(image,CMYKColorspace,exception);
145   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         }
153       if (DiscardBlobBytes(image,image->offset) == MagickFalse)
154         ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
155           image->filename);
156     }
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);
162   (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
163     exception);
164   quantum_info=AcquireQuantumInfo(image_info,canvas_image);
165   if (quantum_info == (QuantumInfo *) NULL)
166     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
167   quantum_type=CMYKQuantum;
168   if (LocaleCompare(image_info->magick,"CMYKA") == 0)
169     {
170       quantum_type=CMYKAQuantum;
171       image->alpha_trait=BlendPixelTrait;
172     }
173   if (image_info->number_scenes != 0)
174     while (image->scene < image_info->scene)
175     {
176       /*
177         Skip to next image.
178       */
179       image->scene++;
180       length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
181       for (y=0; y < (ssize_t) image->rows; y++)
182       {
183         pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
184           &count);
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;
200     status=SetImageExtent(image,image->columns,image->rows,exception);
201     if (status == MagickFalse)
202       return(DestroyImageList(image));
203     SetImageColorspace(image,CMYKColorspace,exception);
204     switch (image_info->interlace)
205     {
206       case NoInterlace:
207       default:
208       {
209         /*
210           No interlacing:  CMYKCMYKCMYKCMYKCMYKCMYK...
211         */
212         if (scene == 0)
213           {
214             length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
215             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
216               &count);
217           }
218         for (y=0; y < (ssize_t) image->extract_info.height; y++)
219         {
220           register const Quantum
221             *restrict p;
222
223           register Quantum
224             *restrict q;
225
226           register ssize_t
227             x;
228
229           if (count != (ssize_t) length)
230             {
231               ThrowFileException(exception,CorruptImageError,
232                 "UnexpectedEndOfFile",image->filename);
233               break;
234             }
235           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
236             exception);
237           if (q == (Quantum *) NULL)
238             break;
239           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
240             quantum_info,quantum_type,pixels,exception);
241           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
242             break;
243           if (((y-image->extract_info.y) >= 0) && 
244               ((y-image->extract_info.y) < (ssize_t) image->rows))
245             {
246               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
247                 canvas_image->columns,1,exception);
248               q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
249                 image->columns,1,exception);
250               if ((p == (const Quantum *) NULL) ||
251                   (q == (Quantum *) NULL))
252                 break;
253               for (x=0; x < (ssize_t) image->columns; x++)
254               {
255                 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
256                 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
257                 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
258                 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
259                 SetPixelAlpha(image,OpaqueAlpha,q);
260                 if (image->alpha_trait != UndefinedPixelTrait)
261                   SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
262                 p+=GetPixelChannels(canvas_image);
263                 q+=GetPixelChannels(image);
264               }
265               if (SyncAuthenticPixels(image,exception) == MagickFalse)
266                 break;
267             }
268           if (image->previous == (Image *) NULL)
269             {
270               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
271                 image->rows);
272               if (status == MagickFalse)
273                 break;
274             }
275           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
276             &count);
277         }
278         break;
279       }
280       case LineInterlace:
281       {
282         static QuantumType
283           quantum_types[5] =
284           {
285             CyanQuantum,
286             MagentaQuantum,
287             YellowQuantum,
288             BlackQuantum,
289             OpacityQuantum
290           };
291
292         /*
293           Line interlacing:  CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK...
294         */
295         if (scene == 0)
296           {
297             length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
298             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
299               &count);
300           }
301         for (y=0; y < (ssize_t) image->extract_info.height; y++)
302         {
303           register const Quantum
304             *restrict p;
305
306           register Quantum
307             *restrict q;
308
309           register ssize_t
310             x;
311
312           if (count != (ssize_t) length)
313             {
314               ThrowFileException(exception,CorruptImageError,
315                 "UnexpectedEndOfFile",image->filename);
316               break;
317             }
318           for (i=0; i < (image->alpha_trait != UndefinedPixelTrait ? 5 : 4); i++)
319           {
320             quantum_type=quantum_types[i];
321             q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
322               exception);
323             if (q == (Quantum *) NULL)
324               break;
325             length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
326               quantum_info,quantum_type,pixels,exception);
327             if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
328               break;
329             if (((y-image->extract_info.y) >= 0) && 
330                 ((y-image->extract_info.y) < (ssize_t) image->rows))
331               {
332                 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
333                   0,canvas_image->columns,1,exception);
334                 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
335                   image->columns,1,exception);
336                 if ((p == (const Quantum *) NULL) ||
337                     (q == (Quantum *) NULL))
338                   break;
339                 for (x=0; x < (ssize_t) image->columns; x++)
340                 {
341                   switch (quantum_type)
342                   {
343                     case CyanQuantum:
344                     {
345                       SetPixelCyan(image,GetPixelCyan(canvas_image,p),q);
346                       break;
347                     }
348                     case MagentaQuantum:
349                     {
350                       SetPixelMagenta(image,GetPixelMagenta(canvas_image,p),q);
351                       break;
352                     }
353                     case YellowQuantum:
354                     {
355                       SetPixelYellow(image,GetPixelYellow(canvas_image,p),q);
356                       break;
357                     }
358                     case BlackQuantum:
359                     {
360                       SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
361                       break;
362                     }
363                     case OpacityQuantum:
364                     {
365                       SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
366                       break;
367                     }
368                     default:
369                       break;
370                   }
371                   p+=GetPixelChannels(canvas_image);
372                   q+=GetPixelChannels(image);
373                 }
374                 if (SyncAuthenticPixels(image,exception) == MagickFalse)
375                   break;
376               }
377             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
378               &count);
379           }
380           if (image->previous == (Image *) NULL)
381             {
382               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
383                 image->rows);
384               if (status == MagickFalse)
385                 break;
386             }
387         }
388         break;
389       }
390       case PlaneInterlace:
391       {
392         /*
393           Plane interlacing:  CCCCCC...MMMMMM...YYYYYY...KKKKKK...
394         */
395         if (scene == 0)
396           {
397             length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
398             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
399               &count);
400           }
401         for (y=0; y < (ssize_t) image->extract_info.height; y++)
402         {
403           register const Quantum
404             *restrict p;
405
406           register Quantum
407             *restrict q;
408
409           register ssize_t
410             x;
411
412           if (count != (ssize_t) length)
413             {
414               ThrowFileException(exception,CorruptImageError,
415                 "UnexpectedEndOfFile",image->filename);
416               break;
417             }
418           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
419             exception);
420           if (q == (Quantum *) NULL)
421             break;
422           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
423             quantum_info,CyanQuantum,pixels,exception);
424           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
425             break;
426           if (((y-image->extract_info.y) >= 0) && 
427               ((y-image->extract_info.y) < (ssize_t) image->rows))
428             {
429               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
430                 canvas_image->columns,1,exception);
431               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
432                 image->columns,1,exception);
433               if ((p == (const Quantum *) NULL) ||
434                   (q == (Quantum *) NULL))
435                 break;
436               for (x=0; x < (ssize_t) image->columns; x++)
437               {
438                 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
439                 p+=GetPixelChannels(canvas_image);
440                 q+=GetPixelChannels(image);
441               }
442               if (SyncAuthenticPixels(image,exception) == MagickFalse)
443                 break;
444             }
445           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
446             &count);
447         }
448         if (image->previous == (Image *) NULL)
449           {
450             status=SetImageProgress(image,LoadImageTag,1,6);
451             if (status == MagickFalse)
452               break;
453           }
454         for (y=0; y < (ssize_t) image->extract_info.height; y++)
455         {
456           register const Quantum
457             *restrict p;
458
459           register Quantum
460             *restrict q;
461
462           register ssize_t
463             x;
464
465           if (count != (ssize_t) length)
466             {
467               ThrowFileException(exception,CorruptImageError,
468                 "UnexpectedEndOfFile",image->filename);
469               break;
470             }
471           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
472             exception);
473           if (q == (Quantum *) NULL)
474             break;
475           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
476             quantum_info,MagentaQuantum,pixels,exception);
477           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
478             break;
479           if (((y-image->extract_info.y) >= 0) && 
480               ((y-image->extract_info.y) < (ssize_t) image->rows))
481             {
482               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
483                 canvas_image->columns,1,exception);
484               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
485                 image->columns,1,exception);
486               if ((p == (const Quantum *) NULL) ||
487                   (q == (Quantum *) NULL))
488                 break;
489               for (x=0; x < (ssize_t) image->columns; x++)
490               {
491                 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
492                 p+=GetPixelChannels(canvas_image);
493                 q+=GetPixelChannels(image);
494               }
495               if (SyncAuthenticPixels(image,exception) == MagickFalse)
496                 break;
497            }
498           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
499             &count);
500         }
501         if (image->previous == (Image *) NULL)
502           {
503             status=SetImageProgress(image,LoadImageTag,2,6);
504             if (status == MagickFalse)
505               break;
506           }
507         for (y=0; y < (ssize_t) image->extract_info.height; y++)
508         {
509           register const Quantum
510             *restrict p;
511
512           register Quantum
513             *restrict q;
514
515           register ssize_t
516             x;
517
518           if (count != (ssize_t) length)
519             {
520               ThrowFileException(exception,CorruptImageError,
521                 "UnexpectedEndOfFile",image->filename);
522               break;
523             }
524           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
525             exception);
526           if (q == (Quantum *) NULL)
527             break;
528           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
529             quantum_info,YellowQuantum,pixels,exception);
530           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
531             break;
532           if (((y-image->extract_info.y) >= 0) && 
533               ((y-image->extract_info.y) < (ssize_t) image->rows))
534             {
535               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
536                 canvas_image->columns,1,exception);
537               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
538                 image->columns,1,exception);
539               if ((p == (const Quantum *) NULL) ||
540                   (q == (Quantum *) NULL))
541                 break;
542               for (x=0; x < (ssize_t) image->columns; x++)
543               {
544                 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
545                 p+=GetPixelChannels(canvas_image);
546                 q+=GetPixelChannels(image);
547               }
548               if (SyncAuthenticPixels(image,exception) == MagickFalse)
549                 break;
550             }
551           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
552             &count);
553         }
554         if (image->previous == (Image *) NULL)
555           {
556             status=SetImageProgress(image,LoadImageTag,3,6);
557             if (status == MagickFalse)
558               break;
559           }
560         for (y=0; y < (ssize_t) image->extract_info.height; y++)
561         {
562           register const Quantum
563             *restrict p;
564
565           register Quantum
566             *restrict q;
567
568           register ssize_t
569             x;
570
571           if (count != (ssize_t) length)
572             {
573               ThrowFileException(exception,CorruptImageError,
574                 "UnexpectedEndOfFile",image->filename);
575               break;
576             }
577           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
578             exception);
579           if (q == (Quantum *) NULL)
580             break;
581           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
582             quantum_info,BlackQuantum,pixels,exception);
583           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
584             break;
585           if (((y-image->extract_info.y) >= 0) && 
586               ((y-image->extract_info.y) < (ssize_t) image->rows))
587             {
588               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
589                 canvas_image->columns,1,exception);
590               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
591                 image->columns,1,exception);
592               if ((p == (const Quantum *) NULL) ||
593                   (q == (Quantum *) NULL))
594                 break;
595               for (x=0; x < (ssize_t) image->columns; x++)
596               {
597                 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
598                 p+=GetPixelChannels(canvas_image);
599                 q+=GetPixelChannels(image);
600               }
601               if (SyncAuthenticPixels(image,exception) == MagickFalse)
602                 break;
603             }
604           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
605             &count);
606         }
607         if (image->previous == (Image *) NULL)
608           {
609             status=SetImageProgress(image,LoadImageTag,4,6);
610             if (status == MagickFalse)
611               break;
612           }
613         if (image->alpha_trait != UndefinedPixelTrait)
614           {
615             for (y=0; y < (ssize_t) image->extract_info.height; y++)
616             {
617               register const Quantum
618                 *restrict p;
619
620               register Quantum
621                 *restrict q;
622
623               register ssize_t
624                 x;
625
626               if (count != (ssize_t) length)
627                 {
628                   ThrowFileException(exception,CorruptImageError,
629                     "UnexpectedEndOfFile",image->filename);
630                   break;
631                 }
632               q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
633                 exception);
634               if (q == (Quantum *) NULL)
635                 break;
636               length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
637                 quantum_info,AlphaQuantum,pixels,exception);
638               if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
639                 break;
640               if (((y-image->extract_info.y) >= 0) && 
641                   ((y-image->extract_info.y) < (ssize_t) image->rows))
642                 {
643                   p=GetVirtualPixels(canvas_image,
644                     canvas_image->extract_info.x,0,canvas_image->columns,1,
645                     exception);
646                   q=GetAuthenticPixels(image,0,y-image->extract_info.y,
647                     image->columns,1,exception);
648                   if ((p == (const Quantum *) NULL) ||
649                       (q == (Quantum *) NULL))
650                     break;
651                   for (x=0; x < (ssize_t) image->columns; x++)
652                   {
653                     SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
654                     p+=GetPixelChannels(canvas_image);
655                     q+=GetPixelChannels(image);
656                   }
657                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
658                     break;
659                 }
660               pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
661                 &count);
662             }
663             if (image->previous == (Image *) NULL)
664               {
665                 status=SetImageProgress(image,LoadImageTag,5,6);
666                 if (status == MagickFalse)
667                   break;
668               }
669           }
670         if (image->previous == (Image *) NULL)
671           {
672             status=SetImageProgress(image,LoadImageTag,6,6);
673             if (status == MagickFalse)
674               break;
675           }
676         break;
677       }
678       case PartitionInterlace:
679       {
680         /*
681           Partition interlacing:  CCCCCC..., MMMMMM..., YYYYYY..., KKKKKK...
682         */
683         AppendImageFormat("C",image->filename);
684         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
685         if (status == MagickFalse)
686           {
687             canvas_image=DestroyImageList(canvas_image);
688             image=DestroyImageList(image);
689             return((Image *) NULL);
690           }
691         if (DiscardBlobBytes(image,image->offset) == MagickFalse)
692           ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
693             image->filename);
694         length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
695         for (i=0; i < (ssize_t) scene; i++)
696           for (y=0; y < (ssize_t) image->extract_info.height; y++)
697           {
698             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
699               &count);
700             if (count != (ssize_t) length)
701               {
702                 ThrowFileException(exception,CorruptImageError,
703                   "UnexpectedEndOfFile",image->filename);
704                 break;
705               }
706           }
707         pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
708           &count);
709         for (y=0; y < (ssize_t) image->extract_info.height; y++)
710         {
711           register const Quantum
712             *restrict p;
713
714           register Quantum
715             *restrict q;
716
717           register ssize_t
718             x;
719
720           if (count != (ssize_t) length)
721             {
722               ThrowFileException(exception,CorruptImageError,
723                 "UnexpectedEndOfFile",image->filename);
724               break;
725             }
726           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
727             exception);
728           if (q == (Quantum *) NULL)
729             break;
730           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
731             quantum_info,CyanQuantum,pixels,exception);
732           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
733             break;
734           if (((y-image->extract_info.y) >= 0) && 
735               ((y-image->extract_info.y) < (ssize_t) image->rows))
736             {
737               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
738                 canvas_image->columns,1,exception);
739               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
740                 image->columns,1,exception);
741               if ((p == (const Quantum *) NULL) ||
742                   (q == (Quantum *) NULL))
743                 break;
744               for (x=0; x < (ssize_t) image->columns; x++)
745               {
746                 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
747                 p+=GetPixelChannels(canvas_image);
748                 q+=GetPixelChannels(image);
749               }
750               if (SyncAuthenticPixels(image,exception) == MagickFalse)
751                 break;
752             }
753           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
754             &count);
755         }
756         if (image->previous == (Image *) NULL)
757           {
758             status=SetImageProgress(image,LoadImageTag,1,5);
759             if (status == MagickFalse)
760               break;
761           }
762         (void) CloseBlob(image);
763         AppendImageFormat("M",image->filename);
764         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
765         if (status == MagickFalse)
766           {
767             canvas_image=DestroyImageList(canvas_image);
768             image=DestroyImageList(image);
769             return((Image *) NULL);
770           }
771         length=GetQuantumExtent(canvas_image,quantum_info,MagentaQuantum);
772         for (i=0; i < (ssize_t) scene; i++)
773           for (y=0; y < (ssize_t) image->extract_info.height; y++)
774           {
775             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
776               &count);
777             if (count != (ssize_t) length)
778               {
779                 ThrowFileException(exception,CorruptImageError,
780                   "UnexpectedEndOfFile",image->filename);
781                 break;
782               }
783           }
784         pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
785           &count);
786         for (y=0; y < (ssize_t) image->extract_info.height; y++)
787         {
788           register const Quantum
789             *restrict p;
790
791           register Quantum
792             *restrict q;
793
794           register ssize_t
795             x;
796
797           if (count != (ssize_t) length)
798             {
799               ThrowFileException(exception,CorruptImageError,
800                 "UnexpectedEndOfFile",image->filename);
801               break;
802             }
803           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
804             exception);
805           if (q == (Quantum *) NULL)
806             break;
807           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
808             quantum_info,MagentaQuantum,pixels,exception);
809           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
810             break;
811           if (((y-image->extract_info.y) >= 0) && 
812               ((y-image->extract_info.y) < (ssize_t) image->rows))
813             {
814               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
815                 canvas_image->columns,1,exception);
816               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
817                 image->columns,1,exception);
818               if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
819                 break;
820               for (x=0; x < (ssize_t) image->columns; x++)
821               {
822                 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
823                 p+=GetPixelChannels(canvas_image);
824                 q+=GetPixelChannels(image);
825               }
826               if (SyncAuthenticPixels(image,exception) == MagickFalse)
827                 break;
828            }
829           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
830             &count);
831         }
832         if (image->previous == (Image *) NULL)
833           {
834             status=SetImageProgress(image,LoadImageTag,2,5);
835             if (status == MagickFalse)
836               break;
837           }
838         (void) CloseBlob(image);
839         AppendImageFormat("Y",image->filename);
840         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
841         if (status == MagickFalse)
842           {
843             canvas_image=DestroyImageList(canvas_image);
844             image=DestroyImageList(image);
845             return((Image *) NULL);
846           }
847         length=GetQuantumExtent(canvas_image,quantum_info,YellowQuantum);
848         for (i=0; i < (ssize_t) scene; i++)
849           for (y=0; y < (ssize_t) image->extract_info.height; y++)
850           {
851             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
852               &count);
853             if (count != (ssize_t) length)
854               {
855                 ThrowFileException(exception,CorruptImageError,
856                   "UnexpectedEndOfFile",image->filename);
857                 break;
858               }
859           }
860         pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
861           &count);
862         for (y=0; y < (ssize_t) image->extract_info.height; y++)
863         {
864           register const Quantum
865             *restrict p;
866
867           register Quantum
868             *restrict q;
869
870           register ssize_t
871             x;
872
873           if (count != (ssize_t) length)
874             {
875               ThrowFileException(exception,CorruptImageError,
876                 "UnexpectedEndOfFile",image->filename);
877               break;
878             }
879           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
880             exception);
881           if (q == (Quantum *) NULL)
882             break;
883           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
884             quantum_info,YellowQuantum,pixels,exception);
885           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
886             break;
887           if (((y-image->extract_info.y) >= 0) && 
888               ((y-image->extract_info.y) < (ssize_t) image->rows))
889             {
890               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
891                 canvas_image->columns,1,exception);
892               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
893                 image->columns,1,exception);
894               if ((p == (const Quantum *) NULL) ||
895                   (q == (Quantum *) NULL))
896                 break;
897               for (x=0; x < (ssize_t) image->columns; x++)
898               {
899                 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
900                 p+=GetPixelChannels(canvas_image);
901                 q+=GetPixelChannels(image);
902               }
903               if (SyncAuthenticPixels(image,exception) == MagickFalse)
904                 break;
905            }
906           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
907             &count);
908         }
909         if (image->previous == (Image *) NULL)
910           {
911             status=SetImageProgress(image,LoadImageTag,3,5);
912             if (status == MagickFalse)
913               break;
914           }
915         (void) CloseBlob(image);
916         AppendImageFormat("K",image->filename);
917         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
918         if (status == MagickFalse)
919           {
920             canvas_image=DestroyImageList(canvas_image);
921             image=DestroyImageList(image);
922             return((Image *) NULL);
923           }
924         length=GetQuantumExtent(canvas_image,quantum_info,BlackQuantum);
925         for (i=0; i < (ssize_t) scene; i++)
926           for (y=0; y < (ssize_t) image->extract_info.height; y++)
927           {
928             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
929               &count);
930             if (count != (ssize_t) length)
931               {
932                 ThrowFileException(exception,CorruptImageError,
933                   "UnexpectedEndOfFile",image->filename);
934                 break;
935               }
936           }
937         pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
938           &count);
939         for (y=0; y < (ssize_t) image->extract_info.height; y++)
940         {
941           register const Quantum
942             *restrict p;
943
944           register Quantum
945             *restrict q;
946
947           register ssize_t
948             x;
949
950           if (count != (ssize_t) length)
951             {
952               ThrowFileException(exception,CorruptImageError,
953                 "UnexpectedEndOfFile",image->filename);
954               break;
955             }
956           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
957             exception);
958           if (q == (Quantum *) NULL)
959             break;
960           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
961             quantum_info,BlackQuantum,pixels,exception);
962           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
963             break;
964           if (((y-image->extract_info.y) >= 0) && 
965               ((y-image->extract_info.y) < (ssize_t) image->rows))
966             {
967               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
968                 canvas_image->columns,1,exception);
969               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
970                 image->columns,1,exception);
971               if ((p == (const Quantum *) NULL) ||
972                   (q == (Quantum *) NULL))
973                 break;
974               for (x=0; x < (ssize_t) image->columns; x++)
975               {
976                 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
977                 p+=GetPixelChannels(canvas_image);
978                 q+=GetPixelChannels(image);
979               }
980               if (SyncAuthenticPixels(image,exception) == MagickFalse)
981                 break;
982            }
983           pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
984             &count);
985         }
986         if (image->previous == (Image *) NULL)
987           {
988             status=SetImageProgress(image,LoadImageTag,3,5);
989             if (status == MagickFalse)
990               break;
991           }
992         if (image->alpha_trait != UndefinedPixelTrait)
993           {
994             (void) CloseBlob(image);
995             AppendImageFormat("A",image->filename);
996             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
997             if (status == MagickFalse)
998               {
999                 canvas_image=DestroyImageList(canvas_image);
1000                 image=DestroyImageList(image);
1001                 return((Image *) NULL);
1002               }
1003             length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
1004             for (i=0; i < (ssize_t) scene; i++)
1005               for (y=0; y < (ssize_t) image->extract_info.height; y++)
1006               {
1007                 pixels=ReadBlobStream(image,length,
1008                   GetQuantumPixels(quantum_info),&count);
1009                 if (count != (ssize_t) length)
1010                   {
1011                     ThrowFileException(exception,CorruptImageError,
1012                       "UnexpectedEndOfFile",image->filename);
1013                     break;
1014                   }
1015               }
1016             pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
1017               &count);
1018             for (y=0; y < (ssize_t) image->extract_info.height; y++)
1019             {
1020               register const Quantum
1021                 *restrict p;
1022
1023               register Quantum
1024                 *restrict q;
1025
1026               register ssize_t
1027                 x;
1028
1029               if (count != (ssize_t) length)
1030                 {
1031                   ThrowFileException(exception,CorruptImageError,
1032                     "UnexpectedEndOfFile",image->filename);
1033                   break;
1034                 }
1035               q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
1036                 exception);
1037               if (q == (Quantum *) NULL)
1038                 break;
1039               length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
1040                 quantum_info,YellowQuantum,pixels,exception);
1041               if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
1042                 break;
1043               if (((y-image->extract_info.y) >= 0) && 
1044                   ((y-image->extract_info.y) < (ssize_t) image->rows))
1045                 {
1046                   p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
1047                     0,canvas_image->columns,1,exception);
1048                   q=GetAuthenticPixels(image,0,y-image->extract_info.y,
1049                     image->columns,1,exception);
1050                   if ((p == (const Quantum *) NULL) ||
1051                       (q == (Quantum *) NULL))
1052                     break;
1053                   for (x=0; x < (ssize_t) image->columns; x++)
1054                   {
1055                     SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
1056                     p+=GetPixelChannels(canvas_image);
1057                     q+=GetPixelChannels(image);
1058                   }
1059                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
1060                     break;
1061                }
1062               pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
1063                 &count);
1064             }
1065             if (image->previous == (Image *) NULL)
1066               {
1067                 status=SetImageProgress(image,LoadImageTag,4,5);
1068                 if (status == MagickFalse)
1069                   break;
1070               }
1071           }
1072         if (image->previous == (Image *) NULL)
1073           {
1074             status=SetImageProgress(image,LoadImageTag,5,5);
1075             if (status == MagickFalse)
1076               break;
1077           }
1078         break;
1079       }
1080     }
1081     SetQuantumImageType(image,quantum_type);
1082     /*
1083       Proceed to next image.
1084     */
1085     if (image_info->number_scenes != 0)
1086       if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1087         break;
1088     if (count == (ssize_t) length)
1089       {
1090         /*
1091           Allocate next image structure.
1092         */
1093         AcquireNextImage(image_info,image,exception);
1094         if (GetNextImageInList(image) == (Image *) NULL)
1095           {
1096             image=DestroyImageList(image);
1097             return((Image *) NULL);
1098           }
1099         image=SyncNextImageInList(image);
1100         status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1101           GetBlobSize(image));
1102         if (status == MagickFalse)
1103           break;
1104       }
1105     scene++;
1106   } while (count == (ssize_t) length);
1107   quantum_info=DestroyQuantumInfo(quantum_info);
1108   canvas_image=DestroyImage(canvas_image);
1109   (void) CloseBlob(image);
1110   return(GetFirstImageInList(image));
1111 }
1112 \f
1113 /*
1114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115 %                                                                             %
1116 %                                                                             %
1117 %                                                                             %
1118 %   R e g i s t e r C M Y K I m a g e                                         %
1119 %                                                                             %
1120 %                                                                             %
1121 %                                                                             %
1122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 %
1124 %  RegisterCMYKImage() adds attributes for the CMYK image format to
1125 %  the list of supported formats.  The attributes include the image format
1126 %  tag, a method to read and/or write the format, whether the format
1127 %  supports the saving of more than one frame to the same file or blob,
1128 %  whether the format supports native in-memory I/O, and a brief
1129 %  description of the format.
1130 %
1131 %  The format of the RegisterCMYKImage method is:
1132 %
1133 %      size_t RegisterCMYKImage(void)
1134 %
1135 */
1136 ModuleExport size_t RegisterCMYKImage(void)
1137 {
1138   MagickInfo
1139     *entry;
1140
1141   entry=SetMagickInfo("CMYK");
1142   entry->decoder=(DecodeImageHandler *) ReadCMYKImage;
1143   entry->encoder=(EncodeImageHandler *) WriteCMYKImage;
1144   entry->raw=MagickTrue;
1145   entry->endian_support=MagickTrue;
1146   entry->description=ConstantString("Raw cyan, magenta, yellow, and black "
1147     "samples");
1148   entry->module=ConstantString("CMYK");
1149   (void) RegisterMagickInfo(entry);
1150   entry=SetMagickInfo("CMYKA");
1151   entry->decoder=(DecodeImageHandler *) ReadCMYKImage;
1152   entry->encoder=(EncodeImageHandler *) WriteCMYKImage;
1153   entry->raw=MagickTrue;
1154   entry->endian_support=MagickTrue;
1155   entry->description=ConstantString("Raw cyan, magenta, yellow, black, and "
1156     "alpha samples");
1157   entry->module=ConstantString("CMYK");
1158   (void) RegisterMagickInfo(entry);
1159   return(MagickImageCoderSignature);
1160 }
1161 \f
1162 /*
1163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164 %                                                                             %
1165 %                                                                             %
1166 %                                                                             %
1167 %   U n r e g i s t e r C M Y K I m a g e                                     %
1168 %                                                                             %
1169 %                                                                             %
1170 %                                                                             %
1171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1172 %
1173 %  UnregisterCMYKImage() removes format registrations made by the
1174 %  CMYK module from the list of supported formats.
1175 %
1176 %  The format of the UnregisterCMYKImage method is:
1177 %
1178 %      UnregisterCMYKImage(void)
1179 %
1180 */
1181 ModuleExport void UnregisterCMYKImage(void)
1182 {
1183   (void) UnregisterMagickInfo("CMYK");
1184   (void) UnregisterMagickInfo("CMYKA");
1185 }
1186 \f
1187 /*
1188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189 %                                                                             %
1190 %                                                                             %
1191 %                                                                             %
1192 %   W r i t e C M Y K I m a g e                                               %
1193 %                                                                             %
1194 %                                                                             %
1195 %                                                                             %
1196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 %
1198 %  WriteCMYKImage() writes an image to a file in cyan, magenta, yellow, and
1199 %  black,rasterfile format.
1200 %
1201 %  The format of the WriteCMYKImage method is:
1202 %
1203 %      MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
1204 %        Image *image,ExceptionInfo *exception)
1205 %
1206 %  A description of each parameter follows.
1207 %
1208 %    o image_info: the image info.
1209 %
1210 %    o image:  The image.
1211 %
1212 %    o exception: return any errors or warnings in this structure.
1213 %
1214 */
1215 static MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
1216   Image *image,ExceptionInfo *exception)
1217 {
1218   MagickBooleanType
1219     status;
1220
1221   MagickOffsetType
1222     scene;
1223
1224   QuantumInfo
1225     *quantum_info;
1226
1227   QuantumType
1228     quantum_type;
1229
1230   size_t
1231     length;
1232
1233   ssize_t
1234     count,
1235     y;
1236
1237   unsigned char
1238     *pixels;
1239
1240   /*
1241     Allocate memory for pixels.
1242   */
1243   assert(image_info != (const ImageInfo *) NULL);
1244   assert(image_info->signature == MagickSignature);
1245   assert(image != (Image *) NULL);
1246   assert(image->signature == MagickSignature);
1247   if (image->debug != MagickFalse)
1248     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1249   if (image_info->interlace != PartitionInterlace)
1250     {
1251       /*
1252         Open output image file.
1253       */
1254       status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1255       if (status == MagickFalse)
1256         return(status);
1257     }
1258   scene=0;
1259   do
1260   {
1261     /*
1262       Convert MIFF to CMYK raster pixels.
1263     */
1264     if (image->colorspace != CMYKColorspace)
1265       (void) TransformImageColorspace(image,CMYKColorspace,exception);
1266     quantum_type=CMYKQuantum;
1267     if (LocaleCompare(image_info->magick,"CMYKA") == 0)
1268       {
1269         quantum_type=CMYKAQuantum;
1270         if (image->alpha_trait == UndefinedPixelTrait)
1271           (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1272       }
1273     quantum_info=AcquireQuantumInfo(image_info,image);
1274     if (quantum_info == (QuantumInfo *) NULL)
1275       ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1276     pixels=GetQuantumPixels(quantum_info);
1277     switch (image_info->interlace)
1278     {
1279       case NoInterlace:
1280       default:
1281       {
1282         /*
1283           No interlacing:  CMYKCMYKCMYKCMYKCMYKCMYK...
1284         */
1285         for (y=0; y < (ssize_t) image->rows; y++)
1286         {
1287           register const Quantum
1288             *restrict p;
1289
1290           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1291           if (p == (const Quantum *) NULL)
1292             break;
1293           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1294             quantum_type,pixels,exception);
1295           count=WriteBlob(image,length,pixels);
1296           if (count != (ssize_t) length)
1297             break;
1298           if (image->previous == (Image *) NULL)
1299             {
1300               status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1301                 image->rows);
1302               if (status == MagickFalse)
1303                 break;
1304             }
1305         }
1306         break;
1307       }
1308       case LineInterlace:
1309       {
1310         /*
1311           Line interlacing:  CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK...
1312         */
1313         for (y=0; y < (ssize_t) image->rows; y++)
1314         {
1315           register const Quantum
1316             *restrict p;
1317
1318           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1319           if (p == (const Quantum *) NULL)
1320             break;
1321           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1322             CyanQuantum,pixels,exception);
1323           count=WriteBlob(image,length,pixels);
1324           if (count != (ssize_t) length)
1325             break;
1326           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1327             MagentaQuantum,pixels,exception);
1328           count=WriteBlob(image,length,pixels);
1329           if (count != (ssize_t) length)
1330             break;
1331           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1332             YellowQuantum,pixels,exception);
1333           count=WriteBlob(image,length,pixels);
1334           if (count != (ssize_t) length)
1335             break;
1336           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1337             BlackQuantum,pixels,exception);
1338           count=WriteBlob(image,length,pixels);
1339           if (count != (ssize_t) length)
1340             break;
1341           if (quantum_type == CMYKAQuantum)
1342             {
1343               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1344                 AlphaQuantum,pixels,exception);
1345               count=WriteBlob(image,length,pixels);
1346               if (count != (ssize_t) length)
1347                 break;
1348             }
1349           if (image->previous == (Image *) NULL)
1350             {
1351               status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1352                 image->rows);
1353               if (status == MagickFalse)
1354                 break;
1355             }
1356         }
1357         break;
1358       }
1359       case PlaneInterlace:
1360       {
1361         /*
1362           Plane interlacing:  CCCCCC...MMMMMM...YYYYYY...KKKKKK...
1363         */
1364         for (y=0; y < (ssize_t) image->rows; y++)
1365         {
1366           register const Quantum
1367             *restrict p;
1368
1369           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1370           if (p == (const Quantum *) NULL)
1371             break;
1372           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1373             CyanQuantum,pixels,exception);
1374           count=WriteBlob(image,length,pixels);
1375           if (count != (ssize_t) length)
1376             break;
1377         }
1378         if (image->previous == (Image *) NULL)
1379           {
1380             status=SetImageProgress(image,SaveImageTag,1,6);
1381             if (status == MagickFalse)
1382               break;
1383           }
1384         for (y=0; y < (ssize_t) image->rows; y++)
1385         {
1386           register const Quantum
1387             *restrict p;
1388
1389           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1390           if (p == (const Quantum *) NULL)
1391             break;
1392           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1393             MagentaQuantum,pixels,exception);
1394           count=WriteBlob(image,length,pixels);
1395           if (count != (ssize_t) length)
1396             break;
1397         }
1398         if (image->previous == (Image *) NULL)
1399           {
1400             status=SetImageProgress(image,SaveImageTag,2,6);
1401             if (status == MagickFalse)
1402               break;
1403           }
1404         for (y=0; y < (ssize_t) image->rows; y++)
1405         {
1406           register const Quantum
1407             *restrict p;
1408
1409           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1410           if (p == (const Quantum *) NULL)
1411             break;
1412           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1413             YellowQuantum,pixels,exception);
1414           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,3,6);
1421             if (status == MagickFalse)
1422               break;
1423           }
1424         for (y=0; y < (ssize_t) image->rows; y++)
1425         {
1426           register const Quantum
1427             *restrict p;
1428
1429           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1430           if (p == (const Quantum *) NULL)
1431             break;
1432           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1433             BlackQuantum,pixels,exception);
1434           count=WriteBlob(image,length,pixels);
1435           if (count != (ssize_t) length)
1436             break;
1437         }
1438         if (image->previous == (Image *) NULL)
1439           {
1440             status=SetImageProgress(image,SaveImageTag,4,6);
1441             if (status == MagickFalse)
1442               break;
1443           }
1444         if (quantum_type == CMYKAQuantum)
1445           {
1446             for (y=0; y < (ssize_t) image->rows; y++)
1447             {
1448               register const Quantum
1449                 *restrict p;
1450
1451               p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1452               if (p == (const Quantum *) NULL)
1453                 break;
1454               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1455                 AlphaQuantum,pixels,exception);
1456               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,5,6);
1463                 if (status == MagickFalse)
1464                   break;
1465               }
1466           }
1467         if (image_info->interlace == PartitionInterlace)
1468           (void) CopyMagickString(image->filename,image_info->filename,
1469             MaxTextExtent);
1470         if (image->previous == (Image *) NULL)
1471           {
1472             status=SetImageProgress(image,SaveImageTag,6,6);
1473             if (status == MagickFalse)
1474               break;
1475           }
1476         break;
1477       }
1478       case PartitionInterlace:
1479       {
1480         /*
1481           Partition interlacing:  CCCCCC..., MMMMMM..., YYYYYY..., KKKKKK...
1482         */
1483         AppendImageFormat("C",image->filename);
1484         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1485           AppendBinaryBlobMode,exception);
1486         if (status == MagickFalse)
1487           return(status);
1488         for (y=0; y < (ssize_t) image->rows; y++)
1489         {
1490           register const Quantum
1491             *restrict p;
1492
1493           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1494           if (p == (const Quantum *) NULL)
1495             break;
1496           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1497             CyanQuantum,pixels,exception);
1498           count=WriteBlob(image,length,pixels);
1499           if (count != (ssize_t) length)
1500             break;
1501         }
1502         if (image->previous == (Image *) NULL)
1503           {
1504             status=SetImageProgress(image,SaveImageTag,1,6);
1505             if (status == MagickFalse)
1506               break;
1507           }
1508         (void) CloseBlob(image);
1509         AppendImageFormat("M",image->filename);
1510         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1511           AppendBinaryBlobMode,exception);
1512         if (status == MagickFalse)
1513           return(status);
1514         for (y=0; y < (ssize_t) image->rows; y++)
1515         {
1516           register const Quantum
1517             *restrict p;
1518
1519           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1520           if (p == (const Quantum *) NULL)
1521             break;
1522           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1523             MagentaQuantum,pixels,exception);
1524           count=WriteBlob(image,length,pixels);
1525           if (count != (ssize_t) length)
1526             break;
1527         }
1528         if (image->previous == (Image *) NULL)
1529           {
1530             status=SetImageProgress(image,SaveImageTag,2,6);
1531             if (status == MagickFalse)
1532               break;
1533           }
1534         (void) CloseBlob(image);
1535         AppendImageFormat("Y",image->filename);
1536         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1537           AppendBinaryBlobMode,exception);
1538         if (status == MagickFalse)
1539           return(status);
1540         for (y=0; y < (ssize_t) image->rows; y++)
1541         {
1542           register const Quantum
1543             *restrict p;
1544
1545           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1546           if (p == (const Quantum *) NULL)
1547             break;
1548           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1549             YellowQuantum,pixels,exception);
1550           count=WriteBlob(image,length,pixels);
1551           if (count != (ssize_t) length)
1552             break;
1553         }
1554         if (image->previous == (Image *) NULL)
1555           {
1556             status=SetImageProgress(image,SaveImageTag,3,6);
1557             if (status == MagickFalse)
1558               break;
1559           }
1560         (void) CloseBlob(image);
1561         AppendImageFormat("K",image->filename);
1562         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1563           AppendBinaryBlobMode,exception);
1564         if (status == MagickFalse)
1565           return(status);
1566         for (y=0; y < (ssize_t) image->rows; y++)
1567         {
1568           register const Quantum
1569             *restrict p;
1570
1571           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1572           if (p == (const Quantum *) NULL)
1573             break;
1574           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1575             BlackQuantum,pixels,exception);
1576           count=WriteBlob(image,length,pixels);
1577           if (count != (ssize_t) length)
1578             break;
1579         }
1580         if (image->previous == (Image *) NULL)
1581           {
1582             status=SetImageProgress(image,SaveImageTag,4,6);
1583             if (status == MagickFalse)
1584               break;
1585           }
1586         if (quantum_type == CMYKAQuantum)
1587           {
1588             (void) CloseBlob(image);
1589             AppendImageFormat("A",image->filename);
1590             status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1591               AppendBinaryBlobMode,exception);
1592             if (status == MagickFalse)
1593               return(status);
1594             for (y=0; y < (ssize_t) image->rows; y++)
1595             {
1596               register const Quantum
1597                 *restrict p;
1598
1599               p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1600               if (p == (const Quantum *) NULL)
1601                 break;
1602               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1603                 AlphaQuantum,pixels,exception);
1604               count=WriteBlob(image,length,pixels);
1605               if (count != (ssize_t) length)
1606                 break;
1607             }
1608             if (image->previous == (Image *) NULL)
1609               {
1610                 status=SetImageProgress(image,SaveImageTag,5,6);
1611                 if (status == MagickFalse)
1612                   break;
1613               }
1614           }
1615         (void) CloseBlob(image);
1616         (void) CopyMagickString(image->filename,image_info->filename,
1617           MaxTextExtent);
1618         if (image->previous == (Image *) NULL)
1619           {
1620             status=SetImageProgress(image,SaveImageTag,6,6);
1621             if (status == MagickFalse)
1622               break;
1623           }
1624         break;
1625       }
1626     }
1627     quantum_info=DestroyQuantumInfo(quantum_info);
1628     if (GetNextImageInList(image) == (Image *) NULL)
1629       break;
1630     image=SyncNextImageInList(image);
1631     status=SetImageProgress(image,SaveImagesTag,scene++,
1632       GetImageListLength(image));
1633     if (status == MagickFalse)
1634       break;
1635   } while (image_info->adjoin != MagickFalse);
1636   (void) CloseBlob(image);
1637   return(MagickTrue);
1638 }