color to ABGR

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

Moderators: cheriff, TyRaNiD

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

color to ABGR

Post by LuMo »

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:
iA = ((mesh.verticesV1.color>>24) & 255);
iB = ((mesh.verticesV1.color >> 16) & 255);
iG = ((mesh.verticesV1.color >> 8) & 255);
iR = (mesh.verticesV1.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
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

nothing, but what do you actually get? all zeros?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

Code: Select all

	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
white rabbit
Posts: 60
Joined: Wed Jul 06, 2005 7:03 pm

Post by white rabbit »

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.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

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.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
white rabbit
Posts: 60
Joined: Wed Jul 06, 2005 7:03 pm

Post by white rabbit »

Use unsigned ints?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

yes
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Post Reply