-
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yan Yakubov
committed
Apr 4, 2016
1 parent
66323ad
commit abd6f22
Showing
9 changed files
with
272 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "stdafx.h" | ||
#include "lzo_compressor.h" | ||
#include "lzo/lzo1x.h" | ||
|
||
int lzo_compress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize, | ||
void *workMem, const void *dict, u32 dictSize) | ||
{ | ||
return lzo1x_999_compress_dict((lzo_bytep)input, inputSize, (lzo_bytep)output, (lzo_uintp)&outputSize, | ||
workMem, (lzo_bytep)dict, dictSize); | ||
} | ||
|
||
int lzo_decompress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize, | ||
void *workMem, const void *dict, u32 dictSize) | ||
{ | ||
return lzo1x_decompress_dict_safe((lzo_bytep)input, inputSize, (lzo_bytep)output, (lzo_uintp)&outputSize, | ||
workMem, (lzo_bytep)dict, dictSize); | ||
} | ||
|
||
int lzo_initialize() | ||
{ return lzo_init(); } | ||
|
||
u32 lzo_get_workmem_size() | ||
{ return LZO1X_999_MEM_COMPRESS; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
#include "xrCore/xrCore.h" | ||
|
||
XRCORE_API int lzo_compress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize, | ||
void *workMem, const void *dict, u32 dictSize); | ||
|
||
XRCORE_API int lzo_decompress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize, | ||
void *workMem, const void *dict, u32 dict_len); | ||
|
||
XRCORE_API int lzo_initialize(); | ||
|
||
XRCORE_API u32 lzo_get_workmem_size(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "stdafx.h" | ||
#pragma hdrstop | ||
|
||
|
||
|
||
#include "lzo/lzo1x.h" | ||
|
||
|
||
#define HEAP_ALLOC(var,size) \ | ||
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] | ||
|
||
__declspec(thread) HEAP_ALLOC(rtc_wrkmem, LZO1X_1_MEM_COMPRESS); | ||
|
||
|
||
void rtc_initialize() | ||
{ | ||
VERIFY(lzo_init() == LZO_E_OK); | ||
} | ||
|
||
u32 rtc_csize(u32 in) | ||
{ | ||
VERIFY(in); | ||
return in + in / 64 + 16 + 3; | ||
} | ||
|
||
u32 rtc_compress(void* dst, u32 dst_len, const void* src, u32 src_len) | ||
{ | ||
u32 out_size = dst_len; | ||
int r = lzo1x_1_compress( | ||
(const lzo_byte*)src, (lzo_uint)src_len, | ||
(lzo_byte*)dst, (lzo_uintp)&out_size, | ||
rtc_wrkmem); | ||
VERIFY(r == LZO_E_OK); | ||
return out_size; | ||
} | ||
u32 rtc_decompress(void* dst, u32 dst_len, const void* src, u32 src_len) | ||
{ | ||
u32 out_size = dst_len; | ||
int r = lzo1x_decompress( | ||
(const lzo_byte*)src, (lzo_uint)src_len, | ||
(lzo_byte*)dst, (lzo_uintp)&out_size, | ||
rtc_wrkmem); | ||
VERIFY(r == LZO_E_OK); | ||
return out_size; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef rt_compressorH | ||
#define rt_compressorH | ||
#pragma once | ||
|
||
extern XRCORE_API void rtc_initialize(); | ||
extern XRCORE_API u32 rtc_compress(void* dst, u32 dst_len, const void* src, u32 src_len); | ||
extern XRCORE_API u32 rtc_decompress(void* dst, u32 dst_len, const void* src, u32 src_len); | ||
extern XRCORE_API u32 rtc_csize(u32 in); | ||
|
||
extern XRCORE_API void rtc9_initialize(); | ||
extern XRCORE_API void rtc9_uninitialize(); | ||
extern XRCORE_API u32 rtc9_compress(void* dst, u32 dst_len, const void* src, u32 src_len); | ||
extern XRCORE_API u32 rtc9_decompress(void* dst, u32 dst_len, const void* src, u32 src_len); | ||
extern XRCORE_API u32 rtc9_csize(u32 in); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include "stdafx.h" | ||
#pragma hdrstop | ||
|
||
#include "lzo/lzo1x.h" | ||
|
||
|
||
//============================================================================== | ||
|
||
#define HEAP_ALLOC(var,size) \ | ||
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] | ||
|
||
__declspec(thread) HEAP_ALLOC(rtc9_wrkmem, LZO1X_999_MEM_COMPRESS); | ||
|
||
|
||
static u8* _LZO_Dictionary = NULL; | ||
static u32 _LZO_DictionarySize = 0; | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
|
||
void | ||
rtc9_initialize() | ||
{ | ||
static bool initialized = false; | ||
|
||
if (initialized) | ||
return; | ||
|
||
VERIFY(lzo_init() == LZO_E_OK); | ||
|
||
string_path file_name; | ||
|
||
FS.update_path(file_name, "$game_config$", "mp\\lzo-dict.bin"); | ||
|
||
if (FS.exist(file_name)) | ||
{ | ||
IReader* reader = FS.r_open(file_name); | ||
|
||
R_ASSERT(reader); | ||
|
||
_LZO_DictionarySize = reader->length(); | ||
_LZO_Dictionary = (u8*)xr_malloc(_LZO_DictionarySize); | ||
|
||
reader->r(_LZO_Dictionary, _LZO_DictionarySize); | ||
FS.r_close(reader); | ||
|
||
Msg("using LZO-dictionary \"%s\"", file_name); | ||
} | ||
else | ||
{ | ||
Msg("\"%s\" not found", file_name); | ||
} | ||
|
||
initialized = true; | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
|
||
void | ||
rtc9_uninitialize() | ||
{ | ||
if (_LZO_Dictionary) | ||
{ | ||
xr_free(_LZO_Dictionary); | ||
|
||
_LZO_Dictionary = NULL; | ||
_LZO_DictionarySize = 0; | ||
} | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
|
||
u32 | ||
rtc9_csize(u32 in) | ||
{ | ||
VERIFY(in); | ||
return in + in / 64 + 16 + 3; | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
|
||
u32 | ||
rtc9_compress(void* dst, u32 dst_len, const void* src, u32 src_len) | ||
{ | ||
u32 out_size = dst_len; | ||
int r = LZO_E_ERROR; | ||
|
||
rtc9_initialize(); | ||
|
||
if (_LZO_Dictionary) | ||
{ | ||
r = lzo1x_999_compress_dict((const lzo_byte*)src, (lzo_uint)src_len, | ||
(lzo_byte*)dst, (lzo_uintp)&out_size, | ||
rtc9_wrkmem, _LZO_Dictionary, _LZO_DictionarySize | ||
); | ||
} | ||
else | ||
{ | ||
r = lzo1x_999_compress((const lzo_byte*)src, (lzo_uint)src_len, | ||
(lzo_byte*)dst, (lzo_uintp)&out_size, | ||
rtc9_wrkmem | ||
); | ||
} | ||
|
||
VERIFY(r == LZO_E_OK); | ||
|
||
return out_size; | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
|
||
u32 | ||
rtc9_decompress(void* dst, u32 dst_len, const void* src, u32 src_len) | ||
{ | ||
u32 out_size = dst_len; | ||
int r = LZO_E_ERROR; | ||
|
||
rtc9_initialize(); | ||
|
||
if (_LZO_Dictionary) | ||
{ | ||
r = lzo1x_decompress_dict_safe((const lzo_byte*)src, (lzo_uint)src_len, | ||
(lzo_byte*)dst, (lzo_uintp)&out_size, | ||
NULL, _LZO_Dictionary, _LZO_DictionarySize | ||
); | ||
} | ||
else | ||
{ | ||
r = lzo1x_decompress((const lzo_byte*)src, (lzo_uint)src_len, | ||
(lzo_byte*)dst, (lzo_uintp)&out_size, | ||
NULL | ||
); | ||
} | ||
|
||
VERIFY(r == LZO_E_OK); | ||
|
||
return out_size; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.