public override ColorBgra Apply (ColorBgra color)
		{
			// Adjust saturation
			var intensity = color.GetIntensityByte ();
			color.R = Utility.ClampToByte ((intensity * 1024 + (color.R - intensity) * sat_factor) >> 10);
			color.G = Utility.ClampToByte ((intensity * 1024 + (color.G - intensity) * sat_factor) >> 10);
			color.B = Utility.ClampToByte ((intensity * 1024 + (color.B - intensity) * sat_factor) >> 10);

			var hsvColor = (new RgbColor (color.R, color.G, color.B)).ToHsv ();
			int hue = hsvColor.Hue;

			hue += hue_delta;

			while (hue < 0)
				hue += 360;

			while (hue > 360)
				hue -= 360;

			hsvColor.Hue = hue;

			var rgbColor = hsvColor.ToRgb ();
			var newColor = ColorBgra.FromBgr ((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red);
			
			newColor = blend_op.Apply (newColor);
			newColor.A = color.A;

			return newColor;
		}
Ejemplo n.º 2
0
        public override ColorBgra Apply(ColorBgra color)
        {
            byte lumi = color.GetIntensityByte();
            int  diff = Curve[lumi] - lumi;

            return(ColorBgra.FromBgraClamped(
                       color.B + diff,
                       color.G + diff,
                       color.R + diff,
                       color.A));
        }
		public override ColorBgra Apply (ColorBgra color)
		{
			byte lumi = color.GetIntensityByte ();
			int diff = Curve[lumi] - lumi;

			return ColorBgra.FromBgraClamped (
			    color.B + diff,
			    color.G + diff,
			    color.R + diff,
			    color.A);
		}
Ejemplo n.º 4
0
            public override ColorBgra Apply(ColorBgra color)
            {
                byte value = (byte)(Math.Abs(color.GetIntensityByte() - FilterColor.GetIntensityByte()));

                if (Grayscale)
                {
                    if (!Invert)
                    {
                        value = (byte)(255 - value);
                    }
                    return(ColorBgra.FromBgr(value, value, value));
                }
                return(value < Tolerance ? TransparentColor : OpaqueColor);
            }
        public override void Render(Surface src, Surface dst, Rectangle[] rois, int startIndex, int length)
        {
            unsafe
            {
                for (int r = startIndex; r < startIndex + length; ++r)
                {
                    Rectangle rect = rois[r];

                    for (int y = rect.Top; y < rect.Bottom; ++y)
                    {
                        ColorBgra *srcRowPtr    = src.GetPointAddressUnchecked(rect.Left, y);
                        ColorBgra *dstRowPtr    = dst.GetPointAddressUnchecked(rect.Left, y);
                        ColorBgra *dstRowEndPtr = dstRowPtr + rect.Width;

                        if (divide == 0)
                        {
                            while (dstRowPtr < dstRowEndPtr)
                            {
                                ColorBgra col = *srcRowPtr;
                                int       i   = col.GetIntensityByte();
                                uint      c   = this.rgbTable[i];
                                dstRowPtr->Bgra = (col.Bgra & 0xff000000) | c | (c << 8) | (c << 16);

                                ++dstRowPtr;
                                ++srcRowPtr;
                            }
                        }
                        else
                        {
                            while (dstRowPtr < dstRowEndPtr)
                            {
                                ColorBgra col        = *srcRowPtr;
                                int       i          = col.GetIntensityByte();
                                int       shiftIndex = i * 256;

                                col.R = this.rgbTable[shiftIndex + col.R];
                                col.G = this.rgbTable[shiftIndex + col.G];
                                col.B = this.rgbTable[shiftIndex + col.B];

                                *dstRowPtr = col;
                                ++dstRowPtr;
                                ++srcRowPtr;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public unsafe override void Render(ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
        {
            if (!table_calculated)
            {
                Calculate();
            }

            foreach (Gdk.Rectangle rect in rois)
            {
                for (int y = rect.Top; y <= rect.GetBottom(); y++)
                {
                    ColorBgra *srcRowPtr    = src.GetPointAddressUnchecked(rect.Left, y);
                    ColorBgra *dstRowPtr    = dest.GetPointAddressUnchecked(rect.Left, y);
                    ColorBgra *dstRowEndPtr = dstRowPtr + rect.Width;

                    if (divide == 0)
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col = *srcRowPtr;
                            int       i   = col.GetIntensityByte();
                            uint      c   = rgbTable[i];
                            dstRowPtr->Bgra = (col.Bgra & 0xff000000) | c | (c << 8) | (c << 16);

                            ++dstRowPtr;
                            ++srcRowPtr;
                        }
                    }
                    else
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col        = *srcRowPtr;
                            int       i          = col.GetIntensityByte();
                            int       shiftIndex = i * 256;

                            col.R = rgbTable[shiftIndex + col.R];
                            col.G = rgbTable[shiftIndex + col.G];
                            col.B = rgbTable[shiftIndex + col.B];

                            *dstRowPtr = col;
                            ++dstRowPtr;
                            ++srcRowPtr;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public unsafe override void Render(ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
        {
            if (!table_calculated)
            {
                Calculate();
            }

            foreach (Gdk.Rectangle rect in rois)
            {
                for (int y = rect.Top; y <= rect.GetBottom(); y++)
                {
                    ColorBgra *srcRowPtr    = src.GetPointAddressUnchecked(rect.Left, y);
                    ColorBgra *dstRowPtr    = dest.GetPointAddressUnchecked(rect.Left, y);
                    ColorBgra *dstRowEndPtr = dstRowPtr + rect.Width;

                    if (divide == 0)
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col = *srcRowPtr;
                            int       i   = col.GetIntensityByte();
                            uint      c   = rgbTable ![i];                     // NRT - Set in Calculate
            public override ColorBgra Apply(ColorBgra color)
            {
                int i = 0;
                int h, s, v, delta;

                switch (InputMode)
                {
                case Channel.A:
                    i = Curve[color.A];
                    break;

                case Channel.R:
                    i = Curve[color.R];
                    break;

                case Channel.G:
                    i = Curve[color.G];
                    break;

                case Channel.B:
                    i = Curve[color.B];
                    break;

                case Channel.C:
                    i  = 255 - color.R;
                    i -= Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B);
                    i  = Curve[i];
                    break;

                case Channel.M:
                    i  = 255 - color.G;
                    i -= Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B);
                    i  = Curve[i];
                    break;

                case Channel.Y:
                    i  = 255 - color.B;
                    i -= Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B);
                    i  = Curve[i];
                    break;

                case Channel.K:
                    i = Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B);
                    i = Curve[i];
                    break;

                case Channel.H:
                    s     = 0;
                    v     = (color.R > color.G) ? color.R : color.G;
                    delta = 0;
                    if (color.B > v)
                    {
                        v = color.B;
                    }
                    if (v == 0)
                    {
                        s = 0;
                    }
                    else
                    {
                        int min = (color.R < color.G) ? color.R : color.G;
                        if (color.B < min)
                        {
                            min = color.B;
                        }
                        delta = v - min;
                        if (delta > 0)
                        {
                            s = CommonUtil.IntDiv(255 * delta, v);
                        }
                    }
                    if (s == 0)
                    {
                        i = 0;
                    }
                    else
                    {
                        if (color.R == v)     // Between Yellow and Magenta
                        {
                            i = CommonUtil.IntDiv(255 * (color.G - color.B), delta);
                        }
                        else if (color.G == v)     // Between Cyan and Yellow
                        {
                            i = 512 + CommonUtil.IntDiv(255 * (color.B - color.R), delta);
                        }
                        else     // Between Magenta and Cyan
                        {
                            i = 1024 + CommonUtil.IntDiv(255 * (color.R - color.G), delta);
                        }

                        if (i < 0)
                        {
                            i += 1536;
                        }

                        i = CommonUtil.IntDiv(i, 6);
                    }
                    i = Curve[i];
                    break;

                case Channel.S:
                    v = (color.R > color.G) ? color.R : color.G;
                    if (color.B > v)
                    {
                        v = color.B;
                    }
                    if (v == 0)
                    {
                        i = 0;
                    }
                    else
                    {
                        int min = (color.R < color.G) ? color.R : color.G;
                        if (color.B < min)
                        {
                            min = color.B;
                        }
                        delta = v - min;
                        if (delta > 0)
                        {
                            i = CommonUtil.IntDiv(255 * delta, v);
                        }
                    }
                    i = Curve[i];
                    break;

                case Channel.V:
                    i = (color.R > color.G) ? color.R : color.G;
                    if (color.B > i)
                    {
                        i = color.B;
                    }
                    i = Curve[i];
                    break;

                case Channel.L:
                    i = color.GetIntensityByte();
                    i = Curve[i];
                    break;

                default: throw new Exception();
                }
                switch (OutputMode)
                {
                case Channel.A:
                    return(ColorBgra.FromBgra(
                               color.B,
                               color.G,
                               color.R,
                               (byte)i));

                case Channel.R:
                    return(ColorBgra.FromBgra(
                               color.B,
                               color.G,
                               (byte)i,
                               color.A));

                case Channel.G:
                    return(ColorBgra.FromBgra(
                               color.B,
                               (byte)i,
                               color.R,
                               color.A));

                case Channel.B:
                    return(ColorBgra.FromBgra(
                               (byte)i,
                               color.G,
                               color.R,
                               color.A));

                case Channel.C:
                    i = (byte)(i + Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B)).Clamp(0, 255);
                    return(ColorBgra.FromBgra(
                               color.B,
                               color.G,
                               (byte)(255 - i),
                               color.A));

                case Channel.M:
                    i = (byte)(i + Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B)).Clamp(0, 255);
                    return(ColorBgra.FromBgra(
                               color.B,
                               (byte)(255 - i),
                               color.R,
                               color.A));

                case Channel.Y:
                    i = (byte)(i + Math.Min(Math.Min(255 - color.R, 255 - color.G), 255 - color.B)).Clamp(0, 255);
                    return(ColorBgra.FromBgra(
                               (byte)(255 - i),
                               color.G,
                               color.R,
                               color.A));

                case Channel.K:
                    int C = 255 - color.R;
                    int M = 255 - color.G;
                    int Y = 255 - color.B;
                    int K = Math.Min(Math.Min(C, M), Y);
                    return(ColorBgra.FromBgraClamped(
                               255 - (Y - K + i),
                               255 - (M - K + i),
                               255 - (C - K + i),
                               color.A));

                case Channel.H:
                    s     = 0;
                    v     = (color.R > color.G) ? color.R : color.G;
                    delta = 0;
                    if (color.B > v)
                    {
                        v = color.B;
                    }
                    if (v == 0)
                    {
                        s = 0;
                    }
                    else
                    {
                        int min = (color.R < color.G) ? color.R : color.G;
                        if (color.B < min)
                        {
                            min = color.B;
                        }
                        delta = v - min;
                        if (delta > 0)
                        {
                            s = CommonUtil.IntDiv(255 * delta, v);
                        }
                    }
                    i *= 6;
                    int fSector = (i & 0xff);
                    int sNumber = (i >> 8);
                    switch (sNumber)
                    {
                    case 0:
                        int tmp0 = ((s * (255 - fSector)) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - s)) + 128) >> 8),
                                   (byte)(((v * (255 - tmp0)) + 128) >> 8),
                                   (byte)v,
                                   color.A));

                    case 1:
                        int tmp1 = ((s * fSector) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - s)) + 128) >> 8),
                                   (byte)v,
                                   (byte)(((v * (255 - tmp1)) + 128) >> 8),
                                   color.A));

                    case 2:
                        int tmp2 = ((s * (255 - fSector)) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - tmp2)) + 128) >> 8),
                                   (byte)v,
                                   (byte)(((v * (255 - s)) + 128) >> 8),
                                   color.A));

                    case 3:
                        int tmp3 = ((s * fSector) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)v,
                                   (byte)(((v * (255 - tmp3)) + 128) >> 8),
                                   (byte)(((v * (255 - s)) + 128) >> 8),
                                   color.A));

                    case 4:
                        int tmp4 = ((s * (255 - fSector)) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)v,
                                   (byte)(((v * (255 - s)) + 128) >> 8),
                                   (byte)(((v * (255 - tmp4)) + 128) >> 8),
                                   color.A));

                    case 5:
                        int tmp5 = ((s * fSector) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - tmp5)) + 128) >> 8),
                                   (byte)(((v * (255 - s)) + 128) >> 8),
                                   (byte)v,
                                   color.A));

                    default:
                        return(new ColorBgra());
                    }

                case Channel.S:
                    s     = 0;
                    v     = (color.R > color.G) ? color.R : color.G;
                    delta = 0;
                    if (color.B > v)
                    {
                        v = color.B;
                    }
                    if (v == 0)
                    {
                        s = 0;
                    }
                    else
                    {
                        int min = (color.R < color.G) ? color.R : color.G;
                        if (color.B < min)
                        {
                            min = color.B;
                        }
                        delta = v - min;
                        if (delta > 0)
                        {
                            s = CommonUtil.IntDiv(255 * delta, v);
                        }
                    }
                    if (s == 0)
                    {
                        h = 0;
                    }
                    else
                    {
                        if (color.R == v)     // Between Yellow and Magenta
                        {
                            h = CommonUtil.IntDiv(255 * (color.G - color.B), delta);
                        }
                        else if (color.G == v)     // Between Cyan and Yellow
                        {
                            h = 512 + CommonUtil.IntDiv(255 * (color.B - color.R), delta);
                        }
                        else     // Between Magenta and Cyan
                        {
                            h = 1024 + CommonUtil.IntDiv(255 * (color.R - color.G), delta);
                        }

                        if (h < 0)
                        {
                            h += 1536;
                        }
                    }

                    int fs = (h & 0xff);
                    int sn = (h >> 8);
                    switch (sn)
                    {
                    case 0:
                        int tmp0 = ((i * (255 - fs)) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - i)) + 128) >> 8),
                                   (byte)(((v * (255 - tmp0)) + 128) >> 8),
                                   (byte)v,
                                   color.A));

                    case 1:
                        int tmp1 = ((i * fs) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - i)) + 128) >> 8),
                                   (byte)v,
                                   (byte)(((v * (255 - tmp1)) + 128) >> 8),
                                   color.A));

                    case 2:
                        int tmp2 = ((i * (255 - fs)) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - tmp2)) + 128) >> 8),
                                   (byte)v,
                                   (byte)(((v * (255 - i)) + 128) >> 8),
                                   color.A));

                    case 3:
                        int tmp3 = ((i * fs) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)v,
                                   (byte)(((v * (255 - tmp3)) + 128) >> 8),
                                   (byte)(((v * (255 - i)) + 128) >> 8),
                                   color.A));

                    case 4:
                        int tmp4 = ((i * (255 - fs)) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)v,
                                   (byte)(((v * (255 - i)) + 128) >> 8),
                                   (byte)(((v * (255 - tmp4)) + 128) >> 8),
                                   color.A));

                    case 5:
                        int tmp5 = ((i * fs) + 128) >> 8;
                        return(ColorBgra.FromBgra(
                                   (byte)(((v * (255 - tmp5)) + 128) >> 8),
                                   (byte)(((v * (255 - i)) + 128) >> 8),
                                   (byte)v,
                                   color.A));

                    default:
                        return(new ColorBgra());
                    }

                case Channel.V:
                    int max = (color.R > color.G) ? color.R : color.G;
                    if (color.B > max)
                    {
                        max = color.B;
                    }
                    return(ColorBgra.FromBgra(
                               (byte)CommonUtil.IntDiv(color.B * i, max),
                               (byte)CommonUtil.IntDiv(color.G * i, max),
                               (byte)CommonUtil.IntDiv(color.R * i, max),
                               color.A
                               ));

                case Channel.L:
                    return(ColorBgra.FromBgraClamped(
                               color.B + i - color.GetIntensityByte(),
                               color.G + i - color.GetIntensityByte(),
                               color.R + i - color.GetIntensityByte(),
                               color.A));

                default:
                    throw new Exception();
                }
            }
