Grok  7.6.3
mqc_enc_inl.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 
25 
31 void mqc_byteout(mqcoder *mqc);
32 
40 #define mqc_renorme_macro(mqc, a_, c_, ct_) \
41 { \
42  do { \
43  a_ <<= 1; \
44  c_ <<= 1; \
45  ct_--; \
46  if (ct_ == 0) { \
47  mqc->c = c_; \
48  mqc_byteout(mqc); \
49  c_ = mqc->c; \
50  ct_ = mqc->ct; \
51  } \
52  } while( (a_ & 0x8000) == 0); \
53 }
54 
55 #define mqc_codemps_macro(mqc, curctx, a, c, ct) \
56 { \
57  a -= (*curctx)->qeval; \
58  if ((a & 0x8000) == 0) { \
59  if (a < (*curctx)->qeval) { \
60  a = (*curctx)->qeval; \
61  } else { \
62  c += (*curctx)->qeval; \
63  } \
64  *curctx = (*curctx)->nmps; \
65  mqc_renorme_macro(mqc, a, c, ct); \
66  } else { \
67  c += (*curctx)->qeval; \
68  } \
69 }
70 
71 #define mqc_codelps_macro(mqc, curctx, a, c, ct) \
72 { \
73  a -= (*curctx)->qeval; \
74  if (a < (*curctx)->qeval) { \
75  c += (*curctx)->qeval; \
76  } else { \
77  a = (*curctx)->qeval; \
78  } \
79  *curctx = (*curctx)->nlps; \
80  mqc_renorme_macro(mqc, a, c, ct); \
81 }
82 
83 #define mqc_encode_macro(mqc, curctx, a, c, ct, d) \
84 { \
85  if ((*curctx)->mps == (d)) { \
86  mqc_codemps_macro(mqc, curctx, a, c, ct); \
87  } else { \
88  mqc_codelps_macro(mqc, curctx, a, c, ct); \
89  } \
90 }
91 
92 
93 #define mqc_bypass_enc_macro(mqc, c, ct, d) \
94 {\
95  if (ct == BYPASS_CT_INIT) {\
96  ct = 8;\
97  }\
98  ct--;\
99  c = c + ((d) << ct);\
100  if (ct == 0) {\
101  *mqc->bp = (uint8_t)c;\
102  ct = 8;\
103  /* If the previous byte was 0xff, make sure that the next msb is 0 */ \
104  if (*mqc->bp == 0xff) {\
105  ct = 7;\
106  }\
107  mqc->bp++;\
108  c = 0;\
109  }\
110 }
grk::mqc_bypass_get_extra_bytes_enc
uint32_t mqc_bypass_get_extra_bytes_enc(mqcoder *mqc, bool erterm)
Definition: mqc_enc.cpp:273
grk::mqc_erterm_enc
void mqc_erterm_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:331
t1_common.h
grk::mqcoder::start
uint8_t * start
pointer to the start of the buffer
Definition: mqc.h:54
grk::mqc_renorm_enc
static void mqc_renorm_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:166
grk::mqc_init_enc
void mqc_init_enc(mqcoder *mqc, uint8_t *bp)
Definition: mqc_enc.cpp:210
grk::mqc_codelps_enc
static void mqc_codelps_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:190
grk::mqc_byteout
void mqc_byteout(mqcoder *mqc)
Definition: mqc_enc.cpp:133
grk::mqcoder::bp
uint8_t * bp
pointer to the current position in the buffer
Definition: mqc.h:52
mqc_setcurctx
#define mqc_setcurctx(mqc, ctxno)
Definition: mqc_inl.h:38
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
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
BYPASS_CT_INIT
#define BYPASS_CT_INIT
Definition: mqc_inl.h:24
grk::mqc_state
Definition: mqc.h:30
grk::mqc_segmark_enc
void mqc_segmark_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:344
grk::mqc_encode
void mqc_encode(mqcoder *mqc, uint32_t d)
Definition: mqc_enc.cpp:232
grk::mqc_numbytes_enc
uint32_t mqc_numbytes_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:206
mqc_byteout
void mqc_byteout(mqcoder *mqc)
Output a byte, doing bit-stuffing if necessary.
grk::mqcoder::end_of_byte_stream_counter
uint32_t end_of_byte_stream_counter
Definition: mqc.h:50
grk::mqc_states
static const mqc_state mqc_states[47 *2]
Definition: mqc_dec.cpp:29
grk::mqc_codemps_enc
static void mqc_codemps_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:176
grk::mqc_setbits_enc
static void mqc_setbits_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:200
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_init_enc
void mqc_bypass_init_enc(mqcoder *mqc)
Definition: mqc_enc.cpp:256