Skip to content

Commit

Permalink
Matrix Contrast slider #1713
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Dec 9, 2023
1 parent 64e3b3b commit 24199b3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 23 deletions.
11 changes: 7 additions & 4 deletions app/AnimeMatrix/AniMatrixControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ protected void ProcessPicture(Image image)

int matrixX = AppConfig.Get("matrix_x", 0);
int matrixY = AppConfig.Get("matrix_y", 0);

int matrixZoom = AppConfig.Get("matrix_zoom", 100);
int matrixContrast = AppConfig.Get("matrix_contrast", 100);

int matrixSpeed = AppConfig.Get("matrix_speed", 50);

MatrixRotation rotation = (MatrixRotation)AppConfig.Get("matrix_rotation", 0);
Expand All @@ -368,9 +371,9 @@ protected void ProcessPicture(Image image)
image.SelectActiveFrame(dimension, i);

if (rotation == MatrixRotation.Planar)
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality);
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
else
device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality);
device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);

device.AddFrame();
}
Expand All @@ -385,9 +388,9 @@ protected void ProcessPicture(Image image)
else
{
if (rotation == MatrixRotation.Planar)
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality);
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
else
device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality);
device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);

device.Present();
}
Expand Down
16 changes: 8 additions & 8 deletions app/AnimeMatrix/AnimeMatrixDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,29 +399,29 @@ public void SetBuiltInAnimation(bool enable, BuiltInAnimation animation)
}


private void SetBitmapDiagonal(Bitmap bmp, int deltaX = 0, int deltaY = 0)
private void SetBitmapDiagonal(Bitmap bmp, int deltaX = 0, int deltaY = 0, int contrast = 100)
{
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
var pixel = bmp.GetPixel(x, y);
var color = (pixel.R + pixel.G + pixel.B) / 3;
var color = Math.Min((pixel.R + pixel.G + pixel.B) * contrast / 300, 255);
if (color > 20)
SetLedDiagonal(x, y, (byte)color, deltaX + (FullRows / 2) + 1, deltaY - (FullRows / 2) - 1);
}
}
}

private void SetBitmapLinear(Bitmap bmp)
private void SetBitmapLinear(Bitmap bmp, int contrast = 100)
{
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
if (x % 2 == y % 2)
{
var pixel = bmp.GetPixel(x, y);
var color = (pixel.R + pixel.G + pixel.B) / 3;
var color = Math.Min((pixel.R + pixel.G + pixel.B) * contrast / 300, 255);
if (color > 20)
SetLedPlanar(x / 2, y, (byte)color);
}
Expand Down Expand Up @@ -468,7 +468,7 @@ public void PresentClock()
Present();

}
public void GenerateFrame(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default)
public void GenerateFrame(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default, int contrast = 100)
{
int width = MaxColumns / 2 * 6;
int height = MaxRows;
Expand All @@ -495,11 +495,11 @@ public void GenerateFrame(Image image, float zoom = 100, int panX = 0, int panY
}

Clear();
SetBitmapLinear(bmp);
SetBitmapLinear(bmp, contrast);
}
}

