1 ! Copyright (C) 2022 Raghu Ranganathan.
2 ! See http://factorcode.org/license.txt for BSD license.
4 ! Makes use of Kamila Szewczyk's bzip3 library.
5 ! See https://github.com/kspalaiologos/bzip3/blob/master/include/libbz3.h for the API specifics.
6 USING: alien alien.libraries alien.c-types alien.syntax
7 classes.struct combinators system words ;
8 IN: compression.bzip3.ffi
10 { [ os windows? ] [ "bzip3.dll" ] }
11 { [ os macosx? ] [ "libbzip3.dylib" ] }
12 { [ os unix? ] [ "libbzip3.so" ] }
13 } cond cdecl add-library >>
19 ! u8 *in_queue, *out_queue;
20 ! s32 input_ptr, output_ptr, input_max;
22 ! /* C0, C1 - used for making the initial prediction, C2 used for an APM with a slightly low
23 ! learning rate (6) and 512 contexts. kanzi merges C0 and C1, uses slightly different
24 ! counter initialisation code and prediction code which from my tests tends to be suboptimal. */
25 ! u16 C0[256], C1[256][256], C2[512][17];
28 { in_queue u8* } { out_queue u8* }
29 { input_ptr s32 } { output_ptr s32 } { input_max s32 }
30 { C0 u16[256] } { C1 u16[256][256] } { C2 u16[512][17] }
36 ! s32 *sais_array, *lzp_lut;
43 { sais_array s32* } { lzp_lut s32* }
48 FUNCTION: c-string bz3_version ( )
49 FUNCTION: int8_t bz3_last_error ( bz3_state* state )
50 FUNCTION: c-string bz3_strerror ( bz3_state* state )
51 FUNCTION: bz3_state* bz3_new ( int32_t block_size )
52 FUNCTION: void bz3_free ( bz3_state* state )
53 FUNCTION: size_t bz3_bound ( size_t input_size )
56 FUNCTION: int bz3_compress ( uint32_t block_size, uint8_t* in, uint8_t* out, size_t in_size, size_t* out_size )
57 FUNCTION: int bz3_decompress ( uint8_t* in, uint8_t* out, size_t in_size, size_t* out_size )
60 FUNCTION: int32_t bz3_encode_block ( bz3_state* state, uint8_t* buffer, int32_t size )
61 FUNCTION: int32_t bz3_decode_block ( bz3_state* state, uint8_t* buffer, int32_t size, int32_t orig_size )
62 FUNCTION: void bz3_encode_blocks ( bz3_state* states[], uint8_t* buffers[], int32_t sizes[], int32_t n )
63 FUNCTION: void bz3_decode_blocks ( bz3_state* states[], uint8_t* buffers[], int32_t sizes[], int32_t orig_sizes[], int32_t n )