Grok 20.3.2
mqc.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 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
18#pragma once
19
20#include "mqc_base.h"
21#include "mqc_backup.h"
22
23// the next line must be uncommented in order to support debugging
24// for plugin encode
25// #define PLUGIN_DEBUG_ENCODE
27#ifdef PLUGIN_DEBUG_ENCODE
29#endif
31namespace grk::t1
36 * @brief MQ coder
37 */
38struct mqcoder : public mqcoder_base
39{
43 mqcoder(void);
47 */
48 explicit mqcoder(bool cached);
49
50 // Copy constructor
51 mqcoder(const mqcoder& other);
52
53 ~mqcoder();
54
55 // Copy assignment operator
56 mqcoder& operator=(const mqcoder& other);
57
58 bool operator==(const mqcoder& other) const;
59
62
63 void print(const std::string& msg);
64
65 void resetstates(void);
66
67 void reinit(void);
68
69
70 * @brief Backs up data to backup_
71 */
72 void backup();
76 void restore();
80 * @param bp Pointer to the start of the buffer from which the bytes will be read
81 * @param len Length of input buffer
82 */
83 void init_dec(uint8_t** buffers, uint32_t* buffer_lengths, uint16_t num_buffers);
84
85 void init_dec_common(uint8_t** buffers, uint32_t* buffer_lengths, uint16_t num_buffers);
86 void update_dec(uint8_t** buffers, uint32_t* buffer_lengths, uint16_t num_buffers);
87
88 /**
89 * @brief Initializes decoder for RAW decoding
90 * @param bp Pointer to the start of the buffer from which the bytes will be read
91 * @param len Length of input buffer
92 */
93 void raw_init_dec(uint8_t** buffers, uint32_t* buffer_lengths, uint16_t num_buffers);
94
95 uint16_t numbytes_enc(void);
96 void init_enc(uint8_t* bp);
97 void flush_enc(void);
98 void bypass_init_enc(void);
99 uint16_t bypass_get_extra_bytes_enc(bool erterm);
100 void bypass_flush_enc(bool erterm);
101 void restart_init_enc(void);
102 void erterm_enc(void);
103 void segmark_enc(void);
104 void setbits_enc(void);
109 uint8_t* start;
111 * @brief Pointer to end of buffer
112 */
113 uint8_t* end;
114
116 * @brief Array of pointers to buffers
117 */
118 uint8_t** buffers;
123 uint32_t* buffer_lengths;
124
128 uint16_t num_buffers;
129
134
144
145 /**
146 * @brief lut_ctxno_zc shifted by (1 << 9) * bandIndex
147 */
148 const uint8_t* lut_ctxno_zc_orient;
149#ifdef PLUGIN_DEBUG_ENCODE
150 grk_plugin_debug_mqc debug_mqc;
151#endif
152};
153
154#ifdef PLUGIN_DEBUG_ENCODE
155#define CODER_SETCURCTX(mqc, ctxno) \
156 (mqc)->debug_mqc.context_number = ctxno; \
157 (mqc)->curctx = (mqc)->ctxs + (uint32_t)(ctxno)
158#else
159#define CODER_SETCURCTX(mqc, ctxno) (mqc)->curctx = (mqc)->ctxs + (uint32_t)(ctxno)
160#endif
161#include "mqc_dec_inl.h"
162#include "mqc_enc_inl.h"
163
164/* DECODE */
166} // namespace grk::t1
Definition SchedulerFreebyrd.h:36
Definition plugin_interface.h:38
MQ coder base class used to manage backup/restore.
Definition mqc_backup.h:33
uint8_t * bp
Pointer to current position in buffer.
Definition mqc_base.h:254
mqcoder_base(bool cached)
Creates an mqcoder_base.
Definition mqc_base.cpp:26
uint16_t bypass_get_extra_bytes_enc(bool erterm)
Definition mqc.cpp:248
mqcoder & operator=(const mqcoder &other)
Definition mqc.cpp:44
void setbits_enc(void)
Definition mqc.cpp:183
void update_dec(uint8_t **buffers, uint32_t *buffer_lengths, uint16_t num_buffers)
Definition mqc.cpp:162
mqcoder_backup * backup_
mqcoder_backup
Definition mqc.h:138
uint16_t numbytes_enc(void)
Definition mqc.cpp:178
void resetstates(void)
Definition mqc.cpp:112
uint8_t * start
Pointer to start of buffer.
Definition mqc.h:109
void restore()
Restores data from backup_.
Definition mqc.cpp:102
void raw_init_dec(uint8_t **buffers, uint32_t *buffer_lengths, uint16_t num_buffers)
Initializes decoder for RAW decoding.
Definition mqc.cpp:169
void print(const std::string &msg)
Prints internal state.
Definition mqc.cpp:85
void init_dec_common(uint8_t **buffers, uint32_t *buffer_lengths, uint16_t num_buffers)
Definition mqc.cpp:127
void reinit(void)
Definition mqc.cpp:121
void bypass_flush_enc(bool erterm)
Definition mqc.cpp:253
void init_enc(uint8_t *bp)
Definition mqc.cpp:191
void init_dec(uint8_t **buffers, uint32_t *buffer_lengths, uint16_t num_buffers)
Initializes decoder for MQ decoding.
Definition mqc.cpp:136
void segmark_enc(void)
Definition mqc.cpp:327
uint8_t * end
Pointer to end of buffer.
Definition mqc.h:113
uint32_t * buffer_lengths
Array of buffer lengths.
Definition mqc.h:123
void backup()
Backs up data to backup_.
Definition mqc.cpp:92
void restart_init_enc(void)
Definition mqc.cpp:295
uint32_t cur_buffer_index
Index of the current buffer.
Definition mqc.h:133
~mqcoder()
Definition mqc.cpp:38
const uint8_t * lut_ctxno_zc_orient
lut_ctxno_zc shifted by (1 << 9) * bandIndex
Definition mqc.h:148
bool overflow_
true if compressed buffer overflow detected
Definition mqc.h:143
uint16_t num_buffers
Number of buffers.
Definition mqc.h:128
void flush_enc(void)
Definition mqc.cpp:214
void erterm_enc(void)
Definition mqc.cpp:313
mqcoder(void)
Creates an mqcoder.
Definition mqc.cpp:27
bool operator==(const mqcoder &other) const
Definition mqc.cpp:65
uint8_t ** buffers
Array of pointers to buffers.
Definition mqc.h:118
void bypass_init_enc(void)
Definition mqc.cpp:230