Ambient mode improvements

This commit is contained in:
Serge
2023-12-13 16:42:29 +01:00
parent 9543cd400e
commit 8ca043de7d
2 changed files with 41 additions and 9 deletions

View File

@@ -26,6 +26,38 @@ namespace GHelper.Helpers
(color1.B + color2.B) / 2); (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 class HSV
{ {
public double Hue { get; set; } public double Hue { get; set; }

View File

@@ -630,17 +630,16 @@ namespace GHelper.USB
public static void ApplyAmbient(bool init = false) public static void ApplyAmbient(bool init = false)
{ {
var bound = Screen.GetBounds(Point.Empty); var bound = Screen.GetBounds(Point.Empty);
bound.Y += bound.Height / 3; //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.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 screen_low = AmbientData.CamptureScreen(bound, 512, 288); //quality decreases greatly if it is less 512 ;
Bitmap screeb_pxl; Bitmap screeb_pxl = AmbientData.ResizeImage(screen_low, 4, 2); // 4x2 zone. top for keyboard and bot for lightbar;
int zones = AURA_ZONES; int zones = AURA_ZONES;
if (isStrix) // laptop with lightbar 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_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)); var mid_right = ColorUtils.GetMidColor(screeb_pxl.GetPixel(2, 1), screeb_pxl.GetPixel(3, 1));
@@ -655,12 +654,13 @@ namespace GHelper.USB
else else
{ {
zones = 1; zones = 1;
screeb_pxl = AmbientData.ResizeImage(screen_low, 1, 1); AmbientData.Colors[0].RGB = ColorUtils.HSV.UpSaturation(ColorUtils.GetDominantColor(screeb_pxl), (float)0.3);
AmbientData.Colors[0].RGB = ColorUtils.HSV.UpSaturation(screeb_pxl.GetPixel(0, 0), (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(); screen_low.Dispose();
screeb_pxl.Dispose(); screeb_pxl.Dispose();
@@ -756,7 +756,7 @@ namespace GHelper.USB
{ {
graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.Bicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.None; graphics.SmoothingMode = SmoothingMode.None;
graphics.PixelOffsetMode = PixelOffsetMode.None; graphics.PixelOffsetMode = PixelOffsetMode.None;