public static Pixel32 ApplyColorFilter(Pixel32 pixel, ColorFilter filter)
        {
            switch (filter)
            {
            case ColorFilter.Magenta:
                return(new Pixel32(pixel.A, pixel.R, 0, pixel.B));

            case ColorFilter.Yellow:
                return(new Pixel32(pixel.A, pixel.R, pixel.G, 0));

            case ColorFilter.Cyan:
                return(new Pixel32(pixel.A, 0, pixel.G, pixel.B));

            case ColorFilter.Red:
                return(new Pixel32(pixel.A, pixel.R, 0, 0));

            case ColorFilter.Green:
                return(new Pixel32(pixel.A, 0, pixel.G, 0));

            case ColorFilter.Blue:
                return(new Pixel32(pixel.A, 0, 0, pixel.B));

            default:
                return(pixel);
            }
        }
Beispiel #2
0
        public static byte Lightness(Pixel32 pixel)
        {
            var max = MathUtils.Max(pixel.R, pixel.G, pixel.B);
            var min = MathUtils.Min(pixel.R, pixel.G, pixel.B);

            return(MathUtils.RoundToByte(0.5d * (max + min)));
        }
Beispiel #3
0
 public void Add(Pixel32 pixel)
 {
     Count++;
     RedSum   += pixel.R;
     GreenSum += pixel.G;
     BlueSum  += pixel.B;
 }
Beispiel #4
0
        public static Pixel32 Sepia(Pixel32 pixel, int level)
        {
            var r = MathUtils.ByteClamp(pixel.R + 2 * level);
            var g = MathUtils.ByteClamp(pixel.G + level);
            var b = pixel.B;

            return(new Pixel32(pixel.A, r, g, b));
        }
Beispiel #5
0
        public static Image <Pixel32> Inversion(this Image <Pixel32> image, Pixel32 inversionPoint)
        {
            Pixel32 pixelOperator(Pixel32 pixel)
            {
                var r = Inversion(pixel.R, inversionPoint.R);
                var g = Inversion(pixel.G, inversionPoint.G);
                var b = Inversion(pixel.B, inversionPoint.B);

                return(new Pixel32(pixel.A, r, g, b));
            };
            return(image.Inversion(pixelOperator));
        }
Beispiel #6
0
        public void Add(Pixel32 pixel)
        {
            var intensity = MathUtils.FloorToInt((pixel.R + pixel.G + pixel.B) * q);

            OilPaintIntensity oilPaintIntensity;

            if (intensities.ContainsKey(intensity))
            {
                oilPaintIntensity = intensities[intensity];
            }
            else
            {
                oilPaintIntensity = new OilPaintIntensity();
                intensities.Add(intensity, oilPaintIntensity);
            }
            oilPaintIntensity.Add(pixel);
        }
Beispiel #7
0
        public CMYK(Pixel32 pixel)
        {
            var nr = pixel.R / 255d;
            var ng = pixel.G / 255d;
            var nb = pixel.B / 255d;

            K = 1d - MathUtils.Max(nr, ng, nb);
            var den = 1d - K;

            C = M = Y = 0d;
            if (den != 0d)
            {
                C = GetComponent(nr, den);
                M = GetComponent(ng, den);
                Y = GetComponent(nb, den);
            }
            K = MathUtils.Clamp(100d * K, 0d, 100d);
        }
Beispiel #8
0
        public HSV(Pixel32 pixel)
        {
            var r = pixel.R;
            var g = pixel.G;
            var b = pixel.B;

            var cmin  = MathUtils.Min(r, g, b);
            var cmax  = MathUtils.Max(r, g, b);
            var delta = cmax - cmin;

            H = 0d;
            if (delta == 0)
            {
                H = 0d;
            }
            else if (cmax == r)
            {
                H = (((g - b) / (double)delta) % 6) * 60;
            }
            else if (cmax == g)
            {
                H = (((b - r) / (double)delta) + 2) * 60;
            }
            else if (cmax == b)
            {
                H = (((r - g) / (double)delta) + 4) * 60;
            }
            H = MathUtils.Clamp(H, 0d, 360d);

            S = 0d;
            if (cmax != 0)
            {
                S = MathUtils.Clamp(100d * delta / cmax, 0d, 100d);
            }

            V = MathUtils.Clamp(100d * cmax / 255d, 0d, 100d);
        }
Beispiel #9
0
 public static Image <Pixel32> ColorAccent(this Image <Pixel32> image, Pixel32 color, double hueRange)
 {
     return(image.ColorAccent(color.ToHSV().H, hueRange));
 }
Beispiel #10
0
 public static byte Luminance(Pixel32 pixel)
 {
     return(MathUtils.RoundToByte(0.3d * pixel.R + 0.59d * pixel.G + 0.11d * pixel.B));
 }
Beispiel #11
0
        public static byte Average(Pixel32 pixel)
        {
            double q = 1d / 3d;

            return(MathUtils.RoundToByte(q * (pixel.R + pixel.G + pixel.B)));
        }