From 728ddc4d593fae288f5844c942ffe3868b06bbd0 Mon Sep 17 00:00:00 2001 From: femsci Date: Tue, 15 Nov 2022 21:14:09 +0100 Subject: [PATCH] Add trans filter --- src/filter.c | 25 +++++++++++++++++++++++++ src/main.c | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/src/filter.c b/src/filter.c index 720f4bb..52600d2 100644 --- a/src/filter.c +++ b/src/filter.c @@ -29,6 +29,7 @@ static void filter_crop(context_t *); static void filter_rainbow(context_t *); +static void filter_trans(context_t *); static void filter_metal(context_t *); static void filter_flip(context_t *); static void filter_flop(context_t *); @@ -47,6 +48,7 @@ const lookup[] = { { "crop", filter_crop, "crop unused blanks" }, { "rainbow", filter_rainbow, "add a rainbow colour effect" }, + { "trans", filter_trans, "trans rights uwu~"}, { "metal", filter_metal, "add a metallic colour effect" }, { "flip", filter_flip, "flip horizontally" }, { "flop", filter_flop, "flip vertically" }, @@ -211,6 +213,29 @@ static void filter_rainbow(context_t *cx) } } +static void filter_trans(context_t *cx) +{ + static unsigned char const colors[] = + { + CACA_LIGHTCYAN, CACA_LIGHTRED, CACA_WHITE, CACA_LIGHTRED, CACA_LIGHTCYAN + }; + unsigned int x, y, w, h; + + w = caca_get_canvas_width(cx->torender); + h = caca_get_canvas_height(cx->torender); + + for(x = 0; x < w; x++) + for(y = 0; y < h; y++) + { + unsigned long int ch = caca_get_char(cx->torender, x, y); + if(ch != (unsigned char)' ') + { + caca_set_color_ansi(cx->torender, colors[(y - 2) % 5], CACA_TRANSPARENT); + caca_put_char(cx->torender, x, y, ch); + } + } +} + static void filter_flip(context_t *cx) { caca_flip(cx->torender); diff --git a/src/main.c b/src/main.c index 31926aa..4b91387 100644 --- a/src/main.c +++ b/src/main.c @@ -66,6 +66,7 @@ int main(int argc, char *argv[]) { "termwidth", 0, NULL, 't' }, { "filter", 1, NULL, 'F' }, { "gay", 0, NULL, 130 }, + { "trans", 0, NULL, 160 }, { "metal", 0, NULL, 131 }, { "rainbow", 0, NULL, 132 }, { "export", 1, NULL, 'E' }, @@ -114,6 +115,9 @@ int main(int argc, char *argv[]) case 132: /* --rainbow */ filter_add(cx, "rainbow"); break; + case 160: + filter_add(cx, "trans"); + break; case 'w': /* --width */ cx->term_width = atoi(caca_optarg); break; @@ -217,6 +221,7 @@ int main(int argc, char *argv[]) " -t, --termwidth adapt to terminal's width\n" \ " -F, --filter apply one or several filters to the text\n" \ " -F, --filter list list available filters\n" \ + " --trans traaaaaaaa filter (same as -F trans)\n" \ " --rainbow rainbow filter (same as -F rainbow)\n" \ " --metal metal filter (same as -F metal)\n" \ " -E, --export select export format\n" \