Skip to content

Commit

Permalink
use libzedmd 0.8.0 for ZeDMD 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Dec 27, 2024
1 parent 82cbba5 commit 4485340
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 277 deletions.
Binary file modified LibDmd/Costura32/zedmd.dll
Binary file not shown.
Binary file modified LibDmd/Costura64/zedmd64.dll
Binary file not shown.
44 changes: 3 additions & 41 deletions LibDmd/Output/ZeDMD/ZeDMD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace LibDmd.Output.ZeDMD
/// Check "ZeDMD Project Page" https://github.com/PPUC/ZeDMD) for details.
/// This implementation supports ZeDMD and ZeDMD HD.
/// </summary>
public class ZeDMD : ZeDMDBase, IGray2Destination, IGray4Destination, IColoredGray2Destination, IColoredGray4Destination,
IColoredGray6Destination, IRgb565Destination, IMultiSizeDestination, IColorRotationDestination
public class ZeDMD : ZeDMDBase, IRgb24Destination, IRgb565Destination, IMultiSizeDestination
{
public override string Name => "ZeDMD";

Expand Down Expand Up @@ -40,9 +39,6 @@ public static ZeDMD GetInstance(bool debug, int brightness, int rgbOrder, string
OpenUSBConnection();
SendConfiguration();
ZeDMD_SetFrameSize(_pZeDMD, _currentDimensions.Width, _currentDimensions.Height);
ZeDMD_EnforceStreaming(_pZeDMD);
ZeDMD_EnablePreDownscaling(_pZeDMD);
ZeDMD_EnablePreUpscaling(_pZeDMD);
}

private void SetDimensions(Dimensions newDim)
Expand All @@ -53,50 +49,16 @@ private void SetDimensions(Dimensions newDim)
}
}

public void RenderGray2(DmdFrame frame)
{
SetDimensions(frame.Dimensions);
ZeDMD_RenderGray2(_pZeDMD, frame.Data);
}

public void RenderColoredGray2(ColoredFrame frame)
{
SetDimensions(frame.Dimensions);
SetPalette(frame.Palette);
ZeDMD_RenderGray2(_pZeDMD, frame.Data);
}

public void RenderGray4(DmdFrame frame)
{
SetDimensions(frame.Dimensions);
ZeDMD_RenderGray4(_pZeDMD, frame.Data);
}

public void RenderColoredGray4(ColoredFrame frame)
{
SetDimensions(frame.Dimensions);
SetPalette(frame.Palette);
ZeDMD_RenderGray4(_pZeDMD, frame.Data);
}

public void RenderColoredGray6(ColoredFrame frame)
{
SetDimensions(frame.Dimensions);
SetPalette(frame.Palette);
ZeDMD_RenderColoredGray6(_pZeDMD, frame.Data, null);
_lastFrame = (ColoredFrame)frame.Clone();
}

public void RenderRgb24(DmdFrame frame)
{
SetDimensions(frame.Dimensions);
ZeDMD_RenderRgb24EncodedAs565(_pZeDMD, frame.Data);
ZeDMD_RenderRgb888(_pZeDMD, frame.Data);
}

public void RenderRgb565(DmdFrame frame)
{
SetDimensions(frame.Dimensions);
ZeDMD_RenderRgb16(_pZeDMD, frame.Data);
ZeDMD_RenderRgb565(_pZeDMD, frame.Data);
}
}
}
117 changes: 6 additions & 111 deletions LibDmd/Output/ZeDMD/ZeDMDBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Media;
using NLog;
using System.Linq;
using System.IO.Ports;

