gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Color index conversion

#19649 - CyberSlag5k - Fri Apr 23, 2004 3:45 am

I am attempting to add transparency to my sprites. I know that pallete[0] is always transparent. I figure I'll just set that to some obscure color that I will have my artist use as the transparent color. My problem is, however, converting the RGB channels to the 0xXXXX format. What do those 4 X's represent? Analyzing colors in photoshop yeilds 6 of them, so white in photoshop is FFFFF but FFFF is light blue (I'm assuming the missing digits just go to 0). So how can I convert the color I want from RGB to that 0xXXXX format (and also, what's a better name than "that 0xXXXX format?).

Thanks!
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#19652 - sajiimori - Fri Apr 23, 2004 4:02 am

Many graphics applications use 24-bit RGB colors, where the red, green, and blue channels each get a byte, in that order.

GBA uses 15-bit BGR encoding for colors, where blue, green, and red each get 5 bits, in that order.

The X's you were talking about represent hexidecimal digits. You need 2 hex digits to represent a byte. So, 3 bytes for 24-bit color means 6 hex digits.

GBA colors waste a bit because the 15-bit values are rounded up to an even 16, so we have colors that are 2 bytes long which needs 4 hex digits.

As you've probably figured out by now, to convert from 24-bit RGB to 15-bit BGR, you drop the low 3 bits of each channel and then reverse the order of the channels.

#19655 - CyberSlag5k - Fri Apr 23, 2004 4:29 am

Sounds good. Thank you.

The only thing is, I set index 0 of my sprite pallete to 0xFFFF, hoping to make the white border around my sprite go away. It, unfortunately, did not. Could it be that I am not drawing anything behind it? I was kind of just hoping that the default black background would just shine through. It simply is not so...
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#19662 - poslundc - Fri Apr 23, 2004 5:36 am

Changing palette index 0 to 0xFFFF doesn't change all of the occurrences within your bitmap that are white to point to palette index 0. I'm sure if you look at your palette you'll see another occurrence of 0xFFFF (or 0x7FFF) which is the entry that is being used wherever there is white in your bitmap.

To fix that, you need to change all of the occurrences of that index in the bitmap to 0.

But this is a hacky way to go about it, and means you must waste a colour in your palette. Find a better way, either using the current conversion tools you are using or by writing your own.

Dan.

#19688 - CyberSlag5k - Fri Apr 23, 2004 3:24 pm

Quote:

Changing palette index 0 to 0xFFFF doesn't change all of the occurrences within your bitmap that are white to point to palette index 0.


Excellent point. Got it.
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...