At least I can import images slurped from the Game Boy Printer dumps into SRAM files
This commit is contained in:
parent
775a822035
commit
26196ab925
3 changed files with 57 additions and 20 deletions
41
bin/main.c
41
bin/main.c
|
@ -9,6 +9,7 @@
|
|||
#include <errno.h>
|
||||
#include "pnglite.h"
|
||||
|
||||
#include <cammy/screen.h>
|
||||
#include <cammy/image.h>
|
||||
#include <cammy/screen.h>
|
||||
#include <cammy/photo.h>
|
||||
|
@ -524,7 +525,8 @@ error_sram_open:
|
|||
|
||||
static int import_tile(int argc, char **argv) {
|
||||
cammy_sram *sram;
|
||||
int fd;
|
||||
cammy_image *dest, *src;
|
||||
int photo;
|
||||
|
||||
if (argc < 2) {
|
||||
usage(argc, argv, "No camera SRAM file provided");
|
||||
|
@ -534,6 +536,12 @@ static int import_tile(int argc, char **argv) {
|
|||
usage(argc, argv, "No Game Boy screen tile data file provided");
|
||||
}
|
||||
|
||||
photo = atoi(argv[3]);
|
||||
|
||||
if (photo < 1 || photo > CAMMY_SRAM_PHOTO_COUNT) {
|
||||
usage(argc, argv, "Invalid photo number");
|
||||
}
|
||||
|
||||
if ((sram = cammy_sram_open(argv[2])) == NULL) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], "cammy_sram_open()", argv[2], strerror(errno));
|
||||
|
@ -541,18 +549,41 @@ static int import_tile(int argc, char **argv) {
|
|||
goto error_sram_open;
|
||||
}
|
||||
|
||||
if ((fd = open(argv[4], O_RDONLY)) < 0) {
|
||||
if ((src = cammy_image_open_tile(argv[4], CAMMY_SCREEN_WIDTH,
|
||||
CAMMY_SCREEN_HEIGHT)) == NULL) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], "open()", argv[2], strerror(errno));
|
||||
argv[0], "cammy_image_open_tile()", argv[4], strerror(errno));
|
||||
|
||||
goto error_open;
|
||||
goto error_image_open_tile;
|
||||
}
|
||||
|
||||
if ((dest = malloc(sizeof(*dest))) == NULL) {
|
||||
goto error_malloc_dest;
|
||||
}
|
||||
|
||||
dest->format = CAMMY_IMAGE_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,
|
||||
0, 0, 16, 16, CAMMY_PHOTO_WIDTH, CAMMY_PHOTO_HEIGHT);
|
||||
|
||||
free(dest);
|
||||
|
||||
cammy_image_close(src);
|
||||
|
||||
cammy_sram_close(sram);
|
||||
|
||||
return 0;
|
||||
|
||||
error_sram_open:
|
||||
error_malloc_dest:
|
||||
cammy_image_close(src);
|
||||
|
||||
error_image_open_tile:
|
||||
cammy_sram_close(sram);
|
||||
|
||||
error_sram_open:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,13 +74,13 @@ void cammy_image_merge_tiles(uint8_t *dest,
|
|||
size_t height,
|
||||
int depth);
|
||||
|
||||
void cammy_image_tile_copy(cammy_tile *dest,
|
||||
cammy_tile *src,
|
||||
size_t x_dest,
|
||||
size_t y_dest,
|
||||
size_t x_src,
|
||||
size_t y_src,
|
||||
size_t width,
|
||||
size_t height);
|
||||
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);
|
||||
|
||||
#endif /* _CAMMY_IMAGE_H */
|
||||
|
|
20
src/image.c
20
src/image.c
|
@ -102,8 +102,7 @@ static inline uint8_t tile_read(cammy_tile *tiles,
|
|||
|
||||
return
|
||||
((tile->data[ tile_y<<1] & (0x80 >> tile_x)) >> (tile_x ^ 7)
|
||||
| ((tile->data[(tile_y<<1)|1] & (0x80 >> tile_x)) >> (tile_x ^ 7) << 1))
|
||||
^ 3;
|
||||
| ((tile->data[(tile_y<<1)|1] & (0x80 >> tile_x)) >> (tile_x ^ 7) << 1));
|
||||
}
|
||||
|
||||
static inline void tile_write(cammy_tile *tiles,
|
||||
|
@ -116,6 +115,9 @@ static inline void tile_write(cammy_tile *tiles,
|
|||
int tile_x = x & 7,
|
||||
tile_y = y & 7;
|
||||
|
||||
tile->data[ tile_y<<1] &= ~(1 << (tile_x ^ 7));
|
||||
tile->data[(tile_y<<1)|1] &= ~(1 << (tile_x ^ 7));
|
||||
|
||||
tile->data[ tile_y<<1] |= (value & 0x01) << (tile_x ^ 7);
|
||||
tile->data[(tile_y<<1)|1] |= ((value & 0x02) >> 1) << (tile_x ^ 7);
|
||||
}
|
||||
|
@ -232,7 +234,7 @@ void cammy_image_split_to_tiles(cammy_tile *destr,
|
|||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
uint8_t r, g, b;
|
||||
|
||||
|
||||
buf_read(src, x, y, width, &r, &g, &b, depth);
|
||||
|
||||
tile_write(destr, x, y, width, rgb_to_tile_2bpp(r, r, r, x, y) ^ 3);
|
||||
|
@ -252,7 +254,7 @@ void cammy_image_copy_from_tile(uint8_t *dest,
|
|||
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
uint8_t value = tile_read(src, x, y, width);
|
||||
uint8_t value = tile_read(src, x, y, width) ^ 3;
|
||||
|
||||
buf_write(dest, x, y, width, palette->colors[value][0],
|
||||
palette->colors[value][1],
|
||||
|
@ -292,9 +294,9 @@ void cammy_image_merge_tiles(uint8_t *dest,
|
|||
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
uint8_t r = tile_read(srcr, x, y, width),
|
||||
g = tile_read(srcg, x, y, width),
|
||||
b = tile_read(srcb, x, y, width);
|
||||
uint8_t r = tile_read(srcr, x, y, width) ^ 3,
|
||||
g = tile_read(srcg, x, y, width) ^ 3,
|
||||
b = tile_read(srcb, x, y, width) ^ 3;
|
||||
|
||||
buf_write(dest, x, y, width, level_2bpp_to_8bpp[r],
|
||||
level_2bpp_to_8bpp[g],
|
||||
|
@ -314,6 +316,10 @@ void cammy_image_copy(cammy_image *dest,
|
|||
size_t x_offset,
|
||||
y_offset;
|
||||
|
||||
if (dest->format != CAMMY_IMAGE_TILE || src->format != CAMMY_IMAGE_TILE) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (y_offset=0; y_offset<height; y_offset++) {
|
||||
if (y_dest + y_offset > dest->height) {
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue