ibireme / YYImage

Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.
MIT License
1.77k stars 482 forks source link

Crash on image encoding (WebPPictureImportRGBA) #148

Open DomenicoGonnelli opened 4 years ago

DomenicoGonnelli commented 4 years ago

Hi, I'm using this lib and I have a problem to convert png image on webp. In particular when I try to encode png Data, App crashes on line 1284 if(!WebPPictureImportRGBA(&picture, buffer.data, (int)buffer.rowBytes)) goto fail;

I find a possible solution of problem: analyzing the code I see that variable "lossless" is used to set picture.use_argb, so if you pass NO app crash on png image, if you force YES on YYImageCoder.m - line 2683

CFDataRef frameData = YYCGImageCreateEncodedWebPData(image, YES, _quality, 4, YYImagePresetDefault);

it works.

I suggest to modify the switcher on YYImageCoder (line 2357) in .. case YYImageTypeWebP: { _quality = 0.8; _lossless = YES; } ...

rebeloper commented 4 years ago

Yes, adding _lossless = YES; solved the issue for me 👏 Thanks for the solution