Skip to content

Commit

Permalink
minor optimizations, NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
toxieainc committed Jan 15, 2024
1 parent a5d9bc6 commit 8a4dc78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/AlphaNumeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void AlphaNumeric::SmoothDigitCorners(const int x, const int y)
DrawPixel(6 + x, 10 + y, 0);
}

void AlphaNumeric::SmoothDigitCorners6Px(int x, int y)
void AlphaNumeric::SmoothDigitCorners6Px(const int x, const int y)
{
if (GetPixel(x, 1 + y) && GetPixel(1 + x, y))
DrawPixel(0 + x, y, 0);
Expand Down
50 changes: 19 additions & 31 deletions src/DMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,18 @@ bool DMD::UpdatePalette(const DMDUpdate* pUpdate)

memset(m_palette, 0, 192);

uint8_t r = pUpdate->r;
uint8_t g = pUpdate->g;
uint8_t b = pUpdate->b;
const float r = (float)pUpdate->r;
const float g = (float)pUpdate->g;
const float b = (float)pUpdate->b;

int colors = (pUpdate->depth == 2) ? 4 : 16;
const int colors = (pUpdate->depth == 2) ? 4 : 16;
int pos = 0;

for (int i = 0; i < colors; i++) {
float perc = FrameUtil::CalcBrightness((float)i / (float)(colors - 1));
m_palette[pos++] = (uint8_t)((float)r * perc);
m_palette[pos++] = (uint8_t)((float)g * perc);
m_palette[pos++] = (uint8_t)((float)b * perc);
m_palette[pos++] = (uint8_t)(r * perc);
m_palette[pos++] = (uint8_t)(g * perc);
m_palette[pos++] = (uint8_t)(b * perc);
}

return (memcmp(m_palette, palette, 192) != 0);
Expand Down Expand Up @@ -339,16 +339,12 @@ void DMD::UpdateData(const DMDUpdate* pUpdate, bool update)

for (int i = 0; i < m_length; i++) {
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];
uint32_t r = m_palette[pos ];
uint32_t g = m_palette[pos+1];
uint32_t b = m_palette[pos+2];

m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFFu << 24;

uint16_t x1 = (r & 0xF8) | (g >> 5);
uint16_t x2 = ((g & 0x1C) << 3) | (b >> 3);

m_pRGB565Data[i] = ((x1 << 8) + x2);
m_pRGB565Data[i] = (uint16_t)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | (b >> 3));
}

if (m_pZeDMD) {
Expand Down Expand Up @@ -395,9 +391,9 @@ void DMD::UpdateRGB24Data(const DMDUpdate* pUpdate, bool update)

int pos = 0;
for (int i = 0; i < m_length; i++) {
uint8_t r = m_pRGB24Data[pos++];
uint8_t g = m_pRGB24Data[pos++];
uint8_t b = m_pRGB24Data[pos++];
uint32_t r = m_pRGB24Data[pos++];
uint32_t g = m_pRGB24Data[pos++];
uint32_t b = m_pRGB24Data[pos++];

if (pUpdate->depth != 24) {
int v = (int)(0.2126f * (float)r + 0.7152f * (float)g + 0.0722f * (float)b);
Expand All @@ -420,11 +416,7 @@ void DMD::UpdateRGB24Data(const DMDUpdate* pUpdate, bool update)
}

m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFFu << 24;

uint16_t x1 = (r & 0xF8) | (g >> 5);
uint16_t x2 = ((g & 0x1C) << 3) | (b >> 3);

m_pRGB565Data[i] = ((x1 << 8) + x2);
m_pRGB565Data[i] = (uint16_t)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | (b >> 3));
}

if (pUpdate->depth == 2) {
Expand Down Expand Up @@ -482,16 +474,12 @@ void DMD::UpdateAlphaNumericData(const DMDUpdate* pUpdate, bool update)

for (int i = 0; i < m_length; i++) {
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];
uint32_t r = m_palette[pos ];
uint32_t g = m_palette[pos+1];
uint32_t b = m_palette[pos+2];

m_pRGB32Data[i] = r | g << 8 | b << 16 | 0xFFu << 24;

uint16_t x1 = (r & 0xF8) | (g >> 5);
uint16_t x2 = ((g & 0x1C) << 3) | (b >> 3);

m_pRGB565Data[i] = ((x1 << 8) + x2);
m_pRGB565Data[i] = (uint16_t)(((r & 0xF8u) << 8) | ((g & 0xFCu) << 3) | (b >> 3));
}

if (m_pZeDMD) {
Expand Down

0 comments on commit 8a4dc78

Please sign in to comment.