diff options
author | red031000 <rubenru09@aol.com> | 2020-06-22 01:37:06 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-06-22 01:37:06 +0100 |
commit | c9a26fd84fad7ba98035c22d13233e0bc4c429f6 (patch) | |
tree | b363dae1fcd4a6d50d7bb3c6eebf782e8323ec02 /tools/nitrogfx/main.c | |
parent | d2710751ca6b1c4cc5399ea7206fb8faa00de5fe (diff) |
NCGR extracting
Diffstat (limited to 'tools/nitrogfx/main.c')
-rw-r--r-- | tools/nitrogfx/main.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 7365cf39..aa46d7b0 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -44,6 +44,29 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * FreeImage(&image); } +void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions *options) +{ + struct Image image; + + if (options->paletteFilePath != NULL) + { + ReadNtrPalette(options->paletteFilePath, &image.palette); + image.hasPalette = true; + } + else + { + image.hasPalette = false; + } + + ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); + + image.hasTransparency = options->hasTransparency; + + WritePng(outputPath, &image); + + FreeImage(&image); +} + void ConvertPngToGba(char *inputPath, char *outputPath, struct PngToGbaOptions *options) { struct Image image; @@ -136,6 +159,83 @@ void HandleGbaToPngCommand(char *inputPath, char *outputPath, int argc, char **a ConvertGbaToPng(inputPath, outputPath, &options); } +void HandleNtrToPngCommand(char *inputPath, char *outputPath, int argc, char **argv) +{ + struct GbaToPngOptions options; + options.paletteFilePath = NULL; + 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 HandlePngToGbaCommand(char *inputPath, char *outputPath, int argc, char **argv) { char *outputFileExtension = GetFileExtension(outputPath); @@ -541,6 +641,7 @@ 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 }, |