aboutsummaryrefslogtreecommitdiffstats
path: root/src/vu-stack.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-12 00:13:17 +0100
committerMattias Andrée <maandree@kth.se>2017-01-12 00:13:17 +0100
commit45ac53d25ba0e5d5255789d7665057e404dc3269 (patch)
tree55ccb71255871c4b6d5523b4d8676565f15b74c1 /src/vu-stack.c
parentFix writeall + vu-split: reuse code (diff)
downloadblind-45ac53d25ba0e5d5255789d7665057e404dc3269.tar.gz
blind-45ac53d25ba0e5d5255789d7665057e404dc3269.tar.bz2
blind-45ac53d25ba0e5d5255789d7665057e404dc3269.tar.xz
cleanup
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/vu-stack.c121
1 files changed, 32 insertions, 89 deletions
diff --git a/src/vu-stack.c b/src/vu-stack.c
index 3647c12..a03fd91 100644
--- a/src/vu-stack.c
+++ b/src/vu-stack.c
@@ -9,71 +9,44 @@
USAGE("[-b] bottom-stream ... top-stream")
-static void
-process_xyza(struct stream *streams, size_t n_streams, size_t n)
-{
- double x1, y1, z1, a1;
- double x2, y2, z2, a2;
- size_t i, j;
- for (i = 0; i < n; i += streams->pixel_size) {
- x1 = ((double *)(streams[0].buf + i))[0];
- y1 = ((double *)(streams[0].buf + i))[1];
- z1 = ((double *)(streams[0].buf + i))[2];
- a1 = ((double *)(streams[0].buf + i))[3];
- for (j = 1; j < n_streams; j++) {
- x2 = ((double *)(streams[j].buf + i))[0];
- y2 = ((double *)(streams[j].buf + i))[1];
- z2 = ((double *)(streams[j].buf + i))[2];
- a2 = ((double *)(streams[j].buf + i))[3];
- x1 = x1 * a1 * (1 - a2) + x2 * a2;
- y1 = y1 * a1 * (1 - a2) + y2 * a2;
- z1 = z1 * a1 * (1 - a2) + z2 * a2;
- a1 = a1 * (1 - a2) + a2;
- }
- ((double *)(streams[0].buf + i))[0] = x1;
- ((double *)(streams[0].buf + i))[1] = y1;
- ((double *)(streams[0].buf + i))[2] = z1;
- ((double *)(streams[0].buf + i))[3] = a1;
- }
-}
+#define PROCESS_LINEAR_3CH_ALPHA(TYPE, BLEND)\
+ do {\
+ TYPE x1, y1, z1, a1;\
+ TYPE x2, y2, z2, a2;\
+ size_t i, j;\
+ for (i = 0; i < n; i += streams->pixel_size) {\
+ x1 = ((TYPE *)(streams[0].buf + i))[0];\
+ y1 = ((TYPE *)(streams[0].buf + i))[1];\
+ z1 = ((TYPE *)(streams[0].buf + i))[2];\
+ a1 = ((TYPE *)(streams[0].buf + i))[3];\
+ for (j = 1; j < n_streams; j++) {\
+ x2 = ((TYPE *)(streams[j].buf + i))[0];\
+ y2 = ((TYPE *)(streams[j].buf + i))[1];\
+ z2 = ((TYPE *)(streams[j].buf + i))[2];\
+ a2 = ((TYPE *)(streams[j].buf + i))[3];\
+ if (BLEND)\
+ a2 /= j + 1;\
+ x1 = x1 * a1 * (1 - a2) + x2 * a2;\
+ y1 = y1 * a1 * (1 - a2) + y2 * a2;\
+ z1 = z1 * a1 * (1 - a2) + z2 * a2;\
+ a1 = a1 * (1 - a2) + a2;\
+ }\
+ ((TYPE *)(streams[0].buf + i))[0] = x1;\
+ ((TYPE *)(streams[0].buf + i))[1] = y1;\
+ ((TYPE *)(streams[0].buf + i))[2] = z1;\
+ ((TYPE *)(streams[0].buf + i))[3] = a1;\
+ }\
+ } while (0)
-static void
-process_xyza_b(struct stream *streams, size_t n_streams, size_t n)
-{
- double x1, y1, z1, a1;
- double x2, y2, z2, a2;
- size_t i, j;
- for (i = 0; i < n; i += streams->pixel_size) {
- x1 = ((double *)(streams[0].buf + i))[0];
- y1 = ((double *)(streams[0].buf + i))[1];
- z1 = ((double *)(streams[0].buf + i))[2];
- a1 = ((double *)(streams[0].buf + i))[3];
- for (j = 1; j < n_streams;) {
- x2 = ((double *)(streams[j].buf + i))[0];
- y2 = ((double *)(streams[j].buf + i))[1];
- z2 = ((double *)(streams[j].buf + i))[2];
- a2 = ((double *)(streams[j].buf + i))[3];
- a2 /= ++j;
- x1 = x1 * a1 * (1 - a2) + x2 * a2;
- y1 = y1 * a1 * (1 - a2) + y2 * a2;
- z1 = z1 * a1 * (1 - a2) + z2 * a2;
- a1 = a1 * (1 - a2) + a2;
- }
- ((double *)(streams[0].buf + i))[0] = x1;
- ((double *)(streams[0].buf + i))[1] = y1;
- ((double *)(streams[0].buf + i))[2] = z1;
- ((double *)(streams[0].buf + i))[3] = a1;
- }
-}
+static void process_xyza (struct stream *streams, size_t n_streams, size_t n) { PROCESS_LINEAR_3CH_ALPHA(double, 0); }
+static void process_xyza_b(struct stream *streams, size_t n_streams, size_t n) { PROCESS_LINEAR_3CH_ALPHA(double, 1); }
int
main(int argc, char *argv[])
{
struct stream *streams;
- size_t n_streams;
+ size_t n_streams, i;
int blend = 0;
- size_t i, j, n;
- size_t closed;
void (*process)(struct stream *streams, size_t n_streams, size_t n) = NULL;
ARGBEGIN {
@@ -93,8 +66,6 @@ main(int argc, char *argv[])
for (i = 0; i < n_streams; i++) {
streams[i].file = argv[i];
streams[i].fd = eopen(streams[i].file, O_RDONLY);
- if (i)
- echeck_compat(streams + i, streams);
}
if (!strcmp(streams->pixfmt, "xyza"))
@@ -102,35 +73,7 @@ main(int argc, char *argv[])
else
eprintf("pixel format %s is not supported, try xyza\n", streams->pixfmt);
- while (n_streams) {
- n = SIZE_MAX;
- for (i = 0; i < n_streams; i++) {
- if (streams[i].ptr < sizeof(streams->buf) && !eread_stream(streams + i, SIZE_MAX)) {
- close(streams[i].fd);
- streams[i].fd = -1;
- }
- if (streams[i].ptr && streams[i].ptr < n)
- n = streams[i].ptr;
- }
- n -= n % streams->pixel_size;
-
- process(streams, n_streams, n);
-
- ewriteall(STDOUT_FILENO, streams->buf, n, "<stdout>");
-
- closed = SIZE_MAX;
- for (i = 0; i < n_streams; i++) {
- memmove(streams[i].buf, streams[i].buf + n, streams[i].ptr -= n);
- if (streams[i].ptr < streams->pixel_size && streams[i].fd < 0 && closed == SIZE_MAX)
- closed = i;
- }
- if (closed != SIZE_MAX) {
- for (i = (j = closed) + 1; i < n_streams; i++)
- if (streams[i].ptr < streams->pixel_size && streams[i].fd < 0)
- streams[j++] = streams[i];
- n_streams = j;
- }
- }
+ process_multiple_streams(streams, n_streams, STDOUT_FILENO, "<stdout>", process);
free(streams);
return 0;