```
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 "minilzo.h"
|
||||
|
||||
//#define XBOXAPI __declspec(dllimport)
|
||||
//#include "xcompress.h"
|
||||
#include "minilzo.h"
|
||||
#include "xcompress.h"
|
||||
|
||||
#include <QLibrary>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
|
||||
QByteArray Compression::CompressXMem(const QByteArray &data)
|
||||
{
|
||||
// XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
||||
// lzxParams.Flags = 0;
|
||||
// lzxParams.WindowSize = 0x20000;
|
||||
// lzxParams.CompressionPartitionSize = 0x80000;
|
||||
XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
||||
lzxParams.Flags = 0;
|
||||
lzxParams.WindowSize = 0x20000;
|
||||
lzxParams.CompressionPartitionSize = 0x80000;
|
||||
|
||||
// XMEMCOMPRESSION_CONTEXT ctx = nullptr;
|
||||
// if (FAILED(XMemCreateCompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
||||
// return QByteArray();
|
||||
XMEMCOMPRESSION_CONTEXT ctx = nullptr;
|
||||
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;
|
||||
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);
|
||||
HRESULT hr = XMemCompress(ctx, output.data(), &actualSize, data.constData(), data.size());
|
||||
XMemDestroyCompressionContext(ctx);
|
||||
|
||||
// if (FAILED(hr))
|
||||
// return QByteArray();
|
||||
if (FAILED(hr))
|
||||
return QByteArray();
|
||||
|
||||
// output.resize(static_cast<int>(actualSize));
|
||||
// return output;
|
||||
return QByteArray();
|
||||
output.resize(static_cast<int>(actualSize));
|
||||
return output;
|
||||
}
|
||||
|
||||
QByteArray Compression::DecompressXMem(const QByteArray &data, int flags, int windowSize, int partSize)
|
||||
{
|
||||
// if (data.isEmpty())
|
||||
// return {};
|
||||
if (data.isEmpty())
|
||||
return {};
|
||||
|
||||
// XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
||||
// lzxParams.Flags = flags;
|
||||
// lzxParams.WindowSize = windowSize;
|
||||
// lzxParams.CompressionPartitionSize = partSize;
|
||||
XMEMCODEC_PARAMETERS_LZX lzxParams = {};
|
||||
lzxParams.Flags = flags;
|
||||
lzxParams.WindowSize = windowSize;
|
||||
lzxParams.CompressionPartitionSize = partSize;
|
||||
|
||||
// XMEMDECOMPRESSION_CONTEXT ctx = nullptr;
|
||||
// if (FAILED(XMemCreateDecompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
||||
// return {};
|
||||
XMEMDECOMPRESSION_CONTEXT ctx = nullptr;
|
||||
if (FAILED(XMemCreateDecompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx)
|
||||
return {};
|
||||
|
||||
// // Allocate large enough buffer for decompression (16 MB is a safe upper bound)
|
||||
// const SIZE_T kMaxOutSize = 16 * 1024 * 1024;
|
||||
// QByteArray output(static_cast<int>(kMaxOutSize), Qt::Uninitialized);
|
||||
// SIZE_T actualSize = kMaxOutSize;
|
||||
// Allocate large enough buffer for decompression (16 MB is a safe upper bound)
|
||||
const SIZE_T kMaxOutSize = 16 * 1024 * 1024;
|
||||
QByteArray output(static_cast<int>(kMaxOutSize), Qt::Uninitialized);
|
||||
SIZE_T actualSize = kMaxOutSize;
|
||||
|
||||
// HRESULT hr = XMemDecompress(ctx,
|
||||
// output.data(), &actualSize,
|
||||
// data.constData(), data.size() + 16);
|
||||
HRESULT hr = XMemDecompress(ctx,
|
||||
output.data(), &actualSize,
|
||||
data.constData(), data.size() + 16);
|
||||
|
||||
// XMemDestroyDecompressionContext(ctx);
|
||||
XMemDestroyDecompressionContext(ctx);
|
||||
|
||||
// if (FAILED(hr)) {
|
||||
// qWarning() << "XMemDecompress failed with HRESULT:" << hr;
|
||||
// return {};
|
||||
// }
|
||||
if (FAILED(hr)) {
|
||||
qWarning() << "XMemDecompress failed with HRESULT:" << hr;
|
||||
return {};
|
||||
}
|
||||
|
||||
// output.resize(static_cast<int>(actualSize));
|
||||
// return output;
|
||||
return QByteArray();
|
||||
output.resize(static_cast<int>(actualSize));
|
||||
return output;
|
||||
}
|
||||
|
||||
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 dst;
|
||||
// static bool ok = (lzo_init() == LZO_E_OK);
|
||||
// if (!ok)
|
||||
// throw std::runtime_error("lzo_init failed");
|
||||
static bool ok = (lzo_init() == LZO_E_OK);
|
||||
if (!ok)
|
||||
throw std::runtime_error("lzo_init failed");
|
||||
|
||||
// dst = QByteArray(aDestSize, Qt::Uninitialized);
|
||||
// lzo_uint out = aDestSize;
|
||||
dst = QByteArray(aDestSize, Qt::Uninitialized);
|
||||
lzo_uint out = aDestSize;
|
||||
|
||||
// int rc = lzo1x_decompress_safe(
|
||||
// reinterpret_cast<const lzo_bytep>(aCompressedData.constData()),
|
||||
// static_cast<lzo_uint>(aCompressedData.size()),
|
||||
// reinterpret_cast<lzo_bytep>(dst.data()),
|
||||
// &out,
|
||||
// nullptr);
|
||||
int rc = lzo1x_decompress_safe(
|
||||
reinterpret_cast<const lzo_bytep>(aCompressedData.constData()),
|
||||
static_cast<lzo_uint>(aCompressedData.size()),
|
||||
reinterpret_cast<lzo_bytep>(dst.data()),
|
||||
&out,
|
||||
nullptr);
|
||||
|
||||
// if (rc != LZO_E_OK || out != aDestSize)
|
||||
// throw std::runtime_error("LZO decompression error");
|
||||
if (rc != LZO_E_OK || out != aDestSize)
|
||||
throw std::runtime_error("LZO decompression error");
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user