Actually implement cammy_image_copy()

This commit is contained in:
XANTRONIX Development 2016-06-07 19:38:33 -05:00
parent 109a3a9efb
commit 775a822035
2 changed files with 26 additions and 8 deletions

View file

@ -26,7 +26,7 @@ typedef struct _cammy_image {
union { union {
uint8_t *buf; uint8_t *buf;
cammy_tile *tile; cammy_tile *tiles;
}; };
} cammy_image; } cammy_image;

View file

@ -155,8 +155,8 @@ cammy_image *cammy_image_open_tile(const char *filename,
goto error_malloc_image; goto error_malloc_image;
} }
if ((image->tile = malloc(size)) == NULL) { if ((image->tiles = malloc(size)) == NULL) {
goto error_malloc_buf; goto error_malloc_tiles;
} }
for (off=0; off<size;) { for (off=0; off<size;) {
@ -178,9 +178,9 @@ cammy_image *cammy_image_open_tile(const char *filename,
return image; return image;
error_read: error_read:
free(image->buf); free(image->tiles);
error_malloc_buf: error_malloc_tiles:
free(image); free(image);
error_malloc_image: error_malloc_image:
@ -311,9 +311,27 @@ void cammy_image_copy(cammy_image *dest,
size_t y_src, size_t y_src,
size_t width, size_t width,
size_t height) { size_t height) {
size_t y, y_max = y_src + height; size_t x_offset,
y_offset;
for (y=y_src; y<y_max; y++) { for (y_offset=0; y_offset<height; y_offset++) {
size_t x, x_max = x_src + width; if (y_dest + 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,
src->width);
if (x_dest + x_offset > dest->width) {
break;
}
tile_write(dest->tiles, x_dest + x_offset,
y_dest + y_offset,
dest->width,
value);
}
} }
} }