Introduction
Introduction Statistics Contact Development Disclaimer Help
Add blind-apply-palette and blind-colour-ciexyz always outputs all three parame…
git clone git://git.suckless.org/blind
Log
Files
Refs
README
LICENSE
---
commit 1fdf6986e7bc23e2bdf4b2b7973652a2cb2dd3b7
parent 975a02fba76fce7526278ea09a27cc0aae608d30
Author: Mattias Andrée <[email protected]>
Date: Wed, 12 Jul 2017 03:40:51 +0200
Add blind-apply-palette and blind-colour-ciexyz always outputs all three parame…
Signed-off-by: Mattias Andrée <[email protected]>
Diffstat:
M Makefile | 1 +
A man/blind-apply-palette.1 | 23 +++++++++++++++++++++++
M man/blind-get-colours.1 | 1 +
M man/blind-repeat-tessellation.1 | 3 ++-
A src/blind-apply-palette.c | 107 +++++++++++++++++++++++++++++…
M src/blind-chroma-key.c | 1 +
M src/blind-colour-ciexyz.c | 14 ++++++++++----
7 files changed, 145 insertions(+), 5 deletions(-)
---
diff --git a/Makefile b/Makefile
@@ -2,6 +2,7 @@ CONFIGFILE = config.mk
include $(CONFIGFILE)
BIN =\
+ blind-apply-palette\
blind-arithm\
blind-cat-cols\
blind-cat-rows\
diff --git a/man/blind-apply-palette.1 b/man/blind-apply-palette.1
@@ -0,0 +1,23 @@
+.TH BLIND-APPLY-PALETTE 1 blind
+.SH NAME
+blind-apply-palette - Apply a colour palette to a video
+.SH SYNOPSIS
+.B blind-apply-palette
+.I palette-stream
+.SH DESCRIPTION
+.B blind-apply-palette
+reads a video from stdin and video from
+.IR palette-stream .
+For each frame, the colours in the video from
+stdin are replaces with the closest match colour
+from the same from in the video in
+.IR palette-stream .
+The resulting video is printed to stdout.
+.SH SEE ALSO
+.BR blind (7),
+.BR blind-repeat (1),
+.BR blind-get-colours (1),
+.BR blind-repeat-tessellation (1)
+.SH AUTHORS
+Mattias Andrée
+.RI < [email protected] >
diff --git a/man/blind-get-colours.1 b/man/blind-get-colours.1
@@ -9,6 +9,7 @@ reads a video from stdin and prints a single-frame
video to stdout contain all colours from the video.
.SH SEE ALSO
.BR blind (7),
+.BR blind-apply-palette (1),
.BR blind-repeat-tessellation (1)
.SH AUTHORS
Mattias Andrée
diff --git a/man/blind-repeat-tessellation.1 b/man/blind-repeat-tessellation.1
@@ -29,7 +29,8 @@ the video from stdin into memory. A frame requires 32
bytes per pixel it contains.
.SH SEE ALSO
.BR blind (7),
-.BR blind-get-colours (1)
+.BR blind-get-colours (1),
+.BR blind-apply-palette (1)
.SH AUTHORS
Mattias Andrée
.RI < [email protected] >
diff --git a/src/blind-apply-palette.c b/src/blind-apply-palette.c
@@ -0,0 +1,107 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+USAGE("palette-stream")
+
+
+static double (*compare)(double x1, double y1, double z1, double a1, double x2…
+/* TODO add more formulae: https://en.wikipedia.org/wiki/Color_difference */
+
+
+static double
+distance_xyz(double x1, double y1, double z1, double a1, double x2, double y2,…
+{
+ x2 -= x1, x2 *= x2;
+ y2 -= y1, y2 *= y2;
+ z2 -= z1, z2 *= z2;
+ a2 -= a1, a2 *= a2;
+ return sqrt(x2 + y2 + z2 + a2);
+}
+
+
+#define PROCESS(TYPE, SUFFIX)\
+ static void\
+ process_##SUFFIX(struct stream *stream, struct stream *palette, char *…
+ {\
+ size_t i, j, n, m;\
+ size_t palsiz = palette->width * palette->height;\
+ size_t best = 0;\
+ TYPE x, y, z, a, lx = 0, ly = 0, lz = 0, la = 0;\
+ TYPE cx, cy, cz, ca;\
+ double distance, best_distance = 0;\
+ while (eread_frame(palette, pal)) {\
+ m = stream->frame_size;\
+ do {\
+ n = MIN(stream->ptr, m) / stream->pixel_size;\
+ for (i = 0; i < n; i++) {\
+ x = ((TYPE *)(stream->buf + i * stream…
+ y = ((TYPE *)(stream->buf + i * stream…
+ z = ((TYPE *)(stream->buf + i * stream…
+ a = ((TYPE *)(stream->buf + i * stream…
+ if ((!i && m == stream->frame_size) ||…
+ for (j = 0; j < palsiz; j++) {\
+ cx = ((TYPE *)(pal + j…
+ cy = ((TYPE *)(pal + j…
+ cz = ((TYPE *)(pal + j…
+ ca = ((TYPE *)(pal + j…
+ distance = compare((do…
+ (do…
+ if (!j || distance < b…
+ best_distance …
+ best = j;\
+ }\
+ }\
+ lx = x, ly = y, lz = z, la = a…
+ }\
+ memcpy(stream->buf + i * stream->pixel…
+ pal + best * stream->pixel_size…
+ stream->pixel_size);\
+ }\
+ m -= n *= stream->pixel_size;\
+ ewriteall(STDOUT_FILENO, stream->buf, n, "<std…
+ memmove(stream->buf, stream->buf + n, stream->…
+ } while (m && eread_stream(stream, SIZE_MAX));\
+ if (m)\
+ eprintf("%s: incomplete frame\n", stream->file…
+ }\
+ }
+
+PROCESS(double, lf)
+PROCESS(float, f)
+
+
+int
+main(int argc, char *argv[])
+{
+ struct stream stream, palette;
+ void (*process)(struct stream *stream, struct stream *palette, char *p…
+ char *pal;
+
+ compare = distance_xyz;
+
+ UNOFLAGS(argc != 1);
+
+ eopen_stream(&stream, NULL);
+ eopen_stream(&palette, argv[0]);
+
+ if (!strcmp(stream.pixfmt, "xyza"))
+ process = process_lf;
+ else if (!strcmp(stream.pixfmt, "xyza f"))
+ process = process_f;
+ else
+ eprintf("pixel format %s is not supported, try xyza\n", stream…
+
+ if (strcmp(stream.pixfmt, palette.pixfmt))
+ eprintf("videos use incompatible pixel formats\n");
+
+ echeck_dimensions(&stream, WIDTH | HEIGHT, NULL);
+ echeck_dimensions(&palette, WIDTH | HEIGHT, NULL);
+ pal = emalloc(palette.frame_size);
+ fprint_stream_head(stdout, &stream);
+ efflush(stdout, "<stdout>");
+
+ process(&stream, &palette, pal);
+
+ free(pal);
+ return 0;
+}
diff --git a/src/blind-chroma-key.c b/src/blind-chroma-key.c
@@ -27,6 +27,7 @@ USAGE("key-stream")
z = z1 - keyxyza[6];\
a2 = keyxyza[7];\
variance2 = x * x + y * y + z * z;\
+ /* TODO add more formulae: https://en.wikipedi…
if (a2 > a1) {\
a1 = 1 - a1;\
a2 = 1 - a2;\
diff --git a/src/blind-colour-ciexyz.c b/src/blind-colour-ciexyz.c
@@ -6,14 +6,20 @@ USAGE("(X Y Z | Y)")
int
main(int argc, char *argv[])
{
+ double X, Y, Z;
+
UNOFLAGS(0);
- if (argc == 1)
- printf("%s\n", argv[0]);
- else if (argc == 3)
+ if (argc == 1) {
+ Y = etolf_arg("the Y value", argv[0]);
+ X = Y * D65_XYZ_X;
+ Z = Y * D65_XYZ_Z;
+ printf("%lf %lf %lf\n", X, Y, Z);
+ } else if (argc == 3) {
printf("%s %s %s\n", argv[0], argv[1], argv[2]);
- else
+ } else {
usage();
+ }
efshut(stdout, "<stdout>");
return 0;
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.