| View previous topic :: View next topic |
| Author |
Message |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Wed Jun 07, 2006 7:52 pm Post subject: color to ABGR |
|
|
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 |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Wed Jun 07, 2006 8:26 pm Post subject: |
|
|
| nothing, but what do you actually get? all zeros? |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Wed Jun 07, 2006 8:32 pm Post subject: |
|
|
| 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 |
|
 |
white rabbit
Joined: 06 Jul 2005 Posts: 60
|
Posted: Wed Jun 07, 2006 8:43 pm Post subject: |
|
|
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 |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Wed Jun 07, 2006 8:51 pm Post subject: |
|
|
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 |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Wed Jun 07, 2006 8:58 pm Post subject: |
|
|
| 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 |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Wed Jun 07, 2006 9:02 pm Post subject: |
|
|
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 |
|
 |
white rabbit
Joined: 06 Jul 2005 Posts: 60
|
Posted: Fri Jun 09, 2006 6:24 pm Post subject: |
|
|
| Use unsigned ints? |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri Jun 09, 2006 7:04 pm Post subject: |
|
|
yes _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
|