Slim numerical data compression 1.0
slim_single_codec.h
Go to the documentation of this file.
1// -*- mode: c++; -*-
2
7
8#ifndef SLIM_SINGLE_CODEC_H
9#define SLIM_SINGLE_CODEC_H
10
11#include "bitstream.h"
12
13
14
19inline void mexp_golomb_write(obitstream *ob, uint32_t u,
20 unsigned int order=1) {
21 unsigned int n = bit_size(u);
22 if (n > order) {
23 ob->write_unary(n-order);
24 ob->writebits(u, n-1);
25 } else {
26 ob->write_unary(0);
27 ob->writebits(u, order);
28 }
29}
30
31
32
37inline uint32_t mexp_golomb_read_u32(ibitstream *ib,
38 unsigned int order=1) {
39
40 uint32_t n_minus_order = ib->read_unary();
41 if (n_minus_order > 0) {
42 int n_minus_1 = n_minus_order + order - 1;
43
44 uint32_t uval = ib->readbits(n_minus_1);
45 return uval | bitNset[n_minus_1];
46 } else {
47 return ib->readbits(order);
48 }
49}
50
51
52
53
54
55#endif // #ifndef SLIM_SINGLE_CODEC_H
Include file for the bitstream and derived classes.
static unsigned int bit_size(int32_t i)
Find size (on [0,32]) of the smallest # that can hold the integer i.
Definition bitstream.h:166
Input bit stream.
Definition bitstream.h:105
Word_t readbits(int nbits)
Read data from the buffer as unsigned ints.
Definition bitstream.cpp:556
Word_t read_unary()
Read a single unary-coded value.
Definition bitstream.cpp:622
Output bit stream.
Definition bitstream.h:78
void write_unary(unsigned int value)
Write a unary code for the value.
Definition bitstream.cpp:303
void writebits(uint32_t data, int nbits)
Write data to the buffer.
Definition bitstream.cpp:237
void mexp_golomb_write(obitstream *ob, uint32_t u, unsigned int order=1)
Write an unsigned value to a bitstream by method mexp_golomb.
Definition slim_single_codec.h:19
uint32_t mexp_golomb_read_u32(ibitstream *ib, unsigned int order=1)
Read an unsigned 32-bit value from a bitstream by method mexp_golomb.
Definition slim_single_codec.h:37