From 0c5e25abd8d5511aa476cc6af0bbc3d9dcc15695 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 2 Mar 2018 17:26:15 -0500 Subject: Take filter patterns in glitch --- bin/glitch.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/glitch.c b/bin/glitch.c index 8ce3905d..37d93a70 100644 --- a/bin/glitch.c +++ b/bin/glitch.c @@ -265,10 +265,10 @@ enum PACKED Filter { static struct { bool brokenPaeth; - bool forceDeclareFilter; - bool forceApplyFilter; - enum Filter declareFilter; - enum Filter applyFilter; + uint8_t declareFilter; + uint8_t applyFilter; + enum Filter declareFilters[255]; + enum Filter applyFilters[255]; } options; struct Bytes { @@ -366,14 +366,15 @@ static void filterData(void) { if (heuristic[type] < heuristic[minType]) minType = type; } - if (options.forceDeclareFilter) { - lines[y]->type = options.declareFilter; + if (options.declareFilter) { + lines[y]->type = options.declareFilters[y % options.declareFilter]; } else { lines[y]->type = minType; } - if (options.forceApplyFilter) { - memcpy(lines[y]->data, filter[options.applyFilter], lineSize()); + if (options.applyFilter) { + enum Filter type = options.applyFilters[y % options.applyFilter]; + memcpy(lines[y]->data, filter[type], lineSize()); } else { memcpy(lines[y]->data, filter[minType], lineSize()); } @@ -421,7 +422,7 @@ static void glitch(const char *inPath, const char *outPath) { if (error) err(EX_IOERR, "%s", path); } -enum Filter parseFilter(const char *s) { +static enum Filter parseFilter(const char *s) { switch (s[0]) { case 'N': case 'n': return NONE; case 'S': case 's': return SUB; @@ -432,6 +433,15 @@ enum Filter parseFilter(const char *s) { } } +static uint8_t parseFilters(enum Filter *filters, const char *s) { + uint8_t len = 0; + do { + filters[len++] = parseFilter(s); + s = strchr(s, ','); + } while (s++); + return len; +} + int main(int argc, char *argv[]) { bool stdio = false; char *output = NULL; @@ -440,13 +450,11 @@ int main(int argc, char *argv[]) { while (0 < (opt = getopt(argc, argv, "a:cd:o:p"))) { switch (opt) { case 'a': { - options.forceApplyFilter = true; - options.applyFilter = parseFilter(optarg); + options.applyFilter = parseFilters(options.applyFilters, optarg); } break; case 'c': stdio = true; break; case 'd': { - options.forceDeclareFilter = true; - options.declareFilter = parseFilter(optarg); + options.declareFilter = parseFilters(options.declareFilters, optarg); } break; case 'o': output = optarg; break; case 'p': options.brokenPaeth = true; break; -- cgit 1.4.1 29cc361b1e7e8389d08&follow=1'>Add The Fated SkyJune McEnroe 2019-08-28Factor out cap_rights_limit error handlingJune McEnroe 2019-08-27Cast %lc parameter to wint_tJune McEnroe I hadn't realized that's what type %lc takes and suddenly started seeing warnings about it for some reason. 2019-08-27Remove host thursdayJune McEnroe RIP. 2019-08-22Add cards to causal.agencyJune McEnroe 2019-08-20Add Record of a Spaceborn FewJune McEnroe 2019-08-13Add The Calculating StarsJune McEnroe 2019-08-12Make dtch one command, add sinkingJune McEnroe 2019-08-03Add ImagoJune McEnroe 2019-07-29Add KindredJune McEnroe 2019-07-27Clean up home filesJune McEnroe 2019-07-27Fix shell script style in ~/.local/binJune McEnroe 2019-07-27Shell script style passJune McEnroe 2019-07-27Add c11.pdfJune McEnroe 2019-07-27Move pdf script to MakefileJune McEnroe 2019-07-27Update macOS neovim to 0.3.8June McEnroe Which somehow still doesn't include my man fix. 2019-07-27Rewrite port makefiles consistentlyJune McEnroe 2019-07-27Rewrite Makefile once more with more organizationJune McEnroe 2019-07-27Reference png.h in bin.7June McEnroe 2019-07-27Revert "Use scheme to style HTMLs"June McEnroe This reverts commit 4b7d5161a30645b0a23691687ef1aafdda62d3bb. I don't know why but I don't like it. 2019-07-27Remove scheme text linkJune McEnroe No standard base64 encoder so no way to maintain it. 2019-07-26Update Dark.terminalJune McEnroe Why are the blobs so much bigger now? 2019-07-26Lighten dark whiteJune McEnroe 2019-07-25Add png.3 man pageJune McEnroe 2019-07-25Use scheme to style HTMLsJune McEnroe 2019-07-25Don't match comments in strings in makeJune McEnroe 2019-07-25Generate index.html with links from bin.7June McEnroe 2019-07-24Warn when date has changedJune McEnroe 2019-07-24Add whenJune McEnroe When? Now. 2019-07-24Remove histedit from bitJune McEnroe