sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 0587d71a70e20ae12730e52747d8a79b038d4e60
parent 188b1c89c0c1dc76887d8d521ebe59894f684a34
Author: FRIGN <dev@frign.de>
Date:   Tue, 12 Jan 2016 22:42:21 +0100

Add farbfeld examples

Diffstat:
Mtools.suckless.org/farbfeld/index.md | 27+++++++++++++++++++++++++++
Atools.suckless.org/farbfeld/invert.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/farbfeld/index.md b/tools.suckless.org/farbfeld/index.md @@ -13,6 +13,33 @@ It has the following format: The RGB-data should be sRGB for best interoperability. +Examples +-------- + +Convert image.png to a farbfeld, run it through a filter and write the +result to image-filtered.png: + + png2ff < image.png | filter | ff2png > image-filtered.png + +[Here](invert.c) you can find an example for such a filter which inverts +the colors. Notice that there are no dependencies on external libraries. +A hypothetical farbfeld-library would hardly exceed the size of +the given filter example. + + +Store image.png as a compressed farbfeld: + + png2ff < image.png | bzip2 > image.ff.bz2 + +Access a compressed farbfeld as a png: + + bunzip2 < image.ff.bz2 | ff2png {> image.png, | feh -, ...} + +Handle arbitrary image data using 2ff(1), which falls +back to imagemagick's convert(1) for unknown image types: + + 2ff < image | filter | ff2png > image-filtered.png + FAQ --- diff --git a/tools.suckless.org/farbfeld/invert.c b/tools.suckless.org/farbfeld/invert.c @@ -0,0 +1,68 @@ +/* + * Copy me if you can. + * by FRIGN + */ +#include <arpa/inet.h> + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int +main(int argc, char *argv[]) +{ + uint32_t width, height, i, j, k; + uint16_t rgba[4]; + uint8_t hdr[strlen("farbfeld") + 2 * sizeof(uint32_t)]; + + if (argc > 1) { + fprintf(stderr, "usage: %s\n", argv[0]); + return 1; + } + + if (fread(hdr, 1, sizeof(hdr), stdin) != sizeof(hdr)) { + fprintf(stderr, "incomplete header\n"); + return 1; + } + if (memcmp("farbfeld", hdr, strlen("farbfeld"))) { + fprintf(stderr, "invalid magic\n"); + return 1; + } + width = ntohl(*((uint32_t *)(hdr + 8))); + height = ntohl(*((uint32_t *)(hdr + 12))); + + if (fwrite(hdr, 1, sizeof(hdr), stdout) != sizeof(hdr)) { + fprintf(stderr, "write error\n"); + return 1; + } + + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + if (fread(rgba, sizeof(uint16_t), 4, + stdin) != 4) { + fprintf(stderr, "unexpected EOF\n"); + return 1; + } + for (k = 0; k < 4; k++) { + rgba[k] = ntohs(rgba[k]); + } + + /* invert colors */ + rgba[0] = 65535 - rgba[0]; + rgba[1] = 65535 - rgba[1]; + rgba[2] = 65535 - rgba[2]; + + for (k = 0; k < 4; k++) { + rgba[k] = htons(rgba[k]); + } + if (fwrite(rgba, sizeof(uint16_t), 4, + stdout) != 4) { + fprintf(stderr, "write error\n"); + return 1; + } + } + } + + return 0; +}