![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
Masked blit..Filtering black background, not pink? |
spellcaster
Member #1,493
September 2001
![]() |
Quote: By your logic 8888 would be 24-bit mode leaving 8 bits for alpha
Quote: Isn't it so for the 32-bit pixel format ?
That's the point. For the 32bit pixel format. Not for the 24bit mode. -- |
X-G
Member #856
December 2000
![]() |
Quote: Isn't it so for the 32-bit pixel format ?
Yes, and 5551 is indeed a 16-bit pixel format, NOT a 15-bit pixel format. As Lenny said - 5 + 5 + 5 + 1 = ..? -- |
axilmar
Member #1,204
April 2001
|
Quote:
That's the point. For the 32bit pixel format. Not for the 24bit mode.
Quote: Yes, and 5551 is indeed a 16-bit pixel format, NOT a 15-bit pixel format Certainly, but not all color depths leave room for alpha blending bits. So doing masking by alpha blending is not a solution for every color depth, as it was previously suggested. |
X-G
Member #856
December 2000
![]() |
You can still pack an 1-bit color mask separately from your color data without problems. -- |
Bob
Free Market Evangelist
September 2000
![]() |
Quote: the MOV instruction does not affect any flags. Ahh, right. Sorry, I got mixed up with HC12 (another brain-dead ISA). In any case, there are other reasons why 0 is used: Quote: 3) Would n't it be faster to CMP with BL, for example, instead of an immediate value ? There are no free registers. Quote: 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 ? Using %eax (%al too?) as a register makes the code one byte smaller in most cases. This saves decode bandwidth and icache. Quote: 2) If MOV affected the Z flag, why this trick is not used in the other color depths ? it would speed them up.
Because you'd like your black to be black, and not dark blue -- |
axilmar
Member #1,204
April 2001
|
Thanks for the explanation, Bob. A final question: You are saying that the Allegro blit routines already use 8 registers. In the case of 15/16/24/32 bits, where is the magic pink value stored at ? Quote: Because you'd like your black to be black, and not dark blue Check out the simple image I am posting. Half of it is pure black (RGB = 0, 0, 0) and the other half is RGB=0, 0, 1. Can you tell which half is the pure black by simply looking at it ? I can't. |
Evert
Member #794
November 2000
![]() |
Quote: It could have been done as for the other color depths. It's exactly the same. No, it's not, because you don't know in advance that there even is a value corresponding to magic pink in the palette (and let's not get started again on how everyone should just agree to set colour 255 to magic pink. We both know that that is nonsense). 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. Ok, in that case, you can always set colour 0 to magic pink when you safe and something different (dark blue is easy on the eyes and easy to distinguish from other colours) while you work. You could also look into programs that allow you to change the border colour, but I don't know if the state is persistent between videomode changes and if it even works on modern hardware (if it's VGA compatible, it probably should - but you never know). Quote: 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 ? I had the recollection of rep movsb (rep movs really) breaking when either CX (or ECX) hits 0, or AL (or AX or EAX) becomes 0. Seems like I remembered incorrectly based on the link you posted, though Sun's reference is less clear. I'll dig up some old code when I get home and see how I used to do this in the past, but for now it seems my memory was incorrect. 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. Please, palette manipulations aren't that hard... taking a little time to think about it should convince you that that isn't true (you might want to use two sets of graphics, one which is hand-optimized for low colourdepths, but you don't have to). Quote: Not if index 255 was preagreed to contain the magic value. Obviously. But it wasn't, so there. Quote: I don't find it a big deal. So what, index 255 is used for transparencies. Same could be said for index 0... Quote: I don't want to do translucency, I am only speaking about "show-through" bitmaps. Apart from 1bit alpha channels which have already been mentioned, there's noone forcing you to use intermediate alpha values. Just make areas completely transparent or completely opaque. Quote: 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),
The docs says it converts colours, not that it preserves transparency. No inconsistency. If you set palette index 0 to magic pink, you don't need COLORCONV_KEEP_TRANS. Quote: Why, does everyone use color 0 for transparencies ? I always have (which is partially why I remember that being easy to optimize for). Quote: if I have color 0 (which is 99% black, due to border issues), then I need another color for black, right ? Not every sprite needs to be drawn transparently. Using pure black in sprites can often even be a bad idea (I don't have the pixel-artist tutorial where it's explained handy right now, but the bottom line is that black is very dominant). Quote: In the case of 15/16/24/32 bits, where is the magic pink value stored at ? I haven't checked, but I suspect it's not stored at all, but hardcoded. That's faster and easier to implement. If it were stored in a register, it would be trivial to make it possible to change the mask colour in Allegro, simply by changing a a variable. Since I know it's not that simple, by reverse logic (;)), it's not done in this way. |
spellcaster
Member #1,493
September 2001
![]() |
If you work for TV Screens, no value should go below 32/32/32 or above 248/248/248. Quote: If it were stored in a register, it would be trivial to make it possible to change the mask colour in Allegro, simply by changing a a variable
In fact, setting the mask color works nicely for the directX driver -- |
Bob
Free Market Evangelist
September 2000
![]() |
Quote: In the case of 15/16/24/32 bits, where is the magic pink value stored at ? It's an inlined constant. Quote: Check out the simple image I am posting. Half of it is pure black (RGB = 0, 0, 0) and the other half is RGB=0, 0, 1. Can you tell which half is the pure black by simply looking at it ? If I pump up the brightness, then yes. Black has the neat property of black times anything == black. This is something important when blending or performing other non-trivial operations on your pixels. -- |
axilmar
Member #1,204
April 2001
|
If I pump up the brightness, then yes. Black has the neat property of black times anything == black First of all, I tried with 100% brightness and I could not spot the difference. Honestly. And I tried both CRT and TFT monitors. Secondly, no one has 100% brightness all the time. Anyway, it does not matter. All I wanted to say is that if I would make the decision, I would prefer the API to be consistent and then fast, rather the other way around. I see many people tricked with the transparent graphics in 8-bit mode, and there always the issues about the drawing tools. |
Evert
Member #794
November 2000
![]() |
Quote: First of all, I tried with 100% brightness and I could not spot the difference That's not what he meant. If you increase the brighness of the image by a factor of 10, you'll see the difference. Quote: All I wanted to say is that if I would make the decision, I would prefer the API to be consistent Have you even listened to what has been posted above? There is a fundamental difference at the hardware level between 8 bit colour mode and higher colourdepths. There is no inconsistency in the API, since you're dealing with different things. Quote: I see many people tricked with the transparent graphics in 8-bit mode With 8 bit graphics becoming dated, I suspect many people are unfamiliar with palettes. This is the main cause for confusion in 8 bit modes. |
axilmar
Member #1,204
April 2001
|
Quote: We both know that that is nonsense But right now we have all agreed (or rather forced) to use palette entry 0 for transparency, because Allegro does it like this. There would be no difference if entry 255 was used. Quote: but I don't know if the state is persistent between videomode changes and if it even works on modern hardware (if it's VGA compatible, it probably should - but you never know). Aside from hardware problems, it's not good to change the dark blue to bright pink when you save (assuming you meant 'save' instead of 'safe'), because usually graphics are retouched after the first test. Quote: I'll dig up some old code when I get home and see how I used to do this in the past, but for now it seems my memory was incorrect The Z flag is set only from within comparison instructions, i.e. SCANS etc. The MOV instruction does not affect any flag. Quote: Please, palette manipulations aren't that hard... But why should I have to do that ? libraries are here to help the programmer. Less effort = more (programming) happiness Quote: Obviously. But it wasn't, so there It should have been though. Quote: Same could be said for index 0... But you loose one more entry, since in all cases an opaque black would be needed, too. Quote: Apart from 1bit alpha channels which have already been mentioned But how do I do that in, let's say, 16 bits, where all bits are occupied by color information ? Furthermore, isn't alpha transparency much slower, especially when reading from the video ram ? Quote: Not every sprite needs to be drawn transparently Sure. Out of the 100% of the sprites, only rectangular tiles need to be opaque. That may be 10%. All the other sprites are usually non-rectangular. Quote: I haven't checked, but I suspect it's not stored at all, but hardcoded. That's faster and easier to implement But Bob said: Quote: For hard-coded values, you lose flexibility, and you increase the code size. Code size might have an effect on speed (icache misses / decode bandwidth). So, he is saying that hardcoded values are slower, and you are saying that is faster. I think Bob got it right. Quote: The docs says it converts colours, not that it preserves transparency But the operation of turning one transparent pixel to another is a ...conversion. And when I hear "total conversion", transparency conversion is included. It does not say explicitely "only for opaque pixels". Furthermore, the COLORCONV_KEEP_TRANS flag is presented in the same list as the other flags. Finally, it should be included as default in COLORCONV_TOTAL: why would not I want transparency to be kept ? Quote: It's an inlined constant That means it's hardcoded. What would be the benefit if it was done as in 8-bits ? Wouldn't that benefit justify the use of 0 as the transparent color ? Quote: Black has the neat property of black times anything == black. This is something important when blending Not really. Blending white on black with half translucency results in a nice grey. Blending a white on RGB(0, 0, 1) results in a nice grey also, which is indistinguishable from the previous one. Only XOR produces vastly different colors, I think. Quote: That's not what he meant. If you increase the brighness of the image by a factor of 10, you'll see the difference How's that irrelevant to a game ? Quote: With 8 bit graphics becoming dated, I suspect many people are unfamiliar with palettes. This is the main cause for confusion in 8 bit modes Hey, in the same line of thought, we all learned how to use DOS, right ? even if it was not the best system around. That something can people learn how to use is no excuse for its quality(look at Win32, for example). |
Richard Phipps
Member #1,632
November 2001
![]() |
Sorry Axilmar, you have some good points, but I also don't think you are listening.. You said: Quote: But right now we have all agreed (or rather forced) to use palette entry 0 for transparency, because Allegro does it like this. There would be no difference if entry 255 was used. Bob earlier said: Quote: In any case, there are other reasons why 0 is used: so there is a reason why 0 is used rather than another value.. So that's your first question answered. Quote: Aside from hardware problems, it's not good to change the dark blue to bright pink when you save (assuming you meant 'save' instead of 'safe'), because usually graphics are retouched after the first test. I take it that you are refering to drawing images with a distracting bright pink background. Earlier I said that you only change the colour to bright pink in your program, not the saved image file. You can always restore it to resave an image. Quote:
Quote: -------------------------------------------------------------------------------- But why should I have to do that ? libraries are here to help the programmer. Less effort = more (programming) happiness It seems that you want to treat a paletted graphics mode as a truecolour one. The two modes are fundamentally different and should not be treated the same. Otherwise people would be forced to have an entry in their palette for magic pink. This would mean that the blitting routines would have to either check through each of the 256 palette entries to find the colour or use a look up table. If it was using a look up table then the routine would be comparing against another variable which is slower. So we wouldhave to hardcode a palette entry to be transparant. If we used 255 it would still be slower than using 0 due to Bob's explanation. Quote: Blending a white on RGB(0, 0, 1) results in a nice grey also, which is indistinguishable from the previous one. . Due to the VGA hardware used for palette modes, each colour channel only can go from 0-63 rather than 0-255. So 0,0,1 would become 0,0,4 which is just enough to be visible in some situations. Bright pink would suffer the same problem, but it's a colour least likely to be found in nature and other art due to it's extreme vividness. So from a speed perspective index 0 is better. |
Plucky
Member #1,346
May 2001
![]() |
Quote: Not really. Blending white on black with half translucency results in a nice grey. Blending a white on RGB(0, 0, 1) results in a nice grey also You only described one kind of blending. How about multiplication blending, additive blending, screen blending, dodge blending, etc.? |
Tobias Dammers
Member #2,604
August 2002
![]() |
There are, actually, several 32-bit formats, as there are several 16-bit formats. Saying "32 bits" doesn't say anything about the format except that each pixel uses 32 bits of memory. The point is, allegro uses only a few of these:
(the "real" 16 bit mode)
But there is no reason why one couldn't write their own routines that use other color formats. OpenGL, for once, knows a lot more formats, like GL_RGBA4, with 4 bytes for each component. Allegro can easily produce this kind of bitmaps, you only need to make your own blender functions. --- |
Evert
Member #794
November 2000
![]() |
Quote: There would be no difference if entry 255 was used. Right. As I said, from the user's point of view, they're equally arbitrary. I take it than that we agree on this issue? Quote: Aside from hardware problems, it's not good to change the dark blue to bright pink when you save because usually graphics are retouched after the first test. So change it back when you edit? Quote: It should have been though.
You do realize that you're effectively saying that everyone should have been forced to set palette index 255 to magic pink since the day the first VGA card was produced, right? Because that is what I mean if I say that it wasn't agreed from the beginning that colour 255 should be magic pink. Quote: But how do I do that in, let's say, 16 bits, where all bits are occupied by color information? I only ever used alpha blending in 32 bit images, so I can't say for sure. However, I think Allegro supports a 16 bit format that has an alpha layer of 1 pixel. Not sure though - it may depend on the hardware. Quote: Furthermore, isn't alpha transparency much slower, especially when reading from the video ram ?
Yes, except possibly if it were to be hardware accelerated. AFAIK, Allegro never accelerates alpha blending though... Quote: So, he is saying that hardcoded values are slower, and you are saying that is faster. I think Bob got it right.
Hardcoding the value saves the (small) time needed to load it from memory. It also saves a register, which you already don't have in abundance. So I'd say that having values hardcoded is faster than reading them from a variable in memory. I haven't benchmarked this, but in this case, I'm not taking Bob's word for it. Quote: But the operation of turning one transparent pixel to another is a ...conversion. Sure. It's just not a colour conversion. Quote: And when I hear "total conversion", transparency conversion is included. Hmm... ok, I see how that can be misleading. It's only an issue when converting between paletted graphics and non-paletted graphics, which is probably why it's not in there. But I understand you point here. Quote: How's that irrelevant to a game ? Assuming you meant relevant instead of irrelevant Quote: Hey, in the same line of thought, we all learned how to use DOS, right ? even if it was not the best system around. That something can people learn how to use is no excuse for its quality(look at Win32, for example). I wasn't arguing that people would be unable to understand palettes. People have done it in the past, so there's no reason they couldn't now. But in the past, palettes were part of the way the computer worked, something you simply had to learn if you wanted to do anything with computer graphics. Today, with everyone running graphical shells in high or true colours, palettes are far less noticable and obvious to newbies. |
Richard Phipps
Member #1,632
November 2001
![]() |
Must be catching.. Evert didn't you read my response? You already said the same for some of his questions as I did.. |
Evert
Member #794
November 2000
![]() |
Quote: Must be catching.. Evert didn't you read my response?
Yes, I did. |
|
1
2
|