cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % W W EEEEE BBBB PPPP % |
| 7 | % W W E B B P P % |
| 8 | % W W W EEE BBBB PPPP % |
| 9 | % WW WW E B B P % |
| 10 | % W W EEEEE BBBB P % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write WebP Image Format % |
| 14 | % % |
| 15 | % Software Design % |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 16 | % John Cristy % |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 17 | % March 2011 % |
| 18 | % % |
| 19 | % % |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 20 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
cristy | 76ce6e1 | 2013-04-05 14:33:38 +0000 | [diff] [blame] | 43 | #include "MagickCore/artifact.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/client.h" |
cristy | e65bb19 | 2013-08-01 11:22:06 +0000 | [diff] [blame] | 47 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 48 | #include "MagickCore/display.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/monitor.h" |
| 56 | #include "MagickCore/monitor-private.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/option.h" |
| 59 | #include "MagickCore/pixel-accessor.h" |
| 60 | #include "MagickCore/quantum-private.h" |
| 61 | #include "MagickCore/static.h" |
| 62 | #include "MagickCore/string_.h" |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 63 | #include "MagickCore/string-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 64 | #include "MagickCore/module.h" |
| 65 | #include "MagickCore/utility.h" |
| 66 | #include "MagickCore/xwindow.h" |
| 67 | #include "MagickCore/xwindow-private.h" |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 68 | #if defined(MAGICKCORE_WEBP_DELEGATE) |
| 69 | #include <webp/decode.h> |
| 70 | #include <webp/encode.h> |
| 71 | #endif |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | Forward declarations. |
| 75 | */ |
| 76 | #if defined(MAGICKCORE_WEBP_DELEGATE) |
| 77 | static MagickBooleanType |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 78 | WriteWEBPImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
cristy | dffa79e | 2013-02-20 00:57:26 +0000 | [diff] [blame] | 81 | /* |
| 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 83 | % % |
| 84 | % % |
| 85 | % % |
| 86 | % I s W E B P % |
| 87 | % % |
| 88 | % % |
| 89 | % % |
| 90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 91 | % |
| 92 | % IsWEBP() returns MagickTrue if the image format type, identified by the |
| 93 | % magick string, is WebP. |
| 94 | % |
| 95 | % The format of the IsWEBP method is: |
| 96 | % |
| 97 | % MagickBooleanType IsWEBP(const unsigned char *magick,const size_t length) |
| 98 | % |
| 99 | % A description of each parameter follows: |
| 100 | % |
| 101 | % o magick: compare image format pattern against these bytes. |
| 102 | % |
| 103 | % o length: Specifies the length of the magick string. |
| 104 | % |
| 105 | */ |
| 106 | static MagickBooleanType IsWEBP(const unsigned char *magick,const size_t length) |
| 107 | { |
| 108 | if (length < 12) |
| 109 | return(MagickFalse); |
| 110 | if (LocaleNCompare((const char *) magick+8,"WEBP",4) == 0) |
| 111 | return(MagickTrue); |
| 112 | return(MagickFalse); |
| 113 | } |
| 114 | |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 115 | #if defined(MAGICKCORE_WEBP_DELEGATE) |
| 116 | /* |
| 117 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 118 | % % |
| 119 | % % |
| 120 | % % |
| 121 | % R e a d W E B P I m a g e % |
| 122 | % % |
| 123 | % % |
| 124 | % % |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 | % |
| 127 | % ReadWEBPImage() reads an image in the WebP image format. |
| 128 | % |
| 129 | % The format of the ReadWEBPImage method is: |
| 130 | % |
| 131 | % Image *ReadWEBPImage(const ImageInfo *image_info, |
| 132 | % ExceptionInfo *exception) |
| 133 | % |
| 134 | % A description of each parameter follows: |
| 135 | % |
| 136 | % o image_info: the image info. |
| 137 | % |
| 138 | % o exception: return any errors or warnings in this structure. |
| 139 | % |
| 140 | */ |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 141 | |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 142 | static inline uint32_t ReadWebPLSBWord(const unsigned char *restrict data) |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 143 | { |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 144 | register const unsigned char |
| 145 | *p; |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 146 | |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 147 | register uint32_t |
| 148 | value; |
| 149 | |
| 150 | p=data; |
| 151 | value=(uint32_t) (*p++); |
| 152 | value|=((uint32_t) (*p++)) << 8; |
| 153 | value|=((uint32_t) (*p++)) << 16; |
| 154 | value|=((uint32_t) (*p++)) << 24; |
| 155 | return(value); |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static MagickBooleanType IsWEBPImageLossless(const unsigned char *stream, |
| 159 | const size_t length) |
| 160 | { |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 161 | #define VP8_CHUNK_INDEX 15 |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 162 | #define LOSSLESS_FLAG 'L' |
| 163 | #define EXTENDED_HEADER 'X' |
| 164 | #define VP8_CHUNK_HEADER "VP8" |
| 165 | #define VP8_CHUNK_HEADER_SIZE 3 |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 166 | #define RIFF_HEADER_SIZE 12 |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 167 | #define VP8X_CHUNK_SIZE 10 |
| 168 | #define TAG_SIZE 4 |
| 169 | #define CHUNK_SIZE_BYTES 4 |
| 170 | #define CHUNK_HEADER_SIZE 8 |
cristy | a230a61 | 2014-01-05 20:51:47 +0000 | [diff] [blame] | 171 | #define MAX_CHUNK_PAYLOAD (~0U-CHUNK_HEADER_SIZE-1) |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 172 | |
| 173 | ssize_t |
| 174 | offset; |
| 175 | |
| 176 | /* |
| 177 | Read simple header. |
| 178 | */ |
| 179 | if (stream[VP8_CHUNK_INDEX] != EXTENDED_HEADER) |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 180 | return(stream[VP8_CHUNK_INDEX] == LOSSLESS_FLAG ? MagickTrue : MagickFalse); |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 181 | /* |
| 182 | Read extended header. |
| 183 | */ |
| 184 | offset=RIFF_HEADER_SIZE+TAG_SIZE+CHUNK_SIZE_BYTES+VP8X_CHUNK_SIZE; |
cristy | b0de93f | 2013-05-03 13:39:25 +0000 | [diff] [blame] | 185 | while (offset <= (ssize_t) length) |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 186 | { |
| 187 | uint32_t |
| 188 | chunk_size, |
| 189 | chunk_size_pad; |
| 190 | |
cristy | ef97829 | 2013-02-23 02:32:06 +0000 | [diff] [blame] | 191 | chunk_size=ReadWebPLSBWord(stream+offset+TAG_SIZE); |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 192 | if (chunk_size > MAX_CHUNK_PAYLOAD) |
| 193 | break; |
| 194 | chunk_size_pad=(CHUNK_HEADER_SIZE+chunk_size+1) & ~1; |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 195 | if (memcmp(stream+offset,VP8_CHUNK_HEADER,VP8_CHUNK_HEADER_SIZE) == 0) |
cristy | ef97829 | 2013-02-23 02:32:06 +0000 | [diff] [blame] | 196 | return(*(stream+offset+VP8_CHUNK_HEADER_SIZE) == LOSSLESS_FLAG ? |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 197 | MagickTrue : MagickFalse); |
| 198 | offset+=chunk_size_pad; |
| 199 | } |
| 200 | return(MagickFalse); |
| 201 | } |
| 202 | |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 203 | static Image *ReadWEBPImage(const ImageInfo *image_info, |
| 204 | ExceptionInfo *exception) |
| 205 | { |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 206 | Image |
| 207 | *image; |
| 208 | |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 209 | int |
| 210 | webp_status; |
| 211 | |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 212 | MagickBooleanType |
| 213 | status; |
| 214 | |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 215 | register unsigned char |
| 216 | *p; |
| 217 | |
| 218 | size_t |
| 219 | length; |
| 220 | |
| 221 | ssize_t |
| 222 | count, |
| 223 | y; |
| 224 | |
| 225 | unsigned char |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 226 | *stream; |
| 227 | |
| 228 | WebPDecoderConfig |
| 229 | configure; |
| 230 | |
| 231 | WebPDecBuffer |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 232 | *restrict webp_image = &configure.output; |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 233 | |
| 234 | WebPBitstreamFeatures |
cristy | 0b7a033 | 2013-02-23 02:28:08 +0000 | [diff] [blame] | 235 | *restrict features = &configure.input; |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 236 | |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 237 | /* |
| 238 | Open image file. |
| 239 | */ |
| 240 | assert(image_info != (const ImageInfo *) NULL); |
| 241 | assert(image_info->signature == MagickSignature); |
| 242 | if (image_info->debug != MagickFalse) |
| 243 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 244 | image_info->filename); |
| 245 | assert(exception != (ExceptionInfo *) NULL); |
| 246 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 247 | image=AcquireImage(image_info,exception); |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 248 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 249 | if (status == MagickFalse) |
| 250 | { |
| 251 | image=DestroyImageList(image); |
| 252 | return((Image *) NULL); |
| 253 | } |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 254 | if (WebPInitDecoderConfig(&configure) == 0) |
| 255 | ThrowReaderException(ResourceLimitError,"UnableToDecodeImageFile"); |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 256 | webp_image->colorspace=MODE_RGBA; |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 257 | length=(size_t) GetBlobSize(image); |
| 258 | stream=(unsigned char *) AcquireQuantumMemory(length,sizeof(*stream)); |
| 259 | if (stream == (unsigned char *) NULL) |
| 260 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 261 | count=ReadBlob(image,length,stream); |
| 262 | if (count != (ssize_t) length) |
| 263 | ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 264 | webp_status=WebPGetFeatures(stream,length,features); |
| 265 | if (webp_status == VP8_STATUS_OK) |
| 266 | { |
cristy | 106ce7d | 2013-12-12 13:02:12 +0000 | [diff] [blame] | 267 | image->columns=(size_t) features->width; |
| 268 | image->rows=(size_t) features->height; |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 269 | image->depth=8; |
| 270 | image->alpha_trait=features->has_alpha != 0 ? BlendPixelTrait : |
| 271 | UndefinedPixelTrait; |
| 272 | if (image_info->ping != MagickFalse) |
| 273 | { |
| 274 | stream=(unsigned char*) RelinquishMagickMemory(stream); |
| 275 | (void) CloseBlob(image); |
| 276 | return(GetFirstImageInList(image)); |
| 277 | } |
| 278 | webp_status=WebPDecode(stream,length,&configure); |
| 279 | } |
| 280 | if (webp_status != VP8_STATUS_OK) |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 281 | { |
| 282 | stream=(unsigned char*) RelinquishMagickMemory(stream); |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 283 | switch (webp_status) |
| 284 | { |
| 285 | case VP8_STATUS_OUT_OF_MEMORY: |
| 286 | { |
| 287 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 288 | break; |
| 289 | } |
cristy | eb043f2 | 2014-04-06 00:30:25 +0000 | [diff] [blame] | 290 | case VP8_STATUS_INVALID_PARAM: |
| 291 | { |
| 292 | ThrowReaderException(CorruptImageError,"invalid parameter"); |
| 293 | break; |
| 294 | } |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 295 | case VP8_STATUS_BITSTREAM_ERROR: |
| 296 | { |
| 297 | ThrowReaderException(CorruptImageError,"CorruptImage"); |
| 298 | break; |
| 299 | } |
| 300 | case VP8_STATUS_UNSUPPORTED_FEATURE: |
| 301 | { |
| 302 | ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported"); |
| 303 | break; |
| 304 | } |
cristy | eb043f2 | 2014-04-06 00:30:25 +0000 | [diff] [blame] | 305 | case VP8_STATUS_SUSPENDED: |
| 306 | { |
| 307 | ThrowReaderException(CorruptImageError,"decoder suspended"); |
| 308 | break; |
| 309 | } |
| 310 | case VP8_STATUS_USER_ABORT: |
| 311 | { |
| 312 | ThrowReaderException(CorruptImageError,"user abort"); |
| 313 | break; |
| 314 | } |
cristy | ef632a5 | 2013-12-03 11:06:33 +0000 | [diff] [blame] | 315 | case VP8_STATUS_NOT_ENOUGH_DATA: |
| 316 | { |
| 317 | ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); |
| 318 | break; |
| 319 | } |
| 320 | default: |
| 321 | ThrowReaderException(CorruptImageError,"CorruptImage"); |
| 322 | } |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 323 | } |
cristy | 8f25aa8 | 2013-02-23 02:14:37 +0000 | [diff] [blame] | 324 | if (IsWEBPImageLossless(stream,length) != MagickFalse) |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 325 | image->quality=100; |
cristy | b22ab41 | 2014-04-06 15:09:41 +0000 | [diff] [blame^] | 326 | p=(unsigned char *) webp_image->u.RGBA.rgba; |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 327 | for (y=0; y < (ssize_t) image->rows; y++) |
| 328 | { |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 329 | register Quantum |
| 330 | *q; |
| 331 | |
| 332 | register ssize_t |
| 333 | x; |
| 334 | |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 335 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 336 | if (q == (Quantum *) NULL) |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 337 | break; |
| 338 | for (x=0; x < (ssize_t) image->columns; x++) |
| 339 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 340 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 341 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 342 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 343 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 344 | q+=GetPixelChannels(image); |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 345 | } |
| 346 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 347 | break; |
| 348 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 349 | image->rows); |
| 350 | if (status == MagickFalse) |
| 351 | break; |
| 352 | } |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 353 | WebPFreeDecBuffer(webp_image); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 354 | stream=(unsigned char*) RelinquishMagickMemory(stream); |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 355 | return(image); |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 356 | } |
| 357 | #endif |
| 358 | |
| 359 | /* |
| 360 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 361 | % % |
| 362 | % % |
| 363 | % % |
| 364 | % R e g i s t e r W E B P I m a g e % |
| 365 | % % |
| 366 | % % |
| 367 | % % |
| 368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 369 | % |
| 370 | % RegisterWEBPImage() adds attributes for the WebP image format to |
| 371 | % the list of supported formats. The attributes include the image format |
| 372 | % tag, a method to read and/or write the format, whether the format |
| 373 | % supports the saving of more than one frame to the same file or blob, |
| 374 | % whether the format supports native in-memory I/O, and a brief |
| 375 | % description of the format. |
| 376 | % |
| 377 | % The format of the RegisterWEBPImage method is: |
| 378 | % |
| 379 | % size_t RegisterWEBPImage(void) |
| 380 | % |
| 381 | */ |
| 382 | ModuleExport size_t RegisterWEBPImage(void) |
| 383 | { |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 384 | char |
| 385 | version[MaxTextExtent]; |
| 386 | |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 387 | MagickInfo |
| 388 | *entry; |
| 389 | |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 390 | *version='\0'; |
cristy | 25ba0c0 | 2011-03-14 00:54:32 +0000 | [diff] [blame] | 391 | entry=SetMagickInfo("WEBP"); |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 392 | #if defined(MAGICKCORE_WEBP_DELEGATE) |
| 393 | entry->decoder=(DecodeImageHandler *) ReadWEBPImage; |
| 394 | entry->encoder=(EncodeImageHandler *) WriteWEBPImage; |
cristy | eb043f2 | 2014-04-06 00:30:25 +0000 | [diff] [blame] | 395 | (void) FormatLocaleString(version,MaxTextExtent,"libwebp %d.%d.%d (%04X)", |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 396 | (WebPGetDecoderVersion() >> 16) & 0xff, |
| 397 | (WebPGetDecoderVersion() >> 8) & 0xff, |
cristy | eb043f2 | 2014-04-06 00:30:25 +0000 | [diff] [blame] | 398 | (WebPGetDecoderVersion() >> 0) & 0xff,WEBP_ENCODER_ABI_VERSION); |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 399 | #endif |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 400 | entry->description=ConstantString("WebP Image Format"); |
cristy | 99872d0 | 2014-02-05 12:26:14 +0000 | [diff] [blame] | 401 | entry->mime_type=ConstantString("image/x-webp"); |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 402 | entry->adjoin=MagickFalse; |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 403 | entry->module=ConstantString("WEBP"); |
cristy | dffa79e | 2013-02-20 00:57:26 +0000 | [diff] [blame] | 404 | entry->magick=(IsImageFormatHandler *) IsWEBP; |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 405 | if (*version != '\0') |
| 406 | entry->version=ConstantString(version); |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 407 | (void) RegisterMagickInfo(entry); |
| 408 | return(MagickImageCoderSignature); |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 413 | % % |
| 414 | % % |
| 415 | % % |
| 416 | % U n r e g i s t e r W E B P I m a g e % |
| 417 | % % |
| 418 | % % |
| 419 | % % |
| 420 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 421 | % |
| 422 | % UnregisterWEBPImage() removes format registrations made by the WebP module |
| 423 | % from the list of supported formats. |
| 424 | % |
| 425 | % The format of the UnregisterWEBPImage method is: |
| 426 | % |
| 427 | % UnregisterWEBPImage(void) |
| 428 | % |
| 429 | */ |
| 430 | ModuleExport void UnregisterWEBPImage(void) |
| 431 | { |
| 432 | (void) UnregisterMagickInfo("WEBP"); |
| 433 | } |
| 434 | #if defined(MAGICKCORE_WEBP_DELEGATE) |
| 435 | |
| 436 | /* |
| 437 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 438 | % % |
| 439 | % % |
| 440 | % % |
| 441 | % W r i t e W E B P I m a g e % |
| 442 | % % |
| 443 | % % |
| 444 | % % |
| 445 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 446 | % |
| 447 | % WriteWEBPImage() writes an image in the WebP image format. |
| 448 | % |
| 449 | % The format of the WriteWEBPImage method is: |
| 450 | % |
| 451 | % MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, |
| 452 | % Image *image) |
| 453 | % |
| 454 | % A description of each parameter follows. |
| 455 | % |
| 456 | % o image_info: the image info. |
| 457 | % |
| 458 | % o image: The image. |
| 459 | % |
| 460 | */ |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 461 | |
cristy | b22ab41 | 2014-04-06 15:09:41 +0000 | [diff] [blame^] | 462 | #if WEBP_ENCODER_ABI_VERSION >= 0x0100 |
| 463 | static int WebPEncodeProgress(int percent,const WebPPicture* picture) |
| 464 | { |
| 465 | Image |
| 466 | *image; |
| 467 | |
| 468 | MagickBooleanType |
| 469 | status; |
| 470 | |
| 471 | image=(Image *) picture->custom_ptr; |
| 472 | status=SetImageProgress(image,SaveImageTag,percent-1,100); |
| 473 | return(status == MagickFalse ? 0 : 1); |
| 474 | } |
| 475 | #endif |
| 476 | |
| 477 | static int WebPEncodeWriter(const unsigned char *stream,size_t length, |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 478 | const WebPPicture *const picture) |
| 479 | { |
| 480 | Image |
| 481 | *image; |
| 482 | |
| 483 | image=(Image *) picture->custom_ptr; |
| 484 | return(length != 0 ? (int) WriteBlob(image,length,stream) : 1); |
| 485 | } |
| 486 | |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 487 | static MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 488 | Image *image,ExceptionInfo *exception) |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 489 | { |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 490 | const char |
| 491 | *value; |
| 492 | |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 493 | int |
| 494 | webp_status; |
| 495 | |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 496 | MagickBooleanType |
| 497 | status; |
| 498 | |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 499 | MemoryInfo |
| 500 | *pixel_info; |
| 501 | |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 502 | register uint32_t |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 503 | *restrict q; |
| 504 | |
| 505 | ssize_t |
| 506 | y; |
| 507 | |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 508 | WebPConfig |
| 509 | configure; |
| 510 | |
| 511 | WebPPicture |
| 512 | picture; |
| 513 | |
| 514 | WebPAuxStats |
| 515 | statistics; |
| 516 | |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 517 | /* |
| 518 | Open output image file. |
| 519 | */ |
| 520 | assert(image_info != (const ImageInfo *) NULL); |
| 521 | assert(image_info->signature == MagickSignature); |
| 522 | assert(image != (Image *) NULL); |
| 523 | assert(image->signature == MagickSignature); |
| 524 | if (image->debug != MagickFalse) |
| 525 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 5779030 | 2013-02-18 18:19:08 +0000 | [diff] [blame] | 526 | if ((image->columns > 16383UL) || (image->rows > 16383UL)) |
cristy | e4d08fd | 2012-04-26 17:29:08 +0000 | [diff] [blame] | 527 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 528 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | ffa663d | 2011-03-14 00:58:51 +0000 | [diff] [blame] | 529 | if (status == MagickFalse) |
| 530 | return(status); |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 531 | if ((WebPPictureInit(&picture) == 0) || (WebPConfigInit(&configure) == 0)) |
| 532 | ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); |
cristy | b22ab41 | 2014-04-06 15:09:41 +0000 | [diff] [blame^] | 533 | picture.writer=WebPEncodeWriter; |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 534 | picture.custom_ptr=(void *) image; |
cristy | b22ab41 | 2014-04-06 15:09:41 +0000 | [diff] [blame^] | 535 | #if WEBP_ENCODER_ABI_VERSION >= 0x0100 |
| 536 | picture.progress_hook=WebPEncodeProgress; |
| 537 | #endif |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 538 | picture.stats=(&statistics); |
| 539 | picture.width=(int) image->columns; |
| 540 | picture.height=(int) image->rows; |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 541 | picture.argb_stride=(int) image->columns; |
| 542 | picture.use_argb=1; |
cristy | 35c63c7 | 2012-10-23 14:40:54 +0000 | [diff] [blame] | 543 | if (image->quality != UndefinedCompressionQuality) |
| 544 | configure.quality=(float) image->quality; |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 545 | else |
| 546 | if (image->quality >= 100) |
| 547 | configure.lossless=1; |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 548 | value=GetImageOption(image_info,"webp:lossless"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 549 | if (value != (char *) NULL) |
cristy | b22ab41 | 2014-04-06 15:09:41 +0000 | [diff] [blame^] | 550 | configure.lossless=(int) ParseCommandOption(MagickBooleanOptions, |
| 551 | MagickFalse,value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 552 | value=GetImageOption(image_info,"webp:method"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 553 | if (value != (char *) NULL) |
| 554 | configure.method=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 555 | value=GetImageOption(image_info,"webp:image-hint"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 556 | if (value != (char *) NULL) |
cristy | d6f2cc4 | 2013-02-18 17:24:19 +0000 | [diff] [blame] | 557 | { |
cristy | 547fe7f | 2013-02-18 17:27:13 +0000 | [diff] [blame] | 558 | if (LocaleCompare(value,"graph") == 0) |
cristy | d6f2cc4 | 2013-02-18 17:24:19 +0000 | [diff] [blame] | 559 | configure.image_hint=WEBP_HINT_GRAPH; |
cristy | 547fe7f | 2013-02-18 17:27:13 +0000 | [diff] [blame] | 560 | if (LocaleCompare(value,"photo") == 0) |
cristy | d6f2cc4 | 2013-02-18 17:24:19 +0000 | [diff] [blame] | 561 | configure.image_hint=WEBP_HINT_PHOTO; |
cristy | 547fe7f | 2013-02-18 17:27:13 +0000 | [diff] [blame] | 562 | if (LocaleCompare(value,"picture") == 0) |
cristy | d6f2cc4 | 2013-02-18 17:24:19 +0000 | [diff] [blame] | 563 | configure.image_hint=WEBP_HINT_PICTURE; |
| 564 | } |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 565 | value=GetImageOption(image_info,"webp:target-size"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 566 | if (value != (char *) NULL) |
| 567 | configure.target_size=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 568 | value=GetImageOption(image_info,"webp:target-psnr"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 569 | if (value != (char *) NULL) |
| 570 | configure.target_PSNR=(float) StringToDouble(value,(char **) NULL); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 571 | value=GetImageOption(image_info,"webp:segments"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 572 | if (value != (char *) NULL) |
| 573 | configure.segments=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 574 | value=GetImageOption(image_info,"webp:sns-strength"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 575 | if (value != (char *) NULL) |
| 576 | configure.sns_strength=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 577 | value=GetImageOption(image_info,"webp:filter-strength"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 578 | if (value != (char *) NULL) |
| 579 | configure.filter_strength=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 580 | value=GetImageOption(image_info,"webp:filter-sharpness"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 581 | if (value != (char *) NULL) |
| 582 | configure.filter_sharpness=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 583 | value=GetImageOption(image_info,"webp:filter-type"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 584 | if (value != (char *) NULL) |
| 585 | configure.filter_type=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 586 | value=GetImageOption(image_info,"webp:auto-filter"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 587 | if (value != (char *) NULL) |
cristy | b22ab41 | 2014-04-06 15:09:41 +0000 | [diff] [blame^] | 588 | configure.autofilter=(int) ParseCommandOption(MagickBooleanOptions, |
| 589 | MagickFalse,value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 590 | value=GetImageOption(image_info,"webp:alpha-compression"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 591 | if (value != (char *) NULL) |
| 592 | configure.alpha_compression=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 593 | value=GetImageOption(image_info,"webp:alpha-filtering"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 594 | if (value != (char *) NULL) |
| 595 | configure.alpha_filtering=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 596 | value=GetImageOption(image_info,"webp:alpha-quality"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 597 | if (value != (char *) NULL) |
| 598 | configure.alpha_quality=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 599 | value=GetImageOption(image_info,"webp:pass"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 600 | if (value != (char *) NULL) |
| 601 | configure.pass=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 602 | value=GetImageOption(image_info,"webp:show-compressed"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 603 | if (value != (char *) NULL) |
| 604 | configure.show_compressed=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 605 | value=GetImageOption(image_info,"webp:preprocessing"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 606 | if (value != (char *) NULL) |
| 607 | configure.preprocessing=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 608 | value=GetImageOption(image_info,"webp:partitions"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 609 | if (value != (char *) NULL) |
| 610 | configure.partitions=StringToInteger(value); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 611 | value=GetImageOption(image_info,"webp:partition-limit"); |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 612 | if (value != (char *) NULL) |
| 613 | configure.partition_limit=StringToInteger(value); |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 614 | if (WebPValidateConfig(&configure) == 0) |
| 615 | ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); |
| 616 | /* |
| 617 | Allocate memory for pixels. |
| 618 | */ |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 619 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 620 | pixel_info=AcquireVirtualMemory(image->columns,image->rows* |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 621 | sizeof(*picture.argb)); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 622 | if (pixel_info == (MemoryInfo *) NULL) |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 623 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 624 | picture.argb=(uint32_t *) GetVirtualMemoryBlob(pixel_info); |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 625 | /* |
| 626 | Convert image to WebP raster pixels. |
| 627 | */ |
cristy | e71e089 | 2013-02-18 13:13:53 +0000 | [diff] [blame] | 628 | q=picture.argb; |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 629 | for (y=0; y < (ssize_t) image->rows; y++) |
| 630 | { |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 631 | register const Quantum |
| 632 | *restrict p; |
| 633 | |
| 634 | register ssize_t |
| 635 | x; |
| 636 | |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 637 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 638 | if (p == (const Quantum *) NULL) |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 639 | break; |
| 640 | for (x=0; x < (ssize_t) image->columns; x++) |
| 641 | { |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 642 | *q++=(uint32_t) (image->alpha_trait == BlendPixelTrait ? |
cristy | b0de93f | 2013-05-03 13:39:25 +0000 | [diff] [blame] | 643 | ScaleQuantumToChar(GetPixelAlpha(image,p)) << 24 : 0xff000000) | |
cristy | af29b62 | 2013-02-18 15:06:48 +0000 | [diff] [blame] | 644 | (ScaleQuantumToChar(GetPixelRed(image,p)) << 16) | |
| 645 | (ScaleQuantumToChar(GetPixelGreen(image,p)) << 8) | |
| 646 | (ScaleQuantumToChar(GetPixelBlue(image,p))); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 647 | p+=GetPixelChannels(image); |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 648 | } |
| 649 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 650 | image->rows); |
| 651 | if (status == MagickFalse) |
| 652 | break; |
| 653 | } |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 654 | webp_status=WebPEncode(&configure,&picture); |
cristy | eb043f2 | 2014-04-06 00:30:25 +0000 | [diff] [blame] | 655 | if (webp_status != VP8_ENC_OK) |
cristy | f13926d | 2014-03-13 12:38:55 +0000 | [diff] [blame] | 656 | { |
| 657 | const char |
| 658 | *message; |
| 659 | |
| 660 | switch (picture.error_code) |
| 661 | { |
| 662 | case VP8_ENC_ERROR_OUT_OF_MEMORY: |
| 663 | { |
| 664 | message="out of memory"; |
| 665 | break; |
| 666 | } |
| 667 | case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: |
| 668 | { |
| 669 | message="bitstream out of memory"; |
| 670 | break; |
| 671 | } |
| 672 | case VP8_ENC_ERROR_NULL_PARAMETER: |
| 673 | { |
| 674 | message="NULL parameter"; |
| 675 | break; |
| 676 | } |
| 677 | case VP8_ENC_ERROR_INVALID_CONFIGURATION: |
| 678 | { |
| 679 | message="invalid configuration"; |
| 680 | break; |
| 681 | } |
| 682 | case VP8_ENC_ERROR_BAD_DIMENSION: |
| 683 | { |
| 684 | message="bad dimension"; |
| 685 | break; |
| 686 | } |
| 687 | case VP8_ENC_ERROR_PARTITION0_OVERFLOW: |
| 688 | { |
| 689 | message="partition 0 overflow (> 512K)"; |
| 690 | break; |
| 691 | } |
| 692 | case VP8_ENC_ERROR_PARTITION_OVERFLOW: |
| 693 | { |
| 694 | message="partition overflow (> 16M)"; |
| 695 | break; |
| 696 | } |
| 697 | case VP8_ENC_ERROR_BAD_WRITE: |
| 698 | { |
| 699 | message="bad write"; |
| 700 | break; |
| 701 | } |
| 702 | case VP8_ENC_ERROR_FILE_TOO_BIG: |
| 703 | { |
| 704 | message="file too big (> 4GB)"; |
| 705 | break; |
| 706 | } |
| 707 | #if WEBP_ENCODER_ABI_VERSION >= 0x0100 |
| 708 | case VP8_ENC_ERROR_USER_ABORT: |
| 709 | { |
| 710 | message="user abort"; |
| 711 | break; |
| 712 | } |
| 713 | #endif |
| 714 | default: |
| 715 | { |
| 716 | message="unknown exception"; |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError, |
| 721 | (char *) message,"`%s'",image->filename); |
| 722 | } |
cristy | 05df112 | 2012-09-26 09:43:12 +0000 | [diff] [blame] | 723 | WebPPictureFree(&picture); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 724 | pixel_info=RelinquishVirtualMemory(pixel_info); |
cristy | 644040e | 2011-03-14 17:31:59 +0000 | [diff] [blame] | 725 | (void) CloseBlob(image); |
| 726 | return(webp_status == 0 ? MagickFalse : MagickTrue); |
cristy | b186075 | 2011-03-14 00:27:46 +0000 | [diff] [blame] | 727 | } |
| 728 | #endif |