mirror of
https://github.com/red031000/nitrogfx.git
synced 2025-06-18 13:15:35 -04:00
Merge pull request #21 from Gudf/lz-pad-option
Add a flag to disable padding lz-encoded files
This commit is contained in:
commit
14aaef3caf
14
lz.c
14
lz.c
@ -122,7 +122,7 @@ static void FindBestBlockBackwards(unsigned char *src, int srcPos, int srcSize,
|
|||||||
|
|
||||||
typedef void (*FindBestBlockFunc)(unsigned char *src, int srcPos, int srcSize, const int minDistance, int *outBestBlockDistance, int *outBestBlockSize);
|
typedef void (*FindBestBlockFunc)(unsigned char *src, int srcPos, int srcSize, const int minDistance, int *outBestBlockDistance, int *outBestBlockSize);
|
||||||
|
|
||||||
unsigned char *LZCompress(unsigned char *src, int srcSize, int *compressedSize, const int minDistance, bool forwardIteration)
|
unsigned char *LZCompress(unsigned char *src, int srcSize, int *compressedSize, const int minDistance, bool forwardIteration, bool pad)
|
||||||
{
|
{
|
||||||
if (srcSize <= 0)
|
if (srcSize <= 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -169,12 +169,14 @@ unsigned char *LZCompress(unsigned char *src, int srcSize, int *compressedSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (srcPos == srcSize) {
|
if (srcPos == srcSize) {
|
||||||
// Pad to multiple of 4 bytes.
|
if (pad) {
|
||||||
int remainder = destPos % 4;
|
// Pad to multiple of 4 bytes.
|
||||||
|
int remainder = destPos % 4;
|
||||||
|
|
||||||
if (remainder != 0) {
|
if (remainder != 0) {
|
||||||
for (int i = 0; i < 4 - remainder; i++)
|
for (int i = 0; i < 4 - remainder; i++)
|
||||||
dest[destPos++] = 0;
|
dest[destPos++] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*compressedSize = destPos;
|
*compressedSize = destPos;
|
||||||
|
2
lz.h
2
lz.h
@ -6,6 +6,6 @@
|
|||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
|
|
||||||
unsigned char *LZDecompress(unsigned char *src, int srcSize, int *uncompressedSize);
|
unsigned char *LZDecompress(unsigned char *src, int srcSize, int *uncompressedSize);
|
||||||
unsigned char *LZCompress(unsigned char *src, int srcSize, int *compressedSize, const int minDistance, bool forwardIteration);
|
unsigned char *LZCompress(unsigned char *src, int srcSize, int *compressedSize, const int minDistance, bool forwardIteration, bool pad);
|
||||||
|
|
||||||
#endif // LZ_H
|
#endif // LZ_H
|
||||||
|
7
main.c
7
main.c
@ -973,6 +973,7 @@ void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char *
|
|||||||
int overflowSize = 0;
|
int overflowSize = 0;
|
||||||
int minDistance = 2; // default, for compatibility with LZ77UnCompVram()
|
int minDistance = 2; // default, for compatibility with LZ77UnCompVram()
|
||||||
bool forwardIteration = true;
|
bool forwardIteration = true;
|
||||||
|
bool nopad = false;
|
||||||
|
|
||||||
for (int i = 3; i < argc; i++)
|
for (int i = 3; i < argc; i++)
|
||||||
{
|
{
|
||||||
@ -1008,6 +1009,10 @@ void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char *
|
|||||||
{
|
{
|
||||||
forwardIteration = false;
|
forwardIteration = false;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(option, "-nopad") == 0)
|
||||||
|
{
|
||||||
|
nopad = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
|
||||||
@ -1024,7 +1029,7 @@ void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char *
|
|||||||
unsigned char *buffer = ReadWholeFileZeroPadded(inputPath, &fileSize, overflowSize);
|
unsigned char *buffer = ReadWholeFileZeroPadded(inputPath, &fileSize, overflowSize);
|
||||||
|
|
||||||
int compressedSize;
|
int compressedSize;
|
||||||
unsigned char *compressedData = LZCompress(buffer, fileSize + overflowSize, &compressedSize, minDistance, forwardIteration);
|
unsigned char *compressedData = LZCompress(buffer, fileSize + overflowSize, &compressedSize, minDistance, forwardIteration, !nopad);
|
||||||
|
|
||||||
compressedData[1] = (unsigned char)fileSize;
|
compressedData[1] = (unsigned char)fileSize;
|
||||||
compressedData[2] = (unsigned char)(fileSize >> 8);
|
compressedData[2] = (unsigned char)(fileSize >> 8);
|
||||||
|
Loading…
Reference in New Issue
Block a user