RLE blitter, plus RLE encoding and decoding tools
[bootsplash] / rle / unrle.c
1 #include <stdio.h>
2
3 int main(void)
4 {
5         int c, count, rawbytes = 0;
6
7         printf("P5\n320 200\n255\n");
8
9         while((c = getchar()) != -1) {
10                 if(c & 0x80) {
11                         count = c & 0x7f;
12                         if((c = getchar()) == -1) {
13                                 fprintf(stderr, "Unexpected EOF while decoding RLE data\n");
14                                 return 1;
15                         }
16                         rawbytes += count;
17                         while(count--) putchar(c);
18                 } else {
19                         rawbytes++;
20                         putchar(c);
21                 }
22         }
23
24         fprintf(stderr, "decoded (raw) size: %d bytes\n", rawbytes);
25         return 0;
26 }