FRBDK/FilteringHaloRemover/FilteringHaloRemover/FormMain.cs
/// <summary>
/// Returns the color the supplied pixel should be by investigating surrounding pixels.
/// </summary>
/// <param name="bitmap"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
Returns the color the supplied pixel should be by investigating surrounding pixels.
Returns the color the supplied pixel should be by investigating surrounding pixels .
private Color DeterminePixelColor(Bitmap bitmap, int x, int y, Color originalColor)
        {
            Color tmpColor;
            bool canProcessRight = (x < (bitmap.Width - 1));
            bool canProcessLeft = (x > 0);
            bool canProcessBelow = (y < (bitmap.Height - 1));
            bool canProcessAbove = (y > 0);
            if (canProcessRight)
            {
                tmpColor = bitmap.GetPixel(x + 1, y);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessLeft)
            {
                tmpColor = bitmap.GetPixel(x - 1, y);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessBelow)
            {
                tmpColor = bitmap.GetPixel(x, y + 1);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessAbove)
            {
                tmpColor = bitmap.GetPixel(x, y - 1);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessRight && canProcessAbove)
            {
                tmpColor = bitmap.GetPixel(x + 1, y - 1);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessRight && canProcessBelow)
            {
                tmpColor = bitmap.GetPixel(x + 1, y + 1);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessLeft && canProcessAbove)
            {
                tmpColor = bitmap.GetPixel(x - 1, y - 1);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            if (canProcessLeft && canProcessBelow)
            {
                tmpColor = bitmap.GetPixel(x - 1, y + 1);
                if (tmpColor.A > 0)
                {
                    return Color.FromArgb(0, tmpColor.R, tmpColor.G, tmpColor.B);
                }
            }
            return originalColor;
        }
private Color DeterminePixelColor ( Bitmap bitmap , int x , int y , Color originalColor ) { Color tmpColor ; bool canProcessRight = ( x < ( bitmap . Width - 1 ) ) ; bool canProcessLeft = ( x > 0 ) ; bool canProcessBelow = ( y < ( bitmap . Height - 1 ) ) ; bool canProcessAbove = ( y > 0 ) ; if ( canProcessRight ) { tmpColor = bitmap . GetPixel ( x + 1 , y ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessLeft ) { tmpColor = bitmap . GetPixel ( x - 1 , y ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessBelow ) { tmpColor = bitmap . GetPixel ( x , y + 1 ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessAbove ) { tmpColor = bitmap . GetPixel ( x , y - 1 ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessRight && canProcessAbove ) { tmpColor = bitmap . GetPixel ( x + 1 , y - 1 ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessRight && canProcessBelow ) { tmpColor = bitmap . GetPixel ( x + 1 , y + 1 ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessLeft && canProcessAbove ) { tmpColor = bitmap . GetPixel ( x - 1 , y - 1 ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } if ( canProcessLeft && canProcessBelow ) { tmpColor = bitmap . GetPixel ( x - 1 , y + 1 ) ; if ( tmpColor . A > 0 ) { return Color . FromArgb ( 0 , tmpColor . R , tmpColor . G , tmpColor . B ) ; } } return originalColor ; }
Returns the color the supplied pixel should be by investigating surrounding pixels.
Returns the color the supplied pixel should be by investigating surrounding pixels .
//@kao TODO //set up the processing flags //get the adjacent pixels in priority order and set the color accordingly and return //right first //left //bottom //top //corners //upper-right //lower-right //upper-left //lower-left //if nothign found, return the original color //return Color.Black;
None
bitmap
Bitmap
None
x
int
None
y
int
None
originalColor
Color