RLE blitter, plus RLE encoding and decoding tools
[bootsplash] / rle / unrle.c
diff --git a/rle/unrle.c b/rle/unrle.c
new file mode 100644 (file)
index 0000000..7f70edd
--- /dev/null
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+int main(void)
+{
+       int c, count, rawbytes = 0;
+
+       printf("P5\n320 200\n255\n");
+
+       while((c = getchar()) != -1) {
+               if(c & 0x80) {
+                       count = c & 0x7f;
+                       if((c = getchar()) == -1) {
+                               fprintf(stderr, "Unexpected EOF while decoding RLE data\n");
+                               return 1;
+                       }
+                       rawbytes += count;
+                       while(count--) putchar(c);
+               } else {
+                       rawbytes++;
+                       putchar(c);
+               }
+       }
+
+       fprintf(stderr, "decoded (raw) size: %d bytes\n", rawbytes);
+       return 0;
+}