Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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 1394 times)
0 Members and 1 Guest are viewing this topic.
Offline weevil

Senior Newbie





« Posted 2007-12-17 11: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
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)

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 Member





« Reply #1 - Posted 2007-12-18 00: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 @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #2 - Posted 2007-12-18 01: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.

Thanks,
  Dmitri
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 13:55:33 »

I've mailed you an isolated test case Dmitri.

Thanks for your time Smiley
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


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

I've mailed you an isolated test case Dmitri.

Thanks for your time Smiley
[/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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (42 views)
2013-05-17 21:29:12

alaslipknot (51 views)
2013-05-16 21:24:48

gouessej (79 views)
2013-05-16 00:53:38

gouessej (79 views)
2013-05-16 00:17:58

theagentd (88 views)
2013-05-15 15:01:13

theagentd (81 views)
2013-05-15 15:00:54

StreetDoggy (123 views)
2013-05-14 15:56:26

kutucuk (147 views)
2013-05-12 17:10:36

kutucuk (147 views)
2013-05-12 15:36:09

UnluckyDevil (157 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.097 seconds with 20 queries.