Renamed matrix brightness to gamma

This commit is contained in:
Serge
2024-04-26 12:19:39 +02:00
parent 6d36794f5e
commit 7e523d02c0
5 changed files with 75 additions and 80 deletions

View File

@@ -465,7 +465,7 @@ namespace GHelper.AnimeMatrix
int matrixZoom = AppConfig.Get("matrix_zoom", 100); int matrixZoom = AppConfig.Get("matrix_zoom", 100);
int matrixContrast = AppConfig.Get("matrix_contrast", 100); int matrixContrast = AppConfig.Get("matrix_contrast", 100);
int matrixBrightness = AppConfig.Get("matrix_brightness", 0); int matrixGamma = AppConfig.Get("matrix_gamma", 0);
int matrixSpeed = AppConfig.Get("matrix_speed", 50); int matrixSpeed = AppConfig.Get("matrix_speed", 50);
@@ -487,9 +487,9 @@ namespace GHelper.AnimeMatrix
image.SelectActiveFrame(dimension, i); image.SelectActiveFrame(dimension, i);
if (rotation == MatrixRotation.Planar) if (rotation == MatrixRotation.Planar)
deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixBrightness); deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixGamma);
else else
deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixBrightness); deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixGamma);
deviceMatrix.AddFrame(); deviceMatrix.AddFrame();
} }
@@ -504,9 +504,9 @@ namespace GHelper.AnimeMatrix
else else
{ {
if (rotation == MatrixRotation.Planar) if (rotation == MatrixRotation.Planar)
deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixBrightness); deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixGamma);
else else
deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixBrightness); deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast, matrixGamma);
deviceMatrix.Present(); deviceMatrix.Present();
} }

View File

@@ -344,21 +344,21 @@ namespace GHelper.AnimeMatrix
if (present) Present(); if (present) Present();
} }
private void SetBitmapDiagonal(Bitmap bmp, int deltaX = 0, int deltaY = 0, int contrast = 100, int brightness = 0) private void SetBitmapDiagonal(Bitmap bmp, int deltaX = 0, int deltaY = 0, int contrast = 100, int gamma = 0)
{ {
for (int y = 0; y < bmp.Height; y++) for (int y = 0; y < bmp.Height; y++)
{ {
for (int x = 0; x < bmp.Width; x++) for (int x = 0; x < bmp.Width; x++)
{ {
var pixel = bmp.GetPixel(x, y); var pixel = bmp.GetPixel(x, y);
var color = Math.Min((pixel.R + pixel.G + pixel.B + brightness) * contrast / 300, 255); var color = Math.Min((pixel.R + pixel.G + pixel.B + gamma) * contrast / 300, 255);
if (color > 20) if (color > 20)
SetLedDiagonal(x, y, (byte)color, deltaX, deltaY - (FullRows / 2) - 1); SetLedDiagonal(x, y, (byte)color, deltaX, deltaY - (FullRows / 2) - 1);
} }
} }
} }
private void SetBitmapLinear(Bitmap bmp, int contrast = 100, int brightness = 0) private void SetBitmapLinear(Bitmap bmp, int contrast = 100, int gamma = 0)
{ {
for (int y = 0; y < bmp.Height; y++) for (int y = 0; y < bmp.Height; y++)
{ {
@@ -366,7 +366,7 @@ namespace GHelper.AnimeMatrix
if (x % 2 == y % 2) if (x % 2 == y % 2)
{ {
var pixel = bmp.GetPixel(x, y); var pixel = bmp.GetPixel(x, y);
var color = Math.Min((pixel.R + pixel.G + pixel.B + brightness) * contrast / 300, 255); var color = Math.Min((pixel.R + pixel.G + pixel.B + gamma) * contrast / 300, 255);
if (color > 20) if (color > 20)
SetLedPlanar(x / 2, y, (byte)color); SetLedPlanar(x / 2, y, (byte)color);
} }
@@ -413,7 +413,7 @@ namespace GHelper.AnimeMatrix
Present(); Present();
} }
public void GenerateFrame(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default, int contrast = 100, int brightness = 0) public void GenerateFrame(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default, int contrast = 100, int gamma = 0)
{ {
int width = MaxColumns / 2 * 6; int width = MaxColumns / 2 * 6;
int height = MaxRows; int height = MaxRows;
@@ -440,11 +440,11 @@ namespace GHelper.AnimeMatrix
} }
Clear(); Clear();
SetBitmapLinear(bmp, contrast, brightness); SetBitmapLinear(bmp, contrast, gamma);
} }
} }
public void GenerateFrameDiagonal(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default, int contrast = 100, int brightness = 0) public void GenerateFrameDiagonal(Image image, float zoom = 100, int panX = 0, int panY = 0, InterpolationMode quality = InterpolationMode.Default, int contrast = 100, int gamma = 0)
{ {
int width = MaxRows + FullRows; int width = MaxRows + FullRows;
int height = MaxColumns + FullRows; int height = MaxColumns + FullRows;
@@ -471,7 +471,7 @@ namespace GHelper.AnimeMatrix
} }
Clear(); Clear();
SetBitmapDiagonal(bmp, -panX, height + panY, contrast, brightness); SetBitmapDiagonal(bmp, -panX, height + panY, contrast, gamma);
} }
} }

