|
pixel format |
William Labbett
Member #4,486
March 2004
|
Quote:
ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA - Let the driver choose a 32 bit format with alpha. When using ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA I suppose when writing to a locked bitmap - the effects will depend on whether ARGB or BGRA was chosen ? Is this correct ? ...and if so is there a way to get the pixel format chosen ? Would it be a good idea to write to the data of an ALLEGRO_BITMAP by taking this into account ? - ie is it just a plain bad idea or is it okay because it means portability is enhanced ? Would be grateful for some guidance here.
|
Trent Gamblin
Member #261
April 2000
|
ALLEGRO_LOCKED_REGION has a format variable that will tell you the format. You have several options: 1) Easiest but not optimally quick. Pass whatever format you want to al_lock_bitmap and the data will be in that format. 2) Pass ALLEGRO_PIXEL_FORMAT_ANY and it will automatically choose the format that the bitmap data is already stored in. Faster because there is no conversion. As for how to read/write the different formats, every pixel format in Allegro specifies in its name the order of the bits/bytes such that the most significant bits are mentioned first. Example: ARGB_8888 means each component is 8 bits, therefore the whole thing is 32 bits, and would fit in an int like this: 0xAARRGGBB. So to create a pixel out of 4 bytes for example you would do pixel = b | (g << 8) | (r << 16) | (a << 24);. The problem you might encounter is that some machines may use big endian byte ordering but that's rare. So even though 'A' comes first, if you were writing a byte at a time into the locked region data buffer, on little endian machines you need to write the 'B' byte, then the 'G' byte etc. This leads to unportable code, and that's why the pixel format RGBA_8888_LE was created. With that format, you should always write the bytes out in little endian (the LE stands for it) despite the byte order of the machine. So if you're using OpenGL, RGBA_8888_LE is a good choice for bitmaps. If you're also using d3d, well, it only runs on little endian hardware anyway, but you'll have to pick something else like ARGB_8888 when using it.
|
William Labbett
Member #4,486
March 2004
|
Thanks for all that Trent. If I was to use ALLEGRO_PIXEL_FORMAT_ANY for al_lock_bitmap - I would get the format To know that could I call al_get_new_bitmap_format() ? If I'd used al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA); previously, would al_get_new_bitmap_format() return ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA or would it be a specific one like ALLEGRO_PIXEL_FORMAT_****_8888?
|
Trent Gamblin
Member #261
April 2000
|
To get the format before locking, use al_get_bitmap_format(bmp), after locking use int format = locked_region->format.
|
William Labbett
Member #4,486
March 2004
|
Brilliant. Thanks again.
|
|