public void GenerateFrameDiagonal(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default)
public void GenerateFrameDiagonal(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default, int contrast = 100)
{
int width = MaxRows - FullRows;
int height = MaxRows - FullRows*2;
Expand All @@ -523,7 +523,7 @@ public void GenerateFrameDiagonal(Image image, float zoom = 100, int panX = 0, i
}

Clear();
SetBitmapDiagonal(bmp, -panX, height + panY);
SetBitmapDiagonal(bmp, -panX, height + panY, contrast);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public static bool IsPowerRequired()

public static bool IsGPUFixNeeded()
{
return ContainsModel("GA402X") || ContainsModel("GV302") || ContainsModel("GV301") || ContainsModel("GZ301") || ContainsModel("FX506") || ContainsModel("GU603") || ContainsModel("GU604");
return ContainsModel("GA402X") || ContainsModel("GV302") || ContainsModel("GV301") || ContainsModel("GZ301") || ContainsModel("FX506") || ContainsModel("GU603") || ContainsModel("GU604") || ContainsModel("G614J");
}

public static bool IsGPUFix()
Expand Down
67 changes: 64 additions & 3 deletions app/Matrix.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions app/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ public Matrix()

trackZoom.MouseUp += TrackZoom_MouseUp;
trackZoom.ValueChanged += TrackZoom_Changed;

trackZoom.Value = Math.Min(trackZoom.Maximum, AppConfig.Get("matrix_zoom", 100));
VisualiseZoom();

trackContrast.MouseUp += TrackContrast_MouseUp; ;
trackContrast.ValueChanged += TrackContrast_ValueChanged; ;
trackContrast.Value = Math.Min(trackContrast.Maximum, AppConfig.Get("matrix_contrast", 100));

VisualiseMatrix();

comboScaling.DropDownStyle = ComboBoxStyle.DropDownList;
comboScaling.SelectedIndex = AppConfig.Get("matrix_quality", 0);
Expand All @@ -55,6 +59,17 @@ public Matrix()

}

private void TrackContrast_ValueChanged(object? sender, EventArgs e)
{
VisualiseMatrix();
}

private void TrackContrast_MouseUp(object? sender, MouseEventArgs e)
{
AppConfig.Set("matrix_contrast", trackContrast.Value);
SetMatrixPicture();
}

private void ComboRotation_SelectedValueChanged(object? sender, EventArgs e)
{
AppConfig.Set("matrix_rotation", comboRotation.SelectedIndex);
Expand All @@ -77,18 +92,21 @@ private void Matrix_FormClosed(object? sender, FormClosingEventArgs e)
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
}

private void VisualiseZoom()
private void VisualiseMatrix()
{
labelZoom.Text = trackZoom.Value + "%";
labelContrast.Text = trackContrast.Value + "%";
}

private void ButtonReset_Click(object? sender, EventArgs e)
{
AppConfig.Set("matrix_contrast", 100);
AppConfig.Set("matrix_zoom", 100);
AppConfig.Set("matrix_x", 0);
AppConfig.Set("matrix_y", 0);

trackZoom.Value = 100;
trackContrast.Value = 100;

SetMatrixPicture();

Expand All @@ -102,7 +120,7 @@ private void TrackZoom_MouseUp(object? sender, EventArgs e)

private void TrackZoom_Changed(object? sender, EventArgs e)
{
VisualiseZoom();
VisualiseMatrix();
}


Expand Down Expand Up @@ -195,7 +213,6 @@ public void VisualiseMatrix(string fileName)
int matrixY = AppConfig.Get("matrix_y", 0);
int matrixZoom = AppConfig.Get("matrix_zoom", 100);


float scale = Math.Min((float)panelPicture.Width / (float)width, (float)panelPicture.Height / (float)height) * matrixZoom / 100;

pictureMatrix.Width = (int)(width * scale);
Expand Down
4 changes: 2 additions & 2 deletions app/USB/Aura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ static Aura()
timer.Elapsed += Timer_Elapsed;
isSingleColor = AppConfig.IsSingleColor(); // Mono Color

if (AppConfig.ContainsModel("GA402X") || AppConfig.ContainsModel("GA402N"))
if (AppConfig.ContainsModel("GA402X") || AppConfig.ContainsModel("GA402N") || AppConfig.ContainsModel("GA503R"))
{
var device = AsusHid.FindDevices(AsusHid.AURA_ID).FirstOrDefault();
if (device is null) return;
Logger.WriteLine($"GA402: {device.ReleaseNumberBcd} {device.ReleaseNumber}");
Logger.WriteLine($"USB Version: {device.ReleaseNumberBcd} {device.ReleaseNumber}");
if (device.ReleaseNumberBcd >= 22 && device.ReleaseNumberBcd <= 25) isSingleColor = true;
}
}
Expand Down

0 comments on commit 24199b3

Please sign in to comment.