Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
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  
  Matte around text?  (Read 2168 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Posted 2010-01-21 09:35:57 »

Hi!

I have a problem I haven't managed to get my head around, nor has Google provided any useful help.

What I am trying to do is to somehow define or apply a matte for translucent pixels.

So that any pixels that aren't opaque will be get a opaque background color.

Here are two comparisons. The above image has translucent pixels (which I don't want) and the below image has white matte:



I was thinking about going through all the pixels, doing some color calculations. Isn't there a better way?

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #1 - Posted 2010-01-21 09:59:37 »

You could do it with 2 text render passes couldn't you?
First pass using your matte colour, with anti-aliasing off, so every touched pixel gets full colour.
Second pass using text colour, with anti-aliasing on.

Wanting to do this just seems so wrong; though i'm sure you have a legitimate reason =)

:edit:

Oh hang on, with anti-aliasing off different pixels will be touched....
Perhaps for the matte pass you can get what you want by using one of the more exotic alpha composites?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline pjt33
« Reply #2 - Posted 2010-01-21 11:48:50 »

What precisely is the use-case? If you're drawing monochrome onto a transparent background, as in your example image, then you could do it with IndexedColorModel (possibly using two models for the same raster: draw with a model which has no transparency and then use the raster with a model which has the 0 value as fully transparent).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #3 - Posted 2010-01-21 12:44:08 »

The use case... hm.. you'll find it strange.

I'm dynamically generating a png image, that will be displayed in a web browser of a set-top-box. This browser does not support translucent png images, only bitmask images (1 or 0 transparency). It can display translucent png images, but will convert any translucent pixels to a default matte color. I want to define my own matte color, so the image appears right on a background of the same color.

I think I'll just add the matte color to any translucent pixels, seems like the most straightforward trick.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Nate

JGO Kernel


Medals: 147
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2010-01-21 22:16:10 »

Just fill the background with a solid color before drawing your text, no transparency. If you placed the matte text over anything but a solid color, it would look like crap anyway.

Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #5 - Posted 2010-01-22 00:34:04 »

On 2nd look, it appears to be dead simple - embarrisingly so....

1) Make sure you image you are drawing onto only has 1 bit transparency, and starts off initialised to clear+transparent.
1  
getGraphicsConfiguration.createCompatibleImage(width,height,Transparency.BITMASK);

worked for me.
Though i'm sure one of BufferedImage's more complex constructors could do it too.
2) Don't forget to turn on the text anti-alias hint.
Then, draw the text in 2 passes as I mentioned before.

3) First pass, draw with your matte colour, any pixels touched will be turned from 0x00000000, to 0xFFrrggbb. (where rrggbb is your matte colour).
4) Second pass, draw with your text colour, the pixels touched will already contain 0xFFrrggbb and so will be replaced with the desired matte/colour blend -  according to the alpha values generated by the anti-aliasing text rasterizer.

No need to mess around with AlphaComposites at all!

:edit:

Nvm, doesn't work due to the rounding ^_^
When drawing the matte, pixels are only touched with an alpha >127.
I'm sure it's possible & simple to fix though...

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #6 - Posted 2010-01-22 10:02:53 »

Just fill the background with a solid color before drawing your text, no transparency. If you placed the matte text over anything but a solid color, it would look like crap anyway.

That I cannot do. If I could, I wouldn't need to ask about it.

In any case, the text gets placed on top of a video stream, and a translucent solid color. So, it does matter!

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline pjt33
« Reply #7 - Posted 2010-01-22 10:41:45 »

I'm sure it's possible & simple to fix though...
I think it should be doable by writing your own ColorModel...

Or how about BandCombineOp on an alpha-premultiplied image, assuming that it clips the results to range? Haven't tested it, but it might work. r' = r + r0(255 - alpha) where r0 is from the matte colour, alpha' = 255 alpha. Doesn't work. It doesn't clip the results to range.
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.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!