Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » a bug RLE sprites

This thread is locked; no one can reply to it. rss feed Print
a bug RLE sprites
Milan Mimica
Member #3,877
September 2003
avatar

There is a bug somewhere in RLE sprite code because draw_trans_sprite() and draw_trans_rle_sprite() do not display the same image, when the RLE sprite and the plain sprite are of the same contens.

Attached is a test program that shows the difference: the magenta color is not displayed but it should.

X-G
Member #856
December 2000
avatar

Actually, attached is a TGA, which is (believe it or not) an even worse web format than BMP. Try again.

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

Evert
Member #794
November 2000
avatar

Show code. I'm willing to bet there's a colour conversion happening somewhere.

Milan Mimica
Member #3,877
September 2003
avatar

I attached a wrong file, sorry. Corrected now.

edit:
So is it a bug? If you admit it is, I'll see if I can fix it ;)

GullRaDriel
Member #3,861
September 2003
avatar

Milan Mimica's test code:

1#include <allegro.h>
2 
3int main()
4{
5 int y, x;
6 
7 allegro_init();
8 install_keyboard();
9 set_color_depth(32);
10 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
11
12 for (y = 0; y < SCREEN_H; y += 20) {
13 for (x = 0; x < SCREEN_W; x += 20) {
14 int sx = (x / 20) & 1;
15 int sy = (y / 20) & 1;
16 float c = sx ^ sy;
17 rectfill(screen, x, y, x+19, y+19, c*makecol(255, 255, 255));
18 }
19 }
20 
21 BITMAP *bmp = load_bitmap("test.tga", NULL);
22 RLE_SPRITE *rle = get_rle_sprite(bmp);
23 set_alpha_blender();
24 
25 draw_trans_rle_sprite(screen, rle, 0, 0);
26 draw_trans_sprite(screen, bmp, 0, bmp->h);
27 
28 readkey();
29 
30 return 0;
31}

Screenshot of the program:
{"name":"591274","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/c\/7c42c56e9998d6f691999bc465b23d14.png","w":646,"h":505,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/c\/7c42c56e9998d6f691999bc465b23d14"}591274

Source Image:
{"name":"591275","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/f\/cfaa158f7725b7c98c20a0629cf3af69.png","w":320,"h":200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/f\/cfaa158f7725b7c98c20a0629cf3af69"}591275

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Evert
Member #794
November 2000
avatar

Quote:

So is it a bug?

It can't literally be , since I know from my own code that using a BITMAP or an RLE sprite created from that bitmap do actually produce the same result when normally drawn. You should have mentioned you were using alpha channels though (or maybe I should have read your original post a bit more carefully and inferred it from there)!

When you construct the RLE sprite, it throws away the magic pink parts irrespective of the alpha value there (the docs are actually outdated in this respect because they say that "repeated zero pixels are replaced by a single length count"). When you then activate the alpha blender and draw the sprite, it will only look at the alpha value for the parts that it has retained - it cannot draw parts of the image it has thrown away. In other words, the image shows the expected behavior for the RLE sprite.
The normal bitmap is another matter. It is clear from that image that it only looks at the alpha value to determine transparency. This is in contradiction with the draw_trans_sprite() documentation, which states

Quote:

As draw_sprite() this function skips transparent pixels.

For the alpha-blending mode, however, "transparency" is only determined by the alpha value (as per http://www.allegro.cc/manual/set_alpha_blender), so this is probably actually the intended behavior for alpha blending.

If anything, this is a bug in draw_trans_sprite(), not in the RLE sprite code. However, I think this more reflects a difference between RLE sprites and "normal" sprites than a bug in the code. You may argue that RLE sprites created after enabling the alpha blending mode should skip pixels that are invisible according to the alpha value rather than the mask colour (maybe it actually does this, but I don't think so), but I personally feel this makes things much more complicated for little gain. I don't think you have a case for RLE sprites created before enabling the alpha blender. I think the current behavior is actually consistent with the documentation, but the documentation doesn't make this clear enough. In other words, I think the documentation should be clarified rather than the code changed. Feel free to argue this point though.

One other thing: I vaguely recall something like this being discussed on AD at some point in the past few years. You may want to see if anything like that turns up in the archive (I can probably do that more easily from my local mailbox at home than through the SF archive, but I won't be able to do that for a couple of days at least).

Go to: