From c216ac3049102422a41ba2c9476b0dbf4f3e4034 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 16 Jul 2017 00:59:42 +0200 Subject: Use #include instead of #define MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-radial-gradient.c | 150 +++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 73 deletions(-) (limited to 'src/blind-radial-gradient.c') diff --git a/src/blind-radial-gradient.c b/src/blind-radial-gradient.c index ce20366..e3483d3 100644 --- a/src/blind-radial-gradient.c +++ b/src/blind-radial-gradient.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#ifndef TYPE #include "common.h" USAGE("-w width -h height") @@ -7,79 +8,8 @@ static size_t width = 0; static size_t height = 0; static int with_params; -#define PROCESS(TYPE, SUFFIX)\ - static void\ - process_##SUFFIX(struct stream *stream)\ - {\ - typedef TYPE pixel_t[4];\ - pixel_t buf[BUFSIZ / sizeof(pixel_t)];\ - TYPE *params, x1, y1, x2, y2, norm, rd = 1, pe = 2, re = 2, e = 0.5;\ - TYPE x, y, p, r, rx, ry;\ - size_t ix, iy, ptr = 0;\ - for (;;) {\ - while (stream->ptr < stream->frame_size) {\ - if (!eread_stream(stream, stream->frame_size - stream->ptr)) {\ - ewriteall(STDOUT_FILENO, buf, ptr * sizeof(*buf), "");\ - return;\ - }\ - }\ - params = (TYPE *)stream->buf;\ - x1 = (params)[0];\ - y1 = (params)[1];\ - x2 = (params)[4];\ - y2 = (params)[5];\ - if (with_params) {\ - pe = (params)[8];\ - re = (params)[9];\ - rd = (params)[10];\ - e = 1 / sqrt(pe * re);\ - }\ - memmove(stream->buf, stream->buf + stream->frame_size,\ - stream->ptr -= stream->frame_size);\ - \ - x2 -= x1;\ - y2 -= y1;\ - norm = sqrt(x2 * x2 + y2 * y2);\ - \ - if (!with_params) {\ - for (iy = 0; iy < height; iy++) {\ - y = (TYPE)iy - y1;\ - y *= y;\ - for (ix = 0; ix < width; ix++) {\ - x = (TYPE)ix - x1;\ - x = sqrt(x * x + y) / norm;\ - buf[ptr][0] = buf[ptr][1] = buf[ptr][2] = buf[ptr][3] = x;\ - if (++ptr == ELEMENTSOF(buf)) {\ - ewriteall(STDOUT_FILENO, buf, sizeof(buf), "");\ - ptr = 0;\ - }\ - }\ - }\ - } else {\ - for (iy = 0; iy < height; iy++) {\ - y = (TYPE)iy - y1;\ - for (ix = 0; ix < width; ix++) {\ - x = (TYPE)ix - x1;\ - p = (x * x2 + y * y2) / norm;\ - rx = x - p * x2 / norm;\ - ry = y - p * y2 / norm;\ - r = sqrt(rx * rx + ry * ry) / rd;\ - p = pow(abs(p / norm), pe);\ - r = pow(abs(r / norm), re);\ - x = pow(p + r, e);\ - buf[ptr][0] = buf[ptr][1] = buf[ptr][2] = buf[ptr][3] = x;\ - if (++ptr == ELEMENTSOF(buf)) {\ - ewriteall(STDOUT_FILENO, buf, sizeof(buf), "");\ - ptr = 0;\ - }\ - }\ - }\ - }\ - }\ - } - -PROCESS(double, lf) -PROCESS(float, f) +#define FILE "blind-radial-gradient.c" +#include "define-functions.h" int main(int argc, char *argv[]) @@ -124,3 +54,77 @@ main(int argc, char *argv[]) process(&stream); return 0; } + +#else + +static void +PROCESS(struct stream *stream) +{ + typedef TYPE pixel_t[4]; + pixel_t buf[BUFSIZ / sizeof(pixel_t)]; + TYPE *params, x1, y1, x2, y2, norm, rd = 1, pe = 2, re = 2, e = 0.5; + TYPE x, y, p, r, rx, ry; + size_t ix, iy, ptr = 0; + for (;;) { + while (stream->ptr < stream->frame_size) { + if (!eread_stream(stream, stream->frame_size - stream->ptr)) { + ewriteall(STDOUT_FILENO, buf, ptr * sizeof(*buf), ""); + return; + } + } + params = (TYPE *)stream->buf; + x1 = (params)[0]; + y1 = (params)[1]; + x2 = (params)[4]; + y2 = (params)[5]; + if (with_params) { + pe = (params)[8]; + re = (params)[9]; + rd = (params)[10]; + e = 1 / sqrt(pe * re); + } + memmove(stream->buf, stream->buf + stream->frame_size, + stream->ptr -= stream->frame_size); + + x2 -= x1; + y2 -= y1; + norm = sqrt(x2 * x2 + y2 * y2); + + if (!with_params) { + for (iy = 0; iy < height; iy++) { + y = (TYPE)iy - y1; + y *= y; + for (ix = 0; ix < width; ix++) { + x = (TYPE)ix - x1; + x = sqrt(x * x + y) / norm; + buf[ptr][0] = buf[ptr][1] = buf[ptr][2] = buf[ptr][3] = x; + if (++ptr == ELEMENTSOF(buf)) { + ewriteall(STDOUT_FILENO, buf, sizeof(buf), ""); + ptr = 0; + } + } + } + } else { + for (iy = 0; iy < height; iy++) { + y = (TYPE)iy - y1; + for (ix = 0; ix < width; ix++) { + x = (TYPE)ix - x1; + p = (x * x2 + y * y2) / norm; + rx = x - p * x2 / norm; + ry = y - p * y2 / norm; + r = sqrt(rx * rx + ry * ry) / rd; + p = pow(abs(p / norm), pe); + r = pow(abs(r / norm), re); + x = pow(p + r, e); + buf[ptr][0] = buf[ptr][1] = buf[ptr][2] = buf[ptr][3] = x; + if (++ptr == ELEMENTSOF(buf)) { + ewriteall(STDOUT_FILENO, buf, sizeof(buf), ""); + ptr = 0; + } + } + } + } + } +} + +#endif -- cgit v1.2.3-70-g09d2