diff options
author | Niall Cooling <niallcooling@gmail.com> | 2021-03-22 17:23:49 +0000 |
---|---|---|
committer | Niall Cooling <niallcooling@gmail.com> | 2021-03-22 17:23:49 +0000 |
commit | e5e3fc02b8a2adf9ea100c162d1290cecdf617ef (patch) | |
tree | 78d4da0239ff8bf7a8694c28f804f81d2496979f /src/components/rle/RleDecoder.cpp | |
parent | 14bd790701f4e2f6d75ef8a1f52b9f38023c2dd9 (diff) | |
parent | 9f9d0eb5df8ff86b9cd1e095afa3159094dde53c (diff) |
Updated to include WatchFaceAnalog and fixed clashes
Diffstat (limited to 'src/components/rle/RleDecoder.cpp')
-rw-r--r-- | src/components/rle/RleDecoder.cpp | 39 |
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; + } +} + |