diff --git a/include/DMDUtil/LevelDMD.h b/include/DMDUtil/LevelDMD.h new file mode 100644 index 0000000..e83289c --- /dev/null +++ b/include/DMDUtil/LevelDMD.h @@ -0,0 +1,46 @@ +#pragma once + +#ifdef _MSC_VER +#define DMDUTILAPI __declspec(dllexport) +#define DMDUTILCALLBACK __stdcall +#else +#define DMDUTILAPI __attribute__((visibility("default"))) +#define DMDUTILCALLBACK +#endif + +#include + +namespace DMDUtil +{ + +class DMDUTILAPI LevelDMD +{ + public: + LevelDMD(uint16_t width, uint16_t height, bool sam); + ~LevelDMD(); + + void Update(uint8_t* pLevelData, uint8_t depth); + int GetWidth() { return m_width; } + int GetHeight() { return m_height; } + int GetLength() const { return m_length; } + int GetPitch() const { return m_pitch; } + uint8_t* GetData(); + + private: + static constexpr uint8_t LEVELS_WPC[] = {0x14, 0x21, 0x43, 0x64}; + static constexpr uint8_t LEVELS_GTS3[] = {0x00, 0x1E, 0x23, 0x28, 0x2D, 0x32, 0x37, 0x3C, + 0x41, 0x46, 0x4B, 0x50, 0x55, 0x5A, 0x5F, 0x64}; + static constexpr uint8_t LEVELS_SAM[] = {0x00, 0x14, 0x19, 0x1E, 0x23, 0x28, 0x2D, 0x32, + 0x37, 0x3C, 0x41, 0x46, 0x4B, 0x50, 0x5A, 0x64}; + + uint16_t m_width; + uint16_t m_height; + int m_length; + int m_pitch; + int m_update; + bool m_sam; + + uint8_t* m_pData; +}; + +} // namespace DMDUtil \ No newline at end of file diff --git a/include/DMDUtil/RGB24DMD.h b/include/DMDUtil/RGB24DMD.h new file mode 100644 index 0000000..34d0d3a --- /dev/null +++ b/include/DMDUtil/RGB24DMD.h @@ -0,0 +1,39 @@ +#pragma once + +#ifdef _MSC_VER +#define DMDUTILAPI __declspec(dllexport) +#define DMDUTILCALLBACK __stdcall +#else +#define DMDUTILAPI __attribute__((visibility("default"))) +#define DMDUTILCALLBACK +#endif + +#include + +namespace DMDUtil +{ + +class DMDUTILAPI RGB24DMD +{ + public: + RGB24DMD(uint16_t width, uint16_t height); + ~RGB24DMD(); + + void Update(uint8_t* pRGB24Data); + int GetWidth() { return m_width; } + int GetHeight() { return m_height; } + int GetLength() const { return m_length; } + int GetPitch() const { return m_pitch; } + uint8_t* GetData(); + + private: + uint16_t m_width; + uint16_t m_height; + int m_length; + int m_pitch; + int m_update; + + uint8_t* m_pData; +}; + +} // namespace DMDUtil \ No newline at end of file diff --git a/src/DMD.cpp b/src/DMD.cpp index 5fadc91..ade3e26 100644 --- a/src/DMD.cpp +++ b/src/DMD.cpp @@ -459,10 +459,9 @@ void DMD::ZeDMDThread() if (update) { if (m_updateBuffer[bufferPosition]->hasSegData2) - m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1, - (const uint16_t*)segData2); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, segData1, segData2); else - m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, segData1); m_pZeDMD->SetPalette(palette, 4); m_pZeDMD->RenderGray2(renderBuffer); @@ -514,14 +513,14 @@ void DMD::PixelcadeDMDThread() if (m_updateBuffer[bufferPosition]->mode == DMDMode::RGB24) { - AdjustRGB24Depth((uint8_t*)m_updateBuffer[bufferPosition]->data, rgb24Data, length * 3, palette, + AdjustRGB24Depth(m_updateBuffer[bufferPosition]->data, rgb24Data, length * 3, palette, m_updateBuffer[bufferPosition]->depth); for (int i = 0; i < length; i++) { int pos = i * 3; - uint32_t r = ((uint8_t*)(m_updateBuffer[bufferPosition]->data))[pos]; - uint32_t g = ((uint8_t*)(m_updateBuffer[bufferPosition]->data))[pos + 1]; - uint32_t b = ((uint8_t*)(m_updateBuffer[bufferPosition]->data))[pos + 2]; + uint32_t r = m_updateBuffer[bufferPosition]->data[pos]; + uint32_t g = m_updateBuffer[bufferPosition]->data[pos + 1]; + uint32_t b = m_updateBuffer[bufferPosition]->data[pos + 2]; rgb565Data[i] = (uint16_t)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | (b >> 3)); } @@ -565,11 +564,9 @@ void DMD::PixelcadeDMDThread() uint8_t* pData; if (m_updateBuffer[bufferPosition]->hasSegData2) - m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1, - (const uint16_t*)segData2); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, segData1, segData2); else - m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, - (const uint16_t*)segData1); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, segData1); } } @@ -668,7 +665,7 @@ void DMD::RGB24DMDThread() m_updateBuffer[bufferPosition]->g, m_updateBuffer[bufferPosition]->b); } - AdjustRGB24Depth((uint8_t*)m_updateBuffer[bufferPosition]->data, rgb24Data, length * 3, palette, + AdjustRGB24Depth(m_updateBuffer[bufferPosition]->data, rgb24Data, length * 3, palette, m_updateBuffer[bufferPosition]->depth); for (RGB24DMD* pRGB24DMD : m_rgb24DMDs) @@ -685,7 +682,7 @@ void DMD::RGB24DMDThread() // attached. if (m_updateBuffer[bufferPosition]->mode == DMDMode::Data && m_pSerum && !HasDisplay()) { - update = m_pSerum->Convert((uint8_t*)m_updateBuffer[bufferPosition]->data, renderBuffer, palette, + update = m_pSerum->Convert(m_updateBuffer[bufferPosition]->data, renderBuffer, palette, m_updateBuffer[bufferPosition]->width, m_updateBuffer[bufferPosition]->height); } else @@ -719,11 +716,9 @@ void DMD::RGB24DMDThread() if (update) { if (m_updateBuffer[bufferPosition]->hasSegData2) - m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, - (const uint16_t*)segData1, (const uint16_t*)segData2); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, segData1, segData2); else - m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, - (const uint16_t*)segData1); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, segData1); } } } diff --git a/src/LevelDMD.cpp b/src/LevelDMD.cpp new file mode 100644 index 0000000..d873b6b --- /dev/null +++ b/src/LevelDMD.cpp @@ -0,0 +1,56 @@ +#include "DMDUtil/LevelDMD.h" + +#include +#include +#include + +namespace DMDUtil +{ + +LevelDMD::LevelDMD(uint16_t width, uint16_t height, bool sam) +{ + m_width = width; + m_height = height; + m_length = width * height; + m_pitch = width * 3; + m_sam = sam; + + m_pData = (uint8_t*)malloc(m_length); + memset(m_pData, 0, m_length); + + m_update = false; +} + +LevelDMD::~LevelDMD() { free(m_pData); } + +void LevelDMD::Update(uint8_t* pData, uint8_t depth) +{ + memcpy(m_pData, pData, m_length); + if (depth == 2) + { + for (int i = 0; i < m_length; i++) m_pData[i] = LEVELS_WPC[pData[i]]; + m_update = true; + } + else if (depth == 4) + { + if (m_sam) + { + for (int i = 0; i < m_length; i++) m_pData[i] = LEVELS_SAM[pData[i]]; + } + else + { + for (int i = 0; i < m_length; i++) m_pData[i] = LEVELS_GTS3[pData[i]]; + } + m_update = true; + } +} + +uint8_t* LevelDMD::GetData() +{ + if (!m_update) return nullptr; + + m_update = false; + return m_pData; +} + +} // namespace DMDUtil \ No newline at end of file diff --git a/src/RGB24DMD.cpp b/src/RGB24DMD.cpp new file mode 100644 index 0000000..dff88bb --- /dev/null +++ b/src/RGB24DMD.cpp @@ -0,0 +1,40 @@ +#include "DMDUtil/RGB24DMD.h" + +#include +#include +#include + +namespace DMDUtil +{ + +RGB24DMD::RGB24DMD(uint16_t width, uint16_t height) +{ + m_width = width; + m_height = height; + m_length = width * height * 3; + m_pitch = width * 3; + + m_pData = (uint8_t*)malloc(m_length); + memset(m_pData, 0, m_length); + + m_update = false; +} + +RGB24DMD::~RGB24DMD() { free(m_pData); } + +void RGB24DMD::Update(uint8_t* pData) +{ + memcpy(m_pData, pData, m_length); + + m_update = true; +} + +uint8_t* RGB24DMD::GetData() +{ + if (!m_update) return nullptr; + + m_update = false; + return m_pData; +} + +} // namespace DMDUtil \ No newline at end of file