```
Commit message: Fix: Resolve compilation issues with XCompress and Minilzo. ```
This commit is contained in:
parent
9a5ae3bf51
commit
f3d0abb65e
@ -1,73 +1,68 @@
|
|||||||
#include "compression.h"
|
#include "compression.h"
|
||||||
//#include "minilzo.h"
|
#include "minilzo.h"
|
||||||
|
#include "xcompress.h"
|
||||||
//#define XBOXAPI __declspec(dllimport)
|
|
||||||
//#include "xcompress.h"
|
|
||||||
|
|
||||||
#include <QLibrary>
|
#include <QLibrary>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDataStream>
|
|
||||||
|
|
||||||
QByteArray Compression::CompressXMem(const QByteArray &data)
|
QByteArray Compression::CompressXMem(const QByteArray &data)
|
||||||
{
|
{
|
||||||
// XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
||||||
// lzxParams.Flags = 0;
|
lzxParams.Flags = 0;
|
||||||
// lzxParams.WindowSize = 0x20000;
|
lzxParams.WindowSize = 0x20000;
|
||||||
// lzxParams.CompressionPartitionSize = 0x80000;
|
lzxParams.CompressionPartitionSize = 0x80000;
|
||||||
|
|
||||||
// XMEMCOMPRESSION_CONTEXT ctx = nullptr;
|
XMEMCOMPRESSION_CONTEXT ctx = nullptr;
|
||||||
// if (FAILED(XMemCreateCompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
if (FAILED(XMemCreateCompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
||||||
// return QByteArray();
|
|
||||||
|
|
||||||
// SIZE_T estimatedSize = data.size() + XCOMPRESS_LZX_BLOCK_GROWTH_SIZE_MAX;
|
|
||||||
// QByteArray output(static_cast<int>(estimatedSize), 0);
|
|
||||||
// SIZE_T actualSize = estimatedSize;
|
|
||||||
|
|
||||||
// HRESULT hr = XMemCompress(ctx, output.data(), &actualSize, data.constData(), data.size());
|
|
||||||
// XMemDestroyCompressionContext(ctx);
|
|
||||||
|
|
||||||
// if (FAILED(hr))
|
|
||||||
// return QByteArray();
|
|
||||||
|
|
||||||
// output.resize(static_cast<int>(actualSize));
|
|
||||||
// return output;
|
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|
||||||
|
SIZE_T estimatedSize = data.size() + XCOMPRESS_LZX_BLOCK_GROWTH_SIZE_MAX;
|
||||||
|
QByteArray output(static_cast<int>(estimatedSize), 0);
|
||||||
|
SIZE_T actualSize = estimatedSize;
|
||||||
|
|
||||||
|
HRESULT hr = XMemCompress(ctx, output.data(), &actualSize, data.constData(), data.size());
|
||||||
|
XMemDestroyCompressionContext(ctx);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
return QByteArray();
|
||||||
|
|
||||||
|
output.resize(static_cast<int>(actualSize));
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray Compression::DecompressXMem(const QByteArray &data, int flags, int windowSize, int partSize)
|
QByteArray Compression::DecompressXMem(const QByteArray &data, int flags, int windowSize, int partSize)
|
||||||
{
|
{
|
||||||
// if (data.isEmpty())
|
if (data.isEmpty())
|
||||||
// return {};
|
return {};
|
||||||
|
|
||||||
// XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
||||||
// lzxParams.Flags = flags;
|
lzxParams.Flags = flags;
|
||||||
// lzxParams.WindowSize = windowSize;
|
lzxParams.WindowSize = windowSize;
|
||||||
// lzxParams.CompressionPartitionSize = partSize;
|
lzxParams.CompressionPartitionSize = partSize;
|
||||||
|
|
||||||
// XMEMDECOMPRESSION_CONTEXT ctx = nullptr;
|
XMEMDECOMPRESSION_CONTEXT ctx = nullptr;
|
||||||
// if (FAILED(XMemCreateDecompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
if (FAILED(XMemCreateDecompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
||||||
// return {};
|
return {};
|
||||||
|
|
||||||
// // Allocate large enough buffer for decompression (16 MB is a safe upper bound)
|
// Allocate large enough buffer for decompression (16 MB is a safe upper bound)
|
||||||
// const SIZE_T kMaxOutSize = 16 * 1024 * 1024;
|
const SIZE_T kMaxOutSize = 16 * 1024 * 1024;
|
||||||
// QByteArray output(static_cast<int>(kMaxOutSize), Qt::Uninitialized);
|
QByteArray output(static_cast<int>(kMaxOutSize), Qt::Uninitialized);
|
||||||
// SIZE_T actualSize = kMaxOutSize;
|
SIZE_T actualSize = kMaxOutSize;
|
||||||
|
|
||||||
// HRESULT hr = XMemDecompress(ctx,
|
HRESULT hr = XMemDecompress(ctx,
|
||||||
// output.data(), &actualSize,
|
output.data(), &actualSize,
|
||||||
// data.constData(), data.size() + 16);
|
data.constData(), data.size() + 16);
|
||||||
|
|
||||||
// XMemDestroyDecompressionContext(ctx);
|
XMemDestroyDecompressionContext(ctx);
|
||||||
|
|
||||||
// if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
// qWarning() << "XMemDecompress failed with HRESULT:" << hr;
|
qWarning() << "XMemDecompress failed with HRESULT:" << hr;
|
||||||
// return {};
|
return {};
|
||||||
// }
|
}
|
||||||
|
|
||||||
// output.resize(static_cast<int>(actualSize));
|
output.resize(static_cast<int>(actualSize));
|
||||||
// return output;
|
return output;
|
||||||
return QByteArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 Compression::CalculateAdler32Checksum(const QByteArray &data) {
|
quint32 Compression::CalculateAdler32Checksum(const QByteArray &data) {
|
||||||
@ -298,22 +293,22 @@ QByteArray Compression::CompressDeflateWithSettings(const QByteArray &aData, int
|
|||||||
|
|
||||||
QByteArray Compression::DecompressLZO(const QByteArray &aCompressedData, quint32 aDestSize) {
|
QByteArray Compression::DecompressLZO(const QByteArray &aCompressedData, quint32 aDestSize) {
|
||||||
QByteArray dst;
|
QByteArray dst;
|
||||||
// static bool ok = (lzo_init() == LZO_E_OK);
|
static bool ok = (lzo_init() == LZO_E_OK);
|
||||||
// if (!ok)
|
if (!ok)
|
||||||
// throw std::runtime_error("lzo_init failed");
|
throw std::runtime_error("lzo_init failed");
|
||||||
|
|
||||||
// dst = QByteArray(aDestSize, Qt::Uninitialized);
|
dst = QByteArray(aDestSize, Qt::Uninitialized);
|
||||||
// lzo_uint out = aDestSize;
|
lzo_uint out = aDestSize;
|
||||||
|
|
||||||
// int rc = lzo1x_decompress_safe(
|
int rc = lzo1x_decompress_safe(
|
||||||
// reinterpret_cast<const lzo_bytep>(aCompressedData.constData()),
|
reinterpret_cast<const lzo_bytep>(aCompressedData.constData()),
|
||||||
// static_cast<lzo_uint>(aCompressedData.size()),
|
static_cast<lzo_uint>(aCompressedData.size()),
|
||||||
// reinterpret_cast<lzo_bytep>(dst.data()),
|
reinterpret_cast<lzo_bytep>(dst.data()),
|
||||||
// &out,
|
&out,
|
||||||
// nullptr);
|
nullptr);
|
||||||
|
|
||||||
// if (rc != LZO_E_OK || out != aDestSize)
|
if (rc != LZO_E_OK || out != aDestSize)
|
||||||
// throw std::runtime_error("LZO decompression error");
|
throw std::runtime_error("LZO decompression error");
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user