Skip to content

Commit

Permalink
fixed streaming mode for 128x32
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Dec 21, 2023
1 parent 1dc4aa6 commit a926406
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/ZeDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void ZeDMD::RenderRgb24(uint8_t *pFrame)
{
m_pZeDMDWiFi->QueueCommand(ZEDMD_WIFI_COMMAND::UDP_RGB24, m_pPlanes, bufferSize, width, height);
}
else if (m_hd)
else if (m_hd || m_streaming)
{
m_pZeDMDComm->QueueCommand(ZEDMD_COMM_COMMAND::RGB24ZonesStream, m_pPlanes, bufferSize, width, height);
}
Expand Down Expand Up @@ -544,8 +544,8 @@ int ZeDMD::Scale(uint8_t *pScaledFrame, uint8_t *pFrame, uint8_t colors, uint16_
}
else if (m_downscaling && m_romWidth == 192)
{
(*width) = m_romWidth;
(*height) = m_romHeight;
(*width) = frameWidth;
(*height) = frameHeight;

xoffset = 16;
scale = 1;
Expand All @@ -567,8 +567,8 @@ int ZeDMD::Scale(uint8_t *pScaledFrame, uint8_t *pFrame, uint8_t colors, uint16_
}
else if (m_downscaling && m_romWidth == 256 && frameWidth == 128)
{
(*width) = m_romWidth;
(*height) = m_romHeight;
(*width) = frameWidth;
(*height) = frameHeight;

scale = 1;
}
Expand Down
27 changes: 14 additions & 13 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ void ZeDMDComm::QueueCommand(char command)

void ZeDMDComm::QueueCommand(char command, uint8_t *data, int size, uint16_t width, uint16_t height)
{
uint8_t buffer[256 * 16 * 3 + 32];
uint8_t buffer[256 * 16 * 3 + 16];
uint16_t bufferSize = 0;
uint8_t idx = 0;
uint8_t zone[16 * 8 * 3] = { 0 };

if (++m_streamId > 64)
{
Expand All @@ -191,27 +192,25 @@ void ZeDMDComm::QueueCommand(char command, uint8_t *data, int size, uint16_t wid
m_delayedFrameMutex.unlock();
}

for (uint16_t y = 0; y < height; y += 8)
{
for (uint16_t x = 0; x < width; x += 16)
{
uint8_t zone[16 * 8 * 3] = {0};

for (uint8_t z = 0; z < 8; z++)
for (uint16_t y = 0; y < height; y += m_zoneHeight)
{
for (uint16_t x = 0; x < width; x += m_zoneWidth)
{
for (uint8_t z = 0; z < m_zoneHeight; z++)
{
memcpy(&zone[z * 16 * 3], &data[((y + z) * width + x) * 3], 16 * 3);
memcpy(&zone[z * m_zoneWidth * 3], &data[((y + z) * width + x) * 3], m_zoneWidth * 3);
}

uint64_t hash = komihash(zone, 16 * 8 * 3, 0);
uint64_t hash = komihash(zone, m_zoneWidth * m_zoneHeight * 3, 0);
if (hash != m_zoneHashes[idx])
{
m_zoneHashes[idx] = hash;

buffer[bufferSize++] = idx;
memcpy(&buffer[bufferSize], zone, 16 * 8 * 3);
bufferSize += 16 * 8 * 3;
memcpy(&buffer[bufferSize], zone, m_zoneWidth * m_zoneHeight * 3);
bufferSize += m_zoneWidth * m_zoneHeight * 3;

if (bufferSize >= 256 * 16 * 3 + 32)
if (bufferSize >= (width * m_zoneHeight * 3 + 16))
{
QueueCommand(command, buffer, bufferSize, m_streamId, delayed);
bufferSize = 0;
Expand Down Expand Up @@ -344,6 +343,8 @@ bool ZeDMDComm::Connect(char *pDevice)
{
m_width = data[4] + data[5] * 256;
m_height = data[6] + data[7] * 256;
m_zoneWidth = m_width / 16;
m_zoneHeight = m_height / 8;

uint8_t response;

Expand Down
2 changes: 2 additions & 0 deletions src/ZeDMDComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class ZeDMDComm
uint64_t m_zoneHashes[128] = {0};
uint16_t m_width = 128;
uint16_t m_height = 32;
uint8_t m_zoneWidth = 8;
uint8_t m_zoneHeight = 4;
int8_t m_streamId = -1;
int8_t m_lastStreamId = -1;
uint8_t m_flowControlCounter = 0;
Expand Down

0 comments on commit a926406

Please sign in to comment.