diff options
Diffstat (limited to 'coders/webp.c')
-rw-r--r-- | coders/webp.c | 572 |
1 files changed, 278 insertions, 294 deletions
diff --git a/coders/webp.c b/coders/webp.c index 282bbbe7e..16d8d301e 100644 --- a/coders/webp.c +++ b/coders/webp.c @@ -17,7 +17,7 @@ % March 2011 % % % % % -% Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization % +% Copyright 1999-2021 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 % @@ -149,10 +149,10 @@ static MagickBooleanType IsWEBP(const unsigned char *magick,const size_t length) static inline uint32_t ReadWebPLSBWord( const unsigned char *magick_restrict data) { - register const unsigned char + const unsigned char *p; - register uint32_t + uint32_t value; p=data; @@ -240,7 +240,7 @@ static int ReadSingleWEBPImage(Image *image,const uint8_t *stream, int webp_status; - register unsigned char + unsigned char *p; size_t @@ -255,11 +255,12 @@ static int ReadSingleWEBPImage(Image *image,const uint8_t *stream, y; WebPDecBuffer - *magick_restrict webp_image = &configure->output; + *magick_restrict webp_image; MagickBooleanType status; + webp_image=&configure->output; if (is_first) { canvas_width=image->columns; @@ -296,10 +297,10 @@ static int ReadSingleWEBPImage(Image *image,const uint8_t *stream, p=(unsigned char *) webp_image->u.RGBA.rgba; for (y=0; y < (ssize_t) image->rows; y++) { - register Quantum + Quantum *q; - register ssize_t + ssize_t x; q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); @@ -307,8 +308,8 @@ static int ReadSingleWEBPImage(Image *image,const uint8_t *stream, break; for (x=0; x < (ssize_t) image->columns; x++) { - if ((x >= x_offset && x < x_offset + image_width) && - (y >= y_offset && y < y_offset + image_height)) + if ((x >= x_offset && x < (ssize_t) (x_offset+image_width)) && + (y >= y_offset && y < (ssize_t) (y_offset+image_height))) { SetPixelRed(image,ScaleCharToQuantum(*p++),q); SetPixelGreen(image,ScaleCharToQuantum(*p++),q); @@ -760,24 +761,55 @@ static int WebPEncodeWriter(const unsigned char *stream,size_t length, } #endif -typedef struct PictureMemory { - MemoryInfo *pixel_info; - struct PictureMemory *next; -} PictureMemory; +static const char * WebPErrorCodeMessage(WebPEncodingError error_code) +{ + switch (error_code) + { + case VP8_ENC_OK: + return NULL; + case VP8_ENC_ERROR_OUT_OF_MEMORY: + return "out of memory"; + case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: + return "bitstream out of memory"; + case VP8_ENC_ERROR_NULL_PARAMETER: + return "NULL parameter"; + case VP8_ENC_ERROR_INVALID_CONFIGURATION: + return "invalid configuration"; + case VP8_ENC_ERROR_BAD_DIMENSION: + return "bad dimension"; + case VP8_ENC_ERROR_PARTITION0_OVERFLOW: + return "partition 0 overflow (> 512K)"; + case VP8_ENC_ERROR_PARTITION_OVERFLOW: + return "partition overflow (> 16M)"; + case VP8_ENC_ERROR_BAD_WRITE: + return "bad write"; + case VP8_ENC_ERROR_FILE_TOO_BIG: + return "file too big (> 4GB)"; +#if WEBP_ENCODER_ABI_VERSION >= 0x0100 + case VP8_ENC_ERROR_USER_ABORT: + return "user abort"; + case VP8_ENC_ERROR_LAST: + return "error last"; +#endif + } + return "unknown exception"; +} -static MagickBooleanType WriteSingleWEBPImage(const ImageInfo *image_info, - Image *image,WebPPicture *picture,PictureMemory *picture_memory, - ExceptionInfo *exception) +static MagickBooleanType WriteSingleWEBPPicture(const ImageInfo *image_info, + Image *image,WebPConfig *configure,WebPPicture *picture,ExceptionInfo *exception) { MagickBooleanType - status = MagickFalse; + status; - register uint32_t + uint32_t *magick_restrict q; ssize_t y; + MemoryInfo + *pixel_info; + #if WEBP_ENCODER_ABI_VERSION >= 0x0100 picture->progress_hook=WebPEncodeProgress; picture->user_data=(void *) image; @@ -791,22 +823,23 @@ static MagickBooleanType WriteSingleWEBPImage(const ImageInfo *image_info, Allocate memory for pixels. */ (void) TransformImageColorspace(image,sRGBColorspace,exception); - picture_memory->pixel_info=AcquireVirtualMemory(image->columns,image->rows* + pixel_info=AcquireVirtualMemory(image->columns,image->rows* sizeof(*(picture->argb))); - if (picture_memory->pixel_info == (MemoryInfo *) NULL) + if (pixel_info == (MemoryInfo *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); - picture->argb=(uint32_t *) GetVirtualMemoryBlob(picture_memory->pixel_info); + picture->argb=(uint32_t *) GetVirtualMemoryBlob(pixel_info); /* Convert image to WebP raster pixels. */ + status=MagickFalse; q=picture->argb; for (y=0; y < (ssize_t) image->rows; y++) { - register const Quantum + const Quantum *magick_restrict p; - register ssize_t + ssize_t x; p=GetVirtualPixels(image,0,y,image->columns,1,exception); @@ -826,35 +859,53 @@ static MagickBooleanType WriteSingleWEBPImage(const ImageInfo *image_info, if (status == MagickFalse) break; } - return status; + + if (status != MagickFalse) + status=(MagickBooleanType) WebPEncode(configure, picture); + + RelinquishVirtualMemory(pixel_info); + + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError, + WebPErrorCodeMessage(picture->error_code),"`%s'", + image->filename); + + return(status); } -#if defined(MAGICKCORE_WEBPMUX_DELEGATE) -static void FreePictureMemoryList (PictureMemory* head) { - PictureMemory* next; - while(head != NULL) { - next = head->next; - if(head->pixel_info != NULL) - RelinquishVirtualMemory(head->pixel_info); - free(head); - head = next; - } +static MagickBooleanType WriteSingleWEBPImage(const ImageInfo *image_info, + Image *image,WebPConfig *configure,WebPMemoryWriter *writer, + ExceptionInfo *exception) +{ + MagickBooleanType + status; + + WebPPicture + picture; + + if (WebPPictureInit(&picture) == 0) + ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); + + picture.writer=WebPMemoryWrite; + picture.custom_ptr=writer; + + status=WriteSingleWEBPPicture(image_info,image,configure,&picture,exception); + WebPPictureFree(&picture); + + return(status); } +#if defined(MAGICKCORE_WEBPMUX_DELEGATE) static MagickBooleanType WriteAnimatedWEBPImage(const ImageInfo *image_info, - Image *image,WebPConfig *configure,WebPMemoryWriter *writer_info, + Image *image,WebPConfig *configure,WebPData *webp_data, ExceptionInfo *exception) { Image *first_image; - PictureMemory - *current, - *head; - size_t - effective_delta = 0, - frame_timestamp = 0; + effective_delta, + frame_timestamp; WebPAnimEncoder *enc; @@ -862,83 +913,167 @@ static MagickBooleanType WriteAnimatedWEBPImage(const ImageInfo *image_info, WebPAnimEncoderOptions enc_options; - WebPData - webp_data; - WebPPicture picture; - WebPAnimEncoderOptionsInit(&enc_options); - if (image_info->verbose) - enc_options.verbose = 1; + MagickBooleanType + status; + + first_image=CoalesceImages(image,exception); + if (first_image == (Image *) NULL) + return(MagickFalse); + image=first_image; + effective_delta=0; + frame_timestamp=0; - image=CoalesceImages(image, exception); - first_image=image; + (void) WebPAnimEncoderOptionsInit(&enc_options); + if (image_info->verbose) + enc_options.verbose=1; enc=WebPAnimEncoderNew((int) image->page.width,(int) image->page.height, &enc_options); - head=(PictureMemory *) calloc(sizeof(*head),1); - current=head; - + status=MagickTrue; while (image != NULL) { - if (WebPPictureInit(&picture) == 0) - ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); + status=(MagickBooleanType) WebPPictureInit(&picture); + if (status == MagickFalse) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"UnableToEncodeImageFile","`%s'",image->filename); + break; + } - WriteSingleWEBPImage(image_info, image, &picture, current, exception); - WebPAnimEncoderAdd(enc,&picture,(int) frame_timestamp,configure); + status=WriteSingleWEBPPicture(image_info,image,configure,&picture, + exception); + if (status == MagickFalse) + break; + + status=(MagickBooleanType) WebPAnimEncoderAdd(enc,&picture, + (int) frame_timestamp,configure); + WebPPictureFree(&picture); + if (status == MagickFalse) + { + (void) ThrowMagickException(exception,GetMagickModule(), + CoderError,WebPAnimEncoderGetError(enc),"`%s'",image->filename); + break; + } - effective_delta = image->delay*1000/image->ticks_per_second; + effective_delta=image->delay*1000/image->ticks_per_second; if (effective_delta < 10) - effective_delta = 100; /* Consistent with gif2webp */ + effective_delta=100; /* Consistent with gif2webp */ frame_timestamp+=effective_delta; - image = GetNextImageInList(image); - current->next=(PictureMemory *) calloc(sizeof(*head), 1); - current = current->next; + image=GetNextImageInList(image); } - WebPAnimEncoderAdd(enc,NULL,(int) frame_timestamp,configure); - webp_data.bytes=writer_info->mem; - webp_data.size=writer_info->size; - WebPAnimEncoderAssemble(enc, &webp_data); - WebPMemoryWriterClear(writer_info); - writer_info->size=webp_data.size; - writer_info->mem=(unsigned char *) webp_data.bytes; + + if (status != MagickFalse) + { + // add last null frame and assemble picture. + status=(MagickBooleanType) WebPAnimEncoderAdd(enc,(WebPPicture *) NULL, + (int) frame_timestamp,configure); + if (status != MagickFalse) + status=(MagickBooleanType) WebPAnimEncoderAssemble(enc,webp_data); + + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(), + CoderError,WebPAnimEncoderGetError(enc),"`%s'", + first_image->filename); + } + WebPAnimEncoderDelete(enc); DestroyImageList(first_image); - FreePictureMemoryList(head); + return(status); +} + +static MagickBooleanType WriteWEBPImageProfile(Image *image, + WebPData *webp_data,ExceptionInfo *exception) +{ + const StringInfo + *icc_profile, + *exif_profile, + *xmp_profile; + + WebPData + chunk; + + WebPMux + *mux; + + WebPMuxError + mux_error=WEBP_MUX_OK; + + icc_profile=GetImageProfile(image,"ICC"); + exif_profile=GetImageProfile(image,"EXIF"); + xmp_profile=GetImageProfile(image,"XMP"); + + if (icc_profile == (StringInfo *) NULL + && exif_profile == (StringInfo *) NULL + && xmp_profile == (StringInfo *) NULL) + return(MagickTrue); + + mux=WebPMuxCreate(webp_data, 1); + WebPDataClear(webp_data); + + if (mux == NULL) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"UnableToEncodeImageFile","`%s'",image->filename); + + // Clean up returned data + memset(webp_data, 0, sizeof(*webp_data)); + if (icc_profile != (StringInfo *) NULL && (mux_error == WEBP_MUX_OK)) + { + chunk.bytes=GetStringInfoDatum(icc_profile); + chunk.size=GetStringInfoLength(icc_profile); + mux_error=WebPMuxSetChunk(mux,"ICCP",&chunk,0); + } + if (exif_profile != (StringInfo *) NULL && (mux_error == WEBP_MUX_OK)) + { + chunk.bytes=GetStringInfoDatum(exif_profile); + chunk.size=GetStringInfoLength(exif_profile); + mux_error=WebPMuxSetChunk(mux,"EXIF",&chunk,0); + } + if (xmp_profile != (StringInfo *) NULL && (mux_error == WEBP_MUX_OK)) + { + chunk.bytes=GetStringInfoDatum(xmp_profile); + chunk.size=GetStringInfoLength(xmp_profile); + mux_error=WebPMuxSetChunk(mux,"XMP",&chunk,0); + } + if (mux_error == WEBP_MUX_OK) + mux_error=WebPMuxAssemble(mux,webp_data); + WebPMuxDelete(mux); + + if (mux_error != WEBP_MUX_OK) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"UnableToEncodeImageFile","`%s'",image->filename); return(MagickTrue); } #endif +static inline void SetIntegerOption(const ImageInfo *image_info, + const char *option,int *setting) +{ + const char + *value; + + value=GetImageOption(image_info,option); + if (value != (const char *) NULL) + *setting=StringToInteger(value); +} + static MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, Image *image,ExceptionInfo * exception) { const char *value; - int - webp_status; - MagickBooleanType status; - WebPAuxStats - statistics; - WebPConfig configure; -#if defined(MAGICKCORE_WEBPMUX_DELEGATE) WebPMemoryWriter - writer_info; -#endif - - WebPPicture - picture; - - PictureMemory - memory = {0}; + writer; /* Open output image file. @@ -956,17 +1091,6 @@ static MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, return(status); if (WebPConfigInit(&configure) == 0) ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); - if (WebPPictureInit(&picture) == 0) - ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); -#if !defined(MAGICKCORE_WEBPMUX_DELEGATE) - picture.writer=WebPEncodeWriter; - picture.custom_ptr=(void *) image; -#else - WebPMemoryWriterInit(&writer_info); - picture.writer=WebPMemoryWrite; - picture.custom_ptr=(&writer_info); -#endif - picture.stats=(&statistics); if (image->quality != UndefinedCompressionQuality) configure.quality=(float) image->quality; if (image->quality >= 100) @@ -975,9 +1099,6 @@ static MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, if (value != (char *) NULL) configure.lossless=(int) ParseCommandOption(MagickBooleanOptions, MagickFalse,value); - value=GetImageOption(image_info,"webp:method"); - if (value != (char *) NULL) - configure.method=StringToInteger(value); value=GetImageOption(image_info,"webp:image-hint"); if (value != (char *) NULL) { @@ -992,55 +1113,35 @@ static MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, configure.image_hint=WEBP_HINT_GRAPH; #endif } - value=GetImageOption(image_info,"webp:target-size"); - if (value != (char *) NULL) - configure.target_size=StringToInteger(value); - value=GetImageOption(image_info,"webp:target-psnr"); - if (value != (char *) NULL) - configure.target_PSNR=(float) StringToDouble(value,(char **) NULL); - value=GetImageOption(image_info,"webp:segments"); - if (value != (char *) NULL) - configure.segments=StringToInteger(value); - value=GetImageOption(image_info,"webp:sns-strength"); - if (value != (char *) NULL) - configure.sns_strength=StringToInteger(value); - value=GetImageOption(image_info,"webp:filter-strength"); - if (value != (char *) NULL) - configure.filter_strength=StringToInteger(value); - value=GetImageOption(image_info,"webp:filter-sharpness"); - if (value != (char *) NULL) - configure.filter_sharpness=StringToInteger(value); - value=GetImageOption(image_info,"webp:filter-type"); - if (value != (char *) NULL) - configure.filter_type=StringToInteger(value); value=GetImageOption(image_info,"webp:auto-filter"); if (value != (char *) NULL) configure.autofilter=(int) ParseCommandOption(MagickBooleanOptions, MagickFalse,value); - value=GetImageOption(image_info,"webp:alpha-compression"); - if (value != (char *) NULL) - configure.alpha_compression=StringToInteger(value); - value=GetImageOption(image_info,"webp:alpha-filtering"); - if (value != (char *) NULL) - configure.alpha_filtering=StringToInteger(value); - value=GetImageOption(image_info,"webp:alpha-quality"); - if (value != (char *) NULL) - configure.alpha_quality=StringToInteger(value); - value=GetImageOption(image_info,"webp:pass"); - if (value != (char *) NULL) - configure.pass=StringToInteger(value); - value=GetImageOption(image_info,"webp:show-compressed"); - if (value != (char *) NULL) - configure.show_compressed=StringToInteger(value); - value=GetImageOption(image_info,"webp:preprocessing"); - if (value != (char *) NULL) - configure.preprocessing=StringToInteger(value); - value=GetImageOption(image_info,"webp:partitions"); - if (value != (char *) NULL) - configure.partitions=StringToInteger(value); - value=GetImageOption(image_info,"webp:partition-limit"); + value=GetImageOption(image_info,"webp:target-psnr"); if (value != (char *) NULL) - configure.partition_limit=StringToInteger(value); + configure.target_PSNR=(float) StringToDouble(value,(char **) NULL); + SetIntegerOption(image_info,"webp:alpha-compression", + &configure.alpha_compression); + SetIntegerOption(image_info,"webp:alpha-filtering", + &configure.alpha_filtering); + SetIntegerOption(image_info,"webp:alpha-quality", + &configure.alpha_quality); + SetIntegerOption(image_info,"webp:filter-strength", + &configure.filter_strength); + SetIntegerOption(image_info,"webp:filter-sharpness", + &configure.filter_sharpness); + SetIntegerOption(image_info,"webp:filter-type",&configure.filter_type); + SetIntegerOption(image_info,"webp:method",&configure.method); + SetIntegerOption(image_info,"webp:partitions",&configure.partitions); + SetIntegerOption(image_info,"webp:partition-limit", + &configure.partition_limit); + SetIntegerOption(image_info,"webp:pass",&configure.pass); + SetIntegerOption(image_info,"webp:preprocessing",&configure.preprocessing); + SetIntegerOption(image_info,"webp:segments",&configure.segments); + SetIntegerOption(image_info,"webp:show-compressed", + &configure.show_compressed); + SetIntegerOption(image_info,"webp:sns-strength",&configure.sns_strength); + SetIntegerOption(image_info,"webp:target-size",&configure.target_size); #if WEBP_ENCODER_ABI_VERSION >= 0x0201 value=GetImageOption(image_info,"webp:emulate-jpeg-size"); if (value != (char *) NULL) @@ -1050,170 +1151,53 @@ static MagickBooleanType WriteWEBPImage(const ImageInfo *image_info, if (value != (char *) NULL) configure.low_memory=(int) ParseCommandOption(MagickBooleanOptions, MagickFalse,value); - value=GetImageOption(image_info,"webp:thread-level"); - if (value != (char *) NULL) - configure.thread_level=StringToInteger(value); + SetIntegerOption(image_info,"webp:thread-level",&configure.thread_level); #endif #if WEBP_ENCODER_ABI_VERSION >= 0x020e - value=GetImageOption(image_info,"webp:use-sharp-yuv"); - if (value != (char *) NULL) - configure.use_sharp_yuv=StringToInteger(value); + SetIntegerOption(image_info,"webp:near-lossless",&configure.near_lossless); + SetIntegerOption(image_info,"webp:use-sharp-yuv",&configure.use_sharp_yuv); #endif if (WebPValidateConfig(&configure) == 0) ThrowWriterException(ResourceLimitError,"UnableToEncodeImageFile"); - - WriteSingleWEBPImage(image_info,image,&picture,&memory,exception); - -#if defined(MAGICKCORE_WEBPMUX_DELEGATE) - if ((image_info->adjoin != MagickFalse) && - (GetPreviousImageInList(image) == (Image *) NULL) && - (GetNextImageInList(image) != (Image *) NULL)) - WriteAnimatedWEBPImage(image_info,image,&configure,&writer_info,exception); -#endif - - webp_status=WebPEncode(&configure,&picture); - if (webp_status == 0) - { - const char - *message; - - switch (picture.error_code) - { - case VP8_ENC_ERROR_OUT_OF_MEMORY: - { - message="out of memory"; - break; - } - case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: - { - message="bitstream out of memory"; - break; - } - case VP8_ENC_ERROR_NULL_PARAMETER: - { - message="NULL parameter"; - break; - } - case VP8_ENC_ERROR_INVALID_CONFIGURATION: - { - message="invalid configuration"; - break; - } - case VP8_ENC_ERROR_BAD_DIMENSION: - { - message="bad dimension"; - break; - } - case VP8_ENC_ERROR_PARTITION0_OVERFLOW: - { - message="partition 0 overflow (> 512K)"; - break; - } - case VP8_ENC_ERROR_PARTITION_OVERFLOW: - { - message="partition overflow (> 16M)"; - break; - } - case VP8_ENC_ERROR_BAD_WRITE: - { - message="bad write"; - break; - } - case VP8_ENC_ERROR_FILE_TOO_BIG: - { - message="file too big (> 4GB)"; - break; - } -#if WEBP_ENCODER_ABI_VERSION >= 0x0100 - case VP8_ENC_ERROR_USER_ABORT: - { - message="user abort"; - break; - } -#endif - default: - { - message="unknown exception"; - break; - } - } - (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError, - (char *) message,"`%s'",image->filename); - } #if defined(MAGICKCORE_WEBPMUX_DELEGATE) { - const StringInfo - *profile; - WebPData - chunk, - image_chunk; - - WebPMux - *mux; - - WebPMuxError - mux_error; - - /* - Set image profiles (if any). - */ - image_chunk.bytes=writer_info.mem; - image_chunk.size=writer_info.size; - mux_error=WEBP_MUX_OK; - (void) memset(&chunk,0,sizeof(chunk)); - mux=WebPMuxNew(); - profile=GetImageProfile(image,"ICC"); - if ((profile != (StringInfo *) NULL) && (mux_error == WEBP_MUX_OK)) - { - chunk.bytes=GetStringInfoDatum(profile); - chunk.size=GetStringInfoLength(profile); - mux_error=WebPMuxSetChunk(mux,"ICCP",&chunk,0); - } - profile=GetImageProfile(image,"EXIF"); - if ((profile != (StringInfo *) NULL) && (mux_error == WEBP_MUX_OK)) - { - chunk.bytes=GetStringInfoDatum(profile); - chunk.size=GetStringInfoLength(profile); - mux_error=WebPMuxSetChunk(mux,"EXIF",&chunk,0); - } - profile=GetImageProfile(image,"XMP"); - if ((profile != (StringInfo *) NULL) && (mux_error == WEBP_MUX_OK)) + webp_data; + + memset(&webp_data,0,sizeof(webp_data)); + if ((image_info->adjoin != MagickFalse) && + (GetPreviousImageInList(image) == (Image *) NULL) && + (GetNextImageInList(image) != (Image *) NULL)) + status=WriteAnimatedWEBPImage(image_info,image,&configure,&webp_data, + exception); + else { - chunk.bytes=GetStringInfoDatum(profile); - chunk.size=GetStringInfoLength(profile); - mux_error=WebPMuxSetChunk(mux,"XMP",&chunk,0); - } - if (mux_error != WEBP_MUX_OK) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"UnableToEncodeImageFile","`%s'",image->filename); - if (chunk.size != 0) - { - WebPData - picture_profiles; - - /* - Replace original container with image profile (if any). - */ - picture_profiles.bytes=writer_info.mem; - picture_profiles.size=writer_info.size; - WebPMuxSetImage(mux,&image_chunk,1); - mux_error=WebPMuxAssemble(mux,&picture_profiles); - WebPMemoryWriterClear(&writer_info); - writer_info.size=picture_profiles.size; - writer_info.mem=(unsigned char *) picture_profiles.bytes; + WebPMemoryWriterInit(&writer); + status=WriteSingleWEBPImage(image_info,image,&configure,&writer, + exception); + if (status == MagickFalse) + WebPMemoryWriterClear(&writer); + else + { + webp_data.bytes=writer.mem; + webp_data.size=writer.size; + } } - WebPMuxDelete(mux); + if (status != MagickFalse) + status=WriteWEBPImageProfile(image,&webp_data,exception); + if (status != MagickFalse) + (void) WriteBlob(image,webp_data.size,webp_data.bytes); + WebPDataClear(&webp_data); } - (void) WriteBlob(image,writer_info.size,writer_info.mem); -#endif - picture.argb=(uint32_t *) NULL; - WebPPictureFree(&picture); -#if defined(MAGICKCORE_WEBPMUX_DELEGATE) - WebPMemoryWriterClear(&writer_info); +#else + WebPMemoryWriterInit(&writer); + status=WriteSingleWEBPImage(image_info,image,&configure,&writer, + exception); + if (status != MagickFalse) + (void) WriteBlob(image,writer.size,writer.mem); + WebPMemoryWriterClear(&writer); #endif (void) CloseBlob(image); - RelinquishVirtualMemory(memory.pixel_info); - return(webp_status == 0 ? MagickFalse : MagickTrue); + return(status); } #endif |