summaryrefslogtreecommitdiff
path: root/tools/nitrogfx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/nitrogfx')
-rw-r--r--tools/nitrogfx/Makefile6
-rw-r--r--tools/nitrogfx/gfx.c14
-rw-r--r--tools/nitrogfx/gfx.h4
-rw-r--r--tools/nitrogfx/main.c8
-rw-r--r--tools/nitrogfx/options.h1
5 files changed, 25 insertions, 8 deletions
diff --git a/tools/nitrogfx/Makefile b/tools/nitrogfx/Makefile
index 16b2632d..2ed6cf1e 100644
--- a/tools/nitrogfx/Makefile
+++ b/tools/nitrogfx/Makefile
@@ -1,5 +1,11 @@
CC = gcc
+HAVE_LIBPNG := $(shell pkg-config libpng; echo $?)
+
+ifeq ($(HAVE_LIBPNG),1)
+$(error No package 'libpng' found)
+endif
+
CFLAGS = -Wall -Wextra -Werror -Wno-sign-compare -std=c11 -O2 -DPNG_SKIP_SETJMP_CHECK $(shell pkg-config --cflags libpng)
LIBS = $(shell pkg-config --libs libpng)
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index ee7e0d6f..43e8f83c 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -433,7 +433,9 @@ 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, uint32_t key)
+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, bool wrongSize)
{
FILE *fp = fopen(path, "wb");
@@ -499,15 +501,15 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
}
}
- WriteGenericNtrHeader(fp, "RGCN", bufferSize + (sopc ? 0x30 : 0x20), byteOrder, version101, sopc ? 2 : 1);
+ WriteGenericNtrHeader(fp, "RGCN", bufferSize + (sopc ? 0x30 : 0x20) + (wrongSize ? -8 : 0), 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 };
- charHeader[4] = (bufferSize + 0x20) & 0xFF;
- charHeader[5] = ((bufferSize + 0x20) >> 8) & 0xFF;
- charHeader[6] = ((bufferSize + 0x20) >> 16) & 0xFF;
- charHeader[7] = ((bufferSize + 0x20) >> 24) & 0xFF;
+ charHeader[4] = (bufferSize + 0x20 + (wrongSize ? -8 : 0)) & 0xFF;
+ charHeader[5] = ((bufferSize + 0x20 + (wrongSize ? -8 : 0)) >> 8) & 0xFF;
+ charHeader[6] = ((bufferSize + 0x20 + (wrongSize ? -8 : 0)) >> 16) & 0xFF;
+ charHeader[7] = ((bufferSize + 0x20 + (wrongSize ? -8 : 0)) >> 24) & 0xFF;
if (!clobberSize)
{
diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h
index d0e6521a..389aec41 100644
--- a/tools/nitrogfx/gfx.h
+++ b/tools/nitrogfx/gfx.h
@@ -32,7 +32,9 @@ struct Image {
void ReadImage(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, uint32_t key);
+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, bool wrongSize);
void FreeImage(struct Image *image);
void ReadGbaPalette(char *path, struct Palette *palette);
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex);
diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c
index b2d3352a..5561e44e 100644
--- a/tools/nitrogfx/main.c
+++ b/tools/nitrogfx/main.c
@@ -116,7 +116,9 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions *
free(string);
}
- WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned, key);
+ WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight,
+ &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101,
+ options->sopc, options->scanned, key, options->wrongSize);
FreeImage(&image);
}
@@ -360,6 +362,7 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a
options.bitDepth = 4;
options.metatileWidth = 1;
options.metatileHeight = 1;
+ options.wrongSize = false;
options.clobberSize = false;
options.byteOrder = true;
options.version101 = false;
@@ -442,6 +445,9 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a
{
options.scanned = true;
}
+ else if (strcmp(option, "-wrongsize") == 0) {
+ options.wrongSize = true;
+ }
else
{
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h
index 66e9895d..e6721766 100644
--- a/tools/nitrogfx/options.h
+++ b/tools/nitrogfx/options.h
@@ -32,6 +32,7 @@ struct PngToNtrOptions {
bool version101;
bool sopc;
bool scanned;
+ bool wrongSize;
};
struct Attr0 {