mqc.h
Go to the documentation of this file.
/*
* Copyright (C) 2016-2023 Grok Image Compression Inc.
*
* This source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* This source code incorporates work covered by the BSD 2-clause license.
* Please see the LICENSE file in the root directory for details.
*
*/
#pragma once
#include <t1_common.h>
namespace grk
{
struct mqc_state;
struct mqcoder;
struct mqc_state
{
uint32_t qeval;
uint32_t mps;
const mqc_state* nmps;
const mqc_state* nlps;
};
#define MQC_NUMCTXS 19
struct mqcoder
{
uint32_t c;
uint32_t a;
uint32_t ct;
/* only used by decoder, to count the number of times a terminating 0xFF >0x8F marker is read */
uint32_t end_of_byte_stream_counter;
uint8_t* bp;
uint8_t* start;
uint8_t* end;
const mqc_state* ctxs[MQC_NUMCTXS];
const mqc_state** curctx;
/* lut_ctxno_zc shifted by (1 << 9) * bandIndex */
const uint8_t* lut_ctxno_zc_orient;
uint8_t backup[grk_cblk_dec_compressed_data_pad_right];
};
const uint32_t A_MIN = 0x8000;
#include "mqc_inl.h"
#include "mqc_dec_inl.h"
#include "mqc_enc_inl.h"
uint32_t mqc_numbytes_enc(mqcoder* mqc);
void mqc_resetstates(mqcoder* mqc);
/* ENCODE */
void mqc_init_enc(mqcoder* mqc, uint8_t* bp);
void mqc_encode(mqcoder* mqc, uint32_t d);
void mqc_flush_enc(mqcoder* mqc);
void mqc_bypass_init_enc(mqcoder* mqc);
uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder* mqc, bool erterm);
void mqc_bypass_enc(mqcoder* mqc, uint32_t d);
void mqc_bypass_flush_enc(mqcoder* mqc, bool erterm);
void mqc_restart_init_enc(mqcoder* mqc);
void mqc_erterm_enc(mqcoder* mqc);
void mqc_segmark_enc(mqcoder* mqc);
/* DECODE */
void mqc_init_dec(mqcoder* mqc, uint8_t* bp, uint32_t len);
void mqc_raw_init_dec(mqcoder* mqc, uint8_t* bp, uint32_t len);
void mqc_finish_dec(mqcoder* mqc);
} // namespace grk
MQC_NUMCTXS
#define MQC_NUMCTXS
Definition mqc.h:42
mqc_dec_inl.h
mqc_enc_inl.h
mqc_inl.h
grk
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
grk::mqc_flush_enc
void mqc_flush_enc(mqcoder *mqc)
Definition mqc_enc.cpp:213
grk::grk_read
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
grk::mqc_numbytes_enc
uint32_t mqc_numbytes_enc(mqcoder *mqc)
Definition mqc_enc.cpp:177
grk::mqc_segmark_enc
void mqc_segmark_enc(mqcoder *mqc)
Definition mqc_enc.cpp:327
grk::mqc_raw_init_dec
void mqc_raw_init_dec(mqcoder *mqc, uint8_t *bp, uint32_t len)
Initialize the decoder for RAW decoding.
Definition mqc_dec.cpp:107
grk::mqc_bypass_flush_enc
void mqc_bypass_flush_enc(mqcoder *mqc, bool erterm)
Definition mqc_enc.cpp:252
grk::A_MIN
const uint32_t A_MIN
Definition mqc.h:69
grk::mqc_erterm_enc
void mqc_erterm_enc(mqcoder *mqc)
Definition mqc_enc.cpp:312
grk::mqc_bypass_enc
void mqc_bypass_enc(mqcoder *mqc, uint32_t d)
grk::mqc_finish_dec
void mqc_finish_dec(mqcoder *mqc)
Terminate RAW/MQC decoding.
Definition mqc_dec.cpp:114
grk::mqc_restart_init_enc
void mqc_restart_init_enc(mqcoder *mqc)
Definition mqc_enc.cpp:294
grk::mqc_bypass_init_enc
void mqc_bypass_init_enc(mqcoder *mqc)
Definition mqc_enc.cpp:229
grk::mqc_encode
void mqc_encode(mqcoder *mqc, uint32_t d)
Definition mqc_enc.cpp:205
grk::mqc_init_enc
void mqc_init_enc(mqcoder *mqc, uint8_t *bp)
Definition mqc_enc.cpp:182
grk::mqc_bypass_get_extra_bytes_enc
uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder *mqc, bool erterm)
Definition mqc_enc.cpp:247
grk::mqc_init_dec
void mqc_init_dec(mqcoder *mqc, uint8_t *bp, uint32_t len)
Initialize the decoder for MQ decoding.
Definition mqc_dec.cpp:91
grk::mqc_resetstates
void mqc_resetstates(mqcoder *mqc)
Definition mqc_dec.cpp:120
grk::mqc_state
Definition mqc.h:31
grk::mqc_state::nmps
const mqc_state * nmps
next state if the next encoded symbol is the MPS
Definition mqc.h:37
grk::mqc_state::nlps
const mqc_state * nlps
next state if the next encoded symbol is the LPS
Definition mqc.h:39
grk::mqc_state::mps
uint32_t mps
the Most Probable Symbol (0 or 1)
Definition mqc.h:35
grk::mqc_state::qeval
uint32_t qeval
the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff)
Definition mqc.h:33
grk::mqcoder
Definition mqc.h:44
grk::mqcoder::end_of_byte_stream_counter
uint32_t end_of_byte_stream_counter
Definition mqc.h:52
grk::mqcoder::end
uint8_t * end
pointer to the end of the buffer
Definition mqc.h:58
grk::mqcoder::ctxs
const mqc_state * ctxs[MQC_NUMCTXS]
Array of contexts.
Definition mqc.h:60
grk::mqcoder::a
uint32_t a
only used by MQ decoder
Definition mqc.h:48
grk::mqcoder::start
uint8_t * start
pointer to the start of the buffer
Definition mqc.h:56
grk::mqcoder::lut_ctxno_zc_orient
const uint8_t * lut_ctxno_zc_orient
Definition mqc.h:64
grk::mqcoder::curctx
const mqc_state ** curctx
Active context.
Definition mqc.h:62
grk::mqcoder::bp
uint8_t * bp
pointer to the current position in the buffer
Definition mqc.h:54
grk::mqcoder::backup
uint8_t backup[grk_cblk_dec_compressed_data_pad_right]
Original value of the 2 bytes at end[0] and end[1].
Definition mqc.h:66
grk::mqcoder::ct
uint32_t ct
number of bits already read or free to write
Definition mqc.h:50
grk::mqcoder::c
uint32_t c
temporary buffer where bits are coded or decoded
Definition mqc.h:46
t1_common.h
grk_cblk_dec_compressed_data_pad_right
const uint8_t grk_cblk_dec_compressed_data_pad_right
< Space for a fake FFFF marker
Definition t1_common.h:37