diff options
Diffstat (limited to '')
| -rw-r--r-- | src/blind-sawtooth-wave.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/src/blind-sawtooth-wave.c b/src/blind-sawtooth-wave.c index a4ecfb4..d1eeec1 100644 --- a/src/blind-sawtooth-wave.c +++ b/src/blind-sawtooth-wave.c @@ -5,41 +5,30 @@ USAGE("[-e]") static int equal = 0; - #define PROCESS(TYPE, SUFFIX)\ static void\ process_##SUFFIX(struct stream *stream)\ {\ - size_t i, n;\ - TYPE x, y, z, a;\ + size_t i, j, n;\ + TYPE v, *p;\ do {\ - n = stream->ptr / stream->pixel_size;\ if (equal) {\ + n = stream->ptr / stream->pixel_size;\ for (i = 0; i < n; i++) {\ - a = ((TYPE *)(stream->buf))[4 * i + 3];\ - a = posmod(a, (TYPE)1);\ - ((TYPE *)(stream->buf))[4 * i + 0] = a;\ - ((TYPE *)(stream->buf))[4 * i + 1] = a;\ - ((TYPE *)(stream->buf))[4 * i + 2] = a;\ - ((TYPE *)(stream->buf))[4 * i + 3] = a;\ + p = (TYPE *)(stream->buf) + i * stream->n_chan;\ + v = posmod(*p, (TYPE)1);\ + for (j = 0; j < stream->n_chan; j++)\ + p[j] = v;\ }\ + n *= stream->pixel_size;\ } else {\ + n = stream->ptr / stream->chan_size;\ for (i = 0; i < n; i++) {\ - x = ((TYPE *)(stream->buf))[4 * i + 0];\ - y = ((TYPE *)(stream->buf))[4 * i + 1];\ - z = ((TYPE *)(stream->buf))[4 * i + 2];\ - a = ((TYPE *)(stream->buf))[4 * i + 3];\ - x = posmod(x, (TYPE)1);\ - y = posmod(y, (TYPE)1);\ - z = posmod(z, (TYPE)1);\ - a = posmod(a, (TYPE)1);\ - ((TYPE *)(stream->buf))[4 * i + 0] = x;\ - ((TYPE *)(stream->buf))[4 * i + 1] = y;\ - ((TYPE *)(stream->buf))[4 * i + 2] = z;\ - ((TYPE *)(stream->buf))[4 * i + 3] = a;\ + p = (TYPE *)(stream->buf) + i;\ + *p = posmod(*p, (TYPE)1);\ }\ + n *= stream->chan_size;\ }\ - n *= stream->pixel_size;\ ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>");\ memmove(stream->buf, stream->buf + n, stream->ptr -= n);\ } while (eread_stream(stream, SIZE_MAX));\ @@ -50,7 +39,6 @@ static int equal = 0; PROCESS(double, lf) PROCESS(float, f) - int main(int argc, char *argv[]) { @@ -70,9 +58,9 @@ main(int argc, char *argv[]) eopen_stream(&stream, NULL); - if (!strcmp(stream.pixfmt, "xyza")) + if (stream.encoding == DOUBLE) process = process_lf; - else if (!strcmp(stream.pixfmt, "xyza f")) + else if (stream.encoding == FLOAT) process = process_f; else eprintf("pixel format %s is not supported, try xyza\n", stream.pixfmt); |
