From b7a82c980fe7e0c1f9029b55be97422428d65d5a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 11 Jan 2017 09:11:51 +0100 Subject: Clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-flop.c | 71 +++++++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 53 deletions(-) (limited to 'src/vu-flop.c') diff --git a/src/vu-flop.c b/src/vu-flop.c index 1d21d20..e98771d 100644 --- a/src/vu-flop.c +++ b/src/vu-flop.c @@ -1,79 +1,44 @@ /* See LICENSE file for copyright and license details. */ -#include "arg.h" #include "stream.h" #include "util.h" -#include #include #include #include -static void -usage(void) -{ - eprintf("usage: %s\n", argv0); -} +USAGE("") int main(int argc, char *argv[]) { struct stream stream; - char *buf, t1, t2; - size_t ptr, n, i, j, k, wm; - ssize_t r; + char *buf, *image; + size_t i, j, n, m; - ARGBEGIN { - default: - usage(); - } ARGEND; - - if (argc) - usage(); + ENOFLAGS(argc); stream.file = ""; stream.fd = STDIN_FILENO; einit_stream(&stream); fprint_stream_head(stdout, &stream); - fflush(stdout); - if (ferror(stdout)) - eprintf(":"); + efflush(stdout, ""); if (stream.width > SIZE_MAX / stream.pixel_size) - eprintf(": video is too wide\n"); + eprintf(": video frame is too wide\n"); n = stream.width * stream.pixel_size; - if (!(buf = malloc(n))) - eprintf("malloc:"); - - wm = stream.width - 1; - memcpy(buf, stream.buf, ptr = stream.ptr); - for (;;) { - for (; ptr < n; ptr += (size_t)r) { - r = read(stream.fd, buf + ptr, n - ptr); - if (r < 0) { - eprintf("read %s:", stream.file); - } else if (r == 0) { - if (!ptr) - break; - eprintf("%s: incomplete frame", stream.file); - } - } - if (!ptr) - break; - for (i = 0; i < stream.pixel_size; i++) { - for (j = 0; j < stream.width >> 1; j++) { - k = wm - j; - t1 = buf[j * stream.pixel_size + i]; - t2 = buf[k * stream.pixel_size + i]; - buf[j * stream.pixel_size + i] = t2; - buf[k * stream.pixel_size + i] = t1; - } - } - for (ptr = 0; ptr < n; ptr += (size_t)r) { - r = write(STDOUT_FILENO, buf + ptr, n - ptr); - if (r < 0) - eprintf("write "); - } + buf = emalloc(n); + image = emalloc(n); + + m = n - stream.pixel_size; + memcpy(buf, stream.buf, stream.ptr); + while (eread_row(&stream, buf, n)) { + for (i = 0; i < stream.pixel_size; i++) + for (j = 0; j < n; j += stream.pixel_size) + image[m - j + i] = buf[i + j]; + ewriteall(STDOUT_FILENO, image, n, ""); } + free(buf); + free(image); return 0; } -- cgit v1.2.3-70-g09d2