SameBoy/BootROMs/logo-compress.c

63 lines
1.1 KiB
C
Raw Normal View History

#include <assert.h>
#include <inttypes.h>
2019-06-22 15:16:55 +00:00
#include <stdio.h>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
2019-06-14 11:34:02 +00:00
void pair(size_t count, uint8_t byte)
{
static size_t unique_count = 0;
static uint8_t unique_data[15];
if (count == 1) {
unique_data[unique_count++] = byte;
assert(unique_count <= 15);
2019-06-14 11:34:02 +00:00
}
else {
assert(count <= 15);
uint8_t control = (count << 4) | unique_count;
putchar(control);
for (size_t i = 0; i < unique_count; i++) {
putchar(unique_data[i]);
}
if (count != 0) {
putchar(byte);
2019-06-14 11:34:02 +00:00
}
else {
assert(control == 0);
}
unique_count = 0;
}
}
2019-06-14 11:34:02 +00:00
int main(int argc, char *argv[])
{
size_t count = 1;
uint8_t byte = getchar();
int new;
2019-06-22 15:16:55 +00:00
size_t position = 0;
#ifdef _WIN32
_setmode(0,_O_BINARY);
_setmode(1,_O_BINARY);
#endif
while ((new = getchar()) != EOF) {
if (byte == new) {
count++;
2019-06-14 11:34:02 +00:00
}
else {
pair(count, byte);
byte = new;
count = 1;
}
}
pair(count, byte);
pair(0, 0);
}