| View previous topic :: View next topic |
| Author |
Message |
Harold
Joined: 30 Jun 2005 Posts: 7
|
Posted: Thu Jun 30, 2005 1:53 pm Post subject: Question about the color space on the PSP |
|
|
<gush>I finally got to dig into some real development tonight and I'd like to say I'm having the time of my life. </gush>
I found this snippet which convers RGB colors down to the 4byte madness that is the psp's color space:
| Code: | | unsigned short rgb2col(unsigned char r,unsigned char g,unsigned char b){return ((((b>>3) & 0x1F)<<10)+(((g>>3) & 0x1F)<<5)+(((r>>3) & 0x1F)<<0)+0x8000);} |
First off, is this as accurate as it gets? and second off is there a reverse operation?
Here is my pathetic contribution to the pg.c library ;)
| Code: | unsigned short pgGetPixel(int x, int y)
{
unsigned short *vptr0 = pgGetVramAddr(0,0);
return vptr0[y * LINESIZE + x];
} |
Basically this returns the 4byte short, and thats great, but is there some way to get the constituant RGB values from it? Or maybe a way to set the palette up in some sane fashion?
sorry if this has been brought up before, a search didn't lead me to the answers I was looking for, but if its in here somewhere a link to a similar thread would be appreciated as much as a straight answer.
Thanks in advance,
-Harold |
|
| Back to top |
|
 |
sasq
Joined: 29 Jun 2005 Posts: 16
|
Posted: Thu Jun 30, 2005 5:17 pm Post subject: |
|
|
4-byte madness? Its a standard 16bit screenmode.
ARRRRRGGGGGBBBBB
Just read up on your shifting and or:ing operations.
Also you can set the screen to 32bit if you prefer. |
|
| Back to top |
|
 |
Hippo
Joined: 25 Jun 2005 Posts: 19
|
Posted: Thu Jun 30, 2005 5:35 pm Post subject: |
|
|
In response to your contribution, couldn't you just do the following:
| Code: | unsigned short pgGetPixel(int x, int y)
{
return *(unsigned short *)pgGetVramAddr (x, y);
} |
Or something that works, if this doesn't? |
|
| Back to top |
|
 |
Harold
Joined: 30 Jun 2005 Posts: 7
|
Posted: Thu Jun 30, 2005 11:07 pm Post subject: |
|
|
| sasq wrote: | 4-byte madness? Its a standard 16bit screenmode.
ARRRRRGGGGGBBBBB
Just read up on your shifting and or:ing operations.
Also you can set the screen to 32bit if you prefer. |
Maybe I have it in a wacky screen mode.
If it were ARRRRRGGGGGBBBBB wouldn't something like:
| Code: | c = 0;
for(y = 10; y < 262; y++)
{
for(x=10;x<470;x++)
{
pgPutPixel(x,y,c);
c+=1;
}
} |
start with black pixels and have a slow gradient up through blue, then start mixing blue with green and so on?
Because thats not what I see at all. What im seeing is it starting with black and quickly ramping up through red, and then it slowly starting to mix in green, but with lots of repetition. This seems weird to me, or maybe I just have my head way up my ass.
Also, can you tell me how to put it into a 32 bit screen mode? Or point me towards some information that can tell me how?
Thanks,
-Harold |
|
| Back to top |
|
 |
maddogjt1
Joined: 27 Jun 2005 Posts: 13
|
Posted: Fri Jul 01, 2005 12:00 am Post subject: |
|
|
| the 16bit pixel format is actually ABBBBBGGGGGRRRRR. |
|
| Back to top |
|
 |
f_bohmann
Joined: 02 May 2005 Posts: 16 Location: hamburg, germany
|
Posted: Fri Jul 01, 2005 12:27 am Post subject: |
|
|
harold, i guess you did not understand what people are telling you. :)
each pixel has 16 bits, of which 1 bit is used for alpha, and 5 bits for each red, green and blue. this "shifting orgy" you posted just scales down the color components from 8 bits per color to 5 bits per color and then shifts those bits into one 16bit value. there is absolutely no magic or orgy involved here. you just have to understand that sometimes the data you use is not 8/16/32 bits, but something in between. in 16 bit mode you have less accuracy per color, but also only half the memory useage/bandwidth than in 32bit mode.
to get back from 16 to 32 bits, you just have to do the logical operation in reverse. (mask out the bits for each color, shift them back up to 8 bits and put them into a 32 bits number).
edit: by the way, (unsigned) short is 2 bytes, not 4. :)
Last edited by f_bohmann on Fri Jul 01, 2005 12:35 am; edited 1 time in total |
|
| Back to top |
|
 |
Harold
Joined: 30 Jun 2005 Posts: 7
|
Posted: Fri Jul 01, 2005 12:30 am Post subject: |
|
|
Thanks f_ and maddog, your posts explain better what I'm seeing. Too bad I'm stuck at work for the next 8 hours, I just want to code more.
Peace out, I'm looking forward to being a part of this community.
-Harold |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Fri Jul 01, 2005 12:37 am Post subject: |
|
|
| Harold wrote: | | Too bad I'm stuck at work for the next 8 hours, I just want to code more. |
Me too :-/ I hate work, wish i could independent code all day :-D |
|
| Back to top |
|
 |
Harold
Joined: 30 Jun 2005 Posts: 7
|
Posted: Fri Jul 01, 2005 11:03 pm Post subject: |
|
|
Ahhh, a few hours later and I've derived the answer I was looking for. Here are the macros I came up with. Thanks again.
| Code: |
#define RGB(r,g,b) ((((b>>3) & 0x1F)<<10)|(((g>>3) & 0x1F)<<5)|(((r>>3) & 0x1F)<<0)|0x8000)
#define R( c ) ( (c & 0x1f) << 3 )
#define G( c ) ( ((c >> 5) & 0x1f ) << 3 )
#define B( c ) ( ((c >> 10) & 0x1f) << 3 )
|
-Harold |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Thu Jul 07, 2005 1:38 am Post subject: |
|
|
Sorry for the post bump, but I have been having trouble with my RGB macros. I have been using the suggested macro, and was wondering who has gotten it to work, because for me only the red element displays correctly.
I think I must have changed Nem's code somewhat incorrectly, and was wondering if somebody could give me a small code sample of the PG.c .h and any other important changes in other files.
I hope you can find time to reply. |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Thu Jul 07, 2005 3:49 am Post subject: |
|
|
Eureka! I've fixed it!
I was using the default code of | Code: | | *(unsigned char *)vptr= RGB16(x ,x ,x); | but that was cutting off the Blue element, so when I changed it to | Code: | | *(unsigned short *)vptr= RGB16(x ,x ,x); | IT WORKS!
Hooray! I can now continue with my engine and hopefull make some fun games.
Thanks for everyone that helped though. |
|
| Back to top |
|
 |
|