[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi,
I've hit a problem when dealing with how to pass colors to Allegro
functions.
Ideally, we'd like to support:
- Depths of more then 32bpp
- Alternative color spaces (YUV)
The current way to pass colors in Allegro is via an int parameter to its
functions, which is built via make[a]col().
putpixel(bmp, x, y, makecol(r, g, b));
However, if we want to support depths larger than 32 bpp, we can't pass
that value as a 32-bit int (obviously).
We could encode the information inside a struct, and pass its pointer to
functions that require color values.
This would look something like:
AL_COLOR color;
al_map_rgba_b(bmp, &color, r, g, b, a);
al_put_pixel(bmp, x, y, &color);
or:
AL_COLOR color;
al_put_pixel(bmp, x, y, al_map_rgba_b(bmp, &color, r, g, b, a));
al_map_rgba_b would then take the RGBA components and form the
corresponding color adapted to the bitmap 'bmp', and place the result
inside the 'color' struct. A pointer to that color struct is then passed
back to put_pixel().
Neither form is very pretty. However, we keep virtually the same
efficiency as we used to have with Allegro 4. The structure AL_COLOR can
then defined to be a 128 bit quantity (for up to floating point RGBA
components), which is adapted to the destination bitmap format.
If we ever need to use more bits, we can simply extend the structure
without having to change the API.
An other alternative is to have the current color as a state, much like
OpenGL:
al_set_rgba_b(r, g, b, a);
al_put_pixel(bmp, x, y);
or:
al_set_color_b(AL_RGBA, r, g, b, a);
al_put_pixel(bmp, x, y);
This is far less efficient, since there will be color conversion going
on for every call to put_pixel. It also uglyfies Allegro (IMHO) and
makes it fall even deeper in the state-based API realm. However, this
construct would allow to support any combination of bit depth and color
spaces, as those would just add entry points (or #defines) to Allegro.
Thoughts? Comments? Flames?