Grok
7.6.6
src
lib
jp2
t1
t1_part1
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
}
mqc_byteout
void mqc_byteout(mqcoder *mqc)
Output a byte, doing bit-stuffing if necessary.
Generated by
1.9.1