seanooi / iOS-WebP

Google's WebP image format decoder and encoder for iOS
http://seanooi.github.io/iOS-WebP/
MIT License
856 stars 138 forks source link

Image with alpha becomes bluish #2

Closed shmidt closed 10 years ago

shmidt commented 10 years ago

I suddenly found, that there is some problem with alpha, when saving it to webp. I changed your example to demonstrate it.
https://www.dropbox.com/s/bjww7ud4n7qhsgn/iOS-WebP-master-alpha.zip

This is the result of saving webp with transparency: ios simulator screen shot 10 jan 2014 12 54 34

seanooi commented 10 years ago

I just pushed a fix for images with alpha channel transparency. It's not a complete fix yet, but it fixes rendering bluish images.

My use case for encoding/decoding did not include semi transparent images, hence the missing function for it.

Right now there is still a gray background for WebP images when transparency is set which I'm still trying to fix, but if anyone has an idea or solution to it please feel free to let me know.

shmidt commented 10 years ago

@seanooi Great job! Thanks a lot!

leavez commented 10 years ago

The problem is still exist when I resize the image with UIGraphicsGetImageFromCurrentImageContext() before converting to webP.

update: The problem is temporally solved by changing the resizing method ( UIImage -> CIImage -> resized CIImage -> CGImage -> UIImage )

2014-04-23 2 56 54 original image is JPEG, not PNG

skochan commented 10 years ago

I'm getting a bluish color to my images whenever there is a large amount of white text placed on it. Without the white text, there is no color shift. Note that that alpha setting is 1.0. This occurs with lots of different images, not just the sample shown here. On the left is the original, on the right the webP.

screen shot 2014-04-25 at 12 34 10 pm

seanooi commented 10 years ago

Sorry guys, been a little busy at work the past few weeks. @leavez I'll definitely look into your solution @skochan I'm assuming you encoded the image after placing text on the image? And is the text a UILabel?

skochan commented 10 years ago

UPDATE: This is not related to text being composited into the image after all. In fact, here are two images, JPEG and webP. Notice the big color shift. The UIImage that's give to the JPEG and webP compressors is generated from a cocos2D openGL layer that gets rendered into a UIImage. I'm not sure if that's affecting the webP encoder, but as you can see, the color shift is noticeable. Again, If I decompress the JEPG and then recompress with webP, I have no problem.

m4 screen shot 2014-05-01 at 10 42 16 am

weien commented 10 years ago

I was getting this color shift issue, too. Like, @leavez, I was using UIGraphicsGetImageFromCurrentImageContext() to resize/crop. I tried to do like he said and convert to CIImage before converting, but that caused some other issues.

In the end, I went with @skochan's solution. I just had to add the following two lines before [UIImage imageToWebP:...]: NSData* data = UIImageJPEGRepresentation(image, 1); image = [UIImage imageWithData:data];

And my orangey images are back to their orangey goodness. :) Thanks all for this discussion.

newacct commented 9 years ago

It seems that the "fix" of Jan 12, 2014 mentioned above (commit 1664801, "Added function for image with transparency") was for some unexplained reason reverted by a commit on Jan 20, 2014 (commit e72ea1c, "Fixed alpha channel showing dark gray background when alpha is < 1").