From 014e0a98cf101062a4ba1aa066b763272b889ac7 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 5 Sep 2018 01:38:13 -0400 Subject: Simplify glitch -x -y to just zero --- bin/README | 4 ++-- bin/glitch.c | 28 ++++++++++------------------ 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'bin') diff --git a/bin/README b/bin/README index c1b454a6..53c170c5 100644 --- a/bin/README +++ b/bin/README @@ -41,8 +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 + -x zero first pixels after filtering + -y zero first scanline after filtering hnel diff --git a/bin/glitch.c b/bin/glitch.c index 56590f0b..b7b26213 100644 --- a/bin/glitch.c +++ b/bin/glitch.c @@ -278,8 +278,8 @@ static struct { uint8_t applyFilter; enum Filter declareFilters[255]; enum Filter applyFilters[255]; - bool swapX; - bool swapY; + bool zeroX; + bool zeroY; bool invert; bool mirror; } options; @@ -402,23 +402,15 @@ static void filterData(void) { } } -static void swapX(void) { +static void zeroX(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); + memset(lines[y]->data, 0, 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 zeroY(void) { + memset(lines[0]->data, 0, lineSize()); } static void invert(void) { @@ -458,8 +450,8 @@ static void glitch(const char *inPath, const char *outPath) { scanlines(); reconData(); filterData(); - if (options.swapX) swapX(); - if (options.swapY) swapY(); + if (options.zeroX) zeroX(); + if (options.zeroY) zeroY(); if (options.invert) invert(); if (options.mirror) mirror(); free(lines); @@ -522,8 +514,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; case 'x': options.zeroX = true; + break; case 'y': options.zeroY = true; break; default: return EX_USAGE; } } -- cgit 1.4.1