• Post Reply Bookmark Topic Watch Topic
  • New Topic

Blending image colors into another color  RSS feed

 
Magnus Gunnarsson
Greenhorn
Posts: 10
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello my name is magnus, and i wanna begin with saying im new in this forum, so i apologize if i break some rule or posted in the wrong sub forum thank you for understanding

at the moment im making an application in java (SE 8) the application uses paintComponent to draw subimages of the transparant font file (mage below)



it then draws on the screen (image below) in colors



now.. theres nothing specifically wrong with my code, HOWEVER to change color on the fonts (from white to X color), im going through an incredibly SLOW method, and this litteraly takes paintComponent 200 to 400 ms, which as you might guess.. is the reason why im here, the current code im using to draw the entire screen is


my parameters is the bufferedImage and a color, either Color.COLOR or new Color()

and what i'd like is a speeded up alternative to change all the white pixels on the image to the specified colors, my java teacher told me something about palette swapping, however i dont find much about that on google
any help would be greatly appreciated

thank you.

~ Magnus
 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is why switch at all? The map you present seems like it is not very large, so why not offer a limited color choice and have each map already colored?

As an alternate thought, why not color each of the characters before it is rendered rather than doing the entire map?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Magnus Gunnarsson wrote:my java teacher told me something about palette swapping, however i dont find much about that on google

I don't either, but Graphics#setXORMode(...) may be a close fit.
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Magnus,

a couple of years ago I rewrote an old Basic program in Java. That program was about a lot of cirkels
growing in size and melting into one another. I did that by constantly changing the color palette . That
was very easy to do in that Basic. In this topic:

http://www.coderanch.com/t/652409/GUI/java/Circle-Oval-increase-size-timer#3015749

you can see what I was after, although in that demo the cirkels do overlap.

In Java, it was much harder. The only way I managed was by using BufferedImages of
TYPE_BYTE_INDEXED and a suitable colormodel. Unfortunately, it looks like the colormodel
of a BI is immutable. So, to get the effect of palette changes, I needed to create multiple BI's.

Have a look at the following demo.

In this demo, I create a normal type_argb BI, and I draw filled cirkels into it. Then I create
a BI of type byte_indexed, with 1 bit per pixel, and two colors: a transparant color and a
second color. Next I draw my normal argb_BI into it, forcing all the colored pixels to get a
pixel value of 1 in my byte_indexed BI.

After that, I constantly create a new BI, again type_indexed, only with the color that I want,
and I copy the raster of my current indexed BI into this. Then I paint this new index BI into my panel.
I guess this sounds a lot more complex than it is. You could do the same, by creating a
type_byte_indexed BI, the same size as your font-image, and then following the strategy that I used.

Is there any particular reason why you write strings in this very complex way?

Here is the demo code.

Greetz,
Piet

 
Magnus Gunnarsson
Greenhorn
Posts: 10
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan, this is gonna be a library and thus i want asmuch features as possible, including all 16mil colors
Piet Souris, yeah it looks incredibly complex, the reason i write strings like this is because i wanna have.. kinda a tileset font that can be very easily exchanged into another less or more graphical font, its kinda the whole idea with this ^^

i decided to maybe just save all tiles, for example when drawing a .. green T, it would be saved in a hashmao, this.. slow yeah, but it appered to work fairly well

but Piet Souris, i'll definetly look into your example! i appreciate everyones help greatly

thank you
- magnus
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!