Skip to content

Commit

Permalink
Improved Animatrix rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Mar 20, 2023
1 parent 265c6ce commit 06be8c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
32 changes: 20 additions & 12 deletions app/AnimeMatrix/AnimeMatrixDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
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
{
Expand Down Expand Up @@ -164,11 +167,8 @@ public int RowToLinearAddress(int row)

var ret = 0;

if (row > 0)
{
for (var i = 0; i < row; i++)
ret += Columns(i);
}
for (var i = 0; i < row; i++)
ret += Columns(i);

return ret;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void SetLedPlanar(int x, int y, byte value)
EnsureRowInRange(y);
var start = RowToLinearAddress(y) - EmptyColumns(y);

if (x > EmptyColumns(y))
if (x >= EmptyColumns(y))
SetLedLinear(start + x, value);
}

Expand Down Expand Up @@ -272,10 +272,15 @@ public void SetBuiltInAnimation(bool enable, BuiltInAnimation animation)
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)
{

int width = MaxColumns * 3;
int width = MaxColumns*3;
int height = MaxRows;
float scale;

Expand All @@ -291,17 +296,20 @@ public void GenerateFrame(Image image)
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);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/Settings.Designer.cs

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

4 changes: 3 additions & 1 deletion app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,11 @@ public void InitScreen()

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);
Expand Down

0 comments on commit 06be8c7

Please sign in to comment.