You are not logged in.
Is there s simple way to change, brighten or darken a color u32 color in c? I'm passing one color to my cube function but I want a different shade of the same color on each side of the cube. Is there a way to increased of decrease the hex value by a specified amount?
Also I've noticed that when I specify 0x11111100 or 0x00000000 that the object is not completely transparent. I'm using the code in Grrlib examples.
Offline
RESOLVED I figured it out after looking at the GRRLIB image manipulation Source
u32 color_darken(u32 color) { u16 sr, sg, sb; sr = R(color)-30; sg = G(color)-30; sb = B(color); if (sr>255) sr=255; if (sg>255) sg=255; if (sb>255) sb=255; return RGBA(sr,sg,sb,A(color)); } u32 color_brighten(u32 color) { u16 sr, sg, sb; sr = R(color)+30; sg = G(color)+30; sb = B(color)-3; if (sr>255) sr=255; if (sg>255) sg=255; if (sb>255) sb=255; return RGBA(sr,sg,sb,A(color)); } //GRRLIB_GetColor(sr,sg,sb,color&0xFF); deprecated or something or removed
Offline
here is an improved and corrected version
u32 color_darken(u32 color, int value) { u16 sr, sg, sb; sr = R(color)- value; sg = G(color)-value; sb = B(color)-value; if (sr<0) sr=0; if (sg<0) sg=0; if (sb<0) sb=0; return RGBA(sr,sg,sb,A(color)); } u32 color_brighten(u32 color, int value) { u16 sr, sg, sb; sr = R(color)+ value; sg = G(color)+value; sb = B(color)-value; if (sr>255) sr=255; if (sg>255) sg=255; if (sb>255) sb=255; return RGBA(sr,sg,sb,A(color)); }
Offline
oh ok, but what about the second part of the question? I've noticed that when I specify 0x11111100 or 0x00000000 that the object is not completely transparent. why is that?
Offline
In the color_brighten function, with this code by NNN:
sb = B(color)-value;
or this code by owen:
sb = B(color)-3;
It's wrong to do:
if (sb>255) sb=255;
You need to do:
if (sb<0) sb=0;
Except if value parameter could be set to negative value in the NNN code.
Offline
Right Crayon,
Anyway, he have to clamp the final value of each component to 0-255, by the way he wants
Offline