summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorred031000 <rubenru09@aol.com>2020-07-18 14:41:48 +0100
committerred031000 <rubenru09@aol.com>2020-07-18 14:41:48 +0100
commit9e87848fa3797db4fa0efd8165c94e25aca01a5b (patch)
tree2db3a585e48e6eef2937eff00224f42cc999fe4f
parentae8212ad5d3413e4c5b3397ab4bb782fdea1a194 (diff)
nitrogfx - output key to output and input key from input
-rw-r--r--tools/nitrogfx/gfx.c24
-rw-r--r--tools/nitrogfx/gfx.h4
-rw-r--r--tools/nitrogfx/main.c29
3 files changed, 33 insertions, 24 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index 56abc694..c1be2a36 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -298,7 +298,7 @@ void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int
free(buffer);
}
-void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors)
+uint32_t ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors)
{
int fileSize;
unsigned char *buffer = ReadWholeFile(path, &fileSize);
@@ -350,9 +350,9 @@ void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, i
int metatilesWide = tilesWidth / metatileWidth;
+ uint32_t key = 0;
if (scanned)
{
- uint32_t key;
switch (bitDepth)
{
case 4:
@@ -362,13 +362,6 @@ void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, i
FATAL_ERROR("8bpp is not implemented yet\n");
break;
}
- char string[strlen(path) + 6];
- strcpy(string, path);
- FILE *fp = fopen(strcat(string, ".key"), "wb");
- if (fp == NULL)
- FATAL_ERROR("Failed to open key file for writing.\n");
- fwrite(&key, 4, 1, fp);
- fclose(fp);
}
else
{
@@ -386,6 +379,7 @@ void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, i
}
free(buffer);
+ return key;
}
void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors)
@@ -439,7 +433,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, bool version101, bool sopc, bool scanned)
+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, bool scanned, uint32_t key)
{
FILE *fp = fopen(path, "wb");
@@ -480,16 +474,6 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
if (scanned)
{
- char string[strlen(path) + 6];
- strcpy(string, path);
- FILE *fp2 = fopen(strcat(string, ".key"), "rb");
- if (fp2 == NULL)
- FATAL_ERROR("Failed to open key file for reading.\n");
- uint32_t key;
- size_t count = fread(&key, 4, 1, fp2);
- if (count != 1)
- FATAL_ERROR("Not a valid key file.\n");
- fclose(fp2);
switch (bitDepth)
{
case 4:
diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h
index 6e5ebe9a..ef1f493d 100644
--- a/tools/nitrogfx/gfx.h
+++ b/tools/nitrogfx/gfx.h
@@ -29,9 +29,9 @@ struct Image {
};
void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
-void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
+uint32_t ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
-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, bool scanned);
+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, bool scanned, uint32_t key);
void FreeImage(struct Image *image);
void ReadGbaPalette(char *path, struct Palette *palette);
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth);
diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c
index 265c2df9..4ff025ab 100644
--- a/tools/nitrogfx/main.c
+++ b/tools/nitrogfx/main.c
@@ -58,7 +58,18 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions *
image.hasPalette = false;
}
- ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette);
+ uint32_t key = ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette);
+
+ if (key)
+ {
+ char string[strlen(outputPath) + 6];
+ strcpy(string, outputPath);
+ FILE *fp = fopen(strcat(string, ".key"), "wb");
+ if (fp == NULL)
+ FATAL_ERROR("Failed to open key file for writing.\n");
+ fwrite(&key, 4, 1, fp);
+ fclose(fp);
+ }
image.hasTransparency = options->hasTransparency;
@@ -88,7 +99,21 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions *
ReadPng(inputPath, &image);
- WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned);
+ uint32_t key = 0;
+ if (options->scanned)
+ {
+ char string[strlen(inputPath) + 6];
+ strcpy(string, inputPath);
+ FILE *fp2 = fopen(strcat(string, ".key"), "rb");
+ if (fp2 == NULL)
+ FATAL_ERROR("Failed to open key file for reading.\n");
+ size_t count = fread(&key, 4, 1, fp2);
+ if (count != 1)
+ FATAL_ERROR("Not a valid key file.\n");
+ fclose(fp2);
+ }
+
+ WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned, key);
FreeImage(&image);
}