diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-07-16 00:59:42 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-07-16 00:59:42 +0200 |
| commit | c216ac3049102422a41ba2c9476b0dbf4f3e4034 (patch) | |
| tree | 809793e1f01fafcb67422f654b6e9dbcab897660 /src/blind-matrix-reflect.c | |
| parent | Install the scripts (diff) | |
| download | blind-c216ac3049102422a41ba2c9476b0dbf4f3e4034.tar.gz blind-c216ac3049102422a41ba2c9476b0dbf4f3e4034.tar.bz2 blind-c216ac3049102422a41ba2c9476b0dbf4f3e4034.tar.xz | |
Use #include instead of #define
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-matrix-reflect.c')
| -rw-r--r-- | src/blind-matrix-reflect.c | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/src/blind-matrix-reflect.c b/src/blind-matrix-reflect.c index ef882b5..45f6ed8 100644 --- a/src/blind-matrix-reflect.c +++ b/src/blind-matrix-reflect.c @@ -1,54 +1,13 @@ /* See LICENSE file for copyright and license details. */ +#ifndef TYPE #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;\ - size_t i;\ - \ - for (i = 0; i < stream->n_chan; 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 < stream->n_chan; 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;\ - for (i = 1; i < stream->n_chan; i++) {\ - matrix[0][i] = matrix[0][0];\ - matrix[1][i] = matrix[1][0];\ - matrix[3][i] = matrix[3][0];\ - matrix[4][i] = 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); } +#define FILE "blind-matrix-reflect.c" +#include "define-functions.h" int main(int argc, char *argv[]) @@ -87,3 +46,50 @@ main(int argc, char *argv[]) process(&stream); return 0; } + +#else + +static void +PROCESS(struct stream *stream) +{ + typedef TYPE pixel_t[4]; + pixel_t matrix[9]; + pixel_t buf[2]; + TYPE x2, y2, norm2; + size_t i; + + for (i = 0; i < stream->n_chan; 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 < stream->n_chan; 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; + for (i = 1; i < stream->n_chan; i++) { + matrix[0][i] = matrix[0][0]; + matrix[1][i] = matrix[1][0]; + matrix[3][i] = matrix[3][0]; + matrix[4][i] = matrix[4][0]; + } + } + ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>"); + } +} + +#endif |
