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 
19 inline 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 
37 inline 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
BITS_SECTION_FOOT
@ BITS_SECTION_FOOT
Number of bits to write for sect. foot markers.
Definition: slim_file.cpp:41
slim_expander_t
long_opt
static const struct option long_opt[]
The long options slim recognizes.
Definition: slim_control.cpp:41
encoder_reduced_binary
short_opt
const char short_opt[]
Single-character options.
Definition: slim_control.cpp:38
slim_compressor_t
decoder_constant
decoder_runlength
main
int main(int argc, char *argv[])
Main program.
Definition: slim_dump.cpp:61
log2
double log2(double x)
Log-base2 of the argument.
Definition: slim_codec_reduced_binary.cpp:168
ibitstream::read_unary
Word_t read_unary()
Read a single unary-coded value.
Definition: bitstream.cpp:622
encoder_constant
ibitstream::readbits
Word_t readbits(int nbits)
Read data from the buffer as unsigned ints.
Definition: bitstream.cpp:556
slim_channel_decode
decoder_reduced_binary
ibitstream
Definition: bitstream.h:105
section_foot_markers_t
section_foot_markers_t
Markers at the end of sections to tell whether more follow.
Definition: slim_file.cpp:38
encoder_runlength
alter_mtime
int alter_mtime(const char *filename, time_t mtime)
Alter the access and modification time on a closed file.
Definition: slim_file.cpp:68
dump_one_file
void dump_one_file(const char *path)
Dump the info from a single file.
Definition: slim_dump.cpp:28
slim_channel
obitstream::writebits
void writebits(uint32_t data, int nbits)
Write data to the buffer.
Definition: bitstream.cpp:237
slim_single_codec.h
decoder_generator
decoder * decoder_generator(code_t code, data_t data_type, bool deltas)
Generating function for various decoders.
Definition: slim_codec_factory.cpp:105
bit_size
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
obitstream::write_unary
void write_unary(unsigned int value)
Write a unary code for the value.
Definition: bitstream.cpp:303
obitstream
Definition: bitstream.h:78
mexp_golomb_read_u32
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
encoder
bitstream.h
encoder_generator
encoder * encoder_generator(enum code_t code, enum data_t data_type, bool deltas)
Generating function for various encoders.
Definition: slim_codec_factory.cpp:34
raw_section
NOT_LAST_SECTION
@ NOT_LAST_SECTION
Marker for all non-final sections in file.
Definition: slim_file.cpp:39
slim_channel_encode
verify_twos_complement
static void verify_twos_complement()
Fail an assertion if this is NOT a TWOS-COMPLEMENT machine.
Definition: slim_file.cpp:50
LAST_SECTION
@ LAST_SECTION
Marker for the last section in a file.
Definition: slim_file.cpp:40
decoder
RAW_SUFFIX
#define RAW_SUFFIX
Suffix for all raw files when preserving original.
Definition: slim_control.cpp:34
mexp_golomb_write
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