Skip to content

Commit cdb2dae

Browse files
committed
scale RGB24DMD
1 parent 829d84f commit cdb2dae

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

include/DMDUtil/RGB24DMD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DMDUTILAPI RGB24DMD
1919
RGB24DMD(uint16_t width, uint16_t height);
2020
~RGB24DMD();
2121

22-
virtual void Update(uint8_t* pRGB24Data);
22+
virtual void Update(uint8_t* pRGB24Data, uint16_t width = 0, uint16_t height = 0);
2323
int GetWidth() const { return m_width; }
2424
int GetHeight() const { return m_height; }
2525
int GetLength() const { return m_length; }

src/DMD.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,7 @@ void DMD::RGB24DMDThread()
14911491
uint8_t palette[PALETTE_SIZE] = {0};
14921492
uint8_t renderBuffer[256 * 64] = {0};
14931493
uint8_t rgb24Data[256 * 64 * 3] = {0};
1494+
uint8_t rgb24DataScaled[256 * 64 * 3] = {0};
14941495

14951496
(void)m_dmdFrameReady.load(std::memory_order_acquire);
14961497
(void)m_stopFlag.load(std::memory_order_acquire);
@@ -1539,7 +1540,8 @@ void DMD::RGB24DMDThread()
15391540

15401541
for (RGB24DMD* pRGB24DMD : m_rgb24DMDs)
15411542
{
1542-
if (pRGB24DMD->GetLength() == length * 3) pRGB24DMD->Update(rgb24Data);
1543+
pRGB24DMD->Update(rgb24Data, m_pUpdateBufferQueue[bufferPosition]->width,
1544+
m_pUpdateBufferQueue[bufferPosition]->height);
15431545
}
15441546
// Reset renderBuffer in case the mode changes for the next frame to ensure that memcmp() will detect it.
15451547
memset(renderBuffer, 0, sizeof(renderBuffer));
@@ -1608,7 +1610,8 @@ void DMD::RGB24DMDThread()
16081610

16091611
for (RGB24DMD* pRGB24DMD : m_rgb24DMDs)
16101612
{
1611-
if (pRGB24DMD->GetLength() == length * 3) pRGB24DMD->Update(rgb24Data);
1613+
pRGB24DMD->Update(rgb24Data, m_pUpdateBufferQueue[bufferPosition]->width,
1614+
m_pUpdateBufferQueue[bufferPosition]->height);
16121615
}
16131616
}
16141617
}
@@ -1634,7 +1637,8 @@ void DMD::RGB24DMDThread()
16341637
(pRGB24DMD->GetWidth() < 256 && m_pUpdateBufferQueue[bufferPosition]->mode == Mode::SerumV2_64_32)))
16351638
continue;
16361639

1637-
if (pRGB24DMD->GetLength() == length * 3) pRGB24DMD->Update(rgb24Data);
1640+
pRGB24DMD->Update(rgb24Data, m_pUpdateBufferQueue[bufferPosition]->width,
1641+
m_pUpdateBufferQueue[bufferPosition]->height);
16381642
}
16391643
}
16401644
}

src/RGB24DMD.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <cstring>
55
#include <string>
66

7+
#include "FrameUtil.h"
8+
79
namespace DMDUtil
810
{
911

@@ -22,11 +24,31 @@ RGB24DMD::RGB24DMD(uint16_t width, uint16_t height)
2224

2325
RGB24DMD::~RGB24DMD() { free(m_pData); }
2426

25-
void RGB24DMD::Update(uint8_t* pData)
27+
void RGB24DMD::Update(uint8_t* pData, uint16_t width, uint16_t height)
2628
{
27-
memcpy(m_pData, pData, m_length);
28-
29-
m_update = true;
29+
if (width == 0) width = m_width;
30+
if (height == 0) height = m_height;
31+
32+
if (width == m_width && height == m_height)
33+
{
34+
memcpy(m_pData, pData, m_length);
35+
m_update = true;
36+
}
37+
else if (width == 128 && height == 16 && m_width == 128 && m_height == 32)
38+
{
39+
FrameUtil::Helper::Center(m_pData, 128, 32, pData, 128, 16, 24);
40+
m_update = true;
41+
}
42+
else if (height == 64 && m_height == 32)
43+
{
44+
FrameUtil::Helper::ScaleDown(m_pData, 128, 32, pData, width, height, 24);
45+
m_update = true;
46+
}
47+
else if (height == 32 && m_height == 64)
48+
{
49+
FrameUtil::Helper::ScaleUp(m_pData, pData, width, height, 24);
50+
m_update = true;
51+
}
3052
}
3153

3254
uint8_t* RGB24DMD::GetData()

0 commit comments

Comments
 (0)