Skip to content

Commit

Permalink
Added additional logging and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mista-funky authored and freezy committed Feb 18, 2022
1 parent b003000 commit ed1d459
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
63 changes: 43 additions & 20 deletions LibDmd/Common/FrameUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.InteropServices;
using System.Text;
using NLog;
using SharpGL.SceneGraph.Feedback;
using Color = System.Windows.Media.Color;

namespace LibDmd.Common
Expand Down Expand Up @@ -33,31 +34,53 @@ public static byte[][] Split(int width, int height, int bitlen, byte[] frame)
{
var planeSize = width * height / 8;
var planes = new byte[bitlen][];
for (var i = 0; i < bitlen; i++) {
planes[i] = new byte[planeSize];
}
var byteIdx = 0;
var bd = new byte[bitlen];
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x += 8) {
for (var i = 0; i < bitlen; i++) {
bd[i] = 0;
}
for (var v = 7; v >= 0; v--) {
var pixel = frame[(y * width) + (x + v)];
for (var i = 0; i < bitlen; i++) {
bd[i] <<= 1;
if ((pixel & ( 1 << i) ) != 0) {
bd[i] |= 1;

try
{
for (var i = 0; i < bitlen; i++)
{
planes[i] = new byte[planeSize];
}

var byteIdx = 0;
var bd = new byte[bitlen];
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x += 8)
{
for (var i = 0; i < bitlen; i++)
{
bd[i] = 0;
}

for (var v = 7; v >= 0; v--)
{
var pixel = frame[(y * width) + (x + v)];
for (var i = 0; i < bitlen; i++)
{
bd[i] <<= 1;
if ((pixel & (1 << i)) != 0)
{
bd[i] |= 1;
}
}
}

for (var i = 0; i < bitlen; i++)
{
planes[i][byteIdx] = bd[i];
}

byteIdx++;
}
for (var i = 0; i < bitlen; i++) {
planes[i][byteIdx] = bd[i];
}
byteIdx++;
}
}
catch (IndexOutOfRangeException e)
{
Logger.Error("Split failed: {0}x{1} frame:{2} bitlen:{3}", width, height, frame.Length, bitlen);
throw new IndexOutOfRangeException(e.Message);
}

return planes;
}

Expand Down
18 changes: 11 additions & 7 deletions LibDmd/DmdDevice/DmdDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ public DmdDevice()
Logger.Info("Starting VPinMAME API {0} through {1}.exe.", _fullVersion,
Process.GetCurrentProcess().ProcessName);
Logger.Info("Assembly located at {0}", assembly.Location);

Logger.Info("ScaleToHd = " + _config.Global.ScaleToHd);

if (_config.Global.ScaleToHd)
{
Logger.Info("ScalerMode = " + _config.Global.ScalerMode.ToString());
}
}

/// <summary>
Expand Down Expand Up @@ -232,8 +225,10 @@ private void SetupColorizer()
Logger.Info("Loaded animation set {0}", vni);
aniHeight = vni.MaxHeight;
aniWidth = vni.MaxWidth;
Logger.Info("Animation Dimensions: {0}x{1}", aniWidth, aniHeight);
} else
{
Logger.Info("No animation set found");
aniHeight = Height;
aniWidth = Width;
}
Expand All @@ -250,6 +245,15 @@ private void SetupColorizer()
} else {
Logger.Info("No palette file found at {0}.", palPath);
}

if (_config.Global.ScaleToHd)
{
Logger.Info("ScaleToHd = True, ScalerMode = " + _config.Global.ScalerMode.ToString());
}
else
{
Logger.Info("ScaleToHd = False");
}
}

/// <summary>
Expand Down

0 comments on commit ed1d459

Please sign in to comment.