From cc67cafa094351a033f295d054380acc63fddd78 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 7 Jun 2020 15:57:16 +0100 Subject: fix bitdepth --- tools/nitrogfx/gfx.c | 3 ++- tools/nitrogfx/gfx.h | 1 + tools/nitrogfx/jasc_pal.c | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 25c346db..bb6ff442 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -400,7 +400,8 @@ void WriteNtrPalette(char *path, struct Palette *palette) fputc((extSize >> 24) & 0xFF, fp); //bit depth - fputc(0x03, fp); //todo figure out a way to determine bit depth + char bitDepth = palette->bitDepth == 4 ? 0x03: 0x04; + fputc(bitDepth, fp); fputc(0x00, fp); fputc(0x00, fp); fputc(0x00, fp); diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index d5241509..c563a2dc 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -15,6 +15,7 @@ struct Color { struct Palette { struct Color colors[256]; int numColors; + int bitDepth; }; struct Image { diff --git a/tools/nitrogfx/jasc_pal.c b/tools/nitrogfx/jasc_pal.c index e5ba9c3c..4f80f5d9 100644 --- a/tools/nitrogfx/jasc_pal.c +++ b/tools/nitrogfx/jasc_pal.c @@ -91,6 +91,8 @@ void ReadJascPalette(char *path, struct Palette *palette) if (palette->numColors < 1 || palette->numColors > 256) FATAL_ERROR("%d is an invalid number of colors. The number of colors must be in the range [1, 256].\n", palette->numColors); + palette->bitDepth = 4; + for (int i = 0; i < palette->numColors; i++) { ReadJascPaletteLine(fp, line); @@ -146,6 +148,11 @@ void ReadJascPalette(char *path, struct Palette *palette) palette->colors[i].red = red; palette->colors[i].green = green; palette->colors[i].blue = blue; + if (i >= 16) + { + if (red || green || blue) + palette->bitDepth = 8; + } } if (fgetc(fp) != EOF) -- cgit v1.2.3