2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write RAW CMYK Image Format %
20 % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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"
69 static MagickBooleanType
70 WriteCMYKImage(const ImageInfo *,Image *,ExceptionInfo *);
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % R e a d C M Y K I m a g e %
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
87 % The format of the ReadCMYKImage method is:
89 % Image *ReadCMYKImage(const ImageInfo *image_info,
90 % ExceptionInfo *exception)
92 % A description of each parameter follows:
94 % o image_info: the image info.
96 % o exception: return any errors or warnings in this structure.
99 static Image *ReadCMYKImage(const ImageInfo *image_info,
100 ExceptionInfo *exception)
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)
147 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
148 if (status == MagickFalse)
150 image=DestroyImageList(image);
151 return((Image *) NULL);
153 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
154 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
158 Create virtual canvas to support cropping (i.e. image.cmyk[100x100+10+20]).
160 canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
162 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
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)
170 quantum_type=CMYKAQuantum;
171 image->alpha_trait=BlendPixelTrait;
173 if (image_info->number_scenes != 0)
174 while (image->scene < image_info->scene)
180 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
181 for (y=0; y < (ssize_t) image->rows; y++)
183 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
185 if (count != (ssize_t) length)
195 Read pixels to virtual canvas image then push to image.
197 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
198 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
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)
210 No interlacing: CMYKCMYKCMYKCMYKCMYKCMYK...
214 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
215 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
218 for (y=0; y < (ssize_t) image->extract_info.height; y++)
220 register const Quantum
229 if (count != (ssize_t) length)
231 ThrowFileException(exception,CorruptImageError,
232 "UnexpectedEndOfFile",image->filename);
235 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
237 if (q == (Quantum *) NULL)
239 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
240 quantum_info,quantum_type,pixels,exception);
241 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
243 if (((y-image->extract_info.y) >= 0) &&
244 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
253 for (x=0; x < (ssize_t) image->columns; x++)
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);
265 if (SyncAuthenticPixels(image,exception) == MagickFalse)
268 if (image->previous == (Image *) NULL)
270 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
272 if (status == MagickFalse)
275 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
293 Line interlacing: CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK...
297 length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
298 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
301 for (y=0; y < (ssize_t) image->extract_info.height; y++)
303 register const Quantum
312 if (count != (ssize_t) length)
314 ThrowFileException(exception,CorruptImageError,
315 "UnexpectedEndOfFile",image->filename);
318 for (i=0; i < (image->alpha_trait != UndefinedPixelTrait ? 5 : 4); i++)
320 quantum_type=quantum_types[i];
321 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
323 if (q == (Quantum *) NULL)
325 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
326 quantum_info,quantum_type,pixels,exception);
327 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
329 if (((y-image->extract_info.y) >= 0) &&
330 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
339 for (x=0; x < (ssize_t) image->columns; x++)
341 switch (quantum_type)
345 SetPixelCyan(image,GetPixelCyan(canvas_image,p),q);
350 SetPixelMagenta(image,GetPixelMagenta(canvas_image,p),q);
355 SetPixelYellow(image,GetPixelYellow(canvas_image,p),q);
360 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
365 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
371 p+=GetPixelChannels(canvas_image);
372 q+=GetPixelChannels(image);
374 if (SyncAuthenticPixels(image,exception) == MagickFalse)
377 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
380 if (image->previous == (Image *) NULL)
382 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
384 if (status == MagickFalse)
393 Plane interlacing: CCCCCC...MMMMMM...YYYYYY...KKKKKK...
397 length=GetQuantumExtent(canvas_image,quantum_info,CyanQuantum);
398 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
401 for (y=0; y < (ssize_t) image->extract_info.height; y++)
403 register const Quantum
412 if (count != (ssize_t) length)
414 ThrowFileException(exception,CorruptImageError,
415 "UnexpectedEndOfFile",image->filename);
418 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
420 if (q == (Quantum *) NULL)
422 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
423 quantum_info,CyanQuantum,pixels,exception);
424 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
426 if (((y-image->extract_info.y) >= 0) &&
427 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
436 for (x=0; x < (ssize_t) image->columns; x++)
438 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
439 p+=GetPixelChannels(canvas_image);
440 q+=GetPixelChannels(image);
442 if (SyncAuthenticPixels(image,exception) == MagickFalse)
445 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
448 if (image->previous == (Image *) NULL)
450 status=SetImageProgress(image,LoadImageTag,1,6);
451 if (status == MagickFalse)
454 for (y=0; y < (ssize_t) image->extract_info.height; y++)
456 register const Quantum
465 if (count != (ssize_t) length)
467 ThrowFileException(exception,CorruptImageError,
468 "UnexpectedEndOfFile",image->filename);
471 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
473 if (q == (Quantum *) NULL)
475 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
476 quantum_info,MagentaQuantum,pixels,exception);
477 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
479 if (((y-image->extract_info.y) >= 0) &&
480 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
489 for (x=0; x < (ssize_t) image->columns; x++)
491 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
492 p+=GetPixelChannels(canvas_image);
493 q+=GetPixelChannels(image);
495 if (SyncAuthenticPixels(image,exception) == MagickFalse)
498 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
501 if (image->previous == (Image *) NULL)
503 status=SetImageProgress(image,LoadImageTag,2,6);
504 if (status == MagickFalse)
507 for (y=0; y < (ssize_t) image->extract_info.height; y++)
509 register const Quantum
518 if (count != (ssize_t) length)
520 ThrowFileException(exception,CorruptImageError,
521 "UnexpectedEndOfFile",image->filename);
524 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
526 if (q == (Quantum *) NULL)
528 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
529 quantum_info,YellowQuantum,pixels,exception);
530 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
532 if (((y-image->extract_info.y) >= 0) &&
533 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
542 for (x=0; x < (ssize_t) image->columns; x++)
544 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
545 p+=GetPixelChannels(canvas_image);
546 q+=GetPixelChannels(image);
548 if (SyncAuthenticPixels(image,exception) == MagickFalse)
551 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
554 if (image->previous == (Image *) NULL)
556 status=SetImageProgress(image,LoadImageTag,3,6);
557 if (status == MagickFalse)
560 for (y=0; y < (ssize_t) image->extract_info.height; y++)
562 register const Quantum
571 if (count != (ssize_t) length)
573 ThrowFileException(exception,CorruptImageError,
574 "UnexpectedEndOfFile",image->filename);
577 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
579 if (q == (Quantum *) NULL)
581 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
582 quantum_info,BlackQuantum,pixels,exception);
583 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
585 if (((y-image->extract_info.y) >= 0) &&
586 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
595 for (x=0; x < (ssize_t) image->columns; x++)
597 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
598 p+=GetPixelChannels(canvas_image);
599 q+=GetPixelChannels(image);
601 if (SyncAuthenticPixels(image,exception) == MagickFalse)
604 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
607 if (image->previous == (Image *) NULL)
609 status=SetImageProgress(image,LoadImageTag,4,6);
610 if (status == MagickFalse)
613 if (image->alpha_trait != UndefinedPixelTrait)
615 for (y=0; y < (ssize_t) image->extract_info.height; y++)
617 register const Quantum
626 if (count != (ssize_t) length)
628 ThrowFileException(exception,CorruptImageError,
629 "UnexpectedEndOfFile",image->filename);
632 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
634 if (q == (Quantum *) NULL)
636 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
637 quantum_info,AlphaQuantum,pixels,exception);
638 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
640 if (((y-image->extract_info.y) >= 0) &&
641 ((y-image->extract_info.y) < (ssize_t) image->rows))
643 p=GetVirtualPixels(canvas_image,
644 canvas_image->extract_info.x,0,canvas_image->columns,1,
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))
651 for (x=0; x < (ssize_t) image->columns; x++)
653 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
654 p+=GetPixelChannels(canvas_image);
655 q+=GetPixelChannels(image);
657 if (SyncAuthenticPixels(image,exception) == MagickFalse)
660 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
663 if (image->previous == (Image *) NULL)
665 status=SetImageProgress(image,LoadImageTag,5,6);
666 if (status == MagickFalse)
670 if (image->previous == (Image *) NULL)
672 status=SetImageProgress(image,LoadImageTag,6,6);
673 if (status == MagickFalse)
678 case PartitionInterlace:
681 Partition interlacing: CCCCCC..., MMMMMM..., YYYYYY..., KKKKKK...
683 AppendImageFormat("C",image->filename);
684 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
685 if (status == MagickFalse)
687 canvas_image=DestroyImageList(canvas_image);
688 image=DestroyImageList(image);
689 return((Image *) NULL);
691 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
692 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
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++)
698 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
700 if (count != (ssize_t) length)
702 ThrowFileException(exception,CorruptImageError,
703 "UnexpectedEndOfFile",image->filename);
707 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
709 for (y=0; y < (ssize_t) image->extract_info.height; y++)
711 register const Quantum
720 if (count != (ssize_t) length)
722 ThrowFileException(exception,CorruptImageError,
723 "UnexpectedEndOfFile",image->filename);
726 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
728 if (q == (Quantum *) NULL)
730 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
731 quantum_info,CyanQuantum,pixels,exception);
732 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
734 if (((y-image->extract_info.y) >= 0) &&
735 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
744 for (x=0; x < (ssize_t) image->columns; x++)
746 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
747 p+=GetPixelChannels(canvas_image);
748 q+=GetPixelChannels(image);
750 if (SyncAuthenticPixels(image,exception) == MagickFalse)
753 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
756 if (image->previous == (Image *) NULL)
758 status=SetImageProgress(image,LoadImageTag,1,5);
759 if (status == MagickFalse)
762 (void) CloseBlob(image);
763 AppendImageFormat("M",image->filename);
764 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
765 if (status == MagickFalse)
767 canvas_image=DestroyImageList(canvas_image);
768 image=DestroyImageList(image);
769 return((Image *) NULL);
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++)
775 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
777 if (count != (ssize_t) length)
779 ThrowFileException(exception,CorruptImageError,
780 "UnexpectedEndOfFile",image->filename);
784 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
786 for (y=0; y < (ssize_t) image->extract_info.height; y++)
788 register const Quantum
797 if (count != (ssize_t) length)
799 ThrowFileException(exception,CorruptImageError,
800 "UnexpectedEndOfFile",image->filename);
803 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
805 if (q == (Quantum *) NULL)
807 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
808 quantum_info,MagentaQuantum,pixels,exception);
809 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
811 if (((y-image->extract_info.y) >= 0) &&
812 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
820 for (x=0; x < (ssize_t) image->columns; x++)
822 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
823 p+=GetPixelChannels(canvas_image);
824 q+=GetPixelChannels(image);
826 if (SyncAuthenticPixels(image,exception) == MagickFalse)
829 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
832 if (image->previous == (Image *) NULL)
834 status=SetImageProgress(image,LoadImageTag,2,5);
835 if (status == MagickFalse)
838 (void) CloseBlob(image);
839 AppendImageFormat("Y",image->filename);
840 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
841 if (status == MagickFalse)
843 canvas_image=DestroyImageList(canvas_image);
844 image=DestroyImageList(image);
845 return((Image *) NULL);
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++)
851 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
853 if (count != (ssize_t) length)
855 ThrowFileException(exception,CorruptImageError,
856 "UnexpectedEndOfFile",image->filename);
860 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
862 for (y=0; y < (ssize_t) image->extract_info.height; y++)
864 register const Quantum
873 if (count != (ssize_t) length)
875 ThrowFileException(exception,CorruptImageError,
876 "UnexpectedEndOfFile",image->filename);
879 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
881 if (q == (Quantum *) NULL)
883 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
884 quantum_info,YellowQuantum,pixels,exception);
885 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
887 if (((y-image->extract_info.y) >= 0) &&
888 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
897 for (x=0; x < (ssize_t) image->columns; x++)
899 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
900 p+=GetPixelChannels(canvas_image);
901 q+=GetPixelChannels(image);
903 if (SyncAuthenticPixels(image,exception) == MagickFalse)
906 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
909 if (image->previous == (Image *) NULL)
911 status=SetImageProgress(image,LoadImageTag,3,5);
912 if (status == MagickFalse)
915 (void) CloseBlob(image);
916 AppendImageFormat("K",image->filename);
917 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
918 if (status == MagickFalse)
920 canvas_image=DestroyImageList(canvas_image);
921 image=DestroyImageList(image);
922 return((Image *) NULL);
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++)
928 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
930 if (count != (ssize_t) length)
932 ThrowFileException(exception,CorruptImageError,
933 "UnexpectedEndOfFile",image->filename);
937 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
939 for (y=0; y < (ssize_t) image->extract_info.height; y++)
941 register const Quantum
950 if (count != (ssize_t) length)
952 ThrowFileException(exception,CorruptImageError,
953 "UnexpectedEndOfFile",image->filename);
956 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
958 if (q == (Quantum *) NULL)
960 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
961 quantum_info,BlackQuantum,pixels,exception);
962 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
964 if (((y-image->extract_info.y) >= 0) &&
965 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
974 for (x=0; x < (ssize_t) image->columns; x++)
976 SetPixelBlack(image,GetPixelBlack(canvas_image,p),q);
977 p+=GetPixelChannels(canvas_image);
978 q+=GetPixelChannels(image);
980 if (SyncAuthenticPixels(image,exception) == MagickFalse)
983 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
986 if (image->previous == (Image *) NULL)
988 status=SetImageProgress(image,LoadImageTag,3,5);
989 if (status == MagickFalse)
992 if (image->alpha_trait != UndefinedPixelTrait)
994 (void) CloseBlob(image);
995 AppendImageFormat("A",image->filename);
996 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
997 if (status == MagickFalse)
999 canvas_image=DestroyImageList(canvas_image);
1000 image=DestroyImageList(image);
1001 return((Image *) NULL);
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++)
1007 pixels=ReadBlobStream(image,length,
1008 GetQuantumPixels(quantum_info),&count);
1009 if (count != (ssize_t) length)
1011 ThrowFileException(exception,CorruptImageError,
1012 "UnexpectedEndOfFile",image->filename);
1016 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
1018 for (y=0; y < (ssize_t) image->extract_info.height; y++)
1020 register const Quantum
1029 if (count != (ssize_t) length)
1031 ThrowFileException(exception,CorruptImageError,
1032 "UnexpectedEndOfFile",image->filename);
1035 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
1037 if (q == (Quantum *) NULL)
1039 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
1040 quantum_info,YellowQuantum,pixels,exception);
1041 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
1043 if (((y-image->extract_info.y) >= 0) &&
1044 ((y-image->extract_info.y) < (ssize_t) image->rows))
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))
1053 for (x=0; x < (ssize_t) image->columns; x++)
1055 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
1056 p+=GetPixelChannels(canvas_image);
1057 q+=GetPixelChannels(image);
1059 if (SyncAuthenticPixels(image,exception) == MagickFalse)
1062 pixels=ReadBlobStream(image,length,GetQuantumPixels(quantum_info),
1065 if (image->previous == (Image *) NULL)
1067 status=SetImageProgress(image,LoadImageTag,4,5);
1068 if (status == MagickFalse)
1072 if (image->previous == (Image *) NULL)
1074 status=SetImageProgress(image,LoadImageTag,5,5);
1075 if (status == MagickFalse)
1081 SetQuantumImageType(image,quantum_type);
1083 Proceed to next image.
1085 if (image_info->number_scenes != 0)
1086 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
1088 if (count == (ssize_t) length)
1091 Allocate next image structure.
1093 AcquireNextImage(image_info,image,exception);
1094 if (GetNextImageInList(image) == (Image *) NULL)
1096 image=DestroyImageList(image);
1097 return((Image *) NULL);
1099 image=SyncNextImageInList(image);
1100 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1101 GetBlobSize(image));
1102 if (status == MagickFalse)
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));
1114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1118 % R e g i s t e r C M Y K I m a g e %
1122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
1131 % The format of the RegisterCMYKImage method is:
1133 % size_t RegisterCMYKImage(void)
1136 ModuleExport size_t RegisterCMYKImage(void)
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 "
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 "
1157 entry->module=ConstantString("CMYK");
1158 (void) RegisterMagickInfo(entry);
1159 return(MagickImageCoderSignature);
1163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1167 % U n r e g i s t e r C M Y K I m a g e %
1171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1173 % UnregisterCMYKImage() removes format registrations made by the
1174 % CMYK module from the list of supported formats.
1176 % The format of the UnregisterCMYKImage method is:
1178 % UnregisterCMYKImage(void)
1181 ModuleExport void UnregisterCMYKImage(void)
1183 (void) UnregisterMagickInfo("CMYK");
1184 (void) UnregisterMagickInfo("CMYKA");
1188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1192 % W r i t e C M Y K I m a g e %
1196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198 % WriteCMYKImage() writes an image to a file in cyan, magenta, yellow, and
1199 % black,rasterfile format.
1201 % The format of the WriteCMYKImage method is:
1203 % MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
1204 % Image *image,ExceptionInfo *exception)
1206 % A description of each parameter follows.
1208 % o image_info: the image info.
1210 % o image: The image.
1212 % o exception: return any errors or warnings in this structure.
1215 static MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
1216 Image *image,ExceptionInfo *exception)
1241 Allocate memory for pixels.
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)
1252 Open output image file.
1254 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1255 if (status == MagickFalse)
1262 Convert MIFF to CMYK raster pixels.
1264 if (image->colorspace != CMYKColorspace)
1265 (void) TransformImageColorspace(image,CMYKColorspace,exception);
1266 quantum_type=CMYKQuantum;
1267 if (LocaleCompare(image_info->magick,"CMYKA") == 0)
1269 quantum_type=CMYKAQuantum;
1270 if (image->alpha_trait == UndefinedPixelTrait)
1271 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
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)
1283 No interlacing: CMYKCMYKCMYKCMYKCMYKCMYK...
1285 for (y=0; y < (ssize_t) image->rows; y++)
1287 register const Quantum
1290 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1291 if (p == (const Quantum *) NULL)
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)
1298 if (image->previous == (Image *) NULL)
1300 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1302 if (status == MagickFalse)
1311 Line interlacing: CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK...
1313 for (y=0; y < (ssize_t) image->rows; y++)
1315 register const Quantum
1318 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1319 if (p == (const Quantum *) NULL)
1321 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1322 CyanQuantum,pixels,exception);
1323 count=WriteBlob(image,length,pixels);
1324 if (count != (ssize_t) length)
1326 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1327 MagentaQuantum,pixels,exception);
1328 count=WriteBlob(image,length,pixels);
1329 if (count != (ssize_t) length)
1331 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1332 YellowQuantum,pixels,exception);
1333 count=WriteBlob(image,length,pixels);
1334 if (count != (ssize_t) length)
1336 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1337 BlackQuantum,pixels,exception);
1338 count=WriteBlob(image,length,pixels);
1339 if (count != (ssize_t) length)
1341 if (quantum_type == CMYKAQuantum)
1343 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1344 AlphaQuantum,pixels,exception);
1345 count=WriteBlob(image,length,pixels);
1346 if (count != (ssize_t) length)
1349 if (image->previous == (Image *) NULL)
1351 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1353 if (status == MagickFalse)
1359 case PlaneInterlace:
1362 Plane interlacing: CCCCCC...MMMMMM...YYYYYY...KKKKKK...
1364 for (y=0; y < (ssize_t) image->rows; y++)
1366 register const Quantum
1369 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1370 if (p == (const Quantum *) NULL)
1372 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1373 CyanQuantum,pixels,exception);
1374 count=WriteBlob(image,length,pixels);
1375 if (count != (ssize_t) length)
1378 if (image->previous == (Image *) NULL)
1380 status=SetImageProgress(image,SaveImageTag,1,6);
1381 if (status == MagickFalse)
1384 for (y=0; y < (ssize_t) image->rows; y++)
1386 register const Quantum
1389 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1390 if (p == (const Quantum *) NULL)
1392 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1393 MagentaQuantum,pixels,exception);
1394 count=WriteBlob(image,length,pixels);
1395 if (count != (ssize_t) length)
1398 if (image->previous == (Image *) NULL)
1400 status=SetImageProgress(image,SaveImageTag,2,6);
1401 if (status == MagickFalse)
1404 for (y=0; y < (ssize_t) image->rows; y++)
1406 register const Quantum
1409 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1410 if (p == (const Quantum *) NULL)
1412 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1413 YellowQuantum,pixels,exception);
1414 count=WriteBlob(image,length,pixels);
1415 if (count != (ssize_t) length)
1418 if (image->previous == (Image *) NULL)
1420 status=SetImageProgress(image,SaveImageTag,3,6);
1421 if (status == MagickFalse)
1424 for (y=0; y < (ssize_t) image->rows; y++)
1426 register const Quantum
1429 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1430 if (p == (const Quantum *) NULL)
1432 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1433 BlackQuantum,pixels,exception);
1434 count=WriteBlob(image,length,pixels);
1435 if (count != (ssize_t) length)
1438 if (image->previous == (Image *) NULL)
1440 status=SetImageProgress(image,SaveImageTag,4,6);
1441 if (status == MagickFalse)
1444 if (quantum_type == CMYKAQuantum)
1446 for (y=0; y < (ssize_t) image->rows; y++)
1448 register const Quantum
1451 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1452 if (p == (const Quantum *) NULL)
1454 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1455 AlphaQuantum,pixels,exception);
1456 count=WriteBlob(image,length,pixels);
1457 if (count != (ssize_t) length)
1460 if (image->previous == (Image *) NULL)
1462 status=SetImageProgress(image,SaveImageTag,5,6);
1463 if (status == MagickFalse)
1467 if (image_info->interlace == PartitionInterlace)
1468 (void) CopyMagickString(image->filename,image_info->filename,
1470 if (image->previous == (Image *) NULL)
1472 status=SetImageProgress(image,SaveImageTag,6,6);
1473 if (status == MagickFalse)
1478 case PartitionInterlace:
1481 Partition interlacing: CCCCCC..., MMMMMM..., YYYYYY..., KKKKKK...
1483 AppendImageFormat("C",image->filename);
1484 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1485 AppendBinaryBlobMode,exception);
1486 if (status == MagickFalse)
1488 for (y=0; y < (ssize_t) image->rows; y++)
1490 register const Quantum
1493 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1494 if (p == (const Quantum *) NULL)
1496 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1497 CyanQuantum,pixels,exception);
1498 count=WriteBlob(image,length,pixels);
1499 if (count != (ssize_t) length)
1502 if (image->previous == (Image *) NULL)
1504 status=SetImageProgress(image,SaveImageTag,1,6);
1505 if (status == MagickFalse)
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)
1514 for (y=0; y < (ssize_t) image->rows; y++)
1516 register const Quantum
1519 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1520 if (p == (const Quantum *) NULL)
1522 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1523 MagentaQuantum,pixels,exception);
1524 count=WriteBlob(image,length,pixels);
1525 if (count != (ssize_t) length)
1528 if (image->previous == (Image *) NULL)
1530 status=SetImageProgress(image,SaveImageTag,2,6);
1531 if (status == MagickFalse)
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)
1540 for (y=0; y < (ssize_t) image->rows; y++)
1542 register const Quantum
1545 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1546 if (p == (const Quantum *) NULL)
1548 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1549 YellowQuantum,pixels,exception);
1550 count=WriteBlob(image,length,pixels);
1551 if (count != (ssize_t) length)
1554 if (image->previous == (Image *) NULL)
1556 status=SetImageProgress(image,SaveImageTag,3,6);
1557 if (status == MagickFalse)
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)
1566 for (y=0; y < (ssize_t) image->rows; y++)
1568 register const Quantum
1571 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1572 if (p == (const Quantum *) NULL)
1574 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1575 BlackQuantum,pixels,exception);
1576 count=WriteBlob(image,length,pixels);
1577 if (count != (ssize_t) length)
1580 if (image->previous == (Image *) NULL)
1582 status=SetImageProgress(image,SaveImageTag,4,6);
1583 if (status == MagickFalse)
1586 if (quantum_type == CMYKAQuantum)
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)
1594 for (y=0; y < (ssize_t) image->rows; y++)
1596 register const Quantum
1599 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1600 if (p == (const Quantum *) NULL)
1602 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1603 AlphaQuantum,pixels,exception);
1604 count=WriteBlob(image,length,pixels);
1605 if (count != (ssize_t) length)
1608 if (image->previous == (Image *) NULL)
1610 status=SetImageProgress(image,SaveImageTag,5,6);
1611 if (status == MagickFalse)
1615 (void) CloseBlob(image);
1616 (void) CopyMagickString(image->filename,image_info->filename,
1618 if (image->previous == (Image *) NULL)
1620 status=SetImageProgress(image,SaveImageTag,6,6);
1621 if (status == MagickFalse)
1627 quantum_info=DestroyQuantumInfo(quantum_info);
1628 if (GetNextImageInList(image) == (Image *) NULL)
1630 image=SyncNextImageInList(image);
1631 status=SetImageProgress(image,SaveImagesTag,scene++,
1632 GetImageListLength(image));
1633 if (status == MagickFalse)
1635 } while (image_info->adjoin != MagickFalse);
1636 (void) CloseBlob(image);