aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/rle/RleDecoder.h
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.h
parent754ac233040af805ffa2e15b24539d5d02a876e5 (diff)
parenta3ff2e46ca9e663af864a2bd04b9afa3efbddfb8 (diff)
Merged upstream
Diffstat (limited to 'src/components/rle/RleDecoder.h')
-rw-r--r--src/components/rle/RleDecoder.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/components/rle/RleDecoder.h b/src/components/rle/RleDecoder.h
new file mode 100644
index 00000000..0f607fb8
--- /dev/null
+++ b/src/components/rle/RleDecoder.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <cstdint>
+#include <cstddef>
+
+namespace Pinetime {
+ namespace Tools {
+ /* 1-bit RLE decoder. Provide the encoded buffer to the constructor and then call DecodeNext() by
+ * specifying the output (decoded) buffer and the maximum number of bytes this buffer can handle.
+ *
+ * Code from https://github.com/daniel-thompson/wasp-bootloader by Daniel Thompson released under the MIT license.
+ */
+ class RleDecoder {
+ public:
+ RleDecoder(const uint8_t* buffer, size_t size);
+ RleDecoder(const uint8_t* buffer, size_t size, uint16_t foregroundColor, uint16_t backgroundColor);
+
+ void DecodeNext(uint8_t* output, size_t maxBytes);
+
+ private:
+ const uint8_t* buffer;
+ size_t size;
+
+ int encodedBufferIndex = 0;
+ int y = 0;
+ uint16_t bp = 0;
+ uint16_t foregroundColor = 0xffff;
+ uint16_t backgroundColor = 0;
+ uint16_t color = backgroundColor;
+ int processedCount = 0;
+ };
+ }
+}