2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % Y Y YYYC BBBB YYYC RRRR %
10 % Y YYYC BBBB YYYC R R %
13 % Read/Write Raw YCbCr Image Format %
20 % Copyright 1999-2012 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/constitute.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/image.h"
51 #include "MagickCore/image-private.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/magick.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/monitor.h"
56 #include "MagickCore/monitor-private.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/static.h"
60 #include "MagickCore/statistic.h"
61 #include "MagickCore/string_.h"
62 #include "MagickCore/module.h"
63 #include "MagickCore/utility.h"
68 static MagickBooleanType
69 WriteYCBCRImage(const ImageInfo *,Image *,ExceptionInfo *);
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % R e a d Y C b C r I m a g e %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % ReadYCBCRImage() reads an image of raw YCbCr or YCbCrA 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 ReadYCBCRImage method is:
88 % Image *ReadYCBCRImage(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 *ReadYCBCRImage(const ImageInfo *image_info,
99 ExceptionInfo *exception)
117 register const Quantum
140 assert(image_info != (const ImageInfo *) NULL);
141 assert(image_info->signature == MagickSignature);
142 if (image_info->debug != MagickFalse)
143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
144 image_info->filename);
145 assert(exception != (ExceptionInfo *) NULL);
146 assert(exception->signature == MagickSignature);
147 image=AcquireImage(image_info,exception);
148 if ((image->columns == 0) || (image->rows == 0))
149 ThrowReaderException(OptionError,"MustSpecifyImageSize");
150 image->colorspace=YCbCrColorspace;
151 if (image_info->interlace != PartitionInterlace)
153 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
154 if (status == MagickFalse)
156 image=DestroyImageList(image);
157 return((Image *) NULL);
159 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
160 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
164 Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
166 canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
168 (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
169 quantum_info=AcquireQuantumInfo(image_info,canvas_image);
170 if (quantum_info == (QuantumInfo *) NULL)
171 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
172 pixels=GetQuantumPixels(quantum_info);
173 quantum_type=RGBQuantum;
174 if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
176 quantum_type=RGBAQuantum;
177 image->matte=MagickTrue;
179 if (image_info->number_scenes != 0)
180 while (image->scene < image_info->scene)
186 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
187 for (y=0; y < (ssize_t) image->rows; y++)
189 count=ReadBlob(image,length,pixels);
190 if (count != (ssize_t) length)
200 Read pixels to virtual canvas image then push to image.
202 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
203 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
205 image->colorspace=YCbCrColorspace;
206 switch (image_info->interlace)
212 No interlacing: YCbCrYCbCrYCbCrYCbCrYCbCrYCbCr...
216 length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
217 count=ReadBlob(image,length,pixels);
219 for (y=0; y < (ssize_t) image->extract_info.height; y++)
221 if (count != (ssize_t) length)
223 ThrowFileException(exception,CorruptImageError,
224 "UnexpectedEndOfFile",image->filename);
227 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
229 if (q == (Quantum *) NULL)
231 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
232 quantum_info,quantum_type,pixels,exception);
233 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
235 if (((y-image->extract_info.y) >= 0) &&
236 ((y-image->extract_info.y) < (ssize_t) image->rows))
238 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
239 canvas_image->columns,1,exception);
240 q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
241 image->columns,1,exception);
242 if ((p == (const Quantum *) NULL) ||
243 (q == (Quantum *) NULL))
245 for (x=0; x < (ssize_t) image->columns; x++)
247 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
248 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
249 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
250 if (image->matte != MagickFalse)
251 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
252 p+=GetPixelChannels(canvas_image);
253 q+=GetPixelChannels(image);
255 if (SyncAuthenticPixels(image,exception) == MagickFalse)
258 if (image->previous == (Image *) NULL)
260 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
262 if (status == MagickFalse)
265 count=ReadBlob(image,length,pixels);
281 Line interlacing: YYY...CbCbCb...CrCrCr...YYY...CbCbCb...CrCrCr...
285 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
286 count=ReadBlob(image,length,pixels);
288 for (y=0; y < (ssize_t) image->extract_info.height; y++)
290 for (i=0; i < (image->matte != MagickFalse ? 4 : 3); i++)
292 if (count != (ssize_t) length)
294 ThrowFileException(exception,CorruptImageError,
295 "UnexpectedEndOfFile",image->filename);
298 quantum_type=quantum_types[i];
299 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
301 if (q == (Quantum *) NULL)
303 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
304 quantum_info,quantum_type,pixels,exception);
305 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
307 if (((y-image->extract_info.y) >= 0) &&
308 ((y-image->extract_info.y) < (ssize_t) image->rows))
310 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
311 0,canvas_image->columns,1,exception);
312 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
313 image->columns,1,exception);
314 if ((p == (const Quantum *) NULL) ||
315 (q == (Quantum *) NULL))
317 for (x=0; x < (ssize_t) image->columns; x++)
319 switch (quantum_type)
323 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
328 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
333 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
338 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
344 p+=GetPixelChannels(canvas_image);
345 q+=GetPixelChannels(image);
347 if (SyncAuthenticPixels(image,exception) == MagickFalse)
350 count=ReadBlob(image,length,pixels);
352 if (image->previous == (Image *) NULL)
354 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
356 if (status == MagickFalse)
365 Plane interlacing: YYYYYY...CbCbCbCbCbCb...CrCrCrCrCrCr...
369 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
370 count=ReadBlob(image,length,pixels);
372 for (y=0; y < (ssize_t) image->extract_info.height; y++)
374 if (count != (ssize_t) length)
376 ThrowFileException(exception,CorruptImageError,
377 "UnexpectedEndOfFile",image->filename);
380 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
382 if (q == (Quantum *) NULL)
384 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
385 quantum_info,RedQuantum,pixels,exception);
386 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
388 if (((y-image->extract_info.y) >= 0) &&
389 ((y-image->extract_info.y) < (ssize_t) image->rows))
391 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
392 canvas_image->columns,1,exception);
393 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
394 image->columns,1,exception);
395 if ((p == (const Quantum *) NULL) ||
396 (q == (Quantum *) NULL))
398 for (x=0; x < (ssize_t) image->columns; x++)
400 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
401 p+=GetPixelChannels(canvas_image);
402 q+=GetPixelChannels(image);
404 if (SyncAuthenticPixels(image,exception) == MagickFalse)
407 count=ReadBlob(image,length,pixels);
409 if (image->previous == (Image *) NULL)
411 status=SetImageProgress(image,LoadImageTag,1,5);
412 if (status == MagickFalse)
415 for (y=0; y < (ssize_t) image->extract_info.height; y++)
417 if (count != (ssize_t) length)
419 ThrowFileException(exception,CorruptImageError,
420 "UnexpectedEndOfFile",image->filename);
423 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
425 if (q == (Quantum *) NULL)
427 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
428 quantum_info,GreenQuantum,pixels,exception);
429 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
431 if (((y-image->extract_info.y) >= 0) &&
432 ((y-image->extract_info.y) < (ssize_t) image->rows))
434 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
435 canvas_image->columns,1,exception);
436 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
437 image->columns,1,exception);
438 if ((p == (const Quantum *) NULL) ||
439 (q == (Quantum *) NULL))
441 for (x=0; x < (ssize_t) image->columns; x++)
443 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
444 p+=GetPixelChannels(canvas_image);
445 q+=GetPixelChannels(image);
447 if (SyncAuthenticPixels(image,exception) == MagickFalse)
450 count=ReadBlob(image,length,pixels);
452 if (image->previous == (Image *) NULL)
454 status=SetImageProgress(image,LoadImageTag,2,5);
455 if (status == MagickFalse)
458 for (y=0; y < (ssize_t) image->extract_info.height; y++)
460 if (count != (ssize_t) length)
462 ThrowFileException(exception,CorruptImageError,
463 "UnexpectedEndOfFile",image->filename);
466 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
468 if (q == (Quantum *) NULL)
470 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
471 quantum_info,BlueQuantum,pixels,exception);
472 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
474 if (((y-image->extract_info.y) >= 0) &&
475 ((y-image->extract_info.y) < (ssize_t) image->rows))
477 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
478 canvas_image->columns,1,exception);
479 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
480 image->columns,1,exception);
481 if ((p == (const Quantum *) NULL) ||
482 (q == (Quantum *) NULL))
484 for (x=0; x < (ssize_t) image->columns; x++)
486 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
487 p+=GetPixelChannels(canvas_image);
488 q+=GetPixelChannels(image);
490 if (SyncAuthenticPixels(image,exception) == MagickFalse)
493 count=ReadBlob(image,length,pixels);
495 if (image->previous == (Image *) NULL)
497 status=SetImageProgress(image,LoadImageTag,3,5);
498 if (status == MagickFalse)
501 if (image->matte != MagickFalse)
503 for (y=0; y < (ssize_t) image->extract_info.height; y++)
505 if (count != (ssize_t) length)
507 ThrowFileException(exception,CorruptImageError,
508 "UnexpectedEndOfFile",image->filename);
511 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
513 if (q == (Quantum *) NULL)
515 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
516 quantum_info,AlphaQuantum,pixels,exception);
517 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
519 if (((y-image->extract_info.y) >= 0) &&
520 ((y-image->extract_info.y) < (ssize_t) image->rows))
522 p=GetVirtualPixels(canvas_image,
523 canvas_image->extract_info.x,0,canvas_image->columns,1,
525 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
526 image->columns,1,exception);
527 if ((p == (const Quantum *) NULL) ||
528 (q == (Quantum *) NULL))
530 for (x=0; x < (ssize_t) image->columns; x++)
532 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
533 p+=GetPixelChannels(canvas_image);
534 q+=GetPixelChannels(image);
536 if (SyncAuthenticPixels(image,exception) == MagickFalse)
539 count=ReadBlob(image,length,pixels);
541 if (image->previous == (Image *) NULL)
543 status=SetImageProgress(image,LoadImageTag,4,5);
544 if (status == MagickFalse)
548 if (image->previous == (Image *) NULL)
550 status=SetImageProgress(image,LoadImageTag,5,5);
551 if (status == MagickFalse)
556 case PartitionInterlace:
559 Partition interlacing: YYYYYY..., CbCbCbCbCbCb..., CrCrCrCrCrCr...
561 AppendImageFormat("Y",image->filename);
562 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
563 if (status == MagickFalse)
565 canvas_image=DestroyImageList(canvas_image);
566 image=DestroyImageList(image);
567 return((Image *) NULL);
569 if (DiscardBlobBytes(image,image->offset) == MagickFalse)
570 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
572 length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
573 for (i=0; i < (ssize_t) scene; i++)
574 for (y=0; y < (ssize_t) image->extract_info.height; y++)
575 if (ReadBlob(image,length,pixels) != (ssize_t) length)
577 ThrowFileException(exception,CorruptImageError,
578 "UnexpectedEndOfFile",image->filename);
581 count=ReadBlob(image,length,pixels);
582 for (y=0; y < (ssize_t) image->extract_info.height; y++)
584 if (count != (ssize_t) length)
586 ThrowFileException(exception,CorruptImageError,
587 "UnexpectedEndOfFile",image->filename);
590 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
592 if (q == (Quantum *) NULL)
594 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
595 quantum_info,RedQuantum,pixels,exception);
596 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
598 if (((y-image->extract_info.y) >= 0) &&
599 ((y-image->extract_info.y) < (ssize_t) image->rows))
601 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
602 canvas_image->columns,1,exception);
603 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
604 image->columns,1,exception);
605 if ((p == (const Quantum *) NULL) ||
606 (q == (Quantum *) NULL))
608 for (x=0; x < (ssize_t) image->columns; x++)
610 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
611 p+=GetPixelChannels(canvas_image);
612 q+=GetPixelChannels(image);
614 if (SyncAuthenticPixels(image,exception) == MagickFalse)
617 count=ReadBlob(image,length,pixels);
619 if (image->previous == (Image *) NULL)
621 status=SetImageProgress(image,LoadImageTag,1,5);
622 if (status == MagickFalse)
625 (void) CloseBlob(image);
626 AppendImageFormat("Cb",image->filename);
627 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
628 if (status == MagickFalse)
630 canvas_image=DestroyImageList(canvas_image);
631 image=DestroyImageList(image);
632 return((Image *) NULL);
634 length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
635 for (i=0; i < (ssize_t) scene; i++)
636 for (y=0; y < (ssize_t) image->extract_info.height; y++)
637 if (ReadBlob(image,length,pixels) != (ssize_t) length)
639 ThrowFileException(exception,CorruptImageError,
640 "UnexpectedEndOfFile",image->filename);
643 count=ReadBlob(image,length,pixels);
644 for (y=0; y < (ssize_t) image->extract_info.height; y++)
646 if (count != (ssize_t) length)
648 ThrowFileException(exception,CorruptImageError,
649 "UnexpectedEndOfFile",image->filename);
652 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
654 if (q == (Quantum *) NULL)
656 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
657 quantum_info,GreenQuantum,pixels,exception);
658 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
660 if (((y-image->extract_info.y) >= 0) &&
661 ((y-image->extract_info.y) < (ssize_t) image->rows))
663 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
664 canvas_image->columns,1,exception);
665 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
666 image->columns,1,exception);
667 if ((p == (const Quantum *) NULL) ||
668 (q == (Quantum *) NULL))
670 for (x=0; x < (ssize_t) image->columns; x++)
672 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
673 p+=GetPixelChannels(canvas_image);
674 q+=GetPixelChannels(image);
676 if (SyncAuthenticPixels(image,exception) == MagickFalse)
679 count=ReadBlob(image,length,pixels);
681 if (image->previous == (Image *) NULL)
683 status=SetImageProgress(image,LoadImageTag,2,5);
684 if (status == MagickFalse)
687 (void) CloseBlob(image);
688 AppendImageFormat("Cr",image->filename);
689 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
690 if (status == MagickFalse)
692 canvas_image=DestroyImageList(canvas_image);
693 image=DestroyImageList(image);
694 return((Image *) NULL);
696 length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
697 for (i=0; i < (ssize_t) scene; i++)
698 for (y=0; y < (ssize_t) image->extract_info.height; y++)
699 if (ReadBlob(image,length,pixels) != (ssize_t) length)
701 ThrowFileException(exception,CorruptImageError,
702 "UnexpectedEndOfFile",image->filename);
705 count=ReadBlob(image,length,pixels);
706 for (y=0; y < (ssize_t) image->extract_info.height; y++)
708 if (count != (ssize_t) length)
710 ThrowFileException(exception,CorruptImageError,
711 "UnexpectedEndOfFile",image->filename);
714 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
716 if (q == (Quantum *) NULL)
718 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
719 quantum_info,BlueQuantum,pixels,exception);
720 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
722 if (((y-image->extract_info.y) >= 0) &&
723 ((y-image->extract_info.y) < (ssize_t) image->rows))
725 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
726 canvas_image->columns,1,exception);
727 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
728 image->columns,1,exception);
729 if ((p == (const Quantum *) NULL) ||
730 (q == (Quantum *) NULL))
732 for (x=0; x < (ssize_t) image->columns; x++)
734 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
735 p+=GetPixelChannels(canvas_image);
736 q+=GetPixelChannels(image);
738 if (SyncAuthenticPixels(image,exception) == MagickFalse)
741 count=ReadBlob(image,length,pixels);
743 if (image->previous == (Image *) NULL)
745 status=SetImageProgress(image,LoadImageTag,3,5);
746 if (status == MagickFalse)
749 if (image->matte != MagickFalse)
751 (void) CloseBlob(image);
752 AppendImageFormat("A",image->filename);
753 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
754 if (status == MagickFalse)
756 canvas_image=DestroyImageList(canvas_image);
757 image=DestroyImageList(image);
758 return((Image *) NULL);
760 length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
761 for (i=0; i < (ssize_t) scene; i++)
762 for (y=0; y < (ssize_t) image->extract_info.height; y++)
763 if (ReadBlob(image,length,pixels) != (ssize_t) length)
765 ThrowFileException(exception,CorruptImageError,
766 "UnexpectedEndOfFile",image->filename);
769 count=ReadBlob(image,length,pixels);
770 for (y=0; y < (ssize_t) image->extract_info.height; y++)
772 if (count != (ssize_t) length)
774 ThrowFileException(exception,CorruptImageError,
775 "UnexpectedEndOfFile",image->filename);
778 q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
780 if (q == (Quantum *) NULL)
782 length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
783 quantum_info,BlueQuantum,pixels,exception);
784 if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
786 if (((y-image->extract_info.y) >= 0) &&
787 ((y-image->extract_info.y) < (ssize_t) image->rows))
789 p=GetVirtualPixels(canvas_image,
790 canvas_image->extract_info.x,0,canvas_image->columns,1,
792 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
793 image->columns,1,exception);
794 if ((p == (const Quantum *) NULL) ||
795 (q == (Quantum *) NULL))
797 for (x=0; x < (ssize_t) image->columns; x++)
799 SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
800 p+=GetPixelChannels(canvas_image);
801 q+=GetPixelChannels(image);
803 if (SyncAuthenticPixels(image,exception) == MagickFalse)
806 count=ReadBlob(image,length,pixels);
808 if (image->previous == (Image *) NULL)
810 status=SetImageProgress(image,LoadImageTag,4,5);
811 if (status == MagickFalse)
815 if (image->previous == (Image *) NULL)
817 status=SetImageProgress(image,LoadImageTag,5,5);
818 if (status == MagickFalse)
824 SetQuantumImageType(image,quantum_type);
826 Proceed to next image.
828 if (image_info->number_scenes != 0)
829 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
831 if (count == (ssize_t) length)
834 Allocate next image structure.
836 AcquireNextImage(image_info,image,exception);
837 if (GetNextImageInList(image) == (Image *) NULL)
839 image=DestroyImageList(image);
840 return((Image *) NULL);
842 image=SyncNextImageInList(image);
843 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
845 if (status == MagickFalse)
849 } while (count == (ssize_t) length);
850 quantum_info=DestroyQuantumInfo(quantum_info);
851 canvas_image=DestroyImage(canvas_image);
852 (void) CloseBlob(image);
853 return(GetFirstImageInList(image));
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
861 % R e g i s t e r Y C b C r I m a g e %
865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
867 % RegisterYCBCRImage() adds attributes for the YCbCr or YCbCrA image format to
868 % the list of supported formats. The attributes include the image format
869 % tag, a method to read and/or write the format, whether the format
870 % supports the saving of more than one frame to the same file or blob,
871 % whether the format supports native in-memory I/O, and a brief
872 % description of the format.
874 % The format of the RegisterYCBCRImage method is:
876 % size_t RegisterYCBCRImage(void)
879 ModuleExport size_t RegisterYCBCRImage(void)
884 entry=SetMagickInfo("YCbCr");
885 entry->decoder=(DecodeImageHandler *) ReadYCBCRImage;
886 entry->encoder=(EncodeImageHandler *) WriteYCBCRImage;
887 entry->raw=MagickTrue;
888 entry->endian_support=MagickTrue;
889 entry->description=ConstantString("Raw Y, Cb, and Cr samples");
890 entry->module=ConstantString("YCbCr");
891 (void) RegisterMagickInfo(entry);
892 entry=SetMagickInfo("YCbCrA");
893 entry->decoder=(DecodeImageHandler *) ReadYCBCRImage;
894 entry->encoder=(EncodeImageHandler *) WriteYCBCRImage;
895 entry->raw=MagickTrue;
896 entry->endian_support=MagickTrue;
897 entry->description=ConstantString("Raw Y, Cb, Cr, and alpha samples");
898 entry->module=ConstantString("YCbCr");
899 (void) RegisterMagickInfo(entry);
900 return(MagickImageCoderSignature);
904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
908 % U n r e g i s t e r Y C b C r I m a g e %
912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
914 % UnregisterYCBCRImage() removes format registrations made by the
915 % YCbCr module from the list of supported formats.
917 % The format of the UnregisterYCBCRImage method is:
919 % UnregisterYCBCRImage(void)
922 ModuleExport void UnregisterYCBCRImage(void)
924 (void) UnregisterMagickInfo("YCbCr");
925 (void) UnregisterMagickInfo("YCbCrA");
929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
933 % W r i t e Y C b C r I m a g e %
937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939 % WriteYCBCRImage() writes an image to a file in the YCbCr or YCbCrA
942 % The format of the WriteYCBCRImage method is:
944 % MagickBooleanType WriteYCBCRImage(const ImageInfo *image_info,
945 % Image *image,ExceptionInfo *exception)
947 % A description of each parameter follows.
949 % o image_info: the image info.
951 % o image: The image.
953 % o exception: return any errors or warnings in this structure.
956 static MagickBooleanType WriteYCBCRImage(const ImageInfo *image_info,
957 Image *image,ExceptionInfo *exception)
971 register const Quantum
985 Allocate memory for pixels.
987 assert(image_info != (const ImageInfo *) NULL);
988 assert(image_info->signature == MagickSignature);
989 assert(image != (Image *) NULL);
990 assert(image->signature == MagickSignature);
991 if (image->debug != MagickFalse)
992 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
993 if (image_info->interlace != PartitionInterlace)
996 Open output image file.
998 assert(exception != (ExceptionInfo *) NULL);
999 assert(exception->signature == MagickSignature);
1000 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1001 if (status == MagickFalse)
1004 quantum_type=RGBQuantum;
1005 if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
1007 quantum_type=RGBAQuantum;
1008 image->matte=MagickTrue;
1014 Convert MIFF to YCbCr raster pixels.
1016 if (image->colorspace != YCbCrColorspace)
1017 (void) TransformImageColorspace(image,YCbCrColorspace,exception);
1018 if ((LocaleCompare(image_info->magick,"YCbCrA") == 0) &&
1019 (image->matte == MagickFalse))
1020 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1021 quantum_info=AcquireQuantumInfo(image_info,image);
1022 if (quantum_info == (QuantumInfo *) NULL)
1023 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1024 pixels=GetQuantumPixels(quantum_info);
1025 switch (image_info->interlace)
1031 No interlacing: YCbCrYCbCrYCbCrYCbCrYCbCrYCbCr...
1033 for (y=0; y < (ssize_t) image->rows; y++)
1035 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1036 if (p == (const Quantum *) NULL)
1038 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1039 quantum_type,pixels,exception);
1040 count=WriteBlob(image,length,pixels);
1041 if (count != (ssize_t) length)
1043 if (image->previous == (Image *) NULL)
1045 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1047 if (status == MagickFalse)
1056 Line interlacing: YYY...CbCbCb...CrCrCr...YYY...CbCbCb...CrCrCr...
1058 for (y=0; y < (ssize_t) image->rows; y++)
1060 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1061 if (p == (const Quantum *) NULL)
1063 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1064 RedQuantum,pixels,exception);
1065 count=WriteBlob(image,length,pixels);
1066 if (count != (ssize_t) length)
1068 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1069 GreenQuantum,pixels,exception);
1070 count=WriteBlob(image,length,pixels);
1071 if (count != (ssize_t) length)
1073 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1074 BlueQuantum,pixels,exception);
1075 count=WriteBlob(image,length,pixels);
1076 if (count != (ssize_t) length)
1078 if (quantum_type == RGBAQuantum)
1080 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1081 AlphaQuantum,pixels,exception);
1082 count=WriteBlob(image,length,pixels);
1083 if (count != (ssize_t) length)
1086 if (image->previous == (Image *) NULL)
1088 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1090 if (status == MagickFalse)
1096 case PlaneInterlace:
1099 Plane interlacing: YYYYYY...CbCbCbCbCbCb...CrCrCrCrCrCr...
1101 for (y=0; y < (ssize_t) image->rows; y++)
1103 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1104 if (p == (const Quantum *) NULL)
1106 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1107 RedQuantum,pixels,exception);
1108 count=WriteBlob(image,length,pixels);
1109 if (count != (ssize_t) length)
1112 if (image->previous == (Image *) NULL)
1114 status=SetImageProgress(image,SaveImageTag,1,5);
1115 if (status == MagickFalse)
1118 for (y=0; y < (ssize_t) image->rows; y++)
1120 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1121 if (p == (const Quantum *) NULL)
1123 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1124 GreenQuantum,pixels,exception);
1125 count=WriteBlob(image,length,pixels);
1126 if (count != (ssize_t) length)
1129 if (image->previous == (Image *) NULL)
1131 status=SetImageProgress(image,SaveImageTag,2,5);
1132 if (status == MagickFalse)
1135 for (y=0; y < (ssize_t) image->rows; y++)
1137 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1138 if (p == (const Quantum *) NULL)
1140 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1141 BlueQuantum,pixels,exception);
1142 count=WriteBlob(image,length,pixels);
1143 if (count != (ssize_t) length)
1146 if (image->previous == (Image *) NULL)
1148 status=SetImageProgress(image,SaveImageTag,3,5);
1149 if (status == MagickFalse)
1152 if (quantum_type == RGBAQuantum)
1154 for (y=0; y < (ssize_t) image->rows; y++)
1156 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1157 if (p == (const Quantum *) NULL)
1159 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1160 AlphaQuantum,pixels,exception);
1161 count=WriteBlob(image,length,pixels);
1162 if (count != (ssize_t) length)
1166 if (image_info->interlace == PartitionInterlace)
1167 (void) CopyMagickString(image->filename,image_info->filename,
1169 if (image->previous == (Image *) NULL)
1171 status=SetImageProgress(image,SaveImageTag,5,5);
1172 if (status == MagickFalse)
1177 case PartitionInterlace:
1180 Partition interlacing: YYYYYY..., CbCbCbCbCbCb..., CrCrCrCrCrCr...
1182 AppendImageFormat("Y",image->filename);
1183 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1184 AppendBinaryBlobMode,exception);
1185 if (status == MagickFalse)
1187 for (y=0; y < (ssize_t) image->rows; y++)
1189 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1190 if (p == (const Quantum *) NULL)
1192 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1193 RedQuantum,pixels,exception);
1194 count=WriteBlob(image,length,pixels);
1195 if (count != (ssize_t) length)
1198 if (image->previous == (Image *) NULL)
1200 status=SetImageProgress(image,SaveImageTag,1,5);
1201 if (status == MagickFalse)
1204 (void) CloseBlob(image);
1205 AppendImageFormat("Cb",image->filename);
1206 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1207 AppendBinaryBlobMode,exception);
1208 if (status == MagickFalse)
1210 for (y=0; y < (ssize_t) image->rows; y++)
1212 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1213 if (p == (const Quantum *) NULL)
1215 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1216 GreenQuantum,pixels,exception);
1217 count=WriteBlob(image,length,pixels);
1218 if (count != (ssize_t) length)
1221 if (image->previous == (Image *) NULL)
1223 status=SetImageProgress(image,SaveImageTag,2,5);
1224 if (status == MagickFalse)
1227 (void) CloseBlob(image);
1228 AppendImageFormat("Cr",image->filename);
1229 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1230 AppendBinaryBlobMode,exception);
1231 if (status == MagickFalse)
1233 for (y=0; y < (ssize_t) image->rows; y++)
1235 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1236 if (p == (const Quantum *) NULL)
1238 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1239 BlueQuantum,pixels,exception);
1240 count=WriteBlob(image,length,pixels);
1241 if (count != (ssize_t) length)
1244 if (image->previous == (Image *) NULL)
1246 status=SetImageProgress(image,SaveImageTag,3,5);
1247 if (status == MagickFalse)
1250 if (quantum_type == RGBAQuantum)
1252 (void) CloseBlob(image);
1253 AppendImageFormat("A",image->filename);
1254 status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1255 AppendBinaryBlobMode,exception);
1256 if (status == MagickFalse)
1258 for (y=0; y < (ssize_t) image->rows; y++)
1260 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1261 if (p == (const Quantum *) NULL)
1263 length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1264 AlphaQuantum,pixels,exception);
1265 count=WriteBlob(image,length,pixels);
1266 if (count != (ssize_t) length)
1269 if (image->previous == (Image *) NULL)
1271 status=SetImageProgress(image,SaveImageTag,4,5);
1272 if (status == MagickFalse)
1276 (void) CloseBlob(image);
1277 (void) CopyMagickString(image->filename,image_info->filename,
1279 if (image->previous == (Image *) NULL)
1281 status=SetImageProgress(image,SaveImageTag,5,5);
1282 if (status == MagickFalse)
1288 quantum_info=DestroyQuantumInfo(quantum_info);
1289 if (GetNextImageInList(image) == (Image *) NULL)
1291 image=SyncNextImageInList(image);
1292 status=SetImageProgress(image,SaveImagesTag,scene++,
1293 GetImageListLength(image));
1294 if (status == MagickFalse)
1296 } while (image_info->adjoin != MagickFalse);
1297 (void) CloseBlob(image);