ht_block_encoding.hpp
Go to the documentation of this file.
// Copyright (c) 2019 - 2021, Osamu Watanabe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <cstdint>
#define MAX_Lcup 16834
#define MAX_Scup 4079
/********************************************************************************
* state_MS_enc: state class for MagSgn encoding
*******************************************************************************/
class state_MS_enc {
private:
int32_t pos; // current position in the buffer
uint8_t *const buf; // buffer for MagSgn
#ifdef MSNAIVE
uint8_t bits;
uint8_t max;
uint8_t tmp;
#else
uint64_t Creg; // temporal buffer to store up to 4 codewords
uint32_t ctreg; // number of used bits in Creg
uint8_t last; // last byte in the buffer
void emit_dword(); // internal function to emit 4 code words
#endif
public:
explicit state_MS_enc(uint8_t *p)
: pos(0),
buf(p),
#ifdef MSNAIVE
bits(0),
max(8),
tmp(0)
#else
Creg(0),
ctreg(0),
last(0)
#endif
{
}
#ifdef MSNAIVE
void emitMagSgnBits(uint32_t cwd, uint8_t m_n);
#else
void emitMagSgnBits(uint32_t cwd, uint8_t m_n, uint8_t emb_1);
#endif
int32_t termMS();
};
class state_MEL_enc; // forward declaration for friend function "termMELandVLC()"
/********************************************************************************
* state_VLC_enc: state classe for VLC encoding
*******************************************************************************/
class state_VLC_enc {
private:
int32_t pos;
uint8_t bits;
uint8_t tmp;
uint8_t last;
uint8_t *const buf;
friend int32_t termMELandVLC(state_VLC_enc &, state_MEL_enc &);
public:
explicit state_VLC_enc(uint8_t *p) : pos(MAX_Scup - 2), bits(4), tmp(0xF), last(0xFF), buf(p) {
buf[pos + 1] = 0xFF;
}
void emitVLCBits(uint16_t cwd, uint8_t len);
};
/********************************************************************************
* state_MEL_enc: state class for MEL encoding
*******************************************************************************/
class state_MEL_enc {
private:
int8_t MEL_k;
uint8_t MEL_run;
const uint8_t MEL_E[13];
uint8_t MEL_t;
int32_t pos;
uint8_t rem;
uint8_t tmp;
uint8_t *const buf;
void emitMELbit(uint8_t bit);
friend int32_t termMELandVLC(state_VLC_enc &, state_MEL_enc &);
public:
explicit state_MEL_enc(uint8_t *p)
: MEL_k(0),
MEL_run(0),
MEL_E{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5},
MEL_t(1 << MEL_E[MEL_k]),
pos(0),
rem(8),
tmp(0),
buf(p) {}
void encodeMEL(uint8_t smel);
void termMEL();
};
state_MEL_enc
Definition ht_block_encoding.hpp:100
state_MEL_enc::MEL_k
int8_t MEL_k
Definition ht_block_encoding.hpp:102
state_MEL_enc::MEL_E
const uint8_t MEL_E[13]
Definition ht_block_encoding.hpp:104
state_MEL_enc::buf
uint8_t *const buf
Definition ht_block_encoding.hpp:109
state_MEL_enc::pos
int32_t pos
Definition ht_block_encoding.hpp:106
state_MEL_enc::MEL_run
uint8_t MEL_run
Definition ht_block_encoding.hpp:103
state_MEL_enc::MEL_t
uint8_t MEL_t
Definition ht_block_encoding.hpp:105
state_MEL_enc::termMELandVLC
friend int32_t termMELandVLC(state_VLC_enc &, state_MEL_enc &)
Definition ht_block_encoding.cpp:394
state_MEL_enc::encodeMEL
void encodeMEL(uint8_t smel)
Definition ht_block_encoding.cpp:238
state_MEL_enc::rem
uint8_t rem
Definition ht_block_encoding.hpp:107
state_MEL_enc::state_MEL_enc
state_MEL_enc(uint8_t *p)
Definition ht_block_encoding.hpp:115
state_MEL_enc::termMEL
void termMEL()
Definition ht_block_encoding.cpp:268
state_MEL_enc::emitMELbit
void emitMELbit(uint8_t bit)
Definition ht_block_encoding.cpp:227
state_MEL_enc::tmp
uint8_t tmp
Definition ht_block_encoding.hpp:108
state_MS_enc
Definition ht_block_encoding.hpp:38
state_MS_enc::Creg
uint64_t Creg
Definition ht_block_encoding.hpp:47
state_MS_enc::state_MS_enc
state_MS_enc(uint8_t *p)
Definition ht_block_encoding.hpp:54
state_MS_enc::termMS
int32_t termMS()
Definition ht_block_encoding.cpp:176
state_MS_enc::emitMagSgnBits
void emitMagSgnBits(uint32_t cwd, uint8_t m_n, uint8_t emb_1)
Definition ht_block_encoding.cpp:151
state_MS_enc::buf
uint8_t *const buf
Definition ht_block_encoding.hpp:41
state_MS_enc::emit_dword
void emit_dword()
Definition ht_block_encoding.cpp:160
state_MS_enc::last
uint8_t last
Definition ht_block_encoding.hpp:49
state_MS_enc::ctreg
uint32_t ctreg
Definition ht_block_encoding.hpp:48
state_MS_enc::pos
int32_t pos
Definition ht_block_encoding.hpp:40
state_VLC_enc
Definition ht_block_encoding.hpp:80
state_VLC_enc::pos
int32_t pos
Definition ht_block_encoding.hpp:82
state_VLC_enc::last
uint8_t last
Definition ht_block_encoding.hpp:85
state_VLC_enc::tmp
uint8_t tmp
Definition ht_block_encoding.hpp:84
state_VLC_enc::termMELandVLC
friend int32_t termMELandVLC(state_VLC_enc &, state_MEL_enc &)
Definition ht_block_encoding.cpp:394
state_VLC_enc::state_VLC_enc
state_VLC_enc(uint8_t *p)
Definition ht_block_encoding.hpp:91
state_VLC_enc::bits
uint8_t bits
Definition ht_block_encoding.hpp:83
state_VLC_enc::buf
uint8_t *const buf
Definition ht_block_encoding.hpp:86
state_VLC_enc::emitVLCBits
void emitVLCBits(uint16_t cwd, uint8_t len)
Definition ht_block_encoding.cpp:277
MAX_Scup
#define MAX_Scup
Definition ht_block_encoding.hpp:33