From cc5a1e59920fe0ed975af40aa49b7870832323af Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 6 Jun 2020 23:58:19 +0100 Subject: palette conversion --- tools/narccomp/.gitignore | 1 + tools/nitrogfx/gfx.c | 95 +++++++++++++++++++++++++++ tools/nitrogfx/gfx.h | 2 + tools/nitrogfx/main.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++ tools/nitrogfx/util.c | 30 +++++++++ tools/nitrogfx/util.h | 2 + 6 files changed, 291 insertions(+) create mode 100644 tools/narccomp/.gitignore diff --git a/tools/narccomp/.gitignore b/tools/narccomp/.gitignore new file mode 100644 index 00000000..e96a03a5 --- /dev/null +++ b/tools/narccomp/.gitignore @@ -0,0 +1 @@ +narccomp diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index f927deed..25c346db 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -322,6 +322,39 @@ void ReadGbaPalette(char *path, struct Palette *palette) free(data); } +void ReadNtrPalette(char *path, struct Palette *palette) +{ + int fileSize; + 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); + + unsigned char *paletteHeader = data + 0x10; + + magicNumber = (paletteHeader[3] << 24) | (paletteHeader[2] << 16) | (paletteHeader[1] << 8) | paletteHeader[0]; + if (magicNumber != 0x504C5454) //PLTT + FATAL_ERROR("No valid PLTT file after NCLR header. Magic number (%x).\n", magicNumber); + + if ((fileSize - 0x28) % 2 != 0) + FATAL_ERROR("The file size (%d) is not a multiple of 2.\n", fileSize); + + palette->numColors = (fileSize - 0x28) / 2; //remove header and divide by 2 + + unsigned char *paletteData = paletteHeader + 0x18; + + for (int i = 0; i < palette->numColors; 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)); + } + + free(data); +} + void WriteGbaPalette(char *path, struct Palette *palette) { FILE *fp = fopen(path, "wb"); @@ -342,3 +375,65 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } + +void WriteNtrPalette(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 + 0x18; + + //NCLR header + WriteGenericNtrHeader(fp, "RLCN", extSize); + + //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 + fputc(0x03, fp); //todo figure out a way to determine bit depth + 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); +} diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index 5355ced8..d5241509 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -31,6 +31,8 @@ void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); 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); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index b9f4272c..07083234 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -44,6 +44,39 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * FreeImage(&image); } +void ConvertNtrToPng(char *inputPath UNUSED, char *outputPath UNUSED, struct GbaToPngOptions *options) //todo finish +{ + struct Image image; + + if (options->paletteFilePath != NULL) + { + ReadNtrPalette(options->paletteFilePath, &image.palette); + image.hasPalette = true; + } + else + { + image.hasPalette = false; + } + + if (image.hasPalette) + { + printf("Image has palette!\n"); + printf("Colours: %d\n", image.palette.numColors); + for (int i = 0; i < image.palette.numColors; i++) + { + printf("Red: %d ", image.palette.colors[i].red); + printf("Green: %d ", image.palette.colors[i].green); + printf("Blue: %d\n", image.palette.colors[i].blue); + } + } + else + { + printf("No palette detected!\n"); + } + + FreeImage(&image); +} + void ConvertPngToGba(char *inputPath, char *outputPath, struct PngToGbaOptions *options) { struct Image image; @@ -198,6 +231,85 @@ void HandlePngToGbaCommand(char *inputPath, char *outputPath, int argc, char **a ConvertPngToGba(inputPath, outputPath, &options); } +void HandleNtrToPngCommand(char *inputPath, char *outputPath, int argc, char **argv) +{ + //char *inputFileExtension = GetFileExtension(inputPath); + struct GbaToPngOptions options; + options.paletteFilePath = NULL; + options.bitDepth = 4; //todo read from header + options.hasTransparency = false; + options.width = 1; + options.metatileWidth = 1; + options.metatileHeight = 1; + + for (int i = 3; i < argc; i++) + { + char *option = argv[i]; + + if (strcmp(option, "-palette") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No palette file path following \"-palette\".\n"); + + i++; + + options.paletteFilePath = argv[i]; + } + else if (strcmp(option, "-object") == 0) + { + options.hasTransparency = true; + } + else if (strcmp(option, "-width") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No width following \"-width\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &options.width)) + FATAL_ERROR("Failed to parse width.\n"); + + if (options.width < 1) + FATAL_ERROR("Width must be positive.\n"); + } + else if (strcmp(option, "-mwidth") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No metatile width value following \"-mwidth\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &options.metatileWidth)) + FATAL_ERROR("Failed to parse metatile width.\n"); + + if (options.metatileWidth < 1) + FATAL_ERROR("metatile width must be positive.\n"); + } + else if (strcmp(option, "-mheight") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No metatile height value following \"-mheight\".\n"); + + i++; + + if (!ParseNumber(argv[i], NULL, 10, &options.metatileHeight)) + FATAL_ERROR("Failed to parse metatile height.\n"); + + if (options.metatileHeight < 1) + FATAL_ERROR("metatile height must be positive.\n"); + } + else + { + FATAL_ERROR("Unrecognized option \"%s\".\n", option); + } + } + + if (options.metatileWidth > options.width) + options.width = options.metatileWidth; + + ConvertNtrToPng(inputPath, outputPath, &options); +} + void HandlePngToGbaPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) { struct Palette palette; @@ -214,6 +326,14 @@ void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc U WriteJascPalette(outputPath, &palette); } +void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) +{ + struct Palette palette; + + ReadNtrPalette(inputPath, &palette); + WriteJascPalette(outputPath, &palette); +} + void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) { int numColors = 0; @@ -251,6 +371,43 @@ void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc, WriteGbaPalette(outputPath, &palette); } +void HandleJascToNtrPaletteCommand(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; + + WriteNtrPalette(outputPath, &palette); +} + void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) { struct Image image; @@ -491,12 +648,16 @@ int main(int argc, char **argv) { "1bpp", "png", HandleGbaToPngCommand }, { "4bpp", "png", HandleGbaToPngCommand }, { "8bpp", "png", HandleGbaToPngCommand }, + //{ "ncgr", "png", HandleNtrToPngCommand }, { "png", "1bpp", HandlePngToGbaCommand }, { "png", "4bpp", HandlePngToGbaCommand }, { "png", "8bpp", HandlePngToGbaCommand }, + //{ "png", "ncgr", HandlePngToNtrCommand }, { "png", "gbapal", HandlePngToGbaPaletteCommand }, { "gbapal", "pal", HandleGbaToJascPaletteCommand }, + { "nclr", "pal", HandleNtrToJascPaletteCommand }, { "pal", "gbapal", HandleJascToGbaPaletteCommand }, + { "pal", "nclr", HandleJascToNtrPaletteCommand }, { "latfont", "png", HandleLatinFontToPngCommand }, { "png", "latfont", HandlePngToLatinFontCommand }, { "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand }, diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index 87abeb31..8fec7d72 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "global.h" @@ -122,3 +123,32 @@ void WriteWholeFile(char *path, void *buffer, int bufferSize) fclose(fp); } + +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size) +{ + //magic number + fputs(magicNumber, fp); + + //byte order + fputc(0xFF, fp); + fputc(0xFE, fp); + + //version + fputc(0x00, fp); + fputc(0x01, fp); + + //size + size += 0x10; //add header size + fputc(size & 0xFF, fp); + fputc((size >> 8) & 0xFF, fp); + fputc((size >> 16) & 0xFF, fp); + fputc((size >> 24) & 0xFF, fp); + + //header size + fputc(0x10, fp); + fputc(0x00, fp); + + //sections + fputc(0x01, fp); + fputc(0x00, fp); +} \ No newline at end of file diff --git a/tools/nitrogfx/util.h b/tools/nitrogfx/util.h index 6d7a9c21..a220ba81 100644 --- a/tools/nitrogfx/util.h +++ b/tools/nitrogfx/util.h @@ -4,11 +4,13 @@ #define UTIL_H #include +#include bool ParseNumber(char *s, char **end, int radix, int *intValue); 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); #endif // UTIL_H -- cgit v1.2.3 From cc67cafa094351a033f295d054380acc63fddd78 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 15:57:16 +0100 Subject: fix bitdepth --- tools/nitrogfx/gfx.c | 3 ++- tools/nitrogfx/gfx.h | 1 + tools/nitrogfx/jasc_pal.c | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 25c346db..bb6ff442 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -400,7 +400,8 @@ void WriteNtrPalette(char *path, struct Palette *palette) fputc((extSize >> 24) & 0xFF, fp); //bit depth - fputc(0x03, fp); //todo figure out a way to determine bit depth + char bitDepth = palette->bitDepth == 4 ? 0x03: 0x04; + fputc(bitDepth, fp); fputc(0x00, fp); fputc(0x00, fp); fputc(0x00, fp); diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index d5241509..c563a2dc 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -15,6 +15,7 @@ struct Color { struct Palette { struct Color colors[256]; int numColors; + int bitDepth; }; struct Image { diff --git a/tools/nitrogfx/jasc_pal.c b/tools/nitrogfx/jasc_pal.c index e5ba9c3c..4f80f5d9 100644 --- a/tools/nitrogfx/jasc_pal.c +++ b/tools/nitrogfx/jasc_pal.c @@ -91,6 +91,8 @@ void ReadJascPalette(char *path, struct Palette *palette) if (palette->numColors < 1 || palette->numColors > 256) FATAL_ERROR("%d is an invalid number of colors. The number of colors must be in the range [1, 256].\n", palette->numColors); + palette->bitDepth = 4; + for (int i = 0; i < palette->numColors; i++) { ReadJascPaletteLine(fp, line); @@ -146,6 +148,11 @@ void ReadJascPalette(char *path, struct Palette *palette) palette->colors[i].red = red; palette->colors[i].green = green; palette->colors[i].blue = blue; + if (i >= 16) + { + if (red || green || blue) + palette->bitDepth = 8; + } } if (fgetc(fp) != EOF) -- cgit v1.2.3 From 28bffae5bc2b497329e04dbae842d3b6fe3024d8 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 16:46:28 +0100 Subject: ncpr palette support --- files/data/dp_areawindow.NCLR | Bin 552 -> 0 bytes files/data/dp_areawindow.ncpr | Bin 0 -> 552 bytes tools/nitrogfx/gfx.c | 71 +++++++++++++++++++++++++++++++++++++++--- tools/nitrogfx/gfx.h | 3 +- tools/nitrogfx/main.c | 45 ++++++++++++++++++++++++-- tools/nitrogfx/util.c | 14 +++++++-- tools/nitrogfx/util.h | 2 +- 7 files changed, 123 insertions(+), 12 deletions(-) delete mode 100644 files/data/dp_areawindow.NCLR create mode 100644 files/data/dp_areawindow.ncpr diff --git a/files/data/dp_areawindow.NCLR b/files/data/dp_areawindow.NCLR deleted file mode 100644 index cb93762b..00000000 Binary files a/files/data/dp_areawindow.NCLR and /dev/null differ diff --git a/files/data/dp_areawindow.ncpr b/files/data/dp_areawindow.ncpr new file mode 100644 index 00000000..cb93762b Binary files /dev/null and b/files/data/dp_areawindow.ncpr differ 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 -- cgit v1.2.3 From 34aa56f33abb2270f95807baa621be2435829afc Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 16:49:06 +0100 Subject: ncpr to nclr --- files/data/dp_areawindow.nclr | Bin 0 -> 552 bytes files/data/dp_areawindow.ncpr | Bin 552 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 files/data/dp_areawindow.nclr delete mode 100644 files/data/dp_areawindow.ncpr diff --git a/files/data/dp_areawindow.nclr b/files/data/dp_areawindow.nclr new file mode 100644 index 00000000..cb93762b Binary files /dev/null and b/files/data/dp_areawindow.nclr differ diff --git a/files/data/dp_areawindow.ncpr b/files/data/dp_areawindow.ncpr deleted file mode 100644 index cb93762b..00000000 Binary files a/files/data/dp_areawindow.ncpr and /dev/null differ -- cgit v1.2.3 From 76e1f0cc3ae83473d01152202c6b04c2188fac10 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 16:50:56 +0100 Subject: capitalisation --- files/data/dp_areawindow.NCLR | Bin 0 -> 552 bytes files/data/dp_areawindow.nclr | Bin 552 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 files/data/dp_areawindow.NCLR delete mode 100644 files/data/dp_areawindow.nclr diff --git a/files/data/dp_areawindow.NCLR b/files/data/dp_areawindow.NCLR new file mode 100644 index 00000000..cb93762b Binary files /dev/null and b/files/data/dp_areawindow.NCLR differ diff --git a/files/data/dp_areawindow.nclr b/files/data/dp_areawindow.nclr deleted file mode 100644 index cb93762b..00000000 Binary files a/files/data/dp_areawindow.nclr and /dev/null differ -- cgit v1.2.3 From 292a0f16f5492c0b89b11f4eec9bc8397874f9f0 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 17:00:13 +0100 Subject: cleanup ncpr handling --- tools/nitrogfx/main.c | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 1c7fc1e1..64f7e8a5 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -374,6 +374,7 @@ void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc, void HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) { int numColors = 0; + bool ncpr = false; for (int i = 3; i < argc; i++) { @@ -392,42 +393,9 @@ void HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int ar 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; - - 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) + else if (strcmp(option, "-ncpr") == 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"); + ncpr = true; } else { @@ -442,7 +410,10 @@ void HandleJascToNtrNCPRPaletteCommand(char *inputPath, char *outputPath, int ar if (numColors != 0) palette.numColors = numColors; - WriteNtrNCPRPalette(outputPath, &palette); + if (ncpr) + WriteNtrNCPRPalette(outputPath, &palette); + else + WriteNtrNCLRPalette(outputPath, &palette); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -696,7 +667,6 @@ int main(int argc, char **argv) { "ncpr", "pal", HandleNtrToJascPaletteCommand }, { "pal", "gbapal", HandleJascToGbaPaletteCommand }, { "pal", "nclr", HandleJascToNtrNCLRPaletteCommand }, - { "pal", "ncpr", HandleJascToNtrNCPRPaletteCommand }, { "latfont", "png", HandleLatinFontToPngCommand }, { "png", "latfont", HandlePngToLatinFontCommand }, { "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand }, -- cgit v1.2.3 From 6bd0b1970c1b096d9791c8ea1515e0f722fd99a8 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 17:34:32 +0100 Subject: bit of cleanup --- tools/nitrogfx/gfx.c | 69 +++------------------------------------------------ tools/nitrogfx/gfx.h | 3 +-- tools/nitrogfx/main.c | 9 +++---- tools/nitrogfx/util.c | 2 +- 4 files changed, 8 insertions(+), 75 deletions(-) diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 8a10efe2..92483228 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -376,7 +376,7 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } -void WriteNtrNCLRPalette(char *path, struct Palette *palette) +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) { FILE *fp = fopen(path, "wb"); @@ -384,73 +384,10 @@ void WriteNtrNCLRPalette(char *path, struct Palette *palette) FATAL_ERROR("Failed too open \"%s\" for writing.\n", path); uint32_t size = palette->numColors * 2; - uint32_t extSize = size + 0x18; + uint32_t extSize = size + (ncpr ? 0x10 : 0x18); //NCLR header - 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); + WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr); //PLTT header //magic number diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index 06adca79..fc57380e 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -34,7 +34,6 @@ 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 WriteNtrNCLRPalette(char *path, struct Palette *palette); -void WriteNtrNCPRPalette(char *path, struct Palette *palette); +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 64f7e8a5..645a1512 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 HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) +void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) { int numColors = 0; bool ncpr = false; @@ -410,10 +410,7 @@ void HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int ar if (numColors != 0) palette.numColors = numColors; - if (ncpr) - WriteNtrNCPRPalette(outputPath, &palette); - else - WriteNtrNCLRPalette(outputPath, &palette); + WriteNtrPalette(outputPath, &palette, ncpr); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -666,7 +663,7 @@ int main(int argc, char **argv) { "nclr", "pal", HandleNtrToJascPaletteCommand }, { "ncpr", "pal", HandleNtrToJascPaletteCommand }, { "pal", "gbapal", HandleJascToGbaPaletteCommand }, - { "pal", "nclr", HandleJascToNtrNCLRPaletteCommand }, + { "pal", "nclr", HandleJascToNtrPaletteCommand }, { "latfont", "png", HandleLatinFontToPngCommand }, { "png", "latfont", HandlePngToLatinFontCommand }, { "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand }, diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index ab65aa7a..3fd718fb 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -159,4 +159,4 @@ void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, boo //sections fputc(0x01, fp); fputc(0x00, fp); -} \ No newline at end of file +} -- cgit v1.2.3 From 36a3f6f46f384190c214d3e359efa3fe4e1186d8 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 19:33:50 +0100 Subject: cleanup --- tools/nitrogfx/main.c | 120 ++------------------------------------------------ 1 file changed, 3 insertions(+), 117 deletions(-) diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 645a1512..7365cf39 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -44,39 +44,6 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * FreeImage(&image); } -void ConvertNtrToPng(char *inputPath UNUSED, char *outputPath UNUSED, struct GbaToPngOptions *options) //todo finish -{ - struct Image image; - - if (options->paletteFilePath != NULL) - { - ReadNtrPalette(options->paletteFilePath, &image.palette); - image.hasPalette = true; - } - else - { - image.hasPalette = false; - } - - if (image.hasPalette) - { - printf("Image has palette!\n"); - printf("Colours: %d\n", image.palette.numColors); - for (int i = 0; i < image.palette.numColors; i++) - { - printf("Red: %d ", image.palette.colors[i].red); - printf("Green: %d ", image.palette.colors[i].green); - printf("Blue: %d\n", image.palette.colors[i].blue); - } - } - else - { - printf("No palette detected!\n"); - } - - FreeImage(&image); -} - void ConvertPngToGba(char *inputPath, char *outputPath, struct PngToGbaOptions *options) { struct Image image; @@ -231,85 +198,6 @@ void HandlePngToGbaCommand(char *inputPath, char *outputPath, int argc, char **a ConvertPngToGba(inputPath, outputPath, &options); } -void HandleNtrToPngCommand(char *inputPath, char *outputPath, int argc, char **argv) -{ - //char *inputFileExtension = GetFileExtension(inputPath); - struct GbaToPngOptions options; - options.paletteFilePath = NULL; - options.bitDepth = 4; //todo read from header - options.hasTransparency = false; - options.width = 1; - options.metatileWidth = 1; - options.metatileHeight = 1; - - for (int i = 3; i < argc; i++) - { - char *option = argv[i]; - - if (strcmp(option, "-palette") == 0) - { - if (i + 1 >= argc) - FATAL_ERROR("No palette file path following \"-palette\".\n"); - - i++; - - options.paletteFilePath = argv[i]; - } - else if (strcmp(option, "-object") == 0) - { - options.hasTransparency = true; - } - else if (strcmp(option, "-width") == 0) - { - if (i + 1 >= argc) - FATAL_ERROR("No width following \"-width\".\n"); - - i++; - - if (!ParseNumber(argv[i], NULL, 10, &options.width)) - FATAL_ERROR("Failed to parse width.\n"); - - if (options.width < 1) - FATAL_ERROR("Width must be positive.\n"); - } - else if (strcmp(option, "-mwidth") == 0) - { - if (i + 1 >= argc) - FATAL_ERROR("No metatile width value following \"-mwidth\".\n"); - - i++; - - if (!ParseNumber(argv[i], NULL, 10, &options.metatileWidth)) - FATAL_ERROR("Failed to parse metatile width.\n"); - - if (options.metatileWidth < 1) - FATAL_ERROR("metatile width must be positive.\n"); - } - else if (strcmp(option, "-mheight") == 0) - { - if (i + 1 >= argc) - FATAL_ERROR("No metatile height value following \"-mheight\".\n"); - - i++; - - if (!ParseNumber(argv[i], NULL, 10, &options.metatileHeight)) - FATAL_ERROR("Failed to parse metatile height.\n"); - - if (options.metatileHeight < 1) - FATAL_ERROR("metatile height must be positive.\n"); - } - else - { - FATAL_ERROR("Unrecognized option \"%s\".\n", option); - } - } - - if (options.metatileWidth > options.width) - options.width = options.metatileWidth; - - ConvertNtrToPng(inputPath, outputPath, &options); -} - void HandlePngToGbaPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) { struct Palette palette; @@ -653,17 +541,15 @@ int main(int argc, char **argv) { "1bpp", "png", HandleGbaToPngCommand }, { "4bpp", "png", HandleGbaToPngCommand }, { "8bpp", "png", HandleGbaToPngCommand }, - //{ "ncgr", "png", HandleNtrToPngCommand }, { "png", "1bpp", HandlePngToGbaCommand }, { "png", "4bpp", HandlePngToGbaCommand }, { "png", "8bpp", HandlePngToGbaCommand }, - //{ "png", "ncgr", HandlePngToNtrCommand }, { "png", "gbapal", HandlePngToGbaPaletteCommand }, { "gbapal", "pal", HandleGbaToJascPaletteCommand }, - { "nclr", "pal", HandleNtrToJascPaletteCommand }, - { "ncpr", "pal", HandleNtrToJascPaletteCommand }, + { "NCLR", "pal", HandleNtrToJascPaletteCommand }, + { "NCPR", "pal", HandleNtrToJascPaletteCommand }, { "pal", "gbapal", HandleJascToGbaPaletteCommand }, - { "pal", "nclr", HandleJascToNtrPaletteCommand }, + { "pal", "NCLR", HandleJascToNtrPaletteCommand }, { "latfont", "png", HandleLatinFontToPngCommand }, { "png", "latfont", HandlePngToLatinFontCommand }, { "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand }, -- cgit v1.2.3 From 550c03c212bee4096c3b2174f8b9d32d655843ec Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 20:18:30 +0100 Subject: cleanup and address issues --- tools/nitrogfx/gfx.c | 60 ++++++++++++++++++++++----------------------------- tools/nitrogfx/util.c | 36 ++++++++++--------------------- 2 files changed, 37 insertions(+), 59 deletions(-) diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 92483228..ad2b313e 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -1,5 +1,6 @@ // Copyright (c) 2015 YamaArashi +#include #include #include #include @@ -327,15 +328,17 @@ void ReadNtrPalette(char *path, struct Palette *palette) int fileSize; unsigned char *data = ReadWholeFile(path, &fileSize); - uint32_t magicNumber = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]; - if (magicNumber != 0x4E434C52 && magicNumber != 0x4E435052) //NCLR / NCPR - FATAL_ERROR("Not a valid NCLR or NCPR palette file. Magic number (%x).\n", magicNumber); + if (memcmp(data, "RLCN", 4) != 0 && memcmp(data, "RPCN", 4) != 0) //NCLR / NCPR + { + FATAL_ERROR("Not a valid NCLR or NCPR palette file.\n"); + } unsigned char *paletteHeader = data + 0x10; - magicNumber = (paletteHeader[3] << 24) | (paletteHeader[2] << 16) | (paletteHeader[1] << 8) | paletteHeader[0]; - if (magicNumber != 0x504C5454) //PLTT - FATAL_ERROR("No valid PLTT file after NCLR header. Magic number (%x).\n", magicNumber); + if (memcmp(paletteHeader, "TTLP", 4) != 0) + { + FATAL_ERROR("No valid PLTT file after NCLR header.\n"); + } if ((fileSize - 0x28) % 2 != 0) FATAL_ERROR("The file size (%d) is not a multiple of 2.\n", fileSize); @@ -389,43 +392,32 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) //NCLR header WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr); - //PLTT header - //magic number - fputs("TTLP", fp); + unsigned char palHeader[0x18] = + { + 0x54, 0x54, 0x4C, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 + }; //section size - fputc(extSize & 0xFF, fp); - fputc((extSize >> 8) & 0xFF, fp); - fputc((extSize >> 16) & 0xFF, fp); - fputc((extSize >> 24) & 0xFF, fp); + palHeader[4] = extSize & 0xFF; + palHeader[5] = (extSize >> 8) & 0xFF; + palHeader[6] = (extSize >> 16) & 0xFF; + palHeader[7] = (extSize >> 24) & 0xFF; //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); + palHeader[8] = palette->bitDepth == 4 ? 0x03: 0x04; //size - fputc(size & 0xFF, fp); - fputc((size >> 8) & 0xFF, fp); - fputc((size >> 16) & 0xFF, fp); - fputc((size >> 24) & 0xFF, fp); + palHeader[16] = size & 0xFF; + palHeader[17] = (size >> 8) & 0xFF; + palHeader[18] = (size >> 16) & 0xFF; + palHeader[19] = (size >> 24) & 0xFF; - //colours per palette - fputc(0x10, fp); - fputc(0x00, fp); - fputc(0x00, fp); - fputc(0x00, fp); + fwrite(palHeader, 1, 0x18, fp); //palette data - for (int i = 0; i < palette->numColors; i++) { + 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); diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index 3fd718fb..73a128a1 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -126,37 +126,23 @@ void WriteWholeFile(char *path, void *buffer, int bufferSize) void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder) { + unsigned char header[0x10] = + { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00 }; //magic number - fputs(magicNumber, fp); + memcpy(header, magicNumber, 4); //byte order - if (byteorder) + if (!byteorder) { - fputc(0xFF, fp); //LE - fputc(0xFE, fp); - } - else - { - fputc(0x00, fp); - fputc(0x00, fp); + memset(header + 4, 0, 2); } - //version - fputc(0x00, fp); - fputc(0x01, fp); - //size size += 0x10; //add header size - fputc(size & 0xFF, fp); - fputc((size >> 8) & 0xFF, fp); - fputc((size >> 16) & 0xFF, fp); - fputc((size >> 24) & 0xFF, fp); - - //header size - fputc(0x10, fp); - fputc(0x00, fp); - - //sections - fputc(0x01, fp); - fputc(0x00, fp); + header[8] = size & 0xFF; + header[9] = (size >> 8) & 0xFF; + header[10] = (size >> 16) & 0xFF; + header[11] = (size >> 24) & 0xFF; + + fwrite(header, 1, 0x10, fp); } -- cgit v1.2.3 From 19f7d55504ad804ba540a8f42aaf1c51b242f8a0 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 20:24:53 +0100 Subject: too -> to --- tools/nitrogfx/gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index ad2b313e..7b17a7b1 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -384,7 +384,7 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) FILE *fp = fopen(path, "wb"); if (fp == NULL) - FATAL_ERROR("Failed too open \"%s\" for writing.\n", path); + FATAL_ERROR("Failed to open \"%s\" for writing.\n", path); uint32_t size = palette->numColors * 2; uint32_t extSize = size + (ncpr ? 0x10 : 0x18); -- cgit v1.2.3 From fce2c89d6edb6d8e6d8fbc6926b1b0784a07c984 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 20:34:43 +0100 Subject: more efficient gfx.c --- tools/nitrogfx/gfx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 7b17a7b1..ac156575 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -415,6 +415,7 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) fwrite(palHeader, 1, 0x18, fp); + unsigned char colours[palette->numColors * 2]; //palette data for (int i = 0; i < palette->numColors; i++) { @@ -424,9 +425,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) uint16_t paletteEntry = SET_GBA_PAL(red, green, blue); - fputc(paletteEntry & 0xFF, fp); - fputc(paletteEntry >> 8, fp); + colours[i * 2] = paletteEntry & 0xFF; + colours[i * 2 + 1] = paletteEntry >> 8; } + fwrite(colours, 1, palette->numColors * 2, fp); + fclose(fp); } -- cgit v1.2.3