Skip to content

Commit

Permalink
fixed rendering of indexed frames with palette (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner authored Jan 14, 2025
1 parent 8f38753 commit 833aad2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/DMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ void DMD::ZeDMDThread()
uint16_t segData1[128] = {0};
uint16_t segData2[128] = {0};
uint8_t palette[PALETTE_SIZE] = {0};
uint8_t renderBuffer[256 * 64] = {0};
uint8_t indexBuffer[256 * 64] = {0};
uint8_t renderBuffer[256 * 64 * 3] = {0};

m_dmdFrameReady.load(std::memory_order_acquire);
m_stopFlag.load(std::memory_order_acquire);
Expand Down Expand Up @@ -697,12 +698,12 @@ void DMD::ZeDMDThread()
if (m_pUpdateBufferQueue[bufferPosition]->mode == Mode::SerumV1)
{
memcpy(palette, m_pUpdateBufferQueue[bufferPosition]->segData, PALETTE_SIZE);
memcpy(renderBuffer, m_pUpdateBufferQueue[bufferPosition]->data, frameSize);
memcpy(indexBuffer, m_pUpdateBufferQueue[bufferPosition]->data, frameSize);
update = true;
}
else if (!m_pSerum && m_pUpdateBufferQueue[bufferPosition]->mode == Mode::Data)
{
memcpy(renderBuffer, m_pUpdateBufferQueue[bufferPosition]->data, frameSize);
memcpy(indexBuffer, m_pUpdateBufferQueue[bufferPosition]->data, frameSize);
update = true;
}
else if (m_pUpdateBufferQueue[bufferPosition]->mode == Mode::AlphaNumeric)
Expand All @@ -723,20 +724,21 @@ void DMD::ZeDMDThread()
if (update)
{
if (m_pUpdateBufferQueue[bufferPosition]->hasSegData2)
m_pAlphaNumeric->Render(renderBuffer, m_pUpdateBufferQueue[bufferPosition]->layout, segData1, segData2);
m_pAlphaNumeric->Render(indexBuffer, m_pUpdateBufferQueue[bufferPosition]->layout, segData1, segData2);
else
m_pAlphaNumeric->Render(renderBuffer, m_pUpdateBufferQueue[bufferPosition]->layout, segData1);
m_pAlphaNumeric->Render(indexBuffer, m_pUpdateBufferQueue[bufferPosition]->layout, segData1);
}
}

if (update)
{
uint16_t renderBuferPosition = 0;
for (int i = 0; i < frameSize; i++)
{
int pos = renderBuffer[i] * 3;
uint32_t r = palette[pos];
uint32_t g = palette[pos + 1];
uint32_t b = palette[pos + 2];
int pos = indexBuffer[i] * 3;
renderBuffer[renderBuferPosition++] = palette[pos];
renderBuffer[renderBuferPosition++] = palette[pos + 1];
renderBuffer[renderBuferPosition++] = palette[pos + 2];
}
}
}
Expand Down

0 comments on commit 833aad2

Please sign in to comment.