2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Raw BGR 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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/colorspace.h"
47 #include "MagickCore/colorspace-private.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 WriteBGRImage(const ImageInfo *,Image *,ExceptionInfo *);
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % R e a d B G R I m a g e %
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 % ReadBGRImage() reads an image of raw BGR, or BGRA samples and returns
84 % it. It allocates the memory necessary for the new Image structure and
85 % returns a pointer to the new image.
87 % The format of the ReadBGRImage method is:
89 % Image *ReadBGRImage(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 *ReadBGRImage(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 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,
163 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
164 if (quantum_info == (QuantumInfo *) NULL)
165 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
166 pixels=GetQuantumPixels(quantum_info);
167 quantum_type=BGRQuantum;
168 if (LocaleCompare(image_info->magick,"BGRA") == 0)
170 quantum_type=BGRAQuantum;
171 image->matte=MagickTrue;
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 count=ReadBlob(image,length,pixels);
184 if (count != (ssize_t) length)
194 Read pixels to virtual canvas image then push to image.
196 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
197 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
199 switch (image_info->interlace)
205 No interlacing: BGRBGRBGRBGRBGRBGR...
209 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
210 count=ReadBlob(image,length,pixels);
212 for (y=0; y < (ssize_t) image->extract_info.height; y++)
214 register const Quantum
223 if (count != (ssize_t) length)
225 ThrowFileException(exception,CorruptImageError,
226 "UnexpectedEndOfFile",image->filename);
229 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
231 if (q == (Quantum *) NULL)
233 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
234 quantum_info,quantum_type,pixels,exception);
235 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
237 if (((y-image->extract_info.y) >= 0) &&
238 ((y-image->extract_info.y) < (ssize_t) image->rows))
240 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
241 canvas_image->columns,1,exception);
242 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
243 image->columns,1,exception);
244 if ((p == (const Quantum *) NULL) ||
245 (q == (Quantum *) NULL))
247 for (x=0; x < (ssize_t) image->columns; x++)
249 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
250 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
251 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
252 SetPixelAlpha(image,OpaqueAlpha,q);
253 if (image->matte != MagickFalse)
254 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
255 p+=GetPixelChannels(canvas_image);
256 q+=GetPixelChannels(image);
258 if (SyncAuthenticPixels(image,exception) == MagickFalse)
261 if (image->previous == (Image *) NULL)
263 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
265 if (status == MagickFalse)
268 count=ReadBlob(image,length,pixels);
284 Line interlacing: BBB...GGG...RRR...RRR...GGG...BBB...
288 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
289 count=ReadBlob(image,length,pixels);
291 for (y=0; y < (ssize_t) image->extract_info.height; y++)
293 register const Quantum
302 if (count != (ssize_t) length)
304 ThrowFileException(exception,CorruptImageError,
305 "UnexpectedEndOfFile",image->filename);
308 for (i=0; i < (ssize_t) (image->matte != MagickFalse ? 4 : 3); i++)
310 quantum_type=quantum_types[i];
311 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
313 if (q == (Quantum *) NULL)
315 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
316 quantum_info,quantum_type,pixels,exception);
317 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
319 if (((y-image->extract_info.y) >= 0) &&
320 ((y-image->extract_info.y) < (ssize_t) image->rows))
322 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
323 canvas_image->columns,1,exception);
324 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
325 image->columns,1,exception);
326 if ((p == (const Quantum *) NULL) ||
327 (q == (Quantum *) NULL))
329 for (x=0; x < (ssize_t) image->columns; x++)
331 switch (quantum_type)
335 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
340 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
345 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
350 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
355 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
361 p+=GetPixelChannels(canvas_image);
362 q+=GetPixelChannels(image);
364 if (SyncAuthenticPixels(image,exception) == MagickFalse)
367 count=ReadBlob(image,length,pixels);
369 if (image->previous == (Image *) NULL)
371 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
373 if (status == MagickFalse)
382 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
386 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
387 count=ReadBlob(image,length,pixels);
389 for (y=0; y < (ssize_t) image->extract_info.height; y++)
391 register const Quantum
400 if (count != (ssize_t) length)
402 ThrowFileException(exception,CorruptImageError,
403 "UnexpectedEndOfFile",image->filename);
406 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
408 if (q == (Quantum *) NULL)
410 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
411 quantum_info,RedQuantum,pixels,exception);
412 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
414 if (((y-image->extract_info.y) >= 0) &&
415 ((y-image->extract_info.y) < (ssize_t) image->rows))
417 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
418 canvas_image->columns,1,exception);
419 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
420 image->columns,1,exception);
421 if ((p == (const Quantum *) NULL) ||
422 (q == (Quantum *) NULL))
424 for (x=0; x < (ssize_t) image->columns; x++)
426 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
427 p+=GetPixelChannels(canvas_image);
428 q+=GetPixelChannels(image);
430 if (SyncAuthenticPixels(image,exception) == MagickFalse)
433 count=ReadBlob(image,length,pixels);
435 if (image->previous == (Image *) NULL)
437 status=SetImageProgress(image,LoadImageTag,1,6);
438 if (status == MagickFalse)
441 for (y=0; y < (ssize_t) image->extract_info.height; y++)
443 register const Quantum
452 if (count != (ssize_t) length)
454 ThrowFileException(exception,CorruptImageError,
455 "UnexpectedEndOfFile",image->filename);
458 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
460 if (q == (Quantum *) NULL)
462 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
463 quantum_info,GreenQuantum,pixels,exception);
464 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
466 if (((y-image->extract_info.y) >= 0) &&
467 ((y-image->extract_info.y) < (ssize_t) image->rows))
469 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
470 canvas_image->columns,1,exception);
471 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
472 image->columns,1,exception);
473 if ((p == (const Quantum *) NULL) ||
474 (q == (Quantum *) NULL))
476 for (x=0; x < (ssize_t) image->columns; x++)
478 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
479 p+=GetPixelChannels(canvas_image);
480 q+=GetPixelChannels(image);
482 if (SyncAuthenticPixels(image,exception) == MagickFalse)
485 count=ReadBlob(image,length,pixels);
487 if (image->previous == (Image *) NULL)
489 status=SetImageProgress(image,LoadImageTag,2,6);
490 if (status == MagickFalse)
493 for (y=0; y < (ssize_t) image->extract_info.height; y++)
495 register const Quantum
504 if (count != (ssize_t) length)
506 ThrowFileException(exception,CorruptImageError,
507 "UnexpectedEndOfFile",image->filename);
510 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
512 if (q == (Quantum *) NULL)
514 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
515 quantum_info,BlueQuantum,pixels,exception);
516 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
518 if (((y-image->extract_info.y) >= 0) &&
519 ((y-image->extract_info.y) < (ssize_t) image->rows))
521 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
522 canvas_image->columns,1,exception);
523 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
524 image->columns,1,exception);
525 if ((p == (const Quantum *) NULL) ||
526 (q == (Quantum *) NULL))
528 for (x=0; x < (ssize_t) image->columns; x++)
530 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
531 p+=GetPixelChannels(canvas_image);
532 q+=GetPixelChannels(image);
534 if (SyncAuthenticPixels(image,exception) == MagickFalse)
537 count=ReadBlob(image,length,pixels);
539 if (image->previous == (Image *) NULL)
541 status=SetImageProgress(image,LoadImageTag,3,6);
542 if (status == MagickFalse)
545 if (image->previous == (Image *) NULL)
547 status=SetImageProgress(image,LoadImageTag,4,6);
548 if (status == MagickFalse)
551 if (image->matte != MagickFalse)
553 for (y=0; y < (ssize_t) image->extract_info.height; y++)
555 register const Quantum
564 if (count != (ssize_t) length)
566 ThrowFileException(exception,CorruptImageError,
567 "UnexpectedEndOfFile",image->filename);
570 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
572 if (q == (Quantum *) NULL)
574 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
575 quantum_info,AlphaQuantum,pixels,exception);
576 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
578 if (((y-image->extract_info.y) >= 0) &&
579 ((y-image->extract_info.y) < (ssize_t) image->rows))
581 p=GetVirtualPixels(canvas_image,
582 canvas_image->extract_info.x,0,canvas_image->columns,1,
584 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
585 image->columns,1,exception);
586 if ((p == (const Quantum *) NULL) ||
587 (q == (Quantum *) NULL))
589 for (x=0; x < (ssize_t) image->columns; x++)
591 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
592 p+=GetPixelChannels(canvas_image);
593 q+=GetPixelChannels(image);
595 if (SyncAuthenticPixels(image,exception) == MagickFalse)
598 count=ReadBlob(image,length,pixels);
600 if (image->previous == (Image *) NULL)
602 status=SetImageProgress(image,LoadImageTag,5,6);
603 if (status == MagickFalse)
607 if (image->previous == (Image *) NULL)
609 status=SetImageProgress(image,LoadImageTag,6,6);
610 if (status == MagickFalse)
615 case PartitionInterlace:
618 Partition interlacing: BBBBBB..., GGGGGG..., RRRRRR...
620 AppendImageFormat("B",image->filename);
621 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
622 if (status == MagickFalse)
624 canvas_image=DestroyImageList(canvas_image);
625 image=DestroyImageList(image);
626 return((Image *) NULL);
628 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
629 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
631 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
632 for (i=0; i < (ssize_t) scene; i++)
633 for (y=0; y < (ssize_t) image->extract_info.height; y++)
634 if (ReadBlob(image,length,pixels) != (ssize_t) length)
636 ThrowFileException(exception,CorruptImageError,
637 "UnexpectedEndOfFile",image->filename);
640 count=ReadBlob(image,length,pixels);
641 for (y=0; y < (ssize_t) image->extract_info.height; y++)
643 register const Quantum
652 if (count != (ssize_t) length)
654 ThrowFileException(exception,CorruptImageError,
655 "UnexpectedEndOfFile",image->filename);
658 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
660 if (q == (Quantum *) NULL)
662 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
663 quantum_info,BlueQuantum,pixels,exception);
664 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
666 if (((y-image->extract_info.y) >= 0) &&
667 ((y-image->extract_info.y) < (ssize_t) image->rows))
669 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
670 canvas_image->columns,1,exception);
671 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
672 image->columns,1,exception);
673 if ((p == (const Quantum *) NULL) ||
674 (q == (Quantum *) NULL))
676 for (x=0; x < (ssize_t) image->columns; x++)
678 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
679 p+=GetPixelChannels(canvas_image);
680 q+=GetPixelChannels(image);
682 if (SyncAuthenticPixels(image,exception) == MagickFalse)
685 count=ReadBlob(image,length,pixels);
687 if (image->previous == (Image *) NULL)
689 status=SetImageProgress(image,LoadImageTag,1,5);
690 if (status == MagickFalse)
693 (void) CloseBlob(image);
694 AppendImageFormat("G",image->filename);
695 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
696 if (status == MagickFalse)
698 canvas_image=DestroyImageList(canvas_image);
699 image=DestroyImageList(image);
700 return((Image *) NULL);
702 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
703 for (i=0; i < (ssize_t) scene; i++)
704 for (y=0; y < (ssize_t) image->extract_info.height; y++)
705 if (ReadBlob(image,length,pixels) != (ssize_t) length)
707 ThrowFileException(exception,CorruptImageError,
708 "UnexpectedEndOfFile",image->filename);
711 count=ReadBlob(image,length,pixels);
712 for (y=0; y < (ssize_t) image->extract_info.height; y++)
714 register const Quantum
723 if (count != (ssize_t) length)
725 ThrowFileException(exception,CorruptImageError,
726 "UnexpectedEndOfFile",image->filename);
729 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
731 if (q == (Quantum *) NULL)
733 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
734 quantum_info,GreenQuantum,pixels,exception);
735 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
737 if (((y-image->extract_info.y) >= 0) &&
738 ((y-image->extract_info.y) < (ssize_t) image->rows))
740 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
741 canvas_image->columns,1,exception);
742 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
743 image->columns,1,exception);
744 if ((p == (const Quantum *) NULL) ||
745 (q == (Quantum *) NULL))
747 for (x=0; x < (ssize_t) image->columns; x++)
749 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
750 p+=GetPixelChannels(canvas_image);
751 q+=GetPixelChannels(image);
753 if (SyncAuthenticPixels(image,exception) == MagickFalse)
756 count=ReadBlob(image,length,pixels);
758 if (image->previous == (Image *) NULL)
760 status=SetImageProgress(image,LoadImageTag,2,5);
761 if (status == MagickFalse)
764 (void) CloseBlob(image);
765 AppendImageFormat("R",image->filename);
766 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
767 if (status == MagickFalse)
769 canvas_image=DestroyImageList(canvas_image);
770 image=DestroyImageList(image);
771 return((Image *) NULL);
773 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
774 for (i=0; i < (ssize_t) scene; i++)
775 for (y=0; y < (ssize_t) image->extract_info.height; y++)
776 if (ReadBlob(image,length,pixels) != (ssize_t) length)
778 ThrowFileException(exception,CorruptImageError,
779 "UnexpectedEndOfFile",image->filename);
782 count=ReadBlob(image,length,pixels);
783 for (y=0; y < (ssize_t) image->extract_info.height; y++)
785 register const Quantum
794 if (count != (ssize_t) length)
796 ThrowFileException(exception,CorruptImageError,
797 "UnexpectedEndOfFile",image->filename);
800 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
802 if (q == (Quantum *) NULL)
804 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
805 quantum_info,RedQuantum,pixels,exception);
806 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
808 if (((y-image->extract_info.y) >= 0) &&
809 ((y-image->extract_info.y) < (ssize_t) image->rows))
811 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
812 canvas_image->columns,1,exception);
813 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
814 image->columns,1,exception);
815 if ((p == (const Quantum *) NULL) ||
816 (q == (Quantum *) NULL))
818 for (x=0; x < (ssize_t) image->columns; x++)
820 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
821 p+=GetPixelChannels(canvas_image);
822 q+=GetPixelChannels(image);
824 if (SyncAuthenticPixels(image,exception) == MagickFalse)
827 count=ReadBlob(image,length,pixels);
829 if (image->previous == (Image *) NULL)
831 status=SetImageProgress(image,LoadImageTag,3,5);
832 if (status == MagickFalse)
835 if (image->matte != MagickFalse)
837 (void) CloseBlob(image);
838 AppendImageFormat("A",image->filename);
839 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
840 if (status == MagickFalse)
842 canvas_image=DestroyImageList(canvas_image);
843 image=DestroyImageList(image);
844 return((Image *) NULL);
846 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
847 for (i=0; i < (ssize_t) scene; i++)
848 for (y=0; y < (ssize_t) image->extract_info.height; y++)
849 if (ReadBlob(image,length,pixels) != (ssize_t) length)
851 ThrowFileException(exception,CorruptImageError,
852 "UnexpectedEndOfFile",image->filename);
855 count=ReadBlob(image,length,pixels);
856 for (y=0; y < (ssize_t) image->extract_info.height; y++)
858 register const Quantum
867 if (count != (ssize_t) length)
869 ThrowFileException(exception,CorruptImageError,
870 "UnexpectedEndOfFile",image->filename);
873 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
875 if (q == (Quantum *) NULL)
877 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
878 quantum_info,BlueQuantum,pixels,exception);
879 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
881 if (((y-image->extract_info.y) >= 0) &&
882 ((y-image->extract_info.y) < (ssize_t) image->rows))
884 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
885 0,canvas_image->columns,1,exception);
886 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
887 image->columns,1,exception);
888 if ((p == (const Quantum *) NULL) ||
889 (q == (Quantum *) NULL))
891 for (x=0; x < (ssize_t) image->columns; x++)
893 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
894 p+=GetPixelChannels(canvas_image);
895 q+=GetPixelChannels(image);
897 if (SyncAuthenticPixels(image,exception) == MagickFalse)
900 count=ReadBlob(image,length,pixels);
902 if (image->previous == (Image *) NULL)
904 status=SetImageProgress(image,LoadImageTag,4,5);
905 if (status == MagickFalse)
909 (void) CloseBlob(image);
910 if (image->previous == (Image *) NULL)
912 status=SetImageProgress(image,LoadImageTag,5,5);
913 if (status == MagickFalse)
919 SetQuantumImageType(image,quantum_type);
921 Proceed to next image.
923 if (image_info->number_scenes != 0)
924 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
926 if (count == (ssize_t) length)
929 Allocate next image structure.
931 AcquireNextImage(image_info,image,exception);
932 if (GetNextImageInList(image) == (Image *) NULL)
934 image=DestroyImageList(image);
935 return((Image *) NULL);
937 image=SyncNextImageInList(image);
938 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
940 if (status == MagickFalse)
944 } while (count == (ssize_t) length);
945 quantum_info=DestroyQuantumInfo(quantum_info);
946 canvas_image=DestroyImage(canvas_image);
947 (void) CloseBlob(image);
948 return(GetFirstImageInList(image));
952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
956 % R e g i s t e r B G R I m a g e %
960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
962 % RegisterBGRImage() adds attributes for the BGR image format to
963 % the list of supported formats. The attributes include the image format
964 % tag, a method to read and/or write the format, whether the format
965 % supports the saving of more than one frame to the same file or blob,
966 % whether the format supports native in-memory I/O, and a brief
967 % description of the format.
969 % The format of the RegisterBGRImage method is:
971 % size_t RegisterBGRImage(void)
974 ModuleExport size_t RegisterBGRImage(void)
979 entry=SetMagickInfo("BGR");
980 entry->decoder=(DecodeImageHandler *) ReadBGRImage;
981 entry->encoder=(EncodeImageHandler *) WriteBGRImage;
982 entry->raw=MagickTrue;
983 entry->endian_support=MagickTrue;
984 entry->description=ConstantString("Raw blue, green, and red samples");
985 entry->module=ConstantString("BGR");
986 (void) RegisterMagickInfo(entry);
987 entry=SetMagickInfo("BGRA");
988 entry->decoder=(DecodeImageHandler *) ReadBGRImage;
989 entry->encoder=(EncodeImageHandler *) WriteBGRImage;
990 entry->raw=MagickTrue;
991 entry->endian_support=MagickTrue;
992 entry->description=ConstantString("Raw blue, green, red, and alpha samples");
993 entry->module=ConstantString("BGR");
994 (void) RegisterMagickInfo(entry);
995 return(MagickImageCoderSignature);
999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003 % U n r e g i s t e r B G R I m a g e %
1007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 % UnregisterBGRImage() removes format registrations made by the BGR module
1010 % from the list of supported formats.
1012 % The format of the UnregisterBGRImage method is:
1014 % UnregisterBGRImage(void)
1017 ModuleExport void UnregisterBGRImage(void)
1019 (void) UnregisterMagickInfo("BGRA");
1020 (void) UnregisterMagickInfo("BGR");
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028 % W r i t e B G R I m a g e %
1032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1034 % WriteBGRImage() writes an image to a file in the BGR or BGRA
1035 % rasterfile format.
1037 % The format of the WriteBGRImage method is:
1039 % MagickBooleanType WriteBGRImage(const ImageInfo *image_info,
1040 % Image *image,ExceptionInfo *exception)
1042 % A description of each parameter follows.
1044 % o image_info: the image info.
1046 % o image: The image.
1048 % o exception: return any errors or warnings in this structure.
1051 static MagickBooleanType WriteBGRImage(const ImageInfo *image_info,Image *image,
1052 ExceptionInfo *exception)
1077 Allocate memory for pixels.
1079 assert(image_info != (const ImageInfo *) NULL);
1080 assert(image_info->signature == MagickSignature);
1081 assert(image != (Image *) NULL);
1082 assert(image->signature == MagickSignature);
1083 if (image->debug != MagickFalse)
1084 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1085 if (image_info->interlace != PartitionInterlace)
1088 Open output image file.
1090 assert(exception != (ExceptionInfo *) NULL);
1091 assert(exception->signature == MagickSignature);
1092 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1093 if (status == MagickFalse)
1096 quantum_type=BGRQuantum;
1097 if (LocaleCompare(image_info->magick,"BGRA") == 0)
1099 quantum_type=BGRAQuantum;
1100 image->matte=MagickTrue;
1106 Convert MIFF to BGR raster pixels.
1108 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
1109 (void) TransformImageColorspace(image,sRGBColorspace,exception);
1110 if ((LocaleCompare(image_info->magick,"BGRA") == 0) &&
1111 (image->matte == MagickFalse))
1112 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1113 quantum_info=AcquireQuantumInfo(image_info,image);
1114 if (quantum_info == (QuantumInfo *) NULL)
1115 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1116 pixels=GetQuantumPixels(quantum_info);
1117 switch (image_info->interlace)
1123 No interlacing: BGRBGRBGRBGRBGRBGR...
1125 for (y=0; y < (ssize_t) image->rows; y++)
1127 register const Quantum
1130 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1131 if (p == (const Quantum *) NULL)
1133 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1134 quantum_type,pixels,exception);
1135 count=WriteBlob(image,length,pixels);
1136 if (count != (ssize_t) length)
1138 if (image->previous == (Image *) NULL)
1140 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1142 if (status == MagickFalse)
1151 Line interlacing: BBB...GGG...RRR...RRR...GGG...BBB...
1153 for (y=0; y < (ssize_t) image->rows; y++)
1155 register const Quantum
1158 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1159 if (p == (const Quantum *) NULL)
1161 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1162 BlueQuantum,pixels,exception);
1163 count=WriteBlob(image,length,pixels);
1164 if (count != (ssize_t) length)
1166 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1167 GreenQuantum,pixels,exception);
1168 count=WriteBlob(image,length,pixels);
1169 if (count != (ssize_t) length)
1171 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1172 RedQuantum,pixels,exception);
1173 count=WriteBlob(image,length,pixels);
1174 if (count != (ssize_t) length)
1176 if (quantum_type == BGRAQuantum)
1178 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1179 AlphaQuantum,pixels,exception);
1180 count=WriteBlob(image,length,pixels);
1181 if (count != (ssize_t) length)
1184 if (image->previous == (Image *) NULL)
1186 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1188 if (status == MagickFalse)
1194 case PlaneInterlace:
1197 Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
1199 for (y=0; y < (ssize_t) image->rows; y++)
1201 register const Quantum
1204 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1205 if (p == (const Quantum *) NULL)
1207 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1208 RedQuantum,pixels,exception);
1209 count=WriteBlob(image,length,pixels);
1210 if (count != (ssize_t) length)
1213 if (image->previous == (Image *) NULL)
1215 status=SetImageProgress(image,SaveImageTag,1,6);
1216 if (status == MagickFalse)
1219 for (y=0; y < (ssize_t) image->rows; y++)
1221 register const Quantum
1224 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1225 if (p == (const Quantum *) NULL)
1227 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1228 GreenQuantum,pixels,exception);
1229 count=WriteBlob(image,length,pixels);
1230 if (count != (ssize_t) length)
1233 if (image->previous == (Image *) NULL)
1235 status=SetImageProgress(image,SaveImageTag,2,6);
1236 if (status == MagickFalse)
1239 for (y=0; y < (ssize_t) image->rows; y++)
1241 register const Quantum
1244 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1245 if (p == (const Quantum *) NULL)
1247 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1248 BlueQuantum,pixels,exception);
1249 count=WriteBlob(image,length,pixels);
1250 if (count != (ssize_t) length)
1253 if (image->previous == (Image *) NULL)
1255 status=SetImageProgress(image,SaveImageTag,3,6);
1256 if (status == MagickFalse)
1259 if (quantum_type == BGRAQuantum)
1261 for (y=0; y < (ssize_t) image->rows; y++)
1263 register const Quantum
1266 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1267 if (p == (const Quantum *) NULL)
1269 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1270 AlphaQuantum,pixels,exception);
1271 count=WriteBlob(image,length,pixels);
1272 if (count != (ssize_t) length)
1275 if (image->previous == (Image *) NULL)
1277 status=SetImageProgress(image,SaveImageTag,5,6);
1278 if (status == MagickFalse)
1282 if (image_info->interlace == PartitionInterlace)
1283 (void) CopyMagickString(image->filename,image_info->filename,
1285 if (image->previous == (Image *) NULL)
1287 status=SetImageProgress(image,SaveImageTag,6,6);
1288 if (status == MagickFalse)
1293 case PartitionInterlace:
1296 Partition interlacing: BBBBBB..., GGGGGG..., RRRRRR...
1298 AppendImageFormat("B",image->filename);
1299 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1300 AppendBinaryBlobMode,exception);
1301 if (status == MagickFalse)
1303 for (y=0; y < (ssize_t) image->rows; y++)
1305 register const Quantum
1308 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1309 if (p == (const Quantum *) NULL)
1311 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1312 BlueQuantum,pixels,exception);
1313 count=WriteBlob(image,length,pixels);
1314 if (count != (ssize_t) length)
1317 if (image->previous == (Image *) NULL)
1319 status=SetImageProgress(image,SaveImageTag,1,6);
1320 if (status == MagickFalse)
1323 (void) CloseBlob(image);
1324 AppendImageFormat("G",image->filename);
1325 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1326 AppendBinaryBlobMode,exception);
1327 if (status == MagickFalse)
1329 for (y=0; y < (ssize_t) image->rows; y++)
1331 register const Quantum
1334 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1335 if (p == (const Quantum *) NULL)
1337 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1338 GreenQuantum,pixels,exception);
1339 count=WriteBlob(image,length,pixels);
1340 if (count != (ssize_t) length)
1343 if (image->previous == (Image *) NULL)
1345 status=SetImageProgress(image,SaveImageTag,2,6);
1346 if (status == MagickFalse)
1349 (void) CloseBlob(image);
1350 AppendImageFormat("R",image->filename);
1351 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1352 AppendBinaryBlobMode,exception);
1353 if (status == MagickFalse)
1355 for (y=0; y < (ssize_t) image->rows; y++)
1357 register const Quantum
1360 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1361 if (p == (const Quantum *) NULL)
1363 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1364 RedQuantum,pixels,exception);
1365 count=WriteBlob(image,length,pixels);
1366 if (count != (ssize_t) length)
1369 if (image->previous == (Image *) NULL)
1371 status=SetImageProgress(image,SaveImageTag,3,6);
1372 if (status == MagickFalse)
1375 (void) CloseBlob(image);
1376 if (quantum_type == BGRAQuantum)
1378 (void) CloseBlob(image);
1379 AppendImageFormat("A",image->filename);
1380 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1381 AppendBinaryBlobMode,exception);
1382 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 AlphaQuantum,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,5,6);
1401 if (status == MagickFalse)
1405 (void) CloseBlob(image);
1406 (void) CopyMagickString(image->filename,image_info->filename,
1408 if (image->previous == (Image *) NULL)
1410 status=SetImageProgress(image,SaveImageTag,6,6);
1411 if (status == MagickFalse)
1417 quantum_info=DestroyQuantumInfo(quantum_info);
1418 if (GetNextImageInList(image) == (Image *) NULL)
1420 image=SyncNextImageInList(image);
1421 status=SetImageProgress(image,SaveImagesTag,scene++,
1422 GetImageListLength(image));
1423 if (status == MagickFalse)
1425 } while (image_info->adjoin != MagickFalse);
1426 (void) CloseBlob(image);