diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-10-12 19:21:36 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-10-12 19:21:36 +0100 |
commit | 2b93e381676bcd96e98a1141dccc7340af05f7c0 (patch) | |
tree | ed6dce4fabbb0e667d04b0e83be985e1144a8b76 /tools | |
parent | 57e87d6280e2e40b0d363bc08d9d15eeec52a113 (diff) | |
download | ubox-msx-lib-2b93e381676bcd96e98a1141dccc7340af05f7c0.tar.gz ubox-msx-lib-2b93e381676bcd96e98a1141dccc7340af05f7c0.zip |
Updated apultra to version 1.4.8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/apultra/src/apultra.c | 152 | ||||
-rw-r--r-- | tools/apultra/src/expand.c | 14 | ||||
-rw-r--r-- | tools/apultra/src/expand.h | 4 | ||||
-rw-r--r-- | tools/apultra/src/matchfinder.c | 65 | ||||
-rw-r--r-- | tools/apultra/src/matchfinder.h | 6 | ||||
-rw-r--r-- | tools/apultra/src/shrink.c | 46 | ||||
-rw-r--r-- | tools/apultra/src/shrink.h | 6 |
7 files changed, 139 insertions, 154 deletions
diff --git a/tools/apultra/src/apultra.c b/tools/apultra/src/apultra.c index 40990dd..6ef4890 100644 --- a/tools/apultra/src/apultra.c +++ b/tools/apultra/src/apultra.c @@ -45,7 +45,7 @@ #define OPT_STATS 2
#define OPT_BACKWARD 4
-#define TOOL_VERSION "1.4.7"
+#define TOOL_VERSION "1.4.8"
/*---------------------------------------------------------------------------*/
@@ -87,8 +87,8 @@ static long long do_get_time() { return nTime;
}
-static void do_reverse_buffer(unsigned char *pBuffer, size_t nBufferSize) {
- size_t nMidPoint = nBufferSize / 2;
+static void do_reverse_buffer(unsigned char *pBuffer, const size_t nBufferSize) {
+ const size_t nMidPoint = nBufferSize / 2;
size_t i, j;
for (i = 0, j = nBufferSize - 1; i < nMidPoint; i++, j--) {
@@ -110,7 +110,6 @@ static void compression_progress(long long nOriginalSize, long long nCompressedS static int do_compress(const char *pszInFilename, const char *pszOutFilename, const char *pszDictionaryFilename, const unsigned int nOptions, const unsigned int nMaxWindowSize) {
long long nStartTime = 0LL, nEndTime = 0LL;
size_t nOriginalSize = 0L, nCompressedSize = 0L, nMaxCompressedSize;
- int nFlags = 0;
apultra_stats stats;
unsigned char *pDecompressedData;
unsigned char *pCompressedData;
@@ -154,7 +153,7 @@ static int do_compress(const char *pszInFilename, const char *pszOutFilename, co if (!pDecompressedData) {
fclose(f_in);
if (f_dict) fclose(f_dict);
- fprintf(stderr, "out of memory for reading '%s', %zd bytes needed\n", pszInFilename, nOriginalSize);
+ fprintf(stderr, "out of memory for reading '%s', %zu bytes needed\n", pszInFilename, nOriginalSize);
return 100;
}
@@ -192,15 +191,15 @@ static int do_compress(const char *pszInFilename, const char *pszOutFilename, co pCompressedData = (unsigned char*)malloc(nMaxCompressedSize);
if (!pCompressedData) {
free(pDecompressedData);
- fprintf(stderr, "out of memory for compressing '%s', %zd bytes needed\n", pszInFilename, nMaxCompressedSize);
+ fprintf(stderr, "out of memory for compressing '%s', %zu bytes needed\n", pszInFilename, nMaxCompressedSize);
return 100;
}
memset(pCompressedData, 0, nMaxCompressedSize);
- nCompressedSize = apultra_compress(pDecompressedData, pCompressedData, nDictionarySize + nOriginalSize, nMaxCompressedSize, nFlags, nMaxWindowSize, nDictionarySize, compression_progress, &stats);
+ nCompressedSize = apultra_compress(pDecompressedData, pCompressedData, nDictionarySize + nOriginalSize, nMaxCompressedSize, 0U /* nFlags */, nMaxWindowSize, nDictionarySize, compression_progress, &stats);
- if ((nOptions & OPT_VERBOSE)) {
+ if (nOptions & OPT_VERBOSE) {
nEndTime = do_get_time();
}
@@ -214,27 +213,28 @@ static int do_compress(const char *pszInFilename, const char *pszOutFilename, co if (nOptions & OPT_BACKWARD)
do_reverse_buffer(pCompressedData, nCompressedSize);
- if (pszOutFilename) {
- FILE *f_out;
-
- /* Write whole compressed file out */
+ /* Write whole compressed file out */
- f_out = fopen(pszOutFilename, "wb");
- if (f_out) {
- fwrite(pCompressedData, 1, nCompressedSize, f_out);
- fclose(f_out);
- }
+ FILE *f_out = fopen(pszOutFilename, "wb");
+ if (!f_out) {
+ free(pCompressedData);
+ free(pDecompressedData);
+ fprintf(stderr, "error opening '%s' for writing\n", pszOutFilename);
+ return 100;
}
+
+ fwrite(pCompressedData, 1, nCompressedSize, f_out);
+ fclose(f_out);
free(pCompressedData);
free(pDecompressedData);
- if ((nOptions & OPT_VERBOSE)) {
+ if (nOptions & OPT_VERBOSE) {
double fDelta = ((double)(nEndTime - nStartTime)) / 1000000.0;
double fSpeed = ((double)nOriginalSize / 1048576.0) / fDelta;
- fprintf(stdout, "\rCompressed '%s' in %g seconds, %.02g Mb/s, %d tokens (%g bytes/token), %d into %d bytes ==> %g %%\n",
+ fprintf(stdout, "\rCompressed '%s' in %g seconds, %.02g Mb/s, %d tokens (%g bytes/token), %zu into %zu bytes ==> %g %%\n",
pszInFilename, fDelta, fSpeed, stats.commands_divisor, (double)nOriginalSize / (double)stats.commands_divisor,
- (int)nOriginalSize, (int)nCompressedSize, (double)(nCompressedSize * 100.0 / nOriginalSize));
+ nOriginalSize, nCompressedSize, (double)(nCompressedSize * 100.0 / nOriginalSize));
}
if (nOptions & OPT_STATS) {
@@ -272,7 +272,6 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, size_t nCompressedSize, nMaxDecompressedSize, nOriginalSize;
unsigned char *pCompressedData;
unsigned char *pDecompressedData;
- int nFlags = 0;
/* Read the whole compressed file in memory */
@@ -289,7 +288,7 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, pCompressedData = (unsigned char*)malloc(nCompressedSize);
if (!pCompressedData) {
fclose(f_in);
- fprintf(stderr, "out of memory for reading '%s', %zd bytes needed\n", pszInFilename, nCompressedSize);
+ fprintf(stderr, "out of memory for reading '%s', %zu bytes needed\n", pszInFilename, nCompressedSize);
return 100;
}
@@ -307,7 +306,7 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, /* Get max decompressed size */
- nMaxDecompressedSize = apultra_get_max_decompressed_size(pCompressedData, nCompressedSize, nFlags);
+ nMaxDecompressedSize = apultra_get_max_decompressed_size(pCompressedData, nCompressedSize, 0U /* nFlags */);
if (nMaxDecompressedSize == -1) {
free(pCompressedData);
fprintf(stderr, "invalid compressed format for file '%s'\n", pszInFilename);
@@ -320,6 +319,7 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, /* Open the dictionary */
f_dict = fopen(pszDictionaryFilename, "rb");
if (!f_dict) {
+ free(pCompressedData);
fprintf(stderr, "error opening dictionary '%s' for reading\n", pszDictionaryFilename);
return 100;
}
@@ -338,7 +338,7 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, if (!pDecompressedData) {
free(pCompressedData);
if (f_dict) fclose(f_dict);
- fprintf(stderr, "out of memory for decompressing '%s', %zd bytes needed\n", pszInFilename, nMaxDecompressedSize);
+ fprintf(stderr, "out of memory for decompressing '%s', %zu bytes needed\n", pszInFilename, nMaxDecompressedSize);
return 100;
}
@@ -348,7 +348,7 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, /* Read dictionary data */
if (fread(pDecompressedData, 1, nDictionarySize, f_dict) != nDictionarySize) {
free(pDecompressedData);
- fclose(f_in);
+ free(pCompressedData);
fclose(f_dict);
fprintf(stderr, "I/O error while reading dictionary '%s'\n", pszDictionaryFilename);
return 100;
@@ -365,7 +365,7 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, nStartTime = do_get_time();
}
- nOriginalSize = apultra_decompress(pCompressedData, pDecompressedData, nCompressedSize, nMaxDecompressedSize, nDictionarySize, nFlags);
+ nOriginalSize = apultra_decompress(pCompressedData, pDecompressedData, nCompressedSize, nMaxDecompressedSize, nDictionarySize, 0U /* nFlags */);
if (nOriginalSize == -1) {
free(pDecompressedData);
free(pCompressedData);
@@ -374,26 +374,31 @@ static int do_decompress(const char *pszInFilename, const char *pszOutFilename, return 100;
}
+ if (nOptions & OPT_VERBOSE) {
+ nEndTime = do_get_time();
+ }
+
if (nOptions & OPT_BACKWARD)
do_reverse_buffer(pDecompressedData + nDictionarySize, nOriginalSize);
- if (pszOutFilename) {
- FILE *f_out;
+ /* Write whole decompressed file out */
- /* Write whole decompressed file out */
+ FILE *f_out = fopen(pszOutFilename, "wb");
+ if (!f_out) {
+ free(pDecompressedData);
+ free(pCompressedData);
- f_out = fopen(pszOutFilename, "wb");
- if (f_out) {
- fwrite(pDecompressedData + nDictionarySize, 1, nOriginalSize, f_out);
- fclose(f_out);
- }
+ fprintf(stderr, "error opening '%s' for writing\n", pszOutFilename);
+ return 100;
}
+
+ fwrite(pDecompressedData + nDictionarySize, 1, nOriginalSize, f_out);
+ fclose(f_out);
free(pDecompressedData);
free(pCompressedData);
if (nOptions & OPT_VERBOSE) {
- nEndTime = do_get_time();
double fDelta = ((double)(nEndTime - nStartTime)) / 1000000.0;
double fSpeed = ((double)nOriginalSize / 1048576.0) / fDelta;
fprintf(stdout, "Decompressed '%s' in %g seconds, %g Mb/s\n",
@@ -411,7 +416,6 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con unsigned char *pCompressedData = NULL;
unsigned char *pOriginalData = NULL;
unsigned char *pDecompressedData = NULL;
- int nFlags = 0;
/* Read the whole compressed file in memory */
@@ -428,7 +432,7 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con pCompressedData = (unsigned char*)malloc(nCompressedSize);
if (!pCompressedData) {
fclose(f_in);
- fprintf(stderr, "out of memory for reading '%s', %zd bytes needed\n", pszInFilename, nCompressedSize);
+ fprintf(stderr, "out of memory for reading '%s', %zu bytes needed\n", pszInFilename, nCompressedSize);
return 100;
}
@@ -461,7 +465,7 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con if (!pOriginalData) {
fclose(f_in);
free(pCompressedData);
- fprintf(stderr, "out of memory for reading '%s', %zd bytes needed\n", pszInFilename, nOriginalSize);
+ fprintf(stderr, "out of memory for reading '%s', %zu bytes needed\n", pszInFilename, nOriginalSize);
return 100;
}
@@ -477,7 +481,7 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con /* Get max decompressed size */
- nMaxDecompressedSize = apultra_get_max_decompressed_size(pCompressedData, nCompressedSize, nFlags);
+ nMaxDecompressedSize = apultra_get_max_decompressed_size(pCompressedData, nCompressedSize, 0U /* nFlags */);
if (nMaxDecompressedSize == -1) {
free(pOriginalData);
free(pCompressedData);
@@ -491,6 +495,8 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con /* Open the dictionary */
f_dict = fopen(pszDictionaryFilename, "rb");
if (!f_dict) {
+ free(pOriginalData);
+ free(pCompressedData);
fprintf(stderr, "error opening dictionary '%s' for reading\n", pszDictionaryFilename);
return 100;
}
@@ -510,7 +516,7 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con free(pOriginalData);
free(pCompressedData);
if (f_dict) fclose(f_dict);
- fprintf(stderr, "out of memory for decompressing '%s', %zd bytes needed\n", pszInFilename, nMaxDecompressedSize);
+ fprintf(stderr, "out of memory for decompressing '%s', %zu bytes needed\n", pszInFilename, nMaxDecompressedSize);
return 100;
}
@@ -520,7 +526,8 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con /* Read dictionary data */
if (fread(pDecompressedData, 1, nDictionarySize, f_dict) != nDictionarySize) {
free(pDecompressedData);
- fclose(f_in);
+ free(pOriginalData);
+ free(pCompressedData);
fclose(f_dict);
fprintf(stderr, "I/O error while reading dictionary '%s'\n", pszDictionaryFilename);
return 100;
@@ -537,7 +544,7 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con nStartTime = do_get_time();
}
- nDecompressedSize = apultra_decompress(pCompressedData, pDecompressedData, nCompressedSize, nMaxDecompressedSize, nDictionarySize, nFlags);
+ nDecompressedSize = apultra_decompress(pCompressedData, pDecompressedData, nCompressedSize, nMaxDecompressedSize, nDictionarySize, 0U /* nFlags */);
if (nDecompressedSize == -1) {
free(pDecompressedData);
free(pOriginalData);
@@ -547,10 +554,17 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con return 100;
}
+ if (nOptions & OPT_VERBOSE) {
+ nEndTime = do_get_time();
+ }
+
if (nOptions & OPT_BACKWARD)
do_reverse_buffer(pDecompressedData + nDictionarySize, nDecompressedSize);
if (nDecompressedSize != nOriginalSize || memcmp(pDecompressedData + nDictionarySize, pOriginalData, nOriginalSize)) {
+ free(pDecompressedData);
+ free(pOriginalData);
+ free(pCompressedData);
fprintf(stderr, "error comparing compressed file '%s' with original '%s'\n", pszInFilename, pszOutFilename);
return 100;
}
@@ -560,7 +574,6 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con free(pCompressedData);
if (nOptions & OPT_VERBOSE) {
- nEndTime = do_get_time();
double fDelta = ((double)(nEndTime - nStartTime)) / 1000000.0;
double fSpeed = ((double)nOriginalSize / 1048576.0) / fDelta;
fprintf(stdout, "Compared '%s' in %g seconds, %g Mb/s\n",
@@ -572,13 +585,13 @@ static int do_compare(const char *pszInFilename, const char *pszOutFilename, con /*---------------------------------------------------------------------------*/
-static void generate_compressible_data(unsigned char *pBuffer, size_t nBufferSize, unsigned int nSeed, int nNumLiteralValues, float fMatchProbability) {
+static void generate_compressible_data(unsigned char *pBuffer, const size_t nBufferSize, const unsigned int nSeed, const int nNumLiteralValues, const float fMatchProbability) {
size_t nIndex = 0;
- int nMatchProbability = (int)(fMatchProbability * 1023.0f);
+ const int nMatchProbability = (const int)(fMatchProbability * 1023.0f);
srand(nSeed);
- if (nIndex >= nBufferSize) return;
+ if (nBufferSize == 0) return;
pBuffer[nIndex++] = rand() % nNumLiteralValues;
while (nIndex < nBufferSize) {
@@ -612,14 +625,12 @@ static void generate_compressible_data(unsigned char *pBuffer, size_t nBufferSiz }
}
-static void xor_data(unsigned char *pBuffer, size_t nBufferSize, unsigned int nSeed, float fXorProbability) {
+static void xor_data(unsigned char *pBuffer, const size_t nBufferSize, const unsigned int nSeed, const float fXorProbability) {
size_t nIndex = 0;
- int nXorProbability = (int)(fXorProbability * 1023.0f);
+ const int nXorProbability = (int)(fXorProbability * 1023.0f);
srand(nSeed);
- if (nIndex >= nBufferSize) return;
-
while (nIndex < nBufferSize) {
if ((rand() & 1023) < nXorProbability) {
pBuffer[nIndex] ^= 0xff;
@@ -636,7 +647,6 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind size_t nGeneratedDataSize;
size_t nMaxCompressedDataSize;
unsigned int nSeed = 123;
- int nFlags = 0;
int i;
pGeneratedData = (unsigned char*)malloc(4 * BLOCK_SIZE);
@@ -651,7 +661,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind free(pGeneratedData);
pGeneratedData = NULL;
- fprintf(stderr, "out of memory, %zd bytes needed\n", nMaxCompressedDataSize);
+ fprintf(stderr, "out of memory, %zu bytes needed\n", nMaxCompressedDataSize);
return 100;
}
@@ -662,7 +672,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind free(pGeneratedData);
pGeneratedData = NULL;
- fprintf(stderr, "out of memory, %zd bytes needed\n", nMaxCompressedDataSize);
+ fprintf(stderr, "out of memory, %zu bytes needed\n", nMaxCompressedDataSize);
return 100;
}
@@ -686,7 +696,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind /* Test compressing with a too small buffer to do anything, expect to fail cleanly */
for (i = 0; i < 12; i++) {
generate_compressible_data(pGeneratedData, i, nSeed, 256, 0.5f);
- apultra_compress(pGeneratedData, pCompressedData, i, i, nFlags, nMaxWindowSize, 0 /* dictionary size */, NULL, NULL);
+ apultra_compress(pGeneratedData, pCompressedData, i, i, 0U /* nFlags */, nMaxWindowSize, 0 /* dictionary size */, NULL, NULL);
}
size_t nDataSizeStep = 128;
@@ -695,7 +705,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind for (nGeneratedDataSize = 1024; nGeneratedDataSize <= (nIsQuickTest ? 1024U : (4U * BLOCK_SIZE)); nGeneratedDataSize += nDataSizeStep) {
float fMatchProbability;
- fprintf(stdout, "size %zd", nGeneratedDataSize);
+ fprintf(stdout, "size %zu", nGeneratedDataSize);
for (fMatchProbability = 0; fMatchProbability <= 0.995f; fMatchProbability += fProbabilitySizeStep) {
int nNumLiteralValues[12] = { 1, 2, 3, 15, 30, 56, 96, 137, 178, 191, 255, 256 };
float fXorProbability;
@@ -709,7 +719,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind /* Try to compress it, expected to succeed */
size_t nActualCompressedSize = apultra_compress(pGeneratedData, pCompressedData, nGeneratedDataSize, apultra_get_max_compressed_size(nGeneratedDataSize),
- nFlags, nMaxWindowSize, 0 /* dictionary size */, NULL, NULL);
+ 0U /* nFlags */, nMaxWindowSize, 0 /* dictionary size */, NULL, NULL);
if (nActualCompressedSize == -1 || nActualCompressedSize < (1 + 1 + 1 /* footer */)) {
free(pTmpDecompressedData);
pTmpDecompressedData = NULL;
@@ -720,13 +730,13 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind free(pGeneratedData);
pGeneratedData = NULL;
- fprintf(stderr, "\nself-test: error compressing size %zd, seed %d, match probability %f, literals range %d\n", nGeneratedDataSize, nSeed, fMatchProbability, nNumLiteralValues[i]);
+ fprintf(stderr, "\nself-test: error compressing size %zu, seed %u, match probability %f, literals range %d\n", nGeneratedDataSize, nSeed, fMatchProbability, nNumLiteralValues[i]);
return 100;
}
/* Try to decompress it, expected to succeed */
size_t nActualDecompressedSize;
- nActualDecompressedSize = apultra_decompress(pCompressedData, pTmpDecompressedData, nActualCompressedSize, nGeneratedDataSize, 0 /* dictionary size */, nFlags);
+ nActualDecompressedSize = apultra_decompress(pCompressedData, pTmpDecompressedData, nActualCompressedSize, nGeneratedDataSize, 0 /* dictionary size */, 0U /* nFlags */);
if (nActualDecompressedSize == -1) {
free(pTmpDecompressedData);
pTmpDecompressedData = NULL;
@@ -737,7 +747,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind free(pGeneratedData);
pGeneratedData = NULL;
- fprintf(stderr, "\nself-test: error decompressing size %zd, seed %d, match probability %f, literals range %d\n", nGeneratedDataSize, nSeed, fMatchProbability, nNumLiteralValues[i]);
+ fprintf(stderr, "\nself-test: error decompressing size %zu, seed %u, match probability %f, literals range %d\n", nGeneratedDataSize, nSeed, fMatchProbability, nNumLiteralValues[i]);
return 100;
}
@@ -751,7 +761,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind free(pGeneratedData);
pGeneratedData = NULL;
- fprintf(stderr, "\nself-test: error comparing decompressed and original data, size %zd, seed %d, match probability %f, literals range %d\n", nGeneratedDataSize, nSeed, fMatchProbability, nNumLiteralValues[i]);
+ fprintf(stderr, "\nself-test: error comparing decompressed and original data, size %zu, seed %u, match probability %f, literals range %d\n", nGeneratedDataSize, nSeed, fMatchProbability, nNumLiteralValues[i]);
return 100;
}
@@ -759,7 +769,7 @@ static int do_self_test(const unsigned int nOptions, const unsigned int nMaxWind for (fXorProbability = 0.05f; fXorProbability <= 0.5f; fXorProbability += 0.05f) {
memcpy(pTmpCompressedData, pCompressedData, nActualCompressedSize);
xor_data(pTmpCompressedData, nActualCompressedSize, nSeed, fXorProbability);
- apultra_decompress(pTmpCompressedData, pGeneratedData, nActualCompressedSize, nGeneratedDataSize, 0 /* dictionary size */, nFlags);
+ apultra_decompress(pTmpCompressedData, pGeneratedData, nActualCompressedSize, nGeneratedDataSize, 0 /* dictionary size */, 0U /* nFlags */);
}
}
@@ -799,7 +809,6 @@ static int do_compr_benchmark(const char *pszInFilename, const char *pszOutFilen size_t nFileSize, nMaxCompressedSize;
unsigned char *pFileData;
unsigned char *pCompressedData;
- int nFlags = 0;
int i;
if (pszDictionaryFilename) {
@@ -822,7 +831,7 @@ static int do_compr_benchmark(const char *pszInFilename, const char *pszOutFilen pFileData = (unsigned char*)malloc(nFileSize);
if (!pFileData) {
fclose(f_in);
- fprintf(stderr, "out of memory for reading '%s', %zd bytes needed\n", pszInFilename, nFileSize);
+ fprintf(stderr, "out of memory for reading '%s', %zu bytes needed\n", pszInFilename, nFileSize);
return 100;
}
@@ -845,7 +854,7 @@ static int do_compr_benchmark(const char *pszInFilename, const char *pszOutFilen pCompressedData = (unsigned char*)malloc(nMaxCompressedSize + 2048);
if (!pCompressedData) {
free(pFileData);
- fprintf(stderr, "out of memory for compressing '%s', %zd bytes needed\n", pszInFilename, nMaxCompressedSize);
+ fprintf(stderr, "out of memory for compressing '%s', %zu bytes needed\n", pszInFilename, nMaxCompressedSize);
return 100;
}
@@ -865,7 +874,7 @@ static int do_compr_benchmark(const char *pszInFilename, const char *pszOutFilen memset(pCompressedData + 1024 + nRightGuardPos, nGuard, 1024);
long long t0 = do_get_time();
- nActualCompressedSize = apultra_compress(pFileData, pCompressedData + 1024, nFileSize, nRightGuardPos, nFlags, nMaxWindowSize, 0 /* dictionary size */, NULL, NULL);
+ nActualCompressedSize = apultra_compress(pFileData, pCompressedData + 1024, nFileSize, nRightGuardPos, 0U /* nFlags */, nMaxWindowSize, 0 /* dictionary size */, NULL, NULL);
long long t1 = do_get_time();
if (nActualCompressedSize == -1) {
free(pCompressedData);
@@ -919,7 +928,7 @@ static int do_compr_benchmark(const char *pszInFilename, const char *pszOutFilen free(pCompressedData);
free(pFileData);
- fprintf(stdout, "compressed size: %zd bytes\n", nActualCompressedSize);
+ fprintf(stdout, "compressed size: %zu bytes\n", nActualCompressedSize);
fprintf(stdout, "compression time: %lld microseconds (%g Mb/s)\n", nBestCompTime, ((double)nActualCompressedSize / 1024.0) / ((double)nBestCompTime / 1000.0));
return 0;
@@ -931,7 +940,6 @@ static int do_dec_benchmark(const char *pszInFilename, const char *pszOutFilenam size_t nFileSize, nMaxDecompressedSize;
unsigned char *pFileData;
unsigned char *pDecompressedData;
- int nFlags = 0;
int i;
if (pszDictionaryFilename) {
@@ -954,7 +962,7 @@ static int do_dec_benchmark(const char *pszInFilename, const char *pszOutFilenam pFileData = (unsigned char*)malloc(nFileSize);
if (!pFileData) {
fclose(f_in);
- fprintf(stderr, "out of memory for reading '%s', %zd bytes needed\n", pszInFilename, nFileSize);
+ fprintf(stderr, "out of memory for reading '%s', %zu bytes needed\n", pszInFilename, nFileSize);
return 100;
}
@@ -972,7 +980,7 @@ static int do_dec_benchmark(const char *pszInFilename, const char *pszOutFilenam /* Allocate max decompressed size */
- nMaxDecompressedSize = apultra_get_max_decompressed_size(pFileData, nFileSize, nFlags);
+ nMaxDecompressedSize = apultra_get_max_decompressed_size(pFileData, nFileSize, 0U /* nFlags */);
if (nMaxDecompressedSize == -1) {
free(pFileData);
fprintf(stderr, "invalid compressed format for file '%s'\n", pszInFilename);
@@ -982,7 +990,7 @@ static int do_dec_benchmark(const char *pszInFilename, const char *pszOutFilenam pDecompressedData = (unsigned char*)malloc(nMaxDecompressedSize);
if (!pDecompressedData) {
free(pFileData);
- fprintf(stderr, "out of memory for decompressing '%s', %zd bytes needed\n", pszInFilename, nMaxDecompressedSize);
+ fprintf(stderr, "out of memory for decompressing '%s', %zu bytes needed\n", pszInFilename, nMaxDecompressedSize);
return 100;
}
@@ -993,7 +1001,7 @@ static int do_dec_benchmark(const char *pszInFilename, const char *pszOutFilenam size_t nActualDecompressedSize = 0;
for (i = 0; i < 50; i++) {
long long t0 = do_get_time();
- nActualDecompressedSize = apultra_decompress(pFileData, pDecompressedData, nFileSize, nMaxDecompressedSize, 0 /* dictionary size */, nFlags);
+ nActualDecompressedSize = apultra_decompress(pFileData, pDecompressedData, nFileSize, nMaxDecompressedSize, 0 /* dictionary size */, 0U /* nFlags */);
long long t1 = do_get_time();
if (nActualDecompressedSize == -1) {
free(pDecompressedData);
@@ -1025,7 +1033,7 @@ static int do_dec_benchmark(const char *pszInFilename, const char *pszOutFilenam free(pDecompressedData);
free(pFileData);
- fprintf(stdout, "decompressed size: %zd bytes\n", nActualDecompressedSize);
+ fprintf(stdout, "decompressed size: %zu bytes\n", nActualDecompressedSize);
fprintf(stdout, "decompression time: %lld microseconds (%g Mb/s)\n", nBestDecTime, ((double)nActualDecompressedSize / 1024.0) / ((double)nBestDecTime / 1000.0));
return 0;
diff --git a/tools/apultra/src/expand.c b/tools/apultra/src/expand.c index b65409d..af870da 100644 --- a/tools/apultra/src/expand.c +++ b/tools/apultra/src/expand.c @@ -83,11 +83,10 @@ static inline FORCE_INLINE int apultra_read_gamma2(const unsigned char **ppInBlo *
* @return maximum decompressed size
*/
-size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t nInputSize, const unsigned int nFlags) {
+size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, const size_t nInputSize, const unsigned int nFlags) {
const unsigned char *pInputDataEnd = pInputData + nInputSize;
int nCurBitMask = 0;
unsigned char bits = 0;
- int nMatchOffset = -1;
int nFollowsLiteral = 3;
size_t nDecompressedSize = 0;
@@ -124,6 +123,8 @@ size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t int nMatchOffsetHi = apultra_read_gamma2(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
nMatchOffsetHi -= nFollowsLiteral;
if (nMatchOffsetHi >= 0) {
+ int nMatchOffset;
+
nMatchOffset = ((unsigned int) nMatchOffsetHi) << 8;
nMatchOffset |= (unsigned int)(*pInputData++);
@@ -159,31 +160,24 @@ size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t }
/* Bits 7-1: offset; bit 0: length */
- nMatchOffset = (nCommand >> 1);
nMatchLen = (nCommand & 1) + 2;
nFollowsLiteral = 2;
nDecompressedSize += nMatchLen;
}
else {
- unsigned int nShortMatchOffset;
-
/* '111': 4 bit offset */
nResult = apultra_read_bit(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
if (nResult < 0) return -1;
- nShortMatchOffset = nResult << 3;
nResult = apultra_read_bit(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
if (nResult < 0) return -1;
- nShortMatchOffset |= nResult << 2;
nResult = apultra_read_bit(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
if (nResult < 0) return -1;
- nShortMatchOffset |= nResult << 1;
nResult = apultra_read_bit(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
if (nResult < 0) return -1;
- nShortMatchOffset |= nResult << 0;
nFollowsLiteral = 3;
nDecompressedSize++;
@@ -207,7 +201,7 @@ size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t *
* @return actual decompressed size, or -1 for error
*/
-size_t apultra_decompress(const unsigned char *pInputData, unsigned char *pOutData, size_t nInputSize, size_t nMaxOutBufferSize, size_t nDictionarySize, const unsigned int nFlags) {
+size_t apultra_decompress(const unsigned char *pInputData, unsigned char *pOutData, const size_t nInputSize, const size_t nMaxOutBufferSize, const size_t nDictionarySize, const unsigned int nFlags) {
const unsigned char *pInputDataEnd = pInputData + nInputSize;
unsigned char *pCurOutData = pOutData + nDictionarySize;
const unsigned char *pOutDataEnd = pCurOutData + nMaxOutBufferSize;
diff --git a/tools/apultra/src/expand.h b/tools/apultra/src/expand.h index 474660c..3d3ebc8 100644 --- a/tools/apultra/src/expand.h +++ b/tools/apultra/src/expand.h @@ -48,7 +48,7 @@ extern "C" { *
* @return maximum decompressed size
*/
-size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t nInputSize, const unsigned int nFlags);
+size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, const size_t nInputSize, const unsigned int nFlags);
/**
* Decompress data in memory
@@ -62,7 +62,7 @@ size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t *
* @return actual decompressed size, or -1 for error
*/
-size_t apultra_decompress(const unsigned char *pInputData, unsigned char *pOutBuffer, size_t nInputSize, size_t nMaxOutBufferSize, size_t nDictionarySize, const unsigned int nFlags);
+size_t apultra_decompress(const unsigned char *pInputData, unsigned char *pOutBuffer, const size_t nInputSize, const size_t nMaxOutBufferSize, const size_t nDictionarySize, const unsigned int nFlags);
#ifdef __cplusplus
}
diff --git a/tools/apultra/src/matchfinder.c b/tools/apultra/src/matchfinder.c index c3a30f3..b331d61 100644 --- a/tools/apultra/src/matchfinder.c +++ b/tools/apultra/src/matchfinder.c @@ -247,14 +247,12 @@ static int apultra_find_matches_at(apultra_compressor *pCompressor, const int nO const int nMatchLen = (const int)(ref >> (LCP_SHIFT + TAG_BITS));
if (nMatchOffset <= nMaxOffset) {
- nCurDepth = 0;
-
- cur_depth = depthptr;
matchptr->length = nMatchLen;
matchptr->offset = nMatchOffset;
- *depthptr = 0;
matchptr++;
- depthptr++;
+
+ *depthptr = nCurDepth = 0;
+ cur_depth = depthptr++;
nPrevLen = nMatchLen;
nPrevOffset = nMatchOffset;
@@ -272,20 +270,18 @@ static int apultra_find_matches_at(apultra_compressor *pCompressor, const int nO if ((matchptr - pMatches) < nMaxMatches) {
const int nMatchLen = (const int)(ref >> (LCP_SHIFT + TAG_BITS));
- if (nMatchOffset <= nMaxOffset && abs(nMatchOffset - nPrevOffset) >= 128) {
+ if (nMatchOffset <= nMaxOffset && (nPrevOffset - nMatchOffset) >= 128) {
if (nPrevOffset && nPrevLen > 2 && nMatchOffset == (nPrevOffset - 1) && nMatchLen == (nPrevLen - 1) && cur_depth && nCurDepth < LCP_MAX) {
- nCurDepth++;
- *cur_depth = nCurDepth | 0x8000;
+ *cur_depth = (++nCurDepth) | 0x8000;
}
else {
- nCurDepth = 0;
-
- cur_depth = depthptr;
matchptr->length = nMatchLen;
matchptr->offset = nMatchOffset;
- *depthptr = 0x8000;
matchptr++;
- depthptr++;
+
+ nCurDepth = 0;
+ *depthptr = 0x8000;
+ cur_depth = depthptr++;
}
nPrevLen = nMatchLen;
@@ -298,26 +294,24 @@ static int apultra_find_matches_at(apultra_compressor *pCompressor, const int nO while ((super_ref = pos_data[match_pos]) > ref) {
match_pos = intervals[super_ref & POS_MASK] & EXCL_VISITED_MASK;
- if (nOffset > match_pos && nIsSelfContainedBlock) {
+ if (nOffset >= match_pos && nIsSelfContainedBlock) {
const int nMatchOffset = (const int)(nOffset - match_pos);
if ((matchptr - pMatches) < nMaxMatches) {
const int nMatchLen = (const int)(ref >> (LCP_SHIFT + TAG_BITS));
- if (nMatchOffset <= nMaxOffset && (nMatchLen >= 3 || (nMatchLen >= 2 && (matchptr - pMatches) < (nMaxMatches - 1))) && nMatchLen < 1280 && abs(nMatchOffset - nPrevOffset) >= 128) {
+ if (nMatchOffset <= nMaxOffset && (nMatchLen >= 3 || (nMatchLen >= 2 && (matchptr - pMatches) < (nMaxMatches - 1))) && nMatchLen < 1280 && (nPrevOffset - nMatchOffset) >= 128) {
if (nPrevOffset && nPrevLen > 2 && nMatchOffset == (nPrevOffset - 1) && nMatchLen == (nPrevLen - 1) && cur_depth && nCurDepth < LCP_MAX) {
- nCurDepth++;
- *cur_depth = nCurDepth | 0x8000;
+ *cur_depth = (++nCurDepth) | 0x8000;
}
else {
- nCurDepth = 0;
-
- cur_depth = depthptr;
matchptr->length = nMatchLen;
matchptr->offset = nMatchOffset;
- *depthptr = 0x8000;
matchptr++;
- depthptr++;
+
+ nCurDepth = 0;
+ *depthptr = 0x8000;
+ cur_depth = depthptr++;
}
nPrevLen = nMatchLen;
@@ -336,18 +330,15 @@ static int apultra_find_matches_at(apultra_compressor *pCompressor, const int nO if ((matchptr - pMatches) < nMaxMatches) {
if (nMainMatchOffset <= nMaxOffset && nMainMatchOffset != nPrevOffset) {
if (nPrevOffset && nPrevLen > 2 && nMainMatchOffset == (nPrevOffset - 1) && nMainMatchLen == (nPrevLen - 1) && cur_depth && nCurDepth < LCP_MAX) {
- nCurDepth++;
- *cur_depth = nCurDepth;
+ *cur_depth = ++nCurDepth;
}
else {
- nCurDepth = 0;
-
- cur_depth = depthptr;
matchptr->length = nMainMatchLen;
matchptr->offset = nMainMatchOffset;
- *depthptr = 0;
matchptr++;
- depthptr++;
+
+ *depthptr = nCurDepth = 0;
+ cur_depth = depthptr++;
}
nPrevLen = nMainMatchLen;
@@ -363,26 +354,24 @@ static int apultra_find_matches_at(apultra_compressor *pCompressor, const int nO ref = super_ref;
match_pos = intervals[ref & POS_MASK] & EXCL_VISITED_MASK;
- if (nOffset > match_pos && nIsSelfContainedBlock) {
+ if (nOffset >= match_pos && nIsSelfContainedBlock) {
const int nMatchOffset = (const int)(nOffset - match_pos);
if ((matchptr - pMatches) < nMaxMatches) {
const int nMatchLen = (const int)(ref >> (LCP_SHIFT + TAG_BITS));
- if (nMatchOffset <= nMaxOffset && nMatchLen >= 2 && abs(nMatchOffset - nPrevOffset) >= 128) {
+ if (nMatchOffset <= nMaxOffset && nMatchLen >= 2 && (nPrevOffset - nMatchOffset) >= 128) {
if (nPrevOffset && nPrevLen > 2 && nMatchOffset == (nPrevOffset - 1) && nMatchLen == (nPrevLen - 1) && cur_depth && nCurDepth < LCP_MAX) {
- nCurDepth++;
- *cur_depth = nCurDepth | 0x8000;
+ *cur_depth = (++nCurDepth) | 0x8000;
}
else {
- nCurDepth = 0;
-
- cur_depth = depthptr;
matchptr->length = nMatchLen;
matchptr->offset = nMatchOffset;
- *depthptr = 0x8000;
matchptr++;
- depthptr++;
+
+ nCurDepth = 0;
+ *depthptr = 0x8000;
+ cur_depth = depthptr++;
}
nPrevLen = nMatchLen;
diff --git a/tools/apultra/src/matchfinder.h b/tools/apultra/src/matchfinder.h index 7fba5ce..ff99e11 100644 --- a/tools/apultra/src/matchfinder.h +++ b/tools/apultra/src/matchfinder.h @@ -33,14 +33,12 @@ #ifndef _MATCHFINDER_H
#define _MATCHFINDER_H
+#include "shrink.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-/* Forward declarations */
-typedef struct _apultra_match apultra_match;
-typedef struct _apultra_compressor apultra_compressor;
-
/**
* Parse input data, build suffix array and overlaid data structures to speed up match finding
*
diff --git a/tools/apultra/src/shrink.c b/tools/apultra/src/shrink.c index dec3566..d7c733d 100644 --- a/tools/apultra/src/shrink.c +++ b/tools/apultra/src/shrink.c @@ -164,7 +164,7 @@ static inline int apultra_get_offset_varlen_size(const int nLength, const int nM *
* @return number of extra bits required
*/
-static inline int apultra_get_match_varlen_size(int nLength, const int nMatchOffset) {
+static inline int apultra_get_match_varlen_size(const int nLength, const int nMatchOffset) {
if (nLength <= 3 && nMatchOffset < 128)
return 0;
else {
@@ -220,7 +220,7 @@ static void apultra_insert_forward_match(apultra_compressor *pCompressor, const const int nLen1 = rle_len[nRepPos];
const int nMinLen = (nLen0 < nLen1) ? nLen0 : nLen1;
- int nMaxRepLen = nEndOffset - nRepPos;
+ unsigned int nMaxRepLen = nEndOffset - nRepPos;
if (nMaxRepLen > LCP_MAX)
nMaxRepLen = LCP_MAX;
@@ -237,14 +237,14 @@ static void apultra_insert_forward_match(apultra_compressor *pCompressor, const while (pInWindowAtRepOffset < pInWindowMax && pInWindowAtRepOffset[0] == pInWindowAtRepOffset[-nMatchOffset])
pInWindowAtRepOffset++;
- const int nCurRepLen = (const int)(pInWindowAtRepOffset - pInWindowStart);
+ const unsigned int nCurRepLen = (const unsigned int)(pInWindowAtRepOffset - pInWindowStart);
unsigned short* fwd_depth = pCompressor->match_depth + ((nRepPos - nStartOffset) << MATCHES_PER_INDEX_SHIFT);
int r;
for (r = 0; fwd_match[r].length; r++) {
if (fwd_match[r].offset == nMatchOffset && (fwd_depth[r] & 0x3fff) == 0) {
- if ((const int)fwd_match[r].length < nCurRepLen) {
+ if (fwd_match[r].length < nCurRepLen) {
fwd_match[r].length = nCurRepLen;
fwd_depth[r] = 0;
}
@@ -729,10 +729,10 @@ static void apultra_optimize_forward(apultra_compressor *pCompressor, const unsi }
if (!nInsertForwardReps) {
- const apultra_arrival* end_arrival = &arrival[(i * nArrivalsPerPosition) + 0];
+ const apultra_arrival* end_arrival = &arrival[i * nArrivalsPerPosition];
apultra_final_match* pBestMatch = pCompressor->best_match - nStartOffset;
- while (end_arrival->from_slot > 0 && end_arrival->from_pos >= 0 && (const int)end_arrival->from_pos < nEndOffset) {
+ while (end_arrival->from_slot > 0 && end_arrival->from_pos < (const unsigned int)nEndOffset) {
pBestMatch[end_arrival->from_pos].length = end_arrival->match_len;
pBestMatch[end_arrival->from_pos].offset = (end_arrival->match_len >= 2) ? end_arrival->rep_offset : end_arrival->short_offset;
@@ -773,8 +773,7 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign i >= pBestMatch[i + 1].offset &&
(i + pBestMatch[i + 1].length + 1) <= nEndOffset &&
!memcmp(pInWindow + i - (pBestMatch[i + 1].offset), pInWindow + i, pBestMatch[i + 1].length + 1)) {
- if ((pBestMatch[i + 1].offset < MINMATCH3_OFFSET || (pBestMatch[i + 1].length + 1) >= 3 || (pBestMatch[i + 1].offset == nRepMatchOffset && nFollowsLiteral)) &&
- (pBestMatch[i + 1].offset < MINMATCH4_OFFSET || (pBestMatch[i + 1].length + 1) >= 4 || (pBestMatch[i + 1].offset == nRepMatchOffset && nFollowsLiteral))) {
+ if (pBestMatch[i + 1].offset < MINMATCH4_OFFSET || (pBestMatch[i + 1].length + 1) >= 4 || (pBestMatch[i + 1].offset == nRepMatchOffset && nFollowsLiteral)) {
int nCurPartialCommandSize = (pMatch->length == 1) ? (TOKEN_SIZE_4BIT_MATCH + 4) : (1 /* literal bit */ + 8 /* literal size */);
if (pBestMatch[i + 1].offset == nRepMatchOffset /* always follows a literal, the one at the current position */) {
@@ -786,10 +785,10 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign int nReducedPartialCommandSize;
if (pBestMatch[i + 1].offset == nRepMatchOffset && nFollowsLiteral) {
- nReducedPartialCommandSize = TOKEN_SIZE_LARGE_MATCH + 2 /* apultra_get_gamma2_size(2) */ + apultra_get_gamma2_size(pBestMatch[i + 1].length);
+ nReducedPartialCommandSize = TOKEN_SIZE_LARGE_MATCH + 2 /* apultra_get_gamma2_size(2) */ + apultra_get_gamma2_size(pBestMatch[i + 1].length + 1);
}
else {
- nReducedPartialCommandSize = apultra_get_offset_varlen_size(pBestMatch[i + 1].length, pBestMatch[i + 1].offset, nFollowsLiteral) + apultra_get_match_varlen_size(pBestMatch[i + 1].length, pBestMatch[i + 1].offset);
+ nReducedPartialCommandSize = apultra_get_offset_varlen_size(pBestMatch[i + 1].length + 1, pBestMatch[i + 1].offset, nFollowsLiteral) + apultra_get_match_varlen_size(pBestMatch[i + 1].length + 1, pBestMatch[i + 1].offset);
}
if (nReducedPartialCommandSize < nCurPartialCommandSize || (nFollowsLiteral == 0 && nLastMatchLen >= LCP_MAX)) {
@@ -805,8 +804,7 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign }
if (pMatch->length >= 2) {
- if (pMatch->length < 32 && /* Don't waste time considering large matches, they will always win over literals */
- (i + pMatch->length) < nEndOffset /* Don't consider the last match in the block, we can only reduce a match inbetween other tokens */) {
+ if (pMatch->length < 32 /* Don't waste time considering large matches, they will always win over literals */) {
int nNextIndex = i + pMatch->length;
int nNextFollowsLiteral = 0;
@@ -821,11 +819,13 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign if (nRepMatchOffset && nRepMatchOffset != pMatch->offset && pBestMatch[nNextIndex].offset && pMatch->offset != pBestMatch[nNextIndex].offset &&
nNextFollowsLiteral) {
/* Try to gain a match forward */
- if (i >= pBestMatch[nNextIndex].offset && (i - pBestMatch[nNextIndex].offset + pMatch->length) <= nEndOffset) {
+ if (i >= pBestMatch[nNextIndex].offset && (i + pMatch->length) <= nEndOffset) {
if ((pBestMatch[nNextIndex].offset < MINMATCH3_OFFSET || pMatch->length >= 3) &&
(pBestMatch[nNextIndex].offset < MINMATCH4_OFFSET || pMatch->length >= 4)) {
int nMaxLen = 0;
const unsigned char* pInWindowAtPos = pInWindow + i;
+ while ((nMaxLen + 8) < pMatch->length && !memcmp(pInWindowAtPos + nMaxLen - pBestMatch[nNextIndex].offset, pInWindowAtPos + nMaxLen, 8))
+ nMaxLen += 8;
while ((nMaxLen + 4) < pMatch->length && !memcmp(pInWindowAtPos + nMaxLen - pBestMatch[nNextIndex].offset, pInWindowAtPos + nMaxLen, 4))
nMaxLen += 4;
while (nMaxLen < pMatch->length && pInWindowAtPos[nMaxLen - pBestMatch[nNextIndex].offset] == pInWindowAtPos[nMaxLen])
@@ -870,7 +870,6 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign * we have calculated that this is shorter */
const int nOrigLen = pMatch->length;
- int j;
pMatch->offset = pBestMatch[nNextIndex].offset;
pMatch->length = nMaxLen;
@@ -938,7 +937,6 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign if (nOriginalCombinedCommandSize > nReducedCommandSize && !nCannotEncode) {
/* Reduce */
const int nMatchLen = pMatch->length;
- int j;
for (j = 0; j < nMatchLen; j++) {
pBestMatch[i + j].offset = match1[i + j];
@@ -1059,7 +1057,7 @@ static int apultra_reduce_commands(apultra_compressor *pCompressor, const unsign *
* @return size of compressed data in output buffer, or -1 if the data is uncompressible
*/
-static int apultra_write_block(apultra_compressor *pCompressor, apultra_final_match *pBestMatch, const unsigned char *pInWindow, const int nStartOffset, const int nEndOffset, unsigned char *pOutData, const int nMaxOutDataSize, int *nCurBitsOffset, int *nCurBitShift, int *nFollowsLiteral, int *nCurRepMatchOffset, const int nBlockFlags) {
+static int apultra_write_block(apultra_compressor *pCompressor, const apultra_final_match *pBestMatch, const unsigned char *pInWindow, const int nStartOffset, const int nEndOffset, unsigned char *pOutData, const int nMaxOutDataSize, int *nCurBitsOffset, int *nCurBitShift, int *nFollowsLiteral, int *nCurRepMatchOffset, const int nBlockFlags) {
int i;
int nRepMatchOffset = *nCurRepMatchOffset;
int nCurFollowsLiteral = *nFollowsLiteral;
@@ -1640,7 +1638,7 @@ static int apultra_compressor_shrink_block(apultra_compressor *pCompressor, cons *
* @return maximum compressed size
*/
-size_t apultra_get_max_compressed_size(size_t nInputSize) {
+size_t apultra_get_max_compressed_size(const size_t nInputSize) {
return ((nInputSize * 9 /* literals + literal bits */ + 1 /* match bit */ + 2 /* 7+1 command bits */ + 8 /* EOD offset bits */) + 7) >> 3;
}
@@ -1659,8 +1657,8 @@ size_t apultra_get_max_compressed_size(size_t nInputSize) { *
* @return actual compressed size, or -1 for error
*/
-size_t apultra_compress(const unsigned char *pInputData, unsigned char *pOutBuffer, size_t nInputSize, size_t nMaxOutBufferSize,
- const unsigned int nFlags, size_t nMaxWindowSize, size_t nDictionarySize, void(*progress)(long long nOriginalSize, long long nCompressedSize), apultra_stats *pStats) {
+size_t apultra_compress(const unsigned char *pInputData, unsigned char *pOutBuffer, const size_t nInputSize, const size_t nMaxOutBufferSize,
+ const unsigned int nFlags, const size_t nMaxWindowSize, const size_t nDictionarySize, void(*progress)(long long nOriginalSize, long long nCompressedSize), apultra_stats *pStats) {
apultra_compressor compressor;
size_t nOriginalSize = 0;
size_t nCompressedSize = 0L;
@@ -1724,12 +1722,10 @@ size_t apultra_compress(const unsigned char *pInputData, unsigned char *pOutBuff if (nOutDataSize >= 0) {
/* Write compressed block */
- if (!nError) {
- nOriginalSize += nInDataSize;
- nCompressedSize += nOutDataSize;
- if (nCurBitShift != -1)
- nCurBitsOffset -= nOutDataSize;
- }
+ nOriginalSize += nInDataSize;
+ nCompressedSize += nOutDataSize;
+ if (nCurBitShift != -1)
+ nCurBitsOffset -= nOutDataSize;
}
else {
nError = -1;
diff --git a/tools/apultra/src/shrink.h b/tools/apultra/src/shrink.h index 3be37e9..44feeb7 100644 --- a/tools/apultra/src/shrink.h +++ b/tools/apultra/src/shrink.h @@ -150,7 +150,7 @@ typedef struct _apultra_compressor { *
* @return maximum compressed size
*/
-size_t apultra_get_max_compressed_size(size_t nInputSize);
+size_t apultra_get_max_compressed_size(const size_t nInputSize);
/**
* Compress memory
@@ -167,8 +167,8 @@ size_t apultra_get_max_compressed_size(size_t nInputSize); *
* @return actual compressed size, or -1 for error
*/
-size_t apultra_compress(const unsigned char *pInputData, unsigned char *pOutBuffer, size_t nInputSize, size_t nMaxOutBufferSize,
- const unsigned int nFlags, size_t nMaxWindowSize, size_t nDictionarySize, void(*progress)(long long nOriginalSize, long long nCompressedSize), apultra_stats *pStats);
+size_t apultra_compress(const unsigned char *pInputData, unsigned char *pOutBuffer, const size_t nInputSize, const size_t nMaxOutBufferSize,
+ const unsigned int nFlags, const size_t nMaxWindowSize, const size_t nDictionarySize, void(*progress)(long long nOriginalSize, long long nCompressedSize), apultra_stats *pStats);
#ifdef __cplusplus
}
|