% Read/Write Raw YCbCr Image Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
#include "MagickCore/blob.h"
#include "MagickCore/blob-private.h"
#include "MagickCore/cache.h"
+#include "MagickCore/channel.h"
#include "MagickCore/colorspace.h"
#include "MagickCore/constitute.h"
#include "MagickCore/exception.h"
static Image *ReadYCBCRImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
+ const unsigned char
+ *pixels;
+
Image
*canvas_image,
*image;
count,
y;
- unsigned char
- *pixels;
-
/*
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
image=AcquireImage(image_info,exception);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
- SetImageColorspace(image,YCbCrColorspace,exception);
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
+ (void) SetImageColorspace(image,YCbCrColorspace,exception);
if (image_info->interlace != PartitionInterlace)
{
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
image=DestroyImageList(image);
return((Image *) NULL);
}
- if (DiscardBlobBytes(image,image->offset) == MagickFalse)
+ if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
}
*/
canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
exception);
+ if (canvas_image == (Image *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
exception);
quantum_info=AcquireQuantumInfo(image_info,canvas_image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- pixels=GetQuantumPixels(quantum_info);
quantum_type=RGBQuantum;
if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
{
quantum_type=RGBAQuantum;
image->alpha_trait=BlendPixelTrait;
}
+ pixels=(const unsigned char *) NULL;
if (image_info->number_scenes != 0)
while (image->scene < image_info->scene)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
for (y=0; y < (ssize_t) image->rows; y++)
{
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
if (count != (ssize_t) length)
break;
}
count=0;
length=0;
scene=0;
+ status=MagickTrue;
do
{
/*
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
- SetImageColorspace(image,YCbCrColorspace,exception);
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ break;
+ if (SetImageColorspace(image,YCbCrColorspace,exception) == MagickFalse)
+ break;
switch (image_info->interlace)
{
case NoInterlace:
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
SetPixelRed(image,GetPixelRed(canvas_image,p),q);
SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
- if (image->alpha_trait == BlendPixelTrait)
+ if (image->alpha_trait != UndefinedPixelTrait)
SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
p+=GetPixelChannels(canvas_image);
q+=GetPixelChannels(image);
if (status == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
break;
}
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
- for (i=0; i < (image->alpha_trait == BlendPixelTrait ? 4 : 3); i++)
+ for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
if (status == MagickFalse)
break;
}
- if (image->alpha_trait == BlendPixelTrait)
+ if (image->alpha_trait != UndefinedPixelTrait)
{
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
- if (DiscardBlobBytes(image,image->offset) == MagickFalse)
+ if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
for (i=0; i < (ssize_t) scene; i++)
for (y=0; y < (ssize_t) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
+ {
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
}
- count=ReadBlob(image,length,pixels);
+ }
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
for (i=0; i < (ssize_t) scene; i++)
for (y=0; y < (ssize_t) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
+ {
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
}
- count=ReadBlob(image,length,pixels);
+ }
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
for (i=0; i < (ssize_t) scene; i++)
for (y=0; y < (ssize_t) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
+ {
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
}
- count=ReadBlob(image,length,pixels);
+ }
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
if (status == MagickFalse)
break;
}
- if (image->alpha_trait == BlendPixelTrait)
+ if (image->alpha_trait != UndefinedPixelTrait)
{
(void) CloseBlob(image);
AppendImageFormat("A",image->filename);
length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
for (i=0; i < (ssize_t) scene; i++)
for (y=0; y < (ssize_t) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
+ {
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
}
- count=ReadBlob(image,length,pixels);
+ }
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
if (image->previous == (Image *) NULL)
{
quantum_info=DestroyQuantumInfo(quantum_info);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
return(GetFirstImageInList(image));
}
\f
MagickInfo
*entry;
- entry=SetMagickInfo("YCbCr");
+ entry=AcquireMagickInfo("YCbCr","YCbCr","Raw Y, Cb, and Cr samples");
entry->decoder=(DecodeImageHandler *) ReadYCBCRImage;
entry->encoder=(EncodeImageHandler *) WriteYCBCRImage;
- entry->raw=MagickTrue;
- entry->endian_support=MagickTrue;
- entry->description=ConstantString("Raw Y, Cb, and Cr samples");
- entry->module=ConstantString("YCbCr");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
(void) RegisterMagickInfo(entry);
- entry=SetMagickInfo("YCbCrA");
+ entry=AcquireMagickInfo("YCbCr","YCbCrA","Raw Y, Cb, Cr, and alpha samples");
entry->decoder=(DecodeImageHandler *) ReadYCBCRImage;
entry->encoder=(EncodeImageHandler *) WriteYCBCRImage;
- entry->raw=MagickTrue;
- entry->endian_support=MagickTrue;
- entry->description=ConstantString("Raw Y, Cb, Cr, and alpha samples");
- entry->module=ConstantString("YCbCr");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
Allocate memory for pixels.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image_info->interlace != PartitionInterlace)
Open output image file.
*/
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
- status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
+ assert(exception->signature == MagickCoreSignature);
+ status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
}
if (image->colorspace != YCbCrColorspace)
(void) TransformImageColorspace(image,YCbCrColorspace,exception);
if ((LocaleCompare(image_info->magick,"YCbCrA") == 0) &&
- (image->alpha_trait != BlendPixelTrait))
+ (image->alpha_trait == UndefinedPixelTrait))
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- pixels=GetQuantumPixels(quantum_info);
+ pixels=(unsigned char *) GetQuantumPixels(quantum_info);
switch (image_info->interlace)
{
case NoInterlace:
}
if (image_info->interlace == PartitionInterlace)
(void) CopyMagickString(image->filename,image_info->filename,
- MaxTextExtent);
+ MagickPathExtent);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,5,5);
}
(void) CloseBlob(image);
(void) CopyMagickString(image->filename,image_info->filename,
- MaxTextExtent);
+ MagickPathExtent);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,5,5);