From 5c8783819a9e693e91b51d0a25a945b8898e8343 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 31 May 2016 22:02:11 -0500 Subject: [PATCH] De-boilerplating because I know people on Twitter will twitch and whinge otherwise --- bin/main.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/bin/main.c b/bin/main.c index 66821c3..da322cb 100644 --- a/bin/main.c +++ b/bin/main.c @@ -44,10 +44,6 @@ static void usage(int argc, char **argv, const char *message, ...) { exit(1); } -static inline uint8_t *buf_malloc(size_t width, size_t height, int stride) { - return malloc(stride * width * height); -} - static int import(int argc, char **argv) { cammy_sram *sram; png_t *png; @@ -98,11 +94,11 @@ static int import(int argc, char **argv) { goto error_invalid_dimensions; } - if ((buf = buf_malloc(png->width, png->height, (int)png->bpp)) == NULL) { + if ((buf = malloc(png->width * png->height * png->bpp)) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "malloc()", strerror(errno)); - goto error_buf_malloc; + goto error_malloc_buf; } if ((error = png_get_data(png, buf)) < 0) { @@ -127,7 +123,7 @@ static int import(int argc, char **argv) { error_png_get_data: free(buf); -error_buf_malloc: +error_malloc_buf: error_invalid_dimensions: png_close_file(png); @@ -183,11 +179,11 @@ static int export(int argc, char **argv) { goto error_png_open_file_write; } - if ((buf = buf_malloc(CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT, 3)) == NULL) { + if ((buf = malloc(CAMMY_PHOTO_WIDTH * CAMMY_PHOTO_HEIGHT * 3)) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "malloc()", strerror(errno)); - goto error_buf_malloc; + goto error_malloc_buf; } cammy_photo_export(&sram->data->photos[photo-1], buf, 3, &palette); @@ -212,7 +208,7 @@ static int export(int argc, char **argv) { error_png_set_data: free(buf); -error_buf_malloc: +error_malloc_buf: png_close_file(png); error_png_open_file_write: @@ -261,18 +257,18 @@ static int dither(int argc, char **argv) { goto error_png_open_file_write; } - if ((bufin = buf_malloc(in->width, in->height, (int)in->bpp)) == NULL) { + if ((bufin = malloc(in->width * in->height * in->bpp)) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "malloc()", strerror(errno)); - goto error_buf_malloc_bufin; + goto error_malloc_bufin; } - if ((bufout = buf_malloc(in->width, in->height, 3)) == NULL) { + if ((bufout = malloc(in->width * in->height * 3)) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "malloc()", strerror(errno)); - goto error_buf_malloc_bufout; + goto error_malloc_bufout; } if ((error = png_get_data(in, bufin)) < 0) { @@ -309,10 +305,10 @@ error_png_set_data: error_png_get_data: free(bufout); -error_buf_malloc_bufout: +error_malloc_bufout: free(bufin); -error_buf_malloc_bufin: +error_malloc_bufin: png_close_file(out); error_png_open_file_write: @@ -390,11 +386,11 @@ static int split(int argc, char **argv) { goto error_invalid_dimensions; } - if ((buf = buf_malloc(png->width, png->height, (int)png->bpp)) == NULL) { + if ((buf = malloc(png->width * png->height * png->bpp)) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "malloc()", strerror(errno)); - goto error_buf_malloc; + goto error_malloc; } if ((error = png_get_data(png, buf)) < 0) { @@ -421,7 +417,7 @@ static int split(int argc, char **argv) { error_png_get_data: free(buf); -error_buf_malloc: +error_malloc: error_invalid_dimensions: png_close_file(png); @@ -483,11 +479,11 @@ static int merge(int argc, char **argv) { goto error_png_open_file_write; } - if ((buf = buf_malloc(CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT, 3)) == NULL) { + if ((buf = malloc(CAMMY_PHOTO_WIDTH * CAMMY_PHOTO_HEIGHT * 3)) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "malloc()", strerror(errno)); - goto error_buf_malloc; + goto error_malloc_buf; } cammy_photo_merge(&sram->data->photos[photo_r-1], @@ -514,7 +510,7 @@ static int merge(int argc, char **argv) { error_png_set_data: free(buf); -error_buf_malloc: +error_malloc_buf: png_close_file(png); error_png_open_file_write: