diff options
author | red031000 <rubenru09@aol.com> | 2020-07-13 13:54:04 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-07-13 14:30:16 +0100 |
commit | 7245b56b693f1cccc8e2809ca650af6790c5c1ce (patch) | |
tree | ed5ffe111dabb4b53b659265275d895c0079b281 | |
parent | 6ebca13d4c5a290e239364f90bf137c12f332a13 (diff) |
palette padding changes
-rw-r--r-- | tools/nitrogfx/gfx.c | 21 | ||||
-rw-r--r-- | tools/nitrogfx/gfx.h | 2 | ||||
-rw-r--r-- | tools/nitrogfx/main.c | 44 |
3 files changed, 56 insertions, 11 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 8f943698..7c57d269 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -549,14 +549,16 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth) +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum) { FILE *fp = fopen(path, "wb"); if (fp == NULL) FATAL_ERROR("Failed to open \"%s\" for writing.\n", path); - uint32_t size = 256 * 2; //todo check if there's a better way to detect :/ + int colourNum = pad ? 256 : 16; + + uint32_t size = colourNum * 2; //todo check if there's a better way to detect :/ uint32_t extSize = size + (ncpr ? 0x10 : 0x18); //NCLR header @@ -582,6 +584,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in //bit depth palHeader[8] = bitdepth == 4 ? 0x03: 0x04; + if (compNum) + { + palHeader[10] = compNum; //assuming this is an indicator of compression, literally no docs for it though + } + //size palHeader[16] = size & 0xFF; palHeader[17] = (size >> 8) & 0xFF; @@ -590,9 +597,9 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in fwrite(palHeader, 1, 0x18, fp); - unsigned char colours[256 * 2]; + unsigned char colours[colourNum * 2]; //palette data - for (int i = 0; i < 256; i++) + for (int i = 0; i < colourNum; i++) { if (i < palette->numColors) { @@ -614,11 +621,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in if (ir) { - colours[510] = 'I'; - colours[511] = 'R'; + colours[colourNum * 2 - 2] = 'I'; + colours[colourNum * 2 - 1] = 'R'; } - fwrite(colours, 1, 256 * 2, fp); + fwrite(colours, 1, colourNum * 2, fp); fclose(fp); } diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index e5189100..f833ac2e 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -36,6 +36,6 @@ void FreeImage(struct Image *image); void ReadGbaPalette(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, int bitdepth); +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 188bdf0a..12521517 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -417,6 +417,8 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c struct Palette palette; bool ncpr = false; bool ir = false; + bool nopad = false; + int compNum; for (int i = 3; i < argc; i++) { @@ -430,6 +432,23 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c { ir = true; } + else if (strcmp(option, "-nopad") == 0) + { + nopad = true; + } + if (strcmp(option, "-comp") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No compression value following \"-comp\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &compNum)) + FATAL_ERROR("Failed to parse compression value.\n"); + + if (compNum > 255) + FATAL_ERROR("Compression value must be 255 or below.\n"); + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -437,7 +456,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c } ReadPngPalette(inputPath, &palette); - WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth); + WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth, !nopad, compNum); } void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -522,7 +541,9 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, int numColors = 0; bool ncpr = false; bool ir = false; + bool nopad = false; int bitdepth = 0; + int compNum = 0; for (int i = 3; i < argc; i++) { @@ -541,7 +562,7 @@ 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) + else if (strcmp(option, "-bitdepth") == 0) { if (i + 1 >= argc) FATAL_ERROR("No bitdepth following \"-bitdepth\".\n"); @@ -554,6 +575,19 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (bitdepth != 4 && bitdepth != 8) FATAL_ERROR("Bitdepth must be 4 or 8.\n"); } + else if (strcmp(option, "-comp") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No compression value following \"-comp\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &compNum)) + FATAL_ERROR("Failed to parse compression value.\n"); + + if (compNum > 255) + FATAL_ERROR("Compression value must be 255 or below.\n"); + } else if (strcmp(option, "-ncpr") == 0) { ncpr = true; @@ -562,6 +596,10 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, { ir = true; } + else if (strcmp(option, "-nopad") == 0) + { + nopad = true; + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -575,7 +613,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (numColors != 0) palette.numColors = numColors; - WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth); + WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) |