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 > PCX2GBA - How does it work

#31400 - QuantumDoja - Fri Dec 10, 2004 8:18 pm

Hi, How does pcx2gba work, i understand that it takes to pixels and puts them into a hexadecimal value (how??)
_________________
Chris Davis

#31420 - tepples - Fri Dec 10, 2004 10:08 pm

What an image conversion program does, at the highest level:
  1. Decode the image file, based on format specs from wotsit.org
  2. Reorder the pixels in a GBA format, according to GBATEK
  3. Write the pixels to a file
Which step do you need explained further?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#31427 - QuantumDoja - Fri Dec 10, 2004 10:55 pm

Well, you have to hex values of 2 pixels, then what, how do they get converted into one?
_________________
Chris Davis

#31429 - Lupin - Fri Dec 10, 2004 11:01 pm

no need to convert them into one.

Just copy 2 pixels at the same time - will also be faster.

If you really feel like you would need to access 1 pixel at a time:

firstpixel = pixeldata[y*WidthOfImage+(x>>1)] >> 8;
secondpixel = pixeldata[y*WidthOfImage+(x>>1)+1] & 0xFF;

WidthOfImage needs to be the half of the actual width because the array stores 2 pixels in 1 array-element. Don't you read tutorials about GBA programming? www.thepernproject.com is very good and it should give you informations about things like this i think
_________________
Team Pokeme
My blog and PM ASM tutorials

#31442 - QuantumDoja - Sat Dec 11, 2004 12:18 am

Hi, Dovoto's program puts tile data like so..

const u16 TileData[] = {
0xFEFE, 0xFEFE,...

Each hex value is 2 pixels, I was wondering how, for instance, if you had two color codes:

#002299 and #ff00ff you combine them to squaeeze them into the 16 bit int. What would the value be?

please help.

Thanks
_________________
Chris Davis

#31453 - tepples - Sat Dec 11, 2004 12:44 am

You can read GBATEK or the CowBite spec to see how to format a 15-bit color. What did you not understand after reading those documents?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#31454 - Lupin - Sat Dec 11, 2004 12:46 am

oh... well, these color codes are 24 bit color.

In 24/32 bit color mode Red, Green and Blue have 8 bits (each channel = 8 bits/1 byte) so you can have red/green/blue values from 0 to 255

In 16 bit (actually 15 bit) color mode Red, Green and Blue only have 5 bits (5*3 = 15) so you can have red/green/blue values from 0 to 31

Understanding binary/hex system helps a lot for understanding this kind of calculation.

When you convert a 24 bit color to 15 bit color you divide the Red/Green/Blue value by 8 and combine the result into one 16 bit half word - voila you have your 15 bit color!

Some systems may use different order of R/G/B values...
_________________
Team Pokeme
My blog and PM ASM tutorials

#31520 - QuantumDoja - Sat Dec 11, 2004 9:21 pm

Ok. what i want to do is from these two hex values make the single value:

We already know what the pixel colors will be, as below

ok:

pixel1: #00ff00
pixel2: #ffff00

Output: 1 hex value.

just need to put them into one. Does it matter im using web hex codes?
_________________
Chris Davis

#31523 - tepples - Sat Dec 11, 2004 9:33 pm

Converted from hex to decimal:
Pixel 1: R=0, G=255, B=0
Pixel 2: R=255, G=255, B=0

The components of a web color range from 0 to 255, while the components of a GBA color range from about 8 to 31. To convert each web color component x to a GBA color component x', do x' = x / 11 + 8.

This gives the GBA colors:
Pixel 1: R=8, G=31, B=8
Pixel 2: R=31, G=31, B=8

Given these, each GBA pixel value is R + 32*G + 1024*B.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#31527 - Lupin - Sat Dec 11, 2004 9:51 pm

Why do you think they Colors for a GBA pixel reach from 8 to 31? I am quite sure that they reach from 0 to 31 =/

The equalation should just be x' = x / 8
As example take web color component 255 for x this will give us x' = 255/8 = 31,875 (don't round this up)
_________________
Team Pokeme
My blog and PM ASM tutorials

#31531 - QuantumDoja - Sat Dec 11, 2004 10:48 pm

So, with that said, in this case, what is the answer?
_________________
Chris Davis

#31532 - Lupin - Sat Dec 11, 2004 11:12 pm

I don't know what you expect as an answer to this... but if you still don't have enough info, here is a simple VB function that takes a normal 24 bit color and converts it to a GBA 15 bit color, i use this function in my converters:

Code:

Private Function C24toC15(c As Long) As Integer
Dim cr As Long, cg As Long, cb As Long
cr = ((c And &HFF) \ 8) * 1024
cg = (((c \ &H100) And &HFF) \ 8) * 32
cb = ((c \ &H10000) And &HFF) \ 8
C24toC15 = cr Or cg Or cb
End Function


The return type is Integer (16 bit), the input type is Long (32 bit). In C you would do the * and \ with shift operators but VB doesn't support them =/
_________________
Team Pokeme
My blog and PM ASM tutorials

#31538 - keldon - Sun Dec 12, 2004 1:11 am

Lupin wrote:
Why do you think they Colors for a GBA pixel reach from 8 to 31? I am quite sure that they reach from 0 to 31 =/

The equalation should just be x' = x / 8
As example take web color component 255 for x this will give us x' = 255/8 = 31,875 (don't round this up)


Because 0-7 are pretty much the same shades of pitch black.