summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/README2
-rw-r--r--bin/glitch.c27
2 files changed, 28 insertions, 1 deletions
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 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;
 		}
 	}