Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding NLT implementation to the lossy path #170

Merged
merged 20 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/codestream/ojph_codeblock_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ namespace ojph {
tx_from_cb64 = NULL;
}
encode_cb64 = ojph_encode_codeblock64;
bool result = initialize_block_encoder_tables();
assert(result); ojph_unused(result);

#endif // !OJPH_ENABLE_WASM_SIMD

Expand Down
68 changes: 48 additions & 20 deletions src/core/codestream/ojph_resolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,31 @@ namespace ojph {

const param_qcd* qp = codestream->access_qcd()->get_qcc(comp_num);
ui32 precision = qp->propose_precision(cdp);
const param_atk* atk = cdp->access_atk();
bool reversible = atk->is_reversible();

ui32 width = res_rect.siz.w + 1;
if (precision <= 32) {
for (ui32 i = 0; i < num_steps; ++i)
if (reversible)
{
if (precision <= 32) {
for (ui32 i = 0; i < num_steps; ++i)
allocator->pre_alloc_data<si32>(width, 1);
allocator->pre_alloc_data<si32>(width, 1);
allocator->pre_alloc_data<si32>(width, 1);
allocator->pre_alloc_data<si32>(width, 1);
allocator->pre_alloc_data<si32>(width, 1);
}
else
{
for (ui32 i = 0; i < num_steps; ++i)
allocator->pre_alloc_data<si64>(width, 1);
allocator->pre_alloc_data<si64>(width, 1);
allocator->pre_alloc_data<si64>(width, 1);
}
}
else
{
else {
for (ui32 i = 0; i < num_steps; ++i)
allocator->pre_alloc_data<si64>(width, 1);
allocator->pre_alloc_data<si64>(width, 1);
allocator->pre_alloc_data<si64>(width, 1);
allocator->pre_alloc_data<float>(width, 1);
allocator->pre_alloc_data<float>(width, 1);
allocator->pre_alloc_data<float>(width, 1);
}
}
}
Expand Down Expand Up @@ -474,21 +485,38 @@ namespace ojph {

// initiate storage of line_buf
ui32 width = res_rect.siz.w + 1;
if (precision <= 32)
if (this->reversible)
{
for (ui32 i = 0; i < num_steps; ++i)
ssp[i].line->wrap(
if (precision <= 32)
{
for (ui32 i = 0; i < num_steps; ++i)
ssp[i].line->wrap(
allocator->post_alloc_data<si32>(width, 1), width, 1);
sig->line->wrap(
allocator->post_alloc_data<si32>(width, 1), width, 1);
sig->line->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
aug->line->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
aug->line->wrap(
allocator->post_alloc_data<si32>(width, 1), width, 1);
}
else
{
for (ui32 i = 0; i < num_steps; ++i)
ssp[i].line->wrap(
allocator->post_alloc_data<si64>(width, 1), width, 1);
sig->line->wrap(
allocator->post_alloc_data<si64>(width, 1), width, 1);
aug->line->wrap(
allocator->post_alloc_data<si64>(width, 1), width, 1);
}
}
else
else
{
for (ui32 i = 0; i < num_steps; ++i)
ssp[i].line->wrap(
allocator->post_alloc_data<si64>(width, 1), width, 1);
sig->line->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
aug->line->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
for (ui32 i = 0; i < num_steps; ++i)
ssp[i].line->wrap(
allocator->post_alloc_data<float>(width, 1), width, 1);
sig->line->wrap(
allocator->post_alloc_data<float>(width, 1), width, 1);
aug->line->wrap(
allocator->post_alloc_data<float>(width, 1), width, 1);
}

cur_line = 0;
Expand Down
24 changes: 18 additions & 6 deletions src/core/codestream/ojph_subband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace ojph {

const param_qcd* qp = codestream->access_qcd()->get_qcc(comp_num);
ui32 precision = qp->propose_precision(cdp);
const param_atk* atk = cdp->access_atk();
bool reversible = atk->is_reversible();

for (ui32 i = 0; i < num_blocks.w; ++i)
codeblock::pre_alloc(codestream, nominal, precision);
Expand All @@ -100,10 +102,15 @@ namespace ojph {
allocator->pre_alloc_obj<line_buf>(1);
//allocate line_buf
ui32 width = band_rect.siz.w + 1;
if (precision <= 32)
allocator->pre_alloc_data<si32>(width, 1);
if (reversible)
{
if (precision <= 32)
allocator->pre_alloc_data<si32>(width, 1);
else
allocator->pre_alloc_data<si64>(width, 1);
}
else
allocator->pre_alloc_data<si64>(width, 1);
allocator->pre_alloc_data<float>(width, 1);
}

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -201,10 +208,15 @@ namespace ojph {
lines = allocator->post_alloc_obj<line_buf>(1);
//allocate line_buf
ui32 width = band_rect.siz.w + 1;
if (precision <= 32)
lines->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
if (reversible)
{
if (precision <= 32)
lines->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
else
lines->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
}
else
lines->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
lines->wrap(allocator->post_alloc_data<float>(width, 1), width, 1);
}

//////////////////////////////////////////////////////////////////////////
Expand Down
76 changes: 45 additions & 31 deletions src/core/codestream/ojph_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ namespace ojph {
}

//allocate lines
if (codestream->get_cod()->is_employing_color_transform())
const param_cod* cdp = codestream->get_cod();
if (cdp->is_employing_color_transform())
{
allocator->pre_alloc_obj<line_buf>(3);
for (int i = 0; i < 3; ++i)
allocator->pre_alloc_data<si32>(width, 0);
if (cdp->access_atk()->is_reversible())
for (int i = 0; i < 3; ++i)
allocator->pre_alloc_data<si32>(width, 0);
else
for (int i = 0; i < 3; ++i)
allocator->pre_alloc_data<float>(width, 0);
}
}

Expand Down Expand Up @@ -230,8 +235,14 @@ namespace ojph {
{
num_lines = 3;
lines = allocator->post_alloc_obj<line_buf>(num_lines);
for (int i = 0; i < 3; ++i)
lines[i].wrap(allocator->post_alloc_data<si32>(width, 0), width, 0);
if (reversible)
for (int i = 0; i < 3; ++i)
lines[i].wrap(
allocator->post_alloc_data<si32>(width, 0), width, 0);
else
for (int i = 0; i < 3; ++i)
lines[i].wrap(
allocator->post_alloc_data<float>(width, 0), width, 0);
}
else
{
Expand Down Expand Up @@ -273,13 +284,12 @@ namespace ojph {
}
else
{
float mul = 1.0f / (float)(1<<num_bits[comp_num]);
const si32 *sp = line->i32 + line_offsets[comp_num];
float *dp = tc->f32;
if (is_signed[comp_num])
cnvrt_si32_to_float(sp, dp, mul, comp_width);
if (nlt_type3[comp_num] == type3)
irv_convert_to_float_nlt_type3(line, line_offsets[comp_num],
tc, num_bits[comp_num], is_signed[comp_num], comp_width);
else
cnvrt_si32_to_float_shftd(sp, dp, mul, comp_width);
irv_convert_to_float(line, line_offsets[comp_num],
tc, num_bits[comp_num], is_signed[comp_num], comp_width);
}
comps[comp_num].push_line();
}
Expand Down Expand Up @@ -311,13 +321,14 @@ namespace ojph {
}
else
{
float mul = 1.0f / (float)(1<<num_bits[comp_num]);
const si32 *sp = line->i32 + line_offsets[comp_num];
float *dp = lines[comp_num].f32;
if (is_signed[comp_num])
cnvrt_si32_to_float(sp, dp, mul, comp_width);
if (nlt_type3[comp_num] == type3)
irv_convert_to_float_nlt_type3(line, line_offsets[comp_num],
lines + comp_num, num_bits[comp_num], is_signed[comp_num],
comp_width);
else
cnvrt_si32_to_float_shftd(sp, dp, mul, comp_width);
irv_convert_to_float(line, line_offsets[comp_num],
lines + comp_num, num_bits[comp_num], is_signed[comp_num],
comp_width);
if (comp_num == 2)
{ // irreversible color transform
ict_forward(lines[0].f32, lines[1].f32, lines[2].f32,
Expand Down Expand Up @@ -364,13 +375,14 @@ namespace ojph {
}
else
{
float mul = (float)(1 << num_bits[comp_num]);
const float *sp = src_line->f32;
si32 *dp = tgt_line->i32 + line_offsets[comp_num];
if (is_signed[comp_num])
cnvrt_float_to_si32(sp, dp, mul, comp_width);
if (nlt_type3[comp_num] == type3)
irv_convert_to_integer_nlt_type3(src_line, tgt_line,
line_offsets[comp_num], num_bits[comp_num],
is_signed[comp_num], comp_width);
else
cnvrt_float_to_si32_shftd(sp, dp, mul, comp_width);
irv_convert_to_integer(src_line, tgt_line,
line_offsets[comp_num], num_bits[comp_num],
is_signed[comp_num], comp_width);
}
}
else
Expand Down Expand Up @@ -407,17 +419,19 @@ namespace ojph {
}
else
{
float mul = (float)(1 << num_bits[comp_num]);
const float *sp;
line_buf* lbp;
if (comp_num < 3)
sp = lines[comp_num].f32;
lbp = lines + comp_num;
else
sp = comps[comp_num].pull_line()->f32;
si32 *dp = tgt_line->i32 + line_offsets[comp_num];
if (is_signed[comp_num])
cnvrt_float_to_si32(sp, dp, mul, comp_width);
lbp = comps[comp_num].pull_line();
if (nlt_type3[comp_num] == type3)
irv_convert_to_integer_nlt_type3(lbp, tgt_line,
line_offsets[comp_num], num_bits[comp_num],
is_signed[comp_num], comp_width);
else
cnvrt_float_to_si32_shftd(sp, dp, mul, comp_width);
irv_convert_to_integer(lbp, tgt_line,
line_offsets[comp_num], num_bits[comp_num],
is_signed[comp_num], comp_width);
}
}

Expand Down
20 changes: 4 additions & 16 deletions src/core/common/ojph_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,18 @@ namespace ojph {
enum : ui32 {
LFT_UNDEFINED = 0x00, // Type is undefined/uninitialized
// These flags reflects data size in bytes
LFT_BYTE = 0x01, // Set when data is 1 byte
LFT_16BIT = 0x02, // Set when data is 2 bytes
LFT_BYTE = 0x01, // Set when data is 1 byte (not used)
LFT_16BIT = 0x02, // Set when data is 2 bytes (not used)
LFT_32BIT = 0x04, // Set when data is 4 bytes
LFT_64BIT = 0x08, // Set when data is 8 bytes
LFT_REVERSIBLE = 0x10, // Set when data is used for reversible coding
// Not all combinations are useful
LFT_INTEGER = 0x10, // Set when data is an integer, in other words
// 32bit integer, not 32bit float
LFT_SIZE_MASK = 0x0F, // To extract data size
};

public:
line_buf() : size(0), pre_size(0), flags(LFT_UNDEFINED), i32(0) {}

template<typename T>
void pre_alloc(mem_fixed_allocator *p, size_t num_ele, ui32 pre_size)
{
memset(this, 0, sizeof(line_buf));
p->pre_alloc_data<T>(num_ele, pre_size);
size = num_ele;
this->pre_size = pre_size;
}

template<typename T>
void finalize_alloc(mem_fixed_allocator *p);

template<typename T>
void wrap(T *buffer, size_t num_ele, ui32 pre_size);

Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@

#define OPENJPH_VERSION_MAJOR 0
#define OPENJPH_VERSION_MINOR 19
#define OPENJPH_VERSION_PATCH 0
#define OPENJPH_VERSION_PATCH 1
28 changes: 2 additions & 26 deletions src/core/others/ojph_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,14 @@ namespace ojph {
//
////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
template<>
void line_buf::finalize_alloc<si32>(mem_fixed_allocator *p)
{
assert(p != 0 && size != 0);
i32 = p->post_alloc_data<si32>(size, pre_size);
}

////////////////////////////////////////////////////////////////////////////
template<>
void line_buf::finalize_alloc<float>(mem_fixed_allocator *p)
{
assert(p != 0 && size != 0);
f32 = p->post_alloc_data<float>(size, pre_size);
}

////////////////////////////////////////////////////////////////////////////
template<>
void line_buf::finalize_alloc<si64>(mem_fixed_allocator *p)
{
assert(p != 0 && size != 0);
i64 = p->post_alloc_data<si64>(size, pre_size);
}

////////////////////////////////////////////////////////////////////////////
template<>
void line_buf::wrap(si32 *buffer, size_t num_ele, ui32 pre_size)
{
this->i32 = buffer;
this->size = num_ele;
this->pre_size = pre_size;
this->flags = LFT_32BIT | LFT_REVERSIBLE;
this->flags = LFT_32BIT | LFT_INTEGER;
}

////////////////////////////////////////////////////////////////////////////
Expand All @@ -100,7 +76,7 @@ namespace ojph {
this->i64 = buffer;
this->size = num_ele;
this->pre_size = pre_size;
this->flags = LFT_64BIT | LFT_REVERSIBLE;
this->flags = LFT_64BIT | LFT_INTEGER;
}

////////////////////////////////////////////////////////////////////////////
Expand Down
Loading
Loading