diff options
Diffstat (limited to '')
| -rw-r--r-- | src/blind-matrix-orthoproject.c | 89 | ||||
| -rw-r--r-- | src/blind-matrix-reflect.c | 87 | ||||
| -rw-r--r-- | src/blind-matrix-rotate.c | 79 | ||||
| -rw-r--r-- | src/blind-matrix-scale.c | 74 | ||||
| -rw-r--r-- | src/blind-matrix-shear.c | 84 | ||||
| -rw-r--r-- | src/blind-matrix-translate.c | 74 | ||||
| -rw-r--r-- | src/blind-matrix-transpose.c | 76 | ||||
| -rw-r--r-- | src/video-math.h | 1 |
8 files changed, 564 insertions, 0 deletions
diff --git a/src/blind-matrix-orthoproject.c b/src/blind-matrix-orthoproject.c new file mode 100644 index 0000000..2fe82a2 --- /dev/null +++ b/src/blind-matrix-orthoproject.c @@ -0,0 +1,89 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-c]") + +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf[2];\ + TYPE x2, y2, norm2;\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + x2 = buf[0][i] * buf[0][i];\ + y2 = buf[1][i] * buf[1][i];\ + norm2 = x2 + y2;\ + matrix[0][i] = x2 / norm2;\ + matrix[4][i] = y2 / norm2;\ + matrix[3][i] = matrix[1][i] = buf[0][i] * buf[1][i] / norm2;\ + }\ + } else {\ + buf[0][1] *= buf[0][3];\ + buf[1][1] *= buf[1][3];\ + x2 = buf[0][1] * buf[0][1];\ + y2 = buf[1][1] * buf[1][1];\ + norm2 = x2 + y2;\ + matrix[0][0] = x2 / norm2;\ + matrix[4][0] = y2 / norm2;\ + matrix[3][0] = matrix[1][0] = buf[0][1] * buf[1][1] / norm2;\ + matrix[0][3] = matrix[0][2] = matrix[0][1] = matrix[0][0];\ + matrix[1][3] = matrix[1][2] = matrix[1][1] = matrix[1][0];\ + matrix[3][3] = matrix[3][2] = matrix[3][1] = matrix[3][0];\ + matrix[4][3] = matrix[4][2] = matrix[4][1] = matrix[4][0];\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width > 2 || stream.height > 2 || stream.width * stream.height != 2) + eprintf("<stdin>: each frame must contain exactly 2 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/blind-matrix-reflect.c b/src/blind-matrix-reflect.c new file mode 100644 index 0000000..905ec96 --- /dev/null +++ b/src/blind-matrix-reflect.c @@ -0,0 +1,87 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-c]") + +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf[2];\ + TYPE x2, y2, norm2;\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + x2 = buf[0][i] * buf[0][i];\ + y2 = buf[1][i] * buf[1][i];\ + norm2 = x2 + y2;\ + matrix[4][i] = -(matrix[0][i] = (x2 - y2) / norm2);\ + matrix[3][i] = matrix[1][i] = 2 * buf[0][i] * buf[1][i] / norm2;\ + }\ + } else {\ + buf[0][1] *= buf[0][3];\ + buf[1][1] *= buf[1][3];\ + x2 = buf[0][1] * buf[0][1];\ + y2 = buf[1][1] * buf[1][1];\ + norm2 = x2 + y2;\ + matrix[4][0] = -(matrix[0][0] = (x2 - y2) / norm2);\ + matrix[3][0] = matrix[1][0] = 2 * buf[0][1] * buf[1][1] / norm2;\ + matrix[0][3] = matrix[0][2] = matrix[0][1] = matrix[0][0];\ + matrix[1][3] = matrix[1][2] = matrix[1][1] = matrix[1][0];\ + matrix[3][3] = matrix[3][2] = matrix[3][1] = matrix[3][0];\ + matrix[4][3] = matrix[4][2] = matrix[4][1] = matrix[4][0];\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width > 2 || stream.height > 2 || stream.width * stream.height != 2) + eprintf("<stdin>: each frame must contain exactly 2 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/blind-matrix-rotate.c b/src/blind-matrix-rotate.c new file mode 100644 index 0000000..3e2f5e3 --- /dev/null +++ b/src/blind-matrix-rotate.c @@ -0,0 +1,79 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-c]") + +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf;\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + matrix[4][i] = matrix[0][i] = cos(buf[i]);\ + matrix[3][i] = -(matrix[1][i] = sin(buf[i]));\ + }\ + } else {\ + buf[1] *= buf[3];\ + matrix[4][0] = matrix[0][0] = cos(buf[1]);\ + matrix[3][0] = -(matrix[1][0] = sin(buf[1]));\ + matrix[0][3] = matrix[0][2] = matrix[0][1] = matrix[0][0];\ + matrix[1][3] = matrix[0][2] = matrix[0][1] = matrix[1][0];\ + matrix[3][3] = matrix[0][2] = matrix[0][1] = matrix[3][0];\ + matrix[4][3] = matrix[0][2] = matrix[0][1] = matrix[4][0];\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width != 1 && stream.height != 1) + eprintf("<stdin>: each frame must contain exactly 1 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/blind-matrix-scale.c b/src/blind-matrix-scale.c new file mode 100644 index 0000000..8dd6b83 --- /dev/null +++ b/src/blind-matrix-scale.c @@ -0,0 +1,74 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-c]") + +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf[2];\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = buf[0][i];\ + matrix[4][i] = buf[1][i];\ + }\ + } else {\ + matrix[0][3] = matrix[0][2] = matrix[0][1] = matrix[0][0] = buf[0][1] * buf[0][3];\ + matrix[4][3] = matrix[4][2] = matrix[4][1] = matrix[4][0] = buf[1][1] * buf[1][3];\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width > 2 || stream.height > 2 || stream.width * stream.height != 2) + eprintf("<stdin>: each frame must contain exactly 2 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/blind-matrix-shear.c b/src/blind-matrix-shear.c new file mode 100644 index 0000000..a4c742b --- /dev/null +++ b/src/blind-matrix-shear.c @@ -0,0 +1,84 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-ac]") + +static int by_angle = 0; +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf[2];\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (by_angle) {\ + for (i = !per_channel; i < (per_channel ? 4 : 2); i++) {\ + buf[0][i] = tan(buf[0][i]);\ + buf[1][i] = tan(buf[1][i]);\ + }\ + }\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + matrix[1][i] = buf[0][i];\ + matrix[3][i] = buf[1][i];\ + }\ + } else {\ + matrix[1][3] = matrix[1][2] = matrix[1][1] = matrix[1][0] = buf[0][1] * buf[0][3];\ + matrix[3][3] = matrix[3][2] = matrix[3][1] = matrix[3][0] = buf[1][1] * buf[1][3];\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'a': + by_angle = 1; + break; + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width > 2 || stream.height > 2 || stream.width * stream.height != 2) + eprintf("<stdin>: each frame must contain exactly 2 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/blind-matrix-translate.c b/src/blind-matrix-translate.c new file mode 100644 index 0000000..c761a7f --- /dev/null +++ b/src/blind-matrix-translate.c @@ -0,0 +1,74 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-c]") + +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf[2];\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + matrix[2][i] = buf[0][i];\ + matrix[5][i] = buf[1][i];\ + }\ + } else {\ + matrix[2][3] = matrix[2][2] = matrix[2][1] = matrix[2][0] = buf[0][1] * buf[0][3];\ + matrix[5][3] = matrix[5][2] = matrix[5][1] = matrix[5][0] = buf[1][1] * buf[1][3];\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width > 2 || stream.height > 2 || stream.width * stream.height != 2) + eprintf("<stdin>: each frame must contain exactly 2 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/blind-matrix-transpose.c b/src/blind-matrix-transpose.c new file mode 100644 index 0000000..2103205 --- /dev/null +++ b/src/blind-matrix-transpose.c @@ -0,0 +1,76 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("[-c]") + +static int per_channel = 0; + +#define PROCESS(TYPE)\ + do {\ + typedef TYPE pixel_t[4];\ + pixel_t matrix[9];\ + pixel_t buf;\ + int i;\ + \ + for (i = 0; i < 4; i++) {\ + matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0;\ + matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0;\ + matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1;\ + }\ + \ + while (eread_frame(stream, buf)) {\ + if (per_channel) {\ + for (i = 0; i < 4; i++) {\ + matrix[3][i] = matrix[1][i] = buf[i];\ + matrix[4][i] = matrix[0][i] = 1 - buf[i];\ + }\ + } else {\ + for (i = 0; i < 4; i++) {\ + matrix[3][i] = matrix[1][i] = buf[1] * buf[3];\ + matrix[4][i] = matrix[0][i] = 1 - matrix[3][i];\ + }\ + }\ + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>");\ + }\ + } while (0) + +static void process_lf(struct stream *stream) { PROCESS(double); } +static void process_f(struct stream *stream) { PROCESS(float); } + +int +main(int argc, char *argv[]) +{ + struct stream stream; + void (*process)(struct stream *stream); + + ARGBEGIN { + case 'c': + per_channel = 1; + break; + default: + usage(); + } ARGEND; + + if (argc) + usage(); + + eopen_stream(&stream, NULL); + + if (stream.width != 1 && stream.height != 12) + eprintf("<stdin>: each frame must contain exactly 1 pixels\n"); + + stream.width = 3; + stream.height = 3; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + 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.pixfmt); + + process(&stream); + return 0; +} diff --git a/src/video-math.h b/src/video-math.h index 281c8f6..28ac4f2 100644 --- a/src/video-math.h +++ b/src/video-math.h @@ -71,6 +71,7 @@ posmodf(float a, float b) #define posmod(...) MATH_GENERIC_N(posmod, __VA_ARGS__) #define cos(...) MATH_GENERIC_1(cos, __VA_ARGS__) #define sin(...) MATH_GENERIC_1(sin, __VA_ARGS__) +#define tan(...) MATH_GENERIC_1(tan, __VA_ARGS__) #define atan2(...) MATH_GENERIC_N(atan2, __VA_ARGS__) #define srgb_encode(...) BLIND_GENERIC_1(srgb_encode, __VA_ARGS__) |
