Originally Posted by
appleGuy
Ok,
Thank you
Also quick question:
In some C code ive seen, when storing an array of values that make up an image (such as a tga or jpeg) they use a char type, why do they do that if the values for R G B are going to be numerical?
Many Thanks
-Alex
I'm not sure here but it could be possible that the chars repesent the RGB components of the colour. You would then to use bitshifting to put them all into a 32bit colour value.
Heres an example (sorry its in C):
Code:
int ToRGB(int r, int g, int b) { r=r<<16; g=g<<8; return r+g+b; }
int ToARGB(int a, int r, int g, int b) { a=a<<24; r=r<<16; g=g<<8; return a+r+g+b; }
int AlphaEl(int col) { return col >> 24; }
int RedEl(int col) { return (col >> 16) & 255; }
int GreenEl(int col) { return (col >> 8) & 255;}
int BlueEl(int col) { return col & 255; }
int main()
{
int r, g, b, col;
printf("Enter red element: "); scanf("%i", &r);
printf("Enter green element: "); scanf("%i", &g);
printf("Enter blue element: "); scanf("%i", &b);
col=ToRGB(r, g, b);
printf("Colour value %i\n", col);
printf("Convert to red: %i\n", RedEl(col));
printf("Convert to green: %i\n", GreenEl(col));
printf("Convert to blue: %i\n", BlueEl(col));
getchar();
getchar();
}