2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Raw RGB Image Format %
20 % Copyright 1999-2008 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 "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/colorspace.h"
47 #include "magick/constitute.h"
48 #include "magick/exception.h"
49 #include "magick/exception-private.h"
50 #include "magick/image.h"
51 #include "magick/image-private.h"
52 #include "magick/list.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/pixel-private.h"
58 #include "magick/quantum-private.h"
59 #include "magick/static.h"
60 #include "magick/statistic.h"
61 #include "magick/string_.h"
62 #include "magick/module.h"
63 #include "magick/utility.h"
68 static MagickBooleanType
69 WriteRGBImage(const ImageInfo *,Image *);
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % R e a d R G B I m a g e %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % ReadRGBImage() reads an image of raw RGB, RGBA, or RGBO samples and returns
83 % it. It allocates the memory necessary for the new Image structure and
84 % returns a pointer to the new image.
86 % The format of the ReadRGBImage method is:
88 % Image *ReadRGBImage(const ImageInfo *image_info,
89 % ExceptionInfo *exception)
91 % A description of each parameter follows:
93 % o image_info: the image info.
95 % o exception: return any errors or warnings in this structure.
98 static Image *ReadRGBImage(const ImageInfo *image_info,
99 ExceptionInfo *exception)
133 assert(image_info != (const ImageInfo *) NULL);
134 assert(image_info->signature == MagickSignature);
135 if (image_info->debug != MagickFalse)
136 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
137 image_info->filename);
138 assert(exception != (ExceptionInfo *) NULL);
139 assert(exception->signature == MagickSignature);
140 image=AcquireImage(image_info);
141 if ((image->columns == 0) || (image->rows == 0))
142 ThrowReaderException(OptionError,"MustSpecifyImageSize");
143 image->colorspace=RGBColorspace;
144 if (image_info->interlace != PartitionInterlace)
146 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
147 if (status == MagickFalse)
149 image=DestroyImageList(image);
150 return((Image *) NULL);
152 for (i=0; i < image->offset; i++)
153 if (ReadBlobByte(image) == EOF)
155 ThrowFileException(exception,CorruptImageError,
156 "UnexpectedEndOfFile",image->filename);
161 Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
163 canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
165 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
166 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
167 if (quantum_info == (QuantumInfo *) NULL)
168 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
169 pixels=GetQuantumPixels(quantum_info);
170 quantum_type=RGBQuantum;
171 if (LocaleCompare(image_info->magick,"RGBA") == 0)
173 quantum_type=RGBAQuantum;
174 image->matte=MagickTrue;
176 if (LocaleCompare(image_info->magick,"RGBO") == 0)
178 quantum_type=RGBOQuantum;
179 image->matte=MagickTrue;
181 if (image_info->number_scenes != 0)
182 while (image->scene < image_info->scene)
188 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
189 for (y=0; y < (ssize_t) image->rows; y++)
191 count=ReadBlob(image,length,pixels);
192 if (count != (ssize_t) length)
202 Read pixels to virtual canvas image then push to image.
204 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
205 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
207 image->colorspace=RGBColorspace;
208 switch (image_info->interlace)
214 No interlacing: RGBRGBRGBRGBRGBRGB...
218 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
219 count=ReadBlob(image,length,pixels);
221 for (y=0; y < (ssize_t) image->extract_info.height; y++)
223 register const PixelPacket
232 if (count != (ssize_t) length)
234 ThrowFileException(exception,CorruptImageError,
235 "UnexpectedEndOfFile",image->filename);
238 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
240 if (q == (PixelPacket *) NULL)
242 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
243 quantum_info,quantum_type,pixels,exception);
244 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
246 if (((y-image->extract_info.y) >= 0) &&
247 ((y-image->extract_info.y) < (ssize_t) image->rows))
249 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
250 canvas_image->columns,1,exception);
251 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
252 image->columns,1,exception);
253 if ((p == (const PixelPacket *) NULL) ||
254 (q == (PixelPacket *) NULL))
256 for (x=0; x < (ssize_t) image->columns; x++)
258 SetRedPixelComponent(q,GetRedPixelComponent(p));
259 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
260 SetBluePixelComponent(q,GetBluePixelComponent(p));
261 SetOpacityPixelComponent(q,OpaqueOpacity);
262 if (image->matte != MagickFalse)
263 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
267 if (SyncAuthenticPixels(image,exception) == MagickFalse)
270 if (image->previous == (Image *) NULL)
272 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
274 if (status == MagickFalse)
277 count=ReadBlob(image,length,pixels);
293 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
295 if (LocaleCompare(image_info->magick,"RGBO") == 0)
296 quantum_types[3]=OpacityQuantum;
299 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
300 count=ReadBlob(image,length,pixels);
302 for (y=0; y < (ssize_t) image->extract_info.height; y++)
304 register const PixelPacket
313 if (count != (ssize_t) length)
315 ThrowFileException(exception,CorruptImageError,
316 "UnexpectedEndOfFile",image->filename);
319 for (i=0; i < (ssize_t) (image->matte != MagickFalse ? 4 : 3); i++)
321 quantum_type=quantum_types[i];
322 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
324 if (q == (PixelPacket *) NULL)
326 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
327 quantum_info,quantum_type,pixels,exception);
328 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
330 if (((y-image->extract_info.y) >= 0) &&
331 ((y-image->extract_info.y) < (ssize_t) image->rows))
333 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
334 0,canvas_image->columns,1,exception);
335 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
336 image->columns,1,exception);
337 if ((p == (const PixelPacket *) NULL) ||
338 (q == (PixelPacket *) NULL))
340 for (x=0; x < (ssize_t) image->columns; x++)
342 switch (quantum_type)
346 SetRedPixelComponent(q,GetRedPixelComponent(p));
351 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
356 SetBluePixelComponent(q,GetBluePixelComponent(p));
361 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
366 SetAlphaPixelComponent(q,GetAlphaPixelComponent(p));
375 if (SyncAuthenticPixels(image,exception) == MagickFalse)
378 count=ReadBlob(image,length,pixels);
380 if (image->previous == (Image *) NULL)
382 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
384 if (status == MagickFalse)
393 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
397 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
398 count=ReadBlob(image,length,pixels);
400 for (y=0; y < (ssize_t) image->extract_info.height; y++)
402 register const PixelPacket
411 if (count != (ssize_t) length)
413 ThrowFileException(exception,CorruptImageError,
414 "UnexpectedEndOfFile",image->filename);
417 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
419 if (q == (PixelPacket *) NULL)
421 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
422 quantum_info,RedQuantum,pixels,exception);
423 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
425 if (((y-image->extract_info.y) >= 0) &&
426 ((y-image->extract_info.y) < (ssize_t) image->rows))
428 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
429 canvas_image->columns,1,exception);
430 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
431 image->columns,1,exception);
432 if ((p == (const PixelPacket *) NULL) ||
433 (q == (PixelPacket *) NULL))
435 for (x=0; x < (ssize_t) image->columns; x++)
437 SetRedPixelComponent(q,GetRedPixelComponent(p));
441 if (SyncAuthenticPixels(image,exception) == MagickFalse)
444 count=ReadBlob(image,length,pixels);
446 if (image->previous == (Image *) NULL)
448 status=SetImageProgress(image,LoadImageTag,1,6);
449 if (status == MagickFalse)
452 for (y=0; y < (ssize_t) image->extract_info.height; y++)
454 register const PixelPacket
463 if (count != (ssize_t) length)
465 ThrowFileException(exception,CorruptImageError,
466 "UnexpectedEndOfFile",image->filename);
469 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
471 if (q == (PixelPacket *) NULL)
473 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
474 quantum_info,GreenQuantum,pixels,exception);
475 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
477 if (((y-image->extract_info.y) >= 0) &&
478 ((y-image->extract_info.y) < (ssize_t) image->rows))
480 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
481 canvas_image->columns,1,exception);
482 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
483 image->columns,1,exception);
484 if ((p == (const PixelPacket *) NULL) ||
485 (q == (PixelPacket *) NULL))
487 for (x=0; x < (ssize_t) image->columns; x++)
489 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
493 if (SyncAuthenticPixels(image,exception) == MagickFalse)
496 count=ReadBlob(image,length,pixels);
498 if (image->previous == (Image *) NULL)
500 status=SetImageProgress(image,LoadImageTag,2,6);
501 if (status == MagickFalse)
504 for (y=0; y < (ssize_t) image->extract_info.height; y++)
506 register const PixelPacket
515 if (count != (ssize_t) length)
517 ThrowFileException(exception,CorruptImageError,
518 "UnexpectedEndOfFile",image->filename);
521 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
523 if (q == (PixelPacket *) NULL)
525 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
526 quantum_info,BlueQuantum,pixels,exception);
527 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
529 if (((y-image->extract_info.y) >= 0) &&
530 ((y-image->extract_info.y) < (ssize_t) image->rows))
532 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
533 canvas_image->columns,1,exception);
534 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
535 image->columns,1,exception);
536 if ((p == (const PixelPacket *) NULL) ||
537 (q == (PixelPacket *) NULL))
539 for (x=0; x < (ssize_t) image->columns; x++)
541 SetBluePixelComponent(q,GetBluePixelComponent(p));
545 if (SyncAuthenticPixels(image,exception) == MagickFalse)
548 count=ReadBlob(image,length,pixels);
550 if (image->previous == (Image *) NULL)
552 status=SetImageProgress(image,LoadImageTag,3,6);
553 if (status == MagickFalse)
556 if (image->previous == (Image *) NULL)
558 status=SetImageProgress(image,LoadImageTag,4,6);
559 if (status == MagickFalse)
562 if (image->matte != MagickFalse)
564 for (y=0; y < (ssize_t) image->extract_info.height; y++)
566 register const PixelPacket
575 if (count != (ssize_t) length)
577 ThrowFileException(exception,CorruptImageError,
578 "UnexpectedEndOfFile",image->filename);
581 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
583 if (q == (PixelPacket *) NULL)
585 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
586 quantum_info,AlphaQuantum,pixels,exception);
587 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
589 if (((y-image->extract_info.y) >= 0) &&
590 ((y-image->extract_info.y) < (ssize_t) image->rows))
592 p=GetVirtualPixels(canvas_image,
593 canvas_image->extract_info.x,0,canvas_image->columns,1,
595 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
596 image->columns,1,exception);
597 if ((p == (const PixelPacket *) NULL) ||
598 (q == (PixelPacket *) NULL))
600 for (x=0; x < (ssize_t) image->columns; x++)
602 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
606 if (SyncAuthenticPixels(image,exception) == MagickFalse)
609 count=ReadBlob(image,length,pixels);
611 if (image->previous == (Image *) NULL)
613 status=SetImageProgress(image,LoadImageTag,5,6);
614 if (status == MagickFalse)
618 if (image->previous == (Image *) NULL)
620 status=SetImageProgress(image,LoadImageTag,6,6);
621 if (status == MagickFalse)
626 case PartitionInterlace:
629 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
631 AppendImageFormat("R",image->filename);
632 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
633 if (status == MagickFalse)
635 canvas_image=DestroyImageList(canvas_image);
636 image=DestroyImageList(image);
637 return((Image *) NULL);
639 for (i=0; i < image->offset; i++)
640 if (ReadBlobByte(image) == EOF)
642 ThrowFileException(exception,CorruptImageError,
643 "UnexpectedEndOfFile",image->filename);
646 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
647 for (i=0; i < (ssize_t) scene; i++)
648 for (y=0; y < (ssize_t) image->extract_info.height; y++)
649 if (ReadBlob(image,length,pixels) != (ssize_t) length)
651 ThrowFileException(exception,CorruptImageError,
652 "UnexpectedEndOfFile",image->filename);
655 count=ReadBlob(image,length,pixels);
656 for (y=0; y < (ssize_t) image->extract_info.height; y++)
658 register const PixelPacket
667 if (count != (ssize_t) length)
669 ThrowFileException(exception,CorruptImageError,
670 "UnexpectedEndOfFile",image->filename);
673 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
675 if (q == (PixelPacket *) NULL)
677 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
678 quantum_info,RedQuantum,pixels,exception);
679 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
681 if (((y-image->extract_info.y) >= 0) &&
682 ((y-image->extract_info.y) < (ssize_t) image->rows))
684 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
685 canvas_image->columns,1,exception);
686 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
687 image->columns,1,exception);
688 if ((p == (const PixelPacket *) NULL) ||
689 (q == (PixelPacket *) NULL))
691 for (x=0; x < (ssize_t) image->columns; x++)
693 SetRedPixelComponent(q,GetRedPixelComponent(p));
697 if (SyncAuthenticPixels(image,exception) == MagickFalse)
700 count=ReadBlob(image,length,pixels);
702 if (image->previous == (Image *) NULL)
704 status=SetImageProgress(image,LoadImageTag,1,5);
705 if (status == MagickFalse)
708 (void) CloseBlob(image);
709 AppendImageFormat("G",image->filename);
710 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
711 if (status == MagickFalse)
713 canvas_image=DestroyImageList(canvas_image);
714 image=DestroyImageList(image);
715 return((Image *) NULL);
717 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
718 for (i=0; i < (ssize_t) scene; i++)
719 for (y=0; y < (ssize_t) image->extract_info.height; y++)
720 if (ReadBlob(image,length,pixels) != (ssize_t) length)
722 ThrowFileException(exception,CorruptImageError,
723 "UnexpectedEndOfFile",image->filename);
726 count=ReadBlob(image,length,pixels);
727 for (y=0; y < (ssize_t) image->extract_info.height; y++)
729 register const PixelPacket
738 if (count != (ssize_t) length)
740 ThrowFileException(exception,CorruptImageError,
741 "UnexpectedEndOfFile",image->filename);
744 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
746 if (q == (PixelPacket *) NULL)
748 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
749 quantum_info,GreenQuantum,pixels,exception);
750 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
752 if (((y-image->extract_info.y) >= 0) &&
753 ((y-image->extract_info.y) < (ssize_t) image->rows))
755 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
756 canvas_image->columns,1,exception);
757 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
758 image->columns,1,exception);
759 if ((p == (const PixelPacket *) NULL) ||
760 (q == (PixelPacket *) NULL))
762 for (x=0; x < (ssize_t) image->columns; x++)
764 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
768 if (SyncAuthenticPixels(image,exception) == MagickFalse)
771 count=ReadBlob(image,length,pixels);
773 if (image->previous == (Image *) NULL)
775 status=SetImageProgress(image,LoadImageTag,2,5);
776 if (status == MagickFalse)
779 (void) CloseBlob(image);
780 AppendImageFormat("B",image->filename);
781 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
782 if (status == MagickFalse)
784 canvas_image=DestroyImageList(canvas_image);
785 image=DestroyImageList(image);
786 return((Image *) NULL);
788 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
789 for (i=0; i < (ssize_t) scene; i++)
790 for (y=0; y < (ssize_t) image->extract_info.height; y++)
791 if (ReadBlob(image,length,pixels) != (ssize_t) length)
793 ThrowFileException(exception,CorruptImageError,
794 "UnexpectedEndOfFile",image->filename);
797 count=ReadBlob(image,length,pixels);
798 for (y=0; y < (ssize_t) image->extract_info.height; y++)
800 register const PixelPacket
809 if (count != (ssize_t) length)
811 ThrowFileException(exception,CorruptImageError,
812 "UnexpectedEndOfFile",image->filename);
815 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
817 if (q == (PixelPacket *) NULL)
819 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
820 quantum_info,BlueQuantum,pixels,exception);
821 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
823 if (((y-image->extract_info.y) >= 0) &&
824 ((y-image->extract_info.y) < (ssize_t) image->rows))
826 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
827 canvas_image->columns,1,exception);
828 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
829 image->columns,1,exception);
830 if ((p == (const PixelPacket *) NULL) ||
831 (q == (PixelPacket *) NULL))
833 for (x=0; x < (ssize_t) image->columns; x++)
835 SetBluePixelComponent(q,GetBluePixelComponent(p));
839 if (SyncAuthenticPixels(image,exception) == MagickFalse)
842 count=ReadBlob(image,length,pixels);
844 if (image->previous == (Image *) NULL)
846 status=SetImageProgress(image,LoadImageTag,3,5);
847 if (status == MagickFalse)
850 if (image->matte != MagickFalse)
852 (void) CloseBlob(image);
853 AppendImageFormat("A",image->filename);
854 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
855 if (status == MagickFalse)
857 canvas_image=DestroyImageList(canvas_image);
858 image=DestroyImageList(image);
859 return((Image *) NULL);
861 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
862 for (i=0; i < (ssize_t) scene; i++)
863 for (y=0; y < (ssize_t) image->extract_info.height; y++)
864 if (ReadBlob(image,length,pixels) != (ssize_t) length)
866 ThrowFileException(exception,CorruptImageError,
867 "UnexpectedEndOfFile",image->filename);
870 count=ReadBlob(image,length,pixels);
871 for (y=0; y < (ssize_t) image->extract_info.height; y++)
873 register const PixelPacket
882 if (count != (ssize_t) length)
884 ThrowFileException(exception,CorruptImageError,
885 "UnexpectedEndOfFile",image->filename);
888 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
890 if (q == (PixelPacket *) NULL)
892 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
893 quantum_info,BlueQuantum,pixels,exception);
894 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
896 if (((y-image->extract_info.y) >= 0) &&
897 ((y-image->extract_info.y) < (ssize_t) image->rows))
899 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
900 0,canvas_image->columns,1,exception);
901 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
902 image->columns,1,exception);
903 if ((p == (const PixelPacket *) NULL) ||
904 (q == (PixelPacket *) NULL))
906 for (x=0; x < (ssize_t) image->columns; x++)
908 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
912 if (SyncAuthenticPixels(image,exception) == MagickFalse)
915 count=ReadBlob(image,length,pixels);
917 if (image->previous == (Image *) NULL)
919 status=SetImageProgress(image,LoadImageTag,4,5);
920 if (status == MagickFalse)
924 (void) CloseBlob(image);
925 if (image->previous == (Image *) NULL)
927 status=SetImageProgress(image,LoadImageTag,5,5);
928 if (status == MagickFalse)
934 SetQuantumImageType(image,quantum_type);
936 Proceed to next image.
938 if (image_info->number_scenes != 0)
939 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
941 if (count == (ssize_t) length)
944 Allocate next image structure.
946 AcquireNextImage(image_info,image);
947 if (GetNextImageInList(image) == (Image *) NULL)
949 image=DestroyImageList(image);
950 return((Image *) NULL);
952 image=SyncNextImageInList(image);
953 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
955 if (status == MagickFalse)
959 } while (count == (ssize_t) length);
960 quantum_info=DestroyQuantumInfo(quantum_info);
961 InheritException(&image->exception,&canvas_image->exception);
962 canvas_image=DestroyImage(canvas_image);
963 (void) CloseBlob(image);
964 return(GetFirstImageInList(image));
968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
972 % R e g i s t e r R G B I m a g e %
976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
978 % RegisterRGBImage() adds attributes for the RGB image format to
979 % the list of supported formats. The attributes include the image format
980 % tag, a method to read and/or write the format, whether the format
981 % supports the saving of more than one frame to the same file or blob,
982 % whether the format supports native in-memory I/O, and a brief
983 % description of the format.
985 % The format of the RegisterRGBImage method is:
987 % size_t RegisterRGBImage(void)
990 ModuleExport size_t RegisterRGBImage(void)
995 entry=SetMagickInfo("RGB");
996 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
997 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
998 entry->raw=MagickTrue;
999 entry->endian_support=MagickTrue;
1000 entry->description=ConstantString("Raw red, green, and blue samples");
1001 entry->module=ConstantString("RGB");
1002 (void) RegisterMagickInfo(entry);
1003 entry=SetMagickInfo("RGBA");
1004 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1005 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
1006 entry->raw=MagickTrue;
1007 entry->endian_support=MagickTrue;
1008 entry->description=ConstantString("Raw red, green, blue, and alpha samples");
1009 entry->module=ConstantString("RGB");
1010 (void) RegisterMagickInfo(entry);
1011 return(MagickImageCoderSignature);
1012 entry=SetMagickInfo("RGBO");
1013 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1014 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
1015 entry->raw=MagickTrue;
1016 entry->endian_support=MagickTrue;
1017 entry->description=ConstantString("Raw red, green, blue, and opacity samples");
1018 entry->module=ConstantString("RGB");
1019 (void) RegisterMagickInfo(entry);
1020 return(MagickImageCoderSignature);
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028 % U n r e g i s t e r R G B I m a g e %
1032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1034 % UnregisterRGBImage() removes format registrations made by the RGB module
1035 % from the list of supported formats.
1037 % The format of the UnregisterRGBImage method is:
1039 % UnregisterRGBImage(void)
1042 ModuleExport void UnregisterRGBImage(void)
1044 (void) UnregisterMagickInfo("RGBO");
1045 (void) UnregisterMagickInfo("RGBA");
1046 (void) UnregisterMagickInfo("RGB");
1050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054 % W r i t e R G B I m a g e %
1058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060 % WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO
1061 % rasterfile format.
1063 % The format of the WriteRGBImage method is:
1065 % MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1068 % A description of each parameter follows.
1070 % o image_info: the image info.
1072 % o image: The image.
1075 static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1101 Allocate memory for pixels.
1103 assert(image_info != (const ImageInfo *) NULL);
1104 assert(image_info->signature == MagickSignature);
1105 assert(image != (Image *) NULL);
1106 assert(image->signature == MagickSignature);
1107 if (image->debug != MagickFalse)
1108 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1109 if (image_info->interlace != PartitionInterlace)
1112 Open output image file.
1114 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1115 if (status == MagickFalse)
1118 quantum_type=RGBQuantum;
1119 if (LocaleCompare(image_info->magick,"RGBA") == 0)
1121 quantum_type=RGBAQuantum;
1122 image->matte=MagickTrue;
1124 if (LocaleCompare(image_info->magick,"RGBO") == 0)
1126 quantum_type=RGBOQuantum;
1127 image->matte=MagickTrue;
1133 Convert MIFF to RGB raster pixels.
1135 if (image->colorspace != RGBColorspace)
1136 (void) TransformImageColorspace(image,RGBColorspace);
1137 if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
1138 (image->matte == MagickFalse))
1139 (void) SetImageAlphaChannel(image,ResetAlphaChannel);
1140 quantum_info=AcquireQuantumInfo(image_info,image);
1141 if (quantum_info == (QuantumInfo *) NULL)
1142 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1143 pixels=GetQuantumPixels(quantum_info);
1144 switch (image_info->interlace)
1150 No interlacing: RGBRGBRGBRGBRGBRGB...
1152 for (y=0; y < (ssize_t) image->rows; y++)
1154 register const PixelPacket
1157 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1158 if (p == (const PixelPacket *) NULL)
1160 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1161 quantum_info,quantum_type,pixels,&image->exception);
1162 count=WriteBlob(image,length,pixels);
1163 if (count != (ssize_t) length)
1165 if (image->previous == (Image *) NULL)
1167 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1169 if (status == MagickFalse)
1178 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
1180 for (y=0; y < (ssize_t) image->rows; y++)
1182 register const PixelPacket
1185 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1186 if (p == (const PixelPacket *) NULL)
1188 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1189 quantum_info,RedQuantum,pixels,&image->exception);
1190 count=WriteBlob(image,length,pixels);
1191 if (count != (ssize_t) length)
1193 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1194 quantum_info,GreenQuantum,pixels,&image->exception);
1195 count=WriteBlob(image,length,pixels);
1196 if (count != (ssize_t) length)
1198 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1199 quantum_info,BlueQuantum,pixels,&image->exception);
1200 count=WriteBlob(image,length,pixels);
1201 if (count != (ssize_t) length)
1203 if (quantum_type == RGBAQuantum)
1205 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1206 quantum_info,AlphaQuantum,pixels,&image->exception);
1207 count=WriteBlob(image,length,pixels);
1208 if (count != (ssize_t) length)
1211 if (quantum_type == RGBOQuantum)
1213 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1214 quantum_info,OpacityQuantum,pixels,&image->exception);
1215 count=WriteBlob(image,length,pixels);
1216 if (count != (ssize_t) length)
1219 if (image->previous == (Image *) NULL)
1221 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1223 if (status == MagickFalse)
1229 case PlaneInterlace:
1232 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
1234 for (y=0; y < (ssize_t) image->rows; y++)
1236 register const PixelPacket
1239 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1240 if (p == (const PixelPacket *) NULL)
1242 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1243 quantum_info,RedQuantum,pixels,&image->exception);
1244 count=WriteBlob(image,length,pixels);
1245 if (count != (ssize_t) length)
1248 if (image->previous == (Image *) NULL)
1250 status=SetImageProgress(image,SaveImageTag,1,6);
1251 if (status == MagickFalse)
1254 for (y=0; y < (ssize_t) image->rows; y++)
1256 register const PixelPacket
1259 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1260 if (p == (const PixelPacket *) NULL)
1262 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1263 quantum_info,GreenQuantum,pixels,&image->exception);
1264 count=WriteBlob(image,length,pixels);
1265 if (count != (ssize_t) length)
1268 if (image->previous == (Image *) NULL)
1270 status=SetImageProgress(image,SaveImageTag,2,6);
1271 if (status == MagickFalse)
1274 for (y=0; y < (ssize_t) image->rows; y++)
1276 register const PixelPacket
1279 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1280 if (p == (const PixelPacket *) NULL)
1282 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1283 quantum_info,BlueQuantum,pixels,&image->exception);
1284 count=WriteBlob(image,length,pixels);
1285 if (count != (ssize_t) length)
1288 if (image->previous == (Image *) NULL)
1290 status=SetImageProgress(image,SaveImageTag,3,6);
1291 if (status == MagickFalse)
1294 if (quantum_type == RGBAQuantum)
1296 for (y=0; y < (ssize_t) image->rows; y++)
1298 register const PixelPacket
1301 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1302 if (p == (const PixelPacket *) NULL)
1304 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1305 quantum_info,AlphaQuantum,pixels,&image->exception);
1306 count=WriteBlob(image,length,pixels);
1307 if (count != (ssize_t) length)
1310 if (image->previous == (Image *) NULL)
1312 status=SetImageProgress(image,SaveImageTag,5,6);
1313 if (status == MagickFalse)
1317 if (image_info->interlace == PartitionInterlace)
1318 (void) CopyMagickString(image->filename,image_info->filename,
1320 if (image->previous == (Image *) NULL)
1322 status=SetImageProgress(image,SaveImageTag,6,6);
1323 if (status == MagickFalse)
1328 case PartitionInterlace:
1331 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
1333 AppendImageFormat("R",image->filename);
1334 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1335 AppendBinaryBlobMode,&image->exception);
1336 if (status == MagickFalse)
1338 for (y=0; y < (ssize_t) image->rows; y++)
1340 register const PixelPacket
1343 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1344 if (p == (const PixelPacket *) NULL)
1346 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1347 quantum_info,RedQuantum,pixels,&image->exception);
1348 count=WriteBlob(image,length,pixels);
1349 if (count != (ssize_t) length)
1352 if (image->previous == (Image *) NULL)
1354 status=SetImageProgress(image,SaveImageTag,1,6);
1355 if (status == MagickFalse)
1358 (void) CloseBlob(image);
1359 AppendImageFormat("G",image->filename);
1360 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1361 AppendBinaryBlobMode,&image->exception);
1362 if (status == MagickFalse)
1364 for (y=0; y < (ssize_t) image->rows; y++)
1366 register const PixelPacket
1369 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1370 if (p == (const PixelPacket *) NULL)
1372 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1373 quantum_info,GreenQuantum,pixels,&image->exception);
1374 count=WriteBlob(image,length,pixels);
1375 if (count != (ssize_t) length)
1378 if (image->previous == (Image *) NULL)
1380 status=SetImageProgress(image,SaveImageTag,2,6);
1381 if (status == MagickFalse)
1384 (void) CloseBlob(image);
1385 AppendImageFormat("B",image->filename);
1386 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1387 AppendBinaryBlobMode,&image->exception);
1388 if (status == MagickFalse)
1390 for (y=0; y < (ssize_t) image->rows; y++)
1392 register const PixelPacket
1395 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1396 if (p == (const PixelPacket *) NULL)
1398 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1399 quantum_info,BlueQuantum,pixels,&image->exception);
1400 count=WriteBlob(image,length,pixels);
1401 if (count != (ssize_t) length)
1404 if (image->previous == (Image *) NULL)
1406 status=SetImageProgress(image,SaveImageTag,3,6);
1407 if (status == MagickFalse)
1410 (void) CloseBlob(image);
1411 if (quantum_type == RGBAQuantum)
1413 (void) CloseBlob(image);
1414 AppendImageFormat("A",image->filename);
1415 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1416 AppendBinaryBlobMode,&image->exception);
1417 if (status == MagickFalse)
1419 for (y=0; y < (ssize_t) image->rows; y++)
1421 register const PixelPacket
1424 p=GetVirtualPixels(image,0,y,image->columns,1,
1426 if (p == (const PixelPacket *) NULL)
1428 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1429 quantum_info,AlphaQuantum,pixels,&image->exception);
1430 count=WriteBlob(image,length,pixels);
1431 if (count != (ssize_t) length)
1434 if (image->previous == (Image *) NULL)
1436 status=SetImageProgress(image,SaveImageTag,5,6);
1437 if (status == MagickFalse)
1441 (void) CloseBlob(image);
1442 (void) CopyMagickString(image->filename,image_info->filename,
1444 if (image->previous == (Image *) NULL)
1446 status=SetImageProgress(image,SaveImageTag,6,6);
1447 if (status == MagickFalse)
1453 quantum_info=DestroyQuantumInfo(quantum_info);
1454 if (GetNextImageInList(image) == (Image *) NULL)
1456 image=SyncNextImageInList(image);
1457 status=SetImageProgress(image,SaveImagesTag,scene++,
1458 GetImageListLength(image));
1459 if (status == MagickFalse)
1461 } while (image_info->adjoin != MagickFalse);
1462 (void) CloseBlob(image);