Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » graphic formats

This thread is locked; no one can reply to it. rss feed Print
graphic formats
thats me
Member #5,501
February 2005

Hello, I would like to use 32 bit images in my program using the alpha value (ARGB) but I'm not sure how could it be done. First I need an image format, which supports 32 bit interface (bmp doesn't). Second, I need a library to load images of this type and convert them to BITMAP * . Finally, I do not know how to work with these images (blit(), makecol(), put/getpixel()...). Could someone help me? :(

X-G
Member #856
December 2000
avatar

TGA is your friend. Allegro supports it natively.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Elias
Member #358
May 2000

A better format is PNG, which is supported through an addon. To use the alpha channel, look at the set_alpha_blender and draw_trans_sprite functions. Also, investigate if the AllegroGL or OpenLayer addons are useful to what you want to do - they can use alpha blitting with HW acceleration.

--
"Either help out or stop whining" - Evert

A J
Member #3,025
December 2002
avatar

PNG is good for Alpha channel support.
althou im not sure how you go about getpixel() when it returns a signed int

___________________________
The more you talk, the more AJ is right. - ML

Elias
Member #358
May 2000

[To mods: can you delete this message and move the thread away from the dev forum?]

--
"Either help out or stop whining" - Evert

Peter Wang
Member #23
April 2000

Quote:

althou im not sure how you go about getpixel() when it returns a signed int

32 bits is 32 bits, no matter if you decide to interpret it as signed or unsigned for some operations.

thats me
Member #5,501
February 2005

The case is as follows: I have a 24 bitmap and another greyscale bitmap, which could be interpreted as alpha equivalent of the same picture. If I could do a program that combines both of this images (the output can be TGA or whatever) and afterwards use the combined image in my program...
If anyone has a tip how to do that and has time for lamers :), please share it. I'm going to read all the blender stuff in the docs and if I have further problems I would ask again. Thanks.

Elias
Member #358
May 2000

You can do it e.g. in Gimp. Add an alpha channel, select the channel, paste the grayscale into it, then save again.

Or you can do it in Allegro, something like:

set_colorconv_mode(COLORCONV_NONE);
bmp24 = load_bitmap("24bit.bmp", NULL);
PALETTE pal;
alpha8 = load_bitmap("8bit.bmp", pal);
select_palette(pal);
BITMAP *bmp32 = create_bitmap_ex(32, w, h);
for(y = 0; y < h; y++) for(x = 0; x < w; x++) {
    c = getpixel(bmp24, x, y);
    r/g/b = getr/g/b24(c);
    a = getpixel(bmp8, x, y);
    r = getr8(a); // assuming, r/g/b is the same in the grayscale..
    putpixel(bmp32, makeacol32(r, g, b, a);
}

The code is apparently only pseudo-code, but basically, you can create a 32-bit bitmap with alpha channel using putpixel.

--
"Either help out or stop whining" - Evert

gnolam
Member #2,030
March 2002
avatar

Quote:

The case is as follows: I have a 24 bitmap and another greyscale bitmap, which could be interpreted as alpha equivalent of the same picture. If I could do a program that combines both of this images (the output can be TGA or whatever) and afterwards use the combined image in my program...
If anyone has a tip how to do that and has time for lamers :), please share it. I'm going to read all the blender stuff in the docs and if I have further problems I would ask again. Thanks.

Check the manual entry for set_write_alpha_blender()and do exactly what it says. :)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Go to: