diff --git a/include/DMDUtil/DMD.h b/include/DMDUtil/DMD.h index b6f610a..aa49865 100644 --- a/include/DMDUtil/DMD.h +++ b/include/DMDUtil/DMD.h @@ -57,18 +57,15 @@ class VirtualDMD; class DMDUTILAPI DMD { public: - DMD(int width, int height, bool sam = false, const char* name = nullptr); + DMD(const char* name = nullptr); ~DMD(); static bool IsFinding(); bool HasDisplay() const; - int GetWidth() const { return m_width; } - int GetHeight() const { return m_height; } - int GetLength() const { return m_length; } - VirtualDMD* CreateVirtualDMD(); + VirtualDMD* CreateVirtualDMD(uint16_t width, uint16_t height); bool DestroyVirtualDMD(VirtualDMD* pVirtualDMD); - void UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b); - void UpdateRGB24Data(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b); + void UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b); + void UpdateRGB24Data(const uint8_t* pData, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b); void UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pData1, const uint16_t* pData2, uint8_t r, uint8_t g, uint8_t b); @@ -86,6 +83,7 @@ class DMDUTILAPI DMD DMDMode mode; AlphaNumericLayout layout; int depth; + bool sam; void* pData; void* pData2; uint8_t r; @@ -107,28 +105,18 @@ class DMDUTILAPI DMD void Run(); void Stop(); bool UpdatePalette(uint8_t* pPalette, uint8_t depth, uint8_t r, uint8_t g, uint8_t b); - void UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b, DMDMode node); + void UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b, DMDMode node); void DmdFrameReadyResetThread(); + void VirtualDMDThread(); void ZeDMDThread(); - int m_width; - int m_height; - int m_length; - bool m_sam; - uint8_t* m_pBuffer; - uint8_t* m_pRGB24Buffer; - uint16_t m_segData1[128]; - uint16_t m_segData2[128]; - uint8_t* m_pLevelData; - uint8_t* m_pRGB24Data; - uint16_t* m_pRGB565Data; - uint8_t m_palette[192]; uint8_t m_updateBufferPosition = 0; AlphaNumeric* m_pAlphaNumeric; Serum* m_pSerum; ZeDMD* m_pZeDMD; + std::thread* m_pVirtualDMDThread; std::thread* m_pZeDMDThread; std::thread* m_pdmdFrameReadyResetThread; std::shared_mutex m_dmdSharedMutex; diff --git a/include/DMDUtil/VirtualDMD.h b/include/DMDUtil/VirtualDMD.h index 7d1c349..60fa21c 100644 --- a/include/DMDUtil/VirtualDMD.h +++ b/include/DMDUtil/VirtualDMD.h @@ -16,10 +16,11 @@ namespace DMDUtil class DMDUTILAPI VirtualDMD { public: - VirtualDMD(int width, int height); + VirtualDMD(uint16_t width, uint16_t height); ~VirtualDMD(); - void Update(uint8_t* pLevelData, uint8_t* pRGB24Data); + void Update(uint8_t* pRGB24Data); + void UpdateLevel(uint8_t* pLevelData); int GetWidth() { return m_width; } int GetHeight() { return m_height; } int GetLength() const { return m_length; } @@ -28,8 +29,8 @@ class DMDUTILAPI VirtualDMD uint8_t* GetRGB24Data(); private: - int m_width; - int m_height; + uint16_t m_width; + uint16_t m_height; int m_length; int m_pitch; int m_update; diff --git a/src/AlphaNumeric.cpp b/src/AlphaNumeric.cpp index 1357057..f19cf43 100644 --- a/src/AlphaNumeric.cpp +++ b/src/AlphaNumeric.cpp @@ -180,409 +180,405 @@ const uint8_t AlphaNumeric::Segs[8][17][5][2] = { }; // clang-format on -AlphaNumeric::AlphaNumeric() { memset(m_frameBuffer, 0, sizeof(m_frameBuffer)); } +AlphaNumeric::AlphaNumeric() {} -uint8_t* AlphaNumeric::Render(AlphaNumericLayout layout, const uint16_t* const seg_data) +void AlphaNumeric::Render(uint8_t* pFrame, AlphaNumericLayout layout, const uint16_t* const seg_data) { if (layout != AlphaNumericLayout::__2x7Num_2x7Num_10x1Num) - Render(layout, seg_data, nullptr); + Render(pFrame, layout, seg_data, nullptr); else - Render(layout, seg_data, seg_data + 32); - - return m_frameBuffer; + Render(pFrame, layout, seg_data, seg_data + 32); } -uint8_t* AlphaNumeric::Render(AlphaNumericLayout layout, const uint16_t* const seg_data, +void AlphaNumeric::Render(uint8_t* pFrame, AlphaNumericLayout layout, const uint16_t* const seg_data, const uint16_t* const seg_data2) { - Clear(); + Clear(pFrame); switch (layout) { case AlphaNumericLayout::__2x16Alpha: - Render2x16Alpha(seg_data); + Render2x16Alpha(pFrame, seg_data); break; case AlphaNumericLayout::__2x20Alpha: - Render2x20Alpha(seg_data); + Render2x20Alpha(pFrame, seg_data); break; case AlphaNumericLayout::__2x7Alpha_2x7Num: - Render2x7Alpha_2x7Num(seg_data); + Render2x7Alpha_2x7Num(pFrame, seg_data); break; case AlphaNumericLayout::__2x7Alpha_2x7Num_4x1Num: - Render2x7Alpha_2x7Num_4x1Num(seg_data); + Render2x7Alpha_2x7Num_4x1Num(pFrame, seg_data); break; case AlphaNumericLayout::__2x7Num_2x7Num_4x1Num: - Render2x7Num_2x7Num_4x1Num(seg_data); + Render2x7Num_2x7Num_4x1Num(pFrame, seg_data); break; case AlphaNumericLayout::__2x7Num_2x7Num_10x1Num: - Render2x7Num_2x7Num_10x1Num(seg_data, seg_data2); + Render2x7Num_2x7Num_10x1Num(pFrame, seg_data, seg_data2); break; case AlphaNumericLayout::__2x7Num_2x7Num_4x1Num_gen7: - Render2x7Num_2x7Num_4x1Num_gen7(seg_data); + Render2x7Num_2x7Num_4x1Num_gen7(pFrame, seg_data); break; case AlphaNumericLayout::__2x7Num10_2x7Num10_4x1Num: - Render2x7Num10_2x7Num10_4x1Num(seg_data); + Render2x7Num10_2x7Num10_4x1Num(pFrame, seg_data); break; case AlphaNumericLayout::__2x6Num_2x6Num_4x1Num: - Render2x6Num_2x6Num_4x1Num(seg_data); + Render2x6Num_2x6Num_4x1Num(pFrame, seg_data); break; case AlphaNumericLayout::__2x6Num10_2x6Num10_4x1Num: - Render2x6Num10_2x6Num10_4x1Num(seg_data); + Render2x6Num10_2x6Num10_4x1Num(pFrame, seg_data); break; case AlphaNumericLayout::__4x7Num10: - Render4x7Num10(seg_data); + Render4x7Num10(pFrame, seg_data); break; case AlphaNumericLayout::__6x4Num_4x1Num: - Render6x4Num_4x1Num(seg_data); + Render6x4Num_4x1Num(pFrame, seg_data); break; case AlphaNumericLayout::__2x7Num_4x1Num_1x16Alpha: - Render2x7Num_4x1Num_1x16Alpha(seg_data); + Render2x7Num_4x1Num_1x16Alpha(pFrame, seg_data); break; case AlphaNumericLayout::__1x16Alpha_1x16Num_1x7Num: - Render1x16Alpha_1x16Num_1x7Num(seg_data); + Render1x16Alpha_1x16Num_1x7Num(pFrame, seg_data); break; case AlphaNumericLayout::__1x7Num_1x16Alpha_1x16Num: - Render1x7Num_1x16Alpha_1x16Num(seg_data); + Render1x7Num_1x16Alpha_1x16Num(pFrame, seg_data); break; case AlphaNumericLayout::__1x16Alpha_1x16Num_1x7Num_1x4Num: - Render1x16Alpha_1x16Num_1x7Num_1x4Num(seg_data); + Render1x16Alpha_1x16Num_1x7Num_1x4Num(pFrame, seg_data); break; default: break; } - - return m_frameBuffer; } -void AlphaNumeric::SmoothDigitCorners(const int x, const int y) +void AlphaNumeric::SmoothDigitCorners(uint8_t* pFrame, const int x, const int y) { - if (GetPixel(x, 1 + y) && GetPixel(1 + x, y)) DrawPixel(0 + x, y, 0); - if (GetPixel(x + 6, 1 + y) && GetPixel(5 + x, y)) DrawPixel(6 + x, y, 0); - if (GetPixel(x, 9 + y) && GetPixel(1 + x, 10 + y)) DrawPixel(0 + x, 10 + y, 0); - if (GetPixel(x + 6, 9 + y) && GetPixel(5 + x, 10 + y)) DrawPixel(6 + x, 10 + y, 0); + if (GetPixel(pFrame, x, 1 + y) && GetPixel(pFrame, 1 + x, y)) DrawPixel(pFrame, 0 + x, y, 0); + if (GetPixel(pFrame, x + 6, 1 + y) && GetPixel(pFrame, 5 + x, y)) DrawPixel(pFrame, 6 + x, y, 0); + if (GetPixel(pFrame, x, 9 + y) && GetPixel(pFrame, 1 + x, 10 + y)) DrawPixel(pFrame, 0 + x, 10 + y, 0); + if (GetPixel(pFrame, x + 6, 9 + y) && GetPixel(pFrame, 5 + x, 10 + y)) DrawPixel(pFrame, 6 + x, 10 + y, 0); } -void AlphaNumeric::SmoothDigitCorners6Px(const int x, const int y) +void AlphaNumeric::SmoothDigitCorners6Px(uint8_t* pFrame, const int x, const int y) { - if (GetPixel(x, 1 + y) && GetPixel(1 + x, y)) DrawPixel(0 + x, y, 0); - if (GetPixel(x + 4, 1 + y) && GetPixel(3 + x, y)) DrawPixel(4 + x, y, 0); - if (GetPixel(x, 9 + y) && GetPixel(1 + x, 10 + y)) DrawPixel(0 + x, 10 + y, 0); - if (GetPixel(x + 4, 9 + y) && GetPixel(3 + x, 10 + y)) DrawPixel(4 + x, 10 + y, 0); + if (GetPixel(pFrame, x, 1 + y) && GetPixel(pFrame, 1 + x, y)) DrawPixel(pFrame, 0 + x, y, 0); + if (GetPixel(pFrame, x + 4, 1 + y) && GetPixel(pFrame, 3 + x, y)) DrawPixel(pFrame, 4 + x, y, 0); + if (GetPixel(pFrame, x, 9 + y) && GetPixel(pFrame, 1 + x, 10 + y)) DrawPixel(pFrame, 0 + x, 10 + y, 0); + if (GetPixel(pFrame, x + 4, 9 + y) && GetPixel(pFrame, 3 + x, 10 + y)) DrawPixel(pFrame, 4 + x, 10 + y, 0); } -void AlphaNumeric::DrawSegment(const int x, const int y, const uint8_t type, const uint16_t seg, const uint8_t colour) +void AlphaNumeric::DrawSegment(uint8_t* pFrame, const int x, const int y, const uint8_t type, const uint16_t seg, const uint8_t colour) { - for (int i = 0; i < SegSizes[type][seg]; i++) DrawPixel(Segs[type][seg][i][0] + x, Segs[type][seg][i][1] + y, colour); + for (int i = 0; i < SegSizes[type][seg]; i++) DrawPixel(pFrame, Segs[type][seg][i][0] + x, Segs[type][seg][i][1] + y, colour); } -bool AlphaNumeric::GetPixel(const int x, const int y) const { return m_frameBuffer[y * 128 + x] > 0; } +bool AlphaNumeric::GetPixel(uint8_t* pFrame, const int x, const int y) const { return pFrame[y * 128 + x] > 0; } -void AlphaNumeric::DrawPixel(const int x, const int y, const uint8_t colour) { m_frameBuffer[y * 128 + x] = colour; } +void AlphaNumeric::DrawPixel(uint8_t* pFrame, const int x, const int y, const uint8_t colour) { pFrame[y * 128 + x] = colour; } -void AlphaNumeric::Clear() { memset(m_frameBuffer, 0, sizeof(m_frameBuffer)); } +void AlphaNumeric::Clear(uint8_t* pFrame) { memset(pFrame, 0, sizeof(pFrame)); } -void AlphaNumeric::Render2x16Alpha(const uint16_t* const seg_data) +void AlphaNumeric::Render2x16Alpha(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i] >> j) & 0x1) DrawSegment(i * 8, 2, 0, j, 3); - if ((seg_data[i + 16] >> j) & 0x1) DrawSegment(i * 8, 19, 0, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, i * 8, 2, 0, j, 3); + if ((seg_data[i + 16] >> j) & 0x1) DrawSegment(pFrame, i * 8, 19, 0, j, 3); } - SmoothDigitCorners(i * 8, 2); - SmoothDigitCorners(i * 8, 19); + SmoothDigitCorners(pFrame, i * 8, 2); + SmoothDigitCorners(pFrame, i * 8, 19); } } -void AlphaNumeric::Render2x20Alpha(const uint16_t* const seg_data) +void AlphaNumeric::Render2x20Alpha(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 20; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i] >> j) & 0x1) DrawSegment((i * 6) + 4, 2, 7, j, 3); - if ((seg_data[i + 20] >> j) & 0x1) DrawSegment((i * 6) + 4, 19, 7, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i * 6) + 4, 2, 7, j, 3); + if ((seg_data[i + 20] >> j) & 0x1) DrawSegment(pFrame, (i * 6) + 4, 19, 7, j, 3); } - SmoothDigitCorners6Px((i * 6) + 4, 2); - SmoothDigitCorners6Px((i * 6) + 4, 19); + SmoothDigitCorners6Px(pFrame, (i * 6) + 4, 2); + SmoothDigitCorners6Px(pFrame, (i * 6) + 4, 19); } } -void AlphaNumeric::Render2x7Alpha_2x7Num(const uint16_t* const seg_data) +void AlphaNumeric::Render2x7Alpha_2x7Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 alphanumeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 2, 0, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 2, 0, j, 3); // 2x7 numeric - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 19, 1, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 19, 1, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 2); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 19); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 2); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 19); } } -void AlphaNumeric::Render2x7Alpha_2x7Num_4x1Num(const uint16_t* const seg_data) +void AlphaNumeric::Render2x7Alpha_2x7Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 alphanumeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 0, 0, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0, 0, j, 3); // 2x7 numeric - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 21, 1, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 21, 1, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 0); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 21); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 21); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[28] >> j) & 0x1) DrawSegment(8, 12, 5, j, 3); - if ((seg_data[29] >> j) & 0x1) DrawSegment(16, 12, 5, j, 3); - if ((seg_data[30] >> j) & 0x1) DrawSegment(32, 12, 5, j, 3); - if ((seg_data[31] >> j) & 0x1) DrawSegment(40, 12, 5, j, 3); + if ((seg_data[28] >> j) & 0x1) DrawSegment(pFrame, 8, 12, 5, j, 3); + if ((seg_data[29] >> j) & 0x1) DrawSegment(pFrame, 16, 12, 5, j, 3); + if ((seg_data[30] >> j) & 0x1) DrawSegment(pFrame, 32, 12, 5, j, 3); + if ((seg_data[31] >> j) & 0x1) DrawSegment(pFrame, 40, 12, 5, j, 3); } } -void AlphaNumeric::Render2x6Num_2x6Num_4x1Num(const uint16_t* const seg_data) +void AlphaNumeric::Render2x6Num_2x6Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 16; j++) { // 2x6 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 6) ? 0 : 4)) * 8, 0, 1, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 0, 1, j, 3); // 2x6 numeric - if ((seg_data[i + 12] >> j) & 0x1) DrawSegment((i + ((i < 6) ? 0 : 4)) * 8, 12, 1, j, 3); + if ((seg_data[i + 12] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 12, 1, j, 3); } - SmoothDigitCorners((i + ((i < 6) ? 0 : 4)) * 8, 0); - SmoothDigitCorners((i + ((i < 6) ? 0 : 4)) * 8, 12); + SmoothDigitCorners(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 12); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[24] >> j) & 0x1) DrawSegment(8, 24, 5, j, 3); - if ((seg_data[25] >> j) & 0x1) DrawSegment(16, 24, 5, j, 3); - if ((seg_data[26] >> j) & 0x1) DrawSegment(32, 24, 5, j, 3); - if ((seg_data[27] >> j) & 0x1) DrawSegment(40, 24, 5, j, 3); + if ((seg_data[24] >> j) & 0x1) DrawSegment(pFrame, 8, 24, 5, j, 3); + if ((seg_data[25] >> j) & 0x1) DrawSegment(pFrame, 16, 24, 5, j, 3); + if ((seg_data[26] >> j) & 0x1) DrawSegment(pFrame, 32, 24, 5, j, 3); + if ((seg_data[27] >> j) & 0x1) DrawSegment(pFrame, 40, 24, 5, j, 3); } } -void AlphaNumeric::Render2x6Num10_2x6Num10_4x1Num(const uint16_t* const seg_data) +void AlphaNumeric::Render2x6Num10_2x6Num10_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 16; j++) { // 2x6 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 6) ? 0 : 4)) * 8, 0, 2, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 0, 2, j, 3); // 2x6 numeric - if ((seg_data[i + 12] >> j) & 0x1) DrawSegment((i + ((i < 6) ? 0 : 4)) * 8, 20, 2, j, 3); + if ((seg_data[i + 12] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 20, 2, j, 3); } - SmoothDigitCorners((i + ((i < 6) ? 0 : 4)) * 8, 0); - SmoothDigitCorners((i + ((i < 6) ? 0 : 4)) * 8, 20); + SmoothDigitCorners(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 6) ? 0 : 4)) * 8, 20); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[24] >> j) & 0x1) DrawSegment(8, 12, 5, j, 3); - if ((seg_data[25] >> j) & 0x1) DrawSegment(16, 12, 5, j, 3); - if ((seg_data[26] >> j) & 0x1) DrawSegment(32, 12, 5, j, 3); - if ((seg_data[27] >> j) & 0x1) DrawSegment(40, 12, 5, j, 3); + if ((seg_data[24] >> j) & 0x1) DrawSegment(pFrame, 8, 12, 5, j, 3); + if ((seg_data[25] >> j) & 0x1) DrawSegment(pFrame, 16, 12, 5, j, 3); + if ((seg_data[26] >> j) & 0x1) DrawSegment(pFrame, 32, 12, 5, j, 3); + if ((seg_data[27] >> j) & 0x1) DrawSegment(pFrame, 40, 12, 5, j, 3); } } -void AlphaNumeric::Render2x7Num_2x7Num_4x1Num(const uint16_t* const seg_data) +void AlphaNumeric::Render2x7Num_2x7Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 0, 1, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0, 1, j, 3); // 2x7 numeric - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 12, 1, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 12, 1, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 0); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 12); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 12); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[28] >> j) & 0x1) DrawSegment(16, 24, 5, j, 3); - if ((seg_data[29] >> j) & 0x1) DrawSegment(24, 24, 5, j, 3); - if ((seg_data[30] >> j) & 0x1) DrawSegment(40, 24, 5, j, 3); - if ((seg_data[31] >> j) & 0x1) DrawSegment(48, 24, 5, j, 3); + if ((seg_data[28] >> j) & 0x1) DrawSegment(pFrame, 16, 24, 5, j, 3); + if ((seg_data[29] >> j) & 0x1) DrawSegment(pFrame, 24, 24, 5, j, 3); + if ((seg_data[30] >> j) & 0x1) DrawSegment(pFrame, 40, 24, 5, j, 3); + if ((seg_data[31] >> j) & 0x1) DrawSegment(pFrame, 48, 24, 5, j, 3); } } -void AlphaNumeric::Render2x7Num_2x7Num_10x1Num(const uint16_t* const seg_data, const uint16_t* const extra_seg_data) +void AlphaNumeric::Render2x7Num_2x7Num_10x1Num(uint8_t* pFrame, const uint16_t* const seg_data, const uint16_t* const extra_seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 0, 1, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0, 1, j, 3); // 2x7 numeric - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 12, 1, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 12, 1, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 0); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 12); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 12); } // 10x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[28] >> j) & 0x1) DrawSegment(16, 24, 5, j, 3); - if ((seg_data[29] >> j) & 0x1) DrawSegment(24, 24, 5, j, 3); - if ((seg_data[30] >> j) & 0x1) DrawSegment(40, 24, 5, j, 3); - if ((seg_data[31] >> j) & 0x1) DrawSegment(48, 24, 5, j, 3); - if ((extra_seg_data[0] >> j) & 0x1) DrawSegment(64, 24, 5, j, 3); - if ((extra_seg_data[1] >> j) & 0x1) DrawSegment(72, 24, 5, j, 3); - if ((extra_seg_data[2] >> j) & 0x1) DrawSegment(88, 24, 5, j, 3); - if ((extra_seg_data[3] >> j) & 0x1) DrawSegment(96, 24, 5, j, 3); - if ((extra_seg_data[4] >> j) & 0x1) DrawSegment(112, 24, 5, j, 3); - if ((extra_seg_data[5] >> j) & 0x1) DrawSegment(120, 24, 5, j, 3); + if ((seg_data[28] >> j) & 0x1) DrawSegment(pFrame, 16, 24, 5, j, 3); + if ((seg_data[29] >> j) & 0x1) DrawSegment(pFrame, 24, 24, 5, j, 3); + if ((seg_data[30] >> j) & 0x1) DrawSegment(pFrame, 40, 24, 5, j, 3); + if ((seg_data[31] >> j) & 0x1) DrawSegment(pFrame, 48, 24, 5, j, 3); + if ((extra_seg_data[0] >> j) & 0x1) DrawSegment(pFrame, 64, 24, 5, j, 3); + if ((extra_seg_data[1] >> j) & 0x1) DrawSegment(pFrame, 72, 24, 5, j, 3); + if ((extra_seg_data[2] >> j) & 0x1) DrawSegment(pFrame, 88, 24, 5, j, 3); + if ((extra_seg_data[3] >> j) & 0x1) DrawSegment(pFrame, 96, 24, 5, j, 3); + if ((extra_seg_data[4] >> j) & 0x1) DrawSegment(pFrame, 112, 24, 5, j, 3); + if ((extra_seg_data[5] >> j) & 0x1) DrawSegment(pFrame, 120, 24, 5, j, 3); } } -void AlphaNumeric::Render2x7Num_2x7Num_4x1Num_gen7(const uint16_t* const seg_data) +void AlphaNumeric::Render2x7Num_2x7Num_4x1Num_gen7(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 21, 1, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 21, 1, j, 3); // 2x7 numeric - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 1, 1, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 1, 1, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 21); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 1); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 21); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 1); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[28] >> j) & 0x1) DrawSegment(8, 13, 5, j, 3); - if ((seg_data[29] >> j) & 0x1) DrawSegment(16, 13, 5, j, 3); - if ((seg_data[30] >> j) & 0x1) DrawSegment(32, 13, 5, j, 3); - if ((seg_data[31] >> j) & 0x1) DrawSegment(40, 13, 5, j, 3); + if ((seg_data[28] >> j) & 0x1) DrawSegment(pFrame, 8, 13, 5, j, 3); + if ((seg_data[29] >> j) & 0x1) DrawSegment(pFrame, 16, 13, 5, j, 3); + if ((seg_data[30] >> j) & 0x1) DrawSegment(pFrame, 32, 13, 5, j, 3); + if ((seg_data[31] >> j) & 0x1) DrawSegment(pFrame, 40, 13, 5, j, 3); } } -void AlphaNumeric::Render2x7Num10_2x7Num10_4x1Num(const uint16_t* const seg_data) +void AlphaNumeric::Render2x7Num10_2x7Num10_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 0, 2, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0, 2, j, 3); // 2x7 numeric - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 20, 2, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 20, 2, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 0); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 20); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 20); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[28] >> j) & 0x1) DrawSegment(8, 12, 5, j, 3); - if ((seg_data[29] >> j) & 0x1) DrawSegment(16, 12, 5, j, 3); - if ((seg_data[30] >> j) & 0x1) DrawSegment(32, 12, 5, j, 3); - if ((seg_data[31] >> j) & 0x1) DrawSegment(40, 12, 5, j, 3); + if ((seg_data[28] >> j) & 0x1) DrawSegment(pFrame, 8, 12, 5, j, 3); + if ((seg_data[29] >> j) & 0x1) DrawSegment(pFrame, 16, 12, 5, j, 3); + if ((seg_data[30] >> j) & 0x1) DrawSegment(pFrame, 32, 12, 5, j, 3); + if ((seg_data[31] >> j) & 0x1) DrawSegment(pFrame, 40, 12, 5, j, 3); } } -void AlphaNumeric::Render4x7Num10(const uint16_t* const seg_data) +void AlphaNumeric::Render4x7Num10(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 numeric10 - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 1, 2, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 1, 2, j, 3); // 2x7 numeric10 - if ((seg_data[i + 14] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 13, 2, j, 3); + if ((seg_data[i + 14] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 13, 2, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 1); - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 13); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 1); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 13); } } -void AlphaNumeric::Render6x4Num_4x1Num(const uint16_t* const seg_data) +void AlphaNumeric::Render6x4Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 16; j++) { // 2x4 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 4) ? 0 : 2)) * 8, 1, 5, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 4) ? 0 : 2)) * 8, 1, 5, j, 3); // 2x4 numeric - if ((seg_data[i + 8] >> j) & 0x1) DrawSegment((i + ((i < 4) ? 0 : 2)) * 8, 9, 5, j, 3); + if ((seg_data[i + 8] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 4) ? 0 : 2)) * 8, 9, 5, j, 3); // 2x4 numeric - if ((seg_data[i + 16] >> j) & 0x1) DrawSegment((i + ((i < 4) ? 0 : 2)) * 8, 17, 5, j, 3); + if ((seg_data[i + 16] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 4) ? 0 : 2)) * 8, 17, 5, j, 3); } - SmoothDigitCorners((i + ((i < 4) ? 0 : 2)) * 8, 1); - SmoothDigitCorners((i + ((i < 4) ? 0 : 2)) * 8, 9); - SmoothDigitCorners((i + ((i < 4) ? 0 : 2)) * 8, 17); + SmoothDigitCorners(pFrame, (i + ((i < 4) ? 0 : 2)) * 8, 1); + SmoothDigitCorners(pFrame, (i + ((i < 4) ? 0 : 2)) * 8, 9); + SmoothDigitCorners(pFrame, (i + ((i < 4) ? 0 : 2)) * 8, 17); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[24] >> j) & 0x1) DrawSegment(16, 25, 5, j, 3); - if ((seg_data[25] >> j) & 0x1) DrawSegment(24, 25, 5, j, 3); - if ((seg_data[26] >> j) & 0x1) DrawSegment(48, 25, 5, j, 3); - if ((seg_data[27] >> j) & 0x1) DrawSegment(56, 25, 5, j, 3); + if ((seg_data[24] >> j) & 0x1) DrawSegment(pFrame, 16, 25, 5, j, 3); + if ((seg_data[25] >> j) & 0x1) DrawSegment(pFrame, 24, 25, 5, j, 3); + if ((seg_data[26] >> j) & 0x1) DrawSegment(pFrame, 48, 25, 5, j, 3); + if ((seg_data[27] >> j) & 0x1) DrawSegment(pFrame, 56, 25, 5, j, 3); } } -void AlphaNumeric::Render2x7Num_4x1Num_1x16Alpha(const uint16_t* const seg_data) +void AlphaNumeric::Render2x7Num_4x1Num_1x16Alpha(uint8_t* pFrame, const uint16_t* const seg_data) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 16; j++) { // 2x7 numeric - if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 7) ? 0 : 2)) * 8, 0, 1, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0, 1, j, 3); } - SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 0); + SmoothDigitCorners(pFrame, (i + ((i < 7) ? 0 : 2)) * 8, 0); } // 4x1 numeric small for (int j = 0; j < 16; j++) { - if ((seg_data[14] >> j) & 0x1) DrawSegment(16, 12, 5, j, 3); - if ((seg_data[15] >> j) & 0x1) DrawSegment(24, 12, 5, j, 3); - if ((seg_data[16] >> j) & 0x1) DrawSegment(40, 12, 5, j, 3); - if ((seg_data[17] >> j) & 0x1) DrawSegment(48, 12, 5, j, 3); + if ((seg_data[14] >> j) & 0x1) DrawSegment(pFrame, 16, 12, 5, j, 3); + if ((seg_data[15] >> j) & 0x1) DrawSegment(pFrame, 24, 12, 5, j, 3); + if ((seg_data[16] >> j) & 0x1) DrawSegment(pFrame, 40, 12, 5, j, 3); + if ((seg_data[17] >> j) & 0x1) DrawSegment(pFrame, 48, 12, 5, j, 3); } // 1x16 alphanumeric for (int i = 0; i < 12; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 18] >> j) & 0x1) DrawSegment((i * 8) + 16, 21, 0, j, 3); + if ((seg_data[i + 18] >> j) & 0x1) DrawSegment(pFrame, (i * 8) + 16, 21, 0, j, 3); } - SmoothDigitCorners((i * 8) + 16, 21); + SmoothDigitCorners(pFrame, (i * 8) + 16, 21); } } -void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data) +void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(uint8_t* pFrame, const uint16_t* const seg_data) { // 1x16 alphanumeric for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i] >> j) & 0x1) DrawSegment((i * 8), 9, 0, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i * 8), 9, 0, j, 3); } - SmoothDigitCorners((i * 8), 9); + SmoothDigitCorners(pFrame, (i * 8), 9); } // 1x16 numeric @@ -590,9 +586,9 @@ void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 16] >> j) & 0x1) DrawSegment((i * 8), 21, 1, j, 3); + if ((seg_data[i + 16] >> j) & 0x1) DrawSegment(pFrame, (i * 8), 21, 1, j, 3); } - SmoothDigitCorners((i * 8), 21); + SmoothDigitCorners(pFrame, (i * 8), 21); } // 1x7 numeric small @@ -600,67 +596,67 @@ void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 32] >> j) & 0x1) DrawSegment((i * 8) + 68, 1, 5, j, 3); + if ((seg_data[i + 32] >> j) & 0x1) DrawSegment(pFrame, (i * 8) + 68, 1, 5, j, 3); } } } -void AlphaNumeric::Render1x7Num_1x16Alpha_1x16Num(const uint16_t* const seg_data) +void AlphaNumeric::Render1x7Num_1x16Alpha_1x16Num(uint8_t* pFrame, const uint16_t* const seg_data) { // 1x16 alphanumeric for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 8] >> j) & 0x1) DrawSegment((i * 8), 9, 0, j, 3); + if ((seg_data[i + 8] >> j) & 0x1) DrawSegment(pFrame, (i * 8), 9, 0, j, 3); } - SmoothDigitCorners((i * 8), 9); + SmoothDigitCorners(pFrame, (i * 8), 9); } // 1x16 numeric for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 24] >> j) & 0x1) DrawSegment((i * 8), 21, 1, j, 3); + if ((seg_data[i + 24] >> j) & 0x1) DrawSegment(pFrame, (i * 8), 21, 1, j, 3); } - SmoothDigitCorners((i * 8), 21); + SmoothDigitCorners(pFrame, (i * 8), 21); } // 1x7 numeric small for (int i = 0; i < 7; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 1] >> j) & 0x1) DrawSegment((i * 8) + 68, 1, 5, j, 3); + if ((seg_data[i + 1] >> j) & 0x1) DrawSegment(pFrame, (i * 8) + 68, 1, 5, j, 3); } } } -void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num_1x4Num(const uint16_t* const seg_data) +void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num_1x4Num(uint8_t* pFrame, const uint16_t* const seg_data) { // 1x16 alphanumeric for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 11] >> j) & 0x1) DrawSegment((i * 8), 9, 0, j, 3); + if ((seg_data[i + 11] >> j) & 0x1) DrawSegment(pFrame, (i * 8), 9, 0, j, 3); } - SmoothDigitCorners((i * 8), 9); + SmoothDigitCorners(pFrame, (i * 8), 9); } // 1x16 numeric for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 27] >> j) & 0x1) DrawSegment((i * 8), 21, 1, j, 3); + if ((seg_data[i + 27] >> j) & 0x1) DrawSegment(pFrame, (i * 8), 21, 1, j, 3); } - SmoothDigitCorners((i * 8), 21); + SmoothDigitCorners(pFrame, (i * 8), 21); } // 1x4 numeric small for (int i = 0; i < 4; i++) { for (int j = 0; j < 16; j++) { - if ((seg_data[i + 7] >> j) & 0x1) DrawSegment((i * 8) + 4, 1, 5, j, 3); + if ((seg_data[i + 7] >> j) & 0x1) DrawSegment(pFrame, (i * 8) + 4, 1, 5, j, 3); } } // 1x7 numeric small @@ -668,7 +664,7 @@ void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num_1x4Num(const uint16_t* const s { for (int j = 0; j < 16; j++) { - if ((seg_data[i] >> j) & 0x1) DrawSegment((i * 8) + 68, 1, 5, j, 3); + if ((seg_data[i] >> j) & 0x1) DrawSegment(pFrame, (i * 8) + 68, 1, 5, j, 3); } } } diff --git a/src/AlphaNumeric.h b/src/AlphaNumeric.h index 4a73abd..ff86433 100644 --- a/src/AlphaNumeric.h +++ b/src/AlphaNumeric.h @@ -20,35 +20,33 @@ class AlphaNumeric AlphaNumeric(); ~AlphaNumeric() {} - uint8_t* Render(AlphaNumericLayout layout, const uint16_t* const seg_data); - uint8_t* Render(AlphaNumericLayout layout, const uint16_t* const seg_data, const uint16_t* const seg_data2); + void Render(uint8_t* pFrame, AlphaNumericLayout layout, const uint16_t* const seg_data); + void Render(uint8_t* pFrame, AlphaNumericLayout layout, const uint16_t* const seg_data, const uint16_t* const seg_data2); private: - void SmoothDigitCorners(const int x, const int y); - void SmoothDigitCorners6Px(const int x, const int y); - void DrawSegment(const int x, const int y, const uint8_t type, const uint16_t seg, const uint8_t colour); - bool GetPixel(const int x, const int y) const; - void DrawPixel(const int x, const int y, const uint8_t colour); - void Clear(); - - void Render2x16Alpha(const uint16_t* const seg_data); - void Render2x20Alpha(const uint16_t* const seg_data); - void Render2x7Alpha_2x7Num(const uint16_t* const seg_data); - void Render2x7Alpha_2x7Num_4x1Num(const uint16_t* const seg_data); - void Render2x6Num_2x6Num_4x1Num(const uint16_t* const seg_data); - void Render2x6Num10_2x6Num10_4x1Num(const uint16_t* const seg_data); - void Render2x7Num_2x7Num_4x1Num(const uint16_t* const seg_data); - void Render2x7Num_2x7Num_10x1Num(const uint16_t* const seg_data, const uint16_t* const extra_seg_data); - void Render2x7Num_2x7Num_4x1Num_gen7(const uint16_t* const seg_data); - void Render2x7Num10_2x7Num10_4x1Num(const uint16_t* const seg_data); - void Render4x7Num10(const uint16_t* const seg_data); - void Render6x4Num_4x1Num(const uint16_t* const seg_data); - void Render2x7Num_4x1Num_1x16Alpha(const uint16_t* const seg_data); - void Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data); - void Render1x7Num_1x16Alpha_1x16Num(const uint16_t* const seg_data); - void Render1x16Alpha_1x16Num_1x7Num_1x4Num(const uint16_t* const seg_data); - - uint8_t m_frameBuffer[4096]; + void SmoothDigitCorners(uint8_t* pFrame, const int x, const int y); + void SmoothDigitCorners6Px(uint8_t* pFrame, const int x, const int y); + void DrawSegment(uint8_t* pFrame, const int x, const int y, const uint8_t type, const uint16_t seg, const uint8_t colour); + bool GetPixel(uint8_t* pFrame, const int x, const int y) const; + void DrawPixel(uint8_t* pFrame, const int x, const int y, const uint8_t colour); + void Clear(uint8_t* pFrame); + + void Render2x16Alpha(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x20Alpha(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x7Alpha_2x7Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x7Alpha_2x7Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x6Num_2x6Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x6Num10_2x6Num10_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x7Num_2x7Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x7Num_2x7Num_10x1Num(uint8_t* pFrame, const uint16_t* const seg_data, const uint16_t* const extra_seg_data); + void Render2x7Num_2x7Num_4x1Num_gen7(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x7Num10_2x7Num10_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render4x7Num10(uint8_t* pFrame, const uint16_t* const seg_data); + void Render6x4Num_4x1Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render2x7Num_4x1Num_1x16Alpha(uint8_t* pFrame, const uint16_t* const seg_data); + void Render1x16Alpha_1x16Num_1x7Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render1x7Num_1x16Alpha_1x16Num(uint8_t* pFrame, const uint16_t* const seg_data); + void Render1x16Alpha_1x16Num_1x7Num_1x4Num(uint8_t* pFrame, const uint16_t* const seg_data); static const uint8_t SegSizes[8][16]; static const uint8_t Segs[8][17][5][2]; diff --git a/src/DMD.cpp b/src/DMD.cpp index d931703..b809998 100644 --- a/src/DMD.cpp +++ b/src/DMD.cpp @@ -31,25 +31,8 @@ void ZEDMDCALLBACK ZeDMDLogCallback(const char* format, va_list args, const void bool DMD::m_finding = false; -DMD::DMD(int width, int height, bool sam, const char* name) +DMD::DMD(const char* name) { - m_width = width; - m_height = height; - m_length = width * height; - m_sam = sam; - m_pBuffer = (uint8_t*)malloc(m_length); - memset(m_pBuffer, 0, m_length); - m_pRGB24Buffer = (uint8_t*)malloc(m_length * 3); - memset(m_pRGB24Buffer, 0, m_length * 3); - memset(m_segData1, 0, 128 * sizeof(uint16_t)); - memset(m_segData2, 0, 128 * sizeof(uint16_t)); - m_pLevelData = (uint8_t*)malloc(m_length); - memset(m_pLevelData, 0, m_length); - m_pRGB24Data = (uint8_t*)malloc(m_length * 3); - memset(m_pRGB24Data, 0, m_length * 3); - m_pRGB565Data = (uint16_t*)malloc(m_length * sizeof(uint16_t)); - memset(m_pRGB565Data, 0, m_length * sizeof(uint16_t)); - memset(m_palette, 0, 192); for (uint8_t i = 0; i < DMD_FRAME_BUFFER_SIZE; i++) { m_updateBuffer[i] = new DMDUpdate(); @@ -83,6 +66,13 @@ DMD::~DMD() delete m_pdmdFrameReadyResetThread; m_pdmdFrameReadyResetThread = nullptr; + if (m_pVirtualDMDThread) + { + m_pVirtualDMDThread->join(); + delete m_pVirtualDMDThread; + m_pVirtualDMDThread = nullptr; + } + if (m_pZeDMDThread) { m_pZeDMDThread->join(); @@ -100,20 +90,6 @@ DMD::~DMD() m_pPixelcadeDMDThread = nullptr; } #endif - /* - while (!m_updates.empty()) { - DMDUpdate* const pUpdate = m_updates.front(); - m_updates.pop(); - free(pUpdate->pData); - free(pUpdate->pData2); - delete pUpdate; - } - */ - free(m_pBuffer); - free(m_pRGB24Buffer); - free(m_pLevelData); - free(m_pRGB24Data); - free(m_pRGB565Data); delete m_pAlphaNumeric; delete m_pSerum; delete m_pZeDMD; @@ -139,10 +115,11 @@ bool DMD::HasDisplay() const #endif } -VirtualDMD* DMD::CreateVirtualDMD() +VirtualDMD* DMD::CreateVirtualDMD(uint16_t width, uint16_t height) { - VirtualDMD* const pVirtualDMD = new VirtualDMD(m_width, m_height); + VirtualDMD* const pVirtualDMD = new VirtualDMD(width, height); m_virtualDMDs.push_back(pVirtualDMD); + if (!m_pZeDMDThread) m_pZeDMDThread = new std::thread(&DMD::VirtualDMDThread, this); return pVirtualDMD; } @@ -154,19 +131,24 @@ bool DMD::DestroyVirtualDMD(VirtualDMD* pVirtualDMD) m_virtualDMDs.erase(it); delete pVirtualDMD; + if (m_virtualDMDs.empty()) + { + //@todo terminate VirtualDMDThread + } + return true; } return false; } -void DMD::UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b, DMDMode mode) +void DMD::UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b, DMDMode mode) { std::unique_lock ul(m_dmdSharedMutex); m_updateBuffer[m_updateBufferPosition]->mode = mode; m_updateBuffer[m_updateBufferPosition]->depth = depth; // @todo width, height and length have to be dynamic. - m_updateBuffer[m_updateBufferPosition]->width = m_width; - m_updateBuffer[m_updateBufferPosition]->height = m_height; + m_updateBuffer[m_updateBufferPosition]->width = width; + m_updateBuffer[m_updateBufferPosition]->height = height; if (m_updateBuffer[m_updateBufferPosition]->pData != nullptr) { free(m_updateBuffer[m_updateBufferPosition]->pData); @@ -179,8 +161,8 @@ void DMD::UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint } if (pData) { - m_updateBuffer[m_updateBufferPosition]->pData = malloc(m_width * m_height * (mode == DMDMode::RGB24 ? 3 : 1)); - memcpy(m_updateBuffer[m_updateBufferPosition]->pData, pData, m_width * m_height * (mode == DMDMode::RGB24 ? 3 : 1)); + m_updateBuffer[m_updateBufferPosition]->pData = malloc(width * height * (mode == DMDMode::RGB24 ? 3 : 1)); + memcpy(m_updateBuffer[m_updateBufferPosition]->pData, pData, width * height * (mode == DMDMode::RGB24 ? 3 : 1)); } m_updateBuffer[m_updateBufferPosition]->r = r; m_updateBuffer[m_updateBufferPosition]->g = g; @@ -190,20 +172,17 @@ void DMD::UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint ul.unlock(); m_dmdCV.notify_all(); - if (++m_updateBufferPosition >= DMD_FRAME_BUFFER_SIZE) - { - m_updateBufferPosition = 0; - } + if (++m_updateBufferPosition >= DMD_FRAME_BUFFER_SIZE) m_updateBufferPosition = 0; } -void DMD::UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b) +void DMD::UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b) { - UpdateData(pData, depth, r, g, b, DMDMode::Data); + UpdateData(pData, depth, width, height, r, g, b, DMDMode::Data); } -void DMD::UpdateRGB24Data(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b) +void DMD::UpdateRGB24Data(const uint8_t* pData, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b) { - UpdateData(pData, depth, r, g, b, DMDMode::RGB24); + UpdateData(pData, 24, width, height, r, g, b, DMDMode::RGB24); } void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pData1, const uint16_t* pData2, uint8_t r, @@ -239,31 +218,7 @@ void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pDat ul.unlock(); m_dmdCV.notify_all(); - if (++m_updateBufferPosition >= DMD_FRAME_BUFFER_SIZE) - { - m_updateBufferPosition = 0; - } -} - -void DMD::DmdFrameReadyResetThread() -{ - while (true) - { - std::shared_lock sl(m_dmdSharedMutex); - m_dmdCV.wait(sl, [&]() { return m_dmdFrameReady || m_stopFlag; }); - sl.unlock(); - - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - - std::unique_lock ul(m_dmdSharedMutex); - m_dmdFrameReady = false; - ul.unlock(); - - if (m_stopFlag) - { - return; - } - } + if (++m_updateBufferPosition >= DMD_FRAME_BUFFER_SIZE) m_updateBufferPosition = 0; } void DMD::FindDevices() @@ -287,7 +242,7 @@ void DMD::FindDevices() if (pConfig->GetZeDMDDevice() != nullptr && pConfig->GetZeDMDDevice()[0] != '\0') pZeDMD->SetDevice(pConfig->GetZeDMDDevice()); - if (pZeDMD->Open(m_width, m_height)) + if (pZeDMD->Open()) { if (pConfig->IsZeDMDDebug()) pZeDMD->EnableDebug(); @@ -315,7 +270,7 @@ void DMD::FindDevices() if (pConfig->IsPixelcade()) { - pPixelcadeDMD = PixelcadeDMD::Connect(pConfig->GetPixelcadeDevice(), m_width, m_height); + pPixelcadeDMD = PixelcadeDMD::Connect(pConfig->GetPixelcadeDevice(), 128, 32); m_pPixelcadeDMDThread = new std::thread(&DMD::PixelcadeDMDThread, this); } @@ -326,6 +281,27 @@ void DMD::FindDevices() }); } +void DMD::DmdFrameReadyResetThread() +{ + while (true) + { + std::shared_lock sl(m_dmdSharedMutex); + m_dmdCV.wait(sl, [&]() { return m_dmdFrameReady || m_stopFlag; }); + sl.unlock(); + + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + + std::unique_lock ul(m_dmdSharedMutex); + m_dmdFrameReady = false; + ul.unlock(); + + if (m_stopFlag) + { + return; + } + } +} + void DMD::ZeDMDThread() { int bufferPosition = 0; @@ -334,6 +310,8 @@ void DMD::ZeDMDThread() uint16_t segData1[128]; uint16_t segData2[128]; uint8_t palette[192] = {0}; + // ZeDMD HD supports 256 * 64 pixels. + uint8_t renderBuffer[256 * 64] = {0}; while (true) { @@ -365,7 +343,6 @@ void DMD::ZeDMDThread() if (m_updateBuffer[bufferPosition]->mode == DMDMode::Data) { - uint8_t renderBuffer[prevWidth * prevHeight]; memcpy(renderBuffer, m_updateBuffer[bufferPosition]->pData, prevWidth * prevHeight); if (m_pSerum) @@ -377,8 +354,8 @@ void DMD::ZeDMDThread() m_pSerum->SetStandardPalette(palette, m_updateBuffer[bufferPosition]->depth); - if (m_pSerum->ColorizeWithMetadata(renderBuffer, prevWidth, prevHeight, palette, rotations, - &triggerID, &hashcode, &frameID)) + if (m_pSerum->ColorizeWithMetadata(renderBuffer, prevWidth, prevHeight, palette, rotations, &triggerID, + &hashcode, &frameID)) { m_pZeDMD->RenderColoredGray6(renderBuffer, palette, rotations); @@ -422,57 +399,141 @@ void DMD::ZeDMDThread() if (update) { - uint8_t* pData; - if (m_updateBuffer[bufferPosition]->pData2) - pData = m_pAlphaNumeric->Render(m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1, - (const uint16_t*)segData2); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1, + (const uint16_t*)segData2); else - pData = m_pAlphaNumeric->Render(m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1); + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1); m_pZeDMD->SetPalette(palette, 4); - m_pZeDMD->RenderGray2(pData); + m_pZeDMD->RenderGray2(renderBuffer); } } } - if (++bufferPosition >= DMD_FRAME_BUFFER_SIZE) - { - bufferPosition = 0; - } + if (++bufferPosition >= DMD_FRAME_BUFFER_SIZE) bufferPosition = 0; } } } -bool DMD::UpdatePalette(uint8_t* pPalette, uint8_t depth, uint8_t r, uint8_t g, uint8_t b) +#if !( \ + (defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || \ + defined(__ANDROID__)) + +void DMD::PixelcadeDMDThread() { - if (depth != 2 && depth != 4) return false; - uint8_t palette[192]; - memcpy(palette, pPalette, 192); + int bufferPosition = 0; + uint16_t segData1[128]; + uint16_t segData2[128]; + uint8_t palette[192] = {0}; + uint16_t rgb565Data[128 * 32 * 3] = {0}; + uint8_t renderBuffer[128 * 32] = {0}; - memset(pPalette, 0, 192); + while (true) + { + std::shared_lock sl(m_dmdSharedMutex); + m_dmdCV.wait(sl, [&]() { return m_dmdFrameReady || m_stopFlag; }); + sl.unlock(); + if (m_stopFlag) + { + return; + } - const uint8_t colors = (depth == 2) ? 4 : 16; - uint8_t pos = 0; + while (!m_stopFlag && bufferPosition != m_updateBufferPosition) + { + // @todo scaling + if (m_updateBuffer[bufferPosition]->width == 128 && m_updateBuffer[bufferPosition]->width == 32) + { + int length = m_updateBuffer[bufferPosition]->width * m_updateBuffer[bufferPosition]->height; + bool update; - for (uint8_t i = 0; i < colors; i++) - { - float perc = FrameUtil::CalcBrightness((float)i / (float)(colors - 1)); - pPalette[pos++] = (uint8_t)(((float)r) * perc); - pPalette[pos++] = (uint8_t)(((float)g) * perc); - pPalette[pos++] = (uint8_t)(((float)b) * perc); - } + if (m_updateBuffer[bufferPosition]->mode == DMDMode::RGB24) + { + for (int i = 0; i < length; i++) + { + int pos = i * 3; + uint32_t r = ((uint8_t*)(m_updateBuffer[bufferPosition]->pData))[pos]; + uint32_t g = ((uint8_t*)(m_updateBuffer[bufferPosition]->pData))[pos + 1]; + uint32_t b = ((uint8_t*)(m_updateBuffer[bufferPosition]->pData))[pos + 2]; - return (memcmp(pPalette, palette, 192) != 0); -} + rgb565Data[i] = (uint16_t)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | (b >> 3)); + } + } + else + { + update = UpdatePalette(palette, m_updateBuffer[bufferPosition]->depth, m_updateBuffer[bufferPosition]->r, + m_updateBuffer[bufferPosition]->g, m_updateBuffer[bufferPosition]->b); -#if !( \ - (defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || \ - defined(__ANDROID__)) + if (m_updateBuffer[bufferPosition]->mode == DMDMode::Data) + { + if (!m_pSerum) + { + memcpy(renderBuffer, (uint8_t*)m_updateBuffer[bufferPosition]->pData, + m_updateBuffer[bufferPosition]->width * m_updateBuffer[bufferPosition]->height); + } + else + { + update = m_pSerum->Convert((uint8_t*)m_updateBuffer[bufferPosition]->pData, renderBuffer, palette, + m_updateBuffer[bufferPosition]->width, m_updateBuffer[bufferPosition]->height); + } + } + else if (m_updateBuffer[bufferPosition]->mode == DMDMode::AlphaNumeric) + { + if (memcmp(segData1, m_updateBuffer[bufferPosition]->pData, 128 * sizeof(uint16_t)) != 0) + { + memcpy(segData1, m_updateBuffer[bufferPosition]->pData, 128 * sizeof(uint16_t)); + update = true; + } -void DMD::PixelcadeDMDThread() + if (m_updateBuffer[bufferPosition]->pData2 && + memcmp(segData2, m_updateBuffer[bufferPosition]->pData2, 128 * sizeof(uint16_t)) != 0) + { + memcpy(segData2, m_updateBuffer[bufferPosition]->pData2, 128 * sizeof(uint16_t)); + update = true; + } + + if (update) + { + uint8_t* pData; + + if (m_updateBuffer[bufferPosition]->pData2) + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1, + (const uint16_t*)segData2); + else + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, + (const uint16_t*)segData1); + } + } + + for (int i = 0; i < length; i++) + { + int pos = renderBuffer[i] * 3; + uint32_t r = palette[pos]; + uint32_t g = palette[pos + 1]; + uint32_t b = palette[pos + 2]; + + rgb565Data[i] = (uint16_t)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | (b >> 3)); + } + } + + if (update) m_pPixelcadeDMD->Update(rgb565Data); + } + + if (++bufferPosition >= DMD_FRAME_BUFFER_SIZE) bufferPosition = 0; + } + } +} +#endif + +void DMD::VirtualDMDThread() { int bufferPosition = 0; + uint16_t segData1[128]; + uint16_t segData2[128]; + uint8_t palette[192] = {0}; + uint8_t renderBuffer[256 * 64] = {0}; + uint8_t rgb24Data[256 * 64 * 3] = {0}; + uint8_t levelData[256 * 64] = {0}; while (true) { @@ -484,11 +545,117 @@ void DMD::PixelcadeDMDThread() return; } - while (bufferPosition != m_updateBufferPosition) + while (!m_stopFlag && bufferPosition != m_updateBufferPosition) { + int length = m_updateBuffer[bufferPosition]->width * m_updateBuffer[bufferPosition]->height; + bool update; + + if (m_updateBuffer[bufferPosition]->mode == DMDMode::RGB24) + { + for (VirtualDMD* pVirtualDMD : m_virtualDMDs) + pVirtualDMD->Update((uint8_t*)m_updateBuffer[bufferPosition]->pData); + } + else + { + update = UpdatePalette(palette, m_updateBuffer[bufferPosition]->depth, m_updateBuffer[bufferPosition]->r, + m_updateBuffer[bufferPosition]->g, m_updateBuffer[bufferPosition]->b); + + if (m_updateBuffer[bufferPosition]->mode == DMDMode::Data) + { + if (!m_pSerum) + { + if (m_updateBuffer[bufferPosition]->depth == 2) + { + for (int i = 0; i < length; i++) + levelData[i] = LEVELS_WPC[((uint8_t*)(m_updateBuffer[bufferPosition]->pData))[i]]; + } + else if (m_updateBuffer[bufferPosition]->depth == 4) + { + if (!m_updateBuffer[bufferPosition]->sam) + { + for (int i = 0; i < length; i++) + levelData[i] = LEVELS_GTS3[((uint8_t*)(m_updateBuffer[bufferPosition]->pData))[i]]; + } + else + { + for (int i = 0; i < length; i++) + levelData[i] = LEVELS_SAM[((uint8_t*)(m_updateBuffer[bufferPosition]->pData))[i]]; + } + } + for (VirtualDMD* pVirtualDMD : m_virtualDMDs) pVirtualDMD->UpdateLevel(levelData); + + memcpy(renderBuffer, m_updateBuffer[bufferPosition]->pData, length); + } + else + { + update = m_pSerum->Convert((uint8_t*)m_updateBuffer[bufferPosition]->pData, renderBuffer, palette, + m_updateBuffer[bufferPosition]->width, m_updateBuffer[bufferPosition]->height); + } + } + else if (m_updateBuffer[bufferPosition]->mode == DMDMode::AlphaNumeric) + { + if (memcmp(segData1, m_updateBuffer[bufferPosition]->pData, 128 * sizeof(uint16_t)) != 0) + { + memcpy(segData1, m_updateBuffer[bufferPosition]->pData, 128 * sizeof(uint16_t)); + update = true; + } + + if (m_updateBuffer[bufferPosition]->pData2 && + memcmp(segData2, m_updateBuffer[bufferPosition]->pData2, 128 * sizeof(uint16_t)) != 0) + { + memcpy(segData2, m_updateBuffer[bufferPosition]->pData2, 128 * sizeof(uint16_t)); + update = true; + } + + if (update) + { + uint8_t* pData; + + if (m_updateBuffer[bufferPosition]->pData2) + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1, + (const uint16_t*)segData2); + else + m_pAlphaNumeric->Render(renderBuffer, m_updateBuffer[bufferPosition]->layout, (const uint16_t*)segData1); + } + } + + for (int i = 0; i < length; i++) + { + int palettePos = renderBuffer[i] * 3; + int pos = i * 3; + rgb24Data[pos] = palette[palettePos]; + rgb24Data[pos + 1] = palette[palettePos + 1]; + rgb24Data[pos + 2] = palette[palettePos + 2]; + } + + for (VirtualDMD* pVirtualDMD : m_virtualDMDs) pVirtualDMD->Update(rgb24Data); + } } + + if (++bufferPosition >= DMD_FRAME_BUFFER_SIZE) bufferPosition = 0; } } -#endif + +bool DMD::UpdatePalette(uint8_t* pPalette, uint8_t depth, uint8_t r, uint8_t g, uint8_t b) +{ + if (depth != 2 && depth != 4) return false; + uint8_t palette[192]; + memcpy(palette, pPalette, 192); + + memset(pPalette, 0, 192); + + const uint8_t colors = (depth == 2) ? 4 : 16; + uint8_t pos = 0; + + for (uint8_t i = 0; i < colors; i++) + { + float perc = FrameUtil::CalcBrightness((float)i / (float)(colors - 1)); + pPalette[pos++] = (uint8_t)(((float)r) * perc); + pPalette[pos++] = (uint8_t)(((float)g) * perc); + pPalette[pos++] = (uint8_t)(((float)b) * perc); + } + + return (memcmp(pPalette, palette, 192) != 0); +} } // namespace DMDUtil diff --git a/src/Serum.cpp b/src/Serum.cpp index 142267a..c58ceab 100644 --- a/src/Serum.cpp +++ b/src/Serum.cpp @@ -56,21 +56,13 @@ Serum* Serum::Load(const std::string& romName) return new Serum(width, height); } -bool Serum::Convert(uint8_t* pFrame, uint8_t* pDstFrame, uint8_t* pDstPalette) +bool Serum::Convert(uint8_t* pFrame, uint8_t* pDstFrame, uint8_t* pDstPalette, uint16_t width, uint16_t height) { - if (pFrame) memcpy(m_pFrame, pFrame, m_length); - + if (pFrame) memcpy(pDstFrame, pFrame, width * height); + unsigned int triggerId; - if (Serum_ColorizeOrApplyRotations(pFrame ? m_pFrame : nullptr, m_width, m_height, m_palette, &triggerId)) - { - memcpy(pDstFrame, m_pFrame, m_length); - memcpy(pDstPalette, m_palette, 192); - - return true; - } - - return false; + return Serum_ColorizeOrApplyRotations(pDstFrame ? pDstFrame : nullptr, width, height, pDstPalette, &triggerId); }; void Serum::SetStandardPalette(const uint8_t* palette, const int bitDepth) diff --git a/src/Serum.h b/src/Serum.h index b8ab014..247ba3e 100644 --- a/src/Serum.h +++ b/src/Serum.h @@ -12,7 +12,7 @@ class Serum ~Serum(); static Serum* Load(const std::string& romName); - bool Convert(uint8_t* pFrame, uint8_t* pDstFrame, uint8_t* pDstPalette); + bool Convert(uint8_t* pFrame, uint8_t* pDstFrame, uint8_t* pDstPalette, uint16_t width, uint16_t height); void SetStandardPalette(const uint8_t* palette, const int bitDepth); bool ColorizeWithMetadata(uint8_t* frame, int width, int height, uint8_t* palette, uint8_t* rotations, uint32_t* triggerID, uint32_t* hashcode, int* frameID); diff --git a/src/VirtualDMD.cpp b/src/VirtualDMD.cpp index 1e3bf01..d64e976 100644 --- a/src/VirtualDMD.cpp +++ b/src/VirtualDMD.cpp @@ -7,7 +7,7 @@ namespace DMDUtil { -VirtualDMD::VirtualDMD(int width, int height) +VirtualDMD::VirtualDMD(uint16_t width, uint16_t height) { m_width = width; m_height = height; @@ -29,14 +29,21 @@ VirtualDMD::~VirtualDMD() free(m_pRGB24Data); } -void VirtualDMD::Update(uint8_t* pLevelData, uint8_t* pRGB24Data) +void VirtualDMD::Update(uint8_t* pRGB24Data) { - memcpy(m_pLevelData, pLevelData, m_length); memcpy(m_pRGB24Data, pRGB24Data, m_length * 3); m_update = true; } + +void VirtualDMD::UpdateLevel(uint8_t* pLevelData) +{ + memcpy(m_pLevelData, pLevelData, m_length); + + m_update = true; +} + uint8_t* VirtualDMD::GetLevelData() { if (!m_update) return nullptr; diff --git a/src/test.cpp b/src/test.cpp index 6ca212d..6abb2ba 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -47,7 +47,7 @@ int main(int argc, const char* argv[]) int width = 128; int height = 32; - DMDUtil::DMD* pDmd = new DMDUtil::DMD(width, height); + DMDUtil::DMD* pDmd = new DMDUtil::DMD(); printf("Finding displays...\n"); @@ -62,37 +62,37 @@ int main(int argc, const char* argv[]) printf("Rendering...\n"); - uint8_t* pImage2 = CreateImage(pDmd->GetWidth(), pDmd->GetHeight(), 2); - uint8_t* pImage4 = CreateImage(pDmd->GetWidth(), pDmd->GetHeight(), 4); - uint8_t* pImage24 = CreateImageRGB24(pDmd->GetWidth(), pDmd->GetHeight()); + uint8_t* pImage2 = CreateImage(128, 32, 2); + uint8_t* pImage4 = CreateImage(128, 32, 4); + uint8_t* pImage24 = CreateImageRGB24(128, 32); for (int i = 0; i < 4; i++) { - pDmd->UpdateData(pImage2, 2, 255, 0, 0); + pDmd->UpdateData(pImage2, 2, 128, 32, 255, 0, 0); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage2, 2, 0, 255, 0); + pDmd->UpdateData(pImage2, 2, 128, 32, 0, 255, 0); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage2, 2, 0, 0, 255); + pDmd->UpdateData(pImage2, 2, 128, 32, 0, 0, 255); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage2, 2, 255, 255, 255); + pDmd->UpdateData(pImage2, 2, 128, 32, 255, 255, 255); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage4, 4, 255, 0, 0); + pDmd->UpdateData(pImage4, 4, 128, 32, 255, 0, 0); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage4, 4, 0, 255, 0); + pDmd->UpdateData(pImage4, 4, 128, 32, 0, 255, 0); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage4, 4, 0, 0, 255); + pDmd->UpdateData(pImage4, 4, 128, 32, 0, 0, 255); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateData(pImage4, 4, 255, 255, 255); + pDmd->UpdateData(pImage4, 4, 128, 32, 255, 255, 255); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - pDmd->UpdateRGB24Data(pImage24, 24, 0, 0, 0); + pDmd->UpdateRGB24Data(pImage24, 128, 32, 0, 0, 0); std::this_thread::sleep_for(std::chrono::milliseconds(200)); }