From a3d05649045c95e27a7342577106cff3397ade1a Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Sat, 18 Mar 2017 08:39:47 +0100 Subject: [PATCH] Corrected a few more things. --- include/libg1m/format/std.h | 2 +- include/libg1m/picture.h | 26 ++++++++++++++++---------- src/decode/std/addin.c | 4 ++-- src/manage/handle.c | 1 + src/type/std.c | 25 +++++++++++++++++++------ src/utils/picture.c | 15 ++++++++++++++- 6 files changed, 53 insertions(+), 20 deletions(-) diff --git a/include/libg1m/format/std.h b/include/libg1m/format/std.h index f25e7b8..7e91ad8 100644 --- a/include/libg1m/format/std.h +++ b/include/libg1m/format/std.h @@ -195,7 +195,7 @@ struct _classpad_subheader { uint8_t _unknown3[0xC54]; }; -/* Also, if there is a Standard Subheader, there is a footer at the end of the +/* Also, if the platform is the Prizm, there is a footer at the end of the * file, which is only made of a 32-bit checksum that should be equal to * the subheader checksum. * diff --git a/include/libg1m/picture.h b/include/libg1m/picture.h index e7f5d73..58ecc59 100644 --- a/include/libg1m/picture.h +++ b/include/libg1m/picture.h @@ -24,22 +24,28 @@ extern "C" { /* picture format */ typedef int g1m_pictureformat_t; -# define g1m_pictureformat_1bit_packed 0x0101 -# define g1m_pictureformat_1bit_reverse 0x0102 -# define g1m_pictureformat_2bit_dual 0x0201 -# define g1m_pictureformat_4bit_rgb 0x0401 -# define g1m_pictureformat_4bit_code 0x0402 -# define g1m_pictureformat_4bit_color 0x0403 -# define g1m_pictureformat_4bit_mono 0x0404 -# define g1m_pictureformat_16bit 0x1000 +# define g1m_pictureformat_1bit 0x0100 +# define g1m_pictureformat_1bit_packed 0x0110 +# define g1m_pictureformat_1bit_packed_r 0x0111 +# define g1m_pictureformat_1bit_packed_old 0x0120 +# define g1m_pictureformat_2bit_dual 0x0200 +# define g1m_pictureformat_4bit_rgb 0x0400 +# define g1m_pictureformat_4bit_code 0x0410 +# define g1m_pictureformat_4bit_color 0x0420 +# define g1m_pictureformat_4bit_mono 0x0430 +# define g1m_pictureformat_16bit 0x1000 /* get size of the raw buffer */ +# define g1m_picturesize_1bit(W, H) \ + ((((W) / 8) + !!((W) % 8)) * (H)) # define g1m_picturesize_1bit_packed(W, H) \ ((W) * (H) / 8) -# define g1m_picturesize_1bit_reverse(W, H) \ +# define g1m_picturesize_1bit_packed_r(W, H) \ + g1m_picturesize_1bit_packed(W, H) +# define g1m_picturesize_1bit_packed_old(W, H) \ g1m_picturesize_1bit_packed(W, H) # define g1m_picturesize_4bit_color(W, H) \ - (4 * g1m_picturesize_1bit_reverse(W, H)) + (4 * g1m_picturesize_1bit_packed_old(W, H)) # define g1m_picturesize_4bit_mono(W, H) \ g1m_picturesize_4bit_color(W, H) diff --git a/src/decode/std/addin.c b/src/decode/std/addin.c index 0094fe4..5f67ffb 100644 --- a/src/decode/std/addin.c +++ b/src/decode/std/addin.c @@ -64,7 +64,7 @@ int g1m_decode_std_addin(g1m_t **h, g1m_buffer_t *buffer, /* fill icon */ g1m_decode_picture(handle->icon_unsel, g1m_pictureformat_1bit_packed, hd.icon, handle->width, handle->height); - g1m_decode_picture(handle->icon_sel, g1m_pictureformat_1bit_packed, + g1m_decode_picture(handle->icon_sel, g1m_pictureformat_1bit_packed_r, hd.icon, handle->width, handle->height); /* skip size */ @@ -117,7 +117,7 @@ int g1m_decode_std_cp_addin(g1m_t **h, g1m_buffer_t *buffer, /* decode pictures */ g1m_decode_picture(handle->icon_unsel, g1m_pictureformat_1bit_packed, cphd.icon, handle->width, handle->height); - g1m_decode_picture(handle->icon_sel, g1m_pictureformat_1bit_packed, + g1m_decode_picture(handle->icon_sel, g1m_pictureformat_1bit_packed_r, cphd.icon, handle->width, handle->height); /* log */ diff --git a/src/manage/handle.c b/src/manage/handle.c index 8b3889f..04620f5 100644 --- a/src/manage/handle.c +++ b/src/manage/handle.c @@ -40,6 +40,7 @@ int g1m_make_picture(g1m_t **h, unsigned int width, unsigned int height) memset(handle, 0, sizeof(g1m_t)); /* allocate the pixels */ + handle->type = g1m_type_picture; handle->width = width; handle->height = height; handle->pixels = alloc_pixels(width, height); diff --git a/src/type/std.c b/src/type/std.c index 3323601..93aeff9 100644 --- a/src/type/std.c +++ b/src/type/std.c @@ -129,13 +129,26 @@ struct ext_corresp { /* Extension correspondances */ static struct ext_corresp ext_types[] = { - /* fx types with non-checked header */ - {"g1l", "fx language file", g1m_platform_fx, g1m_type_lang, 0}, - {"g1n", "fx fkeys file", g1m_platform_fx, g1m_type_fkey, 0}, + /* fx types */ + {"g1l", "fx language file", g1m_platform_fx, g1m_type_lang, 0}, + {"g1n", "fx fkeys file", g1m_platform_fx, g1m_type_fkey, 0}, + {"g1m", "fx mcs archive", g1m_platform_fx, g1m_type_mcs, 0}, + {"g1r", "fx mcs backup", g1m_platform_fx, g1m_type_mcs, 0}, + {"g2m", "fx OS2 mcs archive", g1m_platform_fx, g1m_type_mcs, 0}, + {"g2r", "fx OS2 mcs backup", g1m_platform_fx, g1m_type_mcs, 0}, + {"g1a", "fx add-in", g1m_platform_fx, g1m_type_addin, 0}, + {"g1e", "fx e-activity", g1m_platform_fx, g1m_type_eact, 0}, - /* cg types with non-checked header */ - {"g3l", "fx-CG language file", g1m_platform_cg, g1m_type_lang, f_sub}, - {"g3n", "fx-CG fkeys file", g1m_platform_cg, g1m_type_fkey, f_sub}, + /* fx-CP types */ + {"c2p", "classpad picture", g1m_platform_cp, g1m_type_pict, 0}, + {"c1a", "classpad add-in", g1m_platform_cp, g1m_type_addin, f_sub}, + + /* fx-CG types */ + {"g3l", "fx-CG language file", g1m_platform_cg, g1m_type_lang, f_sub}, + {"g3n", "fx-CG fkeys file", g1m_platform_cg, g1m_type_fkey, f_sub}, + {"g3a", "fx-CG add-in", g1m_platform_cg, g1m_type_addin, f_sub}, + {"g3e", "fx-CG e-activity", g1m_platform_cg, g1m_type_eact, 0}, + {"g3p", "fx-CG picture", g1m_platform_cg, g1m_type_pict, 0}, /* sentinel */ {NULL, NULL, 0, 0, 0} diff --git a/src/utils/picture.c b/src/utils/picture.c index 3086692..60fe2ae 100644 --- a/src/utils/picture.c +++ b/src/utils/picture.c @@ -73,7 +73,20 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, } break; - case g1m_pictureformat_1bit_reverse: + case g1m_pictureformat_1bit_packed_r: + msk = 0x80; + for (unsigned int y = 0; y < height; y++) + for (unsigned int x = 0; x < width; x++) { + /* get pixel */ + pixels[y][x] = (*raw & msk) ? 0xFFFFFF : 0x000000; + + /* go to next */ + raw += msk & 1; + msk = (msk >> 1) | ((msk & 1) << 7); + } + break; + + case g1m_pictureformat_1bit_packed_old: for (unsigned int bx = width - 8; bx != (unsigned int)-8; bx -= 8) for (unsigned int y = height - 1; y != (unsigned int)-1; y--) { msk = 0x80;