From a604bc3b573e2f23bb0eb40e0fc8946b857d6c98 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 12 Jul 2020 18:36:54 +0100 Subject: [PATCH] fix palette issues, demo/title/titledemo narc fully converted --- Makefile | 6 + files/demo/title/titledemo/.gitignore | 6 +- files/demo/title/titledemo/narc_0007.NCGR | Bin 320 -> 0 bytes files/demo/title/titledemo/narc_0007.png | Bin 0 -> 204 bytes files/demo/title/titledemo/narc_0009.NCLR | Bin 552 -> 0 bytes files/demo/title/titledemo/narc_0009.pal | 19 ++ files/demo/title/titledemo/narc_0010.NCLR | Bin 552 -> 0 bytes files/demo/title/titledemo/narc_0010.pal | 19 ++ files/demo/title/titledemo/narc_0011.NCGR | Bin 320 -> 0 bytes files/demo/title/titledemo/narc_0011.png | Bin 0 -> 204 bytes files/demo/title/titledemo/narc_0013.NCLR | Bin 552 -> 0 bytes files/demo/title/titledemo/narc_0013.pal | 19 ++ files/demo/title/titledemo/narc_0014.NCLR | Bin 552 -> 0 bytes files/demo/title/titledemo/narc_0014.pal | 19 ++ files/demo/title/titledemo/narc_0015.NCGR | Bin 32832 -> 0 bytes files/demo/title/titledemo/narc_0015.png | Bin 0 -> 376 bytes files/demo/title/titledemo/narc_0016.NCLR | Bin 552 -> 0 bytes files/demo/title/titledemo/narc_0016.pal | 259 ++++++++++++++++++++++ filesystem.mk | 10 +- graphics_rules.mk | 15 +- tools/nitrogfx/gfx.c | 19 +- tools/nitrogfx/gfx.h | 4 +- tools/nitrogfx/main.c | 48 +++- 23 files changed, 423 insertions(+), 20 deletions(-) delete mode 100644 files/demo/title/titledemo/narc_0007.NCGR create mode 100644 files/demo/title/titledemo/narc_0007.png delete mode 100644 files/demo/title/titledemo/narc_0009.NCLR create mode 100644 files/demo/title/titledemo/narc_0009.pal delete mode 100644 files/demo/title/titledemo/narc_0010.NCLR create mode 100644 files/demo/title/titledemo/narc_0010.pal delete mode 100644 files/demo/title/titledemo/narc_0011.NCGR create mode 100644 files/demo/title/titledemo/narc_0011.png delete mode 100644 files/demo/title/titledemo/narc_0013.NCLR create mode 100644 files/demo/title/titledemo/narc_0013.pal delete mode 100644 files/demo/title/titledemo/narc_0014.NCLR create mode 100644 files/demo/title/titledemo/narc_0014.pal delete mode 100644 files/demo/title/titledemo/narc_0015.NCGR create mode 100644 files/demo/title/titledemo/narc_0015.png delete mode 100644 files/demo/title/titledemo/narc_0016.NCLR create mode 100644 files/demo/title/titledemo/narc_0016.pal diff --git a/Makefile b/Makefile index cecb8b984..e7fecae4f 100644 --- a/Makefile +++ b/Makefile @@ -255,6 +255,9 @@ $(CLOBBER_SIZE_VERSION101_NCGR_FILES): %.NCGR: %.png $(VERSION101_SOPC_8BPP_NCGR_FILES): %.NCGR: %.png $(GFX) $< $@ -version101 -sopc -bitdepth 8 +$(VERSION101_SOPC_NCGR_FILES): %.NCGR: %.png + $(GFX) $< $@ -version101 -sopc + %.NCLR: %.png $(GFX) $< $@ @@ -264,6 +267,9 @@ $(VERSION101_SOPC_8BPP_NCGR_FILES): %.NCGR: %.png $(IR_NCLR_FILES): %.NCLR: %.pal $(GFX) $< $@ -ir +$(4BPP_NCLR_FILES): %.NCLR: %.pal + $(GFX) $< $@ -bitdepth 4 + %.png: ; %.pal: ; diff --git a/files/demo/title/titledemo/.gitignore b/files/demo/title/titledemo/.gitignore index b49b5cb3d..e16f08110 100644 --- a/files/demo/title/titledemo/.gitignore +++ b/files/demo/title/titledemo/.gitignore @@ -1,4 +1,2 @@ -narc_0001.NCGR -narc_0001.NCLR -narc_0003.NCGR -narc_0003.NCLR +*.NCLR +*.NCGR diff --git a/files/demo/title/titledemo/narc_0007.NCGR b/files/demo/title/titledemo/narc_0007.NCGR deleted file mode 100644 index 999daf42cad521adbfcbd34bcb06f26cd8e33b57..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 320 zcmWG?clP`LkCD-Vk%2*gfr%l=(Zg8*$Yx~VU|?oI0zfedBrY!Ie<*l|1nwe%Ge}@J r5?F--UU?ar3$%j4)78&qol`;+042dg ATL1t6 literal 0 HcmV?d00001 diff --git a/files/demo/title/titledemo/narc_0009.NCLR b/files/demo/title/titledemo/narc_0009.NCLR deleted file mode 100644 index d7ac121eb7c4ad5079ebb864753aae52ec766a8e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 552 zcmWIYarXQFkAYExiGe|Yfsr93#3w)k$Yy4M0 diff --git a/files/demo/title/titledemo/narc_0009.pal b/files/demo/title/titledemo/narc_0009.pal new file mode 100644 index 000000000..e69e3f473 --- /dev/null +++ b/files/demo/title/titledemo/narc_0009.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +0 0 0 +255 255 255 +238 238 246 +222 222 230 +205 205 222 +180 189 205 +164 172 197 +148 156 180 +131 131 172 +106 115 156 +90 98 148 +74 82 131 +57 65 123 +32 49 106 +16 32 98 +0 8 82 diff --git a/files/demo/title/titledemo/narc_0010.NCLR b/files/demo/title/titledemo/narc_0010.NCLR deleted file mode 100644 index 1dc5e984777732e2c5315f2e767e57a7e33f0ad9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 552 zcmWIYarXQFkAYExiGe|Yfsr93#3w)k$Yy4M0c!5#SK0S{>poVZy7sn8ZsmTcpP5&JV*f_!%9W4cRFfaTgQAal5#yS6)Wug52ck>gTe~DWM4fuZJsx literal 0 HcmV?d00001 diff --git a/files/demo/title/titledemo/narc_0013.NCLR b/files/demo/title/titledemo/narc_0013.NCLR deleted file mode 100644 index 0dd59fd4245bfba611fed692ef12b7152b4c4bfd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 552 zcmWIYarXQFkAYExiGe|Yfsr93#3w)k$Yy4M0%!SB7DD(D!)z5M8^%3pL*r8ZCyr6nztoyi(z~X;Iv$Hj`33Cbw$lT#+`xd zT}me16zWp`e7SM7NE-b%J)Gv|ak!oO46Ug6lYn1w?{&Y|dL_oOma^9so&;4{cZ@pf z)g78>*y~=O#Ptqb_xkjG&PjP-zYfFrLq)fMHotmnp<{k|mn*N9N7vn7f%2`X*FN6% zTD|_5&N#c#x-y?2wmsj6JwV&4%3(IY>ioMpszvmNKN9t0l|LF?JooUZ-#1+Y=_rRy z*~k4c@^`WpwYz=fpXhd&2m%NofB*srAb@qO{9ir4|J8E-PiJnWuJ~P0F7)-xnr~-reEoA-;B(#gKQale65p?ePCU=( zcI|EA_0+F%hiw^G_5XQ(@=lVkqv(=l8U9gu%NsUoeKK%3U&cBkeZkhR9oDhue{%&) z-4%Xp=S%x9OLg=|9@-b)d_+iC7!N+F6*2UngC6^ Bq^1A> literal 0 HcmV?d00001 diff --git a/files/demo/title/titledemo/narc_0016.NCLR b/files/demo/title/titledemo/narc_0016.NCLR deleted file mode 100644 index 697a342a6e0d2e1bd289c9805bdd6349912e3108..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 552 zcmWIYarXQFkAYExiGe|Yfsr93#3w)k$Yy4M03iECuPH&- dqAb&^^Y@njuLr5XFCWcu+Y)N#C^h6l000|c9ghG2 diff --git a/files/demo/title/titledemo/narc_0016.pal b/files/demo/title/titledemo/narc_0016.pal new file mode 100644 index 000000000..13181a805 --- /dev/null +++ b/files/demo/title/titledemo/narc_0016.pal @@ -0,0 +1,259 @@ +JASC-PAL +0100 +256 +0 0 0 +0 0 0 +16 16 16 +32 32 32 +49 49 49 +74 74 74 +90 90 90 +106 106 106 +123 123 123 +148 148 148 +164 164 164 +180 180 180 +205 205 205 +222 222 222 +238 238 238 +255 255 255 +0 0 0 +0 0 0 +16 16 16 +32 32 32 +49 49 49 +74 74 74 +90 90 90 +106 106 106 +123 123 123 +148 148 148 +164 164 164 +180 180 180 +205 205 205 +222 222 222 +238 238 238 +255 255 255 +0 0 0 +222 16 16 +222 115 115 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 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+0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 diff --git a/filesystem.mk b/filesystem.mk index 1be7b6826..a203a0db4 100644 --- a/filesystem.mk +++ b/filesystem.mk @@ -2223,7 +2223,15 @@ files/demo/title/titledemo.narc: \ files/demo/title/titledemo/narc_0001.NCGR \ files/demo/title/titledemo/narc_0001.NCLR \ files/demo/title/titledemo/narc_0003.NCGR \ - files/demo/title/titledemo/narc_0003.NCLR + files/demo/title/titledemo/narc_0003.NCLR \ + files/demo/title/titledemo/narc_0007.NCGR \ + files/demo/title/titledemo/narc_0009.NCLR \ + files/demo/title/titledemo/narc_0010.NCLR \ + files/demo/title/titledemo/narc_0011.NCGR \ + files/demo/title/titledemo/narc_0013.NCLR \ + files/demo/title/titledemo/narc_0014.NCLR \ + files/demo/title/titledemo/narc_0015.NCGR \ + files/demo/title/titledemo/narc_0016.NCLR .PHONY: filesystem diff --git a/graphics_rules.mk b/graphics_rules.mk index fba3be068..64762f036 100644 --- a/graphics_rules.mk +++ b/graphics_rules.mk @@ -1,6 +1,5 @@ #todo data/dp_areawindow.NCGR (weirdness with size) #todo data/graphic/bag_gra/narc_0007.NCGR (SOPC section) (width 32, palette narc_0003.NCLR) -#todo data/demo/title/titledemo/narc_0007.NCGR (weidness with size, needs investigating) CLOBBER_SIZE_NCGR_FILES := files/data/cell0.NCGR @@ -51,6 +50,8 @@ CLOBBER_SIZE_VERSION101_NCGR_FILES := files/graphic/bag_gra/narc_0002.NCGR \ files/itemtool/itemdata/item_icon/narc_0109.NCGR \ files/itemtool/itemdata/item_icon/narc_0112.NCGR +4BPP_NCLR_FILES := files/demo/title/titledemo/narc_0016.NCLR + IR_NCLR_FILES := files/itemtool/itemdata/item_icon/narc_0028.NCLR \ files/itemtool/itemdata/item_icon/narc_0029.NCLR \ files/itemtool/itemdata/item_icon/narc_0032.NCLR \ @@ -85,9 +86,16 @@ IR_NCLR_FILES := files/itemtool/itemdata/item_icon/narc_0028.NCLR \ VERSION101_SOPC_8BPP_NCGR_FILES := files/demo/title/titledemo/narc_0001.NCGR \ files/demo/title/titledemo/narc_0003.NCGR +VERSION101_SOPC_NCGR_FILES := files/demo/title/titledemo/narc_0007.NCGR \ + files/demo/title/titledemo/narc_0011.NCGR \ + files/demo/title/titledemo/narc_0015.NCGR + NCGR_CLEAN_LIST := files/data/cell0.NCGR \ files/demo/title/titledemo/narc_0001.NCGR \ files/demo/title/titledemo/narc_0003.NCGR \ + files/demo/title/titledemo/narc_0007.NCGR \ + files/demo/title/titledemo/narc_0011.NCGR \ + files/demo/title/titledemo/narc_0015.NCGR \ files/graphic/bag_gra/narc_0002.NCGR \ files/graphic/bag_gra/narc_0006.NCGR \ files/graphic/bag_gra/narc_0034.NCGR \ @@ -139,6 +147,11 @@ NCGR_CLEAN_LIST := files/data/cell0.NCGR \ NCLR_CLEAN_LIST := files/data/cell0.NCLR \ files/demo/title/titledemo/narc_0001.NCLR \ files/demo/title/titledemo/narc_0003.NCLR \ + files/demo/title/titledemo/narc_0009.NCLR \ + files/demo/title/titledemo/narc_0010.NCLR \ + files/demo/title/titledemo/narc_0013.NCLR \ + files/demo/title/titledemo/narc_0014.NCLR \ + files/demo/title/titledemo/narc_0016.NCLR \ files/graphic/bag_gra/narc_0003.NCLR \ files/graphic/bag_gra/narc_0034.NCLR \ files/itemtool/itemdata/item_icon/narc_0002.NCLR \ diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 4e5294900..8f943698e 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -453,10 +453,10 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in sopcBuffer[12] = tilesWidth & 0xFF; sopcBuffer[13] = (tilesWidth >> 8) & 0xFF; - sopcBuffer[14] = tilesHeight & 0xFF; - sopcBuffer[15] = (tilesHeight >> 8) & 0xFF; + sopcBuffer[14] = tilesHeight & 0xFF; + sopcBuffer[15] = (tilesHeight >> 8) & 0xFF; - fwrite(sopcBuffer, 1, 0x10, fp); + fwrite(sopcBuffer, 1, 0x10, fp); } free(pixelBuffer); @@ -489,7 +489,7 @@ void ReadGbaPalette(char *path, struct Palette *palette) free(data); } -void ReadNtrPalette(char *path, struct Palette *palette) +void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth) { int fileSize; unsigned char *data = ReadWholeFile(path, &fileSize); @@ -511,7 +511,9 @@ void ReadNtrPalette(char *path, struct Palette *palette) palette->bitDepth = paletteHeader[0x8] == 3 ? 4 : 8; - palette->numColors = palette->bitDepth == 4 ? 16 : 256; //remove header and divide by 2 + bitdepth = bitdepth ? bitdepth : palette->bitDepth; + + palette->numColors = bitdepth == 4 ? 16 : 256; //remove header and divide by 2 unsigned char *paletteData = paletteHeader + 0x18; @@ -547,7 +549,7 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir) +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth) { FILE *fp = fopen(path, "wb"); @@ -574,8 +576,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir) if (!palette->bitDepth) palette->bitDepth = 4; + + bitdepth = bitdepth ? bitdepth : palette->bitDepth; + //bit depth - palHeader[8] = palette->bitDepth == 4 ? 0x03: 0x04; + palHeader[8] = bitdepth == 4 ? 0x03: 0x04; //size palHeader[16] = size & 0xFF; diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index 54e6fb16c..e51891007 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -34,8 +34,8 @@ void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int m void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc); void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); -void ReadNtrPalette(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); +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 0aaad2013..188bdf0a9 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -50,7 +50,7 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * if (options->paletteFilePath != NULL) { - ReadNtrPalette(options->paletteFilePath, &image.palette); + ReadNtrPalette(options->paletteFilePath, &image.palette, options->bitDepth); image.hasPalette = true; } else @@ -437,7 +437,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c } ReadPngPalette(inputPath, &palette); - WriteNtrPalette(outputPath, &palette, ncpr, ir); + WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth); } void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -448,11 +448,35 @@ void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc U WriteJascPalette(outputPath, &palette); } -void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) +void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv) { struct Palette palette; + int bitdepth = 0; - ReadNtrPalette(inputPath, &palette); + for (int i = 3; i < argc; i++) + { + char *option = argv[i]; + + 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 + { + FATAL_ERROR("Unrecognized option \"%s\".\n", option); + } + } + + ReadNtrPalette(inputPath, &palette, bitdepth); WriteJascPalette(outputPath, &palette); } @@ -498,6 +522,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, int numColors = 0; bool ncpr = false; bool ir = false; + int bitdepth = 0; for (int i = 3; i < argc; i++) { @@ -516,6 +541,19 @@ 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) + { + 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, "-ncpr") == 0) { ncpr = true; @@ -537,7 +575,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (numColors != 0) palette.numColors = numColors; - WriteNtrPalette(outputPath, &palette, ncpr, ir); + WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)