De-boilerplating because I know people on Twitter will twitch and whinge otherwise
This commit is contained in:
parent
47e09e532c
commit
5c8783819a
1 changed files with 18 additions and 22 deletions
40
bin/main.c
40
bin/main.c
|
@ -44,10 +44,6 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
||||||
exit(1);
|
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) {
|
static int import(int argc, char **argv) {
|
||||||
cammy_sram *sram;
|
cammy_sram *sram;
|
||||||
png_t *png;
|
png_t *png;
|
||||||
|
@ -98,11 +94,11 @@ static int import(int argc, char **argv) {
|
||||||
goto error_invalid_dimensions;
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "malloc()", strerror(errno));
|
argv[0], "malloc()", strerror(errno));
|
||||||
|
|
||||||
goto error_buf_malloc;
|
goto error_malloc_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = png_get_data(png, buf)) < 0) {
|
if ((error = png_get_data(png, buf)) < 0) {
|
||||||
|
@ -127,7 +123,7 @@ static int import(int argc, char **argv) {
|
||||||
error_png_get_data:
|
error_png_get_data:
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
error_buf_malloc:
|
error_malloc_buf:
|
||||||
error_invalid_dimensions:
|
error_invalid_dimensions:
|
||||||
png_close_file(png);
|
png_close_file(png);
|
||||||
|
|
||||||
|
@ -183,11 +179,11 @@ static int export(int argc, char **argv) {
|
||||||
goto error_png_open_file_write;
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "malloc()", strerror(errno));
|
argv[0], "malloc()", strerror(errno));
|
||||||
|
|
||||||
goto error_buf_malloc;
|
goto error_malloc_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
cammy_photo_export(&sram->data->photos[photo-1], buf, 3, &palette);
|
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:
|
error_png_set_data:
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
error_buf_malloc:
|
error_malloc_buf:
|
||||||
png_close_file(png);
|
png_close_file(png);
|
||||||
|
|
||||||
error_png_open_file_write:
|
error_png_open_file_write:
|
||||||
|
@ -261,18 +257,18 @@ static int dither(int argc, char **argv) {
|
||||||
goto error_png_open_file_write;
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "malloc()", strerror(errno));
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "malloc()", strerror(errno));
|
argv[0], "malloc()", strerror(errno));
|
||||||
|
|
||||||
goto error_buf_malloc_bufout;
|
goto error_malloc_bufout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = png_get_data(in, bufin)) < 0) {
|
if ((error = png_get_data(in, bufin)) < 0) {
|
||||||
|
@ -309,10 +305,10 @@ error_png_set_data:
|
||||||
error_png_get_data:
|
error_png_get_data:
|
||||||
free(bufout);
|
free(bufout);
|
||||||
|
|
||||||
error_buf_malloc_bufout:
|
error_malloc_bufout:
|
||||||
free(bufin);
|
free(bufin);
|
||||||
|
|
||||||
error_buf_malloc_bufin:
|
error_malloc_bufin:
|
||||||
png_close_file(out);
|
png_close_file(out);
|
||||||
|
|
||||||
error_png_open_file_write:
|
error_png_open_file_write:
|
||||||
|
@ -390,11 +386,11 @@ static int split(int argc, char **argv) {
|
||||||
goto error_invalid_dimensions;
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "malloc()", strerror(errno));
|
argv[0], "malloc()", strerror(errno));
|
||||||
|
|
||||||
goto error_buf_malloc;
|
goto error_malloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = png_get_data(png, buf)) < 0) {
|
if ((error = png_get_data(png, buf)) < 0) {
|
||||||
|
@ -421,7 +417,7 @@ static int split(int argc, char **argv) {
|
||||||
error_png_get_data:
|
error_png_get_data:
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
error_buf_malloc:
|
error_malloc:
|
||||||
error_invalid_dimensions:
|
error_invalid_dimensions:
|
||||||
png_close_file(png);
|
png_close_file(png);
|
||||||
|
|
||||||
|
@ -483,11 +479,11 @@ static int merge(int argc, char **argv) {
|
||||||
goto error_png_open_file_write;
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "malloc()", strerror(errno));
|
argv[0], "malloc()", strerror(errno));
|
||||||
|
|
||||||
goto error_buf_malloc;
|
goto error_malloc_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
cammy_photo_merge(&sram->data->photos[photo_r-1],
|
cammy_photo_merge(&sram->data->photos[photo_r-1],
|
||||||
|
@ -514,7 +510,7 @@ static int merge(int argc, char **argv) {
|
||||||
error_png_set_data:
|
error_png_set_data:
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
error_buf_malloc:
|
error_malloc_buf:
|
||||||
png_close_file(png);
|
png_close_file(png);
|
||||||
|
|
||||||
error_png_open_file_write:
|
error_png_open_file_write:
|
||||||
|
|
Loading…
Add table
Reference in a new issue