PSP colour not working right... Possible Bit Shift problems

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

PSP colour not working right... Possible Bit Shift problems

Post by AnonymousTipster »

I thought I had sorted this out, but obviously not.
To blit RGB values to the PSP vram, I am using the following Macro

Code: Select all

#define RGB16&#40;r, g, b&#41; &#40;&#40;r & 31&#41; + &#40;&#40;g & 31&#41;<<5&#41; + &#40;&#40;b & 31&#41;<<10&#41;&#41;
(I am using 16bit for the moment to get it running correctly)
I am then doing a 1-255 RGB sweep, using this code:

Code: Select all

for&#40;y=1;y<256;y++&#41;&#123;
	for&#40;x=1;x<256;x++&#41;&#123;
	PutPixelRGB&#40;x,y, x, x, x&#41;;
	&#125;
	&#125;
This should draw a 255pixel wide gradient from black to white, but it doesn't. What it draws is a 255pixel wide set of 8 black to white gradients. So you have several pixels of black fading to white, then suddenly to black which fades to white...etc. It is as though the rage is going from 1-2040 in the space of 255pixels.
I have tried everything I can think of, but something is wrong, and I can only pray that you can help me....
maddogjt1
Posts: 13
Joined: Mon Jun 27, 2005 3:06 pm

Post by maddogjt1 »

it has to do with your RGB16 macro. Instead of taking the five most significant bits of each color, you're taking the five least. You should use

#define RGB(r,g,b) ((((b>>3) & 0x1F)<<10)|(((g>>3) & 0x1F)<<5)|(((r>>3) & 0x1F)<<0)|0x8000)
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

Looks like RGB16 is wrong. Use this instead (or modify yours :P):
// stolen from some other thread...
#define RGB16(r, g, b) ((((b>>3) & 0x1F)<<10)+(((g>>3) & 0x1F)<<5)+(((r>>3) & 0x1F)<<0)+0x8000)
EDIT: I am the lose.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

Well, I tried that, in video modes 1,2,3 but I get something worse:
4 gradient bars, one from black to brown/green, then one from dark red to a slightly brownier red, then medium red to pale orange, and then red to light red. Also, the gradients aren't smooth, they are broken into 8 blocks per gradient.
Has anybody else got a macro like this working fully on the PSP yet?
This is very odd, any help appreciated.
Harold
Posts: 7
Joined: Thu Jun 30, 2005 1:33 pm

Post by Harold »

Look at my finaly reply to http://forums.ps2dev.org/viewtopic.php? ... 5127277d84

Those macros work like a charm, and allow you to go back and forth.

-Harold
XenuPSP
Posts: 3
Joined: Mon Apr 04, 2005 12:48 am

Post by XenuPSP »

What mode are you in? Are you sure the color isn't mapped as 5:6:5? I'm wondering if your shift for blue shouldn't be 11 bits instead of 10, and your green mask should be 0x3F instead of 0x1F.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

Harold wrote:Look at my finaly reply to http://forums.ps2dev.org/viewtopic.php? ... 5127277d84
-Harold
I found that thread when the problem arised, but that Macro (the one I am using to get me the really strange results) doesn't seem to work.
Also, I tried using the 5.6.5 macro and that still doesn't work, and that would only tweak the colour somewhat, ATM the colour should be black to white, but is black to dark green to red to orange...etc.
I am using Nem's code as follows:

Code: Select all

//constants
#define		PIXELSIZE	1				//in short
#define		PIXELMODE   1				//The bit depth

/*------------------------------*/

void pgScreenFrame&#40;long mode,long frame&#41;
&#123;
	pg_screenmode=mode;
	frame=&#40;frame?1&#58;0&#41;;
	pg_showframe=frame;
	if &#40;mode==0&#41; &#123;
		//screen off
		pg_drawframe=frame;
		sceDisplaySetFrameBuf&#40;0,0,PIXELMODE,1&#41;;
	&#125; else if &#40;mode==1&#41; &#123;
		//show/draw same
		pg_drawframe=frame;
		sceDisplaySetFrameBuf&#40;pg_vramtop+&#40;pg_showframe?FRAMESIZE&#58;0&#41;,LINESIZE,PIXELMODE,1&#41;;
	&#125; else if &#40;mode==2&#41; &#123;
		//show/draw different
		pg_drawframe=&#40;frame?0&#58;1&#41;;
		sceDisplaySetFrameBuf&#40;pg_vramtop+&#40;pg_showframe?FRAMESIZE&#58;0&#41;,LINESIZE,PIXELMODE,1&#41;;
	&#125;
&#125;


void pgScreenFlip&#40;&#41;
&#123;
	pg_showframe=&#40;pg_showframe?0&#58;1&#41;;
	pg_drawframe=&#40;pg_drawframe?0&#58;1&#41;;
	sceDisplaySetFrameBuf&#40;pg_vramtop+&#40;pg_showframe?FRAMESIZE&#58;0&#41;,LINESIZE, 0,1&#41;;
&#125;
And I'm still having problems, which is very odd, because that Macro seems to work for other people.

And thanks for the help so far.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

I have done a bit more research into it, and instead of plotting black to white, I tried it with black to red, black to green and black to blue.
Black - Red worked perfectly: black to red over 255 pixels
Black - Green displayed 4 black - dark green gradients
Black - Blue displayed nothing at all.

So, the Red element seems to be working, the green is incorrect and the blue is completely off.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

FWIW, I found out that
(((b>>3) & 0x1F)<<8) is where it goes black, and
(((b>>3) & 0x1F)<<7) displays dark green stripes
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

Still having problems, has anybody used the
#define RGB16(r, g, b) ((((b>>3) & 0x1F)<<10)+(((g>>3) & 0x1F)<<5)+(((r>>3) & 0x1F)<<0)+0x8000)
Macro sucessfully with a multitude of colours (i.e, not just black)?
Post Reply