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 to ABGR

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



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Wed Jun 07, 2006 7:52 pm    Post subject: color to ABGR Reply with quote

i know it was in this forum some time ago (think i even helped out :) )
but somehow i screwed it up...
u32 is my color (as used everywhere when it comes to psp...)

i try to extract the values this way:

Quote:
iA = ((mesh.verticesV1[i].color>>24) & 255);
iB = ((mesh.verticesV1[i].color >> 16) & 255);
iG = ((mesh.verticesV1[i].color >> 8) & 255);
iR = (mesh.verticesV1[i].color & 255);


this should give me values between 0..255 (for further calculation of float values between 0..1)

what am i doing wrong?

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



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Jun 07, 2006 8:26 pm    Post subject: Reply with quote

nothing, but what do you actually get? all zeros?
Back to top
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Wed Jun 07, 2006 8:32 pm    Post subject: Reply with quote

Code:
   int iA, iR, iG, iB = 5;
         float fA, fR, fG, fB;

   iA = ((mesh.verticesV3[i].color>>24) & 255);
   iB = ((mesh.verticesV3[i].color >> 16) & 255);
   iG = ((mesh.verticesV3[i].color >> 8) & 255);
   iR = (mesh.verticesV3[i].color & 255);
                

         fA = abs(iA / 255);
         fB = abs(iB / 255);
         fG = abs(iG / 255);
         fR = abs(iR / 255);
 
        printf("%f %f %f %f %f %f %f\n", fA, fB, fG, fR, mesh.verticesV3[i].x, mesh.verticesV3[i].y,
               mesh.verticesV3[i].z);


this is my full code...
so what i input is a value like 0xFFFEFFB4
should bring up values in int:
255, 254, 255, 180
which results in
1, 0.996078, 1, 0,705882
what i get is
1, 0, 1, 0

lumo

ps: does abs round? (did not think about this before :D )
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
white rabbit



Joined: 06 Jul 2005
Posts: 60

PostPosted: Wed Jun 07, 2006 8:43 pm    Post subject: Reply with quote

You may want to change the:

fA = abs(iA / 255);

to

fA = abs(iA / 255.0);

otherwise you'll get integer rounding, which means 120/255 = 0
0/255 = 0 to 254/255 = 0
255/255 = 1 to 509/255 = 1
etc etc

I think that's your problem...

edit - to your PS, abs just uses doubles (unless you use fabs (I hink it's called)), so no rounding the bit I'm on about applys to all maths calls when you have an int as the denominator.
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Wed Jun 07, 2006 8:51 pm    Post subject: Reply with quote

not possible....

stdlib.h:62: note: candidates are: int abs(int)

thats the prob... abs returns integer! (really need to define my OWN?!)
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Jun 07, 2006 8:58 pm    Post subject: Reply with quote

no, fabs should do what you want. However you normally shouldn't need to abs your values, since the i* values will always be positive.
Back to top
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Wed Jun 07, 2006 9:02 pm    Post subject: Reply with quote

thanks! works now!

ad abs... sometimes i get a -1, do not ask me why....

thanks for your help buddies!
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
white rabbit



Joined: 06 Jul 2005
Posts: 60

PostPosted: Fri Jun 09, 2006 6:24 pm    Post subject: Reply with quote

Use unsigned ints?
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri Jun 09, 2006 7:04 pm    Post subject: Reply with quote

yes
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
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