Skip to content

Commit

Permalink
Improved support for Chroma Link (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojeske authored Sep 30, 2020
1 parent 017cd0e commit f209196
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions Ambilight/Logic/LinkLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,33 @@ public LinkLogic(TraySettings settings, IChroma chromaInstance)
/// <param name="newImage">ScreenShot</param>
public void Process(Bitmap newImage)
{
Bitmap map = ImageManipulation.ResizeImage(newImage, 2, 2);
Bitmap map = ImageManipulation.ResizeImage(newImage, 4, 1);
map = ImageManipulation.ApplySaturation(map, _settings.Saturation);
GenerateLinkGrid(map);


ApplyImageToGrid(map);
ApplyC1(ImageManipulation.ResizeImage(map, 1, 1));
_chroma.ChromaLink.SetCustomAsync(_linkGrid);
map.Dispose();
}

private void ApplyC1(Bitmap map)
{
Color color = map.GetPixel(0,0);
_linkGrid[0] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B);
}

/// <summary>
/// From a given resized screenshot, an ambilight effect will be created for the keyboard
/// </summary>
/// <param name="map">resized screenshot</param>
private void GenerateLinkGrid(Bitmap map)
private void ApplyImageToGrid(Bitmap map)
{
//Iterating over each key and set it to the corrosponding color of the resized Screenshot
for (var r = 1; r <= 2; r++)
for (int i = 1; i < Colore.Effects.ChromaLink.ChromaLinkConstants.MaxLeds; i++)
{
for (var c = 0; c < 2; c++)
{
System.Drawing.Color color;
color = map.GetPixel(c, r-1);
if (r == 2) r++;
_linkGrid[c + r] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B);
if (r > 2) r--;
}
Color color = map.GetPixel(i-1,0);
_linkGrid[i] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B);
}
_linkGrid[0] = _linkGrid[1];
}
}
}

0 comments on commit f209196

Please sign in to comment.