![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
Masked blit..Filtering black background, not pink? |
Dean Thomas
Member #3,801
August 2003
|
Hey people. Just curious, is it possible to filter out the black background, rather than the pink one RGB(255, 0, 255) on a sprite/bmp. Thanks. Dean. |
Billybob
Member #3,136
January 2003
|
errr, I think they only thing you can do is go into the Allegro source and change the defines for the mask color... MASK_COLOR, MASK_COLOR_15, etc... EDIT:
|
Dean Thomas
Member #3,801
August 2003
|
bah, thats long, i just finished compiling Alleg 4.1.11 I'm dumb!. Oh well, Thanks.. |
Steve Terry
Member #1,989
March 2002
![]() |
Ah just fire up paint and recolor all your sprites with magic pink ___________________________________ |
Evert
Member #794
November 2000
![]() |
Quote: Just curious, is it possible to filter out the black background, rather than the pink one RGB(255, 0, 255) on a sprite/bmp.
Go over the sprite when you load it and change any pixel you want to have masked to magic pink. |
axilmar
Member #1,204
April 2001
|
Shouldn't the transparent color be the same for all color depths ? either bright pink (since it is considered not very useful) or total black (0, 0, 0). If it was bright pink for 8 bit modes, I would hardcoded in palette index 255. I would prefer it to be black of course. And I would use (0, 0, 1) for black, which is undetectable anyway that it has a very little bit of blue in there. (Of course a better solution would be to have a bit mask, with set bits for opaque pixels and zeroed bits for transparent pixels). |
X-G
Member #856
December 2000
![]() |
In paletted modes, palette index zero is transparent. This is usually black, but technically that's coincidental. -- |
Evert
Member #794
November 2000
![]() |
Quote: Shouldn't the transparent color be the same for all color depths ? either bright pink (since it is considered not very useful) or total black (0, 0, 0).
You can't do that. 8 bpp is a paletted mode, and whatever colour corresponds to the mask colour you pick is unknown until you search the palette. Moreover, it's not even guarenteed to be there. Forcing people to include magic pink into their palette is a bad idea. Magic pink is a good choice in high/true colour modes because it's such an ugly colour noone would ever want to use it for anything else. Black is a bad choice because you would want to use it from time to time. You yourself mentioned that already: Quote: And I would use (0, 0, 1) for black, which is undetectable anyway that it has a very little bit of blue in there. Never assume. It might map to (0,0,0) on some machines, making it true black. Even if it doesn't though, do you picture yourself finding the stray (0,0,1) pixels in a sea of (0,0,0) pixels in your favorite paint program? Quote: (Of course a better solution would be to have a bit mask, with set bits for opaque pixels and zeroed bits for transparent pixels). You could use the alpha channel for this too. And on a final note, Quote: In paletted modes, palette index zero is transparent. This is usually black, but technically that's coincidental.
Yes, I always set colour 0 to magic pink in 8 bit mode - makes it easier to convert graphics and is easier to spot than black. In fact, I already did this years before I started to use Allegro. |
axilmar
Member #1,204
April 2001
|
Quote: You can't do that. 8 bpp is a paletted mode, and whatever colour corresponds to the mask colour you pick is unknown until you search the palette It can always be hardcoded at index 255, just like black is hardcoded at index 0. Quote: Forcing people to include magic pink into their palette is a bad idea It's just one less color. It's not a big deal. It will not spoil graphics, since they would only use 8-bit colors anyway. Quote: Even if it doesn't though, do you picture yourself finding the stray (0,0,1) pixels in a sea of (0,0,0) pixels in your favorite paint program? I didn't think of that, to tell you the truth. You are right, it would be a pain in the butt. But, as it is right now, wouldn't you do it for 8-bit graphics anyway ? What I do is draw my graphics using bright pink for transparent areas, and use a very dark blue (0, 0, 1) for the black colors. Then, when I finish, I pass all the bitmaps through an app that converts the bright pink to black (color index 0). Quote: You could use the alpha channel for this too If the bitmap has an alpha channel. What if it doesn't ? bitmasks are an established way to provide transparency. Quote: The only caveat is that you need to manually set it to something different (black, preferably) because the outline of the screen has the same colour (and you don't want to look at a screen with a magic pink border. You honestly don't). That's why it should have been hardcoded at palette index 255. It's one of the little problems Allegro has, that 8-bit graphics should be different than other color depth graphics, due to magic pink in high color modes and palette index 0 for 8-bit modes. It would have been much nicer to use color index 255, hardcoded to bright pink. Anyway, in this day and era who is using 8 bit color depth ? |
Evert
Member #794
November 2000
![]() |
Quote: It can always be hardcoded at index 255, just like black is hardcoded at index 0. You can't hardcode palette entries. And palette index 0 isn't nescessarily black. Wether you pick 0 or 255 is, from the user perspective, unimportant. It is important for the inline assembler version though, since you can do a rep movsb when you want to break at index 0, but need to manually check against other values. Quote: It's just one less color. It's not a big deal. It will not spoil graphics, since they would only use 8-bit colors anyway. You don't know that. 256 colours is pretty constrained, and someone may need all of them. Quote: What I do is draw my graphics using bright pink for transparent areas, and use a very dark blue (0, 0, 1) for the black colors. Then, when I finish, I pass all the bitmaps through an app that converts the bright pink to black (color index 0). Any particular reason you're not changing palette index 0 to magic pink? I did mention this is what I do, right? Quote: That's why it should have been hardcoded at palette index 255.
Quote: It's one of the little problems Allegro has, that 8-bit graphics should be different than other color depth graphics, due to magic pink in high color modes and palette index 0 for 8-bit modes. It would have been much nicer to use color index 255, hardcoded to bright pink. Allegro has problems, and that's not one of them. If you hardcode index 255 to bright pink in Allegro, you suddenly find yourself unable to reliably load arbitrary bitmaps. Which is a bad idea. Allegro has no fore-knowledge on what the palette looks like and should not force something like that on the user. Without for knowledge, you can't say `ok, we'll use magic pink in 8 bit mode too' and expect to end up with a decently optimized library. Quote: If the bitmap has an alpha channel. What if it doesn't ? bitmasks are an established way to provide transparency.
Obviously, but whereas Allegro doesn't support bitmasks as such, it does support alpha channels. So my suggestion was to load the bitmask into the bitmaps alpha cahnnel and use the alpha-blended drawing mode. If that's what you want. I' Quote: Anyway, in this day and era who is using 8 bit color depth ? |
gillius
Member #119
April 2000
|
Everything Evert says is right. Gillius |
axilmar
Member #1,204
April 2001
|
Quote: You can't hardcode palette entries. And palette index 0 isn't nescessarily black. Wether you pick 0 or 255 is, from the user perspective, unimportant. It is important for the inline assembler version though, since you can do a rep movsb when you want to break at index 0, but need to manually check against other values It could have been done as for the other color depths. It's exactly the same. Quote: You don't know that. 256 colours is pretty constrained, and someone may need all of them Exactly. Since it's pretty constrained, one less color would not hurt anyone. It's more important to have the same bitmaps for any color depth than to loose one color entry in the 8-bit depth. Quote: Any particular reason you're not changing palette index 0 to magic pink? I did mention this is what I do, right? You said it yourself: the ugly pink border. I use Deluxe Paint for Dos to draw stuff, as I find it much better than other apps for this type of drawing. It also introduces an ugly pink border in games. Quote: As I said above, using 0 is natural when you look at a possible optimized implementation. But 16 and 32 bit loops could also have been optimized in the same way. REP MOVSW, REP MOVSD (or with REPE/REPZ) works the same as REP MOVSB. So, black should have been the preferred magic color for 16/32 bit pixel values. Is the logic inconsistent here, or am I missing something ? Quote: Allegro has problems, and that's not one of them. It is for me. In my gui lib, I tried to make a Cursor class which encapsulated the cursor bitmap, but since 8-bit images need to be separate from true color, it needed two images. I always had to synchronize the images pixel by pixel. I wanted the same cursor to be usable in any color depth. And another problem: providing support for 8-bit color depths in game. You need two sets of graphics, one with black as the magic value and one with bright pink. Quote: If you hardcode index 255 to bright pink in Allegro, you suddenly find yourself unable to reliably load arbitrary bitmaps. Not if index 255 was preagreed to contain the magic value. Quote: Which is a bad idea. Allegro has no fore-knowledge on what the palette looks like and should not force something like that on the user. I don't find it a big deal. So what, index 255 is used for transparencies. That's ok, as long as I don't have to use two sets of images. Pardon my ignorance, but from this discussion I understand that the only reason bright pink is not used in 8-bit modes is the REP MOVSB loop. Isn't REP MOVS used in 16/32 bits ? Quote: Obviously, but whereas Allegro doesn't support bitmasks as such Maybe it should. Quote: it does support alpha channels. So my suggestion was to load the bitmask into the bitmaps alpha cahnnel and use the alpha-blended drawing mode. If that's what you want I don't want to do translucency, I am only speaking about "show-through" bitmaps. Quote: Everything Evert says is right Any relation to the Pope, maybe ?;D |
gnolam
Member #2,030
March 2002
![]() |
Quote: You said it yourself: the ugly pink border. I use Deluxe Paint for Dos to draw stuff, as I find it much better than other apps for this type of drawing. It also introduces an ugly pink border in games.
The fix for this is a single line of code in your program -- |
X-G
Member #856
December 2000
![]() |
Quote: And another problem: providing support for 8-bit color depths in game. You need two sets of graphics, one with black as the magic value and one with bright pink. Allegro can color convert and preserve transparency for you. Quote: I don't want to do translucency, I am only speaking about "show-through" bitmaps. Ever heard of 1-bit alpha channels? -- |
axilmar
Member #1,204
April 2001
|
Quote:
The fix for this is a single line of code in your program
Quote: Allegro can color convert and preserve transparency for you Unfortunately, it does not. Maybe I am doing something wrong, therefore I post the source code, bitmap to show and the screenshot jpeg to prove that Allegro does not convert bright pink to black in 8 bit mode. Quote: Ever heard of 1-bit alpha channels? Does the 16-bit pixel format leave room for 1-bit alpha ? Nope (its 556). |
gnolam
Member #2,030
March 2002
![]() |
Add the line [EDIT] -- |
X-G
Member #856
December 2000
![]() |
Quote: Does the 16-bit pixel format leave room for 1-bit alpha ? Nope (its 556). 16-bit can be 565 (pretty much defacto), 556, or 5551. All formats are possible, although I don't know to what extent allegro supports them. -- |
Richard Phipps
Member #1,632
November 2001
![]() |
The only disadvantage of using colour 0 is it's also the border colour. But IMO that's an acceptable trade-off for slightly faster blitting. also, there is no need to have two images as previously said. Just colour convert the images. |
Irrelevant
Member #2,382
May 2002
![]() |
Quote: It could have been done as for the other color depths. It's exactly the same. No it isn't. The other depths aren't paletted. Quote: Since it's pretty constrained, one less color would not hurt anyone.
The lynched hamster swings both ways, I'm afraid. Quote: Not if index 255 was preagreed to contain the magic value. Oh right, so we'll just get everyone in the world who uses 256 color bitmaps to change their palette to keep you happy? Better get started then. It may take a while to convince people that they've been wrong since the birth of 8 bit. I'm afraid you're going to need some bigger boots. Think about this from our point of view: There are many people here who have used Allegro for years. Some have even written parts of it. They all find it perfectly reasonable, because they understand better how it works. Then, someone, with an apparently much shallower understanding of graphics and the innards of Allegro, decides that they want it done their way. And then they start using words like 'should', and suddenly has the community against them. The sources are over here. Feel free to modify them yourself. <code>//----------------//</code>Here be l33tsp33x0rz. |
axilmar
Member #1,204
April 2001
|
Quote: Add the line set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS); Why should I do that ? the Allegro help says explicitely that: "The default mode is total conversion" So I shouldn't set any flags. Quote: 16-bit can be 565 (pretty much defacto), 556, or 5551 5551 is 15 bit, leaving one bit for alpha. Just like 32 bit is RRGGBBAA. Quote: The only disadvantage of using colour 0 is it's also the border colour. But IMO that's an acceptable trade-off for slightly faster blitting Now that the little Allegro help inconsistency is solved (where it says the default color conversion is total conversion, but I have to manually specify COLORCONV_KEEP_TRANS), I don't care if 8-bit is using color 0, because my problem is solved. No one has still explained why using color 0 permits faster blitting. I will have to search the Allegro sources. But since I know 80x86 assembly, I see no difference in using REP MOVSB and REP MOVSW, for example. Its the CX counter that is decremented, and the MOVS instruction does not do any comparison, as far as I know (it's not that the blit will stop as if using SCANS). Quote: No it isn't. The other depths aren't paletted But using color 0 is just an agreement also between us users of the library. Quote: Really, I find your logic rather backwards here If you take my statement as discrete algebra, then you are right. But, practically, it does not make any difference to the graphics designer, because it leaves 255 colors to use. Quote: Why, does everyone use color 0 for transparencies ? Look at it this way, and you might understand it: if I have color 0 (which is 99% black, due to border issues), then I need another color for black, right ? this means two things: 1) one less color nevertheless, since color 0 is for transparencies and must stay black. That means 255 colors in this case also. 2) another color used for blackness means problems when drawing. I have to know by memory which pixel is black-transparent and which pixel is black-opaque. By using another color index for transparency, I would still have 255 colors available, but I would not have problem 2. And I would use the black color both for the border and the game's sprites. Quote: I'm afraid you're going to need some bigger boots Now that I explained it to you, I hope you understand it. If you don't, I will explained to you further. Quote: There are many people here who have used Allegro for years What makes you think I am not using Allegro for years ? my first game (and only so far!!! shame on me!!) was a Tetris game written with Allegro in 1996!!! (God damn, so many years have passed already ?) Quote: They all find it perfectly reasonable, because they understand better how it works. Good for them. I must be of inferior I.Q. not to understand the greatness of having two black colors in the same palette.;D Quote: , someone, with an apparently much shallower understanding of graphics and the innards of Allegro Sure buddy, whatever you say. Quote: decides that they want it done their way.And then they start using words like 'should', and suddenly has the community against them It's a free country, and I am free to express my opinions as I see fit. You can't judge me, since you don't know me, and surely you were not invited to play the devil's advocate. |
Richard Phipps
Member #1,632
November 2001
![]() |
Quote: 2) another color used for blackness means problems when drawing. I have to know by memory which pixel is black-transparent and which pixel is black-opaque.
No. As has already been said you just change what ever colour value you picked for palette entry 0 to black in your program. I tend to pick a darkish blue personally. |
Bob
Free Market Evangelist
September 2000
![]() |
Quote: No one has still explained why using color 0 permits faster blitting. Easy: /* Color 0 is the mask */ movb (%esi), %al; jz no_write; movb %al, %(edi); no_write: /* Color 34 is the mask */ movb (%esi), %al; cmpb $34, %al je no_write; movb %al, %(edi); no_write: See, one more instruction. -- |
X-G
Member #856
December 2000
![]() |
Quote: 5551 is 15 bit, leaving one bit for alpha. Just like 32 bit is RRGGBBAA.
By your logic 8888 would be 24-bit mode leaving 8 bits for alpha. -- |
spellcaster
Member #1,493
September 2001
![]() |
Quote: Why should I do that ? the Allegro help says explicitely that: "The default mode is total conversion" So I shouldn't set any flags.
I'd say you should ignore any advice given to you. It doesn'tz matter if it works... The point is, if you check the flags given to set_color_converions(), you'll see that there's one more flag besides COLOR_CONV_TOTAL... Quote: 5551 Ok let's see... 5+5+5+1 = ? Quote: Why, does everyone use color 0 for transparencies ?
Using an index doesn't force anybody to change the colors... it's not that hard Quote: What makes you think I am not using Allegro for years ?
Now, that is a tough one -- |
axilmar
Member #1,204
April 2001
|
Quote: No. As has already been said you just change what ever colour value you picked for palette entry 0 to black in your program. I tend to pick a darkish blue personally But I want color 0 to be black while I am drawing, since I am using some DOS full screen application for drawing (Deluxe Paint). You still loose one color, either way. Quote:
Easy:
1) According to the MOV documentation, the MOV instruction does not affect any flags. So I fail to see that the code you posted does the job you are saying. orb %al, %al;
preceeds the jz no_write;
Maybe you forgot it ? 3) Would n't it be faster to CMP with BL, for example, instead of an immediate value ? I know that Bob knows the instruction timings, and I have read somewhere that using the AL register is faster than using any other register. Maybe this is the reason (using OR instead of CMP). Is this the reason ? 2) If MOV affected the Z flag, why this trick is not used in the other color depths ? it would speed them up. Quote: By your logic 8888 would be 24-bit mode leaving 8 bits for alpha Isn't it so for the 32-bit pixel format ? |
|
1
2
|