Closed shmidt closed 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.
@seanooi Great job! Thanks a lot!
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 )
original image is JPEG, not PNG
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.

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
?
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.
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.
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").
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: