diff --git a/app/Helpers/ColorUtilities.cs b/app/Helpers/ColorUtilities.cs index 1a21316d..bcb5f024 100644 --- a/app/Helpers/ColorUtilities.cs +++ b/app/Helpers/ColorUtilities.cs @@ -26,6 +26,38 @@ namespace GHelper.Helpers (color1.B + color2.B) / 2); } + public static Color GetDominantColor(Bitmap bmp) + { + + //Used for tally + int r = 0; + int g = 0; + int b = 0; + + int total = 0; + + for (int x = 0; x < bmp.Width; x++) + { + for (int y = 0; y < bmp.Height; y++) + { + Color clr = bmp.GetPixel(x, y); + + r += clr.R; + g += clr.G; + b += clr.B; + + total++; + } + } + + //Calculate average + r /= total; + g /= total; + b /= total; + + return Color.FromArgb(r, g, b); + } + public class HSV { public double Hue { get; set; } diff --git a/app/USB/Aura.cs b/app/USB/Aura.cs index 71beda41..5532b67e 100644 --- a/app/USB/Aura.cs +++ b/app/USB/Aura.cs @@ -630,17 +630,16 @@ namespace GHelper.USB public static void ApplyAmbient(bool init = false) { var bound = Screen.GetBounds(Point.Empty); - bound.Y += bound.Height / 3; - bound.Height -= (int)Math.Round(bound.Height * (0.33f + 0.022f)); // cut 1/3 of the top screen + windows panel + //bound.Y += bound.Height / 3; + //bound.Height -= (int)Math.Round(bound.Height * (0.33f + 0.022f)); // cut 1/3 of the top screen + windows panel - Bitmap screen_low = screen_low = AmbientData.CamptureScreen(bound, 512, 288); //quality decreases greatly if it is less 512 ; - Bitmap screeb_pxl; + Bitmap screen_low = AmbientData.CamptureScreen(bound, 512, 288); //quality decreases greatly if it is less 512 ; + Bitmap screeb_pxl = AmbientData.ResizeImage(screen_low, 4, 2); // 4x2 zone. top for keyboard and bot for lightbar; int zones = AURA_ZONES; if (isStrix) // laptop with lightbar { - screeb_pxl = AmbientData.ResizeImage(screen_low, 4, 2); // 4x2 zone. top for keyboard and bot for lightbar var mid_left = ColorUtils.GetMidColor(screeb_pxl.GetPixel(0, 1), screeb_pxl.GetPixel(1, 1)); var mid_right = ColorUtils.GetMidColor(screeb_pxl.GetPixel(2, 1), screeb_pxl.GetPixel(3, 1)); @@ -655,12 +654,13 @@ namespace GHelper.USB else { zones = 1; - screeb_pxl = AmbientData.ResizeImage(screen_low, 1, 1); - AmbientData.Colors[0].RGB = ColorUtils.HSV.UpSaturation(screeb_pxl.GetPixel(0, 0), (float)0.3); + AmbientData.Colors[0].RGB = ColorUtils.HSV.UpSaturation(ColorUtils.GetDominantColor(screeb_pxl), (float)0.3); } - //screeb_pxl.Save("test.jpg", ImageFormat.Jpeg); + //screen_low.Save("big.jpg", ImageFormat.Jpeg); + //screeb_pxl.Save("small.jpg", ImageFormat.Jpeg); + screen_low.Dispose(); screeb_pxl.Dispose(); @@ -756,7 +756,7 @@ namespace GHelper.USB { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.InterpolationMode = InterpolationMode.Bicubic; + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.None; graphics.PixelOffsetMode = PixelOffsetMode.None;