Grok
7.6.0
build
libgrokj2k-CKORTy
libgrokj2k-7.6.0
src
lib
jp2
t1
t1_part1
mqc_dec_inl.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2016-2020 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
/* For internal use of decode_macro() */
25
#define mpsexchange_dec_macro(d, curctx, a) \
26
{ \
27
if (a < (*curctx)->qeval) { \
28
d = (*curctx)->mps ^ 1; \
29
*curctx = (*curctx)->nlps; \
30
} else { \
31
d = (*curctx)->mps; \
32
*curctx = (*curctx)->nmps; \
33
} \
34
}
35
36
/* For internal use of decode_macro() */
37
#define lpsexchange_dec_macro(d, curctx, a) \
38
{ \
39
if (a < (*curctx)->qeval) { \
40
a = (*curctx)->qeval; \
41
d = (*curctx)->mps; \
42
*curctx = (*curctx)->nmps; \
43
} else { \
44
a = (*curctx)->qeval; \
45
d = (*curctx)->mps ^ 1; \
46
*curctx = (*curctx)->nlps; \
47
} \
48
}
49
55
static
INLINE
uint32_t
mqc_raw_decode
(mqcoder *mqc){
56
if
(mqc->ct == 0) {
57
/* Given mqc_raw_init_dec() we know that at some point we will */
58
/* have a 0xFF 0xFF artificial marker */
59
if
(mqc->c == 0xff) {
60
if
(*mqc->bp > 0x8f) {
61
mqc->c = 0xff;
62
mqc->ct = 8;
63
}
else
{
64
mqc->c = *mqc->bp;
65
mqc->bp ++;
66
mqc->ct = 7;
67
}
68
}
else
{
69
mqc->c = *mqc->bp;
70
mqc->bp ++;
71
mqc->ct = 8;
72
}
73
}
74
mqc->ct--;
75
76
return
((uint32_t)mqc->c >> mqc->ct) & 0x01U;
77
}
78
79
#define bytein_dec_macro(mqc, c, ct) \
80
{ \
81
/* Given mqc_init_dec() we know that at some point we will */
\
82
/* have a 0xFF 0xFF artificial marker */
\
83
uint32_t l_c = *(mqc->bp + 1); \
84
if (*mqc->bp == 0xff) { \
85
if (l_c > 0x8f) { \
86
c += 0xff00; \
87
ct = 8; \
88
mqc->end_of_byte_stream_counter ++; \
89
} else { \
90
mqc->bp++; \
91
c += l_c << 9; \
92
ct = 7; \
93
} \
94
} else { \
95
mqc->bp++; \
96
c += l_c << 8; \
97
ct = 8; \
98
} \
99
}
100
101
/* For internal use of decode_macro() */
102
#define renorm_dec_macro(mqc, a, c, ct) \
103
{ \
104
do { \
105
if (ct == 0) \
106
bytein_dec_macro(mqc, c, ct); \
107
a <<= 1; \
108
c <<= 1; \
109
ct--; \
110
} while (a < A_MIN); \
111
}
112
113
#define decode_macro(d, mqc, curctx, a, c, ct) \
114
{ \
115
/* Implements ISO 15444-1 C.3.2 Decoding a decision (DECODE) */
\
116
a -= (*curctx)->qeval; \
117
uint32_t qeval_shift = (*curctx)->qeval << 16; \
118
if (c < qeval_shift) { \
119
lpsexchange_dec_macro(d, curctx, a); \
120
renorm_dec_macro(mqc, a, c, ct); \
121
} else { \
122
c -= qeval_shift; \
123
if (a < A_MIN) { \
124
mpsexchange_dec_macro(d, curctx, a); \
125
renorm_dec_macro(mqc, a, c, ct); \
126
} else { \
127
d = (*curctx)->mps; \
128
} \
129
} \
130
}
131
136
static
INLINE
void
mqc_bytein
(mqcoder *
const
mqc){
137
bytein_dec_macro
(mqc, mqc->c, mqc->ct);
138
}
139
144
#define mqc_renormd(mqc) \
145
renorm_dec_macro(mqc, mqc->a, mqc->c, mqc->ct)
146
153
#define mqc_decode(d, mqc) \
154
decode_macro(d, mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct)
mqc_bytein
static INLINE void mqc_bytein(mqcoder *const mqc)
Input a byte.
Definition:
mqc_dec_inl.h:136
bytein_dec_macro
#define bytein_dec_macro(mqc, c, ct)
Definition:
mqc_dec_inl.h:79
mqc_raw_decode
static INLINE uint32_t mqc_raw_decode(mqcoder *mqc)
Decode a symbol using raw-decoder.
Definition:
mqc_dec_inl.h:55
INLINE
#define INLINE
Definition:
t1_common.h:28
Generated by
1.8.18