WaveletReverse.h
Go to the documentation of this file.
/*
* Copyright (C) 2016-2023 Grok Image Compression Inc.
*
* This source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* This source code incorporates work covered by the BSD 2-clause license.
* Please see the LICENSE file in the root directory for details.
*
*/
#pragma once
#include <cstdint>
namespace grk
{
typedef vec<float, 4> vec4f;
template<typename T, typename S>
struct TaskInfo
{
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)
: data(data), winLL(winLL), winHL(winHL), winLH(winLH), winHH(winHH), winDest(winDest),
indexMin_(indexMin), indexMax_(indexMax)
{}
TaskInfo(S data, uint32_t indexMin, uint32_t indexMax)
: data(data), indexMin_(indexMin), indexMax_(indexMax)
{}
~TaskInfo(void)
{
data.release();
}
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_;
};
uint32_t max_resolution(Resolution* GRK_RESTRICT r, uint32_t i);
template<class T>
constexpr T getHorizontalPassHeight(bool lossless)
{
return T(lossless ? 1 : vec4f::NUM_ELTS);
}
template<typename T>
struct dwt_data
{
dwt_data(void)
: allocatedMem(nullptr), lenBytes_(0), paddingBytes_(0), mem(nullptr), memL(nullptr),
memH(nullptr), sn_full(0), dn_full(0), parity(0), resno(0)
{}
dwt_data(const dwt_data& rhs)
: allocatedMem(nullptr), lenBytes_(0), paddingBytes_(0), mem(nullptr), memL(nullptr),
memH(nullptr), sn_full(rhs.sn_full), dn_full(rhs.dn_full), parity(rhs.parity),
win_l(rhs.win_l), win_h(rhs.win_h), resno(rhs.resno)
{}
~dwt_data(void)
{
release();
}
bool alloc(size_t len)
{
return alloc(len, 0);
}
bool alloc(size_t len, size_t padding)
{
release();
/* overflow check */
if(len > (SIZE_MAX / sizeof(T)))
{
GRK_ERROR("data size overflow");
return false;
}
paddingBytes_ = grk_make_aligned_width((uint32_t)padding * 2 + 32) * sizeof(T);
lenBytes_ = len * sizeof(T) + 2 * paddingBytes_;
allocatedMem = (T*)grk_aligned_malloc(lenBytes_);
if(!allocatedMem)
{
GRK_ERROR("Failed to allocate %u bytes", lenBytes_);
return false;
}
mem = allocatedMem + paddingBytes_ / sizeof(T);
return (allocatedMem != nullptr) ? true : false;
}
void release(void)
{
grk_aligned_free(allocatedMem);
allocatedMem = nullptr;
mem = nullptr;
memL = nullptr;
memH = nullptr;
}
T* allocatedMem;
size_t lenBytes_;
size_t paddingBytes_;
T* mem;
T* memL;
T* memH;
uint32_t sn_full; /* number of elements in low pass band */
uint32_t dn_full; /* number of elements in high pass band */
uint32_t parity; /* 0 = start on even coord, 1 = start on odd coord */
grk_line32 win_l;
grk_line32 win_h;
uint8_t resno;
};
struct Params97
{
Params97(void) : dataPrev(nullptr), data(nullptr), len(0), lenMax(0) {}
vec4f* dataPrev;
vec4f* data;
uint32_t len;
uint32_t lenMax;
};
class WaveletReverse
{
public:
WaveletReverse(TileProcessor* tileProcessor, TileComponent* tilec, uint16_t compno,
grk_rect32 window, uint8_t numres, uint8_t qmfbid);
~WaveletReverse(void);
bool decompress(void);
static void decompress_step_97(dwt_data<vec4f>* GRK_RESTRICT dwt);
private:
template<typename T, uint32_t FILTER_WIDTH, uint32_t VERT_PASS_WIDTH, typename D>
bool decompress_partial_tile(ISparseCanvas* sa, std::vector<TaskInfo<T, dwt_data<T>>*>& tasks);
static void decompress_step1_97(const Params97& d, const float c);
#ifdef __SSE__
static void decompress_step1_sse_97(Params97 d, const __m128 c);
#endif
static Params97 makeParams97(dwt_data<vec4f>* dwt, bool isBandL, bool step1);
void interleave_h_97(dwt_data<vec4f>* GRK_RESTRICT dwt, grk_buf2d_simple<float> winL,
grk_buf2d_simple<float> winH, uint32_t remaining_height);
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_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);
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_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);
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_tile_97(void);
void decompress_h_parity_even_53(int32_t* buf, int32_t* bandL, /* even */
const uint32_t wL, int32_t* bandH, const uint32_t wH,
int32_t* dest);
void decompress_h_parity_odd_53(int32_t* buf, int32_t* bandL, /* odd */
const uint32_t wL, int32_t* bandH, const uint32_t wH,
int32_t* dest);
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);
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_53(const dwt_data<int32_t>* dwt, int32_t* bandL, int32_t* bandH,
int32_t* dest);
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);
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_h_53(uint8_t res, TileComponentWindow<int32_t>* buf, uint32_t resHeight,
size_t dataLength);
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);
bool decompress_v_53(uint8_t res, TileComponentWindow<int32_t>* buf, uint32_t resWidth,
size_t dataLength);
bool decompress_tile_53(void);
TileProcessor* tileProcessor_;
Scheduler* scheduler_;
TileComponent* tilec_;
uint16_t compno_;
grk_rect32 unreducedWindow_;
uint8_t numres_;
uint8_t qmfbid_;
dwt_data<int32_t> horiz_;
dwt_data<int32_t> vert_;
dwt_data<vec4f> horizF_;
dwt_data<vec4f> vertF_;
std::vector<TaskInfo<vec4f, dwt_data<vec4f>>*> tasksF_;
std::vector<TaskInfo<int32_t, dwt_data<int32_t>>*> tasks_;
};
} // namespace grk
SIZE_MAX
#define SIZE_MAX
Definition MemManager.cpp:29
grk::ISparseCanvas
Definition SparseCanvas.h:39
grk::Scheduler
Definition Scheduler.h:22
grk::WaveletReverse
Definition WaveletReverse.h:140
grk::WaveletReverse::compno_
uint16_t compno_
Definition WaveletReverse.h:210
grk::WaveletReverse::interleave_h_97
void interleave_h_97(dwt_data< vec4f > *GRK_RESTRICT dwt, grk_buf2d_simple< float > winL, grk_buf2d_simple< float > winH, uint32_t remaining_height)
grk::WaveletReverse::decompress_step_97
static void decompress_step_97(dwt_data< vec4f > *GRK_RESTRICT dwt)
grk::WaveletReverse::decompress_partial_tile
bool decompress_partial_tile(ISparseCanvas *sa, std::vector< TaskInfo< T, dwt_data< T > > * > &tasks)
grk::WaveletReverse::decompress_tile_53
bool decompress_tile_53(void)
grk::WaveletReverse::decompress_v_53
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)
grk::WaveletReverse::decompress_step1_97
static void decompress_step1_97(const Params97 &d, const float c)
grk::WaveletReverse::unreducedWindow_
grk_rect32 unreducedWindow_
Definition WaveletReverse.h:211
grk::WaveletReverse::numres_
uint8_t numres_
Definition WaveletReverse.h:212
grk::WaveletReverse::decompress_v_53
bool decompress_v_53(uint8_t res, TileComponentWindow< int32_t > *buf, uint32_t resWidth, size_t dataLength)
grk::WaveletReverse::makeParams97
static Params97 makeParams97(dwt_data< vec4f > *dwt, bool isBandL, bool step1)
grk::WaveletReverse::decompress_h_strip_97
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)
grk::WaveletReverse::decompress_tile_97
bool decompress_tile_97(void)
grk::WaveletReverse::horiz_
dwt_data< int32_t > horiz_
Definition WaveletReverse.h:215
grk::WaveletReverse::decompress_h_53
bool decompress_h_53(uint8_t res, TileComponentWindow< int32_t > *buf, uint32_t resHeight, size_t dataLength)
grk::WaveletReverse::qmfbid_
uint8_t qmfbid_
Definition WaveletReverse.h:213
grk::WaveletReverse::tileProcessor_
TileProcessor * tileProcessor_
Definition WaveletReverse.h:207
grk::WaveletReverse::interleave_v_97
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)
grk::WaveletReverse::decompress_v_parity_even_53
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)
grk::WaveletReverse::decompress
bool decompress(void)
grk::WaveletReverse::decompress_v_strip_53
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)
grk::WaveletReverse::vertF_
dwt_data< vec4f > vertF_
Definition WaveletReverse.h:219
grk::WaveletReverse::vert_
dwt_data< int32_t > vert_
Definition WaveletReverse.h:216
grk::WaveletReverse::scheduler_
Scheduler * scheduler_
Definition WaveletReverse.h:208
grk::WaveletReverse::~WaveletReverse
~WaveletReverse(void)
grk::WaveletReverse::decompress_v_parity_odd_53
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)
grk::WaveletReverse::decompress_h_parity_odd_53
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)
grk::WaveletReverse::decompress_h_parity_even_53
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::WaveletReverse::tasks_
std::vector< TaskInfo< int32_t, dwt_data< int32_t > > * > tasks_
Definition WaveletReverse.h:222
grk::WaveletReverse::decompress_h_strip_53
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)
grk::WaveletReverse::tasksF_
std::vector< TaskInfo< vec4f, dwt_data< vec4f > > * > tasksF_
Definition WaveletReverse.h:221
grk::WaveletReverse::decompress_v_97
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)
grk::WaveletReverse::tilec_
TileComponent * tilec_
Definition WaveletReverse.h:209
grk::WaveletReverse::decompress_h_53
void decompress_h_53(const dwt_data< int32_t > *dwt, int32_t *bandL, int32_t *bandH, int32_t *dest)
grk::WaveletReverse::WaveletReverse
WaveletReverse(TileProcessor *tileProcessor, TileComponent *tilec, uint16_t compno, grk_rect32 window, uint8_t numres, uint8_t qmfbid)
grk::WaveletReverse::decompress_h_97
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)
grk::WaveletReverse::horizF_
dwt_data< vec4f > horizF_
Definition WaveletReverse.h:218
grk::WaveletReverse::decompress_v_strip_97
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)
GRK_RESTRICT
#define GRK_RESTRICT
Definition grk_includes.h:71
grk
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
grk::grk_read
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
grk::grk_make_aligned_width
uint32_t grk_make_aligned_width(uint32_t width)
Definition MemManager.cpp:35
grk::GRK_ERROR
void GRK_ERROR(const char *fmt,...)
Definition logger.cpp:58
grk::vec4f
vec< float, 4 > vec4f
Definition WaveletReverse.h:29
grk::getHorizontalPassHeight
constexpr T getHorizontalPassHeight(bool lossless)
Definition WaveletReverse.h:61
grk::grk_aligned_malloc
void * grk_aligned_malloc(size_t size)
Allocate memory aligned to a 16 byte boundary.
Definition MemManager.cpp:76
grk::max_resolution
uint32_t max_resolution(Resolution *GRK_RESTRICT r, uint32_t i)
grk::grk_aligned_free
void grk_aligned_free(void *ptr)
Definition MemManager.cpp:80
grk::Params97
Definition WaveletReverse.h:131
grk::Params97::lenMax
uint32_t lenMax
Definition WaveletReverse.h:136
grk::Params97::Params97
Params97(void)
Definition WaveletReverse.h:132
grk::Params97::data
vec4f * data
Definition WaveletReverse.h:134
grk::Params97::dataPrev
vec4f * dataPrev
Definition WaveletReverse.h:133
grk::Params97::len
uint32_t len
Definition WaveletReverse.h:135
grk::Resolution
Definition Resolution.h:25
grk::TaskInfo
Definition WaveletReverse.h:33
grk::TaskInfo::winHL
grk_buf2d_simple< T > winHL
Definition WaveletReverse.h:49
grk::TaskInfo::indexMax_
uint32_t indexMax_
Definition WaveletReverse.h:55
grk::TaskInfo::indexMin_
uint32_t indexMin_
Definition WaveletReverse.h:54
grk::TaskInfo::data
S data
Definition WaveletReverse.h:47
grk::TaskInfo::~TaskInfo
~TaskInfo(void)
Definition WaveletReverse.h:43
grk::TaskInfo::winLH
grk_buf2d_simple< T > winLH
Definition WaveletReverse.h:50
grk::TaskInfo::winDest
grk_buf2d_simple< T > winDest
Definition WaveletReverse.h:52
grk::TaskInfo::TaskInfo
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::TaskInfo::winHH
grk_buf2d_simple< T > winHH
Definition WaveletReverse.h:51
grk::TaskInfo::winLL
grk_buf2d_simple< T > winLL
Definition WaveletReverse.h:48
grk::TaskInfo::TaskInfo
TaskInfo(S data, uint32_t indexMin, uint32_t indexMax)
Definition WaveletReverse.h:40
grk::TileComponent
Definition TileComponent.h:28
grk::TileComponentWindow
Definition TileComponentWindow.h:160
grk::TileProcessor
Definition TileProcessor.h:78
grk::dwt_data
Definition WaveletReverse.h:68
grk::dwt_data::~dwt_data
~dwt_data(void)
Definition WaveletReverse.h:78
grk::dwt_data::mem
T * mem
Definition WaveletReverse.h:119
grk::dwt_data::alloc
bool alloc(size_t len)
Definition WaveletReverse.h:82
grk::dwt_data::dn_full
uint32_t dn_full
Definition WaveletReverse.h:123
grk::dwt_data::resno
uint8_t resno
Definition WaveletReverse.h:127
grk::dwt_data::dwt_data
dwt_data(const dwt_data &rhs)
Definition WaveletReverse.h:73
grk::dwt_data::parity
uint32_t parity
Definition WaveletReverse.h:124
grk::dwt_data::win_h
grk_line32 win_h
Definition WaveletReverse.h:126
grk::dwt_data::allocatedMem
T * allocatedMem
Definition WaveletReverse.h:116
grk::dwt_data::alloc
bool alloc(size_t len, size_t padding)
Definition WaveletReverse.h:86
grk::dwt_data::sn_full
uint32_t sn_full
Definition WaveletReverse.h:122
grk::dwt_data::win_l
grk_line32 win_l
Definition WaveletReverse.h:125
grk::dwt_data::release
void release(void)
Definition WaveletReverse.h:108
grk::dwt_data::paddingBytes_
size_t paddingBytes_
Definition WaveletReverse.h:118
grk::dwt_data::dwt_data
dwt_data(void)
Definition WaveletReverse.h:69
grk::dwt_data::memH
T * memH
Definition WaveletReverse.h:121
grk::dwt_data::lenBytes_
size_t lenBytes_
Definition WaveletReverse.h:117
grk::dwt_data::memL
T * memL
Definition WaveletReverse.h:120
grk::grk_buf2d_simple
Definition buffer.h:206
grk::grk_line< uint32_t >
grk::grk_rect< uint32_t >
grk::vec
Definition WaveletCommon.h:26
grk::vec::NUM_ELTS
static constexpr size_t NUM_ELTS
Definition WaveletCommon.h:64