Grok 12.0.1
WaveletReverse.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
24#include <cstdint>
25
26namespace grk
27{
28
30
31template<typename T, typename S>
57
59
60template<class T>
62{
63 return T(lossless ? 1 : vec4f::NUM_ELTS);
64}
65
66template<typename T>
68{
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 Logger::logger_.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 Logger::logger_.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 */
128};
129
138
140{
141 public:
142 WaveletReverse(TileProcessor* tileProcessor, TileComponent* tilec, uint16_t compno,
145 bool decompress(void);
146
148
149 private:
150 template<typename T, uint32_t FILTER_WIDTH, uint32_t VERT_PASS_WIDTH, typename D>
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
177 const uint32_t wL, int32_t* bandH, const uint32_t wH,
178 int32_t* dest);
180 const uint32_t wL, int32_t* bandH, const uint32_t wH,
181 int32_t* dest);
183 const uint32_t strideL, int32_t* bandH, const uint32_t hH,
185 const uint32_t strideDest);
187 const uint32_t strideL, int32_t* bandH, const uint32_t hH,
189 const uint32_t strideDest);
191 int32_t* dest);
199 size_t dataLength);
204 size_t dataLength);
206
214
217
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
#define SIZE_MAX
Definition MemManager.cpp:29
Definition SparseCanvas.h:39
Definition Scheduler.h:22
Definition WaveletReverse.h:140
uint16_t compno_
Definition WaveletReverse.h:210
void interleave_h_97(dwt_data< vec4f > *GRK_RESTRICT dwt, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, uint32_t remaining_height)
static void decompress_step_97(dwt_data< vec4f > *GRK_RESTRICT dwt)
bool decompress_partial_tile(ISparseCanvas *sa, std::vector< TaskInfo< T, dwt_data< T > > * > &tasks)
bool decompress_tile_53(void)
void decompress_v_53(const dwt_data< int32_t > *dwt, grk_buf2d_simple< int32_t > winL, grk_buf2d_simple< int32_t > winH, grk_buf2d_simple< int32_t > winDest, uint32_t nb_cols)
static void decompress_step1_97(const Params97 &d, const float c)
grk_rect32 unreducedWindow_
Definition WaveletReverse.h:211
uint8_t numres_
Definition WaveletReverse.h:212
bool decompress_v_53(uint8_t res, TileComponentWindow< int32_t > *buf, uint32_t resWidth, size_t dataLength)
static Params97 makeParams97(dwt_data< vec4f > *dwt, bool isBandL, bool step1)
void decompress_h_strip_97(dwt_data< vec4f > *GRK_RESTRICT horiz, const uint32_t resHeight, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, grk_buf2d_simple< float > winDest)
bool decompress_tile_97(void)
dwt_data< int32_t > horiz_
Definition WaveletReverse.h:215
bool decompress_h_53(uint8_t res, TileComponentWindow< int32_t > *buf, uint32_t resHeight, size_t dataLength)
uint8_t qmfbid_
Definition WaveletReverse.h:213
TileProcessor * tileProcessor_
Definition WaveletReverse.h:207
void interleave_v_97(dwt_data< vec4f > *GRK_RESTRICT dwt, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, uint32_t nb_elts_read)
void decompress_v_parity_even_53(int32_t *buf, int32_t *bandL, const uint32_t hL, const uint32_t strideL, int32_t *bandH, const uint32_t hH, const uint32_t strideH, int32_t *dest, const uint32_t strideDest)
bool decompress(void)
void decompress_v_strip_53(const dwt_data< int32_t > *vert, uint32_t wMin, uint32_t wMax, grk_buf2d_simple< int32_t > winL, grk_buf2d_simple< int32_t > winH, grk_buf2d_simple< int32_t > winDest)
dwt_data< vec4f > vertF_
Definition WaveletReverse.h:219
dwt_data< int32_t > vert_
Definition WaveletReverse.h:216
Scheduler * scheduler_
Definition WaveletReverse.h:208
void decompress_v_parity_odd_53(int32_t *buf, int32_t *bandL, const uint32_t hL, const uint32_t strideL, int32_t *bandH, const uint32_t hH, const uint32_t strideH, int32_t *dest, const uint32_t strideDest)
void decompress_h_parity_odd_53(int32_t *buf, int32_t *bandL, const uint32_t wL, int32_t *bandH, const uint32_t wH, int32_t *dest)
void decompress_h_parity_even_53(int32_t *buf, int32_t *bandL, const uint32_t wL, int32_t *bandH, const uint32_t wH, int32_t *dest)
std::vector< TaskInfo< int32_t, dwt_data< int32_t > > * > tasks_
Definition WaveletReverse.h:222
void decompress_h_strip_53(const dwt_data< int32_t > *horiz, uint32_t hMin, uint32_t hMax, grk_buf2d_simple< int32_t > winL, grk_buf2d_simple< int32_t > winH, grk_buf2d_simple< int32_t > winDest)
std::vector< TaskInfo< vec4f, dwt_data< vec4f > > * > tasksF_
Definition WaveletReverse.h:221
bool decompress_v_97(uint8_t res, uint32_t numThreads, size_t dataLength, dwt_data< vec4f > &GRK_RESTRICT vert, const uint32_t resWidth, const uint32_t resHeight, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, grk_buf2d_simple< float > winDest)
TileComponent * tilec_
Definition WaveletReverse.h:209
void decompress_h_53(const dwt_data< int32_t > *dwt, int32_t *bandL, int32_t *bandH, int32_t *dest)
WaveletReverse(TileProcessor *tileProcessor, TileComponent *tilec, uint16_t compno, grk_rect32 window, uint8_t numres, uint8_t qmfbid)
bool decompress_h_97(uint8_t res, uint32_t numThreads, size_t dataLength, dwt_data< vec4f > &GRK_RESTRICT horiz, const uint32_t resHeight, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, grk_buf2d_simple< float > winDest)
dwt_data< vec4f > horizF_
Definition WaveletReverse.h:218
void decompress_v_strip_97(dwt_data< vec4f > *GRK_RESTRICT vert, const uint32_t resWidth, const uint32_t resHeight, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, grk_buf2d_simple< float > winDest)
#define GRK_RESTRICT
Definition grk_includes.h:71
Copyright (C) 2016-2024 Grok Image Compression Inc.
Definition ICacheable.h:20
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
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
void error(const char *fmt,...) override
Definition Logger.h:53
static Logger logger_
Definition Logger.h:70
Definition WaveletReverse.h:131
uint32_t lenMax
Definition WaveletReverse.h:136
Params97(void)
Definition WaveletReverse.h:132
vec4f * data
Definition WaveletReverse.h:134
vec4f * dataPrev
Definition WaveletReverse.h:133
uint32_t len
Definition WaveletReverse.h:135
Definition Resolution.h:25
Definition WaveletReverse.h:33
grk_buf2d_simple< T > winHL
Definition WaveletReverse.h:49
uint32_t indexMax_
Definition WaveletReverse.h:55
uint32_t indexMin_
Definition WaveletReverse.h:54
S data
Definition WaveletReverse.h:47
~TaskInfo(void)
Definition WaveletReverse.h:43
grk_buf2d_simple< T > winLH
Definition WaveletReverse.h:50
grk_buf2d_simple< T > winDest
Definition WaveletReverse.h:52
TaskInfo(S data, grk_buf2d_simple< T > winLL, grk_buf2d_simple< T > winHL, grk_buf2d_simple< T > winLH, grk_buf2d_simple< T > winHH, grk_buf2d_simple< T > winDest, uint32_t indexMin, uint32_t indexMax)
Definition WaveletReverse.h:34
grk_buf2d_simple< T > winHH
Definition WaveletReverse.h:51
grk_buf2d_simple< T > winLL
Definition WaveletReverse.h:48
TaskInfo(S data, uint32_t indexMin, uint32_t indexMax)
Definition WaveletReverse.h:40
Definition TileComponent.h:28
Definition TileComponentWindow.h:160
Definition TileProcessor.h:78
Definition WaveletReverse.h:68
~dwt_data(void)
Definition WaveletReverse.h:78
T * mem
Definition WaveletReverse.h:119
bool alloc(size_t len)
Definition WaveletReverse.h:82
uint32_t dn_full
Definition WaveletReverse.h:123
uint8_t resno
Definition WaveletReverse.h:127
dwt_data(const dwt_data &rhs)
Definition WaveletReverse.h:73
uint32_t parity
Definition WaveletReverse.h:124
grk_line32 win_h
Definition WaveletReverse.h:126
T * allocatedMem
Definition WaveletReverse.h:116
bool alloc(size_t len, size_t padding)
Definition WaveletReverse.h:86
uint32_t sn_full
Definition WaveletReverse.h:122
grk_line32 win_l
Definition WaveletReverse.h:125
void release(void)
Definition WaveletReverse.h:108
size_t paddingBytes_
Definition WaveletReverse.h:118
dwt_data(void)
Definition WaveletReverse.h:69
T * memH
Definition WaveletReverse.h:121
size_t lenBytes_
Definition WaveletReverse.h:117
T * memL
Definition WaveletReverse.h:120
Definition buffer.h:206
Definition WaveletCommon.h:26
static constexpr size_t NUM_ELTS
Definition WaveletCommon.h:64