diff --git a/src/ZeDMD.cpp b/src/ZeDMD.cpp index 2c9e44b..6083515 100644 --- a/src/ZeDMD.cpp +++ b/src/ZeDMD.cpp @@ -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); } @@ -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; @@ -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; } diff --git a/src/ZeDMDComm.cpp b/src/ZeDMDComm.cpp index 84c0949..6c9bf9a 100644 --- a/src/ZeDMDComm.cpp +++ b/src/ZeDMDComm.cpp @@ -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) { @@ -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; @@ -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; diff --git a/src/ZeDMDComm.h b/src/ZeDMDComm.h index bdaf5d4..deb4ec9 100644 --- a/src/ZeDMDComm.h +++ b/src/ZeDMDComm.h @@ -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;