Grok  10.0.3
WaveletReverse.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2022 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 
26 namespace grk
27 {
28 
30 
31 template<typename T, typename S>
32 struct TaskInfo
33 {
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  }
47  S data;
53 
54  uint32_t indexMin_;
55  uint32_t indexMax_;
56 };
57 
58 uint32_t max_resolution(Resolution* GRK_RESTRICT r, uint32_t i);
59 
60 template<class T>
61 constexpr T getHorizontalPassHeight(bool lossless)
62 {
63  return T(lossless ? 1 : vec4f::NUM_ELTS);
64 }
65 
66 template<typename T>
67 struct 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;
120  T* memL;
121  T* memH;
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 */
127  uint8_t resno;
128 };
129 
130 struct Params97
131 {
132  Params97(void) : dataPrev(nullptr), data(nullptr), len(0), lenMax(0) {}
135  uint32_t len;
136  uint32_t lenMax;
137 };
138 
140 {
141  public:
142  WaveletReverse(TileProcessor* tileProcessor, TileComponent* tilec, uint16_t compno,
143  grk_rect32 window, uint8_t numres, uint8_t qmfbid);
145  bool decompress(void);
146 
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);
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,
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,
165  grk_buf2d_simple<float> winDest);
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,
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,
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);
194  uint32_t nb_cols);
195  void decompress_h_strip_53(const dwt_data<int32_t>* horiz, uint32_t hMin, uint32_t hMax,
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,
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 
210  uint16_t compno_;
212  uint8_t numres_;
213  uint8_t qmfbid_;
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_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)
bool decompress_partial_tile(ISparseCanvas *sa, std::vector< TaskInfo< T, dwt_data< T >> * > &tasks)
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-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
uint32_t grk_make_aligned_width(uint32_t width)
Definition: MemManager.cpp:35
void GRK_ERROR(const char *fmt,...)
Definition: logger.cpp:58
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:1742
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: 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
constexpr static size_t NUM_ELTS
Definition: WaveletCommon.h:64