diff options
| author | Cleverking2003 <30466983+Cleverking2003@users.noreply.github.com> | 2020-07-14 08:31:45 +0300 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-14 08:31:45 +0300 | 
| commit | e62dcb7dc070fab232b124510938473cc35a2e78 (patch) | |
| tree | e559d4ac0279f78b740b443a8c3936138dbfd226 /tools | |
| parent | 6ebca13d4c5a290e239364f90bf137c12f332a13 (diff) | |
| parent | d2ff9e5df70f2c6be6a0c822ba2e689f82911911 (diff) | |
Merge pull request #233 from red031000/master
palette padding changes + OS_timer
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/nitrogfx/gfx.c | 21 | ||||
| -rw-r--r-- | tools/nitrogfx/gfx.h | 2 | ||||
| -rw-r--r-- | tools/nitrogfx/main.c | 44 | 
3 files changed, 56 insertions, 11 deletions
| diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 8f943698..7c57d269 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -549,14 +549,16 @@ void WriteGbaPalette(char *path, struct Palette *palette)  	fclose(fp);  } -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth) +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum)  {      FILE *fp = fopen(path, "wb");      if (fp == NULL)          FATAL_ERROR("Failed to open \"%s\" for writing.\n", path); -    uint32_t size = 256 * 2; //todo check if there's a better way to detect :/ +    int colourNum = pad ? 256 : 16; + +    uint32_t size = colourNum * 2; //todo check if there's a better way to detect :/      uint32_t extSize = size + (ncpr ? 0x10 : 0x18);      //NCLR header @@ -582,6 +584,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in      //bit depth      palHeader[8] = bitdepth == 4 ? 0x03: 0x04; +    if (compNum) +    { +        palHeader[10] = compNum; //assuming this is an indicator of compression, literally no docs for it though +    } +      //size      palHeader[16] = size & 0xFF;      palHeader[17] = (size >> 8) & 0xFF; @@ -590,9 +597,9 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in      fwrite(palHeader, 1, 0x18, fp); -    unsigned char colours[256 * 2]; +    unsigned char colours[colourNum * 2];      //palette data -    for (int i = 0; i < 256; i++) +    for (int i = 0; i < colourNum; i++)      {          if (i < palette->numColors)          { @@ -614,11 +621,11 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in      if (ir)      { -        colours[510] = 'I'; -        colours[511] = 'R'; +        colours[colourNum * 2 - 2] = 'I'; +        colours[colourNum * 2 - 1] = 'R';      } -    fwrite(colours, 1, 256 * 2, fp); +    fwrite(colours, 1, colourNum * 2, fp);      fclose(fp);  } diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index e5189100..f833ac2e 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -36,6 +36,6 @@ void FreeImage(struct Image *image);  void ReadGbaPalette(char *path, struct Palette *palette);  void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth);  void WriteGbaPalette(char *path, struct Palette *palette); -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth); +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum);  #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 188bdf0a..b7136b03 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -417,6 +417,8 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c      struct Palette palette;      bool ncpr = false;      bool ir = false; +    bool nopad = false; +    int compNum = 0;      for (int i = 3; i < argc; i++)      { @@ -430,6 +432,23 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c          {              ir = true;          } +        else if (strcmp(option, "-nopad") == 0) +        { +            nopad = true; +        } +        if (strcmp(option, "-comp") == 0) +        { +            if (i + 1 >= argc) +                FATAL_ERROR("No compression value following \"-comp\".\n"); + +            i++; + +            if (!ParseNumber(argv[i], NULL, 10, &compNum)) +                FATAL_ERROR("Failed to parse compression value.\n"); + +            if (compNum > 255) +                FATAL_ERROR("Compression value must be 255 or below.\n"); +        }          else          {              FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -437,7 +456,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c      }      ReadPngPalette(inputPath, &palette); -    WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth); +    WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth, !nopad, compNum);  }  void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -522,7 +541,9 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,      int numColors = 0;      bool ncpr = false;      bool ir = false; +    bool nopad = false;      int bitdepth = 0; +    int compNum = 0;      for (int i = 3; i < argc; i++)      { @@ -541,7 +562,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,              if (numColors < 1)                  FATAL_ERROR("Number of colors must be positive.\n");          } -        if (strcmp(option, "-bitdepth") == 0) +        else if (strcmp(option, "-bitdepth") == 0)          {              if (i + 1 >= argc)                  FATAL_ERROR("No bitdepth following \"-bitdepth\".\n"); @@ -554,6 +575,19 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,              if (bitdepth != 4 && bitdepth != 8)                  FATAL_ERROR("Bitdepth must be 4 or 8.\n");          } +        else if (strcmp(option, "-comp") == 0) +        { +            if (i + 1 >= argc) +                FATAL_ERROR("No compression value following \"-comp\".\n"); + +            i++; + +            if (!ParseNumber(argv[i], NULL, 10, &compNum)) +                FATAL_ERROR("Failed to parse compression value.\n"); + +            if (compNum > 255) +                FATAL_ERROR("Compression value must be 255 or below.\n"); +        }          else if (strcmp(option, "-ncpr") == 0)          {              ncpr = true; @@ -562,6 +596,10 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,          {              ir = true;          } +        else if (strcmp(option, "-nopad") == 0) +        { +            nopad = true; +        }          else          {              FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -575,7 +613,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc,      if (numColors != 0)          palette.numColors = numColors; -    WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth); +    WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum);  }  void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) | 
