From 4af59ebf60d502b4de3ce54d9d2e9345cc532576 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 4 Jul 2016 18:28:01 -0500 Subject: [PATCH] Implement 'cammy slice' to dice images into 160x144 pieces --- bin/main.c | 26 ++++++++++++++++-------- include/cammy/image.h | 7 ++++++- src/image.c | 46 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/bin/main.c b/bin/main.c index ccbe586..2e7e0cf 100644 --- a/bin/main.c +++ b/bin/main.c @@ -42,7 +42,7 @@ static void usage(int argc, char **argv, const char *message, ...) { " %1$s import-tile file.sav 1..30 printer.tile\n" " %1$s export-tile file.sav 1..30 output.tile\n" " %1$s convert-tile printer.tile output.png\n" - " %1$s stripe input.png\n", + " %1$s slice x-pad y-pad input.png\n", argv[0]); exit(1); @@ -754,28 +754,38 @@ error_open: return errno; } -static int stripe(int argc, char **argv) { +static int slice(int argc, char **argv) { uint8_t *buf; - size_t width, height; + + size_t width, height, + x_pad, y_pad; + int depth; if (argc < 3) { + usage(argc, argv, "No X padding provided"); + } else if (argc < 4) { + usage(argc, argv, "No Y padding provided"); + } else if (argc < 5) { usage(argc, argv, "No input PNG image provided"); } - if ((buf = read_png_file(argv[2], &width, &height, &depth)) == NULL) { + x_pad = atoi(argv[2]); + y_pad = atoi(argv[3]); + + if ((buf = read_png_file(argv[4], &width, &height, &depth)) == NULL) { goto error_read_png_file; } - if (cammy_image_stripe(buf, width, height, depth) < 0) { - goto error_image_stripe; + if (cammy_image_slice(buf, width, height, x_pad, y_pad, depth) < 0) { + goto error_image_slice; } free(buf); return 0; -error_image_stripe: +error_image_slice: free(buf); error_read_png_file: @@ -794,7 +804,7 @@ static struct { { "import-tile", import_tile }, { "export-tile", export_tile }, { "convert-tile", convert_tile }, - { "stripe", stripe }, + { "slice", slice }, { NULL, NULL } }; diff --git a/include/cammy/image.h b/include/cammy/image.h index 4bb94aa..4862c61 100644 --- a/include/cammy/image.h +++ b/include/cammy/image.h @@ -100,6 +100,11 @@ void cammy_image_copy(cammy_image *dest, size_t width, size_t height); -int cammy_image_stripe(uint8_t *buf, size_t width, size_t height, int depth); +int cammy_image_slice(uint8_t *buf, + size_t width, + size_t height, + size_t x_pad, + size_t y_pad, + int depth); #endif /* _CAMMY_IMAGE_H */ diff --git a/src/image.c b/src/image.c index c5a6e3e..d02a09c 100644 --- a/src/image.c +++ b/src/image.c @@ -528,3 +528,49 @@ error_save_tile_to_file: error_malloc_tiles: return 1; } + +int cammy_image_slice(uint8_t *buf, + size_t width, + size_t height, + size_t x_pad, + size_t y_pad, + int depth) { + cammy_tile *tiles; + int file = 0; + + size_t x, y; + + if ((tiles = malloc(CAMMY_SCREEN_SIZE)) == NULL) { + goto error_malloc_tiles; + } + + for (x=0; x