Use cammy_image_point, region types for copy ops
This commit is contained in:
parent
15f540d763
commit
9a61c3dbf6
3 changed files with 46 additions and 30 deletions
22
bin/tile.c
22
bin/tile.c
|
@ -49,6 +49,14 @@ int cammy_tile_import(int argc, char **argv) {
|
||||||
cammy_image *dest, *src;
|
cammy_image *dest, *src;
|
||||||
int photo;
|
int photo;
|
||||||
|
|
||||||
|
cammy_image_point to = {
|
||||||
|
0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
cammy_image_region from = {
|
||||||
|
16, 16, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT
|
||||||
|
};
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
import_usage(argc, argv, "No camera SRAM file provided");
|
import_usage(argc, argv, "No camera SRAM file provided");
|
||||||
} else if (argc < 3) {
|
} else if (argc < 3) {
|
||||||
|
@ -88,8 +96,7 @@ int cammy_tile_import(int argc, char **argv) {
|
||||||
dest->width = CAMMY_PHOTO_WIDTH;
|
dest->width = CAMMY_PHOTO_WIDTH;
|
||||||
dest->height = CAMMY_PHOTO_HEIGHT;
|
dest->height = CAMMY_PHOTO_HEIGHT;
|
||||||
|
|
||||||
cammy_image_copy(dest, src,
|
cammy_image_copy(dest, src, &to, &from);
|
||||||
0, 0, 16, 16, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT);
|
|
||||||
|
|
||||||
free(dest);
|
free(dest);
|
||||||
|
|
||||||
|
@ -132,6 +139,14 @@ int cammy_tile_export(int argc, char **argv) {
|
||||||
cammy_image *dest, *src;
|
cammy_image *dest, *src;
|
||||||
int photo;
|
int photo;
|
||||||
|
|
||||||
|
cammy_image_point to = {
|
||||||
|
16, 16
|
||||||
|
};
|
||||||
|
|
||||||
|
cammy_image_region from = {
|
||||||
|
0, 0, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT
|
||||||
|
};
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
export_usage(argc, argv, "No camera SRAM file provided");
|
export_usage(argc, argv, "No camera SRAM file provided");
|
||||||
} else if (argc < 3) {
|
} else if (argc < 3) {
|
||||||
|
@ -178,8 +193,7 @@ int cammy_tile_export(int argc, char **argv) {
|
||||||
|
|
||||||
memset(dest->buf, '\0', dest->size);
|
memset(dest->buf, '\0', dest->size);
|
||||||
|
|
||||||
cammy_image_copy(dest, src,
|
cammy_image_copy(dest, src, &to, &from);
|
||||||
16, 16, 0, 0, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT);
|
|
||||||
|
|
||||||
if (cammy_image_save_tile(dest, argv[4]) < 0) {
|
if (cammy_image_save_tile(dest, argv[4]) < 0) {
|
||||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||||
|
|
|
@ -101,12 +101,8 @@ void cammy_image_merge_tiles(uint8_t *dest,
|
||||||
|
|
||||||
void cammy_image_copy(cammy_image *dest,
|
void cammy_image_copy(cammy_image *dest,
|
||||||
cammy_image *src,
|
cammy_image *src,
|
||||||
size_t x_dest,
|
cammy_image_point *to,
|
||||||
size_t y_dest,
|
cammy_image_region *from);
|
||||||
size_t x_src,
|
|
||||||
size_t y_src,
|
|
||||||
size_t width,
|
|
||||||
size_t height);
|
|
||||||
|
|
||||||
int cammy_image_slice(uint8_t *buf,
|
int cammy_image_slice(uint8_t *buf,
|
||||||
size_t width,
|
size_t width,
|
||||||
|
|
46
src/image.c
46
src/image.c
|
@ -410,44 +410,50 @@ void cammy_image_merge_tiles(uint8_t *dest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cammy_image_copy(cammy_image *dest,
|
static void copy_2bpp(cammy_image *dest,
|
||||||
cammy_image *src,
|
cammy_image *src,
|
||||||
size_t x_dest,
|
cammy_image_point *to,
|
||||||
size_t y_dest,
|
cammy_image_region *from) {
|
||||||
size_t x_src,
|
|
||||||
size_t y_src,
|
|
||||||
size_t width,
|
|
||||||
size_t height) {
|
|
||||||
size_t x_offset,
|
size_t x_offset,
|
||||||
y_offset;
|
y_offset;
|
||||||
|
|
||||||
if (dest->format != CAMMY_IMAGE_2BPP_TILE
|
for (y_offset=0; y_offset < from->height; y_offset++) {
|
||||||
|| src->format != CAMMY_IMAGE_2BPP_TILE) {
|
if (to->y + y_offset > dest->height) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (y_offset=0; y_offset<height; y_offset++) {
|
|
||||||
if (y_dest + y_offset > dest->height) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x_offset=0; x_offset<width; x_offset++) {
|
for (x_offset=0; x_offset < from->width; x_offset++) {
|
||||||
uint8_t value = tile_read(src->tiles, x_src + x_offset,
|
uint8_t value = tile_read(src->tiles, from->x + x_offset,
|
||||||
y_src + y_offset,
|
from->y + y_offset,
|
||||||
src->width);
|
src->width);
|
||||||
|
|
||||||
if (x_dest + x_offset > dest->width) {
|
if (to->x + x_offset > dest->width) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_write(dest->tiles, x_dest + x_offset,
|
tile_write(dest->tiles, to->x + x_offset,
|
||||||
y_dest + y_offset,
|
to->y + y_offset,
|
||||||
dest->width,
|
dest->width,
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cammy_image_copy(cammy_image *dest,
|
||||||
|
cammy_image *src,
|
||||||
|
cammy_image_point *to,
|
||||||
|
cammy_image_region *from) {
|
||||||
|
if (src->format == dest->format) {
|
||||||
|
switch (src->format) {
|
||||||
|
case CAMMY_IMAGE_2BPP_TILE:
|
||||||
|
copy_2bpp(dest, src, to, from); break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int save_tile_to_file(cammy_tile *tiles, size_t width,
|
static int save_tile_to_file(cammy_tile *tiles, size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
int file) {
|
int file) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue