From cc5a1e59920fe0ed975af40aa49b7870832323af Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 6 Jun 2020 23:58:19 +0100 Subject: palette conversion --- tools/nitrogfx/util.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tools/nitrogfx/util.c') 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 -- 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 --- tools/nitrogfx/util.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tools/nitrogfx/util.c') 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); -- 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/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/nitrogfx/util.c') 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 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/util.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'tools/nitrogfx/util.c') 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