Implement 'cammy slice' to dice images into 160x144 pieces

This commit is contained in:
XANTRONIX Development 2016-07-04 18:28:01 -05:00
parent 899db9fdaf
commit 4af59ebf60
3 changed files with 70 additions and 9 deletions

View file

@ -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 import-tile file.sav 1..30 printer.tile\n"
" %1$s export-tile file.sav 1..30 output.tile\n" " %1$s export-tile file.sav 1..30 output.tile\n"
" %1$s convert-tile printer.tile output.png\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]); argv[0]);
exit(1); exit(1);
@ -754,28 +754,38 @@ error_open:
return errno; return errno;
} }
static int stripe(int argc, char **argv) { static int slice(int argc, char **argv) {
uint8_t *buf; uint8_t *buf;
size_t width, height;
size_t width, height,
x_pad, y_pad;
int depth; int depth;
if (argc < 3) { 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"); 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; goto error_read_png_file;
} }
if (cammy_image_stripe(buf, width, height, depth) < 0) { if (cammy_image_slice(buf, width, height, x_pad, y_pad, depth) < 0) {
goto error_image_stripe; goto error_image_slice;
} }
free(buf); free(buf);
return 0; return 0;
error_image_stripe: error_image_slice:
free(buf); free(buf);
error_read_png_file: error_read_png_file:
@ -794,7 +804,7 @@ static struct {
{ "import-tile", import_tile }, { "import-tile", import_tile },
{ "export-tile", export_tile }, { "export-tile", export_tile },
{ "convert-tile", convert_tile }, { "convert-tile", convert_tile },
{ "stripe", stripe }, { "slice", slice },
{ NULL, NULL } { NULL, NULL }
}; };

View file

@ -100,6 +100,11 @@ void cammy_image_copy(cammy_image *dest,
size_t width, size_t width,
size_t height); 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 */ #endif /* _CAMMY_IMAGE_H */

View file

@ -528,3 +528,49 @@ error_save_tile_to_file:
error_malloc_tiles: error_malloc_tiles:
return 1; 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<width; x+=CAMMY_SCREEN_WIDTH + (2 * x_pad)) {
for (y=0; y<height; y+=CAMMY_SCREEN_HEIGHT + y_pad) {
cammy_image_dither_to_tile(tiles, buf,
0, 0,
x + x_pad, y,
CAMMY_SCREEN_WIDTH,
CAMMY_SCREEN_HEIGHT,
CAMMY_SCREEN_WIDTH,
CAMMY_SCREEN_HEIGHT,
width,
height,
depth);
if (save_tile_to_file(tiles, CAMMY_SCREEN_WIDTH,
CAMMY_SCREEN_HEIGHT, file++) < 0) {
goto error_save_tile_to_file;
}
}
}
free(tiles);
return 0;
error_save_tile_to_file:
free(tiles);
error_malloc_tiles:
return 1;
}