Copy Berry Fix MB dism from FR (#777)

* Copy Berry Fix MB dism from FR
This commit is contained in:
PikalaxALT
2019-09-03 15:33:11 -04:00
committed by GitHub
parent 5d30304f4e
commit 1f4c88c952
66 changed files with 10373 additions and 31 deletions
+73 -1
View File
@@ -12,6 +12,7 @@
#include "lz.h"
#include "rl.h"
#include "font.h"
#include "huff.h"
struct CommandHandler
{
@@ -319,6 +320,7 @@ void HandlePngToFullwidthJapaneseFontCommand(char *inputPath, char *outputPath,
void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char **argv)
{
int overflowSize = 0;
int minDistance = 2; // default, for compatibility with LZ77UnCompVram()
for (int i = 3; i < argc; i++)
{
@@ -337,6 +339,19 @@ void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char *
if (overflowSize < 1)
FATAL_ERROR("Overflow size must be positive.\n");
}
else if (strcmp(option, "-search") == 0)
{
if (i + 1 >= argc)
FATAL_ERROR("No size following \"-overflow\".\n");
i++;
if (!ParseNumber(argv[i], NULL, 10, &minDistance))
FATAL_ERROR("Failed to parse LZ min search distance.\n");
if (minDistance < 1)
FATAL_ERROR("LZ min search distance must be positive.\n");
}
else
{
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
@@ -353,7 +368,7 @@ void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char *
unsigned char *buffer = ReadWholeFileZeroPadded(inputPath, &fileSize, overflowSize);
int compressedSize;
unsigned char *compressedData = LZCompress(buffer, fileSize + overflowSize, &compressedSize);
unsigned char *compressedData = LZCompress(buffer, fileSize + overflowSize, &compressedSize, minDistance);
compressedData[1] = (unsigned char)fileSize;
compressedData[2] = (unsigned char)(fileSize >> 8);
@@ -411,6 +426,61 @@ void HandleRLDecompressCommand(char *inputPath, char *outputPath, int argc UNUSE
free(uncompressedData);
}
void HandleHuffCompressCommand(char *inputPath, char *outputPath, int argc, char **argv)
{
int fileSize;
int bitDepth = 4;
for (int i = 3; i < argc; i++)
{
char *option = argv[i];
if (strcmp(option, "-depth") == 0)
{
if (i + 1 >= argc)
FATAL_ERROR("No size following \"-depth\".\n");
i++;
if (!ParseNumber(argv[i], NULL, 10, &bitDepth))
FATAL_ERROR("Failed to parse bit depth.\n");
if (bitDepth != 4 && bitDepth != 8)
FATAL_ERROR("GBA only supports bit depth of 4 or 8.\n");
}
else
{
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
}
}
unsigned char *buffer = ReadWholeFile(inputPath, &fileSize);
int compressedSize;
unsigned char *compressedData = HuffCompress(buffer, fileSize, &compressedSize, bitDepth);
free(buffer);
WriteWholeFile(outputPath, compressedData, compressedSize);
free(compressedData);
}
void HandleHuffDecompressCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
int fileSize;
unsigned char *buffer = ReadWholeFile(inputPath, &fileSize);
int uncompressedSize;
unsigned char *uncompressedData = HuffDecompress(buffer, fileSize, &uncompressedSize);
free(buffer);
WriteWholeFile(outputPath, uncompressedData, uncompressedSize);
free(uncompressedData);
}
int main(int argc, char **argv)
{
if (argc < 3)
@@ -433,7 +503,9 @@ int main(int argc, char **argv)
{ "png", "hwjpnfont", HandlePngToHalfwidthJapaneseFontCommand },
{ "fwjpnfont", "png", HandleFullwidthJapaneseFontToPngCommand },
{ "png", "fwjpnfont", HandlePngToFullwidthJapaneseFontCommand },
{ NULL, "huff", HandleHuffCompressCommand },
{ NULL, "lz", HandleLZCompressCommand },
{ "huff", NULL, HandleHuffDecompressCommand },
{ "lz", NULL, HandleLZDecompressCommand },
{ NULL, "rl", HandleRLCompressCommand },
{ "rl", NULL, HandleRLDecompressCommand },