mirror of
https://github.com/pret/pokediamond.git
synced 2026-09-30 20:36:48 -05:00
palette padding changes
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,6 @@ void FreeImage(struct Image *image);
|
||||
void ReadGbaPalette(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, int bitdepth);
|
||||
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum);
|
||||
|
||||
#endif // GFX_H
|
||||
|
||||
@@ -417,6 +417,8 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
|
||||
struct Palette palette;
|
||||
bool ncpr = false;
|
||||
bool ir = false;
|
||||
bool nopad = false;
|
||||
int compNum;
|
||||
|
||||
for (int i = 3; i < argc; i++)
|
||||
{
|
||||
@@ -430,6 +432,23 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
|
||||
{
|
||||
ir = true;
|
||||
}
|
||||
else if (strcmp(option, "-nopad") == 0)
|
||||
{
|
||||
nopad = true;
|
||||
}
|
||||
if (strcmp(option, "-comp") == 0)
|
||||
{
|
||||
if (i + 1 >= argc)
|
||||
FATAL_ERROR("No compression value following \"-comp\".\n");
|
||||
|
||||
i++;
|
||||
|
||||
if (!ParseNumber(argv[i], NULL, 10, &compNum))
|
||||
FATAL_ERROR("Failed to parse compression value.\n");
|
||||
|
||||
if (compNum > 255)
|
||||
FATAL_ERROR("Compression value must be 255 or below.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
||||
@@ -437,7 +456,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
|
||||
}
|
||||
|
||||
ReadPngPalette(inputPath, &palette);
|
||||
WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth);
|
||||
WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth, !nopad, compNum);
|
||||
}
|
||||
|
||||
void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
||||
@@ -522,7 +541,9 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
||||
int numColors = 0;
|
||||
bool ncpr = false;
|
||||
bool ir = false;
|
||||
bool nopad = false;
|
||||
int bitdepth = 0;
|
||||
int compNum = 0;
|
||||
|
||||
for (int i = 3; i < argc; i++)
|
||||
{
|
||||
@@ -541,7 +562,7 @@ 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)
|
||||
else if (strcmp(option, "-bitdepth") == 0)
|
||||
{
|
||||
if (i + 1 >= argc)
|
||||
FATAL_ERROR("No bitdepth following \"-bitdepth\".\n");
|
||||
@@ -554,6 +575,19 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
||||
if (bitdepth != 4 && bitdepth != 8)
|
||||
FATAL_ERROR("Bitdepth must be 4 or 8.\n");
|
||||
}
|
||||
else if (strcmp(option, "-comp") == 0)
|
||||
{
|
||||
if (i + 1 >= argc)
|
||||
FATAL_ERROR("No compression value following \"-comp\".\n");
|
||||
|
||||
i++;
|
||||
|
||||
if (!ParseNumber(argv[i], NULL, 10, &compNum))
|
||||
FATAL_ERROR("Failed to parse compression value.\n");
|
||||
|
||||
if (compNum > 255)
|
||||
FATAL_ERROR("Compression value must be 255 or below.\n");
|
||||
}
|
||||
else if (strcmp(option, "-ncpr") == 0)
|
||||
{
|
||||
ncpr = true;
|
||||
@@ -562,6 +596,10 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
||||
{
|
||||
ir = true;
|
||||
}
|
||||
else if (strcmp(option, "-nopad") == 0)
|
||||
{
|
||||
nopad = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
||||
@@ -575,7 +613,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
||||
if (numColors != 0)
|
||||
palette.numColors = numColors;
|
||||
|
||||
WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth);
|
||||
WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum);
|
||||
}
|
||||
|
||||
void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
||||
|
||||
Reference in New Issue
Block a user