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 >>
28 ! u8 *in_queue, *out_queue;
29 ! s32 input_ptr, output_ptr, input_max;
31 ! /* C0, C1 - used for making the initial prediction, C2 used for an APM with a slightly low
32 ! learning rate (6) and 512 contexts. kanzi merges C0 and C1, uses slightly different
33 ! counter initialisation code and prediction code which from my tests tends to be suboptimal. */
34 ! u16 C0[256], C1[256][256], C2[512][17];
37 { in_queue u8* } { out_queue u8* }
38 { input_ptr s32 } { output_ptr s32 } { input_max s32 }
39 { C0 u16[256] } { C1 u16[256][256] } { C2 u16[512][17] }
45 ! s32 *sais_array, *lzp_lut;
52 { sais_array s32* } { lzp_lut s32* }
57 FUNCTION: c-string bz3_version ( )
58 FUNCTION: int8_t bz3_last_error ( bz3_state* state )
59 FUNCTION: c-string bz3_strerror ( bz3_state* state )
60 FUNCTION: bz3_state* bz3_new ( int32_t block_size )
61 FUNCTION: void bz3_free ( bz3_state* state )
62 FUNCTION: size_t bz3_bound ( size_t input_size )
65 FUNCTION: int bz3_compress ( uint32_t block_size, uint8_t* in, uint8_t* out, size_t in_size, size_t* out_size )
66 FUNCTION: int bz3_decompress ( uint8_t* in, uint8_t* out, size_t in_size, size_t* out_size )
69 FUNCTION: int32_t bz3_encode_block ( bz3_state* state, uint8_t* buffer, int32_t size )
70 FUNCTION: int32_t bz3_decode_block ( bz3_state* state, uint8_t* buffer, int32_t size, int32_t orig_size )
71 FUNCTION: void bz3_encode_blocks ( bz3_state* states[], uint8_t* buffers[], int32_t sizes[], int32_t n )
72 FUNCTION: void bz3_decode_blocks ( bz3_state* states[], uint8_t* buffers[], int32_t sizes[], int32_t orig_sizes[], int32_t n )