public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(Brushes.Black);
            }
            var c   = (Color)value;
            var hsb = SimpleColorTransforms.RgBtoHsb(c);

            return(new SolidColorBrush(SimpleColorTransforms.HsBtoRgb(hsb[0], Math.Min(1, hsb[1] * 1.5), hsb[2] * 0.75)));
        }
Exemple #2
0
        private Color ParseFrame(ColorAlgorithm colorAlg, out int brightness)
        {
            brightness = 0;
            Color color = new Color();

            switch (colorAlg)
            {
            case ColorAlgorithm.DominantColor: {
                // lock bits
                locker.LockBits();
                color = GetDominantColor(locker.Pixels, out brightness);
                locker.UnlockBits();
            }
            break;

            case ColorAlgorithm.AverageColor: {
                // lock bits
                locker.LockBits();
                color = GetAverageColor(locker.Pixels, out brightness);
                locker.UnlockBits();
            }
            break;

            case ColorAlgorithm.DominantColorThief: {
                locker.LockBits();
                brightness = GetBrightness(locker.Pixels);
                locker.UnlockBits();

                QuantizedColor qColor = colorThief.GetColor(bmpScreenSmall);
                color = Color.FromArgb(qColor.Color.R, qColor.Color.G, qColor.Color.B);
            }
            break;

            case ColorAlgorithm.WeightedBrightestColor: {
                return(Color.Black);

                locker.LockBits();
                color = GetWeightedDominantColor(locker.Pixels, out brightness);
                locker.UnlockBits();
            }
            break;

            case ColorAlgorithm.DominantColorKMeans: {
                locker.LockBits();
                brightness = GetBrightness(locker.Pixels);
                locker.UnlockBits();

                // copy colors
                byte[]       pixels      = locker.Pixels;
                int          totalColors = pixels.Length / 3;
                List <Color> colorList   = new List <Color>(totalColors);

                for (int i = 0; i < pixels.Length - 3; i += 3)
                {
                    byte b = pixels[i];
                    byte g = pixels[i + 1];
                    byte r = pixels[i + 2];

                    Color nColor = Color.FromArgb(255,
                                                  (byte)(r * dColorBrightFactor),
                                                  (byte)(g * dColorBrightFactor),
                                                  (byte)(b * dColorBrightFactor));

                    //l = 0.75;

                    //// convert back to rgb
                    //l *= dColorBrightFactor;
                    //Color nColor = ColorUtil.HSL2RGB(h, s, l);

                    // skip dark pixels
                    //if (b < 50 && g < 50 && r < 50) {
                    //    continue;
                    //}

                    // skip dark pixels
                    //if (KCluster.EuclideanDistance(nColor, Color.Black) >= 200 &&
                    //    KCluster.EuclideanDistance(nColor, Color.White) >= 200) {
                    //}

                    // TODO: skipping pixels make the closest color fluctuate
                    colorList.Add(nColor);
                }

                const int k = 1;

                KMeansClusteringCalculator clustering = new KMeansClusteringCalculator();
                IList <Color> dominantColours         = clustering.Calculate(k, colorList, 5.0d);
                color = dominantColours.FirstOrDefault();

                // convert to HSV
                double h, s, l;
                //ColorUtil.RGB2HSL(b, g, r, out h, out s, out l);

                double[] hsl = SimpleColorTransforms.RgBtoHsl(color);

                Color newColor = SimpleColorTransforms.HsLtoRgb(hsl[0], hsl[1], hsl[2]);

                int x = -1;
            }
            break;
            }
            return(color);
        }