Graphics.drawImage() composite problems

I’m trying to render anti aliased text to an offscreen buffer for caching purposes, but I’m having a little trouble rendering the cached text back to the screen. I’m drawing the strings onto a BufferedImage using the pixel format BufferedImage.TYPE_INT_ARGB and the composite function AlphaComposite.Src

When sampling my offscreen buffer I can see the pixel are stored with premultiplied alpha for some reason. That is, a semi transparent white pixel is stored as 0x7F7F7F7F instead of 0x7FFFFFFF. So my brain tells me that I should use the AlphaComposite.SrcOver composite when drawing this offscreen buffer onto another graphics object, but when doing so I get really poor results. I just can’t understand what’s going wrong. For instance if I draw my offscreen buffer onto a completely white graphics object i get gray edges where anti aliasing occurs. How can this be?? With AlphaComposite.SrcOver I should be getting a completely white surface.

JavaDoc from AlphaComposite.SrcOver

[quote]The source is composited over the destination (Porter-Duff Source Over Destination rule).

Fs = 1 and Fd = (1-As), thus:

    Ar = As + Ad*(1-As)
    Cr = Cs + Cd*(1-As)

[/quote]
So let’s try a semi transparent white pixel on top of a white pixel using this formula:

Ar = 0.5 + 1.0 * (1.0 - 0.5) = 0.5 + 0.5 = 1.0
Cr = (0.5, 0.5, 0.5) + (1.0, 1.0, 1.0) * (1.0 - 0.5) = (0.5, 0.5, 0.5) + (0.5, 0.5, 0.5) = (1.0, 1.0, 1.0)

So why am I seeing gray pixels ?

My conclusion: awt’s implementation of AlphaComposite.SrcOver is not functioning properly :slight_smile:

I never used the AlphaComposite for antialiasing, this is JAI rendering hints that are in charge of the rendering aliasing and dithering. If you’ve ever used JAI, the GraphicsJAI wrapper class can be set up the RenderingHints to use at rendering time. :smiley:

Hello weevil,

Could you please post a test case or send it to me (tdv at sun dot com). This may indeed be a bug.

Thanks,
Dmitri
Java2D Team

I’ve mailed you an isolated test case Dmitri.

Thanks for your time :slight_smile:

[quote=“weevil,post:4,topic:31118”]
I’ve mailed you an isolated test case Dmitri.

Thanks for your time :slight_smile:
[/quote

Thanks a lot, I have received the test and forwarded it to the engineer
who wanted to take a look at it. Unfortunately we’re all on vacation now
so you might not get an answer this year =(

Happy Holidays anyway!

Dmitri