YYImage icon indicating copy to clipboard operation
YYImage copied to clipboard

WebP encoding problem of images with certain dimensions?

Open Quentie opened this issue 7 years ago • 7 comments

I try to convert several png images into webp using your nice lib.

I encountered a crash while encoding "wider" images on a real iPad (in my case iPad Mini 2 gen. iOS 10.3) while it is working on the simulator. It does not always crash, but almost always.

Could you please have a look at this one? I tried to find the issue, but was rather unsuccessful :(

Basic code converting a loaded UIImage:

// encoding iPhone.png works but iPad.png crashes
// iPad.png: https://cloud.githubusercontent.com/assets/2254297/25425721/1d132016-2a6d-11e7-974f-03a3a69ade69.png
// iPhone.png: https://cloud.githubusercontent.com/assets/2254297/25425879/ac098972-2a6d-11e7-8057-235014700237.png

UIImage *image = [UIImage imageWithContentsOfFile:@"..."]; 
YYImageEncoder *webPEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeWebP];
webPEncoder.lossless = NO;
webPEncoder.quality = 0.9;
[webPEncoder addImage:image duration:0];

// Encoding crashes on real device for the iPad.png image, but works fine for iPhone.png
// crashes in line 1284 of YYImageCoder.m with EXC_BAD_ACCESS
// if(!WebPPictureImportRGBA(&picture, buffer.data, (int)buffer.rowBytes)) goto fail;
NSData *data = [webPEncoder encode]; 

Quentie avatar Apr 26 '17 08:04 Quentie

  • https://github.com/ibireme/YYImage/pull/79 I gave it a shot and it seems to work for me (not sure if it is nice though as it does not use YYCGImageDecodeToBitmapBufferWith32BitFormat(…) ).

Quentie avatar Apr 28 '17 12:04 Quentie

@Quentie Sorry to bother. It's this CGImageGetDataProvider() always get the actual CGImageRef bitmap or sometimes failed? And how to get the RGBA/ARGB buffer through some params ? I currently draw CGImageRef on an extra CGBitmapContext(with my prefered alphaInfo) and retrieve. It's this an waste ?

dreampiggy avatar Aug 07 '17 19:08 dreampiggy

@dreampiggy You do not bother at all. Actually it is very likely that my pull request is not very good, and should be replaced with another one of someone who really understands this code ;)

But this quick hotfix so far seems to work for me and I did not get any crashes any longer while encoding webP images (Actually not true I still got several crashes on iOS 9 but none on iOS 10 and iOS 11 Beta. I did not further investigate these crashes, as my app is iOS10+ anyways).

It's this CGImageGetDataProvider() always get the actual CGImageRef bitmap or sometimes failed

=> Hm as I did not see any crashes in my beta app I guess it works (at least for iOS 10+ not sure about older iOS as I have not tested it)

And how to get the RGBA/ARGB buffer through some params ? I currently draw CGImageRef on an extra CGBitmapContext(with my preferred alphaInfo) and retrieve. It's this an waste ?

=> Most likely this is a huge waste and could/should probably done a lot better! Sorry if this pull request is not really good enough to be merged, but I thought I'll do one anyway to maybe help point into the right direction ...

Quentie avatar Aug 08 '17 07:08 Quentie

Has anybody found a solution to this? It seems like it's still present and I noticed that the same image will work sometimes and crash sometimes.

MarsVard avatar Nov 10 '18 07:11 MarsVard

For me it only works with PNG file smaller than 100KB. I'm working on PNGs of 350KB :(

DanielZanchi avatar Nov 13 '18 12:11 DanielZanchi

free(webPImageData); there are crash app

monang1611 avatar Nov 28 '18 11:11 monang1611

It is also crashing for me. Do you guys any other libs that can be used to convert to webP?

gholias avatar Dec 04 '18 22:12 gholias