[wiki] [sites] Add farbfeld examples || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 12 Jan 2016 22:42:27 +0100

commit 0587d71a70e20ae12730e52747d8a79b038d4e60
Author: FRIGN <dev_AT_frign.de>
Date: Tue Jan 12 22:42:21 2016 +0100

    Add farbfeld examples

diff --git a/tools.suckless.org/farbfeld/index.md b/tools.suckless.org/farbfeld/index.md
index 9193e75..b6ad6ce 100644
--- a/tools.suckless.org/farbfeld/index.md
+++ b/tools.suckless.org/farbfeld/index.md
_AT_@ -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
new file mode 100644
index 0000000..2e6f67a
--- /dev/null
+++ b/tools.suckless.org/farbfeld/invert.c
_AT_@ -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
", argv[0]);
+ return 1;
+ }
+
+ if (fread(hdr, 1, sizeof(hdr), stdin) != sizeof(hdr)) {
+ fprintf(stderr, "incomplete header
");
+ return 1;
+ }
+ if (memcmp("farbfeld", hdr, strlen("farbfeld"))) {
+ fprintf(stderr, "invalid magic
");
+ 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
");
+ 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
");
+ 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
");
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
Received on Tue Jan 12 2016 - 22:42:27 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 12 2016 - 22:48:13 CET