//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include #include #include #include //*** strumenti gestione file bmp ***// struct bmpfile { long x; long y; char *** matrice; }; char *** crea_bmp(char *nome, long x, long y); struct bmpfile carica_bmp(char *nome); void disegna_bmp(char *nome, char *** array, long x, long y); //*** strumenti gestione colori ***// struct rgb { int red; int green; int blue; }; struct rgb_d { double red; double green; double blue; }; struct hsv { int hue; int saturation; int value; }; struct hsv_d { double hue; double saturation; double value; }; struct rgb hsv_rgb(struct hsv hsv_map); struct hsv rgb_hsv(struct rgb rgb_map); //*** MAIN ***// int main (void){ double peso1 = 0.65; double peso2 = 0.65; long x,y; struct hsv hsv1; struct hsv hsv2; struct hsv hsvf; struct rgb rgbf; struct rgb rgb1; struct rgb rgb2; struct bmpfile img1 = carica_bmp("a.bmp"); struct bmpfile img2 = carica_bmp("b.bmp"); if(img1.x>img2.x) x = img2.x; else x = img1.x; if(img1.y>img2.y) y = img2.y; else y = img1.y; char *** mappanf = crea_bmp("out.bmp",x,y); long i,j; for(i=0;i255) rgbf.red = 255; rgbf.green=(int)(rgb1.green*peso1+rgb2.green*peso2); if(rgbf.green>255) rgbf.green = 255; rgbf.blue=(int)(rgb1.blue*peso1+rgb2.blue*peso2); if(rgbf.blue>255) rgbf.blue = 255; mappanf[i][j][2]=rgbf.red; mappanf[i][j][1]=rgbf.green; mappanf[i][j][0]=rgbf.blue; } disegna_bmp("out.bmp",mappanf,x,y); } //****** FUNZIONI *******// char *** crea_bmp(char *nome, long x, long y){ char buffer [55] = "\x42\x4d\x36\x39\xb1\x00\x00\x00\x00\x00" \ "\x36\x00\x00\x00\x28\x00\x00\x00\xe0\x08\x00\x00\xa8\x06" \ "\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ "\xc4\x0e\x00\x00\xc4\x0e\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00"; buffer[18] = x%256;//asse x buffer[19] = x/256; buffer[22] = y%256;//asse y buffer[23] = y/256; FILE *stream; stream = fopen(nome,"wb"); fwrite(buffer, 1, 54, stream); fclose(stream); char *** array; int i, j, h; array = (char***)malloc(x * sizeof(char *)); for(i=0; i= rgb_d.green && rgb_d.red >= rgb_d.blue && rgb_d.green >= rgb_d.blue){ //rosso maggiore blu minore MAX = rgb_d.red; MIN = rgb_d.blue; gradi = 0; numeratore = rgb_d.green-rgb_d.blue; } else if( rgb_d.red >= rgb_d.green && rgb_d.red >= rgb_d.blue && rgb_d.green < rgb_d.blue){ //rosso maggiore verde minore MAX = rgb_d.red; MIN = rgb_d.green; gradi = 360; numeratore = rgb_d.green-rgb_d.blue; } else if( rgb_d.green >= rgb_d.red && rgb_d.green >= rgb_d.blue && rgb_d.red <= rgb_d.blue){ //verde maggiore, rosso minore MAX = rgb_d.green; MIN = rgb_d.red; gradi = 120; numeratore = rgb_d.blue-rgb_d.red; } else if( rgb_d.green >= rgb_d.red && rgb_d.green >= rgb_d.blue && rgb_d.blue < rgb_d.red){ //verde maggiore, blu minore MAX = rgb_d.green; MIN = rgb_d.blue; gradi = 120; numeratore = rgb_d.blue-rgb_d.red; } else if( rgb_d.blue >= rgb_d.red && rgb_d.blue >= rgb_d.green && rgb_d.red <= rgb_d.green){ //blu maggiore, rosso minore MAX = rgb_d.blue; MIN = rgb_d.red; gradi = 240; numeratore = rgb_d.red-rgb_d.green; } else if( rgb_d.blue >= rgb_d.red && rgb_d.blue >= rgb_d.green && rgb_d.green < rgb_d.red){ //blu maggiore, verde minore MAX = rgb_d.blue; MIN = rgb_d.green; gradi = 240; numeratore = rgb_d.red-rgb_d.green; } else printf("ERRORE!"); H = ( (int) (60*(numeratore/(MAX-MIN)) + gradi) ) % 360;//tonalità trovata *********** } double S = 0;//saturazione if(MAX == 0) S = 0; //saturazione trovata ********** else S = (MAX - MIN) / MAX; //saturazione trovata ********** double V = MAX; //luminosità/valore trovata ********** hsv_d.hue=H; hsv_d.saturation=S; hsv_d.value=V; hsv.hue= (int)(hsv_d.hue); hsv.saturation= (int)(hsv_d.saturation * 255); hsv.value= (int)(hsv_d.value * 255); return hsv; }