Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Transparent pixels causes darkening?
- - By Aaron Date 2011-10-22 17:35
I am programming my game in Ruby. I have an icon with a transparent glow effect. However, the transparent parts of the icon darken the colours behind them instead of blend with them.

As a comparison, here's what it looks like when I past the icon over the screenshot in Photoshop, with the blending that I intended.

As far as I can tell, alpha blending is controlled by the mode parameter in Image::draw. The only modes I'm aware of (since the modes aren't actually listed in the documentation) are :default and :additive. Additive won't work for me since it applies to the whole image instead of just its transparent pixels, rendering the image too bright at best, rendering the image semi-transparent at worst.

Is there anything I can do to fix how transparent pixels in an image are drawn?
Parent - - By Spooner Date 2011-10-22 18:25
There is also :multiply mode (or is it :multiplicative ? I can never remember).

It does seem most likely that there might be an issue with the image of the sword itself, rather than an issue with Gosu. I have had no problems doing the same thing with semi-transparent images in Gosu.
Parent - - By Aaron Date 2011-10-22 19:53
I've verified that it's :multiply mode. Except that it messes up the icon.

How would I tell if the problem is with the image itself? All of my images are PNGs, either exported from Inkscape or created in Photoshop (not The Gimp).
Parent - - By Spooner Date 2011-10-22 21:04
That looks like it is operating correctly for multiply mode though (as was your description of additive making it too bright). The default (which is standard "alpha blending") is what you want; still no idea why it isn't working for you.

I exported all my pngs from The Gimp, but no reason other PNGs would be different or fail in that odd way. Maybe upload the image here or else wait for jlnr (the author) to offer an opinion?
Parent - - By Aaron Date 2011-10-22 21:13
OK, I've attached the icon image.

To be honest, the darkening seems to be happening with all images that have transparencies in them. It's just most noticeable in the glowing sword icon.

I'm developing this on Mac OS X 10.6.8. One thing I've done a lot is opening PNGs created with Photoshop in Preview and re-saving them, because Preview tends to make the file sizes smaller than Photoshop.
Parent - - By Maverick Date 2011-10-23 00:51
"One thing I've done a lot is opening PNGs created with Photoshop in Preview and re-saving them, because Preview tends to make the file sizes smaller than Photoshop."

Have you tried not doing that?
Parent - By Aaron Date 2011-10-23 01:42
I just tried re-saving the sword icon in Photoshop without converting it in Preview. The glow effect is still dark.

I also tried re-exporting the icon directly from Inkscape without modifying it afterwards, but that still had no effect.
Parent - - By jlnr (dev) Date 2011-10-23 15:25
I had trouble with Photoshop exporting alpha channels before, but never had it go darker. Does it maybe add some weird background matte color again? What dialog are you using for exporting, how does it look in that dialog? Have you embedded it in a simple HTML container to compare Gosu with web browsers? If your browser renders it the same, it's a Photoshop problem that should be easier to google than Gosu problems. :)
Parent - - By Aaron Date 2011-10-23 17:09
I haven't noticed a background matte colour, just some darkening in pixels that have a transparency but aren't completely transparent.

The blending seems to work fine in an HTML document, at least in Chrome.

When I save it from Photoshop I just choose "PNG" as the file type (using CS3) and choose no interlacing. I have RGB colour and 8 bits/channel set. When I export it from Inkscape I just use the default export settings for PNGs.

You can check out my project and see if you notice the darkening when you run it on your own computer.
Parent - By jlnr (dev) Date 2011-10-24 09:04
Wow, if Chrome and Gosu disagree then the problem might indeed be with Gosu.

I also use CS3, but I always Save for Web because it disables most of the fancy stuff. Have you tried that dialog?

BTW, what exact OS are you on?
Parent - - By jlnr (dev) Date 2011-10-24 10:51
I tried to run your project, but I was missing priority_queue; I installed the gem but it crashed as soon as I clicked the screen:

./graph.rb:24:in dijkstra_search': undefined method []=' for #<PriorityQueue:0x1027c8668 @queues={}> (NoMethodError)

I think you should consider using Bundler. As much as I hate the whole infrastructure, it's still the best way to manage your dependencies :/
Parent - By Spooner Date 2011-10-24 14:33
I'll second bundler. Hard to live without it unless you are only distributing executables.
Parent - - By Aaron Date 2011-10-24 21:17
I'm using the PriorityQueue gem from (which, incidentally, seems to be down right now). I installed it with gem install PriorityQueue. Of course, if priority_queue is a better alternative I can switch to that. I'll clean up my packaging when I'm ready to start showing my project to a wider audience.

I tried using Save for Web & Devices in Photoshop, selecting PNG-24 as the image type (PNG-8 put a white background on the glow effect). I still got a darkening effect. There's also the fact that the darkening happens to unedited images exported from Inkscape.

I'm running Mac OS X 10.6.8 on an iMac, with an ATI Radeon HD 4850.

As an aside, here's a screenshot of what the icon looks like in Chrome, with a gradient background.
Parent - By jlnr (dev) Date 2011-10-25 07:05 Edited 2011-10-25 08:37
Reproduced it here. I think this is some issue with premultiplied vs non-premultiplied alpha. When I load your PNG into a Gosu::Image and download it again (using #to_blob/OpenGL), I can see that the color values have been premultiplied.

Now to check this out on Windows to see if this is an error with OS X image loading. o_O
Parent - By jlnr (dev) Date 2011-10-25 08:51
Confirmed as a bug on OS X. This is weird- I was using Gosu quite often in the last days and it never occured to me. But I had darker backgrounds and sharper alpha borders. :)
Parent - - By jlnr (dev) Date 2011-10-25 12:03
Fixed in git, just ignore it for now. And thanks for reporting of course!
Parent - By Aaron Date 2011-10-25 20:51
No problem. Glad I could help. :)

Good luck on the next release and on Gosu in general.
Parent - By erisdiscord Date 2011-10-23 19:41
As a sort of workaround, you might export the glow and the icon as separate tiles, then draw the icon normally and draw the glow additively.
Up Topic Gosu / Gosu Exchange / Transparent pixels causes darkening?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill