diff options
-rw-r--r-- | files/data/dp_areawindow.ncpr (renamed from files/data/dp_areawindow.NCLR) | bin | 552 -> 552 bytes | |||
-rw-r--r-- | tools/nitrogfx/gfx.c | 71 | ||||
-rw-r--r-- | tools/nitrogfx/gfx.h | 3 | ||||
-rw-r--r-- | tools/nitrogfx/main.c | 45 | ||||
-rw-r--r-- | tools/nitrogfx/util.c | 14 | ||||
-rw-r--r-- | tools/nitrogfx/util.h | 2 |
6 files changed, 123 insertions, 12 deletions
diff --git a/files/data/dp_areawindow.NCLR b/files/data/dp_areawindow.ncpr Binary files differindex cb93762b..cb93762b 100644 --- a/files/data/dp_areawindow.NCLR +++ b/files/data/dp_areawindow.ncpr diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index bb6ff442..8a10efe2 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -328,8 +328,8 @@ void ReadNtrPalette(char *path, struct Palette *palette) unsigned char *data = ReadWholeFile(path, &fileSize); uint32_t magicNumber = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]; - if (magicNumber != 0x4E434C52) //NCLR - FATAL_ERROR("Not a valid NCLR palette file. Magic number (%x).\n", magicNumber); + if (magicNumber != 0x4E434C52 && magicNumber != 0x4E435052) //NCLR / NCPR + FATAL_ERROR("Not a valid NCLR or NCPR palette file. Magic number (%x).\n", magicNumber); unsigned char *paletteHeader = data + 0x10; @@ -376,7 +376,7 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } -void WriteNtrPalette(char *path, struct Palette *palette) +void WriteNtrNCLRPalette(char *path, struct Palette *palette) { FILE *fp = fopen(path, "wb"); @@ -387,7 +387,70 @@ void WriteNtrPalette(char *path, struct Palette *palette) uint32_t extSize = size + 0x18; //NCLR header - WriteGenericNtrHeader(fp, "RLCN", extSize); + WriteGenericNtrHeader(fp, "RLCN", extSize, true); + + //PLTT header + //magic number + fputs("TTLP", fp); + + //section size + fputc(extSize & 0xFF, fp); + fputc((extSize >> 8) & 0xFF, fp); + fputc((extSize >> 16) & 0xFF, fp); + fputc((extSize >> 24) & 0xFF, fp); + + //bit depth + char bitDepth = palette->bitDepth == 4 ? 0x03: 0x04; + fputc(bitDepth, fp); + fputc(0x00, fp); + fputc(0x00, fp); + fputc(0x00, fp); + + //padding + fputc(0x00, fp); + fputc(0x00, fp); + fputc(0x00, fp); + fputc(0x00, fp); + + //size + fputc(size & 0xFF, fp); + fputc((size >> 8) & 0xFF, fp); + fputc((size >> 16) & 0xFF, fp); + fputc((size >> 24) & 0xFF, fp); + + //colours per palette + fputc(0x10, fp); + fputc(0x00, fp); + fputc(0x00, fp); + fputc(0x00, fp); + + //palette data + for (int i = 0; i < palette->numColors; i++) { + unsigned char red = DOWNCONVERT_BIT_DEPTH(palette->colors[i].red); + unsigned char green = DOWNCONVERT_BIT_DEPTH(palette->colors[i].green); + unsigned char blue = DOWNCONVERT_BIT_DEPTH(palette->colors[i].blue); + + uint16_t paletteEntry = SET_GBA_PAL(red, green, blue); + + fputc(paletteEntry & 0xFF, fp); + fputc(paletteEntry >> 8, fp); + } + + fclose(fp); +} + +void WriteNtrNCPRPalette(char *path, struct Palette *palette) +{ + FILE *fp = fopen(path, "wb"); + + if (fp == NULL) + FATAL_ERROR("Failed too open \"%s\" for writing.\n", path); + + uint32_t size = palette->numColors * 2; + uint32_t extSize = size + 0x10; + + //NCLR header + WriteGenericNtrHeader(fp, "RPCN", extSize, false); //PLTT header //magic number diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index c563a2dc..06adca79 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -34,6 +34,7 @@ void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); void ReadNtrPalette(char *path, struct Palette *palette); void WriteGbaPalette(char *path, struct Palette *palette); -void WriteNtrPalette(char *path, struct Palette *palette); +void WriteNtrNCLRPalette(char *path, struct Palette *palette); +void WriteNtrNCPRPalette(char *path, struct Palette *palette); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 07083234..1c7fc1e1 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -371,7 +371,7 @@ void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc, WriteGbaPalette(outputPath, &palette); } -void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) +void HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) { int numColors = 0; @@ -405,7 +405,44 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (numColors != 0) palette.numColors = numColors; - WriteNtrPalette(outputPath, &palette); + WriteNtrNCLRPalette(outputPath, &palette); +} + +void HandleJascToNtrNCPRPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) +{ + int numColors = 0; + + for (int i = 3; i < argc; i++) + { + char *option = argv[i]; + + if (strcmp(option, "-num_colors") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No number of colors following \"-num_colors\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &numColors)) + FATAL_ERROR("Failed to parse number of colors.\n"); + + if (numColors < 1) + FATAL_ERROR("Number of colors must be positive.\n"); + } + else + { + FATAL_ERROR("Unrecognized option \"%s\".\n", option); + } + } + + struct Palette palette; + + ReadJascPalette(inputPath, &palette); + + if (numColors != 0) + palette.numColors = numColors; + + WriteNtrNCPRPalette(outputPath, &palette); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -656,8 +693,10 @@ int main(int argc, char **argv) { "png", "gbapal", HandlePngToGbaPaletteCommand }, { "gbapal", "pal", HandleGbaToJascPaletteCommand }, { "nclr", "pal", HandleNtrToJascPaletteCommand }, + { "ncpr", "pal", HandleNtrToJascPaletteCommand }, { "pal", "gbapal", HandleJascToGbaPaletteCommand }, - { "pal", "nclr", HandleJascToNtrPaletteCommand }, + { "pal", "nclr", HandleJascToNtrNCLRPaletteCommand }, + { "pal", "ncpr", HandleJascToNtrNCPRPaletteCommand }, { "latfont", "png", HandleLatinFontToPngCommand }, { "png", "latfont", HandlePngToLatinFontCommand }, { "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand }, diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index 8fec7d72..ab65aa7a 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -124,14 +124,22 @@ void WriteWholeFile(char *path, void *buffer, int bufferSize) fclose(fp); } -void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size) +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder) { //magic number fputs(magicNumber, fp); //byte order - fputc(0xFF, fp); - fputc(0xFE, fp); + if (byteorder) + { + fputc(0xFF, fp); //LE + fputc(0xFE, fp); + } + else + { + fputc(0x00, fp); + fputc(0x00, fp); + } //version fputc(0x00, fp); diff --git a/tools/nitrogfx/util.h b/tools/nitrogfx/util.h index a220ba81..f181b66e 100644 --- a/tools/nitrogfx/util.h +++ b/tools/nitrogfx/util.h @@ -11,6 +11,6 @@ char *GetFileExtension(char *path); unsigned char *ReadWholeFile(char *path, int *size); unsigned char *ReadWholeFileZeroPadded(char *path, int *size, int padAmount); void WriteWholeFile(char *path, void *buffer, int bufferSize); -void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size); +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder); #endif // UTIL_H |