//*************************************//
//******** created by mamo139 *********//
//*** http://mamo139.altervista.org ***//
//*************************************//
unsigned char ****tabella_rgb_hsv;
unsigned char ****tabella_hsv_rgb;
inline unsigned char char_conversion(int c){ return ((c)<255) ? ((c)>0) ? (c) : 0 : 255; }
...
//creazione tabella conversione rgb to hsv: tabella_rgb_hsv
printf("preparazione tabella rgb to hsv... ");
tabella_rgb_hsv = new unsigned char ***[3];
for(h=0;h<3;h++){
tabella_rgb_hsv[h] = new unsigned char **[256];
for(x=0;x<256;x++){
tabella_rgb_hsv[h][x] = new unsigned char *[256];
for(y=0;y<256;y++)
tabella_rgb_hsv[h][x][y] = new unsigned char[256];
}
}
for(x=0;x<256;x++) // x = rosso
for(y=0;y<256;y++) // y = verde
for(z=0;z<256;z++){ //z = blu
max = x;
if(y>max) max = y;
if(z>max) max = z;
min = x;
if(y<min) min = y;
if(z<min) min = z;
if(max == min)
tabella_rgb_hsv[0][x][y][z] = 0;
else if(x == max)//else if(x > y && x > z) //se rosso max
tabella_rgb_hsv[0][x][y][z] = char_conversion( ((60*(y-z)/(max-min)+360)%360)*255/359 );
else if(y == max)//else if(y> x && y > z)
tabella_rgb_hsv[0][x][y][z] = char_conversion( (60*(z-x)/(max-min)+120)*255/359 );
else if(z == max)
tabella_rgb_hsv[0][x][y][z] = char_conversion( (60*(x-y)/(max-min)+240)*255/359 );
else
printf("errore rgb->hsv\n");
tabella_rgb_hsv[2][x][y][z] = (unsigned char)max;
if(max == 0)
tabella_rgb_hsv[1][x][y][z] = 0;
else
tabella_rgb_hsv[1][x][y][z] = char_conversion((max - min)*255/max);
}
printf("fatto!\n");
//creazione tabella conversione rgb to hsv: tabella_hsv_rgb
printf("preparazione tabella hsv to rgb...");
tabella_hsv_rgb = new unsigned char ***[3];
for(h=0;h<3;h++){
tabella_hsv_rgb[h] = new unsigned char **[256];
for(x=0;x<256;x++){
tabella_hsv_rgb[h][x] = new unsigned char *[256];
for(y=0;y<256;y++)
tabella_hsv_rgb[h][x][y] = new unsigned char[256];
}
}
for(x=0;x<256;x++) // x = hue
for(y=0;y<256;y++) // y = saturation
for(z=0;z<256;z++){ //z = value
h = (int)floor((float)(x*359/255)/60)%6;
f = (float)(x*359/255)/60 - floor((float)(x*359/255)/60);
s = (float)y/255;
p = (long)( z * (1.0 - s) );
q = (long)( z * (1.0 - f * s ) );
t = (long)( z * (1.0 - (1.0-f) * s) );
if(h == 0){
tabella_hsv_rgb[0][x][y][z] = char_conversion(z);
tabella_hsv_rgb[1][x][y][z] = char_conversion(t);
tabella_hsv_rgb[2][x][y][z] = char_conversion(p);
}
if(h == 1){
tabella_hsv_rgb[0][x][y][z] = char_conversion(q);
tabella_hsv_rgb[1][x][y][z] = char_conversion(z);
tabella_hsv_rgb[2][x][y][z] = char_conversion(p);
}
if(h == 2){
tabella_hsv_rgb[0][x][y][z] = char_conversion(p);
tabella_hsv_rgb[1][x][y][z] = char_conversion(z);
tabella_hsv_rgb[2][x][y][z] = char_conversion(t);
}
if(h == 3){
tabella_hsv_rgb[0][x][y][z] = char_conversion(p);
tabella_hsv_rgb[1][x][y][z] = char_conversion(q);
tabella_hsv_rgb[2][x][y][z] = char_conversion(z);
}
if(h == 4){
tabella_hsv_rgb[0][x][y][z] = char_conversion(t);
tabella_hsv_rgb[1][x][y][z] = char_conversion(p);
tabella_hsv_rgb[2][x][y][z] = char_conversion(z);
}
if(h == 5){
tabella_hsv_rgb[0][x][y][z] = char_conversion(z);
tabella_hsv_rgb[1][x][y][z] = char_conversion(p);
tabella_hsv_rgb[2][x][y][z] = char_conversion(q);
}
}
printf("fatto!\n");