summaryrefslogtreecommitdiff
path: root/tools/nitrogfx/gfx.c
diff options
context:
space:
mode:
authorCleverking2003 <30466983+Cleverking2003@users.noreply.github.com>2020-07-14 08:31:45 +0300
committerGitHub <noreply@github.com>2020-07-14 08:31:45 +0300
commite62dcb7dc070fab232b124510938473cc35a2e78 (patch)
treee559d4ac0279f78b740b443a8c3936138dbfd226 /tools/nitrogfx/gfx.c
parent6ebca13d4c5a290e239364f90bf137c12f332a13 (diff)
parentd2ff9e5df70f2c6be6a0c822ba2e689f82911911 (diff)
Merge pull request #233 from red031000/master
palette padding changes + OS_timer
Diffstat (limited to 'tools/nitrogfx/gfx.c')
-rw-r--r--tools/nitrogfx/gfx.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index 8f943698..7c57d269 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -549,14 +549,16 @@ void WriteGbaPalette(char *path, struct Palette *palette)
fclose(fp);
}
-void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth)
+void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum)
{
FILE *fp = fopen(path, "wb");
if (fp == NULL)
FATAL_ERROR("Failed to open \"%s\" for writing.\n", path);
- uint32_t size = 256 * 2; //todo check if there's a better way to detect :/
+ int colourNum = pad ? 256 : 16;
+
+ uint32_t size = colourNum * 2; //todo check if there's a better way to detect :/
uint32_t extSize = size + (ncpr ? 0x10 : 0x18);
//NCLR header
@@ -582,6 +584,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in
//bit depth
palHeader[8] = bitdepth == 4 ? 0x03: 0x04;
+ if (compNum)
+ {
+ palHeader[10] = compNum; //assuming this is an indicator of compression, literally no docs for it though
+ }
+
//size
palHeader[16] = size & 0xFF;
palHeader[17] = (size >> 8) & 0xFF;
@@ -590,9 +597,9 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in
fwrite(palHeader, 1, 0x18, fp);
- unsigned char colours[256 * 2];
+ unsigned char colours[colourNum * 2];
//palette data
- for (int i = 0; i < 256; i++)
+ for (int i = 0; i < colourNum; i++)
{
if (i < palette->numColors)
{
@@ -614,11 +621,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in
if (ir)
{
- colours[510] = 'I';
- colours[511] = 'R';
+ colours[colourNum * 2 - 2] = 'I';
+ colours[colourNum * 2 - 1] = 'R';
}
- fwrite(colours, 1, 256 * 2, fp);
+ fwrite(colours, 1, colourNum * 2, fp);
fclose(fp);
}