aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-cone-gradient.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/blind-cone-gradient.c137
1 files changed, 69 insertions, 68 deletions
diff --git a/src/blind-cone-gradient.c b/src/blind-cone-gradient.c
index fc23210..c42a7e7 100644
--- a/src/blind-cone-gradient.c
+++ b/src/blind-cone-gradient.c
@@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#ifndef TYPE
#include "common.h"
USAGE("[-a | -s] -w width -h height")
@@ -9,69 +10,8 @@ static size_t width = 0;
static size_t height = 0;
static int with_multiplier = 0;
-#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;\
- TYPE x, y, u, v, m = 1;\
- 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), "<stdout>");\
- return;\
- }\
- }\
- params = (TYPE *)stream->buf;\
- x1 = (params)[0];\
- y1 = (params)[1];\
- x2 = (params)[4];\
- y2 = (params)[5];\
- if (with_multiplier)\
- m = (params)[9];\
- memmove(stream->buf, stream->buf + stream->frame_size,\
- stream->ptr -= stream->frame_size);\
- \
- x2 -= x1;\
- y2 -= y1;\
- u = atan2(y2, x2);\
- \
- for (iy = 0; iy < height; iy++) {\
- y = (TYPE)iy - y1;\
- for (ix = 0; ix < width; ix++) {\
- x = (TYPE)ix - x1;\
- if (!x && !y) {\
- v = 0.5;\
- } else {\
- v = atan2(y, x);\
- v -= u;\
- v += 2 * (TYPE)M_PI;\
- v = mod(v, 2 * (TYPE)M_PI);\
- v /= 2 * (TYPE)M_PI;\
- if (anticlockwise)\
- v = 1 - v;\
- v *= m;\
- if (symmetric) {\
- v = mod(2 * v, (TYPE)2);\
- if (v > 1)\
- v = 2 - v;\
- }\
- }\
- buf[ptr][0] = buf[ptr][1] = buf[ptr][2] = buf[ptr][3] = v;\
- if (++ptr == ELEMENTSOF(buf)) {\
- ewriteall(STDOUT_FILENO, buf, sizeof(buf), "<stdout>");\
- ptr = 0;\
- }\
- }\
- }\
- }\
- }
-
-PROCESS(double, lf)
-PROCESS(float, f)
+#define FILE "blind-cone-gradient.c"
+#include "define-functions.h"
int
main(int argc, char *argv[])
@@ -81,13 +21,9 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'a':
- if (symmetric)
- usage();
anticlockwise = 1;
break;
case 's':
- if (anticlockwise)
- usage();
symmetric = 1;
break;
case 'w':
@@ -100,7 +36,7 @@ main(int argc, char *argv[])
usage();
} ARGEND;
- if (!width || !height || argc)
+ if (!width || !height || (symmetric && anticlockwise) || argc)
usage();
eopen_stream(&stream, NULL);
@@ -126,3 +62,68 @@ 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;
+ TYPE x, y, u, v, m = 1;
+ 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), "<stdout>");
+ return;
+ }
+ }
+ params = (TYPE *)stream->buf;
+ x1 = (params)[0];
+ y1 = (params)[1];
+ x2 = (params)[4];
+ y2 = (params)[5];
+ if (with_multiplier)
+ m = (params)[9];
+ memmove(stream->buf, stream->buf + stream->frame_size,
+ stream->ptr -= stream->frame_size);
+
+ x2 -= x1;
+ y2 -= y1;
+ u = atan2(y2, x2);
+
+ for (iy = 0; iy < height; iy++) {
+ y = (TYPE)iy - y1;
+ for (ix = 0; ix < width; ix++) {
+ x = (TYPE)ix - x1;
+ if (!x && !y) {
+ v = 0.5;
+ } else {
+ v = atan2(y, x);
+ v -= u;
+ v += 2 * (TYPE)M_PI;
+ v = mod(v, 2 * (TYPE)M_PI);
+ v /= 2 * (TYPE)M_PI;
+ if (anticlockwise)
+ v = 1 - v;
+ v *= m;
+ if (symmetric) {
+ v = mod(2 * v, (TYPE)2);
+ if (v > 1)
+ v = 2 - v;
+ }
+ }
+ buf[ptr][0] = buf[ptr][1] = buf[ptr][2] = buf[ptr][3] = v;
+ if (++ptr == ELEMENTSOF(buf)) {
+ ewriteall(STDOUT_FILENO, buf, sizeof(buf), "<stdout>");
+ ptr = 0;
+ }
+ }
+ }
+ }
+}
+
+#endif