#5948 - Link - Tue May 13, 2003 7:06 pm
ok, i've learned what mean hexadecimal values in the .h of images or sprites...
infact i can translate for example this:
Code: |
const u16 sprite1Data[] = {
0x8989, 0x8989,
.... ....
const u16 sprite1Palette[] = {
0x0000, 0x1800,
.... ....
|
the first one is in decimal '35209' the second is yet '35209' instead the first value of palette is '0' and the second is 6144 and so on...
but what mean these?
what mean in the Data Array or Palette are there this numbers?
How can i get the color RGB (or that used by AGB) value?
And what is these value in sprite Data array?
i ask this to you because i don't know and in tutorials i didn't read this...
how can anwer me is good apceptted!
#5950 - Psyk - Tue May 13, 2003 7:39 pm
Well the problem is, the GBA stores it's colours with 5 bits for each color. So for a 16 bit value (4 hexidecimal digits like your's) the first 5 bits represent red, the second 5 bits represent green and the next 5 bits represent blue. Then there is one bit left over. The problem is that one hexidecimal digit represents 4 bits, not 5. I'm not sure how to split it into the seperate colours but it doesn't really matter as you probably wont need to.
As for the data array each 16bit value represents 2 pixels of the sprite because each pixel is only 8 bits but you have to copy 16bits at time on the GBA. So in other words the first 2 hex digits are the palette reference for the 1st pixel then the next two are for the next pixel and so on.
#5951 - niltsair - Tue May 13, 2003 7:41 pm
SpritePalette :
-Each color is represented on 15bits.
-0x1234 Represent a 16bits
-0x1234 when converted to binaries yield this value : (1)0001 (2)0010 (3)0011 (4)0100 => (0001 0010 0011 0100)
-Now for your RGB colors, they each takes 5bits. So, to get the value of each component you get the value of : XBBB BBGG GGGR RRRR (X = not used)
-Thus in the preceding example we get :
(0-001 00-10 001-1 0100-)
Red= 00100 = 0x04 = 4
Green= 10001 = 0x11 = 17
Blue= 10100 = 0x14 = 20
You'll have to learn how to easily understand Hex, and most importantly, easily convert between Hex and binary.
So each entry represent a color.
SpriteData
-Each element represent a pixel.
-This pixel value represent which color to use in your palete, so if it says '34' then it means to display color 34 of your palette for this pixel.
-The problme is, because video memory can only be readed/written in 16bits, they pack 2 pixels in one entry. So for the value (0x1267) the palette's color to use for the first pixel is 0x12, and 0x67 for the second one.
-Because they're packed 2 by 2, to find the value of say pixel 120, then you have to find the entry 60 (120/2) in SpriteData.
#5959 - Link - Tue May 13, 2003 10:20 pm
thank u guys its perfect, really tnx
#5969 - Link - Wed May 14, 2003 11:29 am
so 0x1234 take 5 bit of memory?
#5970 - OrangyTang - Wed May 14, 2003 11:36 am
Link wrote: |
so 0x1234 take 5 bit of memory? |
No. Each hex digit can hold 16 values (0-9, A-F), so therefore each hex digit is 4 bits. Therefore 0xFF is 8 bits (a byte) and 0x1234 is 16 bits. This is basic computer knowledge, you'd be better off looking on other sites for this info.
#5972 - Link - Wed May 14, 2003 12:02 pm
i understand that 0x1234 rappresent 16 bit color but in the memory how much space take that?
the normal max index of RGB color is 255-255-255 right? So 9 numbers to rappresent a color.
with 0x1234 i use 6 numbers, now because AGB don't support numbers of colors bigger then 6 it needs to convert the 9 numbers to rappresent colors in 6 numbers. There becouse i use hexadecimal.
Is it?
#5973 - OrangyTang - Wed May 14, 2003 12:56 pm
Link wrote: |
i understand that 0x1234 rappresent 16 bit color but in the memory how much space take that? |
For every color in 16bit colour, you need (shock! horror!) 16 bits.
Quote: |
the normal max index of RGB color is 255-255-255 right? So 9 numbers to rappresent a color. |
No, 255-255-255 is *not* nine separate numbers, but 3 numbers, ranging between 0 and 255 each.
Quote: |
with 0x1234 i use 6 numbers, now because AGB don't support numbers of colors bigger then 6 it needs to convert the 9 numbers to rappresent colors in 6 numbers. There becouse i use hexadecimal.
Is it? |
Firstly, its not 6, the '0x' is just notation to say 'what comes next is a hex number'. Secondly, you can't think in terms of 'number of numbers' like you are, since they use different bases (10 vs. 16). Re-read niltsair's info about the pallette to understand how the hex number can be converted to RGB values.
As a side note, why is the 16th bit not used? Why didn't they either go with a 565 colour representation or use the extra as a transparency flag (or something)?
#5974 - Link - Wed May 14, 2003 1:09 pm
ok i read again.
#5975 - niltsair - Wed May 14, 2003 2:34 pm
I suppose they wanted all 3 basic color to have the same range.
To use it as transparency would have been unusefull, seing how in those mode, there's only 1 layer that you can see, so there's nothing to see behind it.
And the others modes that use layers, well they use color 0 to say it's transparent. Now that i think of it, for this case, it could have been nice, to just change the 16th bits, and everything using that color turning transparent, and then easily make them opaque again.
Let's file a lawsuit to Nintendo for not having done it :-)
#5981 - Sweex - Wed May 14, 2003 5:14 pm
I'd say the screen (actual hardware) only supports 32768 different colors (Cheaper to make?), and so there was no point making it 16 bits as you wouldn't see the difference.
#6028 - djei-dot - Thu May 15, 2003 5:57 pm
Link wrote: |
the normal max index of RGB color is 255-255-255 right? So 9 numbers to rappresent a color.
|
Actually, since the GBA uses 5 bits for each color (R, G or B), the "normal max index" for GBA is 32-32-32. And as OrangyTang said, it's not six numbers, but three numbers ranging from 0 to 32 each. That is why the GBA can only display 32768=32x32x32 different colors.
Link wrote: |
with 0x1234 i use 6 numbers, now because AGB don't support numbers of colors bigger then 6 it needs to convert the 9 numbers to rappresent colors in 6 numbers. There becouse i use hexadecimal.
Is it? |
The compiler you use (DevKitAdv for example) ignores the 0x when doing its job. So you end up only with four digits. Even though, the compiler turns them into machine code, which is 16 digits (bits) being each either 0 or 1.
btw, it feels good for us newbies to answer some things sometimes.
#6330 - MojoJojo - Fri May 23, 2003 11:18 am
Maybe you could use that spare bit for a hardness map... don't know how practical that would be speed wise. Might be able to get good performance in assembler.
#6341 - niltsair - Fri May 23, 2003 3:03 pm
I guess it could, but only in Mode 3, 5. The other modes use a palette and that would mean you couldn't use the same color elsewhere without being thought as unpassable.
#6359 - Maddox - Fri May 23, 2003 8:00 pm
djei-dot done wrote: Quote: |
btw, it feels good for us newbies to answer some things sometimes. |
Well, I hope you got your jollies but it was at the expense of one crappy explanation! I mean...
Quote: |
The compiler you use (DevKitAdv for example) ignores the 0x when doing its job. |
That's gold! You must be a technical writer.
Everybody shout, "MADDOX!"
_________________
You probably suck. I hope you're is not a game programmer.
#6371 - Touchstone - Fri May 23, 2003 9:13 pm
Everybody shout, "MADDOX, SHUT UP!"
_________________
You can't beat our meat
#6542 - ampz - Wed May 28, 2003 5:49 pm
OrangyTang wrote: |
As a side note, why is the 16th bit not used? Why didn't they either go with a 565 colour representation or use the extra as a transparency flag (or something)? |
In some cases it can be very useful for collision maps and stuff.
Usually, colors that you can walk through are not the same as the ones you can't walk through, and for the few colors that you sometimes can walk through, and sometimes not, you simply define the same color twice in the palette.
djei-dot wrote: |
Actually, since the GBA uses 5 bits for each color (R, G or B), the "normal max index" for GBA is 32-32-32. And as OrangyTang said, it's not six numbers, but three numbers ranging from 0 to 32 each. That is why the GBA can only display 32768=32x32x32 different colors. |
The so called "normal max index" (???) is actually 31-31-31.