[AD] 8-bit palette support for A5

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Prompted by this thread http://www.allegro.cc/forums/thread/607425 I
played a bit with palette support and made two patches:


index.diff.gz:

This adds a new pixel format to Allegro called
ALLEGRO_PIXEL_FORMAT_LUMINANCE_8 and a new bitmap flag called
ALLEGRO_KEEP_INDEX.

ALLEGRO_PIXEL_FORMAT_LUMINANCE_8 would be our first 8-bit format. The
OpenGL driver sets it to GL_LUMINANCE which means r/g/b/a is set to
x/x/x/1 with x the 8-bit value in the texture. DirectX is not
implemented yet.

Color converters simply use the red value when converting to LUMINANCE_8
and when converting from it set r/g/b to the 8-bit value and alpha to 1.
The idea is that you would not usually use color conversion on such
bitmaps so that should be good enough.

ALLEGRO_KEEP_INDEX makes the .pcx and .bmp loaders use the palette index
of the loaded bitmap as pixel data if the image file contains palette
indices. The flag is ignored otherwise. Any palette data in the file are
also ignored.


ex_palette.diff.gz:

This is an example using the above patch to use a shader like in the
allegro.cc thread to do some palette cycling on the included
alexlogo.bmp.


There's still some issues, but I'm not sure when I can work on them so
if we want this for 5.2 maybe can apply the patch anyway. Issues are:

- DirectX (I'd fix that before applying, DirectX should have some format
similar to GL_LUMINANCE hopefully)

- Formats other than .bmp and .pcx. Could be a lot of work, e.g. to
support .png need three versions, one using libpng, one GDIPlus, one the
native OSX loader. And not sure how easy it is to get index/palette
information out of any of those.

- Support for loading the palette information. With the KEEP_INDEX flag
it would make a lot of sense to also load the palette contained in the
bitmap. Very easy to add implementation-wise, just need an API how to
get the palette. Probably something like al_load_bitmap_ex_f() with an
out parameter for the palette.

- Better color conversion for LUMINANCE_8. E.g. OpenGL allows specifying
a weight for r/g/b and does a weighted addition of the components when
converting from RGB to GL_LUMINANCE. Probably even less important than
all of the palette stuff.

-- 
Elias Pschernig <elias.pschernig@xxxxxxxxxx>

Attachment: ex_palette.diff.gz
Description: GNU Zip compressed data

Attachment: index.diff.gz
Description: GNU Zip compressed data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/