Ejemplo n.º 9
0
            public override ColorBgra Apply(ColorBgra lhs, ColorBgra rhs)
            {
                byte intensityByte = rhs.GetIntensityByte();

                return(ColorBgra.FromBgra(lhs.B, lhs.G, lhs.R, ByteUtil.FastScale(intensityByte, lhs.A)));
            }
Ejemplo n.º 10
0
        protected unsafe override void OnRender(Rectangle[] rois, int startIndex, int length)
        {
            Surface dst = DstArgs.Surface;
            Surface src = SrcArgs.Surface;

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];

                // loop through each line of target rectangle
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    int fyStart = 0;
                    int fyEnd   = 3;

                    if (y == src.Bounds.Top)
                    {
                        fyStart = 1;
                    }

                    if (y == src.Bounds.Bottom - 1)
                    {
                        fyEnd = 2;
                    }

                    // loop through each point in the line
                    ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);

                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        int fxStart = 0;
                        int fxEnd   = 3;

                        if (x == src.Bounds.Left)
                        {
                            fxStart = 1;
                        }

                        if (x == src.Bounds.Right - 1)
                        {
                            fxEnd = 2;
                        }

                        // loop through each weight
                        double sum = 0.0;

                        for (int fy = fyStart; fy < fyEnd; ++fy)
                        {
                            for (int fx = fxStart; fx < fxEnd; ++fx)
                            {
                                double    weight    = this.weights[fy][fx];
                                ColorBgra c         = src.GetPointUnchecked(x - 1 + fx, y - 1 + fy);
                                double    intensity = (double)c.GetIntensityByte();
                                sum += weight * intensity;
                            }
                        }

                        int iSum = (int)sum + 128;

                        if (iSum > 255)
                        {
                            iSum = 255;
                        }
                        else if (iSum < 0)
                        {
                            iSum = 0;
                        }

                        *dstPtr = ColorBgra.FromBgra((byte)iSum, (byte)iSum, (byte)iSum, 255);

                        ++dstPtr;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public unsafe override void Render(EffectConfigToken configToken, RenderArgs dstArgs, RenderArgs srcArgs,
                                           Rectangle[] rois, int startIndex, int length)
        {
            EmbossEffectConfigToken eect = (EmbossEffectConfigToken)configToken;

            double[,] weights = eect.Weights;

            Surface dst = dstArgs.Surface;
            Surface src = srcArgs.Surface;

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];

                // loop through each line of target rectangle
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    int fyStart = 0;
                    int fyEnd   = 3;

                    if (y == src.Bounds.Top)
                    {
                        fyStart = 1;
                    }
                    if (y == src.Bounds.Bottom - 1)
                    {
                        fyEnd = 2;
                    }

                    // loop through each point in the line
                    ColorBgra *dstPtr = dst.GetPointAddress(rect.Left, y);
                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        int fxStart = 0;
                        int fxEnd   = 3;

                        if (x == src.Bounds.Left)
                        {
                            fxStart = 1;
                        }
                        if (x == src.Bounds.Right - 1)
                        {
                            fxEnd = 2;
                        }

                        // loop through each weight
                        double sum = 0.0;

                        for (int fy = fyStart; fy < fyEnd; ++fy)
                        {
                            for (int fx = fxStart; fx < fxEnd; ++fx)
                            {
                                double    weight    = weights[fy, fx];
                                ColorBgra c         = src.GetPointUnchecked(x - 1 + fx, y - 1 + fy);
                                double    intensity = (double)c.GetIntensityByte();
                                sum += weight * intensity;
                            }
                        }

                        int iSum = (int)sum;
                        iSum += 128;
                        if (iSum > 255)
                        {
                            iSum = 255;
                        }
                        if (iSum < 0)
                        {
                            iSum = 0;
                        }
                        *dstPtr = ColorBgra.FromBgra((byte)iSum, (byte)iSum, (byte)iSum, 255);

                        ++dstPtr;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        unsafe public override void Render(ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois)
        {
            double[,] weights = Weights;

            var srcWidth  = src.Width;
            var srcHeight = src.Height;

            ColorBgra *src_data_ptr = (ColorBgra *)src.DataPtr;

            foreach (var rect in rois)
            {
                // loop through each line of target rectangle
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    int fyStart = 0;
                    int fyEnd   = 3;

                    if (y == 0)
                    {
                        fyStart = 1;
                    }

                    if (y == srcHeight - 1)
                    {
                        fyEnd = 2;
                    }

                    // loop through each point in the line
                    ColorBgra *dstPtr = dst.GetPointAddress(rect.Left, y);

                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        int fxStart = 0;
                        int fxEnd   = 3;

                        if (x == 0)
                        {
                            fxStart = 1;
                        }

                        if (x == srcWidth - 1)
                        {
                            fxEnd = 2;
                        }

                        // loop through each weight
                        double sum = 0.0;

                        for (int fy = fyStart; fy < fyEnd; ++fy)
                        {
                            for (int fx = fxStart; fx < fxEnd; ++fx)
                            {
                                double    weight    = weights[fy, fx];
                                ColorBgra c         = src.GetPointUnchecked(src_data_ptr, srcWidth, x - 1 + fx, y - 1 + fy);
                                double    intensity = (double)c.GetIntensityByte();
                                sum += weight * intensity;
                            }
                        }

                        int iSum = (int)sum;
                        iSum += 128;

                        if (iSum > 255)
                        {
                            iSum = 255;
                        }

                        if (iSum < 0)
                        {
                            iSum = 0;
                        }

                        *dstPtr = ColorBgra.FromBgra((byte)iSum, (byte)iSum, (byte)iSum, 255);

                        ++dstPtr;
                    }
                }
            }
        }
