#include"hensu.h" #include void rgb_to_yc(LPDWORD image_rgb,double *y,double *c1,double *c2) { int i,j; int r,g,b; for(j=0;j>16; g=(image_rgb[i+j*iWidth] & 0x0000ff00)>>8; b= image_rgb[i+j*iWidth] & 0x000000ff; y [i+j*iWidth]= 0.3*r+0.59*g+0.11*b; c1[i+j*iWidth]= 0.7*r-0.59*g-0.11*b; c2[i+j*iWidth]=-0.3*r-0.59*g+0.89*b; } } void yc_to_rgb(double *y,double *c1,double *c2,LPDWORD image_rgb) { int i,j; double r,g,b; for(j=0;j255) r=255; else if(r<0) r=0; g=y[i+j*iWidth]-0.3/0.59*c1[i+j*iWidth]-0.11/0.59*c2[i+j*iWidth]; if(g>255) g=255; else if(g<0) g=0; b=y[i+j*iWidth]+c2[i+j*iWidth]; if(b>255) b=255; else if(b<0) b=0; image_rgb[i+j*iWidth]=((int)r<<16)+((int)g<<8)+(int)b; } } #define PI 3.141592 void c_to_sh(double *c1,double *c2,double *sat,double *hue) { int i,j; double dhue,length; for(j=0;j0){ dhue=atan2(c1[i+j*iWidth],c2[i+j*iWidth])*180.0/PI; if(dhue<0) dhue+=360; hue[i+j*iWidth]=dhue; } else hue[i+j*iWidth]=0; } } void sh_to_c(double *sat,double *hue,double *c1,double *c2) { int i,j; double rad; for(j=0;jmax) max=sat[i+j*iWidth]; else if(sat[i+j*iWidth]0){ delt=fabs(hue[i+j*iWidth]-stdhue); if(delt>180) delt=360-delt; ihue=(int)(255-delt*255/180.0); image_out[i+j*iWidth]=RGB(ihue,ihue,ihue); } else image_out[i+j*iWidth]=0; } } void y_image(double *y,LPDWORD image_out) { int i,j,Y; for(j=0;j360) out_hue[i+j*iWidth]-=360; else if(out_hue[i+j*iWidth]<0) out_hue[i+j*iWidth]+=360; if(sm>0) out_sat[i+j*iWidth]=in_sat[i+j*iWidth]+(SAT_MAX-in_sat[i+j*iWidth])*sm/100.0; else if(sm<0) out_sat[i+j*iWidth]=in_sat[i+j*iWidth]+in_sat[i+j*iWidth]*sm/100.0; else out_sat[i+j*iWidth]=in_sat[i+j*iWidth]; if(ym>0) out_y[i+j*iWidth]=in_y[i+j*iWidth]+(Y_MAX-in_y[i+j*iWidth])*ym/100.0; else if(ym<0) out_y[i+j*iWidth]=in_y[i+j*iWidth]+in_y[i+j*iWidth]*ym/100.0; else out_y[i+j*iWidth]=in_y[i+j*iWidth]; } }