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 | |
parent | bd54199157769c90be156ba1c9a46a2ab6f37c30 (diff) |
palette indexes
-rw-r--r-- | tools/nitrogfx/gfx.c | 22 | ||||
-rw-r--r-- | tools/nitrogfx/gfx.h | 2 | ||||
-rw-r--r-- | tools/nitrogfx/main.c | 18 | ||||
-rw-r--r-- | tools/nitrogfx/options.h | 1 |
4 files changed, 34 insertions, 9 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); diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index ef1f493d..e04a781a 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -34,7 +34,7 @@ void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int m void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc, bool scanned, uint32_t key); void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); -void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth); +void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex); void WriteGbaPalette(char *path, struct Palette *palette); void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum); diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 942b0d90..35f59d0b 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -50,7 +50,7 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * if (options->paletteFilePath != NULL) { - ReadNtrPalette(options->paletteFilePath, &image.palette, options->bitDepth); + ReadNtrPalette(options->paletteFilePath, &image.palette, options->bitDepth, options->palIndex); image.hasPalette = true; } else @@ -205,6 +205,7 @@ void HandleNtrToPngCommand(char *inputPath, char *outputPath, int argc, char **a options.width = 1; options.metatileWidth = 1; options.metatileHeight = 1; + options.palIndex = 1; for (int i = 3; i < argc; i++) { @@ -223,6 +224,19 @@ void HandleNtrToPngCommand(char *inputPath, char *outputPath, int argc, char **a { options.hasTransparency = true; } + else if (strcmp(option, "-palindex") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No palette index following \"-palindex\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &options.palIndex)) + FATAL_ERROR("Failed to parse palette index.\n"); + + if (options.width < 1) + FATAL_ERROR("Palette index must be positive.\n"); + } else if (strcmp(option, "-width") == 0) { if (i + 1 >= argc) @@ -539,7 +553,7 @@ void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc, } } - ReadNtrPalette(inputPath, &palette, bitdepth); + ReadNtrPalette(inputPath, &palette, bitdepth, 1); WriteJascPalette(outputPath, &palette); } diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h index b03bd561..8c1e7a0e 100644 --- a/tools/nitrogfx/options.h +++ b/tools/nitrogfx/options.h @@ -12,6 +12,7 @@ struct GbaToPngOptions { int width; int metatileWidth; int metatileHeight; + int palIndex; }; struct PngToGbaOptions { |