diff options
author | yenatch <yenatch@gmail.com> | 2015-02-11 14:22:50 -0800 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2015-02-11 14:22:50 -0800 |
commit | 68eae566eca944bc116b5a1301ff63aba8a35c99 (patch) | |
tree | bd4beea69113749563aeb87985523b7ec49f85be | |
parent | fb23f2754c9b94eac871a33621ce43fa71b53170 (diff) | |
parent | 2c2ceb74567664379cebfb121e0db929718a4ba2 (diff) |
Merge remote-tracking branch 'origin/master'
Conflicts:
pokemontools/gfx.py
-rw-r--r-- | pokemontools/gfx.py | 2 | ||||
-rw-r--r-- | redtools/redrle.c | 74 |
2 files changed, 59 insertions, 17 deletions
diff --git a/pokemontools/gfx.py b/pokemontools/gfx.py index b2244a5..53fc039 100644 --- a/pokemontools/gfx.py +++ b/pokemontools/gfx.py @@ -736,7 +736,7 @@ def read_filename_arguments(filename, yaml_filename = os.path.join(config.path, 't': 'tile_padding', } # Filename arguments override yaml. - arguments = os.path.splitext(filename)[0].split('.')[1:] + arguments = os.path.splitext(filename)[0].lstrip('.').split('.')[1:] for argument in arguments: # Check for integer arguments first (i.e. "w128"). diff --git a/redtools/redrle.c b/redtools/redrle.c index e753b3a..b8ec529 100644 --- a/redtools/redrle.c +++ b/redtools/redrle.c @@ -1,5 +1,5 @@ /* - * Copyright © 2011 IIMarckus <iimarckus@gmail.com> + * Copyright © 2011, 2014 IIMarckus <iimarckus@gmail.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,27 +23,50 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> void usage() { - fprintf(stderr, "Usage: redrle [-d] infile outfile\n"); + fprintf(stderr, "Usage: redrle [-dr] infile outfile\n"); exit(1); } +void +squash(int threshold, FILE *f, int lastbyte, int *count, int *xpos) +{ + fputc(lastbyte << 4 | threshold, f); + *xpos += threshold; + *xpos %= 20; + *count -= threshold; +} + int main(int argc, char *argv[]) { FILE *infile, *outfile; + int ch; bool d = false; /* compress or decompress flag */ + bool rows = false; /* compress individual rows or entire file */ + + while ((ch = getopt(argc, argv, "dr")) != -1) { + switch(ch) { + case 'd': + d = true; + break; + case 'r': + rows = true; + break; + default: + usage(); + /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; - if (argc < 3 || argc > 4) + if (argc < 2) { usage(); - - if (strcmp(argv[1], "-d") == 0) { - if (argc != 4) - usage(); - d = true; } infile = fopen(argv[argc - 2], "rb"); @@ -80,17 +103,27 @@ main(int argc, char *argv[]) fputc(byte, outfile); } } else { /* compress */ - int byte, count = 0, lastbyte = 0; + int byte, count = 0, lastbyte = 0, xpos = 0; for (;;) { byte = fgetc(infile); if (feof(infile)) { while (count > 0xF) { - count -= 0xF; - fputc(lastbyte << 4 | 0xF, outfile); + if (rows && 20 - xpos <= 0xF) { + squash(20 - xpos, outfile, + lastbyte, &count, &xpos); + continue; + } + squash(0xF, outfile, lastbyte, &count, + &xpos); } if (count != 0) { - fputc(lastbyte << 4 | count, outfile); + if (rows && 20 - xpos < count) { + squash(20 - xpos, outfile, + lastbyte, &count, &xpos); + } + squash(count, outfile, lastbyte, + &count, &xpos); } break; } @@ -105,12 +138,21 @@ main(int argc, char *argv[]) ++count; else { while (count > 0xF) { - count -= 0xF; - fputc(lastbyte << 4 | 0xF, outfile); + if (rows && 20 - xpos <= 0xF) { + squash(20 - xpos, outfile, + lastbyte, &count, &xpos); + continue; + } + squash(0xF, outfile, lastbyte, &count, + &xpos); } if (count != 0) { - fputc(lastbyte << 4 | count, outfile); - count = 0; + if (rows && 20 - xpos < count) { + squash(20 - xpos, outfile, + lastbyte, &count, &xpos); + } + squash(count, outfile, lastbyte, + &count, &xpos); } lastbyte = byte; |