Grok 20.3.2
BlockExec.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 <functional>
21
22#include "t1_common.h"
23#include "CodeblockCompress.h"
24#include "CodeblockDecompress.h"
25#include "ICoder.h"
26#include "IOpenable.h"
27
28namespace grk::t1
29{
30
32{
33 using IOpenable::open;
34
35 BlockExec() = default;
36 virtual ~BlockExec() override = default;
37 virtual bool open(ICoder* coder) = 0;
38 uint8_t bandIndex = 0;
39 uint8_t bandNumbps = 0;
41 float stepsize = 0;
42 uint8_t cblk_sty = 0;
43 uint8_t qmfbid = 0;
44 /* code block offset in buffer coordinates*/
45 uint32_t x = 0;
46 uint32_t y = 0;
47 // missing bit planes for all blocks in band
48 uint8_t k_msbs = 0;
49 uint8_t R_b = 0;
50
51private:
52 // Delete copy constructor and assignment operator
53 BlockExec(const BlockExec&) = delete;
54 BlockExec& operator=(const BlockExec&) = delete;
55};
56
58
59template<typename T>
61 std::function<void(T* srcData, DecompressBlockExec* block, uint16_t stride)>;
62
64{
65 DecompressBlockExec(bool cacheCoder) : shouldCacheCoder_(cacheCoder) {}
67 {
68 delete cachedCoder_;
69 }
70 void setOpen(std::function<void()>& open)
71 {
72 open_ = open;
73 }
74 void open(void) override
75 {
76 if(open_)
77 open_();
78 }
79 void close(void) override
80 {
81 delete cachedCoder_;
82 cachedCoder_ = nullptr;
83 if(cblk)
84 cblk->release();
85 }
86 bool open(ICoder* coder) override
87 {
88 auto activeCoder = cachedCoder_ ? cachedCoder_ : coder;
89 if(!activeCoder)
90 return false;
91 bool rc = activeCoder->decompress(this);
93 cachedCoder_ = coder;
94
95 return rc;
96 }
97
99 {
101 }
102
103 bool hasCachedCoder(void)
104 {
105 return cachedCoder_ != nullptr;
106 }
107
109 {
110 delete cachedCoder_;
111 cachedCoder_ = nullptr;
112 }
115 uint8_t resno = 0;
116 uint8_t roishift = 0;
118 bool shouldCacheCoder_ = false;
119 bool finalLayer_ = false;
120
121private:
122 std::function<void()> open_;
123
124 // Delete copy constructor and assignment operator
127};
129{
130 CompressBlockExec() = default;
131 ~CompressBlockExec() override = default;
132
133 void open(void) override {}
134 void close(void) override {}
135
136 bool open(ICoder* coder) override
137 {
138 return coder->compress(this);
139 }
140
142 uint32_t tile_width = 0;
143 bool doRateControl = false;
144 double distortion = 0;
145 int32_t* tiledp = nullptr;
146 uint16_t compno = 0;
147 uint8_t resno = 0;
148 uint8_t level = 0;
149 uint64_t precinctIndex = 0;
150 float inv_step_ht = 0;
151 const double* mct_norms = nullptr;
152#ifdef DEBUG_LOSSLESS_T1
153 int32_t* unencodedData = nullptr;
154#endif
155 uint16_t mct_numcomps = 0;
156 bool use16BitDwt = false;
157
158 // Delete copy constructor and assignment operator
161};
162
163} // namespace grk::t1
interface to code block compressor / decompressor
Definition ICoder.h:31
virtual bool decompress(DecompressBlockExec *block)=0
decompress code block
virtual bool compress(CompressBlockExec *block)=0
compress code block
Definition SchedulerFreebyrd.h:36
eBandOrientation
Definition t1_common.h:28
@ BAND_ORIENT_LL
Definition t1_common.h:29
std::function< void(T *srcData, DecompressBlockExec *block, uint16_t stride)> DecompressBlockPostProcessor
Definition BlockExec.h:60
Definition IOpenable.h:24
uint8_t k_msbs
Definition BlockExec.h:48
uint32_t x
Definition BlockExec.h:45
uint8_t cblk_sty
Definition BlockExec.h:42
virtual ~BlockExec() override=default
BlockExec(const BlockExec &)=delete
uint8_t bandIndex
Definition BlockExec.h:38
virtual bool open(ICoder *coder)=0
BlockExec & operator=(const BlockExec &)=delete
uint8_t qmfbid
Definition BlockExec.h:43
uint32_t y
Definition BlockExec.h:46
uint8_t bandNumbps
Definition BlockExec.h:39
eBandOrientation bandOrientation
Definition BlockExec.h:40
float stepsize
Definition BlockExec.h:41
uint8_t R_b
Definition BlockExec.h:49
Stores information about compression code block.
Definition CodeblockCompress.h:31
Definition CodeblockDecompress.h:27
uint16_t compno
Definition BlockExec.h:146
float inv_step_ht
Definition BlockExec.h:150
bool open(ICoder *coder) override
Definition BlockExec.h:136
uint64_t precinctIndex
Definition BlockExec.h:149
uint16_t mct_numcomps
Definition BlockExec.h:155
CompressBlockExec & operator=(const CompressBlockExec &)=delete
double distortion
Definition BlockExec.h:144
uint32_t tile_width
Definition BlockExec.h:142
void close(void) override
Definition BlockExec.h:134
const double * mct_norms
Definition BlockExec.h:151
uint8_t level
Definition BlockExec.h:148
bool use16BitDwt
Definition BlockExec.h:156
~CompressBlockExec() override=default
void open(void) override
Definition BlockExec.h:133
bool doRateControl
Definition BlockExec.h:143
uint8_t resno
Definition BlockExec.h:147
int32_t * tiledp
Definition BlockExec.h:145
CodeblockCompress * cblk
Definition BlockExec.h:141
CompressBlockExec(const CompressBlockExec &)=delete
Definition BlockExec.h:64
bool finalLayer_
Definition BlockExec.h:119
DecompressBlockExec & operator=(const DecompressBlockExec &)=delete
DecompressBlockExec(bool cacheCoder)
Definition BlockExec.h:65
bool hasCachedCoder(void)
Definition BlockExec.h:103
uint8_t roishift
Definition BlockExec.h:116
bool needsCachedCoder(void)
Definition BlockExec.h:98
uint8_t resno
Definition BlockExec.h:115
void clearCachedCoder(void)
Definition BlockExec.h:108
void open(void) override
Definition BlockExec.h:74
void setOpen(std::function< void()> &open)
Definition BlockExec.h:70
bool open(ICoder *coder) override
Definition BlockExec.h:86
DecompressBlockPostProcessor< int32_t > postProcessor_
Definition BlockExec.h:113
CodeblockDecompress * cblk
Definition BlockExec.h:114
ICoder * cachedCoder_
Definition BlockExec.h:117
bool shouldCacheCoder_
Definition BlockExec.h:118
void close(void) override
Definition BlockExec.h:79
std::function< void()> open_
Definition BlockExec.h:122
DecompressBlockExec(const DecompressBlockExec &)=delete
~DecompressBlockExec() override
Definition BlockExec.h:66