Grok 10.0.5
WaveletReverse.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2023 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#include <cstdint>
25
26namespace grk
27{
28
29typedef vec<float, 4> vec4f;
30
31template<typename T, typename S>
32struct TaskInfo
33{
34 TaskInfo(S data, grk_buf2d_simple<T> winLL, grk_buf2d_simple<T> winHL,
35 grk_buf2d_simple<T> winLH, grk_buf2d_simple<T> winHH, grk_buf2d_simple<T> winDest,
36 uint32_t indexMin, uint32_t indexMax)
38 indexMin_(indexMin), indexMax_(indexMax)
39 {}
40 TaskInfo(S data, uint32_t indexMin, uint32_t indexMax)
41 : data(data), indexMin_(indexMin), indexMax_(indexMax)
42 {}
43 ~TaskInfo(void)
44 {
45 data.release();
46 }
48 grk_buf2d_simple<T> winLL;
49 grk_buf2d_simple<T> winHL;
50 grk_buf2d_simple<T> winLH;
51 grk_buf2d_simple<T> winHH;
52 grk_buf2d_simple<T> winDest;
53
54 uint32_t indexMin_;
55 uint32_t indexMax_;
56};
57
58uint32_t max_resolution(Resolution* GRK_RESTRICT r, uint32_t i);
59
60template<class T>
61constexpr T getHorizontalPassHeight(bool lossless)
62{
63 return T(lossless ? 1 : vec4f::NUM_ELTS);
64}
65
66template<typename T>
67struct dwt_data
68{
69 dwt_data(void)
70 : allocatedMem(nullptr), lenBytes_(0), paddingBytes_(0), mem(nullptr), memL(nullptr),
71 memH(nullptr), sn_full(0), dn_full(0), parity(0), resno(0)
72 {}
73 dwt_data(const dwt_data& rhs)
74 : allocatedMem(nullptr), lenBytes_(0), paddingBytes_(0), mem(nullptr), memL(nullptr),
75 memH(nullptr), sn_full(rhs.sn_full), dn_full(rhs.dn_full), parity(rhs.parity),
76 win_l(rhs.win_l), win_h(rhs.win_h), resno(rhs.resno)
77 {}
78 ~dwt_data(void)
79 {
80 release();
81 }
82 bool alloc(size_t len)
83 {
84 return alloc(len, 0);
85 }
86 bool alloc(size_t len, size_t padding)
87 {
88 release();
89
90 /* overflow check */
91 if(len > (SIZE_MAX / sizeof(T)))
92 {
93 GRK_ERROR("data size overflow");
94 return false;
95 }
96 paddingBytes_ = grk_make_aligned_width((uint32_t)padding * 2 + 32) * sizeof(T);
97 lenBytes_ = len * sizeof(T) + 2 * paddingBytes_;
99 if(!allocatedMem)
100 {
101 GRK_ERROR("Failed to allocate %u bytes", lenBytes_);
102 return false;
103 }
104 mem = allocatedMem + paddingBytes_ / sizeof(T);
105
106 return (allocatedMem != nullptr) ? true : false;
107 }
108 void release(void)
109 {
111 allocatedMem = nullptr;
112 mem = nullptr;
113 memL = nullptr;
114 memH = nullptr;
115 }
117 size_t lenBytes_;
119 T* mem;
122 uint32_t sn_full; /* number of elements in low pass band */
123 uint32_t dn_full; /* number of elements in high pass band */
124 uint32_t parity; /* 0 = start on even coord, 1 = start on odd coord */
125 grk_line32 win_l;
126 grk_line32 win_h;
127 uint8_t resno;
128};
129
130struct Params97
131{
132 Params97(void) : dataPrev(nullptr), data(nullptr), len(0), lenMax(0) {}
133 vec4f* dataPrev;
134 vec4f* data;
135 uint32_t len;
136 uint32_t lenMax;
137};
138
139class WaveletReverse
140{
141 public:
142 WaveletReverse(TileProcessor* tileProcessor, TileComponent* tilec, uint16_t compno,
143 grk_rect32 window, uint8_t numres, uint8_t qmfbid);
144 ~WaveletReverse(void);
145 bool decompress(void);
146
147 static void decompress_step_97(dwt_data<vec4f>* GRK_RESTRICT dwt);
148
149 private:
150 template<typename T, uint32_t FILTER_WIDTH, uint32_t VERT_PASS_WIDTH, typename D>
151 bool decompress_partial_tile(ISparseCanvas* sa, std::vector<TaskInfo<T, dwt_data<T>>*>& tasks);
152 static void decompress_step1_97(const Params97& d, const float c);
153#ifdef __SSE__
154 static void decompress_step1_sse_97(Params97 d, const __m128 c);
155#endif
156 static Params97 makeParams97(dwt_data<vec4f>* dwt, bool isBandL, bool step1);
157 void interleave_h_97(dwt_data<vec4f>* GRK_RESTRICT dwt, grk_buf2d_simple<float> winL,
158 grk_buf2d_simple<float> winH, uint32_t remaining_height);
159 void decompress_h_strip_97(dwt_data<vec4f>* GRK_RESTRICT horiz, const uint32_t resHeight,
160 grk_buf2d_simple<float> winL, grk_buf2d_simple<float> winH,
161 grk_buf2d_simple<float> winDest);
162 bool decompress_h_97(uint8_t res, uint32_t numThreads, size_t dataLength,
163 dwt_data<vec4f>& GRK_RESTRICT horiz, const uint32_t resHeight,
164 grk_buf2d_simple<float> winL, grk_buf2d_simple<float> winH,
165 grk_buf2d_simple<float> winDest);
166 void interleave_v_97(dwt_data<vec4f>* GRK_RESTRICT dwt, grk_buf2d_simple<float> winL,
167 grk_buf2d_simple<float> winH, uint32_t nb_elts_read);
168 void decompress_v_strip_97(dwt_data<vec4f>* GRK_RESTRICT vert, const uint32_t resWidth,
169 const uint32_t resHeight, grk_buf2d_simple<float> winL,
170 grk_buf2d_simple<float> winH, grk_buf2d_simple<float> winDest);
171 bool decompress_v_97(uint8_t res, uint32_t numThreads, size_t dataLength,
172 dwt_data<vec4f>& GRK_RESTRICT vert, const uint32_t resWidth,
173 const uint32_t resHeight, grk_buf2d_simple<float> winL,
174 grk_buf2d_simple<float> winH, grk_buf2d_simple<float> winDest);
175 bool decompress_tile_97(void);
176 void decompress_h_parity_even_53(int32_t* buf, int32_t* bandL, /* even */
177 const uint32_t wL, int32_t* bandH, const uint32_t wH,
178 int32_t* dest);
179 void decompress_h_parity_odd_53(int32_t* buf, int32_t* bandL, /* odd */
180 const uint32_t wL, int32_t* bandH, const uint32_t wH,
181 int32_t* dest);
182 void decompress_v_parity_even_53(int32_t* buf, int32_t* bandL, const uint32_t hL,
183 const uint32_t strideL, int32_t* bandH, const uint32_t hH,
184 const uint32_t strideH, int32_t* dest,
185 const uint32_t strideDest);
186 void decompress_v_parity_odd_53(int32_t* buf, int32_t* bandL, const uint32_t hL,
187 const uint32_t strideL, int32_t* bandH, const uint32_t hH,
188 const uint32_t strideH, int32_t* dest,
189 const uint32_t strideDest);
190 void decompress_h_53(const dwt_data<int32_t>* dwt, int32_t* bandL, int32_t* bandH,
191 int32_t* dest);
192 void decompress_v_53(const dwt_data<int32_t>* dwt, grk_buf2d_simple<int32_t> winL,
193 grk_buf2d_simple<int32_t> winH, grk_buf2d_simple<int32_t> winDest,
194 uint32_t nb_cols);
195 void decompress_h_strip_53(const dwt_data<int32_t>* horiz, uint32_t hMin, uint32_t hMax,
196 grk_buf2d_simple<int32_t> winL, grk_buf2d_simple<int32_t> winH,
197 grk_buf2d_simple<int32_t> winDest);
198 bool decompress_h_53(uint8_t res, TileComponentWindow<int32_t>* buf, uint32_t resHeight,
199 size_t dataLength);
200 void decompress_v_strip_53(const dwt_data<int32_t>* vert, uint32_t wMin, uint32_t wMax,
201 grk_buf2d_simple<int32_t> winL, grk_buf2d_simple<int32_t> winH,
202 grk_buf2d_simple<int32_t> winDest);
203 bool decompress_v_53(uint8_t res, TileComponentWindow<int32_t>* buf, uint32_t resWidth,
204 size_t dataLength);
205 bool decompress_tile_53(void);
206
207 TileProcessor* tileProcessor_;
208 Scheduler* scheduler_;
209 TileComponent* tilec_;
210 uint16_t compno_;
212 uint8_t numres_;
213 uint8_t qmfbid_;
214
215 dwt_data<int32_t> horiz_;
216 dwt_data<int32_t> vert_;
217
218 dwt_data<vec4f> horizF_;
219 dwt_data<vec4f> vertF_;
220
221 std::vector<TaskInfo<vec4f, dwt_data<vec4f>>*> tasksF_;
222 std::vector<TaskInfo<int32_t, dwt_data<int32_t>>*> tasks_;
223};
224
225} // namespace grk
uint8_t buf
Definition BitIO.h:84
uint8_t resno
Definition BlockExec.h:53
TileComponent * tilec
Definition BlockExec.h:30
uint32_t len
Definition Codeblock.h:38
uint8_t * data
Definition Codeblock.h:61
uint8_t qmfbid
discrete wavelet transform identifier
Definition CodingParams.h:66
TileProcessor * tileProcessor_
Definition DecompressScheduler.h:51
#define SIZE_MAX
Definition MemManager.cpp:29
TileProcessor * tileProcessor
Definition PacketManager.h:100
uint16_t compno_
Definition PacketParser.h:47
#define GRK_RESTRICT
uint32_t numres_
Definition TileProcessor.h:62
Scheduler * scheduler_
Definition TileProcessor.h:156
grk_buf2d_simple< T > winLL
Definition WaveletReverse.h:48
grk_line32 win_l
Definition WaveletReverse.h:125
dwt_data< vec4f > horizF_
Definition WaveletReverse.h:218
dwt_data< vec4f > vertF_
Definition WaveletReverse.h:219
T * mem
Definition WaveletReverse.h:119
uint32_t lenMax
Definition WaveletReverse.h:136
size_t paddingBytes_
Definition WaveletReverse.h:118
dwt_data< int32_t > vert_
Definition WaveletReverse.h:216
T * memH
Definition WaveletReverse.h:121
grk_buf2d_simple< T > winHL
Definition WaveletReverse.h:49
uint8_t qmfbid_
Definition WaveletReverse.h:213
uint32_t parity
Definition WaveletReverse.h:124
grk_buf2d_simple< T > winLH
Definition WaveletReverse.h:50
uint32_t indexMin_
Definition WaveletReverse.h:54
std::vector< TaskInfo< vec4f, dwt_data< vec4f > > * > tasksF_
Definition WaveletReverse.h:221
T * memL
Definition WaveletReverse.h:120
grk_buf2d_simple< T > winDest
Definition WaveletReverse.h:52
std::vector< TaskInfo< int32_t, dwt_data< int32_t > > * > tasks_
Definition WaveletReverse.h:222
size_t lenBytes_
Definition WaveletReverse.h:117
grk_rect32 unreducedWindow_
Definition WaveletReverse.h:211
uint32_t indexMax_
Definition WaveletReverse.h:55
grk_line32 win_h
Definition WaveletReverse.h:126
T * allocatedMem
Definition WaveletReverse.h:116
TileComponent * tilec_
Definition WaveletReverse.h:209
grk_buf2d_simple< T > winHH
Definition WaveletReverse.h:51
uint32_t dn_full
Definition WaveletReverse.h:123
dwt_data< int32_t > horiz_
Definition WaveletReverse.h:215
uint32_t sn_full
Definition WaveletReverse.h:122
vec4f * dataPrev
Definition WaveletReverse.h:133
uint32_t c
temporary buffer where bits are coded or decoded
Definition mqc.h:46
grk_rect< uint32_t > grk_rect32
Definition TileCache.h:61
void GRK_ERROR(const char *fmt,...)
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
uint32_t grk_make_aligned_width(uint32_t width)
Definition MemManager.cpp:35
vec< float, 4 > vec4f
Definition WaveletReverse.h:29
constexpr T getHorizontalPassHeight(bool lossless)
Definition WaveletReverse.h:61
void * grk_aligned_malloc(size_t size)
Allocate memory aligned to a 16 byte boundary.
Definition MemManager.cpp:76
uint32_t max_resolution(Resolution *GRK_RESTRICT r, uint32_t i)
void grk_aligned_free(void *ptr)
Definition MemManager.cpp:80
d
Definition rvv-inl.h:1998
uint16_t compno
Definition plugin_interface.h:43