Grok
12.0.1
src
lib
core
t1
part1
impl
mqc_enc_inl.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2016-2024 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
29
void
mqc_byteout
(mqcoder* mqc);
30
38
#define mqc_renorme_macro(mqc, a_, c_, ct_) \
39
{ \
40
do \
41
{ \
42
a_ <<= 1; \
43
c_ <<= 1; \
44
ct_--; \
45
if(ct_ == 0) \
46
{ \
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
{ \
60
if(a < (*curctx)->qeval) \
61
a = (*curctx)->qeval; \
62
else \
63
c += (*curctx)->qeval; \
64
*curctx = (*curctx)->nmps; \
65
mqc_renorme_macro(mqc, a, c, ct); \
66
} \
67
else \
68
{ \
69
c += (*curctx)->qeval; \
70
} \
71
}
72
73
#define mqc_codelps_macro(mqc, curctx, a, c, ct) \
74
{ \
75
a -= (*curctx)->qeval; \
76
if(a < (*curctx)->qeval) \
77
c += (*curctx)->qeval; \
78
else \
79
a = (*curctx)->qeval; \
80
*curctx = (*curctx)->nlps; \
81
mqc_renorme_macro(mqc, a, c, ct); \
82
}
83
84
#ifdef PLUGIN_DEBUG_ENCODE
85
#define mqc_encode_macro(mqc, curctx, a, c, ct, d) \
86
{ \
87
(mqc)->debug_mqc.context_number = ctxno; \
88
nextCXD(&(mqc)->debug_mqc, d); \
89
if((*curctx)->mps == (d)) \
90
mqc_codemps_macro(mqc, curctx, a, c, ct) else mqc_codelps_macro(mqc, curctx, a, c, ct) \
91
}
92
#else
93
#define mqc_encode_macro(mqc, curctx, a, c, ct, d) \
94
{ \
95
if((*curctx)->mps == (d)) \
96
mqc_codemps_macro(mqc, curctx, a, c, ct) else mqc_codelps_macro(mqc, curctx, a, c, ct) \
97
}
98
#endif
99
#define mqc_bypass_enc_macro(mqc, c, ct, d) \
100
{ \
101
if(ct == BYPASS_CT_INIT) \
102
ct = 8; \
103
ct--; \
104
c = c + ((d) << ct); \
105
if(ct == 0) \
106
{ \
107
*mqc->bp = (uint8_t)c; \
108
ct = 8; \
109
/* If the previous byte was 0xff, make sure that the next msb is 0 */
\
110
if(*mqc->bp == 0xff) \
111
ct = 7; \
112
mqc->bp++; \
113
c = 0; \
114
} \
115
}
mqc_byteout
void mqc_byteout(mqcoder *mqc)
Output a byte, doing bit-stuffing if necessary.
Generated by
1.10.0