From e0e55af2c9dea2a8b55cd95d69b08bc2ab9d5912 Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 17 Jul 2020 19:09:55 +0100 Subject: nitrogfx support for scanned images --- tools/nitrogfx/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/nitrogfx/main.c') diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index b7136b03..265c2df9 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -88,7 +88,7 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions * ReadPng(inputPath, &image); - WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc); + WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned); FreeImage(&image); } @@ -322,6 +322,7 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a options.byteOrder = true; options.version101 = false; options.sopc = false; + options.scanned = false; for (int i = 3; i < argc; i++) { @@ -395,6 +396,10 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a { options.sopc = true; } + else if (strcmp(option, "-scanned") == 0) + { + options.scanned = true; + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); -- cgit v1.2.3 From 9e87848fa3797db4fa0efd8165c94e25aca01a5b Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 18 Jul 2020 14:41:48 +0100 Subject: nitrogfx - output key to output and input key from input --- tools/nitrogfx/main.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'tools/nitrogfx/main.c') diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 265c2df9..4ff025ab 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -58,7 +58,18 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * image.hasPalette = false; } - ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); + uint32_t key = ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); + + if (key) + { + char string[strlen(outputPath) + 6]; + strcpy(string, outputPath); + FILE *fp = fopen(strcat(string, ".key"), "wb"); + if (fp == NULL) + FATAL_ERROR("Failed to open key file for writing.\n"); + fwrite(&key, 4, 1, fp); + fclose(fp); + } image.hasTransparency = options->hasTransparency; @@ -88,7 +99,21 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions * ReadPng(inputPath, &image); - WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned); + uint32_t key = 0; + if (options->scanned) + { + char string[strlen(inputPath) + 6]; + strcpy(string, inputPath); + FILE *fp2 = fopen(strcat(string, ".key"), "rb"); + if (fp2 == NULL) + FATAL_ERROR("Failed to open key file for reading.\n"); + size_t count = fread(&key, 4, 1, fp2); + if (count != 1) + FATAL_ERROR("Not a valid key file.\n"); + fclose(fp2); + } + + WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned, key); FreeImage(&image); } -- cgit v1.2.3 From 00dceb58da1649e3bb7d7a1fb29a57ae55dd483b Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 18 Jul 2020 17:03:05 +0100 Subject: nitrogfx - use sprintf --- tools/nitrogfx/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/nitrogfx/main.c') diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 4ff025ab..56cf4abd 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -62,9 +62,9 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * if (key) { - char string[strlen(outputPath) + 6]; - strcpy(string, outputPath); - FILE *fp = fopen(strcat(string, ".key"), "wb"); + char string[strlen(outputPath) + 5]; + sprintf(string, "%s.key", outputPath); + FILE *fp = fopen(string, "wb"); if (fp == NULL) FATAL_ERROR("Failed to open key file for writing.\n"); fwrite(&key, 4, 1, fp); @@ -102,9 +102,9 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions * uint32_t key = 0; if (options->scanned) { - char string[strlen(inputPath) + 6]; - strcpy(string, inputPath); - FILE *fp2 = fopen(strcat(string, ".key"), "rb"); + char string[strlen(inputPath) + 5]; + sprintf(string, "%s.key", inputPath); + FILE *fp2 = fopen(string, "rb"); if (fp2 == NULL) FATAL_ERROR("Failed to open key file for reading.\n"); size_t count = fread(&key, 4, 1, fp2); -- cgit v1.2.3 From 8e915f8e654af9d9ea5dc94fde7012c6944ae825 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 18 Jul 2020 19:29:06 +0100 Subject: trainer back sprite proof of concept + fix NCLR from png --- tools/nitrogfx/main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tools/nitrogfx/main.c') diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 56cf4abd..942b0d90 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -448,6 +448,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c bool ncpr = false; bool ir = false; bool nopad = false; + int bitdepth = 0; int compNum = 0; for (int i = 3; i < argc; i++) @@ -466,7 +467,20 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c { nopad = true; } - if (strcmp(option, "-comp") == 0) + else 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, "-comp") == 0) { if (i + 1 >= argc) FATAL_ERROR("No compression value following \"-comp\".\n"); @@ -486,7 +500,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c } ReadPngPalette(inputPath, &palette); - WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth, !nopad, compNum); + WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum); } void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) -- cgit v1.2.3