summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-03-02 18:00:36 -0500
committerJune McEnroe <june@causal.agency>2018-03-02 18:00:36 -0500
commitd9c45d62a19d9bbaf138b74bde0817de4903db95 (patch)
treefe2dc1b3790d2b6302d7295097082bf1c8d55640 /bin
parentTake filter patterns in glitch (diff)
downloadsrc-d9c45d62a19d9bbaf138b74bde0817de4903db95.tar.gz
src-d9c45d62a19d9bbaf138b74bde0817de4903db95.zip
Add -f -r options to glitch
Diffstat (limited to '')
-rw-r--r--bin/glitch.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/bin/glitch.c b/bin/glitch.c
index 37d93a70..22d82c13 100644
--- a/bin/glitch.c
+++ b/bin/glitch.c
@@ -265,6 +265,8 @@ enum PACKED Filter {
 
 static struct {
     bool brokenPaeth;
+    bool filt;
+    bool recon;
     uint8_t declareFilter;
     uint8_t applyFilter;
     enum Filter declareFilters[255];
@@ -347,7 +349,11 @@ static struct Bytes origBytes(uint32_t y, size_t i) {
 static void reconData(void) {
     for (uint32_t y = 0; y < header.height; ++y) {
         for (size_t i = 0; i < lineSize(); ++i) {
-            lines[y]->data[i] = recon(lines[y]->type, origBytes(y, i));
+            if (options.filt) {
+                lines[y]->data[i] = filt(lines[y]->type, origBytes(y, i));
+            } else {
+                lines[y]->data[i] = recon(lines[y]->type, origBytes(y, i));
+            }
         }
         lines[y]->type = NONE;
     }
@@ -360,7 +366,11 @@ static void filterData(void) {
         enum Filter minType = NONE;
         for (enum Filter type = NONE; type < FILTER_COUNT; ++type) {
             for (size_t i = 0; i < lineSize(); ++i) {
-                filter[type][i] = filt(type, origBytes(y, i));
+                if (options.recon) {
+                    filter[type][i] = recon(type, origBytes(y, i));
+                } else {
+                    filter[type][i] = filt(type, origBytes(y, i));
+                }
                 heuristic[type] += abs((int8_t)filter[type][i]);
             }
             if (heuristic[type] < heuristic[minType]) minType = type;
@@ -447,7 +457,7 @@ int main(int argc, char *argv[]) {
     char *output = NULL;
 
     int opt;
-    while (0 < (opt = getopt(argc, argv, "a:cd:o:p"))) {
+    while (0 < (opt = getopt(argc, argv, "a:cd:fo:pr"))) {
         switch (opt) {
             case 'a': {
                 options.applyFilter = parseFilters(options.applyFilters, optarg);
@@ -456,8 +466,10 @@ int main(int argc, char *argv[]) {
             case 'd': {
                 options.declareFilter = parseFilters(options.declareFilters, optarg);
             } break;
+            case 'f': options.filt = true; break;
             case 'o': output = optarg; break;
             case 'p': options.brokenPaeth = true; break;
+            case 'r': options.recon = true; break;
             default: return EX_USAGE;
         }
     }