Implement a compressor that produces bitstreams compatible with the existing Bobrowski decompressor. The engine uses LZ77 sliding-window match finding with hash chains, Huffman entropy coding, and delta-coded tree serialization matching the original UC2 format exactly. New files: - lib/src/compress.c: LZ77+Huffman compressor (~950 lines) - lib/src/uc2_internal.h: shared constants, types, checksums - lib/src/uc2_tables.c: vval/ivval delta tables, default Huffman tree - tests/src/test_roundtrip.c: compress→archive→decompress→verify tests Key details: - 4 compression levels (Fast/Normal/Tight/Ultra) with tunable search - Lazy evaluation for better match selection at higher levels - Delta-coded Huffman tree serialization with RLE - Fletcher/XOR checksum computation - Round-trip test covers 8 patterns × 4 levels (32 test cases) Fixed 28 errors in the hand-computed ivval inverse delta table (rows 9-13) that caused the decompressor to reconstruct wrong Huffman trees from compressor output.
40 lines
1.3 KiB
CMake
40 lines
1.3 KiB
CMake
# libuc2 — UC2 decompression library
|
|
|
|
set(LIBUC2_SOURCES src/decompress.c src/compress.c src/uc2_tables.c)
|
|
|
|
# Embed super.bin: use .S with .incbin on GCC/Clang, generated C array on MSVC
|
|
if(MSVC)
|
|
set(SUPER_C "${CMAKE_CURRENT_BINARY_DIR}/super_data.c")
|
|
add_custom_command(
|
|
OUTPUT "${SUPER_C}"
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
-DINPUT="${CMAKE_CURRENT_SOURCE_DIR}/src/super.bin"
|
|
-DOUTPUT="${SUPER_C}"
|
|
-P "${PROJECT_SOURCE_DIR}/cmake/bin2c.cmake"
|
|
DEPENDS src/super.bin "${PROJECT_SOURCE_DIR}/cmake/bin2c.cmake"
|
|
COMMENT "Generating super_data.c from super.bin"
|
|
)
|
|
list(APPEND LIBUC2_SOURCES "${SUPER_C}")
|
|
else()
|
|
set(SUPER_BIN_ABS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/super.bin")
|
|
configure_file(src/super_data.S.in "${CMAKE_CURRENT_BINARY_DIR}/super_data.S" @ONLY)
|
|
list(APPEND LIBUC2_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/super_data.S")
|
|
endif()
|
|
|
|
add_library(uc2 STATIC ${LIBUC2_SOURCES})
|
|
|
|
target_include_directories(uc2
|
|
PUBLIC include
|
|
PRIVATE src
|
|
"${PROJECT_BINARY_DIR}/lib" # for configured uc2_version.h
|
|
)
|
|
|
|
target_compile_features(uc2 PUBLIC c_std_99)
|
|
target_compile_definitions(uc2 PRIVATE NDEBUG)
|
|
|
|
configure_file(
|
|
include/uc2/uc2_version.h.in
|
|
"${PROJECT_BINARY_DIR}/lib/uc2/uc2_version.h"
|
|
@ONLY
|
|
)
|