ULONG Compress(PVOID pvOutput, ULONG OutBufferSize, PVOID pvInput, ULONG InputSize) { LONG Result; ucl_compress_config_t UclConfig; struct { ULONG Magic; ULONG CompressedSize; } *pHeader; FillMemory(&UclConfig, sizeof(UclConfig), -1); UclConfig.bb_endian = 0; UclConfig.bb_size = 32; UclConfig.max_offset = 0x3FFFFF; *(PULONG_PTR)&pHeader = (ULONG_PTR)pvOutput; pHeader->CompressedSize = OutBufferSize - sizeof(*pHeader); Result = ucl_nrv2e_99_compress( (PBYTE)pvInput, InputSize, (PBYTE)(pHeader + 1), (PUINT)&pHeader->CompressedSize, NULL, 10, &UclConfig, NULL ); pHeader->Magic = UCL_COMPRESS_MAGIC; return pHeader->CompressedSize + sizeof(*pHeader); }
int64_t lzbench_ucl_nrv2e_compress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, char*) { ucl_uint complen; int res = ucl_nrv2e_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL); if (res != UCL_E_OK) return 0; return complen; }
void UclOutSaveFile::flush(void) { int res; if (_bufPos) { if (_wasFlushed) { // the engine flushed this file and afterwards wrote more data. // this is unsupported because it results in savefiles that consist // of two or more compressed segments. printf("Error: 2nd call to UclOutSaveFile::flush!\n"); res = -1; } else { uint32 compSize = _bufPos * 2; uint8 *compBuf = (uint8*)memalign(64, compSize + 8); *(uint32*)(compBuf + 0) = UCL_MAGIC; *(uint32*)(compBuf + 4) = _bufPos; // uncompressed size res = ucl_nrv2e_99_compress(_buf, _bufPos, compBuf + 8, &compSize, NULL, 10, NULL, NULL); if (res >= 0) { res = _mc->write(_fd, compBuf, compSize + 8); if (res != (int)compSize + 8) { printf("flush: write failed, %d != %d\n", res, compSize + 8); res = -1; } } else printf("Unable to compress %d bytes of savedata, errorcode %d\n", _bufPos, res); free(compBuf); _bufPos = 0; } if (res < 0) { _ioFailed = true; printf("UclOutSaveFile::flush failed!\n"); if (_fd >= 0) { // the file is broken; delete it _mc->close(_fd); res = _mc->remove(_fileName); if (res == 0) printf("File %s: remove ok\n", _fileName); else printf("File %s: remove error %d\n", _fileName, res); _fd = -1; } } } }
int64_t lzbench_ucl_compress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t algo, size_t level, size_t) { ucl_uint complen; int res; switch (algo) { default: case 1: res = ucl_nrv2b_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL); break; case 2: res = ucl_nrv2d_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL); break; case 3: res = ucl_nrv2e_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL); break; } if (res != UCL_E_OK) return 0; return complen; }