Implement 'cammy slice' to dice images into 160x144 pieces
This commit is contained in:
parent
899db9fdaf
commit
4af59ebf60
3 changed files with 70 additions and 9 deletions
26
bin/main.c
26
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 }
|
||||
};
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
46
src/image.c
46
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<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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue