Premultiplication problem on iOS using SDL_Image |
Premultiplication problem on iOS using SDL_Image |
Jeffrey Carpenter
Guest
|
Hi there,
Ow, your problem sounds a lot awfully like a known issue, see "Perhaps again? Pixel bug in Mac OS X” at https://forums.libsdl.org/viewtopic.php?t=10013&sid=34e8ef7cf74074039495037c1a077025 for the ugly details — applies to iOS, too, AFAIK. Try the workaround that is mentioned in the thread to help confirm if this is indeed the same issue. If it turns out that it is the same issue, you might consider doing what I have, and rebuild SDL_image with the libpng & friends backends instead. Cheers, Jeffrey Carpenter |
|||||||||||
|
Premultiplication problem on iOS using SDL_Image |
i8degrees
|
Hello,
Have you figured out the problem yet? I’m curious if the issue turned out to be related to the problem I mentioned. If it was, a patch I wrote concerning the issue might be of interest to you — https://bugzilla.libsdl.org/show_bug.cgi?id=2788 I’d love to know if it resolves your problem ... Cheers, Jeffrey Carpenter |
|||||||||||
|
ollika
|
Oh, sorry for not responding earlier. I thought I would be getting notifications for my own posts by default.
However, I think I have a different problem than describe in the issue. Loading works well enough in normal cases when I use premultiplied alpha. I don't need the colors to be perfect, so it doesn't really matter to me if the colors might be off by one bit. However I was getting massive loss of precision with the specific scenario where the image is not premultiplied and have alpha channel has values near to zero. As I understand SDL_Image is currently "undoing" the premultiply that is done by the Apple API (when loading png images at least) by defining something like rgb = (loaded_RGB * 255 / loaded_alpha). The problem I was having is that if my RGBA value is e.g. (245, 235, 255, 1), it is being premultiplied to something like (1,1,1,1). Then when loading the image, SDL tries to undo the premultiply with something like RGB = (1, 1, 1) * 255 / 1 = (255, 255, 255) -> So my color basically turned to white and I'm losing almost all precision. Like I said, the first problem was iOS packaging doing the premultiply for my png images, but that can be easily disabled. After hours of investigation, going through apple documentation and poking the SDL_Image source, I concluded that Apple is doing the premultiply anyway on load time if the image is not already premultiplied. Loading nonpremultiplied images using the apple's own image loading API is either not possible or very hard (I could not figure out how to do it. I have very little experience with objective-C or cocoa so I might be wrong). Finally after so much frustration with a stupid issue like this, I just went with a totally different implementation for the effect that I need that does not need nonpremultiplied images at all. |
|||||||||||
|