예제 #1
0
        static Color TintColor(Color c, Color tint)
        {
            double th, ts, tl;

            HSL.RGB2HSL(tint, out th, out ts, out tl);

            double ch, cs, cl;

            HSL.RGB2HSL(c, out ch, out cs, out cl);

            Color color = HSL.HSL2RGB(th, ts, cl);

            color.A = c.A;

            return(color);
        }
예제 #2
0
        static Color TintColor(Color c, Color tint)
        {
            return(SimpleTint(c, tint));

#if asd
            double th, ts, tl;
            HSL.RGB2HSL(tint, out th, out ts, out tl);

            double ch, cs, cl;
            HSL.RGB2HSL(c, out ch, out cs, out cl);

            Color color = HSL.HSL2RGB(th, ts, cl);
            color.A = c.A;

            return(color);
#endif
        }
예제 #3
0
 private PointF FindColor(Color val)
 {
     return(FindColor(HSL.RGB2HSL(val)));
 }
예제 #4
0
        public void ChangeImage(byte[] pixeldata, byte[] bmiInfoHeader)
        {
            if (!IsConnected())
            {
                return;
            }

            try
            {
                if (coreObject.GetCurrentEffect() == ContentEffect.VUMeter ||
                    coreObject.GetCurrentEffect() == ContentEffect.VUMeterRainbow)
                {
                    for (var y = 0; y < coreObject.GetCaptureHeight(); y++)
                    {
                        var row = coreObject.GetCaptureWidth() * y * 4;

                        if ((pixeldata[row] != 0 || pixeldata[row + 1] != 0 || pixeldata[row + 2] != 0) ||
                            (pixeldata[row + ((coreObject.GetCaptureWidth() - 1) * 4)] != 0 ||
                             pixeldata[row + ((coreObject.GetCaptureWidth() - 1) * 4) + 1] != 0 ||
                             pixeldata[row + ((coreObject.GetCaptureWidth() - 1) * 4) + 2] != 0))
                        {
                            int    r, g, b;
                            double s, l;
                            vuMeterHue += 1.0 / 1200.0;
                            if (vuMeterHue > 1)
                            {
                                vuMeterHue -= 1;
                            }
                            s = 1;
                            l = 0.5 - ((double)y / coreObject.GetCaptureHeight() / 2);
                            HSL.HSL2RGB(vuMeterHue, s, l, out r, out g, out b);
                            ChangeColor((byte)gammaCurve[r], (byte)gammaCurve[g], (byte)gammaCurve[b]);
                            return;
                        }
                    }
                    ChangeColor(0, 0, 0);
                }
                else
                {
                    foreach (var lamp in lamps)
                    {
                        if (lamp.IsConnected())
                        {
                            lamp.OverallAverageColor = new int[3];
                            lamp.AverageColor        = new int[3];
                            lamp.PreviousColor       = new int[3];
                            lamp.PixelCount          = 0;
                        }
                    }
                    for (var y = 0; y < coreObject.GetCaptureHeight(); y++)
                    {
                        var row = coreObject.GetCaptureWidth() * y * 4;
                        for (var x = 0; x < coreObject.GetCaptureWidth(); x++)
                        {
                            foreach (var lamp in lamps.Where(lamp => lamp.IsConnected()))
                            {
                                if ((lamp.ZoneInverted == false && x >= lamp.HScanStart * coreObject.GetCaptureWidth() / 100 &&
                                     x <= lamp.HScanEnd * coreObject.GetCaptureWidth() / 100 &&
                                     y >= lamp.VScanStart * coreObject.GetCaptureHeight() / 100 &&
                                     y <= lamp.VScanEnd * coreObject.GetCaptureHeight() / 100)
                                    ||
                                    (lamp.ZoneInverted &&
                                     (x <= lamp.HScanStart * coreObject.GetCaptureWidth() / 100 ||
                                      x >= lamp.HScanEnd * coreObject.GetCaptureWidth() / 100) &&
                                     (y <= lamp.VScanStart * coreObject.GetCaptureHeight() / 100 ||
                                      y >= lamp.VScanEnd * coreObject.GetCaptureHeight() / 100)))
                                {
                                    if (Math.Abs(pixeldata[row + x * 4 + 2] - pixeldata[row + x * 4 + 1]) > coreObject.atmoOrbMinDiversion ||
                                        Math.Abs(pixeldata[row + x * 4 + 2] - pixeldata[row + x * 4]) > coreObject.atmoOrbMinDiversion ||
                                        Math.Abs(pixeldata[row + x * 4 + 1] - pixeldata[row + x * 4]) > coreObject.atmoOrbMinDiversion)
                                    {
                                        lamp.AverageColor[0] += pixeldata[row + x * 4 + 2];
                                        lamp.AverageColor[1] += pixeldata[row + x * 4 + 1];
                                        lamp.AverageColor[2] += pixeldata[row + x * 4];
                                        lamp.PixelCount++;
                                    }
                                }

                                lamp.OverallAverageColor[0] += pixeldata[row + x * 4 + 2];
                                lamp.OverallAverageColor[1] += pixeldata[row + x * 4 + 1];
                                lamp.OverallAverageColor[2] += pixeldata[row + x * 4];
                            }
                        }
                    }
                    foreach (var lamp in lamps.Where(lamp => lamp.IsConnected()))
                    {
                        Boolean skipSmoothing = false;
                        lamp.OverallAverageColor[0] /= (coreObject.GetCaptureHeight() * coreObject.GetCaptureWidth());
                        lamp.OverallAverageColor[1] /= (coreObject.GetCaptureHeight() * coreObject.GetCaptureWidth());
                        lamp.OverallAverageColor[2] /= (coreObject.GetCaptureHeight() * coreObject.GetCaptureWidth());

                        if (lamp.PixelCount > 0)
                        {
                            lamp.AverageColor[0] /= lamp.PixelCount;
                            lamp.AverageColor[1] /= lamp.PixelCount;
                            lamp.AverageColor[2] /= lamp.PixelCount;

                            if (Math.Abs(lamp.AverageColor[0] - lamp.PreviousColor[0]) >= coreObject.atmoOrbThreshold ||
                                Math.Abs(lamp.AverageColor[1] - lamp.PreviousColor[1]) >= coreObject.atmoOrbThreshold ||
                                Math.Abs(lamp.AverageColor[2] - lamp.PreviousColor[2]) >= coreObject.atmoOrbThreshold)
                            {
                                double hue;
                                double saturation;
                                double lightness;
                                double hueOverall;
                                double saturationOverall;
                                double lightnessOverall;

                                // Save new color as previous color
                                lamp.PreviousColor = lamp.AverageColor;

                                // Convert to hsl color model
                                HSL.RGB2HSL(lamp.AverageColor[0], lamp.AverageColor[1], lamp.AverageColor[2], out hue, out saturation,
                                            out lightness);
                                HSL.RGB2HSL(lamp.OverallAverageColor[0], lamp.OverallAverageColor[1], lamp.OverallAverageColor[2],
                                            out hueOverall, out saturationOverall, out lightnessOverall);

                                // Convert back to rgb with adjusted saturation and lightness
                                HSL.HSL2RGB(hue, Math.Min(saturation + coreObject.atmoOrbSaturation, 1),
                                            (coreObject.atmoOrbUseOverallLightness ? lightnessOverall : lightness), out lamp.AverageColor[0],
                                            out lamp.AverageColor[1], out lamp.AverageColor[2]);

                                if (Math.Abs(gammaCurve[lamp.PreviousColor[0]] - gammaCurve[lamp.AverageColor[0]]) >= coreObject.atmoOrbSmoothThreshold || Math.Abs(gammaCurve[lamp.PreviousColor[1]] - gammaCurve[lamp.AverageColor[1]]) >= coreObject.atmoOrbSmoothThreshold || Math.Abs(gammaCurve[lamp.PreviousColor[2]] - gammaCurve[lamp.AverageColor[2]]) >= coreObject.atmoOrbSmoothThreshold)
                                {
                                    skipSmoothing = true;
                                }

                                // Adjust gamma level and send to lamp
                                lamp.ChangeColor((byte)gammaCurve[lamp.AverageColor[0]], (byte)gammaCurve[lamp.AverageColor[1]], (byte)gammaCurve[lamp.AverageColor[2]], skipSmoothing, lamp.ID);
                            }
                        }
                        else
                        {
                            if (Math.Abs(lamp.OverallAverageColor[0] - lamp.PreviousColor[0]) >= coreObject.atmoOrbThreshold ||
                                Math.Abs(lamp.OverallAverageColor[1] - lamp.PreviousColor[1]) >= coreObject.atmoOrbThreshold ||
                                Math.Abs(lamp.OverallAverageColor[2] - lamp.PreviousColor[2]) >= coreObject.atmoOrbThreshold)
                            {
                                // Save new color as previous color
                                lamp.PreviousColor = lamp.OverallAverageColor;

                                if (lamp.OverallAverageColor[0] <= coreObject.atmoOrbBlackThreshold &&
                                    lamp.OverallAverageColor[1] <= coreObject.atmoOrbBlackThreshold &&
                                    lamp.OverallAverageColor[2] <= coreObject.atmoOrbBlackThreshold)
                                {
                                    if (gammaCurve[lamp.PreviousColor[0]] >= coreObject.atmoOrbSmoothThreshold || gammaCurve[lamp.PreviousColor[1]] >= coreObject.atmoOrbSmoothThreshold || gammaCurve[lamp.PreviousColor[2]] >= coreObject.atmoOrbSmoothThreshold)
                                    {
                                        skipSmoothing = true;
                                    }

                                    lamp.ChangeColor(0, 0, 0, skipSmoothing, lamp.ID);
                                }
                                else
                                {
                                    if (Math.Abs(gammaCurve[lamp.PreviousColor[0]] - gammaCurve[lamp.OverallAverageColor[0]]) >= coreObject.atmoOrbSmoothThreshold || Math.Abs(gammaCurve[lamp.PreviousColor[1]] - gammaCurve[lamp.OverallAverageColor[1]]) >= coreObject.atmoOrbSmoothThreshold || Math.Abs(gammaCurve[lamp.PreviousColor[2]] - gammaCurve[lamp.OverallAverageColor[2]]) >= coreObject.atmoOrbSmoothThreshold)
                                    {
                                        skipSmoothing = true;
                                    }

                                    // Adjust gamma level and send to lamp
                                    lamp.ChangeColor((byte)gammaCurve[lamp.OverallAverageColor[0]], (byte)gammaCurve[lamp.OverallAverageColor[1]], (byte)gammaCurve[lamp.OverallAverageColor[2]], skipSmoothing, lamp.ID);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("AtmoOrbHandler - Error in ChangeImage.");
                Log.Error("AtmoOrbHandler - Exception: {0}", ex.Message);
            }
        }
예제 #5
0
        public void ChangeImage(byte[] pixeldata, byte[] bmiInfoHeader)
        {
            if (!IsConnected())
            {
                return;
            }
            try
            {
                if (coreObject.GetCurrentEffect() == ContentEffect.MediaPortalLiveMode || coreObject.GetCurrentEffect() == ContentEffect.GIFReader)
                {
                    int[] overallAverageColor = new int[3];
                    int[] averageColor        = new int[3];
                    int[] previousColor       = new int[3];
                    int   pixelCount          = 0;

                    for (int y = 0; y < coreObject.GetCaptureHeight(); y++)
                    {
                        int row = coreObject.GetCaptureWidth() * y * 4;
                        for (int x = 0; x < coreObject.GetCaptureWidth(); x++)
                        {
                            overallAverageColor[0] += pixeldata[row + x * 4 + 2];
                            overallAverageColor[1] += pixeldata[row + x * 4 + 1];
                            overallAverageColor[2] += pixeldata[row + x * 4];
                            if (Math.Abs(pixeldata[row + x * 4 + 2] - pixeldata[row + x * 4 + 1]) > coreObject.hueMinDiversion || Math.Abs(pixeldata[row + x * 4 + 2] - pixeldata[row + x * 4]) > coreObject.hueMinDiversion || Math.Abs(pixeldata[row + x * 4 + 1] - pixeldata[row + x * 4]) > coreObject.hueMinDiversion)
                            {
                                averageColor[0] += pixeldata[row + x * 4 + 2];
                                averageColor[1] += pixeldata[row + x * 4 + 1];
                                averageColor[2] += pixeldata[row + x * 4];
                                pixelCount++;
                            }
                        }
                    }
                    overallAverageColor[0] /= (coreObject.GetCaptureHeight() * coreObject.GetCaptureWidth());
                    overallAverageColor[1] /= (coreObject.GetCaptureHeight() * coreObject.GetCaptureWidth());
                    overallAverageColor[2] /= (coreObject.GetCaptureHeight() * coreObject.GetCaptureWidth());
                    if (pixelCount > 0)
                    {
                        averageColor[0] /= pixelCount;
                        averageColor[1] /= pixelCount;
                        averageColor[2] /= pixelCount;

                        if (Math.Abs(averageColor[0] - previousColor[0]) >= coreObject.hueThreshold || Math.Abs(averageColor[1] - previousColor[1]) >= coreObject.hueThreshold || Math.Abs(averageColor[2] - previousColor[2]) >= coreObject.hueThreshold)
                        {
                            double hue;
                            double saturation;
                            double lightness;
                            double hueOverall;
                            double saturationOverall;
                            double lightnessOverall;

                            // Save new color as previous color
                            previousColor = averageColor;

                            // Convert to hsl color model
                            HSL.RGB2HSL(averageColor[0], averageColor[1], averageColor[2], out hue, out saturation, out lightness);
                            HSL.RGB2HSL(overallAverageColor[0], overallAverageColor[1], overallAverageColor[2], out hueOverall, out saturationOverall, out lightnessOverall);

                            // Convert back to rgb with adjusted saturation and lightness
                            HSL.HSL2RGB(hue, Math.Min(saturation + coreObject.hueSaturation, 1), (coreObject.hueUseOverallLightness ? lightnessOverall : lightness), out averageColor[0], out averageColor[1], out averageColor[2]);

                            // Send to lamp
                            ChangeColor(averageColor[0], averageColor[1], averageColor[2], 200, (int)(Math.Min(lightnessOverall, 0.5) * 510));
                        }
                    }
                    else
                    {
                        if (Math.Abs(overallAverageColor[0] - previousColor[0]) >= coreObject.hueThreshold || Math.Abs(overallAverageColor[1] - previousColor[1]) >= coreObject.hueThreshold || Math.Abs(overallAverageColor[2] - previousColor[2]) >= coreObject.hueThreshold)
                        {
                            // Save new color as previous color
                            previousColor = overallAverageColor;

                            if (overallAverageColor[0] <= coreObject.hueBlackThreshold && overallAverageColor[1] <= coreObject.hueBlackThreshold && overallAverageColor[2] <= coreObject.hueBlackThreshold)
                            {
                                ChangeColor(0, 0, 0, 200, 0);
                            }
                            else
                            {
                                double hueOverall;
                                double saturationOverall;
                                double lightnessOverall;
                                HSL.RGB2HSL(overallAverageColor[0], overallAverageColor[1], overallAverageColor[2], out hueOverall, out saturationOverall, out lightnessOverall);
                                // Adjust gamma level and send to lamp
                                ChangeColor(overallAverageColor[0], overallAverageColor[1], overallAverageColor[2], 200, (int)(Math.Min(lightnessOverall, 0.5) * 510));
                            }
                        }
                    }
                }
                // VUMeter
                else
                {
                    unsafe
                    {
                        fixed(byte *ptr = pixeldata)
                        {
                            using (Bitmap image = new Bitmap(coreObject.GetCaptureWidth(), coreObject.GetCaptureHeight(), coreObject.GetCaptureWidth() * 4,
                                                             PixelFormat.Format32bppRgb, new IntPtr(ptr)))
                            {
                                CalculateVUMeterColorAndSendToHue(image);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(string.Format("HueHandler - {0}", "Error during average color calculations"));
                Log.Error(string.Format("HueHandler - {0}", e.Message));
            }
        }