COLORREF CPhotoDialog::GetComplementColor(COLORREF rgb) { int r,b,g; r=GetRValue(rgb); g=GetGValue(rgb); b=GetBValue(rgb); int range=60; int minRange=128-range; int maxRange=128+range; if((minRange<r && r<maxRange) && (minRange<g && g<maxRange) && (minRange<b && b<maxRange)) { if( r<128 && g<128 && b<128) rgb=0xffffff; else rgb=0x0; } else rgb=0xffffff^rgb; return rgb; }
ある点 (x,y) から CORNERSIZE の範囲でのピクセル値を平均する関数を示します。 COLORREF CPhotoDialog::Average(int x, int y) { double ratio=(double)m_pImage->GetWidth()/m_displaySize.cx; x=(int)(x*ratio); y=(int)(y*ratio); COLORREF rgb; long r=0,g=0,b=0; for(int i=x-CORNERSIZE;i<x+CORNERSIZE;i++) for(int j=y-CORNERSIZE;j<y+CORNERSIZE;j++) { if(i<0 || j<0 || m_pImage->GetWidth()<=i || m_pImage->GetHeight()<=j) rgb=m_pImage->GetPixel(x,y); else rgb=m_pImage->GetPixel(i,j); b+=GetBValue(rgb); g+=GetGValue(rgb); r+=GetRValue(rgb); } int nPixels=4*CORNERSIZE*CORNERSIZE; r=(long)((double)r/nPixels); g=(long)((double)g/nPixels); b=(long)((double)b/nPixels); return RGB(r,g,b); }
COLORREF CPhotoDialog::Average(int x, int y) { double ratio=(double)m_pImage->GetWidth()/m_displaySize.cx; x=(int)(x*ratio); y=(int)(y*ratio); COLORREF rgb; long r=0,g=0,b=0; for(int i=x-CORNERSIZE;i<x+CORNERSIZE;i++) for(int j=y-CORNERSIZE;j<y+CORNERSIZE;j++) { if(i<0 || j<0 || m_pImage->GetWidth()<=i || m_pImage->GetHeight()<=j) rgb=m_pImage->GetPixel(x,y); else rgb=m_pImage->GetPixel(i,j); b+=GetBValue(rgb); g+=GetGValue(rgb); r+=GetRValue(rgb); } int nPixels=4*CORNERSIZE*CORNERSIZE; r=(long)((double)r/nPixels); g=(long)((double)g/nPixels); b=(long)((double)b/nPixels); return RGB(r,g,b); }