Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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 1633 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
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 Duke





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

Senior Duke




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.

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 12:55:33 »

I've mailed you an isolated test case Dmitri.

Thanks for your time Smiley
Offline trembovetski

Senior Duke




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
[/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.

 

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

The first screenshot will be displayed as a thumbnail.

theagentd (5 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!