From 551aabfcf03e62c98d88e559fdf9d26fb0ffcd7f Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 5 Sep 2018 01:24:29 -0400 Subject: Add glitch -x and -y --- bin/README | 2 ++ bin/glitch.c | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/bin/README b/bin/README index 8695359f..c1b454a6 100644 --- a/bin/README +++ b/bin/README @@ -41,6 +41,8 @@ PNG glitcher based on pngo. -a LIST apply pattern of comma-separated filters -i invert after filtering -m mirror scanlines after filtering + -y swap first and last scanline after filtering + -x swap first and last pixels of scanlines after filtering hnel diff --git a/bin/glitch.c b/bin/glitch.c index de52eb26..56590f0b 100644 --- a/bin/glitch.c +++ b/bin/glitch.c @@ -278,6 +278,8 @@ static struct { uint8_t applyFilter; enum Filter declareFilters[255]; enum Filter applyFilters[255]; + bool swapX; + bool swapY; bool invert; bool mirror; } options; @@ -400,6 +402,25 @@ static void filterData(void) { } } +static void swapX(void) { + size_t pixelSize = lineSize() / header.width; + uint32_t last = header.width - 1; + for (uint32_t y = 0; y < header.height; ++y) { + uint8_t pixel[pixelSize]; + memcpy(pixel, lines[y]->data, pixelSize); + memcpy(lines[y]->data, &lines[y]->data[pixelSize * last], pixelSize); + memcpy(&lines[y]->data[pixelSize * last], pixel, pixelSize); + } +} + +static void swapY(void) { + uint8_t line[lineSize()]; + uint32_t last = header.height - 1; + memcpy(line, lines[0]->data, lineSize()); + memcpy(lines[0]->data, lines[last]->data, lineSize()); + memcpy(lines[last]->data, line, lineSize()); +} + static void invert(void) { for (uint32_t y = 0; y < header.height; ++y) { for (size_t i = 0; i < lineSize(); ++i) { @@ -437,6 +458,8 @@ static void glitch(const char *inPath, const char *outPath) { scanlines(); reconData(); filterData(); + if (options.swapX) swapX(); + if (options.swapY) swapY(); if (options.invert) invert(); if (options.mirror) mirror(); free(lines); @@ -486,7 +509,7 @@ int main(int argc, char *argv[]) { char *output = NULL; int opt; - while (0 < (opt = getopt(argc, argv, "a:cd:fimo:pr"))) { + while (0 < (opt = getopt(argc, argv, "a:cd:fimo:prxy"))) { switch (opt) { break; case 'a': options.applyFilter = parseFilters(options.applyFilters, optarg); @@ -499,6 +522,8 @@ int main(int argc, char *argv[]) { break; case 'o': output = optarg; break; case 'p': options.brokenPaeth = true; break; case 'r': options.recon = true; + break; case 'x': options.swapX = true; + break; case 'y': options.swapY = true; break; default: return EX_USAGE; } } -- cgit 1.4.1