From 62e3bd554b2b01c3210c2b075b85860ff2248139 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 5 Sep 2018 01:24:29 -0400 Subject: Add glitch -x and -y --- bin/glitch.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'bin/glitch.c') diff --git a/bin/glitch.c b/bin/glitch.c index b8251df7..a780fb5c 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