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;
|
||||
int photo;
|
||||
|
||||
cammy_image_point to = {
|
||||
0, 0
|
||||
};
|
||||
|
||||
cammy_image_region from = {
|
||||
16, 16, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT
|
||||
};
|
||||
|
||||
if (argc < 2) {
|
||||
import_usage(argc, argv, "No camera SRAM file provided");
|
||||
} else if (argc < 3) {
|
||||
|
@ -88,8 +96,7 @@ int cammy_tile_import(int argc, char **argv) {
|
|||
dest->width = CAMMY_PHOTO_WIDTH;
|
||||
dest->height = CAMMY_PHOTO_HEIGHT;
|
||||
|
||||
cammy_image_copy(dest, src,
|
||||
0, 0, 16, 16, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT);
|
||||
cammy_image_copy(dest, src, &to, &from);
|
||||
|
||||
free(dest);
|
||||
|
||||
|
@ -132,6 +139,14 @@ int cammy_tile_export(int argc, char **argv) {
|
|||
cammy_image *dest, *src;
|
||||
int photo;
|
||||
|
||||
cammy_image_point to = {
|
||||
16, 16
|
||||
};
|
||||
|
||||
cammy_image_region from = {
|
||||
0, 0, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT
|
||||
};
|
||||
|
||||
if (argc < 2) {
|
||||
export_usage(argc, argv, "No camera SRAM file provided");
|
||||
} else if (argc < 3) {
|
||||
|
@ -178,8 +193,7 @@ int cammy_tile_export(int argc, char **argv) {
|
|||
|
||||
memset(dest->buf, '\0', dest->size);
|
||||
|
||||
cammy_image_copy(dest, src,
|
||||
16, 16, 0, 0, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT);
|
||||
cammy_image_copy(dest, src, &to, &from);
|
||||
|
||||
if (cammy_image_save_tile(dest, argv[4]) < 0) {
|
||||
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,
|
||||
cammy_image *src,
|
||||
size_t x_dest,
|
||||
size_t y_dest,
|
||||
size_t x_src,
|
||||
size_t y_src,
|
||||
size_t width,
|
||||
size_t height);
|
||||
cammy_image_point *to,
|
||||
cammy_image_region *from);
|
||||
|
||||
int cammy_image_slice(uint8_t *buf,
|
||||
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,
|
||||
size_t x_dest,
|
||||
size_t y_dest,
|
||||
size_t x_src,
|
||||
size_t y_src,
|
||||
size_t width,
|
||||
size_t height) {
|
||||
cammy_image_point *to,
|
||||
cammy_image_region *from) {
|
||||
size_t x_offset,
|
||||
y_offset;
|
||||
|
||||
if (dest->format != CAMMY_IMAGE_2BPP_TILE
|
||||
|| src->format != CAMMY_IMAGE_2BPP_TILE) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (y_offset=0; y_offset<height; y_offset++) {
|
||||
if (y_dest + y_offset > dest->height) {
|
||||
for (y_offset=0; y_offset < from->height; y_offset++) {
|
||||
if (to->y + y_offset > dest->height) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (x_offset=0; x_offset<width; x_offset++) {
|
||||
uint8_t value = tile_read(src->tiles, x_src + x_offset,
|
||||
y_src + y_offset,
|
||||
for (x_offset=0; x_offset < from->width; x_offset++) {
|
||||
uint8_t value = tile_read(src->tiles, from->x + x_offset,
|
||||
from->y + y_offset,
|
||||
src->width);
|
||||
|
||||
if (x_dest + x_offset > dest->width) {
|
||||
if (to->x + x_offset > dest->width) {
|
||||
break;
|
||||
}
|
||||
|
||||
tile_write(dest->tiles, x_dest + x_offset,
|
||||
y_dest + y_offset,
|
||||
tile_write(dest->tiles, to->x + x_offset,
|
||||
to->y + y_offset,
|
||||
dest->width,
|
||||
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,
|
||||
size_t height,
|
||||
int file) {
|
||||
|
|
Loading…
Add table
Reference in a new issue