diff options
author | red031000 <rubenru09@aol.com> | 2020-07-12 18:36:54 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-07-12 18:36:54 +0100 |
commit | a604bc3b573e2f23bb0eb40e0fc8946b857d6c98 (patch) | |
tree | d96c88f0831353b695ee21e492896d5f618ca819 /tools | |
parent | 5f114f5c8413da73f21c9adbfd0165921314e275 (diff) |
fix palette issues, demo/title/titledemo narc fully converted
Diffstat (limited to 'tools')
-rw-r--r-- | tools/nitrogfx/gfx.c | 19 | ||||
-rw-r--r-- | tools/nitrogfx/gfx.h | 4 | ||||
-rw-r--r-- | tools/nitrogfx/main.c | 48 |
3 files changed, 57 insertions, 14 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 4e529490..8f943698 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -453,10 +453,10 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in sopcBuffer[12] = tilesWidth & 0xFF; sopcBuffer[13] = (tilesWidth >> 8) & 0xFF; - sopcBuffer[14] = tilesHeight & 0xFF; - sopcBuffer[15] = (tilesHeight >> 8) & 0xFF; + sopcBuffer[14] = tilesHeight & 0xFF; + sopcBuffer[15] = (tilesHeight >> 8) & 0xFF; - fwrite(sopcBuffer, 1, 0x10, fp); + fwrite(sopcBuffer, 1, 0x10, fp); } free(pixelBuffer); @@ -489,7 +489,7 @@ void ReadGbaPalette(char *path, struct Palette *palette) free(data); } -void ReadNtrPalette(char *path, struct Palette *palette) +void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth) { int fileSize; unsigned char *data = ReadWholeFile(path, &fileSize); @@ -511,7 +511,9 @@ void ReadNtrPalette(char *path, struct Palette *palette) palette->bitDepth = paletteHeader[0x8] == 3 ? 4 : 8; - palette->numColors = palette->bitDepth == 4 ? 16 : 256; //remove header and divide by 2 + bitdepth = bitdepth ? bitdepth : palette->bitDepth; + + palette->numColors = bitdepth == 4 ? 16 : 256; //remove header and divide by 2 unsigned char *paletteData = paletteHeader + 0x18; @@ -547,7 +549,7 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir) +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth) { FILE *fp = fopen(path, "wb"); @@ -574,8 +576,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir) if (!palette->bitDepth) palette->bitDepth = 4; + + bitdepth = bitdepth ? bitdepth : palette->bitDepth; + //bit depth - palHeader[8] = palette->bitDepth == 4 ? 0x03: 0x04; + palHeader[8] = bitdepth == 4 ? 0x03: 0x04; //size palHeader[16] = size & 0xFF; diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index 54e6fb16..e5189100 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -34,8 +34,8 @@ 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); void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); -void ReadNtrPalette(char *path, struct Palette *palette); +void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth); void WriteGbaPalette(char *path, struct Palette *palette); -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir); +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 0aaad201..188bdf0a 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); + ReadNtrPalette(options->paletteFilePath, &image.palette, options->bitDepth); image.hasPalette = true; } else @@ -437,7 +437,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c } ReadPngPalette(inputPath, &palette); - WriteNtrPalette(outputPath, &palette, ncpr, ir); + WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth); } void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -448,11 +448,35 @@ void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc U WriteJascPalette(outputPath, &palette); } -void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) +void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) { struct Palette palette; + int bitdepth = 0; - ReadNtrPalette(inputPath, &palette); + for (int i = 3; i < argc; i++) + { + char *option = argv[i]; + + if (strcmp(option, "-bitdepth") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No bitdepth following \"-bitdepth\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &bitdepth)) + FATAL_ERROR("Failed to parse bitdepth.\n"); + + if (bitdepth != 4 && bitdepth != 8) + FATAL_ERROR("Bitdepth must be 4 or 8.\n"); + } + else + { + FATAL_ERROR("Unrecognized option \"%s\".\n", option); + } + } + + ReadNtrPalette(inputPath, &palette, bitdepth); WriteJascPalette(outputPath, &palette); } @@ -498,6 +522,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, int numColors = 0; bool ncpr = false; bool ir = false; + int bitdepth = 0; for (int i = 3; i < argc; i++) { @@ -516,6 +541,19 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (numColors < 1) FATAL_ERROR("Number of colors must be positive.\n"); } + if (strcmp(option, "-bitdepth") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No bitdepth following \"-bitdepth\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &bitdepth)) + FATAL_ERROR("Failed to parse bitdepth.\n"); + + if (bitdepth != 4 && bitdepth != 8) + FATAL_ERROR("Bitdepth must be 4 or 8.\n"); + } else if (strcmp(option, "-ncpr") == 0) { ncpr = true; @@ -537,7 +575,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (numColors != 0) palette.numColors = numColors; - WriteNtrPalette(outputPath, &palette, ncpr, ir); + WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) |