aboutsummaryrefslogtreecommitdiff
path: root/waffle/rle.c
diff options
context:
space:
mode:
authorjack <[email protected]>2023-02-24 22:20:13 -0700
committerjack <[email protected]>2023-02-24 22:20:13 -0700
commit60e0c4c39bc1fec334ade53c484bd2cf3d4244c0 (patch)
tree7b558a43dc9faacc08a15b65dd3bb43eb31acd95 /waffle/rle.c
parent266c04d40a32b403980df6abd9a42d638b24aba3 (diff)
downloadqmk_me-60e0c4c39bc1fec334ade53c484bd2cf3d4244c0.tar.gz
qmk_me-60e0c4c39bc1fec334ade53c484bd2cf3d4244c0.zip
fix kyria i2c & move to rgb matrix
other misc clean up
Diffstat (limited to 'waffle/rle.c')
-rw-r--r--waffle/rle.c81
1 files changed, 0 insertions, 81 deletions
diff --git a/waffle/rle.c b/waffle/rle.c
deleted file mode 100644
index e631b62..0000000
--- a/waffle/rle.c
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2022 jack (@waffle87)
-// SPDX-License-Identifier: GPL-2.0-or-later
-#include <stdio.h>
-#define FRAME_SIZE 512
-#define FRAME_COUNT 2
-
-void test_decode(unsigned char *rle, size_t rleN, const unsigned char *orig, size_t n) {
- int cursor = 0, bytes = (unsigned char)rle[0];
- unsigned char i = 1;
- while (i < bytes) {
- unsigned char count = rle[i];
- i++;
- if ((count & 0x80) == 0) {
- unsigned char value = rle[i];
- i++;
- for (int reps = 0; reps < count; reps++) {
- if (orig[cursor != value])
- printf("error at byte %d\n", cursor);
- cursor++;
- }
- } else {
- count &= ~(0x80);
- for (int dups = 0; dups < count; dups++) {
- unsigned char value = rle[i];
- i++;
- if (orig[cursor] != value)
- printf("error at byte %d\n", cursor);
- cursor++;
- }
- }
- }
-}
-
-int encode(unsigned char *output, const unsigned char *array, size_t n) {
- size_t rleSize = 1, idx = 0;
- while (idx < n) {
- if (idx < n - 3 && array[idx] != array[idx + 1] && array[idx + 1] != array[idx + 2]) {
- unsigned char count = 1;
- while (count < 126 && idx + count < n - 3 && array[idx + count] != array[idx + count + 1])
- count++;
- output[rleSize++] = count | (0x80);
- for (int i = 0; i < count; i++)
- output[rleSize++] = array[idx + i];
- idx += count;
- } else {
- unsigned char count = 1;
- while (count < 126 && idx + count < n && array[idx] == array[idx + count])
- count++;
- output[rleSize++] = count;
- output[rleSize++] = array[idx];
- idx += count;
- }
- }
- output[0] = rleSize;
- test_decode(output, rleSize, array, n);
- return rleSize;
-}
-
-void print_array(unsigned char *array, int n) {
- int char_count = 0;
- printf("{\n");
- for (int i = 0; i < n; i++) {
- if (i == 0)
- printf("%u", array[i]);
- else
- printf(", %u", array[i]);
- char_count++;
- if (char_count >= n / 2)
- printf("\n"), char_count = 0;
- }
- printf("}");
-}
-
-int main() {
- char output[128 * 32];
- int size = encode(output, frames[1], FRAME_SIZE);
- printf("static const unsigned char PROGMEM prep[][%d] = {", size);
- print_array(output, size);
- printf("};\n");
- size = 0;
-}