aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-sawtooth-wave.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-07-15 17:08:02 +0200
committerMattias Andrée <maandree@kth.se>2017-07-15 17:08:02 +0200
commit3569a10c97d41913dbf7cf3114cb4d2d5f17dc7f (patch)
treee8b08fe9b0cdc208f66582309377bc3c1817fe1f /src/blind-sawtooth-wave.c
parentGenerate USING_BINARY{32,64} (diff)
downloadblind-3569a10c97d41913dbf7cf3114cb4d2d5f17dc7f.tar.gz
blind-3569a10c97d41913dbf7cf3114cb4d2d5f17dc7f.tar.bz2
blind-3569a10c97d41913dbf7cf3114cb4d2d5f17dc7f.tar.xz
Some improvements and fixes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-sawtooth-wave.c')
-rw-r--r--src/blind-sawtooth-wave.c40
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);