#include"hensu.h" void hard_mask(LPDWORD image_in,LPDWORD image_out, LPBYTE image_key,int thresh) { int x,y,d; int r,g,b; for(y=0;y>16; g=(image_in[x+y*iWidth] & 0x0000ff00)>>8; b= image_in[x+y*iWidth] & 0x000000ff; d=(r+g)/2-b; if(d>=thresh){ image_key[x+y*iWidth]=255; image_out[x+y*iWidth]=0x00ffffff; }else{ image_key[x+y*iWidth]=0; image_out[x+y*iWidth]=0; } } } void synth(LPDWORD image_in_front,LPDWORD image_in_back, LPDWORD image_out,LPBYTE image_key) { int x,y; int rf,gf,bf; int rb,gb,bb; int ro,go,bo; int k; for(y=0;y>16; gf=(image_in_front[x+y*iWidth] & 0x0000ff00)>>8; bf= image_in_front[x+y*iWidth] & 0x000000ff; rb=(image_in_back[x+y*iWidth] & 0x00ff0000)>>16; gb=(image_in_back[x+y*iWidth] & 0x0000ff00)>>8; bb= image_in_back[x+y*iWidth] & 0x000000ff; k = image_key[x+y*iWidth]; ro=(rf*k+rb*(255-k))/255; go=(gf*k+gb*(255-k))/255; bo=(bf*k+bb*(255-k))/255; image_out[x+y*iWidth]=(ro<<16)+(go<<8)+bo; } } void soft_mask(LPDWORD image_in,LPDWORD image_out, LPBYTE image_key,int thd_min,int thd_max) { int x,y,d; int k; int r,g,b; for(y=0;y>16; g=(image_in[x+y*iWidth] & 0x0000ff00)>>8; b= image_in[x+y*iWidth] & 0x000000ff; d=(r+g)/2-b; k=(d-thd_min)*255/(thd_max-thd_min); if(k>255){ image_key[x+y*iWidth]=255; image_out[x+y*iWidth]=0x00ffffff; }else if(k<0){ image_key[x+y*iWidth]=0; image_out[x+y*iWidth]=0; }else{ image_key[x+y*iWidth]=k; image_out[x+y*iWidth]=RGB(k,k,k); } } } void s_synth(LPDWORD image_in_front,LPDWORD image_in_back, LPDWORD image_out,LPBYTE image_key) { int x,y; int rf,gf,bf; int rb,gb,bb; int ro,go,bo; int k; for(y=0;y>16; gf=(image_in_front[x+y*iWidth] & 0x0000ff00)>>8; bf= image_in_front[x+y*iWidth] & 0x000000ff; rb=(image_in_back[x+y*iWidth] & 0x00ff0000)>>16; gb=(image_in_back[x+y*iWidth] & 0x0000ff00)>>8; bb= image_in_back[x+y*iWidth] & 0x000000ff; k = image_key[x+y*iWidth]; if(k==255 || k==0){ ro=(rf*k+rb*(255-k))/255; go=(gf*k+gb*(255-k))/255; bo=(bf*k+bb*(255-k))/255; }else{ ro=(gf*k+rb*(255-k))/255; go=(gf*k+gb*(255-k))/255; bo=(gf*k+bb*(255-k))/255; } image_out[x+y*iWidth]=(ro<<16)+(go<<8)+bo; } } void histgram_Hue(double *hue,long hist[360]) { int x,y,n; for(n=0;n<360;n++) hist[n]=0; for(y=0;y=0 && n<360) hist[n]++; } } void thresh_Hue(LPDWORD image_in,LPDWORD image_out, double *hue,int hue_min,int hue_max) { int x,y; for(y=0;yhue_max) image_out[x+y*iWidth]=0; else image_out[x+y*iWidth]=image_in[x+y*iWidth]; else if(hue[x+y*iWidth]<0 || hue[x+y*iWidth]>=360) image_out[x+y*iWidth]=0; else if(hue[x+y*iWidth]hue_max) image_out[x+y*iWidth]=0; else image_out[x+y*iWidth]=image_in[x+y*iWidth]; }