FromBgr() public static method

Creates a new ColorBgra instance with the given color values, and 255 for alpha.
public static FromBgr ( byte b, byte g, byte r ) : ColorBgra
b byte
g byte
r byte
return ColorBgra
Ejemplo n.º 1
0
            public override ColorBgra Apply(ColorBgra color)
            {
                //adjust saturation
                byte intensity = color.GetIntensityByte();

                color.R = Utility.ClampToByte((intensity * 1024 + (color.R - intensity) * satFactor) >> 10);
                color.G = Utility.ClampToByte((intensity * 1024 + (color.G - intensity) * satFactor) >> 10);
                color.B = Utility.ClampToByte((intensity * 1024 + (color.B - intensity) * satFactor) >> 10);

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

                hue += hueDelta;

                while (hue < 0)
                {
                    hue += 360;
                }

                while (hue > 360)
                {
                    hue -= 360;
                }

                hsvColor.Hue = hue;

                RgbColor  rgbColor = hsvColor.ToRgb();
                ColorBgra newColor = ColorBgra.FromBgr((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red);

                newColor   = blendOp.Apply(newColor);
                newColor.A = color.A;

                return(newColor);
            }
Ejemplo n.º 2
0
 public static ColorBgra ToBgraColor(this Gdk.Color color)
 {
     return(ColorBgra.FromBgr((byte)(color.Blue * 255 / ushort.MaxValue), (byte)(color.Green * 255 / ushort.MaxValue), (byte)(color.Red * 255 / ushort.MaxValue)));
 }
Ejemplo n.º 3
0
        public void SetFromLeveledHistogram(HistogramRgb inputHistogram, UnaryPixelOps.Level upo)
        {
            if (inputHistogram == null || upo == null)
            {
                return;
            }

            Clear();

            float[] before = new float[3];
            float[] slopes = new float[3];

            for (int c = 0; c < 3; c++)
            {
                long[] channelHistogramOutput = histogram[c];
                long[] channelHistogramInput  = inputHistogram.histogram[c];

                for (int v = 0; v <= 255; v++)
                {
                    ColorBgra after = ColorBgra.FromBgr((byte)v, (byte)v, (byte)v);

                    upo.UnApply(after, before, slopes);

                    if (after[c] > upo.ColorOutHigh[c] ||
                        after[c] < upo.ColorOutLow[c] ||
                        (int)Math.Floor(before[c]) < 0 ||
                        (int)Math.Ceiling(before[c]) > 255 ||
                        float.IsNaN(before[c]))
                    {
                        channelHistogramOutput[v] = 0;
                    }
                    else if (before[c] <= upo.ColorInLow[c])
                    {
                        channelHistogramOutput[v] = 0;

                        for (int i = 0; i <= upo.ColorInLow[c]; i++)
                        {
                            channelHistogramOutput[v] += channelHistogramInput[i];
                        }
                    }
                    else if (before[c] >= upo.ColorInHigh[c])
                    {
                        channelHistogramOutput[v] = 0;

                        for (int i = upo.ColorInHigh[c]; i < 256; i++)
                        {
                            channelHistogramOutput[v] += channelHistogramInput[i];
                        }
                    }
                    else
                    {
                        channelHistogramOutput[v] = (int)(slopes[c] * Utility.Lerp(
                                                              channelHistogramInput[(int)Math.Floor(before[c])],
                                                              channelHistogramInput[(int)Math.Ceiling(before[c])],
                                                              before[c] - Math.Floor(before[c])));
                    }
                }
            }

            OnHistogramUpdated();
        }
Ejemplo n.º 4
0
        public override ColorBgra GetPercentileColor(float fraction)
        {
            int[] perc = GetPercentile(fraction);

            return(ColorBgra.FromBgr((byte)(perc[0]), (byte)(perc[1]), (byte)(perc[2])));
        }
Ejemplo n.º 5
0
 public override ColorBgra GetMeanColor()
 {
     float[] mean = GetMean();
     return(ColorBgra.FromBgr((byte)(mean[0] + 0.5f), (byte)(mean[1] + 0.5f), (byte)(mean[2] + 0.5f)));
 }