-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitpacking.h
139 lines (129 loc) · 6.98 KB
/
bitpacking.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
** intoPIX SA & Fraunhofer IIS (hereinafter the "Software Copyright **
** Holder") hold or have the right to license copyright with respect to **
** the accompanying software (hereinafter the "Software"). **
** **
** Copyright License for Evaluation and Testing **
** -------------------------------------------- **
** **
** The Software Copyright Holder hereby grants, to any implementer of **
** this ISO Standard, an irrevocable, non-exclusive, worldwide, **
** royalty-free, sub-licensable copyright licence to prepare derivative **
** works of (including translations, adaptations, alterations), the **
** Software and reproduce, display, distribute and execute the Software **
** and derivative works thereof, for the following limited purposes: (i) **
** to evaluate the Software and any derivative works thereof for **
** inclusion in its implementation of this ISO Standard, and (ii) **
** to determine whether its implementation conforms with this ISO **
** Standard. **
** **
** The Software Copyright Holder represents and warrants that, to the **
** best of its knowledge, it has the necessary copyright rights to **
** license the Software pursuant to the terms and conditions set forth in **
** this option. **
** **
** No patent licence is granted, nor is a patent licensing commitment **
** made, by implication, estoppel or otherwise. **
** **
** Disclaimer: Other than as expressly provided herein, (1) the Software **
** is provided “AS IS” WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING **
** BUT NOT LIMITED TO, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A **
** PARTICULAR PURPOSE AND NON-INFRINGMENT OF INTELLECTUAL PROPERTY RIGHTS **
** and (2) neither the Software Copyright Holder (or its affiliates) nor **
** the ISO shall be held liable in any event for any damages whatsoever **
** (including, without limitation, damages for loss of profits, business **
** interruption, loss of information, or any other pecuniary loss) **
** arising out of or related to the use of or inability to use the **
** Software.” **
** **
** RAND Copyright Licensing Commitment **
** ----------------------------------- **
** **
** IN THE EVENT YOU WISH TO INCLUDE THE SOFTWARE IN A CONFORMING **
** IMPLEMENTATION OF THIS ISO STANDARD, PLEASE BE FURTHER ADVISED THAT: **
** **
** The Software Copyright Holder agrees to grant a copyright **
** license on reasonable and non- discriminatory terms and conditions for **
** the purpose of including the Software in a conforming implementation **
** of the ISO Standard. Negotiations with regard to the license are **
** left to the parties concerned and are performed outside the ISO. **
** **
** No patent licence is granted, nor is a patent licensing commitment **
** made, by implication, estoppel or otherwise. **
***************************************************************************/
#ifndef BITPACKING_H
#define BITPACKING_H
#include <stdbool.h>
#include <stdint.h>
#include "libjxs.h"
typedef enum unary_alphabet_e
{
UNARY_ALPHABET_0 = 0,
UNARY_ALPHABET_4_CLIPPED = 1,
UNARY_ALPHABET_FULL = 2,
UNARY_ALPHABET_NB
} unary_alphabet_t;
#define FIRST_ALPHABET UNARY_ALPHABET_0
#define MAX_UNARY 15
#define MAX_UNARY_CLIPPED 13
typedef struct bit_packer_t
{
uint64_t *ptr;
uint64_t *ptr_cur;
uint64_t *ptr_max;
int bit_offset;
size_t max_size;
int flushed;
} bit_packer_t;
typedef struct bit_unpacker_t
{
uint64_t *ptr;
uint64_t *ptr_cur;
uint64_t cur;
int bit_offset;
size_t max_size;
uint64_t consumed;
} bit_unpacker_t;
#ifdef __cplusplus
extern "C"
{
#endif
bit_packer_t *bitpacker_init();
int bitpacker_set_buffer(bit_packer_t *packer, void *ptr, size_t max_size);
uint64_t *bitpacker_get_buffer(bit_packer_t *packer);
int bitpacker_write(bit_packer_t *packer, uint64_t val, unsigned int nbits);
int bitpacker_write_unary_signed(bit_packer_t *packer, int8_t val, unary_alphabet_t alphabet);
int bitpacker_write_unary_unsigned(bit_packer_t *packer, int8_t val);
int bounded_code_get_min_max(int predictor, int gtli, int *min_allowed, int *max_allowed);
int bounded_code_get_unary_code(int8_t delta_val, int8_t min_allowed, int8_t max_allowed);
int bitunpacker_read_bounded_code(bit_unpacker_t *unpacker,
int8_t min_allowed,
int8_t max_allowed,
int8_t *val);
int bitpacker_align(bit_packer_t *packer, int nbits);
int bitpacker_get_len(bit_packer_t *packer);
int bitpacker_add_padding(bit_packer_t *packer, int nbits);
int bitpacker_flush(bit_packer_t *packer);
int bitpacker_reset(bit_packer_t *packer);
int bitpacker_append(bit_packer_t *packer, void *ptr_from, int nbits);
int bitpacker_from_unpacker(bit_packer_t *packer, bit_unpacker_t *unpacker, int nbits);
void bitpacker_close(bit_packer_t *packer);
void bitunpacker_set_info(bit_unpacker_t *unpacker, bitstream_info_t *bitstream_info);
bit_unpacker_t *bitunpacker_init();
int bitunpacker_set_buffer(bit_unpacker_t *unpacker, void *ptr, size_t max_size);
int bitunpacker_read(bit_unpacker_t *unpacker, uint64_t *val, int nbits);
int bitunpacker_peek(bit_unpacker_t *unpacker, uint64_t *val, int nbits);
int bitunpacker_read_unary_signed(bit_unpacker_t *unpacker, int8_t *val, unary_alphabet_t alphabet);
int bitunpacker_read_unary_unsigned(bit_unpacker_t *unpacker, int8_t *val);
int bitunpacker_align(bit_unpacker_t *unpacker, int nbits);
int bitunpacker_reset(bit_unpacker_t *unpacker);
int bitunpacker_close(bit_unpacker_t *unpacker);
size_t bitunpacker_consumed(bit_unpacker_t *unpacker);
bool bitunpacker_consumed_all(bit_unpacker_t *unpacker);
size_t bitunpacker_consumed_bits(bit_unpacker_t *unpacker);
int bitunpacker_skip(bit_unpacker_t *packer, int nbits);
int bitunpacker_rewind(bit_unpacker_t *unpacker, int nbits);
#ifdef __cplusplus
}
#endif
#endif