Grok  9.5.0
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
31 {
33  uint32_t qeval;
35  uint32_t mps;
37  const mqc_state* nmps;
39  const mqc_state* nlps;
40 };
41 
42 #define MQC_NUMCTXS 19
43 struct mqcoder
44 {
46  uint32_t c;
48  uint32_t a;
50  uint32_t ct;
51  /* only used by decoder, to count the number of times a terminating 0xFF >0x8F marker is read */
54  uint8_t* bp;
56  uint8_t* start;
58  uint8_t* end;
62  const mqc_state** curctx;
63  /* lut_ctxno_zc shifted by (1 << 9) * bandIndex */
64  const uint8_t* lut_ctxno_zc_orient;
67 };
68 
69 const uint32_t A_MIN = 0x8000;
70 
71 #include "mqc_inl.h"
72 #include "mqc_dec_inl.h"
73 #include "mqc_enc_inl.h"
74 
75 uint32_t mqc_numbytes_enc(mqcoder* mqc);
76 void mqc_resetstates(mqcoder* mqc);
77 
78 /* ENCODE */
79 
80 void mqc_init_enc(mqcoder* mqc, uint8_t* bp);
81 void mqc_encode(mqcoder* mqc, uint32_t d);
82 void mqc_flush_enc(mqcoder* mqc);
83 void mqc_bypass_init_enc(mqcoder* mqc);
84 uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder* mqc, bool erterm);
85 void mqc_bypass_enc(mqcoder* mqc, uint32_t d);
86 void mqc_bypass_flush_enc(mqcoder* mqc, bool erterm);
87 void mqc_restart_init_enc(mqcoder* mqc);
88 void mqc_erterm_enc(mqcoder* mqc);
89 void mqc_segmark_enc(mqcoder* mqc);
90 
91 /* DECODE */
92 
108 void mqc_init_dec(mqcoder* mqc, uint8_t* bp, uint32_t len);
109 
125 void mqc_raw_init_dec(mqcoder* mqc, uint8_t* bp, uint32_t len);
126 
135 void mqc_finish_dec(mqcoder* mqc);
136 
137 } // namespace grk
#define MQC_NUMCTXS
Definition: mqc.h:42
Copyright (C) 2016-2021 Grok Image Compression Inc.
Definition: ICacheable.h:20
void mqc_flush_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:213
uint32_t mqc_numbytes_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:177
void mqc_segmark_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:327
void mqc_raw_init_dec(mqcoder *mqc, uint8_t *bp, uint32_t len)
Initialize the decoder for RAW decoding.
Definition: mqc_dec.cpp:108
void mqc_bypass_flush_enc(mqcoder *mqc, bool erterm)
Definition: mqc_enc.cpp:252
const uint32_t A_MIN
Definition: mqc.h:69
void mqc_erterm_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:312
void mqc_bypass_enc(mqcoder *mqc, uint32_t d)
void mqc_finish_dec(mqcoder *mqc)
Terminate RAW/MQC decoding.
Definition: mqc_dec.cpp:115
void mqc_restart_init_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:294
void mqc_bypass_init_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:229
void mqc_encode(mqcoder *mqc, uint32_t d)
Definition: mqc_enc.cpp:205
void mqc_init_enc(mqcoder *mqc, uint8_t *bp)
Definition: mqc_enc.cpp:182
uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder *mqc, bool erterm)
Definition: mqc_enc.cpp:247
void mqc_init_dec(mqcoder *mqc, uint8_t *bp, uint32_t len)
Initialize the decoder for MQ decoding.
Definition: mqc_dec.cpp:91
void mqc_resetstates(mqcoder *mqc)
Definition: mqc_dec.cpp:121
Definition: mqc.h:31
const mqc_state * nmps
next state if the next encoded symbol is the MPS
Definition: mqc.h:37
const mqc_state * nlps
next state if the next encoded symbol is the LPS
Definition: mqc.h:39
uint32_t mps
the Most Probable Symbol (0 or 1)
Definition: mqc.h:35
uint32_t qeval
the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff)
Definition: mqc.h:33
Definition: mqc.h:44
uint32_t end_of_byte_stream_counter
Definition: mqc.h:52
uint8_t * end
pointer to the end of the buffer
Definition: mqc.h:58
const mqc_state * ctxs[MQC_NUMCTXS]
Array of contexts.
Definition: mqc.h:60
uint32_t a
only used by MQ decoder
Definition: mqc.h:48
uint8_t * start
pointer to the start of the buffer
Definition: mqc.h:56
const uint8_t * lut_ctxno_zc_orient
Definition: mqc.h:64
const mqc_state ** curctx
Active context.
Definition: mqc.h:62
uint8_t * bp
pointer to the current position in the buffer
Definition: mqc.h:54
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
uint32_t ct
number of bits already read or free to write
Definition: mqc.h:50
uint32_t c
temporary buffer where bits are coded or decoded
Definition: mqc.h:46
const uint8_t grk_cblk_dec_compressed_data_pad_right
< Space for a fake FFFF marker
Definition: t1_common.h:37