summary refs log tree commit diff
path: root/bin/glitch.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-09-05 01:24:29 -0400
committerJune McEnroe <june@causal.agency>2018-09-05 01:24:29 -0400
commit62e3bd554b2b01c3210c2b075b85860ff2248139 (patch)
tree65f444d63693f245b2bf76e976cb257ccf25ee5a /bin/glitch.c
parentAdd glitch -i to README (diff)
downloadsrc-62e3bd554b2b01c3210c2b075b85860ff2248139.tar.gz
src-62e3bd554b2b01c3210c2b075b85860ff2248139.zip
Add glitch -x and -y
Diffstat (limited to 'bin/glitch.c')
-rw-r--r--bin/glitch.c27
1 files changed, 26 insertions, 1 deletions
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;
 		}
 	}