PostT1DecompressFiltersOJPH.h
Go to the documentation of this file.
#pragma once
#include "grk_includes.h"
namespace ojph
{
template<typename T>
class RoiShiftOJPHFilter
{
public:
RoiShiftOJPHFilter(grk::DecompressBlockExec* block)
: roiShift(block->roishift), shift(31U - (block->k_msbs + 1U))
{}
inline void copy(T* dest, T* src, uint32_t len)
{
T thresh = 1 << roiShift;
for(uint32_t i = 0; i < len; ++i)
{
T val = src[i];
T mag = (val & 0x7FFFFFFF);
if(mag >= thresh)
val = (T)(((uint32_t)mag >> roiShift) & ((uint32_t)val & 0x80000000));
int32_t val_shifted = (val & 0x7FFFFFFF) >> shift;
dest[i] = (int32_t)(((uint32_t)val & 0x80000000) ? -val_shifted : val_shifted);
}
}
private:
uint32_t roiShift;
uint32_t shift;
};
template<typename T>
class ShiftOJPHFilter
{
public:
ShiftOJPHFilter(grk::DecompressBlockExec* block) : shift(31U - (block->k_msbs + 1U)) {}
inline void copy(T* dest, T* src, uint32_t len)
{
for(uint32_t i = 0; i < len; ++i)
{
T val = src[i];
T val_shifted = (val & 0x7FFFFFFF) >> shift;
dest[i] = (T)(((uint32_t)val & 0x80000000) ? -val_shifted : val_shifted);
}
}
private:
uint32_t shift;
};
template<typename T>
class RoiScaleOJPHFilter
{
public:
RoiScaleOJPHFilter(grk::DecompressBlockExec* block)
: roiShift(block->roishift),
scale(block->stepsize / (float)(1u << (31 - block->bandNumbps)))
{
assert(block->bandNumbps <= 31);
}
inline void copy(T* dest, T* src, uint32_t len)
{
T thresh = 1 << roiShift;
for(uint32_t i = 0; i < len; ++i)
{
T val = src[i];
T mag = (T)(val & 0x7FFFFFFF);
if(mag >= thresh)
val = (T)(((uint32_t)mag >> roiShift) & ((uint32_t)val & 0x80000000));
float val_scaled = (float)(val & 0x7FFFFFFF) * scale;
((float*)dest)[i] = ((uint32_t)val & 0x80000000) ? -val_scaled : val_scaled;
}
}
private:
uint32_t roiShift;
float scale;
};
template<typename T>
class ScaleOJPHFilter
{
public:
ScaleOJPHFilter(grk::DecompressBlockExec* block)
: scale(block->stepsize / (float)(1u << (31 - block->bandNumbps)))
{
assert(block->bandNumbps <= 31);
}
inline void copy(T* dest, T* src, uint32_t len)
{
for(uint32_t i = 0; i < len; ++i)
{
int32_t val = src[i];
float val_scaled = (float)(val & 0x7FFFFFFF) * scale;
((float*)dest)[i] = ((uint32_t)val & 0x80000000) ? -val_scaled : val_scaled;
}
}
private:
float scale;
};
} // namespace ojph
ojph::RoiScaleOJPHFilter
Definition PostT1DecompressFiltersOJPH.h:53
ojph::RoiScaleOJPHFilter::copy
void copy(T *dest, T *src, uint32_t len)
Definition PostT1DecompressFiltersOJPH.h:61
ojph::RoiScaleOJPHFilter::roiShift
uint32_t roiShift
Definition PostT1DecompressFiltersOJPH.h:76
ojph::RoiScaleOJPHFilter::scale
float scale
Definition PostT1DecompressFiltersOJPH.h:77
ojph::RoiScaleOJPHFilter::RoiScaleOJPHFilter
RoiScaleOJPHFilter(grk::DecompressBlockExec *block)
Definition PostT1DecompressFiltersOJPH.h:55
ojph::RoiShiftOJPHFilter
Definition PostT1DecompressFiltersOJPH.h:9
ojph::RoiShiftOJPHFilter::roiShift
uint32_t roiShift
Definition PostT1DecompressFiltersOJPH.h:29
ojph::RoiShiftOJPHFilter::shift
uint32_t shift
Definition PostT1DecompressFiltersOJPH.h:30
ojph::RoiShiftOJPHFilter::RoiShiftOJPHFilter
RoiShiftOJPHFilter(grk::DecompressBlockExec *block)
Definition PostT1DecompressFiltersOJPH.h:11
ojph::RoiShiftOJPHFilter::copy
void copy(T *dest, T *src, uint32_t len)
Definition PostT1DecompressFiltersOJPH.h:14
ojph::ScaleOJPHFilter
Definition PostT1DecompressFiltersOJPH.h:82
ojph::ScaleOJPHFilter::scale
float scale
Definition PostT1DecompressFiltersOJPH.h:100
ojph::ScaleOJPHFilter::copy
void copy(T *dest, T *src, uint32_t len)
Definition PostT1DecompressFiltersOJPH.h:89
ojph::ScaleOJPHFilter::ScaleOJPHFilter
ScaleOJPHFilter(grk::DecompressBlockExec *block)
Definition PostT1DecompressFiltersOJPH.h:84
ojph::ShiftOJPHFilter
Definition PostT1DecompressFiltersOJPH.h:34
ojph::ShiftOJPHFilter::copy
void copy(T *dest, T *src, uint32_t len)
Definition PostT1DecompressFiltersOJPH.h:37
ojph::ShiftOJPHFilter::ShiftOJPHFilter
ShiftOJPHFilter(grk::DecompressBlockExec *block)
Definition PostT1DecompressFiltersOJPH.h:36
ojph::ShiftOJPHFilter::shift
uint32_t shift
Definition PostT1DecompressFiltersOJPH.h:48
grk_includes.h
ojph
Definition ojph_block_common.cpp:48
grk::BlockExec::bandNumbps
uint8_t bandNumbps
Definition BlockExec.h:32
grk::DecompressBlockExec
Definition BlockExec.h:45