]> gitweb.factorcode.org Git - factor.git/blob - extra/compression/bzip3/ffi/ffi.factor
bzip3.ffi: remove unnecessary words
[factor.git] / extra / compression / bzip3 / ffi / ffi.factor
1 ! Copyright (C) 2022 Raghu Ranganathan.
2 ! See http://factorcode.org/license.txt for BSD license.
3
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
9 << "bzip3" {
10   { [ os windows? ] [ "bzip3.dll" ] }
11   { [ os macosx? ] [ "libbzip3.dylib" ] }
12   { [ os unix? ] [ "libbzip3.so" ] }
13 } cond cdecl add-library >>
14
15 LIBRARY: bzip3
16
17 ! typedef struct {
18 !     /* Input/output. */
19 !     u8 *in_queue, *out_queue;
20 !     s32 input_ptr, output_ptr, input_max;
21
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];
26 ! } state;
27 STRUCT: state
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] }
31 ;
32
33 ! struct bz3_state {
34 !     u8 * swap_buffer;
35 !     s32 block_size;
36 !     s32 *sais_array, *lzp_lut;
37 !     state * cm_state;
38 !     s8 last_error;
39 ! };
40 STRUCT: bz3_state 
41   { swap_buffer u8* }
42   { block_size s32 }
43   { sais_array s32* } { lzp_lut s32* }
44   { cm_state state* }
45   { last_error s8 }
46 ;
47
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 )
54
55 ! HIGH LEVEL APIs
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 )
58
59 ! LOW LEVEL APIs
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 )
64