summaryrefslogtreecommitdiff
path: root/tools/nitrogfx/gfx.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/nitrogfx/gfx.c')
-rw-r--r--tools/nitrogfx/gfx.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index 3315e00e..8f943698 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -359,7 +359,7 @@ void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int m
free(buffer);
}
-void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder)
+void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc)
{
FILE *fp = fopen(path, "wb");
@@ -407,7 +407,7 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
break;
}
- WriteGenericNtrHeader(fp, "RGCN", bufferSize + 0x20, byteOrder);
+ WriteGenericNtrHeader(fp, "RGCN", bufferSize + (sopc ? 0x30 : 0x20), byteOrder, version101, sopc ? 2 : 1);
unsigned char charHeader[0x20] = { 0x52, 0x41, 0x48, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00 };
@@ -419,11 +419,11 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
if (!clobberSize)
{
- charHeader[8] = numTiles & 0xFF;
- charHeader[9] = (numTiles >> 8) & 0xFF;
+ charHeader[8] = tilesHeight & 0xFF;
+ charHeader[9] = (tilesHeight >> 8) & 0xFF;
- charHeader[10] = tileSize & 0xFF;
- charHeader[11] = (tileSize >> 8) & 0xFF;
+ charHeader[10] = tilesWidth & 0xFF;
+ charHeader[11] = (tilesWidth >> 8) & 0xFF;
}
else
{
@@ -446,6 +446,19 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
fwrite(pixelBuffer, 1, bufferSize, fp);
+ if (sopc)
+ {
+ unsigned char sopcBuffer[0x10] = { 0x53, 0x4F, 0x50, 0x43, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+ sopcBuffer[12] = tilesWidth & 0xFF;
+ sopcBuffer[13] = (tilesWidth >> 8) & 0xFF;
+
+ sopcBuffer[14] = tilesHeight & 0xFF;
+ sopcBuffer[15] = (tilesHeight >> 8) & 0xFF;
+
+ fwrite(sopcBuffer, 1, 0x10, fp);
+ }
+
free(pixelBuffer);
fclose(fp);
}
@@ -476,7 +489,7 @@ void ReadGbaPalette(char *path, struct Palette *palette)
free(data);
}
-void ReadNtrPalette(char *path, struct Palette *palette)
+void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth)
{
int fileSize;
unsigned char *data = ReadWholeFile(path, &fileSize);
@@ -498,7 +511,9 @@ void ReadNtrPalette(char *path, struct Palette *palette)
palette->bitDepth = paletteHeader[0x8] == 3 ? 4 : 8;
- palette->numColors = palette->bitDepth == 4 ? 16 : 256; //remove header and divide by 2
+ bitdepth = bitdepth ? bitdepth : palette->bitDepth;
+
+ palette->numColors = bitdepth == 4 ? 16 : 256; //remove header and divide by 2
unsigned char *paletteData = paletteHeader + 0x18;
@@ -534,7 +549,7 @@ void WriteGbaPalette(char *path, struct Palette *palette)
fclose(fp);
}
-void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr)
+void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth)
{
FILE *fp = fopen(path, "wb");
@@ -545,7 +560,7 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr)
uint32_t extSize = size + (ncpr ? 0x10 : 0x18);
//NCLR header
- WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr);
+ WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr, false, 1);
unsigned char palHeader[0x18] =
{
@@ -561,8 +576,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr)
if (!palette->bitDepth)
palette->bitDepth = 4;
+
+ bitdepth = bitdepth ? bitdepth : palette->bitDepth;
+
//bit depth
- palHeader[8] = palette->bitDepth == 4 ? 0x03: 0x04;
+ palHeader[8] = bitdepth == 4 ? 0x03: 0x04;
//size
palHeader[16] = size & 0xFF;
@@ -594,6 +612,12 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr)
}
}
+ if (ir)
+ {
+ colours[510] = 'I';
+ colours[511] = 'R';
+ }
+
fwrite(colours, 1, 256 * 2, fp);
fclose(fp);