From 31b24b6d6027b3419e44954302aea196a2e088da Mon Sep 17 00:00:00 2001 From: toxieainc Date: Sat, 13 Jan 2024 09:23:28 +0100 Subject: [PATCH] avoid taking or passing std::string over library interface, fix wrong declaration of m_segData1/2, avoid duplicating NumericalLayout, (most likely) fix wrong detection of pixelcade magic code string --- include/DMDUtil/Config.h | 33 ++++--- include/DMDUtil/DMD.h | 22 ++--- src/AlphaNumeric.cpp | 180 ++++++++++++++++++--------------------- src/AlphaNumeric.h | 35 ++------ src/Config.cpp | 10 +-- src/DMD.cpp | 147 +++++++++++++------------------- src/FrameUtil.cpp | 42 +++++---- src/Pixelcade.cpp | 14 ++- src/Pixelcade.h | 2 +- src/Serum.cpp | 6 +- src/Serum.h | 2 - src/test.cpp | 2 +- 12 files changed, 209 insertions(+), 286 deletions(-) diff --git a/include/DMDUtil/Config.h b/include/DMDUtil/Config.h index 89cf973..c64f51c 100644 --- a/include/DMDUtil/Config.h +++ b/include/DMDUtil/Config.h @@ -8,9 +8,8 @@ #define DMDUTILCALLBACK #endif -#include #include -#include +#include typedef void(DMDUTILCALLBACK *DMDUtil_LogCallback)(const char *format, va_list args); @@ -20,32 +19,32 @@ class DMDUTILAPI Config { public: static Config* GetInstance(); - bool IsAltColor() { return m_altColor; } + bool IsAltColor() const { return m_altColor; } void SetAltColor(bool altColor) { m_altColor = altColor; } - void SetAltColorPath(const std::string& path) { m_altColorPath = path; } - bool IsZeDMD() { return m_zedmd; } + void SetAltColorPath(const char* path) { m_altColorPath = path; } + bool IsZeDMD() const { return m_zedmd; } void SetZeDMD(bool zedmd) { m_zedmd = zedmd; } - const std::string& GetZeDMDDevice() { return m_zedmdDevice; } - void SetZeDMDDevice(const std::string& port) { m_zedmdDevice = port; } - const bool IsZeDMDDebug() { return m_zedmdDebug; } + const char* GetZeDMDDevice() const { return m_zedmdDevice.c_str(); } + void SetZeDMDDevice(const char* port) { m_zedmdDevice = port; } + bool IsZeDMDDebug() const { return m_zedmdDebug; } void SetZeDMDDebug(bool debug) { m_zedmdDebug = debug; } - const int GetZeDMDRGBOrder() { return m_zedmdRgbOrder; } + int GetZeDMDRGBOrder() const { return m_zedmdRgbOrder; } void SetZeDMDRGBOrder(int rgbOrder) { m_zedmdRgbOrder = rgbOrder; } - const int GetZeDMDBrightness() { return m_zedmdBrightness; } + int GetZeDMDBrightness() const { return m_zedmdBrightness; } void SetZeDMDBrightness(int brightness) { m_zedmdBrightness = brightness; } - const bool IsZeDMDSaveSettings() { return m_zedmdSaveSettings; } + bool IsZeDMDSaveSettings() const { return m_zedmdSaveSettings; } void SetZeDMDSaveSettings(bool saveSettings) { m_zedmdSaveSettings = saveSettings; } - bool IsPixelcade() { return m_pixelcade; } + bool IsPixelcade() const { return m_pixelcade; } void SetPixelcade(bool pixelcade) { m_pixelcade = pixelcade; } - void SetPixelcadeDevice(const std::string& port) { m_pixelcadeDevice = port; } - const std::string& GetPixelcadeDevice() { return m_pixelcadeDevice; } - DMDUtil_LogCallback GetLogCallback() { return m_logCallback; } + void SetPixelcadeDevice(const char* port) { m_pixelcadeDevice = port; } + const char* GetPixelcadeDevice() const { return m_pixelcadeDevice.c_str(); } + const DMDUtil_LogCallback GetLogCallback() const { return m_logCallback; } void SetLogCallback(DMDUtil_LogCallback callback) { m_logCallback = callback; } - const std::string& GetAltColorPath() { return m_altColorPath; } + const char* GetAltColorPath() const { return m_altColorPath.c_str(); } private: Config(); - ~Config(); + ~Config() {} static Config* m_pInstance; bool m_altColor; diff --git a/include/DMDUtil/DMD.h b/include/DMDUtil/DMD.h index 7212086..b18ce21 100644 --- a/include/DMDUtil/DMD.h +++ b/include/DMDUtil/DMD.h @@ -50,22 +50,22 @@ class Pixelcade; class DMDUTILAPI DMD { public: - DMD(int width, int height, bool sam = false, const std::string& name = ""); + DMD(int width, int height, bool sam = false, const char* name = nullptr); ~DMD(); static bool IsFinding(); - bool HasDisplay(); - const int GetWidth() { return m_width; } - const int GetHeight() { return m_height; } - const int GetLength() { return m_length; } - const bool IsUpdated() { return m_updated; } + bool HasDisplay() const; + int GetWidth() const { return m_width; } + int GetHeight() const { return m_height; } + int GetLength() const { return m_length; } + bool IsUpdated() const { return m_updated; } void ResetUpdated() { m_updated = false; } 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 UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pData1, const uint16_t* pData2, uint8_t r, uint8_t g, uint8_t b); - uint8_t* GetLevelData(); - uint32_t* GetRGB32Data(); - + const uint8_t* GetLevelData() const { return m_pLevelData; } + const uint32_t* GetRGB32Data() const { return m_pRGB32Data; } + private: enum class DmdMode { Unknown, @@ -103,8 +103,8 @@ class DMDUTILAPI DMD bool m_sam; uint8_t* m_pData; uint8_t* m_pRGB24Data; - uint16_t* m_segData1[128]; - uint16_t* m_segData2[128]; + uint16_t m_segData1[128]; + uint16_t m_segData2[128]; uint8_t* m_pLevelData; uint32_t* m_pRGB32Data; uint16_t* m_pRGB565Data; diff --git a/src/AlphaNumeric.cpp b/src/AlphaNumeric.cpp index 1b92357..cc261b7 100644 --- a/src/AlphaNumeric.cpp +++ b/src/AlphaNumeric.cpp @@ -7,9 +7,11 @@ #include "AlphaNumeric.h" +#include + namespace DMDUtil { -uint8_t AlphaNumeric::SegSizes[8][16] = { +const uint8_t AlphaNumeric::SegSizes[8][16] = { {5,5,5,5,5,5,2,2,5,5,5,2,5,5,5,1}, {5,5,5,5,5,5,5,2,0,0,0,0,0,0,0,0}, {5,5,5,5,5,5,5,2,5,5,0,0,0,0,0,0}, @@ -20,7 +22,7 @@ uint8_t AlphaNumeric::SegSizes[8][16] = { {5,5,5,5,5,5,3,2,5,5,5,3,5,5,5,1} }; -uint8_t AlphaNumeric::Segs[8][17][5][2] = { +const uint8_t AlphaNumeric::Segs[8][17][5][2] = { /* alphanumeric display characters */ { {{1,0},{2,0},{3,0},{4,0},{5,0}}, // 0 top @@ -177,12 +179,12 @@ uint8_t AlphaNumeric::Segs[8][17][5][2] = { AlphaNumeric::AlphaNumeric() { - memset(m_frameBuffer, 0, 4096); + memset(m_frameBuffer, 0, sizeof(m_frameBuffer)); } -uint8_t* AlphaNumeric::Render(NumericalLayout layout, const uint16_t* const seg_data) +uint8_t* AlphaNumeric::Render(AlphaNumericLayout layout, const uint16_t* const seg_data) { - if (layout != __2x7Num_2x7Num_10x1Num) + if (layout != AlphaNumericLayout::__2x7Num_2x7Num_10x1Num) Render(layout, seg_data, nullptr); else Render(layout, seg_data, seg_data + 32); @@ -190,57 +192,57 @@ uint8_t* AlphaNumeric::Render(NumericalLayout layout, const uint16_t* const seg_ return m_frameBuffer; } -uint8_t* AlphaNumeric::Render(NumericalLayout layout, const uint16_t* const seg_data, const uint16_t* const seg_data2) +uint8_t* AlphaNumeric::Render(AlphaNumericLayout layout, const uint16_t* const seg_data, const uint16_t* const seg_data2) { Clear(); switch (layout) { - case __2x16Alpha: + case AlphaNumericLayout::__2x16Alpha: Render2x16Alpha(seg_data); break; - case __2x20Alpha: + case AlphaNumericLayout::__2x20Alpha: Render2x20Alpha(seg_data); break; - case __2x7Alpha_2x7Num: + case AlphaNumericLayout::__2x7Alpha_2x7Num: Render2x7Alpha_2x7Num(seg_data); break; - case __2x7Alpha_2x7Num_4x1Num: + case AlphaNumericLayout::__2x7Alpha_2x7Num_4x1Num: Render2x7Alpha_2x7Num_4x1Num(seg_data); break; - case __2x7Num_2x7Num_4x1Num: + case AlphaNumericLayout::__2x7Num_2x7Num_4x1Num: Render2x7Num_2x7Num_4x1Num(seg_data); break; - case __2x7Num_2x7Num_10x1Num: + case AlphaNumericLayout::__2x7Num_2x7Num_10x1Num: Render2x7Num_2x7Num_10x1Num(seg_data, seg_data2); break; - case __2x7Num_2x7Num_4x1Num_gen7: + case AlphaNumericLayout::__2x7Num_2x7Num_4x1Num_gen7: Render2x7Num_2x7Num_4x1Num_gen7(seg_data); break; - case __2x7Num10_2x7Num10_4x1Num: + case AlphaNumericLayout::__2x7Num10_2x7Num10_4x1Num: Render2x7Num10_2x7Num10_4x1Num(seg_data); break; - case __2x6Num_2x6Num_4x1Num: + case AlphaNumericLayout::__2x6Num_2x6Num_4x1Num: Render2x6Num_2x6Num_4x1Num(seg_data); break; - case __2x6Num10_2x6Num10_4x1Num: + case AlphaNumericLayout::__2x6Num10_2x6Num10_4x1Num: Render2x6Num10_2x6Num10_4x1Num(seg_data); break; - case __4x7Num10: + case AlphaNumericLayout::__4x7Num10: Render4x7Num10(seg_data); break; - case __6x4Num_4x1Num: + case AlphaNumericLayout::__6x4Num_4x1Num: Render6x4Num_4x1Num(seg_data); break; - case __2x7Num_4x1Num_1x16Alpha: + case AlphaNumericLayout::__2x7Num_4x1Num_1x16Alpha: Render2x7Num_4x1Num_1x16Alpha(seg_data); break; - case __1x16Alpha_1x16Num_1x7Num: + case AlphaNumericLayout::__1x16Alpha_1x16Num_1x7Num: Render1x16Alpha_1x16Num_1x7Num(seg_data); break; - case __1x7Num_1x16Alpha_1x16Num: + case AlphaNumericLayout::__1x7Num_1x16Alpha_1x16Num: Render1x7Num_1x16Alpha_1x16Num(seg_data); break; - case __1x16Alpha_1x16Num_1x7Num_1x4Num: + case AlphaNumericLayout::__1x16Alpha_1x16Num_1x7Num_1x4Num: Render1x16Alpha_1x16Num_1x7Num_1x4Num(seg_data); break; default: @@ -280,7 +282,7 @@ void AlphaNumeric::DrawSegment(const int x, const int y, const uint8_t type, con DrawPixel(Segs[type][seg][i][0] + x, Segs[type][seg][i][1] + y, colour); } -uint8_t AlphaNumeric::GetPixel(const int x, const int y) +bool AlphaNumeric::GetPixel(const int x, const int y) const { return m_frameBuffer[y * 128 + x] > 0; } @@ -292,14 +294,13 @@ void AlphaNumeric::DrawPixel(const int x, const int y, const uint8_t colour) void AlphaNumeric::Clear() { - memset(m_frameBuffer, 0, 4096); + memset(m_frameBuffer, 0, sizeof(m_frameBuffer)); } void AlphaNumeric::Render2x16Alpha(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + 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) @@ -312,9 +313,8 @@ void AlphaNumeric::Render2x16Alpha(const uint16_t* const seg_data) void AlphaNumeric::Render2x20Alpha(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 20; i++) { - for (j = 0; j < 16; j++) { + 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) @@ -327,9 +327,8 @@ void AlphaNumeric::Render2x20Alpha(const uint16_t* const seg_data) void AlphaNumeric::Render2x7Alpha_2x7Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -344,9 +343,8 @@ void AlphaNumeric::Render2x7Alpha_2x7Num(const uint16_t* const seg_data) void AlphaNumeric::Render2x7Alpha_2x7Num_4x1Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -358,7 +356,7 @@ void AlphaNumeric::Render2x7Alpha_2x7Num_4x1Num(const uint16_t* const seg_data) SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 21); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -372,9 +370,8 @@ void AlphaNumeric::Render2x7Alpha_2x7Num_4x1Num(const uint16_t* const seg_data) void AlphaNumeric::Render2x6Num_2x6Num_4x1Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 12; i++) { - for (j = 0; j < 16; j++) { + for (int i = 0; i < 12; i++) { + for (int j = 0; j < 16; j++) { // 2x7 numeric if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 6) ? 0 : 4)) * 8, 0, 1, j, 3); @@ -387,7 +384,7 @@ void AlphaNumeric::Render2x6Num_2x6Num_4x1Num(const uint16_t* const seg_data) SmoothDigitCorners((i + ((i < 6) ? 0 : 4)) * 8, 12); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -401,9 +398,8 @@ void AlphaNumeric::Render2x6Num_2x6Num_4x1Num(const uint16_t* const seg_data) void AlphaNumeric::Render2x6Num10_2x6Num10_4x1Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 12; i++) { - for (j = 0; j < 16; j++) { + for (int i = 0; i < 12; i++) { + for (int j = 0; j < 16; j++) { // 2x7 numeric if ((seg_data[i] >> j) & 0x1) DrawSegment((i + ((i < 6) ? 0 : 4)) * 8, 0, 2, j, 3); @@ -415,7 +411,7 @@ void AlphaNumeric::Render2x6Num10_2x6Num10_4x1Num(const uint16_t* const seg_data SmoothDigitCorners((i + ((i < 6) ? 0 : 4)) * 8, 20); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -429,9 +425,8 @@ void AlphaNumeric::Render2x6Num10_2x6Num10_4x1Num(const uint16_t* const seg_data void AlphaNumeric::Render2x7Num_2x7Num_4x1Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -443,7 +438,7 @@ void AlphaNumeric::Render2x7Num_2x7Num_4x1Num(const uint16_t* const seg_data) SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 12); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -457,9 +452,8 @@ void AlphaNumeric::Render2x7Num_2x7Num_4x1Num(const uint16_t* const seg_data) void AlphaNumeric::Render2x7Num_2x7Num_10x1Num(const uint16_t* const seg_data, const uint16_t* const extra_seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -471,7 +465,7 @@ void AlphaNumeric::Render2x7Num_2x7Num_10x1Num(const uint16_t* const seg_data, c SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 12); } // 10x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -497,9 +491,8 @@ void AlphaNumeric::Render2x7Num_2x7Num_10x1Num(const uint16_t* const seg_data, c void AlphaNumeric::Render2x7Num_2x7Num_4x1Num_gen7(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -511,7 +504,7 @@ void AlphaNumeric::Render2x7Num_2x7Num_4x1Num_gen7(const uint16_t* const seg_dat SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 1); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -525,9 +518,8 @@ void AlphaNumeric::Render2x7Num_2x7Num_4x1Num_gen7(const uint16_t* const seg_dat void AlphaNumeric::Render2x7Num10_2x7Num10_4x1Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -539,7 +531,7 @@ void AlphaNumeric::Render2x7Num10_2x7Num10_4x1Num(const uint16_t* const seg_data SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 20); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -553,9 +545,8 @@ void AlphaNumeric::Render2x7Num10_2x7Num10_4x1Num(const uint16_t* const seg_data void AlphaNumeric::Render4x7Num10(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -570,9 +561,8 @@ void AlphaNumeric::Render4x7Num10(const uint16_t* const seg_data) void AlphaNumeric::Render6x4Num_4x1Num(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 8; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -588,7 +578,7 @@ void AlphaNumeric::Render6x4Num_4x1Num(const uint16_t* const seg_data) SmoothDigitCorners((i + ((i < 4) ? 0 : 2)) * 8, 17); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -602,9 +592,8 @@ void AlphaNumeric::Render6x4Num_4x1Num(const uint16_t* const seg_data) void AlphaNumeric::Render2x7Num_4x1Num_1x16Alpha(const uint16_t* const seg_data) { - int i, j; - for (i = 0; i < 14; i++) { - for (j = 0; j < 16; j++) { + 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); @@ -612,7 +601,7 @@ void AlphaNumeric::Render2x7Num_4x1Num_1x16Alpha(const uint16_t* const seg_data) SmoothDigitCorners((i + ((i < 7) ? 0 : 2)) * 8, 0); } // 4x1 numeric small - for (j = 0; j < 16; j++) { + 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) @@ -623,8 +612,8 @@ void AlphaNumeric::Render2x7Num_4x1Num_1x16Alpha(const uint16_t* const seg_data) DrawSegment(48, 12, 5, j, 3); } // 1x16 alphanumeric - for (i = 0; i < 12; i++) { - for (j = 0; j < 16; j++) { + 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); } @@ -634,10 +623,9 @@ void AlphaNumeric::Render2x7Num_4x1Num_1x16Alpha(const uint16_t* const seg_data) void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data) { - int i, j; // 1x16 alphanumeric - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + 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); } @@ -645,8 +633,8 @@ void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data } // 1x16 numeric - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { if ((seg_data[i + 16] >> j) & 0x1) DrawSegment((i * 8), 21, 1, j, 3); } @@ -654,8 +642,8 @@ void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data } // 1x7 numeric small - for (i = 0; i < 7; i++) { - for (j = 0; j < 16; j++) { + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 16; j++) { if ((seg_data[i + 32] >> j) & 0x1) DrawSegment((i * 8) + 68, 1, 5, j, 3); } @@ -664,26 +652,25 @@ void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num(const uint16_t* const seg_data void AlphaNumeric::Render1x7Num_1x16Alpha_1x16Num(const uint16_t* const seg_data) { - int i, j; // 1x16 alphanumeric - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + 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); } SmoothDigitCorners((i * 8), 9); } // 1x16 numeric - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + 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); } SmoothDigitCorners((i * 8), 21); } // 1x7 numeric small - for (i = 0; i < 7; i++) { - for (j = 0; j < 16; j++) { + 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); } @@ -692,33 +679,32 @@ void AlphaNumeric::Render1x7Num_1x16Alpha_1x16Num(const uint16_t* const seg_data void AlphaNumeric::Render1x16Alpha_1x16Num_1x7Num_1x4Num(const uint16_t* const seg_data) { - int i, j; // 1x16 alphanumeric - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + 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); } SmoothDigitCorners((i * 8), 9); } // 1x16 numeric - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { + 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); } SmoothDigitCorners((i * 8), 21); } // 1x4 numeric small - for (i = 0; i < 4; i++) { - for (j = 0; j < 16; j++) { + 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); } } // 1x7 numeric small - for (i = 0; i < 7; i++) { - for (j = 0; j < 16; j++) { + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 16; j++) { if ((seg_data[i] >> j) & 0x1) DrawSegment((i * 8)+68, 1, 5, j, 3); } diff --git a/src/AlphaNumeric.h b/src/AlphaNumeric.h index 24dd7ae..92b326b 100644 --- a/src/AlphaNumeric.h +++ b/src/AlphaNumeric.h @@ -7,45 +7,26 @@ #pragma once +#include "DMDUtil/DMD.h" + #include -#include namespace DMDUtil { -typedef enum { - None, - __2x16Alpha, - __2x20Alpha, - __2x7Alpha_2x7Num, - __2x7Alpha_2x7Num_4x1Num, - __2x7Num_2x7Num_4x1Num, - __2x7Num_2x7Num_10x1Num, - __2x7Num_2x7Num_4x1Num_gen7, - __2x7Num10_2x7Num10_4x1Num, - __2x6Num_2x6Num_4x1Num, - __2x6Num10_2x6Num10_4x1Num, - __4x7Num10, - __6x4Num_4x1Num, - __2x7Num_4x1Num_1x16Alpha, - __1x16Alpha_1x16Num_1x7Num, - __1x7Num_1x16Alpha_1x16Num, - __1x16Alpha_1x16Num_1x7Num_1x4Num -} NumericalLayout; - class AlphaNumeric { public: AlphaNumeric(); - ~AlphaNumeric() {}; + ~AlphaNumeric() {} - uint8_t* Render(NumericalLayout layout, const uint16_t* const seg_data); - uint8_t* Render(NumericalLayout layout, const uint16_t* const seg_data, const uint16_t* const seg_data2); + 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); 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); - uint8_t GetPixel(const int x, const int y); + bool GetPixel(const int x, const int y) const; void DrawPixel(const int x, const int y, const uint8_t colour); void Clear(); @@ -68,8 +49,8 @@ class AlphaNumeric uint8_t m_frameBuffer[4096]; - static uint8_t SegSizes[8][16]; - static uint8_t Segs[8][17][5][2]; + static const uint8_t SegSizes[8][16]; + static const uint8_t Segs[8][17][5][2]; }; } \ No newline at end of file diff --git a/src/Config.cpp b/src/Config.cpp index fec3800..a1886c9 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -15,20 +15,16 @@ Config* Config::GetInstance() Config::Config() { m_altColor = true; - m_altColorPath = ""; + m_altColorPath.clear(); m_zedmd = true; - m_zedmdDevice = ""; + m_zedmdDevice.clear(); m_zedmdDebug = false; m_zedmdRgbOrder = -1; m_zedmdBrightness = -1; m_zedmdSaveSettings = false; m_pixelcade = true; - m_pixelcadeDevice = ""; + m_pixelcadeDevice.clear(); m_logCallback = nullptr; } -Config::~Config() -{ -} - } \ No newline at end of file diff --git a/src/DMD.cpp b/src/DMD.cpp index 4d92041..caa1e47 100644 --- a/src/DMD.cpp +++ b/src/DMD.cpp @@ -16,14 +16,14 @@ namespace DMDUtil { void ZEDMDCALLBACK ZeDMDLogCallback(const char* format, va_list args, const void* pUserData) { char buffer[1024]; - vsnprintf(buffer, 1024, format, args); + vsnprintf(buffer, sizeof(buffer), format, args); Log("%s", buffer); } bool DMD::m_finding = false; -DMD::DMD(int width, int height, bool sam, const std::string& name) +DMD::DMD(int width, int height, bool sam, const char* name) { m_width = width; m_height = height; @@ -43,7 +43,7 @@ DMD::DMD(int width, int height, bool sam, const std::string& name) memset(m_pRGB565Data, 0, m_length * sizeof(uint16_t)); memset(m_palette, 0, 192); m_pAlphaNumeric = new AlphaNumeric(); - m_pSerum = (Config::GetInstance()->IsAltColor() && !name.empty()) ? Serum::Load(name) : nullptr; + m_pSerum = (Config::GetInstance()->IsAltColor() && name != nullptr && name[0] != '\0') ? Serum::Load(name) : nullptr; m_pZeDMD = nullptr; #if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__)) m_pPixelcade = nullptr; @@ -70,12 +70,10 @@ DMD::~DMD() { std::lock_guard lock(m_mutex); while (!m_updates.empty()) { - DMDUpdate* pUpdate = m_updates.front(); + DMDUpdate* const pUpdate = m_updates.front(); m_updates.pop(); - if (pUpdate->pData) - free(pUpdate->pData); - if (pUpdate->pData2) - free(pUpdate->pData2); + free(pUpdate->pData); + free(pUpdate->pData2); delete pUpdate; } } @@ -86,13 +84,10 @@ DMD::~DMD() free(m_pRGB32Data); free(m_pRGB565Data); delete m_pAlphaNumeric; - if (m_pSerum) - delete m_pSerum; - if (m_pZeDMD) - delete m_pZeDMD; + delete m_pSerum; + delete m_pZeDMD; #if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__)) - if (m_pPixelcade) - delete m_pPixelcade; + delete m_pPixelcade; #endif } @@ -101,7 +96,7 @@ bool DMD::IsFinding() return m_finding; } -bool DMD::HasDisplay() +bool DMD::HasDisplay() const { #if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__)) return (m_pZeDMD != nullptr) || (m_pPixelcade != nullptr); @@ -113,7 +108,7 @@ bool DMD::HasDisplay() void DMD::UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b) { std::lock_guard lock(m_mutex); - DMDUpdate* pUpdate = new DMDUpdate(); + DMDUpdate* const pUpdate = new DMDUpdate(); memset(pUpdate, 0, sizeof(DMDUpdate)); pUpdate->mode = DmdMode::Data; pUpdate->depth = depth; @@ -132,7 +127,7 @@ void DMD::UpdateData(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint void DMD::UpdateRGB24Data(const uint8_t* pData, int depth, uint8_t r, uint8_t g, uint8_t b) { std::lock_guard lock(m_mutex); - DMDUpdate* pUpdate = new DMDUpdate(); + DMDUpdate* const pUpdate = new DMDUpdate(); memset(pUpdate, 0, sizeof(DMDUpdate)); pUpdate->mode = DmdMode::RGB24; pUpdate->depth = depth; @@ -151,7 +146,7 @@ void DMD::UpdateRGB24Data(const uint8_t* pData, int depth, uint8_t r, uint8_t g, void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pData1, const uint16_t* pData2, uint8_t r, uint8_t g, uint8_t b) { std::lock_guard lock(m_mutex); - DMDUpdate* pUpdate = new DMDUpdate(); + DMDUpdate* const pUpdate = new DMDUpdate(); memset(pUpdate, 0, sizeof(DMDUpdate)); pUpdate->mode = DmdMode::AlphaNumeric; pUpdate->layout = layout; @@ -170,16 +165,6 @@ void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pDat m_condVar.notify_one(); } -uint8_t* DMD::GetLevelData() -{ - return m_pLevelData; -} - -uint32_t* DMD::GetRGB32Data() -{ - return m_pRGB32Data; -} - void DMD::FindDevices() { if (m_finding) @@ -193,13 +178,13 @@ void DMD::FindDevices() Pixelcade* pPixelcade = nullptr; #endif - Config* pConfig = Config::GetInstance(); + Config* const pConfig = Config::GetInstance(); if (pConfig->IsZeDMD()) { pZeDMD = new ZeDMD(); pZeDMD->SetLogCallback(ZeDMDLogCallback, nullptr); - if (!pConfig->GetZeDMDDevice().empty()) - pZeDMD->SetDevice(pConfig->GetZeDMDDevice().c_str()); + if (pConfig->GetZeDMDDevice() != nullptr && pConfig->GetZeDMDDevice()[0] != '\0') + pZeDMD->SetDevice(pConfig->GetZeDMDDevice()); if (pZeDMD->Open(m_width, m_height)) { if (pConfig->IsZeDMDDebug()) @@ -222,7 +207,7 @@ void DMD::FindDevices() #if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__)) if (pConfig->IsPixelcade()) - pPixelcade = Pixelcade::Connect(pConfig->GetPixelcadeDevice().c_str(), m_width, m_height); + pPixelcade = Pixelcade::Connect(pConfig->GetPixelcadeDevice(), m_width, m_height); #endif m_pZeDMD = pZeDMD; @@ -246,17 +231,16 @@ void DMD::Run() Log("DMD run thread starting"); DmdMode mode = DmdMode::Unknown; - bool update; while (m_running) { std::unique_lock lock(m_mutex); m_condVar.wait(lock, [this]{ return !m_updates.empty() || !m_running; }); while (!m_updates.empty()) { - DMDUpdate* pUpdate = m_updates.front(); + DMDUpdate* const pUpdate = m_updates.front(); m_updates.pop(); - update = (mode != pUpdate->mode); + const bool update = (mode != pUpdate->mode); mode = pUpdate->mode; if (mode == DmdMode::Data) @@ -266,12 +250,8 @@ void DMD::Run() else if (mode == DmdMode::AlphaNumeric) UpdateAlphaNumericData(pUpdate, update); - if (pUpdate->pData) - free(pUpdate->pData); - - if (pUpdate->pData2) - free(pUpdate->pData2); - + free(pUpdate->pData); + free(pUpdate->pData2); delete pUpdate; } } @@ -292,7 +272,7 @@ bool DMD::UpdatePalette(const DMDUpdate* pUpdate) if (pUpdate->depth != 2 && pUpdate->depth != 4) return false; - static uint8_t palette[192]; + uint8_t palette[192]; memcpy(palette, m_palette, 192); memset(m_palette, 0, 192); @@ -306,9 +286,9 @@ bool DMD::UpdatePalette(const DMDUpdate* pUpdate) for (int i = 0; i < colors; i++) { float perc = FrameUtil::CalcBrightness((float)i / (float)(colors - 1)); - m_palette[pos++] = (uint8_t)(r * perc); - m_palette[pos++] = (uint8_t)(g * perc); - m_palette[pos++] = (uint8_t)(b * perc); + m_palette[pos++] = (uint8_t)((float)r * perc); + m_palette[pos++] = (uint8_t)((float)g * perc); + m_palette[pos++] = (uint8_t)((float)b * perc); } return (memcmp(m_palette, palette, 192) != 0); @@ -316,7 +296,7 @@ bool DMD::UpdatePalette(const DMDUpdate* pUpdate) void DMD::UpdateData(const DMDUpdate* pUpdate, bool update) { - uint8_t* pData = (uint8_t*)pUpdate->pData; + uint8_t* const pData = (uint8_t*)pUpdate->pData; if (pData) { if (pUpdate->depth == 2) { @@ -337,7 +317,7 @@ void DMD::UpdateData(const DMDUpdate* pUpdate, bool update) if (!m_pSerum) { if (pData) { - if (memcmp(m_pData, pData, m_length)) { + if (memcmp(m_pData, pData, m_length) != 0) { memcpy(m_pData, pData, m_length); update = true; } @@ -355,19 +335,16 @@ void DMD::UpdateData(const DMDUpdate* pUpdate, bool update) if (!update) return; - int pos; - uint8_t r, g, b; - uint16_t x1, x2; for (int i = 0; i < m_length; i++) { - pos = m_pData[i] * 3; - r = m_palette[pos++]; - g = m_palette[pos++]; - b = m_palette[pos]; + int pos = m_pData[i] * 3; + uint8_t r = m_palette[pos ]; + uint8_t g = m_palette[pos+1]; + uint8_t b = m_palette[pos+2]; - m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFF << 24; + m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFFu << 24; - x1 = (r & 0xF8) | (g >> 5); - x2 = ((g & 0x1C) << 3) | (b >> 3); + uint16_t x1 = (r & 0xF8) | (g >> 5); + uint16_t x2 = ((g & 0x1C) << 3) | (b >> 3); m_pRGB565Data[i] = ((x1 << 8) + x2); } @@ -399,14 +376,14 @@ void DMD::UpdateData(const DMDUpdate* pUpdate, bool update) void DMD::UpdateRGB24Data(const DMDUpdate* pUpdate, bool update) { - uint8_t* pData = (uint8_t*)pUpdate->pData; + uint8_t* const pData = (uint8_t*)pUpdate->pData; if (pUpdate->depth != 24) { if (UpdatePalette(pUpdate)) update = true; } - if (memcmp(m_pRGB24Data, pData, m_length * 3)) + if (memcmp(m_pRGB24Data, pData, m_length * 3) != 0) update = true; if (!update) @@ -414,19 +391,18 @@ void DMD::UpdateRGB24Data(const DMDUpdate* pUpdate, bool update) memcpy(m_pRGB24Data, pData, m_length * 3); - uint8_t r, g, b, level; - uint16_t x1, x2; - int pos = 0, pos2, v; + int pos = 0; for (int i = 0; i < m_length; i++) { - r = m_pRGB24Data[pos++]; - g = m_pRGB24Data[pos++]; - b = m_pRGB24Data[pos++]; + uint8_t r = m_pRGB24Data[pos++]; + uint8_t g = m_pRGB24Data[pos++]; + uint8_t b = m_pRGB24Data[pos++]; if (pUpdate->depth != 24) { - v = (int)(0.2126f * r + 0.7152f * g + 0.0722f * b); + int v = (int)(0.2126f * (float)r + 0.7152f * (float)g + 0.0722f * (float)b); if (v > 255) v = 255; + uint8_t level; if (pUpdate->depth == 2) level = (uint8_t)(v >> 6); else @@ -434,17 +410,17 @@ void DMD::UpdateRGB24Data(const DMDUpdate* pUpdate, bool update) m_pLevelData[i] = level; - pos2 = level * 3; + int pos2 = level * 3; - r = m_palette[pos2++]; - g = m_palette[pos2++]; - b = m_palette[pos2]; + r = m_palette[pos2 ]; + g = m_palette[pos2+1]; + b = m_palette[pos2+2]; } - m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFF << 24; + m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFFu << 24; - x1 = (r & 0xF8) | (g >> 5); - x2 = ((g & 0x1C) << 3) | (b >> 3); + uint16_t x1 = (r & 0xF8) | (g >> 5); + uint16_t x2 = ((g & 0x1C) << 3) | (b >> 3); m_pRGB565Data[i] = ((x1 << 8) + x2); } @@ -476,12 +452,12 @@ void DMD::UpdateRGB24Data(const DMDUpdate* pUpdate, bool update) void DMD::UpdateAlphaNumericData(const DMDUpdate* pUpdate, bool update) { - if (memcmp(m_segData1, pUpdate->pData, 128 * sizeof(uint16_t))) { + if (memcmp(m_segData1, pUpdate->pData, 128 * sizeof(uint16_t)) != 0) { memcpy(m_segData1, pUpdate->pData, 128 * sizeof(uint16_t)); update = true; } - if (pUpdate->pData2 && memcmp(m_segData2, pUpdate->pData2, 128 * sizeof(uint16_t))) { + if (pUpdate->pData2 && memcmp(m_segData2, pUpdate->pData2, 128 * sizeof(uint16_t)) != 0) { memcpy(m_segData2, pUpdate->pData2, 128 * sizeof(uint16_t)); update = true; } @@ -495,26 +471,23 @@ void DMD::UpdateAlphaNumericData(const DMDUpdate* pUpdate, bool update) uint8_t* pData; if (pUpdate->pData2) - pData = m_pAlphaNumeric->Render((NumericalLayout)pUpdate->layout, (const uint16_t*)m_segData1, (const uint16_t*)m_segData2); + pData = m_pAlphaNumeric->Render(pUpdate->layout, (const uint16_t*)m_segData1, (const uint16_t*)m_segData2); else - pData = m_pAlphaNumeric->Render((NumericalLayout)pUpdate->layout, (const uint16_t*)m_segData1); + pData = m_pAlphaNumeric->Render(pUpdate->layout, (const uint16_t*)m_segData1); for (int i = 0; i < m_length; i++) m_pLevelData[i] = LEVELS_WPC[pData[i]]; - int pos; - uint8_t r, g, b; - uint16_t x1, x2; for (int i = 0; i < m_length; i++) { - pos = pData[i] * 3; - r = m_palette[pos++]; - g = m_palette[pos++]; - b = m_palette[pos]; + int pos = pData[i] * 3; + uint8_t r = m_palette[pos ]; + uint8_t g = m_palette[pos+1]; + uint8_t b = m_palette[pos+2]; - m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFF << 24; + m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFFu << 24; - x1 = (r & 0xF8) | (g >> 5); - x2 = ((g & 0x1C) << 3) | (b >> 3); + uint16_t x1 = (r & 0xF8) | (g >> 5); + uint16_t x2 = ((g & 0x1C) << 3) | (b >> 3); m_pRGB565Data[i] = ((x1 << 8) + x2); } diff --git a/src/FrameUtil.cpp b/src/FrameUtil.cpp index cb19ac8..34b899c 100644 --- a/src/FrameUtil.cpp +++ b/src/FrameUtil.cpp @@ -6,7 +6,6 @@ #include "FrameUtil.h" -#include #include #include #include @@ -31,25 +30,22 @@ inline int FrameUtil::MapAdafruitIndex(int x, int y, int width, int height, int void FrameUtil::SplitIntoRgbPlanes(const uint16_t* rgb565, int rgb565Size, int width, int numLogicalRows, uint8_t* dest, ColorMatrix colorMatrix) { - int pairOffset = 16; + constexpr int pairOffset = 16; int height = rgb565Size / width; int subframeSize = rgb565Size / 2; - int r0 = 0, r1 = 0, g0 = 0, g1 = 0, b0 = 0, b1 = 0, inputIndex0, inputIndex1; - uint16_t color0, color1; - uint8_t dotPair; - for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { if (y % (pairOffset * 2) >= pairOffset) continue; - inputIndex0 = y * width + x; - inputIndex1 = (y + pairOffset) * width + x; + int inputIndex0 = y * width + x; + int inputIndex1 = (y + pairOffset) * width + x; - color0 = rgb565[inputIndex0]; - color1 = rgb565[inputIndex1]; + uint16_t color0 = rgb565[inputIndex0]; + uint16_t color1 = rgb565[inputIndex1]; + int r0 = 0, r1 = 0, g0 = 0, g1 = 0, b0 = 0, b1 = 0; switch (colorMatrix) { case ColorMatrix::Rgb: r0 = (color0 >> 13) & 0x7; @@ -71,7 +67,7 @@ void FrameUtil::SplitIntoRgbPlanes(const uint16_t* rgb565, int rgb565Size, int w } for (int subframe = 0; subframe < 3; ++subframe) { - dotPair = + uint8_t dotPair = (r0 & 1) << 5 | (g0 & 1) << 4 | (b0 & 1) << 3 | @@ -102,9 +98,9 @@ inline uint16_t FrameUtil::InterpolateRgb565Color(uint16_t color1, uint16_t colo int green2 = (color2 >> 5) & 0x3F; int blue2 = color2 & 0x1F; - int red = red1 + static_cast((red2 - red1) * ratio); - int green = green1 + static_cast((green2 - green1) * ratio); - int blue = blue1 + static_cast((blue2 - blue1) * ratio); + int red = red1 + static_cast((float)(red2 - red1) * ratio); + int green = green1 + static_cast((float)(green2 - green1) * ratio); + int blue = blue1 + static_cast((float)(blue2 - blue1) * ratio); red = std::min(std::max(red, 0), 0x1F); green = std::min(std::max(green, 0), 0x3F); @@ -117,8 +113,8 @@ inline uint16_t FrameUtil::InterpolatedRgb565Pixel(const uint16_t* src, float sr { int x = (int)srcX; int y = (int)srcY; - float xDiff = srcX - x; - float yDiff = srcY - y; + float xDiff = srcX - (float)x; + float yDiff = srcY - (float)y; uint16_t a = src[y * srcWidth + x]; uint16_t b = x < srcWidth - 1 ? src[y * srcWidth + (x + 1)] : a; @@ -135,17 +131,17 @@ void FrameUtil::ResizeRgb565Bilinear(const uint16_t* src, int srcWidth, int srcH { memset(dest, 0, destWidth * destHeight * sizeof(uint16_t)); - float srcAspect = (float)(srcWidth) / srcHeight; - float destAspect = (float)(destWidth) / destHeight; + float srcAspect = (float)srcWidth / (float)srcHeight; + float destAspect = (float)destWidth / (float)destHeight; int scaledWidth, scaledHeight; if (srcAspect > destAspect) { scaledWidth = destWidth; - scaledHeight = (int)(destWidth / srcAspect); + scaledHeight = (int)((float)destWidth / srcAspect); } else { scaledHeight = destHeight; - scaledWidth = (int)(destHeight * srcAspect); + scaledWidth = (int)((float)destHeight * srcAspect); } int offsetX = (destWidth - scaledWidth) / 2; @@ -153,8 +149,8 @@ void FrameUtil::ResizeRgb565Bilinear(const uint16_t* src, int srcWidth, int srcH for (int y = 0; y < scaledHeight; ++y) { for (int x = 0; x < scaledWidth; ++x) { - float srcX = (x + 0.5f) * srcWidth / scaledWidth - 0.5f; - float srcY = (y + 0.5f) * srcHeight / scaledHeight - 0.5f; + float srcX = ((float)x + 0.5f) * ((float)srcWidth / (float)scaledWidth) - 0.5f; + float srcY = ((float)y + 0.5f) * ((float)srcHeight / (float)scaledHeight) - 0.5f; srcX = std::max(0.0f, std::min(srcX, static_cast(srcWidth - 1))); srcY = std::max(0.0f, std::min(srcY, static_cast(srcHeight - 1))); @@ -172,7 +168,7 @@ float FrameUtil::CalcBrightness(float x) std::string FrameUtil::HexDump(const uint8_t* data, size_t size) { - const int bytesPerLine = 32; + constexpr int bytesPerLine = 32; std::stringstream ss; diff --git a/src/Pixelcade.cpp b/src/Pixelcade.cpp index 4cf4b66..18e5b4c 100644 --- a/src/Pixelcade.cpp +++ b/src/Pixelcade.cpp @@ -114,7 +114,6 @@ Pixelcade* Pixelcade::Open(const char* pDevice, int width, int height) std::this_thread::sleep_for(std::chrono::milliseconds(100)); unsigned char response[29]; - size_t bytes_read; result = sp_blocking_read(pSerialPort, response, 29, PIXELCADE_COMMAND_READ_TIMEOUT); if (response[0] != PIXELCADE_RESPONSE_ESTABLE_CONNECTION) { @@ -124,7 +123,7 @@ Pixelcade* Pixelcade::Open(const char* pDevice, int width, int height) return nullptr; } - if (response[1] != 'I' || response[2] != 'O' && response[3] != 'I' || response[4] != 'O') { + if (response[1] != 'I' || response[2] != 'O' || response[3] != 'I' || response[4] != 'O') { sp_close(pSerialPort); sp_free_port(pSerialPort); //Log("Pixelcade: expected magic code to equal IOIO but got %c%c%c%c", response[1], response[2], response[3], response[4]); @@ -143,8 +142,6 @@ Pixelcade* Pixelcade::Open(const char* pDevice, int width, int height) Log("Pixelcade found: device=%s, Hardware ID=%s, Bootloader ID=%s, Firmware=%s", pDevice, hardwareId, bootloaderId, firmware); return new Pixelcade(pSerialPort, width, height); - - return nullptr; } void Pixelcade::Update(uint16_t* pData) @@ -167,7 +164,7 @@ void Pixelcade::Update(uint16_t* pData) void Pixelcade::EnableRgbLedMatrix(int shifterLen32, int rows) { - uint8_t data[2] = { PIXELCADE_COMMAND_RGB_LED_MATRIX_ENABLE, (uint8_t)(shifterLen32 & 0x0F | ((rows == 8 ? 0 : 1) << 4)) }; + uint8_t data[2] = { PIXELCADE_COMMAND_RGB_LED_MATRIX_ENABLE, (uint8_t)((shifterLen32 & 0x0F) | ((rows == 8 ? 0 : 1) << 4)) }; sp_blocking_write(m_pSerialPort, data, 2, 0); } @@ -183,9 +180,6 @@ void Pixelcade::Run() Log("Pixelcade run thread starting"); EnableRgbLedMatrix(4, 16); - uint8_t planes[128 * 32 * 3 / 2]; - uint16_t scaledFrame[128 * 32]; - while (m_running) { std::unique_lock lock(m_mutex); m_condVar.wait(lock, [this]{ return !m_frames.empty() || !m_running; }); @@ -204,10 +198,12 @@ void Pixelcade::Run() static uint8_t command = PIXELCADE_COMMAND_RGB_LED_MATRIX_FRAME; sp_blocking_write(m_pSerialPort, &command, 1, PIXELCADE_COMMAND_WRITE_TIMEOUT); - + + uint8_t planes[128 * 32 * 3 / 2]; if (m_width == 128 && m_height == 32) FrameUtil::SplitIntoRgbPlanes(pFrame, 128 * 32, 128, 16, (uint8_t*)planes); else { + uint16_t scaledFrame[128 * 32]; FrameUtil::ResizeRgb565Bilinear(pFrame, m_width, m_height, scaledFrame, 128, 32); FrameUtil::SplitIntoRgbPlanes(scaledFrame, 128 * 32, 128, 16, (uint8_t*)planes); } diff --git a/src/Pixelcade.h b/src/Pixelcade.h index f2a0f2a..320f024 100644 --- a/src/Pixelcade.h +++ b/src/Pixelcade.h @@ -26,13 +26,13 @@ namespace DMDUtil { class Pixelcade { public: + Pixelcade(struct sp_port* pSerialPort, int width, int height); ~Pixelcade(); static Pixelcade* Connect(const char* pDevice, int width, int height); void Update(uint16_t* pData); private: - Pixelcade(struct sp_port* pSerialPort, int width, int height); static Pixelcade* Open(const char* pDevice, int width, int height); void Run(); void Stop(); diff --git a/src/Serum.cpp b/src/Serum.cpp index ebfd16d..be0ea94 100644 --- a/src/Serum.cpp +++ b/src/Serum.cpp @@ -1,4 +1,5 @@ #include "Serum.h" +#include "serum-decode.h" #include "DMDUtil/Config.h" #include "Logger.h" @@ -19,8 +20,7 @@ Serum::Serum(int width, int height) Serum::~Serum() { - if (m_pFrame) - free(m_pFrame); + free(m_pFrame); Serum_Dispose(); @@ -52,8 +52,6 @@ Serum* Serum::Load(const std::string& romName) m_isLoaded = true; return new Serum(width, height); - - return nullptr; } bool Serum::Convert(uint8_t* pFrame, uint8_t* pDstFrame, uint8_t* pDstPalette) diff --git a/src/Serum.h b/src/Serum.h index 462567b..7808de9 100644 --- a/src/Serum.h +++ b/src/Serum.h @@ -1,7 +1,5 @@ #pragma once -#include "serum-decode.h" - #include #include diff --git a/src/test.cpp b/src/test.cpp index 4c3032c..b86d184 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -48,7 +48,7 @@ int main(int argc, const char* argv[]) { printf("Finding displays...\n"); - while (pDmd->IsFinding()) + while (DMDUtil::DMD::IsFinding()) std::this_thread::sleep_for(std::chrono::milliseconds(100)); if (!pDmd->HasDisplay()) {