Ejemplo n.º 13
0
            public override ColorBgra Apply(ColorBgra color)
            {
                byte i = color.GetIntensityByte();

                return(ColorBgra.FromBgra(i, i, i, color.A));
            }
Ejemplo n.º 14
0
 public override ColorBgra Apply(ColorBgra lhs, ColorBgra rhs)
 {
     byte intensity = rhs.GetIntensityByte();
     ColorBgra result = ColorBgra.FromBgra(lhs.B, lhs.G, lhs.R, (byte)Utility.FastScaleByteByByte(intensity, lhs.A));
     return result;
 }
		public override ColorBgra Apply (ColorBgra color)
		{
			var i = color.GetIntensityByte ();
			return ColorBgra.FromBgra (i, i, i, color.A);
		}
        protected unsafe override void RenderLine(ISurface src, ISurface dst, Rectangle rect)
        {
            double[,] weights = Weights;

            var srcWidth  = src.Width;
            var srcHeight = src.Height;

            // loop through each line of target rectangle
            for (int y = rect.Top; y <= rect.Bottom; ++y)
            {
                int fyStart = 0;
                int fyEnd   = 3;

                if (y == 0)
                {
                    fyStart = 1;
                }

                if (y == srcHeight - 1)
                {
                    fyEnd = 2;
                }

                // loop through each point in the line
                ColorBgra *dstPtr = dst.GetPointAddress(rect.Left, y);

                for (int x = rect.Left; x <= rect.Right; ++x)
                {
                    int fxStart = 0;
                    int fxEnd   = 3;

                    if (x == 0)
                    {
                        fxStart = 1;
                    }

                    if (x == srcWidth - 1)
                    {
                        fxEnd = 2;
                    }

                    // loop through each weight
                    double sum = 0.0;

                    for (int fy = fyStart; fy < fyEnd; ++fy)
                    {
                        for (int fx = fxStart; fx < fxEnd; ++fx)
                        {
                            double    weight    = weights[fy, fx];
                            ColorBgra c         = src.GetPoint(x - 1 + fx, y - 1 + fy);
                            double    intensity = (double)c.GetIntensityByte();
                            sum += weight * intensity;
                        }
                    }

                    int iSum = (int)sum;
                    iSum += 128;

                    if (iSum > 255)
                    {
                        iSum = 255;
                    }

                    if (iSum < 0)
                    {
                        iSum = 0;
                    }

                    *dstPtr = ColorBgra.FromBgra((byte)iSum, (byte)iSum, (byte)iSum, 255);

                    ++dstPtr;
                }
            }
        }