Grok  9.7.5
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 struct vec4f
29 {
30  vec4f() : f{0} {}
31  explicit vec4f(float m)
32  {
33  f[0] = m;
34  f[1] = m;
35  f[2] = m;
36  f[3] = m;
37  }
38  float f[4];
39 };
40 
41 uint32_t max_resolution(Resolution* GRK_RESTRICT r, uint32_t i);
42 
43 template<class T>
44 constexpr T getHorizontalPassHeight(bool lossless)
45 {
46  return T(lossless ? (sizeof(int32_t) / sizeof(int32_t)) : (sizeof(vec4f) / sizeof(float)));
47 }
48 
49 template<typename T>
50 struct dwt_data
51 {
53  : allocatedMem(nullptr), lenBytes_(0), paddingBytes_(0), mem(nullptr), memL(nullptr),
54  memH(nullptr), sn_full(0), dn_full(0), parity(0), resno(0)
55  {}
56  dwt_data(const dwt_data& rhs)
57  : allocatedMem(nullptr), lenBytes_(0), paddingBytes_(0), mem(nullptr), memL(nullptr),
58  memH(nullptr), sn_full(rhs.sn_full), dn_full(rhs.dn_full), parity(rhs.parity),
59  win_l(rhs.win_l), win_h(rhs.win_h), resno(rhs.resno)
60  {}
62  {
63  release();
64  }
65  bool alloc(size_t len)
66  {
67  return alloc(len, 0);
68  }
69  bool alloc(size_t len, size_t padding)
70  {
71  release();
72 
73  /* overflow check */
74  if(len > (SIZE_MAX / sizeof(T)))
75  {
76  GRK_ERROR("data size overflow");
77  return false;
78  }
79  paddingBytes_ = grkMakeAlignedWidth((uint32_t)padding * 2 + 32) * sizeof(T);
80  lenBytes_ = len * sizeof(T) + 2 * paddingBytes_;
82  if(!allocatedMem)
83  {
84  GRK_ERROR("Failed to allocate %u bytes", lenBytes_);
85  return false;
86  }
87  mem = allocatedMem + paddingBytes_ / sizeof(T);
88 
89  return (allocatedMem != nullptr) ? true : false;
90  }
91  void release()
92  {
94  allocatedMem = nullptr;
95  mem = nullptr;
96  memL = nullptr;
97  memH = nullptr;
98  }
100  size_t lenBytes_;
102  T* mem;
103  T* memL;
104  T* memH;
105  uint32_t sn_full; /* number of elements in low pass band */
106  uint32_t dn_full; /* number of elements in high pass band */
107  uint32_t parity; /* 0 = start on even coord, 1 = start on odd coord */
110  uint8_t resno;
111 };
112 
113 struct Params97
114 {
115  Params97() : dataPrev(nullptr), data(nullptr), len(0), lenMax(0) {}
118  uint32_t len;
119  uint32_t lenMax;
120 };
121 
123 {
124  public:
125  WaveletReverse(TileProcessor* tileProcessor, TileComponent* tilec, uint16_t compno,
126  grk_rect32 window, uint8_t numres, uint8_t qmfbid);
127  bool decompress(void);
128 
130 
131  private:
132  template<typename T, uint32_t FILTER_WIDTH, uint32_t VERT_PASS_WIDTH, typename D>
134  static void decompress_step1_97(const Params97& d, const float c);
135 #ifdef __SSE__
136  static void decompress_step1_sse_97(Params97 d, const __m128 c);
137 #endif
138  static Params97 makeParams97(dwt_data<vec4f>* dwt, bool isBandL, bool step1);
140  grk_buf2d_simple<float> winH, uint32_t remaining_height);
141  void decompress_h_strip_97(dwt_data<vec4f>* GRK_RESTRICT horiz, const uint32_t resHeight,
143  grk_buf2d_simple<float> winDest);
144  bool decompress_h_97(uint8_t res, uint32_t numThreads, size_t dataLength,
145  dwt_data<vec4f>& GRK_RESTRICT horiz, const uint32_t resHeight,
147  grk_buf2d_simple<float> winDest);
149  grk_buf2d_simple<float> winH, uint32_t nb_elts_read);
150  void decompress_v_strip_97(dwt_data<vec4f>* GRK_RESTRICT vert, const uint32_t resWidth,
151  const uint32_t resHeight, grk_buf2d_simple<float> winL,
153  bool decompress_v_97(uint8_t res, uint32_t numThreads, size_t dataLength,
154  dwt_data<vec4f>& GRK_RESTRICT vert, const uint32_t resWidth,
155  const uint32_t resHeight, grk_buf2d_simple<float> winL,
157  bool decompress_tile_97(void);
158  void decompress_h_parity_even_53(int32_t* buf, int32_t* bandL, /* even */
159  const uint32_t wL, int32_t* bandH, const uint32_t wH,
160  int32_t* dest);
161  void decompress_h_parity_odd_53(int32_t* buf, int32_t* bandL, /* odd */
162  const uint32_t wL, int32_t* bandH, const uint32_t wH,
163  int32_t* dest);
164  void decompress_v_parity_even_53(int32_t* buf, int32_t* bandL, const uint32_t hL,
165  const uint32_t strideL, int32_t* bandH, const uint32_t hH,
166  const uint32_t strideH, int32_t* dest,
167  const uint32_t strideDest);
168  void decompress_v_parity_odd_53(int32_t* buf, int32_t* bandL, const uint32_t hL,
169  const uint32_t strideL, int32_t* bandH, const uint32_t hH,
170  const uint32_t strideH, int32_t* dest,
171  const uint32_t strideDest);
172  void decompress_h_53(const dwt_data<int32_t>* dwt, int32_t* bandL, int32_t* bandH,
173  int32_t* dest);
176  uint32_t nb_cols);
177  void decompress_h_strip_53(const dwt_data<int32_t>* horiz, uint32_t hMin, uint32_t hMax,
179  grk_buf2d_simple<int32_t> winDest);
180  bool decompress_h_53(uint8_t res, TileComponentWindowBuffer<int32_t>* buf, uint32_t resHeight,
181  size_t dataLength);
182  void decompress_v_strip_53(const dwt_data<int32_t>* vert, uint32_t wMin, uint32_t wMax,
184  grk_buf2d_simple<int32_t> winDest);
185  bool decompress_v_53(uint8_t res, TileComponentWindowBuffer<int32_t>* buf, uint32_t resWidth,
186  size_t dataLength);
187  bool decompress_tile_53(void);
188 
192  uint16_t compno_;
194  uint8_t numres_;
195  uint8_t qmfbid_;
196 
199 
202 };
203 
204 } // namespace grk
#define SIZE_MAX
Definition: MemManager.cpp:30
Definition: SparseCanvas.h:27
Definition: Scheduler.h:22
Definition: WaveletReverse.h:123
uint16_t compno_
Definition: WaveletReverse.h:192
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)
bool decompress_partial_tile(ISparseCanvas *sa)
uint8_t numres_
Definition: WaveletReverse.h:194
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:197
uint8_t qmfbid_
Definition: WaveletReverse.h:195
TileProcessor * tileProcessor_
Definition: WaveletReverse.h:189
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:201
dwt_data< int32_t > vert_
Definition: WaveletReverse.h:198
bool decompress_h_53(uint8_t res, TileComponentWindowBuffer< int32_t > *buf, uint32_t resHeight, size_t dataLength)
Scheduler * scheduler_
Definition: WaveletReverse.h:190
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)
grk_rect32 window_
Definition: WaveletReverse.h:193
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)
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)
bool decompress_v_53(uint8_t res, TileComponentWindowBuffer< int32_t > *buf, uint32_t resWidth, size_t dataLength)
TileComponent * tilec_
Definition: WaveletReverse.h:191
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:200
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:77
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
void grkAlignedFree(void *ptr)
Definition: MemManager.cpp:127
void GRK_ERROR(const char *fmt,...)
Definition: logger.cpp:58
constexpr T getHorizontalPassHeight(bool lossless)
Definition: WaveletReverse.h:44
void * grkAlignedMalloc(size_t size)
Allocate memory aligned to a 16 byte boundary.
Definition: MemManager.cpp:123
uint32_t max_resolution(Resolution *GRK_RESTRICT r, uint32_t i)
uint32_t grkMakeAlignedWidth(uint32_t width)
Definition: MemManager.cpp:40
d
Definition: rvv-inl.h:1656
Definition: WaveletReverse.h:114
Params97()
Definition: WaveletReverse.h:115
uint32_t lenMax
Definition: WaveletReverse.h:119
vec4f * data
Definition: WaveletReverse.h:117
vec4f * dataPrev
Definition: WaveletReverse.h:116
uint32_t len
Definition: WaveletReverse.h:118
Definition: Resolution.h:24
Definition: TileComponent.h:28
Tile processor for decompression and compression.
Definition: TileProcessor.h:76
Definition: WaveletReverse.h:51
void release()
Definition: WaveletReverse.h:91
T * mem
Definition: WaveletReverse.h:102
bool alloc(size_t len)
Definition: WaveletReverse.h:65
uint32_t dn_full
Definition: WaveletReverse.h:106
dwt_data()
Definition: WaveletReverse.h:52
uint8_t resno
Definition: WaveletReverse.h:110
dwt_data(const dwt_data &rhs)
Definition: WaveletReverse.h:56
uint32_t parity
Definition: WaveletReverse.h:107
grk_line32 win_h
Definition: WaveletReverse.h:109
T * allocatedMem
Definition: WaveletReverse.h:99
bool alloc(size_t len, size_t padding)
Definition: WaveletReverse.h:69
uint32_t sn_full
Definition: WaveletReverse.h:105
grk_line32 win_l
Definition: WaveletReverse.h:108
~dwt_data()
Definition: WaveletReverse.h:61
size_t paddingBytes_
Definition: WaveletReverse.h:101
T * memH
Definition: WaveletReverse.h:104
size_t lenBytes_
Definition: WaveletReverse.h:100
T * memL
Definition: WaveletReverse.h:103
Definition: MemManager.h:249
Definition: WaveletReverse.h:29
vec4f(float m)
Definition: WaveletReverse.h:31
float f[4]
Definition: WaveletReverse.h:38
vec4f()
Definition: WaveletReverse.h:30