Question about palette shifting

Basically my quesiton is: How do I do it :stuck_out_tongue:

Maybe palette shifting is the wrong phrase, but here is what I’m trying to do:

I have a game where each player controls a sprite. Each sprite has several animations, each animation with several frames. I want each player to have a different “color” of sprite to differentiate between them, but I don’t want to repeat every set of animations with slight color changes in them for every possible color I want. How can I do this, or is reproducing the sprites in different colors the only way?

For example, how does Starcraft achieve the different colors with each unit for each different player? Perhaps Starcraft is a bad example and too complex. If you think back to Diablo I, the boss monsters would have a shifted palette that would give them a different “hue” from all of the other monsters. This effect was basic and crude, but it would work for what I’m doing.

Anyone know what I’m talking about? ^^
I’m using PNG images and loading them into a simple java.awt.image object, if that is of any consequence.

The way the Java2D API is written, makes palette manipulation clumsy & inefficient, and i’m not sure its hardware accelerated even in 5.0 :S

If palette shifting/swapping is absolutely necessary, then I recommend you use a better (for games) API - LWJGL for example.

The only relatively easy way to do it is to make it so the animation frames store information that can be used to create an image from based on a pallette (otherwise known as paint-by-numbers). Basically you need to use some form of collection or array where each element represents a certain coloured pixel of the desired image and where same coloured pixels within the image also have the same number. Once this is done you can use a pallette that assigns colours to particular numbers, then you can generate that particular image from both the pallette and canvas. I can supply some code if wanted…

Why would you want to write by hand a palettized image rendering algorithm when there is one already provided in Java2D =/ (have a look at java.awt.image.BufferedImage and java.awt.image.IndexColorModel)

Anyhow, back to my original statement, the Java2D BufferedImage class prevents you from dynamically changing an images ColorModel.
This means you have to recreate the BufferedImage object each time you want to change the palette. You can reuse the previous images Raster, and simply provide a new ColorModel that contains the revised palette.

However, the biggest limitation is that afaik Java5.0 doesn’t render palettized images directly with hardware. (it simply expands them to a DirectColorModel and stores them in VRAM)
If this is still the case, then performing any palette manipulation is going to prevent hardware acceleration - basically its gonna eat all your bus bandwidth, and reduce your game to a crawl.

[quote]Why would you want to write by hand a palettized image rendering algorithm when there is one already provided in Java2D =/ (have a look at java.awt.image.BufferedImage and java.awt.image.IndexColorModel)

Anyhow, back to my original statement, the Java2D BufferedImage class prevents you from dynamically changing an images ColorModel.
This means you have to recreate the BufferedImage object each time you want to change the palette. You can reuse the previous images Raster, and simply provide a new ColorModel that contains the revised palette.

However, the biggest limitation is that afaik Java5.0 doesn’t render palettized images directly with hardware. (it simply expands them to a DirectColorModel and stores them in VRAM)
If this is still the case, then performing any palette manipulation is going to prevent hardware acceleration - basically its gonna eat all your bus bandwidth, and reduce your game to a crawl.
[/quote]
Wish someone had told me that before i did things, still nevermind… i’m probably better off as i only really use it to store images in txt files and so they can be altered for use in my adventure game engine easily and quickly when different people speak. Plus, it means i can make fonts that can be used in different languages and have many different colours all at once.