aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/rle/RleDecoder.cpp
diff options
context:
space:
mode:
authorpanky-codes <pankaj.sarathy1992@gmail.com>2021-03-20 22:45:29 +0100
committerpanky-codes <pankaj.sarathy1992@gmail.com>2021-03-20 22:45:29 +0100
commit534565088033221d29e968acf7267145ff10203b (patch)
treec93ae7c7aa7995204f56b979ff6524feba83763d /src/components/rle/RleDecoder.cpp
parent754ac233040af805ffa2e15b24539d5d02a876e5 (diff)
parenta3ff2e46ca9e663af864a2bd04b9afa3efbddfb8 (diff)
Merged upstream
Diffstat (limited to 'src/components/rle/RleDecoder.cpp')
-rw-r--r--src/components/rle/RleDecoder.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/components/rle/RleDecoder.cpp b/src/components/rle/RleDecoder.cpp
new file mode 100644
index 00000000..19a90fda
--- /dev/null
+++ b/src/components/rle/RleDecoder.cpp
@@ -0,0 +1,39 @@
+#include "RleDecoder.h"
+
+using namespace Pinetime::Tools;
+
+RleDecoder::RleDecoder(const uint8_t *buffer, size_t size) : buffer{buffer}, size{size} {
+
+}
+
+RleDecoder::RleDecoder(const uint8_t *buffer, size_t size, uint16_t foregroundColor, uint16_t backgroundColor) : RleDecoder{buffer, size} {
+ this->foregroundColor = foregroundColor;
+ this->backgroundColor = backgroundColor;
+}
+
+
+void RleDecoder::DecodeNext(uint8_t *output, size_t maxBytes) {
+ for (;encodedBufferIndex<size; encodedBufferIndex++) {
+ uint8_t rl = buffer[encodedBufferIndex] - processedCount;
+ while (rl) {
+ output[bp] = color >> 8;
+ output[bp + 1] = color & 0xff;
+ bp += 2;
+ rl -= 1;
+ processedCount++;
+
+ if (bp >= maxBytes) {
+ bp = 0;
+ y += 1;
+ return;
+ }
+ }
+ processedCount = 0;
+
+ if (color == backgroundColor)
+ color = foregroundColor;
+ else
+ color = backgroundColor;
+ }
+}
+