summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorred031000 <rubenru09@aol.com>2020-06-07 17:34:32 +0100
committerred031000 <rubenru09@aol.com>2020-06-07 17:34:32 +0100
commit6bd0b1970c1b096d9791c8ea1515e0f722fd99a8 (patch)
tree18e5314e06df51062da58bce7f8f6a0486179fed
parent1c7bd60010bb429bd6cbcfad889bef9e7058cb89 (diff)
bit of cleanup
-rw-r--r--tools/nitrogfx/gfx.c69
-rw-r--r--tools/nitrogfx/gfx.h3
-rw-r--r--tools/nitrogfx/main.c9
-rw-r--r--tools/nitrogfx/util.c2
4 files changed, 8 insertions, 75 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index 8a10efe2..92483228 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -376,7 +376,7 @@ void WriteGbaPalette(char *path, struct Palette *palette)
fclose(fp);
}
-void WriteNtrNCLRPalette(char *path, struct Palette *palette)
+void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr)
{
FILE *fp = fopen(path, "wb");
@@ -384,73 +384,10 @@ void WriteNtrNCLRPalette(char *path, struct Palette *palette)
FATAL_ERROR("Failed too open \"%s\" for writing.\n", path);
uint32_t size = palette->numColors * 2;
- uint32_t extSize = size + 0x18;
+ uint32_t extSize = size + (ncpr ? 0x10 : 0x18);
//NCLR header
- WriteGenericNtrHeader(fp, "RLCN", extSize, true);
-
- //PLTT header
- //magic number
- fputs("TTLP", fp);
-
- //section size
- fputc(extSize & 0xFF, fp);
- fputc((extSize >> 8) & 0xFF, fp);
- fputc((extSize >> 16) & 0xFF, fp);
- fputc((extSize >> 24) & 0xFF, fp);
-
- //bit depth
- char bitDepth = palette->bitDepth == 4 ? 0x03: 0x04;
- fputc(bitDepth, fp);
- fputc(0x00, fp);
- fputc(0x00, fp);
- fputc(0x00, fp);
-
- //padding
- fputc(0x00, fp);
- fputc(0x00, fp);
- fputc(0x00, fp);
- fputc(0x00, fp);
-
- //size
- fputc(size & 0xFF, fp);
- fputc((size >> 8) & 0xFF, fp);
- fputc((size >> 16) & 0xFF, fp);
- fputc((size >> 24) & 0xFF, fp);
-
- //colours per palette
- fputc(0x10, fp);
- fputc(0x00, fp);
- fputc(0x00, fp);
- fputc(0x00, fp);
-
- //palette data
- for (int i = 0; i < palette->numColors; i++) {
- unsigned char red = DOWNCONVERT_BIT_DEPTH(palette->colors[i].red);
- unsigned char green = DOWNCONVERT_BIT_DEPTH(palette->colors[i].green);
- unsigned char blue = DOWNCONVERT_BIT_DEPTH(palette->colors[i].blue);
-
- uint16_t paletteEntry = SET_GBA_PAL(red, green, blue);
-
- fputc(paletteEntry & 0xFF, fp);
- fputc(paletteEntry >> 8, fp);
- }
-
- fclose(fp);
-}
-
-void WriteNtrNCPRPalette(char *path, struct Palette *palette)
-{
- FILE *fp = fopen(path, "wb");
-
- if (fp == NULL)
- FATAL_ERROR("Failed too open \"%s\" for writing.\n", path);
-
- uint32_t size = palette->numColors * 2;
- uint32_t extSize = size + 0x10;
-
- //NCLR header
- WriteGenericNtrHeader(fp, "RPCN", extSize, false);
+ WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr);
//PLTT header
//magic number
diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h
index 06adca79..fc57380e 100644
--- a/tools/nitrogfx/gfx.h
+++ b/tools/nitrogfx/gfx.h
@@ -34,7 +34,6 @@ void FreeImage(struct Image *image);
void ReadGbaPalette(char *path, struct Palette *palette);
void ReadNtrPalette(char *path, struct Palette *palette);
void WriteGbaPalette(char *path, struct Palette *palette);
-void WriteNtrNCLRPalette(char *path, struct Palette *palette);
-void WriteNtrNCPRPalette(char *path, struct Palette *palette);
+void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr);
#endif // GFX_H
diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c
index 64f7e8a5..645a1512 100644
--- a/tools/nitrogfx/main.c
+++ b/tools/nitrogfx/main.c
@@ -371,7 +371,7 @@ void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc,
WriteGbaPalette(outputPath, &palette);
}
-void HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv)
+void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv)
{
int numColors = 0;
bool ncpr = false;
@@ -410,10 +410,7 @@ void HandleJascToNtrNCLRPaletteCommand(char *inputPath, char *outputPath, int ar
if (numColors != 0)
palette.numColors = numColors;
- if (ncpr)
- WriteNtrNCPRPalette(outputPath, &palette);
- else
- WriteNtrNCLRPalette(outputPath, &palette);
+ WriteNtrPalette(outputPath, &palette, ncpr);
}
void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
@@ -666,7 +663,7 @@ int main(int argc, char **argv)
{ "nclr", "pal", HandleNtrToJascPaletteCommand },
{ "ncpr", "pal", HandleNtrToJascPaletteCommand },
{ "pal", "gbapal", HandleJascToGbaPaletteCommand },
- { "pal", "nclr", HandleJascToNtrNCLRPaletteCommand },
+ { "pal", "nclr", HandleJascToNtrPaletteCommand },
{ "latfont", "png", HandleLatinFontToPngCommand },
{ "png", "latfont", HandlePngToLatinFontCommand },
{ "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand },
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
+}