summaryrefslogtreecommitdiff
path: root/tools/gbagfx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gbagfx')
-rw-r--r--tools/gbagfx/gfx.c6
-rw-r--r--tools/gbagfx/main.c27
2 files changed, 29 insertions, 4 deletions
diff --git a/tools/gbagfx/gfx.c b/tools/gbagfx/gfx.c
index c09c4238e..c0f7f492c 100644
--- a/tools/gbagfx/gfx.c
+++ b/tools/gbagfx/gfx.c
@@ -292,10 +292,10 @@ void ReadGbaPalette(char *path, struct Palette *palette)
int fileSize;
unsigned char *data = ReadWholeFile(path, &fileSize);
- palette->numColors = fileSize / 2;
+ if (fileSize % 2 != 0)
+ FATAL_ERROR("The file size (%d) is not a multiple of 2.\n", fileSize);
- if (palette->numColors != 16 && palette->numColors != 256)
- FATAL_ERROR("\"%s\" contains %d colors, but the number of colors must be 16 or 256.\n", path, palette->numColors);
+ palette->numColors = fileSize / 2;
for (int i = 0; i < palette->numColors; i++) {
uint16_t paletteEntry = (data[i * 2 + 1] << 8) | data[i * 2];
diff --git a/tools/gbagfx/main.c b/tools/gbagfx/main.c
index 56a1c2c7b..cc1e8f807 100644
--- a/tools/gbagfx/main.c
+++ b/tools/gbagfx/main.c
@@ -129,11 +129,36 @@ void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc U
WriteJascPalette(outputPath, &palette);
}
-void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
+void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc, char **argv)
{
+ int numColors = 0;
+
+ for (int i = 3; i < argc; i++) {
+ char *option = argv[i];
+
+ if (strcmp(option, "-num_colors") == 0) {
+ if (i + 1 >= argc)
+ FATAL_ERROR("No number of colors following \"-num_colors\".\n");
+
+ i++;
+
+ if (!ParseNumber(argv[i], NULL, 10, &numColors))
+ FATAL_ERROR("Failed to parse number of colors.\n");
+
+ if (numColors < 1)
+ FATAL_ERROR("Number of colors must be positive.\n");
+ } else {
+ FATAL_ERROR("Unrecognized option \"%s\".\n", option);
+ }
+ }
+
struct Palette palette;
ReadJascPalette(inputPath, &palette);
+
+ if (numColors != 0)
+ palette.numColors = numColors;
+
WriteGbaPalette(outputPath, &palette);
}