Mail Archives: djgpp/1997/07/27/19:18:59
Andrew Cheyne <006809c AT news DOT acadiau DOT ca> wrote in article
<33d76086 DOT 0 AT 131 DOT 162 DOT 2 DOT 91>...
> I am currently developing some sprites for a game I am writing
> and am wondering how to manage the palette so that they can
> all be shown at the same time as I designed them. How do I get
> a constant palette with my sprites? I am creating the sprites in
> POVRay and doing touch up with PAintShop Pro. I have thought of a
> couple of solutions to keep a constant palette between sprites,
> but they either seem like a lot of overhead or dont produce the effects
> I'm looking for. Someone suggested taking all my sprites and
> pasting them into a true color image in PAintShop and then reducing
> the color depth to 256. This works fine to get the sprites using the
> same palette and I can even get a palette file from this, but where do
> I go from there?
This is a good idea. It will get you a single palette that is weighted
according
to the colours most frequently used in your images.
>Do I have to cut and paste my sprites out of this
> one large image to smaller images? If so, will they retain the
> palette I extracted from the larger image?
You could do this but it would be time consuming. Instead I suggest
that you save the palette from the combined image. Then load the
palette into your individual images using the Load Palette option under
the Colours menu and choosing either 'nearest index' or 'error diffusion
dithering' (you decide which looks best - I think that 'nearest index' will
look best for small sprites). This should have the same effect as cutting
and pasting from the big picture but it might be a bit quicker.
You could automate the process by writing a small program using
allegro to do the conversion.
Here's a simple algorithm for finding the nearest colour.
best_guess = very_big_number
for each pixel
for each palette_index
error = (pixel.red-palette.red)^2
+ (pixel.green-palette.green)^2
+(pixel.blue-palette.blue)^2
if error < best_guess
best_guess = error
best_index[pixel] = palette_index
- Raw text -