Hi !
Featured games (86)
games approved by the League of Dukes
Games in Showcase (649)
Games in Android Showcase (181)
games submitted by our members
Games in WIP (699)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Graphics.drawImage() composite problems  (Read 1856 times)
0 Members and 1 Guest are viewing this topic.
Offline weevil

Senior Newbie

« Posted 2007-12-17 10:25:26 »

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
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)

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 Smiley
Offline broumbroum

Junior Devvie

« Reply #1 - Posted 2007-12-17 23:10:36 »

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. Cheesy

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @
on /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline trembovetski

Senior Devvie

If only I knew what I'm talking about!

« Reply #2 - Posted 2007-12-18 00:23:03 »

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.

Java2D Team
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline weevil

Senior Newbie

« Reply #3 - Posted 2007-12-18 12:55:33 »

I've mailed you an isolated test case Dmitri.

Thanks for your time Smiley
Offline trembovetski

Senior Devvie

If only I knew what I'm talking about!

« Reply #4 - Posted 2007-12-22 19:42:38 »

I've mailed you an isolated test case Dmitri.

Thanks for your time Smiley

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!

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

KaiHH (62 views)
2016-01-31 23:15:29

sci4me (91 views)
2016-01-23 21:47:05

sci4me (77 views)
2016-01-23 21:46:58

KaiHH (110 views)
2016-01-19 13:26:42

theagentd (191 views)
2016-01-05 17:10:00

ClaasJG (210 views)
2016-01-03 16:58:36

chrisdalke (199 views)
2015-12-28 06:31:21

Guerra2442 (228 views)
2015-12-25 03:42:55

Guerra2442 (225 views)
2015-12-25 03:27:21

theagentd (261 views)
2015-12-21 14:43:24
List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!