mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Improved Animatrix rendering
This commit is contained in:
@@ -4,6 +4,9 @@ using Starlight.Communication;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Management;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Starlight.AnimeMatrix
|
||||
{
|
||||
@@ -164,11 +167,8 @@ namespace Starlight.AnimeMatrix
|
||||
|
||||
var ret = 0;
|
||||
|
||||
if (row > 0)
|
||||
{
|
||||
for (var i = 0; i < row; i++)
|
||||
ret += Columns(i);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ namespace Starlight.AnimeMatrix
|
||||
EnsureRowInRange(y);
|
||||
var start = RowToLinearAddress(y) - EmptyColumns(y);
|
||||
|
||||
if (x > EmptyColumns(y))
|
||||
if (x >= EmptyColumns(y))
|
||||
SetLedLinear(start + x, value);
|
||||
}
|
||||
|
||||
@@ -272,6 +272,11 @@ namespace Starlight.AnimeMatrix
|
||||
Set(Packet<AnimeMatrixPacket>(0xC5, animation.AsByte));
|
||||
}
|
||||
|
||||
static int GetColor(Bitmap bmp, int x, int y)
|
||||
{
|
||||
var pixel = bmp.GetPixel(Math.Max(0,Math.Min(bmp.Width - 1,x)), Math.Max(0, Math.Min(bmp.Height - 1, y)));
|
||||
return (Math.Max((pixel.R + pixel.G + pixel.B) / 3 - 10, 0));
|
||||
}
|
||||
public void GenerateFrame(Image image)
|
||||
{
|
||||
|
||||
@@ -291,17 +296,20 @@ namespace Starlight.AnimeMatrix
|
||||
graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||||
graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
|
||||
graph.DrawImage(image, ((int)width - scaleWidth), ((int)height - scaleHeight) / 2, scaleWidth, scaleHeight);
|
||||
graph.DrawImage(image, ((int)width - scaleWidth), 0, scaleWidth, scaleHeight);
|
||||
|
||||
Bitmap bmp = new Bitmap(canvas, MaxColumns, MaxRows);
|
||||
Bitmap bmp = new Bitmap(canvas, MaxColumns * 2, MaxRows);
|
||||
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
{
|
||||
var pixel = bmp.GetPixel(x, y);
|
||||
byte color = (byte)(Math.Max((pixel.R + pixel.G + pixel.B) / 3 - 10, 0));
|
||||
SetLedPlanar(x, y, color);
|
||||
if (x % 2 == (y % 2))
|
||||
{
|
||||
var color = GetColor(bmp, x, y);
|
||||
//var color2= GetColor(bmp, x+1, y);
|
||||
SetLedPlanar(x/2,y, (byte)color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
app/Settings.Designer.cs
generated
2
app/Settings.Designer.cs
generated
@@ -710,6 +710,8 @@ namespace GHelper
|
||||
tableScreen.Controls.Add(buttonScreenAuto, 0, 0);
|
||||
tableScreen.Controls.Add(button60Hz, 1, 0);
|
||||
tableScreen.Controls.Add(button120Hz, 2, 0);
|
||||
tableScreen.Controls.Add(buttonMiniled, 3, 0);
|
||||
|
||||
tableScreen.Location = new Point(16, 51);
|
||||
tableScreen.Margin = new Padding(8, 4, 8, 4);
|
||||
tableScreen.Name = "tableScreen";
|
||||
|
||||
@@ -705,9 +705,11 @@ namespace GHelper
|
||||
|
||||
if (miniled >= 0)
|
||||
{
|
||||
tableScreen.Controls.Add(buttonMiniled, 3, 0);
|
||||
buttonMiniled.Activated = (miniled == 1);
|
||||
Program.config.setConfig("miniled", miniled);
|
||||
} else
|
||||
{
|
||||
buttonMiniled.Visible = false;
|
||||
}
|
||||
|
||||
Program.config.setConfig("frequency", frequency);
|
||||
|
||||
Reference in New Issue
Block a user