Color Masking

Hello!!
I was wondering if there was a way I could do this: Take a BufferedImage and mask it according to the colors on another BufferedImage.

For instance:
public void colorMask(BufferedImage ImageToBeMasked, BufferedImage ColorMask, RGBA);

So if I have an image that looks like

http://members.gamedev.net/hops/Pics/Java_Tactics_Java2D/screenshot_25.png

I can just mask the colors that I want on an image the same size…

Is this possible???

Any code or ideas would be great.

yup, just write your own class that extends from java.awt.image.RGBImageFilter and the rest is easy.

Okay some problems… how to you use the filter??

Also, this seems to be only for filtering one image…

http://members.gamedev.net/hops/Pics/forum_examples/example_01.png

http://members.gamedev.net/hops/Pics/forum_examples/example_02.png

http://members.gamedev.net/hops/Pics/forum_examples/example_03.png

My goal is to use this with sprite rendering so that I don’t have to render the entire background each frame. So my solution is to create the BufferedImage ColorMask (the third one) and mask the areas of the sprite that shouldn’t be drawn.

In this case I want to mask out the red and the blue but in the sprite graphic.

So maybe the way to do this would be to take the BufferedImage ColorMask, and filter the bad colors to black, and all others to white and then make it a bitmask for the sprite…

The thing is that I have never used a flilter or bitmask before, so I have no idea what I’m doing :frowning:

While looking around on the net I can’t find a good tutorial on the filter or bitmasks, or how to convert a black and white image into a bitmask…

any help?

Well, Im not sure we talk about the same thing but here is my tip. AlphaCompositeMaskTest program masks the original image with the given text.

Its not a direct answer, but maybe you understand this better and see whether its what you are looking for.

http://koti.mbnet.fi/akini/java/png/alphatest/

Your screencaptures looked nice. Are you going to update the scene one colored stripe at a time. You rerender only stripes where moving sprites overlap stripes (current stripe and one or more upper stripes)?

Graphics2D has clip(Shape) method. Shape can be a polygon so can create non-rectangle clips. I dont know whether it boost rendering if you set a polygon clip to stripes you should update and then simple draw everything. Most areas are clipped out, so in theory drawing api could run faster.

My goal is to use this with sprite rendering so that I don’t
have to render the entire background each frame.

Use dirty rects then.

However, even drawing the whole background shoudn’t be a huge drag. If the tiles are stored in compatible/bitmasked images you can achieve a pretty high framerate (on old hardware).

Fiddling around with obscure color masked images will be most likely slower.

I have a 2D array: Tile[][] tiles = new Tile[height][width];
A tile objects holds the reference to the graphic, the number of blocks high, and a reference to the vert (an object that shows the vertical graphics). To draw the Map I do something like this:


for (int y = 0; y<MAXHEIGHT; y++) {
   for (int x = 0; x<MAXWIDTH;  x++) {
      drawTile(getTile(x,y);
      if (getTile(x,y).hasSprite())
         drawSprite(getTile(x,y).getSprite());
   }
}

I do that loop every frame…

I like the idea of having a polygon shape and then clip witht that… thanks for the info!