104
app/Matrix.Designer.cs generated
View File

@@ -35,10 +35,10 @@
panelMain = new Panel(); panelMain = new Panel();
panelButtons = new Panel(); panelButtons = new Panel();
buttonReset = new UI.RButton(); buttonReset = new UI.RButton();
panelBrightness = new Panel(); panelGamma = new Panel();
labelBrightness = new Label(); labelGamma = new Label();
labelBrightnessTitle = new Label(); labelGammaTitle = new Label();
trackBrightness = new TrackBar(); trackGamma = new TrackBar();
panelContrast = new Panel(); panelContrast = new Panel();
labelContrast = new Label(); labelContrast = new Label();
labelContrastTitle = new Label(); labelContrastTitle = new Label();
@@ -57,8 +57,8 @@
panelPicture.SuspendLayout(); panelPicture.SuspendLayout();
panelMain.SuspendLayout(); panelMain.SuspendLayout();
panelButtons.SuspendLayout(); panelButtons.SuspendLayout();
panelBrightness.SuspendLayout(); panelGamma.SuspendLayout();
((System.ComponentModel.ISupportInitialize)trackBrightness).BeginInit(); ((System.ComponentModel.ISupportInitialize)trackGamma).BeginInit();
panelContrast.SuspendLayout(); panelContrast.SuspendLayout();
((System.ComponentModel.ISupportInitialize)trackContrast).BeginInit(); ((System.ComponentModel.ISupportInitialize)trackContrast).BeginInit();
panelRotation.SuspendLayout(); panelRotation.SuspendLayout();
@@ -123,7 +123,7 @@
// //
panelMain.AutoSize = true; panelMain.AutoSize = true;
panelMain.Controls.Add(panelButtons); panelMain.Controls.Add(panelButtons);
panelMain.Controls.Add(panelBrightness); panelMain.Controls.Add(panelGamma);
panelMain.Controls.Add(panelContrast); panelMain.Controls.Add(panelContrast);
panelMain.Controls.Add(panelRotation); panelMain.Controls.Add(panelRotation);
panelMain.Controls.Add(panelScaling); panelMain.Controls.Add(panelScaling);
@@ -164,51 +164,51 @@
buttonReset.TextImageRelation = TextImageRelation.ImageBeforeText; buttonReset.TextImageRelation = TextImageRelation.ImageBeforeText;
buttonReset.UseVisualStyleBackColor = false; buttonReset.UseVisualStyleBackColor = false;
// //
// panelBrightness // panelGamma
// //
panelBrightness.AutoSize = true; panelGamma.AutoSize = true;
panelBrightness.Controls.Add(labelBrightness); panelGamma.Controls.Add(labelGamma);
panelBrightness.Controls.Add(labelBrightnessTitle); panelGamma.Controls.Add(labelGammaTitle);
panelBrightness.Controls.Add(trackBrightness); panelGamma.Controls.Add(trackGamma);
panelBrightness.Dock = DockStyle.Top; panelGamma.Dock = DockStyle.Top;
panelBrightness.Location = new Point(0, 865); panelGamma.Location = new Point(0, 865);
panelBrightness.Name = "panelBrightness"; panelGamma.Name = "panelGamma";
panelBrightness.Size = new Size(834, 145); panelGamma.Size = new Size(834, 145);
panelBrightness.TabIndex = 7; panelGamma.TabIndex = 7;
// //
// labelBrightness // labelGamma
// //
labelBrightness.Anchor = AnchorStyles.Top | AnchorStyles.Right; labelGamma.Anchor = AnchorStyles.Top | AnchorStyles.Right;
labelBrightness.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); labelGamma.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
labelBrightness.Location = new Point(673, 17); labelGamma.Location = new Point(673, 17);
labelBrightness.Name = "labelBrightness"; labelGamma.Name = "labelGamma";
labelBrightness.Size = new Size(125, 32); labelGamma.Size = new Size(125, 32);
labelBrightness.TabIndex = 4; labelGamma.TabIndex = 4;
labelBrightness.Text = "Brightness"; labelGamma.Text = "Brightness";
labelBrightness.TextAlign = ContentAlignment.TopRight; labelGamma.TextAlign = ContentAlignment.TopRight;
// //
// labelBrightnessTitle // labelGammaTitle
// //
labelBrightnessTitle.AutoSize = true; labelGammaTitle.AutoSize = true;
labelBrightnessTitle.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); labelGammaTitle.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelBrightnessTitle.Location = new Point(16, 17); labelGammaTitle.Location = new Point(16, 17);
labelBrightnessTitle.Name = "labelBrightnessTitle"; labelGammaTitle.Name = "labelGammaTitle";
labelBrightnessTitle.Size = new Size(134, 32); labelGammaTitle.Size = new Size(134, 32);
labelBrightnessTitle.TabIndex = 3; labelGammaTitle.TabIndex = 3;
labelBrightnessTitle.Text = "Brightness"; labelGammaTitle.Text = "Brightness";
// //
// trackBrightness // trackGamma
// //
trackBrightness.LargeChange = 50; trackGamma.LargeChange = 50;
trackBrightness.Location = new Point(16, 52); trackGamma.Location = new Point(16, 52);
trackBrightness.Maximum = 100; trackGamma.Maximum = 100;
trackBrightness.Minimum = -100; trackGamma.Minimum = -100;
trackBrightness.Name = "trackBrightness"; trackGamma.Name = "trackGamma";
trackBrightness.Size = new Size(782, 90); trackGamma.Size = new Size(782, 90);
trackBrightness.SmallChange = 10; trackGamma.SmallChange = 10;
trackBrightness.TabIndex = 2; trackGamma.TabIndex = 2;
trackBrightness.TickFrequency = 20; trackGamma.TickFrequency = 20;
trackBrightness.TickStyle = TickStyle.TopLeft; trackGamma.TickStyle = TickStyle.TopLeft;
// //
// panelContrast // panelContrast
// //
@@ -379,9 +379,9 @@
panelMain.ResumeLayout(false); panelMain.ResumeLayout(false);
panelMain.PerformLayout(); panelMain.PerformLayout();
panelButtons.ResumeLayout(false); panelButtons.ResumeLayout(false);
panelBrightness.ResumeLayout(false); panelGamma.ResumeLayout(false);
panelBrightness.PerformLayout(); panelGamma.PerformLayout();
((System.ComponentModel.ISupportInitialize)trackBrightness).EndInit(); ((System.ComponentModel.ISupportInitialize)trackGamma).EndInit();
panelContrast.ResumeLayout(false); panelContrast.ResumeLayout(false);
panelContrast.PerformLayout(); panelContrast.PerformLayout();
((System.ComponentModel.ISupportInitialize)trackContrast).EndInit(); ((System.ComponentModel.ISupportInitialize)trackContrast).EndInit();
@@ -417,9 +417,9 @@
private Label labelContrast; private Label labelContrast;
private Label labelContrastTitle; private Label labelContrastTitle;
private TrackBar trackContrast; private TrackBar trackContrast;
private Panel panelBrightness; private Panel panelGamma;
private Label labelBrightness; private Label labelGamma;
private Label labelBrightnessTitle; private Label labelGammaTitle;
private TrackBar trackBrightness; private TrackBar trackGamma;
} }
} }

View File

@@ -47,13 +47,13 @@ namespace GHelper
trackZoom.ValueChanged += TrackZoom_Changed; trackZoom.ValueChanged += TrackZoom_Changed;
trackZoom.Value = Math.Min(trackZoom.Maximum, AppConfig.Get("matrix_zoom", 100)); trackZoom.Value = Math.Min(trackZoom.Maximum, AppConfig.Get("matrix_zoom", 100));
trackContrast.MouseUp += TrackContrast_MouseUp; trackContrast.MouseUp += TrackMatrix_MouseUp;
trackContrast.ValueChanged += TrackMatrix_ValueChanged; trackContrast.ValueChanged += TrackMatrix_ValueChanged;
trackContrast.Value = Math.Min(trackContrast.Maximum, AppConfig.Get("matrix_contrast", 100)); trackContrast.Value = Math.Min(trackContrast.Maximum, AppConfig.Get("matrix_contrast", 100));
trackBrightness.MouseUp += TrackBrightness_MouseUp; trackGamma.MouseUp += TrackMatrix_MouseUp;
trackBrightness.ValueChanged += TrackMatrix_ValueChanged; trackGamma.ValueChanged += TrackMatrix_ValueChanged;
trackBrightness.Value = Math.Min(trackBrightness.Maximum, AppConfig.Get("matrix_brightness", 0)); trackGamma.Value = Math.Min(trackGamma.Maximum, AppConfig.Get("matrix_gamma", 0));
VisualiseMatrix(); VisualiseMatrix();
@@ -76,15 +76,10 @@ namespace GHelper
VisualiseMatrix(); VisualiseMatrix();
} }
private void TrackContrast_MouseUp(object? sender, MouseEventArgs e) private void TrackMatrix_MouseUp(object? sender, MouseEventArgs e)
{ {
AppConfig.Set("matrix_contrast", trackContrast.Value); AppConfig.Set("matrix_contrast", trackContrast.Value);
SetMatrixPicture(); AppConfig.Set("matrix_gamma", trackGamma.Value);
}
private void TrackBrightness_MouseUp(object? sender, MouseEventArgs e)
{
AppConfig.Set("matrix_brightness", trackBrightness.Value);
SetMatrixPicture(); SetMatrixPicture();
} }
@@ -115,12 +110,12 @@ namespace GHelper
{ {
labelZoom.Text = trackZoom.Value + "%"; labelZoom.Text = trackZoom.Value + "%";
labelContrast.Text = trackContrast.Value + "%"; labelContrast.Text = trackContrast.Value + "%";
labelBrightness.Text = trackBrightness.Value + "%"; labelGamma.Text = trackGamma.Value + "%";
} }
private void ButtonReset_Click(object? sender, EventArgs e) private void ButtonReset_Click(object? sender, EventArgs e)
{ {
AppConfig.Set("matrix_brightness", 0); AppConfig.Set("matrix_gamma", 0);
AppConfig.Set("matrix_contrast", 100); AppConfig.Set("matrix_contrast", 100);
AppConfig.Set("matrix_zoom", 100); AppConfig.Set("matrix_zoom", 100);
AppConfig.Set("matrix_x", 0); AppConfig.Set("matrix_x", 0);
@@ -128,7 +123,7 @@ namespace GHelper
trackZoom.Value = 100; trackZoom.Value = 100;
trackContrast.Value = 100; trackContrast.Value = 100;
trackBrightness.Value = 0; trackGamma.Value = 0;
SetMatrixPicture(); SetMatrixPicture();

View File

@@ -1097,7 +1097,7 @@ namespace GHelper
checkMatrixLid.Visible = true; checkMatrixLid.Visible = true;
} }
comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1); comboMatrix.SelectedIndex = Math.Max(0, Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1));
comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1); comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1);
comboInterval.SelectedIndex = Math.Min(AppConfig.Get("matrix_interval", 0), comboInterval.Items.Count - 1); comboInterval.SelectedIndex = Math.Min(AppConfig.Get("matrix_interval", 0), comboInterval.Items.Count - 1);