diff --git a/bin/tile.c b/bin/tile.c index 896098a..8799303 100644 --- a/bin/tile.c +++ b/bin/tile.c @@ -46,7 +46,7 @@ static void import_usage(int argc, char **argv, const char *message, ...) { int cammy_tile_import(int argc, char **argv) { cammy_sram *sram; - cammy_image *dest, *src; + cammy_image dest, *src; int photo; cammy_image_point to = { @@ -87,18 +87,12 @@ int cammy_tile_import(int argc, char **argv) { goto error_image_open_tile; } - if ((dest = malloc(sizeof(*dest))) == NULL) { - goto error_malloc_dest; - } + dest.format = CAMMY_IMAGE_2BPP_TILE; + dest.tiles = (cammy_tile *)&sram->data->photos[photo-1].tiles; + dest.width = CAMMY_PHOTO_WIDTH; + dest.height = CAMMY_PHOTO_HEIGHT; - dest->format = CAMMY_IMAGE_2BPP_TILE; - dest->tiles = (cammy_tile *)&sram->data->photos[photo-1].tiles; - dest->width = CAMMY_PHOTO_WIDTH; - dest->height = CAMMY_PHOTO_HEIGHT; - - cammy_image_copy(dest, src, &to, &from); - - free(dest); + cammy_image_copy(&dest, src, &to, &from); cammy_image_close(src); @@ -106,9 +100,6 @@ int cammy_tile_import(int argc, char **argv) { return 0; -error_malloc_dest: - cammy_image_close(src); - error_image_open_tile: cammy_sram_close(sram); @@ -136,7 +127,7 @@ static void export_usage(int argc, char **argv, const char *message, ...) { int cammy_tile_export(int argc, char **argv) { cammy_sram *sram; - cammy_image *dest, *src; + cammy_image *dest, src; int photo; cammy_image_point to = { @@ -169,18 +160,11 @@ int cammy_tile_export(int argc, char **argv) { goto error_sram_open; } - if ((src = malloc(sizeof(*src))) == NULL) { - fprintf(stderr, "%s: %s: %s\n", - argv[0], "malloc()", strerror(errno)); - - goto error_malloc_src; - } - - src->format = CAMMY_IMAGE_2BPP_TILE; - src->size = CAMMY_PHOTO_SIZE; - src->width = CAMMY_PHOTO_WIDTH; - src->height = CAMMY_PHOTO_HEIGHT; - src->tiles = (cammy_tile *)&sram->data->photos[photo-1].tiles; + src.format = CAMMY_IMAGE_2BPP_TILE; + src.size = CAMMY_PHOTO_SIZE; + src.width = CAMMY_PHOTO_WIDTH; + src.height = CAMMY_PHOTO_HEIGHT; + src.tiles = (cammy_tile *)&sram->data->photos[photo-1].tiles; if ((dest = cammy_image_new(CAMMY_IMAGE_2BPP_TILE, CAMMY_SCREEN_WIDTH, @@ -193,7 +177,7 @@ int cammy_tile_export(int argc, char **argv) { memset(dest->buf, '\0', dest->size); - cammy_image_copy(dest, src, &to, &from); + cammy_image_copy(dest, &src, &to, &from); if (cammy_image_save_tile(dest, argv[4]) < 0) { fprintf(stderr, "%s: %s: %s: %s\n", @@ -202,9 +186,7 @@ int cammy_tile_export(int argc, char **argv) { goto error_image_save_tile_dest; } - free(dest); - - cammy_image_close(src); + cammy_image_close(dest); cammy_sram_close(sram); @@ -214,9 +196,6 @@ error_image_save_tile_dest: cammy_image_destroy(dest); error_image_new_dest: - free(src); - -error_malloc_src: cammy_sram_close(sram); error_sram_open: