mirror of
https://github.com/red031000/nitrogfx.git
synced 2025-06-19 05:35:41 -04:00
Merge pull request #15 from joshua-smith-12/nclr_size_invert
support NCLR files with unusual inverted size field
This commit is contained in:
commit
e8ea772119
14
gfx.c
14
gfx.c
@ -714,7 +714,7 @@ void ReadGbaPalette(char *path, struct Palette *palette)
|
|||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex)
|
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex, bool inverted)
|
||||||
{
|
{
|
||||||
int fileSize;
|
int fileSize;
|
||||||
unsigned char *data = ReadWholeFile(path, &fileSize);
|
unsigned char *data = ReadWholeFile(path, &fileSize);
|
||||||
@ -739,6 +739,7 @@ void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIn
|
|||||||
bitdepth = bitdepth ? bitdepth : palette->bitDepth;
|
bitdepth = bitdepth ? bitdepth : palette->bitDepth;
|
||||||
|
|
||||||
size_t paletteSize = (paletteHeader[0x10]) | (paletteHeader[0x11] << 8) | (paletteHeader[0x12] << 16) | (paletteHeader[0x13] << 24);
|
size_t paletteSize = (paletteHeader[0x10]) | (paletteHeader[0x11] << 8) | (paletteHeader[0x12] << 16) | (paletteHeader[0x13] << 24);
|
||||||
|
if (inverted) paletteSize = 0x200 - paletteSize;
|
||||||
if (palIndex == 0) {
|
if (palIndex == 0) {
|
||||||
palette->numColors = paletteSize / 2;
|
palette->numColors = paletteSize / 2;
|
||||||
} else {
|
} else {
|
||||||
@ -789,7 +790,7 @@ void WriteGbaPalette(char *path, struct Palette *palette)
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum, bool pcmp)
|
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum, bool pcmp, bool inverted)
|
||||||
{
|
{
|
||||||
FILE *fp = fopen(path, "wb");
|
FILE *fp = fopen(path, "wb");
|
||||||
|
|
||||||
@ -843,10 +844,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
//size
|
//size
|
||||||
palHeader[16] = size & 0xFF;
|
int colorSize = inverted ? 0x200 - size : size;
|
||||||
palHeader[17] = (size >> 8) & 0xFF;
|
palHeader[16] = colorSize & 0xFF;
|
||||||
palHeader[18] = (size >> 16) & 0xFF;
|
palHeader[17] = (colorSize >> 8) & 0xFF;
|
||||||
palHeader[19] = (size >> 24) & 0xFF;
|
palHeader[18] = (colorSize >> 16) & 0xFF;
|
||||||
|
palHeader[19] = (colorSize >> 24) & 0xFF;
|
||||||
|
|
||||||
fwrite(palHeader, 1, 0x18, fp);
|
fwrite(palHeader, 1, 0x18, fp);
|
||||||
|
|
||||||
|
4
gfx.h
4
gfx.h
@ -58,9 +58,9 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int colsPerChunk, int
|
|||||||
uint32_t mappingType, uint32_t key, bool wrongSize);
|
uint32_t mappingType, uint32_t key, bool wrongSize);
|
||||||
void FreeImage(struct Image *image);
|
void FreeImage(struct Image *image);
|
||||||
void ReadGbaPalette(char *path, struct Palette *palette);
|
void ReadGbaPalette(char *path, struct Palette *palette);
|
||||||
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex);
|
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex, bool inverted);
|
||||||
void WriteGbaPalette(char *path, struct Palette *palette);
|
void WriteGbaPalette(char *path, struct Palette *palette);
|
||||||
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum, bool pcmp);
|
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum, bool pcmp, bool inverted);
|
||||||
void ReadNtrCell(char *path, struct JsonToCellOptions *options);
|
void ReadNtrCell(char *path, struct JsonToCellOptions *options);
|
||||||
void WriteNtrCell(char *path, struct JsonToCellOptions *options);
|
void WriteNtrCell(char *path, struct JsonToCellOptions *options);
|
||||||
void WriteNtrScreen(char *path, struct JsonToScreenOptions *options);
|
void WriteNtrScreen(char *path, struct JsonToScreenOptions *options);
|
||||||
|
18
main.c
18
main.c
@ -74,7 +74,7 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct NtrToPngOptions *
|
|||||||
|
|
||||||
if (options->paletteFilePath != NULL)
|
if (options->paletteFilePath != NULL)
|
||||||
{
|
{
|
||||||
ReadNtrPalette(options->paletteFilePath, &image.palette, options->bitDepth, options->palIndex);
|
ReadNtrPalette(options->paletteFilePath, &image.palette, options->bitDepth, options->palIndex, false);
|
||||||
image.hasPalette = true;
|
image.hasPalette = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -619,7 +619,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReadPngPalette(inputPath, &palette);
|
ReadPngPalette(inputPath, &palette);
|
||||||
WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum, pcmp);
|
WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum, pcmp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
||||||
@ -634,6 +634,7 @@ void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc,
|
|||||||
{
|
{
|
||||||
struct Palette palette;
|
struct Palette palette;
|
||||||
int bitdepth = 0;
|
int bitdepth = 0;
|
||||||
|
bool inverted = false;
|
||||||
|
|
||||||
for (int i = 3; i < argc; i++)
|
for (int i = 3; i < argc; i++)
|
||||||
{
|
{
|
||||||
@ -652,13 +653,17 @@ void HandleNtrToJascPaletteCommand(char *inputPath, char *outputPath, int argc,
|
|||||||
if (bitdepth != 4 && bitdepth != 8)
|
if (bitdepth != 4 && bitdepth != 8)
|
||||||
FATAL_ERROR("Bitdepth must be 4 or 8.\n");
|
FATAL_ERROR("Bitdepth must be 4 or 8.\n");
|
||||||
}
|
}
|
||||||
|
else if (strcmp(option, "-invertsize") == 0)
|
||||||
|
{
|
||||||
|
inverted = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadNtrPalette(inputPath, &palette, bitdepth, 0);
|
ReadNtrPalette(inputPath, &palette, bitdepth, 0, inverted);
|
||||||
WriteJascPalette(outputPath, &palette);
|
WriteJascPalette(outputPath, &palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,6 +713,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
|||||||
int bitdepth = 0;
|
int bitdepth = 0;
|
||||||
int compNum = 0;
|
int compNum = 0;
|
||||||
bool pcmp = false;
|
bool pcmp = false;
|
||||||
|
bool inverted = false;
|
||||||
|
|
||||||
for (int i = 3; i < argc; i++)
|
for (int i = 3; i < argc; i++)
|
||||||
{
|
{
|
||||||
@ -768,6 +774,10 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
|||||||
{
|
{
|
||||||
pcmp = true;
|
pcmp = true;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(option, "-invertsize") == 0)
|
||||||
|
{
|
||||||
|
inverted = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
||||||
@ -781,7 +791,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,
|
|||||||
if (numColors != 0)
|
if (numColors != 0)
|
||||||
palette.numColors = numColors;
|
palette.numColors = numColors;
|
||||||
|
|
||||||
WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum, pcmp);
|
WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum, pcmp, inverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleJsonToNtrCellCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
void HandleJsonToNtrCellCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
||||||
|
Loading…
Reference in New Issue
Block a user