diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-05-10 16:59:26 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-05-10 16:59:26 +0200 |
| commit | 6b998b5ed066aeece1146fe245b35965319b3cbd (patch) | |
| tree | c963b48fbefafcec89a4e4af238869a1cb51148e /src/blind-flop.c | |
| parent | blind-flip is optimal (diff) | |
| download | blind-6b998b5ed066aeece1146fe245b35965319b3cbd.tar.gz blind-6b998b5ed066aeece1146fe245b35965319b3cbd.tar.bz2 blind-6b998b5ed066aeece1146fe245b35965319b3cbd.tar.xz | |
Cleaner code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-flop.c')
| -rw-r--r-- | src/blind-flop.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/blind-flop.c b/src/blind-flop.c index c5826be..51f9ab5 100644 --- a/src/blind-flop.c +++ b/src/blind-flop.c @@ -2,10 +2,6 @@ #include "stream.h" #include "util.h" -#include <inttypes.h> -#include <string.h> -#include <unistd.h> - USAGE("") static struct stream stream; @@ -14,41 +10,40 @@ static size_t n, m, ps; #define PROCESS(TYPE)\ do {\ - size_t i, j, pst = ps / sizeof(TYPE);\ - size_t nt = n / sizeof(TYPE);\ - size_t mt = m / sizeof(TYPE);\ - for (i = 0; i < pst; i++)\ - for (j = 0; j < nt; j += pst)\ - ((TYPE *)image)[mt - j + i] = ((TYPE *)buf)[i + j];\ + size_t i, j;\ + for (i = 0; i < ps; i++)\ + for (j = 0; j < n; j += ps)\ + ((TYPE *)image)[m - j + i] = ((TYPE *)buf)[i + j];\ } while (0) -static void process_double(void) {PROCESS(double);} -static void process_float (void) {PROCESS(float);} -static void process_char (void) {PROCESS(char);} +static void process_long(void) {PROCESS(long);} +static void process_char(void) {PROCESS(char);} int main(int argc, char *argv[]) { - void (*process)(void); + void (*process)(void) = process_char; UNOFLAGS(argc); eopen_stream(&stream, NULL); + echeck_dimensions(&stream, WIDTH, NULL); fprint_stream_head(stdout, &stream); efflush(stdout, "<stdout>"); + buf = emalloc(stream.row_size); + image = emalloc(stream.row_size); - echeck_frame_size(stream.width, 1, stream.pixel_size, 0, stream.file); - n = stream.width * (ps = stream.pixel_size); - buf = emalloc(n); - image = emalloc(n); - - process = !(ps % sizeof(double)) ? process_double : - !(ps % sizeof(float)) ? process_float : process_char; + m = (n = stream.row_size) - (ps = stream.pixel_size); + if (!(stream.pixel_size % sizeof(long))) { + process = process_long; + m /= sizeof(long); + n /= sizeof(long); + ps /= sizeof(long); + } - m = n - ps; - while (eread_row(&stream, buf, n)) { + while (eread_row(&stream, buf)) { process(); - ewriteall(STDOUT_FILENO, image, n, "<stdout>"); + ewriteall(STDOUT_FILENO, image, stream.row_size, "<stdout>"); } free(buf); |
