Grok  7.6.3
mqc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2021 Grok Image Compression Inc.
3  *
4  * This source code is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License, version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This source code is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  *
17  * This source code incorporates work covered by the BSD 2-clause license.
18  * Please see the LICENSE file in the root directory for details.
19  *
20  */
21 
22 #pragma once
23 
24 #include <t1_common.h>
25 namespace grk {
26 
27 struct mqc_state;
28 struct mqcoder;
29 
30 struct mqc_state {
32  uint32_t qeval;
34  uint32_t mps;
36  const mqc_state *nmps;
38  const mqc_state *nlps;
39 } ;
40 
41 #define MQC_NUMCTXS 19
42 struct mqcoder {
44  uint32_t c;
46  uint32_t a;
48  uint32_t ct;
49  /* only used by decoder, to count the number of times a terminating 0xFF >0x8F marker is read */
52  uint8_t *bp;
54  uint8_t *start;
56  uint8_t *end;
60  const mqc_state **curctx;
61  /* lut_ctxno_zc shifted by (1 << 9) * bandIndex */
62  const uint8_t* lut_ctxno_zc_orient;
65 } ;
66 
67 const uint32_t A_MIN = 0x8000;
68 
69 #include "mqc_inl.h"
70 #include "mqc_dec_inl.h"
71 #include "mqc_enc_inl.h"
72 
73 uint32_t mqc_numbytes_enc(mqcoder *mqc);
74 void mqc_resetstates(mqcoder *mqc);
75 
76 /* ENCODE */
77 
78 void mqc_init_enc(mqcoder *mqc, uint8_t *bp);
79 void mqc_encode(mqcoder *mqc, uint32_t d);
80 void mqc_flush_enc(mqcoder *mqc);
81 void mqc_bypass_init_enc(mqcoder *mqc);
82 uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder *mqc, bool erterm);
83 void mqc_bypass_enc(mqcoder *mqc, uint32_t d);
84 void mqc_bypass_flush_enc(mqcoder *mqc, bool erterm);
85 void mqc_restart_init_enc(mqcoder *mqc);
86 void mqc_erterm_enc(mqcoder *mqc);
87 void mqc_segmark_enc(mqcoder *mqc);
88 
89 /* DECODE */
90 
106 void mqc_init_dec(mqcoder *mqc, uint8_t *bp, uint32_t len);
107 
123 void mqc_raw_init_dec(mqcoder *mqc, uint8_t *bp, uint32_t len);
124 
125 
134 void mqc_finish_dec(mqcoder *mqc);
135 
136 }
grk::mqc_bypass_get_extra_bytes_enc
uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder *mqc, bool erterm)
Definition: mqc_enc.cpp:273
mqc_inl.h
grk::mqcoder::ctxs
const mqc_state * ctxs[MQC_NUMCTXS]
Array of contexts.
Definition: mqc.h:58
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:140
grk::mqc_erterm_enc
void mqc_erterm_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:331
grk::mqcoder::end
uint8_t * end
pointer to the end of the buffer
Definition: mqc.h:56
t1_common.h
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:156
grk::mqcoder::start
uint8_t * start
pointer to the start of the buffer
Definition: mqc.h:54
grk::mqc_init_enc
void mqc_init_enc(mqcoder *mqc, uint8_t *bp)
Definition: mqc_enc.cpp:210
grk::mqc_resetstates
void mqc_resetstates(mqcoder *mqc)
Definition: mqc_dec.cpp:167
grk::A_MIN
const uint32_t A_MIN
Definition: mqc.h:67
grk::mqc_state::nmps
const mqc_state * nmps
next state if the next encoded symbol is the MPS
Definition: mqc.h:36
mqc_enc_inl.h
grk::mqcoder::bp
uint8_t * bp
pointer to the current position in the buffer
Definition: mqc.h:52
mqc_dec_inl.h
grk::mqcoder::ct
uint32_t ct
number of bits already read or free to write
Definition: mqc.h:48
grk::mqc_restart_init_enc
void mqc_restart_init_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:314
grk::mqcoder::curctx
const mqc_state ** curctx
Active context.
Definition: mqc.h:60
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
grk
Copyright (C) 2016-2021 Grok Image Compression Inc.
Definition: BitIO.cpp:23
grk::mqcoder::c
uint32_t c
temporary buffer where bits are coded or decoded
Definition: mqc.h:44
grk::mqc_state::qeval
uint32_t qeval
the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff)
Definition: mqc.h:32
grk::mqc_state
Definition: mqc.h:30
grk::mqc_segmark_enc
void mqc_segmark_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:344
grk::mqc_state::nlps
const mqc_state * nlps
next state if the next encoded symbol is the LPS
Definition: mqc.h:38
grk::mqc_encode
void mqc_encode(mqcoder *mqc, uint32_t d)
Definition: mqc_enc.cpp:232
grk::mqc_finish_dec
void mqc_finish_dec(mqcoder *mqc)
Terminate RAW/MQC decoding.
Definition: mqc_dec.cpp:162
grk::mqcoder::lut_ctxno_zc_orient
const uint8_t * lut_ctxno_zc_orient
Definition: mqc.h:62
grk::mqc_state::mps
uint32_t mps
the Most Probable Symbol (0 or 1)
Definition: mqc.h:34
grk::mqc_numbytes_enc
uint32_t mqc_numbytes_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:206
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:64
grk::mqcoder::end_of_byte_stream_counter
uint32_t end_of_byte_stream_counter
Definition: mqc.h:50
grk::mqcoder::a
uint32_t a
only used by MQ decoder
Definition: mqc.h:46
grk::mqc_bypass_flush_enc
void mqc_bypass_flush_enc(mqcoder *mqc, bool erterm)
Definition: mqc_enc.cpp:278
grk::mqcoder
Definition: mqc.h:42
grk::mqc_flush_enc
void mqc_flush_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:239
grk::mqc_bypass_enc
void mqc_bypass_enc(mqcoder *mqc, uint32_t d)
grk::mqc_bypass_init_enc
void mqc_bypass_init_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:256
MQC_NUMCTXS
#define MQC_NUMCTXS
Definition: mqc.h:41