Integrated lzokay

This commit is contained in:
Aruki 2018-12-23 22:41:21 -07:00
parent 02e4e47fb2
commit 12ff0d1f73
6 changed files with 72 additions and 9 deletions

5
.gitmodules vendored
View File

@ -18,4 +18,7 @@
url = https://github.com/arukibree/LibCommon
[submodule "externals/lzo"]
path = externals/lzo
url = https://github.com/nemequ/lzo
url = https://github.com/nemequ/lzo
[submodule "externals/lzokay"]
path = externals/lzokay
url = https://github.com/jackoalan/lzokay

1
externals/lzokay vendored Submodule

@ -0,0 +1 @@
Subproject commit f7da328248f3fea1a5e05d3f39598850383b1867

View File

@ -1,4 +1,5 @@
# CONFIG += PUBLIC_RELEASE
DEFINES += USE_LZOKAY
win32: {
QMAKE_CXXFLAGS += /WX \ # Treat warnings as errors

View File

@ -1,7 +1,12 @@
#include "CompressionUtil.h"
#include <Common/Common.h>
#if USE_LZOKAY
#include <lzokay.hpp>
#else
#include <lzo/lzo1x.h>
#endif
#include <zlib.h>
namespace CompressionUtil
@ -23,6 +28,21 @@ namespace CompressionUtil
}
}
#if USE_LZOKAY
const char* ErrorText_LZO(lzokay::EResult Result)
{
switch (Result)
{
case lzokay::EResult::LookbehindOverrun: return "LookbehindOverrun";
case lzokay::EResult::OutputOverrun: return "OutputOverrun";
case lzokay::EResult::InputOverrun: return "InputOverrun";
case lzokay::EResult::Error: return "Error";
case lzokay::EResult::Success: return "Success";
case lzokay::EResult::InputNotConsumed: return "InputNotConsumed";
default: return "UNKNOWN LZO ERROR";
}
}
#else
const char* ErrorText_LZO(int32 Error)
{
switch (Error)
@ -44,6 +64,7 @@ namespace CompressionUtil
default: return "UNKNOWN LZO ERROR";
}
}
#endif
// ************ DECOMPRESS ************
bool DecompressZlib(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32 DstLen, uint32& rTotalOut)
@ -83,6 +104,17 @@ namespace CompressionUtil
bool DecompressLZO(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32& rTotalOut)
{
#if USE_LZOKAY
lzokay::EResult Result = lzokay::decompress(pSrc, (size_t) SrcLen, pDst, (size_t&) rTotalOut);
if (Result < lzokay::EResult::Success)
{
errorf("LZO error: %s", ErrorText_LZO(Result));
return false;
}
return true;
#else
lzo_init();
lzo_uint TotalOut;
int32 Error = lzo1x_decompress(pSrc, SrcLen, pDst, &TotalOut, LZO1X_MEM_DECOMPRESS);
@ -95,6 +127,7 @@ namespace CompressionUtil
}
return true;
#endif
}
bool DecompressSegmentedData(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32 DstLen)
@ -182,8 +215,20 @@ namespace CompressionUtil
else return true;
}
bool CompressLZO(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32& rTotalOut)
bool CompressLZO(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32 DstLen, uint32& rTotalOut)
{
#if USE_LZOKAY
rTotalOut = DstLen;
lzokay::EResult Result = lzokay::compress(pSrc, (size_t) SrcLen, pDst, (size_t&) rTotalOut);
if (Result < lzokay::EResult::Success)
{
errorf("LZO error: %s", ErrorText_LZO(Result));
return false;
}
return true;
#else
lzo_init();
uint8 *pWorkMem = new uint8[LZO1X_999_MEM_COMPRESS];
@ -197,6 +242,7 @@ namespace CompressionUtil
}
return true;
#endif
}
bool CompressSegmentedData(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32& rTotalOut, bool IsZlib, bool AllowUncompressedSegments)
@ -219,7 +265,7 @@ namespace CompressionUtil
if (IsZlib)
CompressZlib(pSrc, Size, Compressed.data(), Compressed.size(), TotalOut);
else
CompressLZO(pSrc, Size, Compressed.data(), TotalOut);
CompressLZO(pSrc, Size, Compressed.data(), Compressed.size(), TotalOut);
// Verify that the compressed data is actually smaller.
if (AllowUncompressedSegments && TotalOut >= Size)

View File

@ -67,7 +67,6 @@ INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/CodeGen/include \
$$EXTERNALS_DIR/glew-2.1.0/include \
$$EXTERNALS_DIR/LibCommon/Source \
$$EXTERNALS_DIR/lzo/include \
$$EXTERNALS_DIR/nod/include \
$$EXTERNALS_DIR/nod/logvisor/include \
$$EXTERNALS_DIR/tinyxml2 \
@ -366,7 +365,14 @@ CODEGEN_OUT_PATH = $$BUILD_DIR/Core/codegen_build/auto_codegen.cpp
CODEGEN_SRC_PATH = $$PWD
include($$EXTERNALS_DIR/CodeGen/codegen.pri)
# Library Sources
SOURCES += $$EXTERNALS_DIR/lzo/src/lzo_init.c \
$$EXTERNALS_DIR/lzo/src/lzo1x_9x.c \
$$EXTERNALS_DIR/lzo/src/lzo1x_d1.c
# LZO
contains(DEFINES, USE_LZOKAY) {
INCLUDEPATH += $$EXTERNALS_DIR/lzokay
SOURCES += $$EXTERNALS_DIR/lzokay/lzokay.cpp
} else {
INCLUDEPATH += $$EXTERNALS_DIR/lzo/include
SOURCES += $$EXTERNALS_DIR/lzo/src/lzo_init.c \
$$EXTERNALS_DIR/lzo/src/lzo1x_9x.c \
$$EXTERNALS_DIR/lzo/src/lzo1x_d1.c
}

View File

@ -79,7 +79,6 @@ INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/CodeGen/include \
$$EXTERNALS_DIR/glew-2.1.0/include \
$$EXTERNALS_DIR/LibCommon/Source \
$$EXTERNALS_DIR/lzo/include \
$$EXTERNALS_DIR/nod/include \
$$EXTERNALS_DIR/nod/logvisor/include \
$$EXTERNALS_DIR/tinyxml2 \
@ -308,3 +307,10 @@ CODEGEN_DIR = $$EXTERNALS_DIR/CodeGen
CODEGEN_OUT_PATH = $$BUILD_DIR/Editor/codegen_build/auto_codegen.cpp
CODEGEN_SRC_PATH = $$PWD
include($$EXTERNALS_DIR/CodeGen/codegen.pri)
# LZO
contains(DEFINES, USE_LZOKAY) {
INCLUDEPATH += $$EXTERNALS_DIR/lzokay
} else {
INCLUDEPATH += $$EXTERNALS_DIR/lzo/include
}