// colori.c # include "alfa.h" void Hsvdargb (int ri, int gi, int bi, Double H, Double S, Double V) {double r=ri/65535.0, g=gi/65535.0, b=bi/65535.0; double max=Max3(r,g,b), min=Min3(r,g,b); *V=max; double d=max-min,h; double s = max ? d/max : 0; if (s) {if (r==max) h=(g-b)/d; else if (g==max) h=2+(b-r)/d; else h=4+(r-g)/d; h*=60; if (h<0) h+=360;} else h=-1; *H=h; *S=s;} void Provacolori () {int r,g,b; double h,s,v,h1,s1,v1; h=235; s=0.8; v=0.9; Rgbdahsv(h,s,v,&r,&g,&b); Hsvdargb(r,g,b,&h1,&s1,&v1); printf("%.0f %.2f %.2f #%04x%04x%04x\n%.0f %.2f %.2f\n",h,s,v,r,g,b,h1,s1,v1);} void Rgbdahsv (double h, double s, double v, Int R, Int G, Int B) {double r,g,b; if (!s) if (h<0) {r=g=b=v;} else {*R=*G=*B=80000; return;} else {double f,p,q,t; int i; if (h==360) h=0; h/=60; i=floor(h); f=h-i; p=v*(1-s); q=v*(1-s*f); t=v*(1-s*(1-f)); switch(i) {case 1: r=q; g=v; b=p; break; case 2: r=p; g=v; b=t; break; case 3: r=p; g=q; b=v; break; case 4: r=t; g=p; b=v; break; case 5: r=v; g=p; b=q; break; case 0: default: r=v; g=t; b=p;}} *R=65535*r; *G=65535*g; *B=65535*b;}