% Read/Write WebP Image Format %
% %
% Software Design %
-% Cristy %
+% John Cristy %
% March 2011 %
% %
% %
-% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2013 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 %
Read simple header.
*/
if (stream[VP8_CHUNK_INDEX] != EXTENDED_HEADER)
- return(stream[VP8_CHUNK_INDEX] == LOSSLESS_FLAG ? MagickTrue : MagickFalse);
+ return(stream[VP8_CHUNK_INDEX] == LOSSLESS_FLAG ? MagickTrue : MagickFalse);
/*
Read extended header.
*/
Image
*image;
+ int
+ webp_status;
+
MagickBooleanType
status;
}
if (WebPInitDecoderConfig(&configure) == 0)
ThrowReaderException(ResourceLimitError,"UnableToDecodeImageFile");
+ webp_image->colorspace=MODE_RGBA;
length=(size_t) GetBlobSize(image);
stream=(unsigned char *) AcquireQuantumMemory(length,sizeof(*stream));
if (stream == (unsigned char *) NULL)
count=ReadBlob(image,length,stream);
if (count != (ssize_t) length)
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
- if (WebPGetFeatures(stream,length,features) != 0)
+ webp_status=WebPGetFeatures(stream,length,features);
+ if (webp_status == VP8_STATUS_OK)
{
- stream=(unsigned char*) RelinquishMagickMemory(stream);
- ThrowReaderException(ResourceLimitError,"UnableToDecodeImageFile");
+ image->columns=(size_t) webp_image->width;
+ image->rows=(size_t) webp_image->height;
+ image->depth=8;
+ image->alpha_trait=features->has_alpha != 0 ? BlendPixelTrait :
+ UndefinedPixelTrait;
+ if (image_info->ping != MagickFalse)
+ {
+ stream=(unsigned char*) RelinquishMagickMemory(stream);
+ (void) CloseBlob(image);
+ return(GetFirstImageInList(image));
+ }
+ webp_status=WebPDecode(stream,length,&configure);
}
- webp_image->colorspace=MODE_RGBA;
- if (WebPDecode(stream,length,&configure) != 0)
+ if (webp_status != VP8_STATUS_OK)
{
stream=(unsigned char*) RelinquishMagickMemory(stream);
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ switch (webp_status)
+ {
+ case VP8_STATUS_OUT_OF_MEMORY:
+ {
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ break;
+ }
+ case VP8_STATUS_BITSTREAM_ERROR:
+ {
+ ThrowReaderException(CorruptImageError,"CorruptImage");
+ break;
+ }
+ case VP8_STATUS_UNSUPPORTED_FEATURE:
+ {
+ ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported");
+ break;
+ }
+ case VP8_STATUS_NOT_ENOUGH_DATA:
+ {
+ ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
+ break;
+ }
+ default:
+ ThrowReaderException(CorruptImageError,"CorruptImage");
+ }
}
- image->columns=(size_t) webp_image->width;
- image->rows=(size_t) webp_image->height;
- image->alpha_trait=features->has_alpha != 0 ? BlendPixelTrait :
- UndefinedPixelTrait;
if (IsWEBPImageLossless(stream,length) != MagickFalse)
image->quality=100;
p=webp_image->u.RGBA.rgba;