diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-07-15 17:08:02 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-07-15 17:08:02 +0200 |
| commit | 3569a10c97d41913dbf7cf3114cb4d2d5f17dc7f (patch) | |
| tree | e8b08fe9b0cdc208f66582309377bc3c1817fe1f /src/blind-extract-alpha.c | |
| parent | Generate USING_BINARY{32,64} (diff) | |
| download | blind-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 '')
| -rw-r--r-- | src/blind-extract-alpha.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/blind-extract-alpha.c b/src/blind-extract-alpha.c index ac27724..f65042a 100644 --- a/src/blind-extract-alpha.c +++ b/src/blind-extract-alpha.c @@ -8,17 +8,17 @@ USAGE("colour-file") process_##SUFFIX(struct stream *stream, int fd, const char *fname)\ {\ char buf[sizeof(stream->buf)];\ - size_t i, n;\ - TYPE a;\ + size_t i, j, n;\ + TYPE a, *p, *b;\ do {\ n = stream->ptr / stream->pixel_size;\ - for (i = 0; i < n; i++) {\ - a = ((TYPE *)(stream->buf))[4 * i + 3];\ - ((TYPE *)(stream->buf))[4 * i + 3] = 1;\ - ((TYPE *)buf)[4 * i + 0] = a;\ - ((TYPE *)buf)[4 * i + 1] = a;\ - ((TYPE *)buf)[4 * i + 2] = a;\ - ((TYPE *)buf)[4 * i + 3] = 1;\ + p = (TYPE *)(stream->buf) + stream->n_chan - 1;\ + b = (TYPE *)buf;\ + for (i = 0; i < n; i++, p += stream->n_chan) {\ + a = *p, *p = 1;\ + for (j = stream->n_chan - 1; j--;)\ + *b++ = a;\ + *b++ = 1;\ }\ n *= stream->pixel_size;\ ewriteall(fd, stream->buf, n, fname);\ @@ -32,7 +32,6 @@ USAGE("colour-file") PROCESS(double, lf) PROCESS(float, f) - int main(int argc, char *argv[]) { @@ -45,9 +44,9 @@ main(int argc, char *argv[]) eopen_stream(&stream, NULL); fd = eopen(argv[0], O_WRONLY | O_CREAT | O_TRUNC, 0666); - 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); |