namespace LibDmd.Output.ZeDMD
{
Expand Down Expand Up @@ -85,50 +86,14 @@ public void Dispose()

public void SetPalette(Color[] colors)
{
if (_pZeDMD == IntPtr.Zero) {
return;
}

byte[] paletteBuffer = Enumerable.Repeat((byte)0x0, 64 * 3).ToArray();
var numOfColors = colors.Length;

if (numOfColors != 4 && numOfColors != 16 && numOfColors != 64) {
return;
}

// Custom palettes could be defined with less colors as required by the ROM.
// So we interpolate bigger palettes up to 64 colors.
while (numOfColors <= 64) {
var palette = ColorUtil.GetPalette(colors, numOfColors);
var pos = 0;

foreach (var color in palette) {
paletteBuffer[pos++] = color.R;
paletteBuffer[pos++] = color.G;
paletteBuffer[pos++] = color.B;
}
ZeDMD_SetPalette(_pZeDMD, paletteBuffer, numOfColors);

numOfColors *= 4;
}
}

public void UpdatePalette(Color[] palette)
{
// For Rgb24, we get a new frame for each color rotation.
// But for ColoredGray6, we have to trigger the frame with
// an updated palette here.
if (_lastFrame != null) {
SetPalette(palette);
ZeDMD_RenderColoredGray6(_pZeDMD, _lastFrame.Data, null);
}
// no palette support here.
}

public void SetColor(Color color)
{
SetPalette(ColorUtil.GetPalette(new[] { Colors.Black, color }, 4));
// no palette support here.
}


public void ClearPalette()
{
}
Expand Down Expand Up @@ -179,34 +144,6 @@ public void ClearColor()
#endif
protected static extern void ZeDMD_EnableDebug(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_EnablePreDownscaling(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_DisablePreDownscaling(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_EnablePreUpscaling(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_DisablePreUpscaling(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
Expand All @@ -221,13 +158,6 @@ public void ClearColor()
#endif
protected static extern void ZeDMD_DisableUpscaling(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_EnforceStreaming(IntPtr pZeDMD);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
Expand Down Expand Up @@ -256,13 +186,6 @@ public void ClearColor()
#endif
protected static extern void ZeDMD_SetFrameSize(IntPtr pZeDMD, int width, int height);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_SetPalette(IntPtr pZeDMD, byte[] palette, int numColors);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
Expand All @@ -275,42 +198,14 @@ public void ClearColor()
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_RenderGray2(IntPtr pZeDMD, byte[] frame);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_RenderGray4(IntPtr pZeDMD, byte[] frame);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_RenderColoredGray6(IntPtr pZeDMD, byte[] frame, byte[] rotations);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_RenderRgb24(IntPtr pZeDMD, byte[] frame);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_RenderRgb24EncodedAs565(IntPtr pZeDMD, byte[] frame);
protected static extern void ZeDMD_RenderRgb888(IntPtr pZeDMD, byte[] frame);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("zedmd.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
#endif
protected static extern void ZeDMD_RenderRgb16(IntPtr pZeDMD, byte[] frame);
protected static extern void ZeDMD_RenderRgb565(IntPtr pZeDMD, byte[] frame);

#if PLATFORM_X64
[DllImport("zedmd64.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
Expand Down
52 changes: 6 additions & 46 deletions LibDmd/Output/ZeDMD/ZeDMDHD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace LibDmd.Output.ZeDMD
/// Check "ZeDMD Project Page" https://github.com/PPUC/ZeDMD) for details.
/// This implementation supports ZeDMD and ZeDMD HD.
/// </summary>
public class ZeDMDHD : ZeDMDBase, IGray2Destination, IGray4Destination, IColoredGray2Destination, IColoredGray4Destination,
IColoredGray6Destination, IRgb565Destination, IFixedSizeDestination, IColorRotationDestination
public class ZeDMDHD : ZeDMDBase, IRgb24Destination, IRgb565Destination, IFixedSizeDestination
{
public override string Name => "ZeDMD HD";
public virtual Dimensions FixedSize { get; } = new Dimensions(256, 64);
Expand Down Expand Up @@ -45,57 +44,18 @@ protected ZeDMDHD()
ZeDMD_SetFrameSize(_pZeDMD, FixedSize.Width, FixedSize.Height);
}

public void RenderGray2(DmdFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_EnablePreUpscaling(_pZeDMD);
ZeDMD_RenderGray2(_pZeDMD, frame.Data);
}

public void RenderColoredGray2(ColoredFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_EnablePreUpscaling(_pZeDMD);
SetPalette(frame.Palette);
ZeDMD_RenderGray2(_pZeDMD, frame.Data);
}

public void RenderGray4(DmdFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_DisablePreUpscaling(_pZeDMD);
ZeDMD_RenderGray4(_pZeDMD, frame.Data);
}

public void RenderColoredGray4(ColoredFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_DisablePreUpscaling(_pZeDMD);
SetPalette(frame.Palette);
ZeDMD_RenderGray4(_pZeDMD, frame.Data);
}

public void RenderColoredGray6(ColoredFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_EnablePreUpscaling(_pZeDMD);
SetPalette(frame.Palette);
ZeDMD_RenderColoredGray6(_pZeDMD, frame.Data, null);
_lastFrame = (ColoredFrame)frame.Clone();
}

public void RenderRgb24(DmdFrame frame)
{
DmdAllowHdScaling = ScaleRgb24;
ZeDMD_EnablePreUpscaling(_pZeDMD);
ZeDMD_RenderRgb24EncodedAs565(_pZeDMD, frame.Data);
if (!ScaleRgb24) { ZeDMD_DisableUpscaling(_pZeDMD); }
ZeDMD_RenderRgb888(_pZeDMD, frame.Data);
}

public void RenderRgb565(DmdFrame frame)
{
DmdAllowHdScaling = ScaleRgb24;
ZeDMD_EnablePreUpscaling(_pZeDMD);
ZeDMD_RenderRgb16(_pZeDMD, frame.Data);
DmdAllowHdScaling = true;
ZeDMD_EnableUpscaling(_pZeDMD);
ZeDMD_RenderRgb565(_pZeDMD, frame.Data);
}
}
}
42 changes: 3 additions & 39 deletions LibDmd/Output/ZeDMD/ZeDMDHDWiFi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace LibDmd.Output.ZeDMD
/// Check "ZeDMD Project Page" https://github.com/PPUC/ZeDMD) for details.
/// This implementation supports ZeDMD and ZeDMD HD.
/// </summary>
public class ZeDMDHDWiFi : ZeDMDWiFiBase, IGray2Destination, IGray4Destination, IColoredGray2Destination,
IColoredGray4Destination, IRgb565Destination, IColoredGray6Destination, IFixedSizeDestination, IColorRotationDestination
public class ZeDMDHDWiFi : ZeDMDWiFiBase, IRgb24Destination, IRgb565Destination, IFixedSizeDestination
{
public override string Name => "ZeDMD HD WiFi";
public virtual Dimensions FixedSize { get; } = new Dimensions(256, 64);
Expand Down Expand Up @@ -36,50 +35,15 @@ public static ZeDMDHDWiFi GetInstance(bool debug, int brightness, int rgbOrder,
ZeDMD_SetFrameSize(_pZeDMD, FixedSize.Width, FixedSize.Height);
}

public void RenderGray2(DmdFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_RenderGray2(_pZeDMD, frame.Data);
}

public void RenderColoredGray2(ColoredFrame frame)
{
DmdAllowHdScaling = true;
SetPalette(frame.Palette);
ZeDMD_RenderGray2(_pZeDMD, frame.Data);
}

public void RenderGray4(DmdFrame frame)
{
DmdAllowHdScaling = true;
ZeDMD_RenderGray4(_pZeDMD, frame.Data);
}

public void RenderColoredGray4(ColoredFrame frame)
{
DmdAllowHdScaling = true;
SetPalette(frame.Palette);
ZeDMD_RenderGray4(_pZeDMD, frame.Data);
}

public void RenderColoredGray6(ColoredFrame frame)
{
DmdAllowHdScaling = true;
SetPalette(frame.Palette);
ZeDMD_RenderColoredGray6(_pZeDMD, frame.Data, null);
_lastFrame = (ColoredFrame)frame.Clone();
}

public void RenderRgb24(DmdFrame frame)
{
DmdAllowHdScaling = ScaleRgb24;
ZeDMD_RenderRgb24EncodedAs565(_pZeDMD, frame.Data);
ZeDMD_RenderRgb888(_pZeDMD, frame.Data);
}

public void RenderRgb565(DmdFrame frame)
{
DmdAllowHdScaling = ScaleRgb24;
ZeDMD_RenderRgb16(_pZeDMD, frame.Data);
ZeDMD_RenderRgb565(_pZeDMD, frame.Data);
}
}
}
Loading

0 comments on commit 4485340

Please sign in to comment.