diff options
author | red031000 <rubenru09@aol.com> | 2020-07-19 16:58:24 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-07-19 16:58:24 +0100 |
commit | 0791e26907187bfe5017f113bdab552d52fe3a12 (patch) | |
tree | 4bc71d52cf25c85c2e15d0f5323cb093cc16e7d3 /tools/nitrogfx/gfx.c | |
parent | bd54199157769c90be156ba1c9a46a2ab6f37c30 (diff) |
palette indexes
Diffstat (limited to 'tools/nitrogfx/gfx.c')
-rw-r--r-- | tools/nitrogfx/gfx.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index c1be2a36..1f414ad7 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -586,7 +586,7 @@ void ReadGbaPalette(char *path, struct Palette *palette) free(data); } -void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth) +void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex) { int fileSize; unsigned char *data = ReadWholeFile(path, &fileSize); @@ -613,13 +613,23 @@ void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth) palette->numColors = bitdepth == 4 ? 16 : 256; //remove header and divide by 2 unsigned char *paletteData = paletteHeader + 0x18; + palIndex = palIndex - 1; - for (int i = 0; i < palette->numColors; i++) + for (int i = 0; i < 256; i++) { - uint16_t paletteEntry = (paletteData[i * 2 + 1] << 8) | paletteData[i * 2]; - palette->colors[i].red = UPCONVERT_BIT_DEPTH(GET_GBA_PAL_RED(paletteEntry)); - palette->colors[i].green = UPCONVERT_BIT_DEPTH(GET_GBA_PAL_GREEN(paletteEntry)); - palette->colors[i].blue = UPCONVERT_BIT_DEPTH(GET_GBA_PAL_BLUE(paletteEntry)); + if (i < palette->numColors) + { + uint16_t paletteEntry = (paletteData[(32 * palIndex) + i * 2 + 1] << 8) | paletteData[(32 * palIndex) + i * 2]; + palette->colors[i].red = UPCONVERT_BIT_DEPTH(GET_GBA_PAL_RED(paletteEntry)); + palette->colors[i].green = UPCONVERT_BIT_DEPTH(GET_GBA_PAL_GREEN(paletteEntry)); + palette->colors[i].blue = UPCONVERT_BIT_DEPTH(GET_GBA_PAL_BLUE(paletteEntry)); + } + else + { + palette->colors[i].red = 0; + palette->colors[i].green = 0; + palette->colors[i].blue = 0; + } } free(data); |