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 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
153 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
157 Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
159 canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
161 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
162 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
163 if (quantum_info == (QuantumInfo *) NULL)
164 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
165 pixels=GetQuantumPixels(quantum_info);
166 quantum_type=RGBQuantum;
167 if (LocaleCompare(image_info->magick,"RGBA") == 0)
169 quantum_type=RGBAQuantum;
170 image->matte=MagickTrue;
172 if (LocaleCompare(image_info->magick,"RGBO") == 0)
174 quantum_type=RGBOQuantum;
175 image->matte=MagickTrue;
177 if (image_info->number_scenes != 0)
178 while (image->scene < image_info->scene)
184 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
185 for (y=0; y < (ssize_t) image->rows; y++)
187 count=ReadBlob(image,length,pixels);
188 if (count != (ssize_t) length)
198 Read pixels to virtual canvas image then push to image.
200 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
201 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
203 image->colorspace=RGBColorspace;
204 switch (image_info->interlace)
210 No interlacing: RGBRGBRGBRGBRGBRGB...
214 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
215 count=ReadBlob(image,length,pixels);
217 for (y=0; y < (ssize_t) image->extract_info.height; y++)
219 register const PixelPacket
228 if (count != (ssize_t) length)
230 ThrowFileException(exception,CorruptImageError,
231 "UnexpectedEndOfFile",image->filename);
234 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
236 if (q == (PixelPacket *) NULL)
238 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
239 quantum_info,quantum_type,pixels,exception);
240 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
242 if (((y-image->extract_info.y) >= 0) &&
243 ((y-image->extract_info.y) < (ssize_t) image->rows))
245 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
246 canvas_image->columns,1,exception);
247 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
248 image->columns,1,exception);
249 if ((p == (const PixelPacket *) NULL) ||
250 (q == (PixelPacket *) NULL))
252 for (x=0; x < (ssize_t) image->columns; x++)
254 SetRedPixelComponent(q,GetRedPixelComponent(p));
255 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
256 SetBluePixelComponent(q,GetBluePixelComponent(p));
257 SetOpacityPixelComponent(q,OpaqueOpacity);
258 if (image->matte != MagickFalse)
259 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
263 if (SyncAuthenticPixels(image,exception) == MagickFalse)
266 if (image->previous == (Image *) NULL)
268 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
270 if (status == MagickFalse)
273 count=ReadBlob(image,length,pixels);
289 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
291 if (LocaleCompare(image_info->magick,"RGBO") == 0)
292 quantum_types[3]=OpacityQuantum;
295 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
296 count=ReadBlob(image,length,pixels);
298 for (y=0; y < (ssize_t) image->extract_info.height; y++)
300 register const PixelPacket
309 if (count != (ssize_t) length)
311 ThrowFileException(exception,CorruptImageError,
312 "UnexpectedEndOfFile",image->filename);
315 for (i=0; i < (ssize_t) (image->matte != MagickFalse ? 4 : 3); i++)
317 quantum_type=quantum_types[i];
318 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
320 if (q == (PixelPacket *) NULL)
322 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
323 quantum_info,quantum_type,pixels,exception);
324 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
326 if (((y-image->extract_info.y) >= 0) &&
327 ((y-image->extract_info.y) < (ssize_t) image->rows))
329 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
330 0,canvas_image->columns,1,exception);
331 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
332 image->columns,1,exception);
333 if ((p == (const PixelPacket *) NULL) ||
334 (q == (PixelPacket *) NULL))
336 for (x=0; x < (ssize_t) image->columns; x++)
338 switch (quantum_type)
342 SetRedPixelComponent(q,GetRedPixelComponent(p));
347 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
352 SetBluePixelComponent(q,GetBluePixelComponent(p));
357 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
362 SetAlphaPixelComponent(q,GetAlphaPixelComponent(p));
371 if (SyncAuthenticPixels(image,exception) == MagickFalse)
374 count=ReadBlob(image,length,pixels);
376 if (image->previous == (Image *) NULL)
378 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
380 if (status == MagickFalse)
389 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
393 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
394 count=ReadBlob(image,length,pixels);
396 for (y=0; y < (ssize_t) image->extract_info.height; y++)
398 register const PixelPacket
407 if (count != (ssize_t) length)
409 ThrowFileException(exception,CorruptImageError,
410 "UnexpectedEndOfFile",image->filename);
413 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
415 if (q == (PixelPacket *) NULL)
417 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
418 quantum_info,RedQuantum,pixels,exception);
419 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
421 if (((y-image->extract_info.y) >= 0) &&
422 ((y-image->extract_info.y) < (ssize_t) image->rows))
424 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
425 canvas_image->columns,1,exception);
426 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
427 image->columns,1,exception);
428 if ((p == (const PixelPacket *) NULL) ||
429 (q == (PixelPacket *) NULL))
431 for (x=0; x < (ssize_t) image->columns; x++)
433 SetRedPixelComponent(q,GetRedPixelComponent(p));
437 if (SyncAuthenticPixels(image,exception) == MagickFalse)
440 count=ReadBlob(image,length,pixels);
442 if (image->previous == (Image *) NULL)
444 status=SetImageProgress(image,LoadImageTag,1,6);
445 if (status == MagickFalse)
448 for (y=0; y < (ssize_t) image->extract_info.height; y++)
450 register const PixelPacket
459 if (count != (ssize_t) length)
461 ThrowFileException(exception,CorruptImageError,
462 "UnexpectedEndOfFile",image->filename);
465 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
467 if (q == (PixelPacket *) NULL)
469 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
470 quantum_info,GreenQuantum,pixels,exception);
471 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
473 if (((y-image->extract_info.y) >= 0) &&
474 ((y-image->extract_info.y) < (ssize_t) image->rows))
476 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
477 canvas_image->columns,1,exception);
478 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
479 image->columns,1,exception);
480 if ((p == (const PixelPacket *) NULL) ||
481 (q == (PixelPacket *) NULL))
483 for (x=0; x < (ssize_t) image->columns; x++)
485 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
489 if (SyncAuthenticPixels(image,exception) == MagickFalse)
492 count=ReadBlob(image,length,pixels);
494 if (image->previous == (Image *) NULL)
496 status=SetImageProgress(image,LoadImageTag,2,6);
497 if (status == MagickFalse)
500 for (y=0; y < (ssize_t) image->extract_info.height; y++)
502 register const PixelPacket
511 if (count != (ssize_t) length)
513 ThrowFileException(exception,CorruptImageError,
514 "UnexpectedEndOfFile",image->filename);
517 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
519 if (q == (PixelPacket *) NULL)
521 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
522 quantum_info,BlueQuantum,pixels,exception);
523 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
525 if (((y-image->extract_info.y) >= 0) &&
526 ((y-image->extract_info.y) < (ssize_t) image->rows))
528 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
529 canvas_image->columns,1,exception);
530 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
531 image->columns,1,exception);
532 if ((p == (const PixelPacket *) NULL) ||
533 (q == (PixelPacket *) NULL))
535 for (x=0; x < (ssize_t) image->columns; x++)
537 SetBluePixelComponent(q,GetBluePixelComponent(p));
541 if (SyncAuthenticPixels(image,exception) == MagickFalse)
544 count=ReadBlob(image,length,pixels);
546 if (image->previous == (Image *) NULL)
548 status=SetImageProgress(image,LoadImageTag,3,6);
549 if (status == MagickFalse)
552 if (image->previous == (Image *) NULL)
554 status=SetImageProgress(image,LoadImageTag,4,6);
555 if (status == MagickFalse)
558 if (image->matte != MagickFalse)
560 for (y=0; y < (ssize_t) image->extract_info.height; y++)
562 register const PixelPacket
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 == (PixelPacket *) NULL)
581 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
582 quantum_info,AlphaQuantum,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,
589 canvas_image->extract_info.x,0,canvas_image->columns,1,
591 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
592 image->columns,1,exception);
593 if ((p == (const PixelPacket *) NULL) ||
594 (q == (PixelPacket *) NULL))
596 for (x=0; x < (ssize_t) image->columns; x++)
598 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
602 if (SyncAuthenticPixels(image,exception) == MagickFalse)
605 count=ReadBlob(image,length,pixels);
607 if (image->previous == (Image *) NULL)
609 status=SetImageProgress(image,LoadImageTag,5,6);
610 if (status == MagickFalse)
614 if (image->previous == (Image *) NULL)
616 status=SetImageProgress(image,LoadImageTag,6,6);
617 if (status == MagickFalse)
622 case PartitionInterlace:
625 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
627 AppendImageFormat("R",image->filename);
628 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
629 if (status == MagickFalse)
631 canvas_image=DestroyImageList(canvas_image);
632 image=DestroyImageList(image);
633 return((Image *) NULL);
635 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
636 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
638 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
639 for (i=0; i < (ssize_t) scene; i++)
640 for (y=0; y < (ssize_t) image->extract_info.height; y++)
641 if (ReadBlob(image,length,pixels) != (ssize_t) length)
643 ThrowFileException(exception,CorruptImageError,
644 "UnexpectedEndOfFile",image->filename);
647 count=ReadBlob(image,length,pixels);
648 for (y=0; y < (ssize_t) image->extract_info.height; y++)
650 register const PixelPacket
659 if (count != (ssize_t) length)
661 ThrowFileException(exception,CorruptImageError,
662 "UnexpectedEndOfFile",image->filename);
665 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
667 if (q == (PixelPacket *) NULL)
669 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
670 quantum_info,RedQuantum,pixels,exception);
671 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
673 if (((y-image->extract_info.y) >= 0) &&
674 ((y-image->extract_info.y) < (ssize_t) image->rows))
676 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
677 canvas_image->columns,1,exception);
678 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
679 image->columns,1,exception);
680 if ((p == (const PixelPacket *) NULL) ||
681 (q == (PixelPacket *) NULL))
683 for (x=0; x < (ssize_t) image->columns; x++)
685 SetRedPixelComponent(q,GetRedPixelComponent(p));
689 if (SyncAuthenticPixels(image,exception) == MagickFalse)
692 count=ReadBlob(image,length,pixels);
694 if (image->previous == (Image *) NULL)
696 status=SetImageProgress(image,LoadImageTag,1,5);
697 if (status == MagickFalse)
700 (void) CloseBlob(image);
701 AppendImageFormat("G",image->filename);
702 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
703 if (status == MagickFalse)
705 canvas_image=DestroyImageList(canvas_image);
706 image=DestroyImageList(image);
707 return((Image *) NULL);
709 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
710 for (i=0; i < (ssize_t) scene; i++)
711 for (y=0; y < (ssize_t) image->extract_info.height; y++)
712 if (ReadBlob(image,length,pixels) != (ssize_t) length)
714 ThrowFileException(exception,CorruptImageError,
715 "UnexpectedEndOfFile",image->filename);
718 count=ReadBlob(image,length,pixels);
719 for (y=0; y < (ssize_t) image->extract_info.height; y++)
721 register const PixelPacket
730 if (count != (ssize_t) length)
732 ThrowFileException(exception,CorruptImageError,
733 "UnexpectedEndOfFile",image->filename);
736 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
738 if (q == (PixelPacket *) NULL)
740 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
741 quantum_info,GreenQuantum,pixels,exception);
742 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
744 if (((y-image->extract_info.y) >= 0) &&
745 ((y-image->extract_info.y) < (ssize_t) image->rows))
747 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
748 canvas_image->columns,1,exception);
749 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
750 image->columns,1,exception);
751 if ((p == (const PixelPacket *) NULL) ||
752 (q == (PixelPacket *) NULL))
754 for (x=0; x < (ssize_t) image->columns; x++)
756 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
760 if (SyncAuthenticPixels(image,exception) == MagickFalse)
763 count=ReadBlob(image,length,pixels);
765 if (image->previous == (Image *) NULL)
767 status=SetImageProgress(image,LoadImageTag,2,5);
768 if (status == MagickFalse)
771 (void) CloseBlob(image);
772 AppendImageFormat("B",image->filename);
773 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
774 if (status == MagickFalse)
776 canvas_image=DestroyImageList(canvas_image);
777 image=DestroyImageList(image);
778 return((Image *) NULL);
780 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
781 for (i=0; i < (ssize_t) scene; i++)
782 for (y=0; y < (ssize_t) image->extract_info.height; y++)
783 if (ReadBlob(image,length,pixels) != (ssize_t) length)
785 ThrowFileException(exception,CorruptImageError,
786 "UnexpectedEndOfFile",image->filename);
789 count=ReadBlob(image,length,pixels);
790 for (y=0; y < (ssize_t) image->extract_info.height; y++)
792 register const PixelPacket
801 if (count != (ssize_t) length)
803 ThrowFileException(exception,CorruptImageError,
804 "UnexpectedEndOfFile",image->filename);
807 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
809 if (q == (PixelPacket *) NULL)
811 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
812 quantum_info,BlueQuantum,pixels,exception);
813 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
815 if (((y-image->extract_info.y) >= 0) &&
816 ((y-image->extract_info.y) < (ssize_t) image->rows))
818 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
819 canvas_image->columns,1,exception);
820 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
821 image->columns,1,exception);
822 if ((p == (const PixelPacket *) NULL) ||
823 (q == (PixelPacket *) NULL))
825 for (x=0; x < (ssize_t) image->columns; x++)
827 SetBluePixelComponent(q,GetBluePixelComponent(p));
831 if (SyncAuthenticPixels(image,exception) == MagickFalse)
834 count=ReadBlob(image,length,pixels);
836 if (image->previous == (Image *) NULL)
838 status=SetImageProgress(image,LoadImageTag,3,5);
839 if (status == MagickFalse)
842 if (image->matte != MagickFalse)
844 (void) CloseBlob(image);
845 AppendImageFormat("A",image->filename);
846 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
847 if (status == MagickFalse)
849 canvas_image=DestroyImageList(canvas_image);
850 image=DestroyImageList(image);
851 return((Image *) NULL);
853 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
854 for (i=0; i < (ssize_t) scene; i++)
855 for (y=0; y < (ssize_t) image->extract_info.height; y++)
856 if (ReadBlob(image,length,pixels) != (ssize_t) length)
858 ThrowFileException(exception,CorruptImageError,
859 "UnexpectedEndOfFile",image->filename);
862 count=ReadBlob(image,length,pixels);
863 for (y=0; y < (ssize_t) image->extract_info.height; y++)
865 register const PixelPacket
874 if (count != (ssize_t) length)
876 ThrowFileException(exception,CorruptImageError,
877 "UnexpectedEndOfFile",image->filename);
880 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
882 if (q == (PixelPacket *) NULL)
884 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
885 quantum_info,BlueQuantum,pixels,exception);
886 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
888 if (((y-image->extract_info.y) >= 0) &&
889 ((y-image->extract_info.y) < (ssize_t) image->rows))
891 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
892 0,canvas_image->columns,1,exception);
893 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
894 image->columns,1,exception);
895 if ((p == (const PixelPacket *) NULL) ||
896 (q == (PixelPacket *) NULL))
898 for (x=0; x < (ssize_t) image->columns; x++)
900 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
904 if (SyncAuthenticPixels(image,exception) == MagickFalse)
907 count=ReadBlob(image,length,pixels);
909 if (image->previous == (Image *) NULL)
911 status=SetImageProgress(image,LoadImageTag,4,5);
912 if (status == MagickFalse)
916 (void) CloseBlob(image);
917 if (image->previous == (Image *) NULL)
919 status=SetImageProgress(image,LoadImageTag,5,5);
920 if (status == MagickFalse)
926 SetQuantumImageType(image,quantum_type);
928 Proceed to next image.
930 if (image_info->number_scenes != 0)
931 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
933 if (count == (ssize_t) length)
936 Allocate next image structure.
938 AcquireNextImage(image_info,image);
939 if (GetNextImageInList(image) == (Image *) NULL)
941 image=DestroyImageList(image);
942 return((Image *) NULL);
944 image=SyncNextImageInList(image);
945 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
947 if (status == MagickFalse)
951 } while (count == (ssize_t) length);
952 quantum_info=DestroyQuantumInfo(quantum_info);
953 InheritException(&image->exception,&canvas_image->exception);
954 canvas_image=DestroyImage(canvas_image);
955 (void) CloseBlob(image);
956 return(GetFirstImageInList(image));
960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
964 % R e g i s t e r R G B I m a g e %
968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
970 % RegisterRGBImage() adds attributes for the RGB image format to
971 % the list of supported formats. The attributes include the image format
972 % tag, a method to read and/or write the format, whether the format
973 % supports the saving of more than one frame to the same file or blob,
974 % whether the format supports native in-memory I/O, and a brief
975 % description of the format.
977 % The format of the RegisterRGBImage method is:
979 % size_t RegisterRGBImage(void)
982 ModuleExport size_t RegisterRGBImage(void)
987 entry=SetMagickInfo("RGB");
988 entry->decoder=(DecodeImageHandler *) ReadRGBImage;
989 entry->encoder=(EncodeImageHandler *) WriteRGBImage;
990 entry->raw=MagickTrue;
991 entry->endian_support=MagickTrue;
992 entry->description=ConstantString("Raw red, green, and blue samples");
993 entry->module=ConstantString("RGB");
994 (void) RegisterMagickInfo(entry);
995 entry=SetMagickInfo("RGBA");
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, blue, and alpha samples");
1001 entry->module=ConstantString("RGB");
1002 (void) RegisterMagickInfo(entry);
1003 entry=SetMagickInfo("RGBO");
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 opacity samples");
1009 entry->module=ConstantString("RGB");
1010 (void) RegisterMagickInfo(entry);
1011 return(MagickImageCoderSignature);
1015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1019 % U n r e g i s t e r R G B I m a g e %
1023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1025 % UnregisterRGBImage() removes format registrations made by the RGB module
1026 % from the list of supported formats.
1028 % The format of the UnregisterRGBImage method is:
1030 % UnregisterRGBImage(void)
1033 ModuleExport void UnregisterRGBImage(void)
1035 (void) UnregisterMagickInfo("RGBO");
1036 (void) UnregisterMagickInfo("RGBA");
1037 (void) UnregisterMagickInfo("RGB");
1041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045 % W r i t e R G B I m a g e %
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051 % WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO
1052 % rasterfile format.
1054 % The format of the WriteRGBImage method is:
1056 % MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1059 % A description of each parameter follows.
1061 % o image_info: the image info.
1063 % o image: The image.
1066 static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1092 Allocate memory for pixels.
1094 assert(image_info != (const ImageInfo *) NULL);
1095 assert(image_info->signature == MagickSignature);
1096 assert(image != (Image *) NULL);
1097 assert(image->signature == MagickSignature);
1098 if (image->debug != MagickFalse)
1099 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1100 if (image_info->interlace != PartitionInterlace)
1103 Open output image file.
1105 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1106 if (status == MagickFalse)
1109 quantum_type=RGBQuantum;
1110 if (LocaleCompare(image_info->magick,"RGBA") == 0)
1112 quantum_type=RGBAQuantum;
1113 image->matte=MagickTrue;
1115 if (LocaleCompare(image_info->magick,"RGBO") == 0)
1117 quantum_type=RGBOQuantum;
1118 image->matte=MagickTrue;
1124 Convert MIFF to RGB raster pixels.
1126 if (image->colorspace != RGBColorspace)
1127 (void) TransformImageColorspace(image,RGBColorspace);
1128 if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
1129 (image->matte == MagickFalse))
1130 (void) SetImageAlphaChannel(image,ResetAlphaChannel);
1131 quantum_info=AcquireQuantumInfo(image_info,image);
1132 if (quantum_info == (QuantumInfo *) NULL)
1133 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1134 pixels=GetQuantumPixels(quantum_info);
1135 switch (image_info->interlace)
1141 No interlacing: RGBRGBRGBRGBRGBRGB...
1143 for (y=0; y < (ssize_t) image->rows; y++)
1145 register const PixelPacket
1148 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1149 if (p == (const PixelPacket *) NULL)
1151 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1152 quantum_info,quantum_type,pixels,&image->exception);
1153 count=WriteBlob(image,length,pixels);
1154 if (count != (ssize_t) length)
1156 if (image->previous == (Image *) NULL)
1158 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1160 if (status == MagickFalse)
1169 Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
1171 for (y=0; y < (ssize_t) image->rows; y++)
1173 register const PixelPacket
1176 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1177 if (p == (const PixelPacket *) NULL)
1179 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1180 quantum_info,RedQuantum,pixels,&image->exception);
1181 count=WriteBlob(image,length,pixels);
1182 if (count != (ssize_t) length)
1184 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1185 quantum_info,GreenQuantum,pixels,&image->exception);
1186 count=WriteBlob(image,length,pixels);
1187 if (count != (ssize_t) length)
1189 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1190 quantum_info,BlueQuantum,pixels,&image->exception);
1191 count=WriteBlob(image,length,pixels);
1192 if (count != (ssize_t) length)
1194 if (quantum_type == RGBAQuantum)
1196 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1197 quantum_info,AlphaQuantum,pixels,&image->exception);
1198 count=WriteBlob(image,length,pixels);
1199 if (count != (ssize_t) length)
1202 if (quantum_type == RGBOQuantum)
1204 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1205 quantum_info,OpacityQuantum,pixels,&image->exception);
1206 count=WriteBlob(image,length,pixels);
1207 if (count != (ssize_t) length)
1210 if (image->previous == (Image *) NULL)
1212 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1214 if (status == MagickFalse)
1220 case PlaneInterlace:
1223 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
1225 for (y=0; y < (ssize_t) image->rows; y++)
1227 register const PixelPacket
1230 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1231 if (p == (const PixelPacket *) NULL)
1233 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1234 quantum_info,RedQuantum,pixels,&image->exception);
1235 count=WriteBlob(image,length,pixels);
1236 if (count != (ssize_t) length)
1239 if (image->previous == (Image *) NULL)
1241 status=SetImageProgress(image,SaveImageTag,1,6);
1242 if (status == MagickFalse)
1245 for (y=0; y < (ssize_t) image->rows; y++)
1247 register const PixelPacket
1250 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1251 if (p == (const PixelPacket *) NULL)
1253 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1254 quantum_info,GreenQuantum,pixels,&image->exception);
1255 count=WriteBlob(image,length,pixels);
1256 if (count != (ssize_t) length)
1259 if (image->previous == (Image *) NULL)
1261 status=SetImageProgress(image,SaveImageTag,2,6);
1262 if (status == MagickFalse)
1265 for (y=0; y < (ssize_t) image->rows; y++)
1267 register const PixelPacket
1270 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1271 if (p == (const PixelPacket *) NULL)
1273 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1274 quantum_info,BlueQuantum,pixels,&image->exception);
1275 count=WriteBlob(image,length,pixels);
1276 if (count != (ssize_t) length)
1279 if (image->previous == (Image *) NULL)
1281 status=SetImageProgress(image,SaveImageTag,3,6);
1282 if (status == MagickFalse)
1285 if (quantum_type == RGBAQuantum)
1287 for (y=0; y < (ssize_t) image->rows; y++)
1289 register const PixelPacket
1292 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1293 if (p == (const PixelPacket *) NULL)
1295 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1296 quantum_info,AlphaQuantum,pixels,&image->exception);
1297 count=WriteBlob(image,length,pixels);
1298 if (count != (ssize_t) length)
1301 if (image->previous == (Image *) NULL)
1303 status=SetImageProgress(image,SaveImageTag,5,6);
1304 if (status == MagickFalse)
1308 if (image_info->interlace == PartitionInterlace)
1309 (void) CopyMagickString(image->filename,image_info->filename,
1311 if (image->previous == (Image *) NULL)
1313 status=SetImageProgress(image,SaveImageTag,6,6);
1314 if (status == MagickFalse)
1319 case PartitionInterlace:
1322 Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
1324 AppendImageFormat("R",image->filename);
1325 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1326 AppendBinaryBlobMode,&image->exception);
1327 if (status == MagickFalse)
1329 for (y=0; y < (ssize_t) image->rows; y++)
1331 register const PixelPacket
1334 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1335 if (p == (const PixelPacket *) NULL)
1337 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1338 quantum_info,RedQuantum,pixels,&image->exception);
1339 count=WriteBlob(image,length,pixels);
1340 if (count != (ssize_t) length)
1343 if (image->previous == (Image *) NULL)
1345 status=SetImageProgress(image,SaveImageTag,1,6);
1346 if (status == MagickFalse)
1349 (void) CloseBlob(image);
1350 AppendImageFormat("G",image->filename);
1351 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1352 AppendBinaryBlobMode,&image->exception);
1353 if (status == MagickFalse)
1355 for (y=0; y < (ssize_t) image->rows; y++)
1357 register const PixelPacket
1360 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1361 if (p == (const PixelPacket *) NULL)
1363 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1364 quantum_info,GreenQuantum,pixels,&image->exception);
1365 count=WriteBlob(image,length,pixels);
1366 if (count != (ssize_t) length)
1369 if (image->previous == (Image *) NULL)
1371 status=SetImageProgress(image,SaveImageTag,2,6);
1372 if (status == MagickFalse)
1375 (void) CloseBlob(image);
1376 AppendImageFormat("B",image->filename);
1377 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1378 AppendBinaryBlobMode,&image->exception);
1379 if (status == MagickFalse)
1381 for (y=0; y < (ssize_t) image->rows; y++)
1383 register const PixelPacket
1386 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1387 if (p == (const PixelPacket *) NULL)
1389 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1390 quantum_info,BlueQuantum,pixels,&image->exception);
1391 count=WriteBlob(image,length,pixels);
1392 if (count != (ssize_t) length)
1395 if (image->previous == (Image *) NULL)
1397 status=SetImageProgress(image,SaveImageTag,3,6);
1398 if (status == MagickFalse)
1401 (void) CloseBlob(image);
1402 if (quantum_type == RGBAQuantum)
1404 (void) CloseBlob(image);
1405 AppendImageFormat("A",image->filename);
1406 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1407 AppendBinaryBlobMode,&image->exception);
1408 if (status == MagickFalse)
1410 for (y=0; y < (ssize_t) image->rows; y++)
1412 register const PixelPacket
1415 p=GetVirtualPixels(image,0,y,image->columns,1,
1417 if (p == (const PixelPacket *) NULL)
1419 length=ExportQuantumPixels(image,(const CacheView *) NULL,
1420 quantum_info,AlphaQuantum,pixels,&image->exception);
1421 count=WriteBlob(image,length,pixels);
1422 if (count != (ssize_t) length)
1425 if (image->previous == (Image *) NULL)
1427 status=SetImageProgress(image,SaveImageTag,5,6);
1428 if (status == MagickFalse)
1432 (void) CloseBlob(image);
1433 (void) CopyMagickString(image->filename,image_info->filename,
1435 if (image->previous == (Image *) NULL)
1437 status=SetImageProgress(image,SaveImageTag,6,6);
1438 if (status == MagickFalse)
1444 quantum_info=DestroyQuantumInfo(quantum_info);
1445 if (GetNextImageInList(image) == (Image *) NULL)
1447 image=SyncNextImageInList(image);
1448 status=SetImageProgress(image,SaveImagesTag,scene++,
1449 GetImageListLength(image));
1450 if (status == MagickFalse)
1452 } while (image_info->adjoin != MagickFalse);
1453 (void) CloseBlob(image);