forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

color blending in 5551 mode???

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Mon Oct 17, 2005 2:27 pm    Post subject: color blending in 5551 mode??? Reply with quote

Could someone please help me out with color blending?

Basically, I need a fast function which would take 2 unsigned shorts representing PSP's 5551 colors and will return the third, representing the resulted blended color:

u16 blend(u16 color1, u16 color2);

for example, if I blend green and white, the func() should return light green...

I am really bad with bit operations, so any help / advise will be greatly appreciated...
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Tue Oct 18, 2005 3:28 am    Post subject: Reply with quote

as your color information is an integer (unsigned 16 bit[u16?])
add the values and shift em one right
thats it
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Tue Oct 18, 2005 4:27 am    Post subject: Reply with quote

o_O thats a joke isn't it?
you mean add the 16bit values and shift them right one bit?

if you mean to add and shift each 5bit component of the 16bit color value individually, then thats correct.
_________________
infj
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Tue Oct 18, 2005 4:34 am    Post subject: Reply with quote

sorry to be not clear
i meant each of the R G B values (A can be ignored)
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Tue Oct 18, 2005 5:56 am    Post subject: Reply with quote

I understand the actual logic behing it but not too clear on the actual syntax of bit manipulations..
could you please provide a code sample of how it's done?

You help will be greatly appreciated...
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Tue Oct 18, 2005 6:23 am    Post subject: Reply with quote

for one value:
Code:

C3_r = (C1_r + C2_r) >> 1; // eg R value

_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
marlov74



Joined: 04 Feb 2005
Posts: 10

PostPosted: Tue Oct 18, 2005 4:34 pm    Post subject: Reply with quote

C1 = C1 and 1111011110111100
C2 = C2 and 1111011110111100
C1 = C1 >> 1
C2 = C2 >> 1
C3 = C1 + C2
Back to top
View user's profile Send private message MSN Messenger
ChaosKnight



Joined: 14 Apr 2005
Posts: 142
Location: Florida, USA

PostPosted: Tue Oct 18, 2005 9:30 pm    Post subject: Reply with quote

And if you want even more examples (not PSP specific but good) you can check out the late Seumas McNally's work on software pixel blending here: http://www.ldagames.com/seumas/progblend.html
_________________
w00t
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Wed Oct 19, 2005 1:45 am    Post subject: Reply with quote

Based on your advise I came up with following func() but it does not work
correctly for all colors.
for example when I blend magenta and white I end up with dome dark blue shade; light blue colors also become darker...
what am I doing wrong here?

PS: Thank you for all your help, guys...


unsigned short blend(unsigned short c1, unsigned short c2){
return (unsigned short)(((c1 & 0xF7BC)>>1) + ((c2 & 0xF7BC)>>1));
}
Back to top
View user's profile Send private message
marlov74



Joined: 04 Feb 2005
Posts: 10

PostPosted: Wed Oct 19, 2005 8:10 am    Post subject: Reply with quote

It should work, Mine PSP is not working right now soo I can not test.
But I did a test with Notepad and the Calculator.

White
=
31 31 31
=
11111 11111 11111 0
and
11110 11110 11110 0
=
11110 11110 11110 0
>> 1
=
01111 01111 01111 0


Magenta
=
31 0 31
11111 00000 11111 0
and
11110 11110 11110 0
=
11110 00000 11110 0
>> 1
=
01111 00000 01111 0


01111 01111 01111 0
+
01111 00000 01111 0
=
11110 01111 11110 0
=
30 15 30
=
Lighter Magenta
Back to top
View user's profile Send private message MSN Messenger
memon



Joined: 03 Oct 2005
Posts: 63

PostPosted: Wed Oct 19, 2005 7:09 pm    Post subject: Reply with quote

This one should work too and you don't lost the one precious bit of precicion either:

Code:
   const unsigned short   maskRB = 0x7c1f;
   const unsigned short   maskG = 0x03e0;
   unsigned short   res = ((((a & maskRB) + (b & maskRB) + 0x401) >> 1) & maskRB) |
      ((((a & maskG) + (b & maskG) + 0x20) >> 1) & maskG);
[/code]
Back to top
View user's profile Send private message
marlov74



Joined: 04 Feb 2005
Posts: 10

PostPosted: Thu Oct 20, 2005 2:40 am    Post subject: Reply with quote

0x7c1f = 111110000011111
0x03e0 = 000001111100000
I Thought 5551 was RRRRRGGGGGBBBBBA, so where did the A Go?

(a & maskRB) + (b & maskRB) is 16 precision ok for that, or are all operations in 32 bit and then masked for 16bit in the end?
Back to top
View user's profile Send private message MSN Messenger
memon



Joined: 03 Oct 2005
Posts: 63

PostPosted: Thu Oct 20, 2005 4:06 am    Post subject: Reply with quote

My texture class says:

Code:
inline u16 pack5551( u8 r, u8 g, u8 b, u8 a )
{
   return (r >> 3) | ((g & 0xf8) << 2) | ((b & 0xf8) << 7) | ((a & 0x80) << 8);
}


And it works and looks ok, so I assume that I made right assumption :)

I did not check what kind of assembly the code generates, but as the alpha bit is last (and not used in this case), it should work in 16bit. On 565 you'll need to do it in 32bit.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group