Skip to content

Commit 39e5d15

Browse files
Merge branch 'aous72:master' into feature/add-32bit-tif-support
2 parents b7f9ea7 + 545acbd commit 39e5d15

16 files changed

+1533
-651
lines changed

src/core/codestream/ojph_codeblock_fun.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ namespace ojph {
276276
tx_from_cb64 = NULL;
277277
}
278278
encode_cb64 = ojph_encode_codeblock64;
279+
bool result = initialize_block_encoder_tables();
280+
assert(result); ojph_unused(result);
279281

280282
#endif // !OJPH_ENABLE_WASM_SIMD
281283

src/core/codestream/ojph_resolution.cpp

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,31 @@ namespace ojph {
207207

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

211213
ui32 width = res_rect.siz.w + 1;
212-
if (precision <= 32) {
213-
for (ui32 i = 0; i < num_steps; ++i)
214+
if (reversible)
215+
{
216+
if (precision <= 32) {
217+
for (ui32 i = 0; i < num_steps; ++i)
218+
allocator->pre_alloc_data<si32>(width, 1);
214219
allocator->pre_alloc_data<si32>(width, 1);
215-
allocator->pre_alloc_data<si32>(width, 1);
216-
allocator->pre_alloc_data<si32>(width, 1);
220+
allocator->pre_alloc_data<si32>(width, 1);
221+
}
222+
else
223+
{
224+
for (ui32 i = 0; i < num_steps; ++i)
225+
allocator->pre_alloc_data<si64>(width, 1);
226+
allocator->pre_alloc_data<si64>(width, 1);
227+
allocator->pre_alloc_data<si64>(width, 1);
228+
}
217229
}
218-
else
219-
{
230+
else {
220231
for (ui32 i = 0; i < num_steps; ++i)
221-
allocator->pre_alloc_data<si64>(width, 1);
222-
allocator->pre_alloc_data<si64>(width, 1);
223-
allocator->pre_alloc_data<si64>(width, 1);
232+
allocator->pre_alloc_data<float>(width, 1);
233+
allocator->pre_alloc_data<float>(width, 1);
234+
allocator->pre_alloc_data<float>(width, 1);
224235
}
225236
}
226237
}
@@ -474,21 +485,38 @@ namespace ojph {
474485

475486
// initiate storage of line_buf
476487
ui32 width = res_rect.siz.w + 1;
477-
if (precision <= 32)
488+
if (this->reversible)
478489
{
479-
for (ui32 i = 0; i < num_steps; ++i)
480-
ssp[i].line->wrap(
490+
if (precision <= 32)
491+
{
492+
for (ui32 i = 0; i < num_steps; ++i)
493+
ssp[i].line->wrap(
494+
allocator->post_alloc_data<si32>(width, 1), width, 1);
495+
sig->line->wrap(
481496
allocator->post_alloc_data<si32>(width, 1), width, 1);
482-
sig->line->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
483-
aug->line->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
497+
aug->line->wrap(
498+
allocator->post_alloc_data<si32>(width, 1), width, 1);
499+
}
500+
else
501+
{
502+
for (ui32 i = 0; i < num_steps; ++i)
503+
ssp[i].line->wrap(
504+
allocator->post_alloc_data<si64>(width, 1), width, 1);
505+
sig->line->wrap(
506+
allocator->post_alloc_data<si64>(width, 1), width, 1);
507+
aug->line->wrap(
508+
allocator->post_alloc_data<si64>(width, 1), width, 1);
509+
}
484510
}
485-
else
511+
else
486512
{
487-
for (ui32 i = 0; i < num_steps; ++i)
488-
ssp[i].line->wrap(
489-
allocator->post_alloc_data<si64>(width, 1), width, 1);
490-
sig->line->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
491-
aug->line->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
513+
for (ui32 i = 0; i < num_steps; ++i)
514+
ssp[i].line->wrap(
515+
allocator->post_alloc_data<float>(width, 1), width, 1);
516+
sig->line->wrap(
517+
allocator->post_alloc_data<float>(width, 1), width, 1);
518+
aug->line->wrap(
519+
allocator->post_alloc_data<float>(width, 1), width, 1);
492520
}
493521

494522
cur_line = 0;

src/core/codestream/ojph_subband.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ namespace ojph {
9292

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

9698
for (ui32 i = 0; i < num_blocks.w; ++i)
9799
codeblock::pre_alloc(codestream, nominal, precision);
@@ -100,10 +102,15 @@ namespace ojph {
100102
allocator->pre_alloc_obj<line_buf>(1);
101103
//allocate line_buf
102104
ui32 width = band_rect.siz.w + 1;
103-
if (precision <= 32)
104-
allocator->pre_alloc_data<si32>(width, 1);
105+
if (reversible)
106+
{
107+
if (precision <= 32)
108+
allocator->pre_alloc_data<si32>(width, 1);
109+
else
110+
allocator->pre_alloc_data<si64>(width, 1);
111+
}
105112
else
106-
allocator->pre_alloc_data<si64>(width, 1);
113+
allocator->pre_alloc_data<float>(width, 1);
107114
}
108115

109116
//////////////////////////////////////////////////////////////////////////
@@ -201,10 +208,15 @@ namespace ojph {
201208
lines = allocator->post_alloc_obj<line_buf>(1);
202209
//allocate line_buf
203210
ui32 width = band_rect.siz.w + 1;
204-
if (precision <= 32)
205-
lines->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
211+
if (reversible)
212+
{
213+
if (precision <= 32)
214+
lines->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
215+
else
216+
lines->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
217+
}
206218
else
207-
lines->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);
219+
lines->wrap(allocator->post_alloc_data<float>(width, 1), width, 1);
208220
}
209221

210222
//////////////////////////////////////////////////////////////////////////

src/core/codestream/ojph_tile.cpp

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ namespace ojph {
122122
}
123123

124124
//allocate lines
125-
if (codestream->get_cod()->is_employing_color_transform())
125+
const param_cod* cdp = codestream->get_cod();
126+
if (cdp->is_employing_color_transform())
126127
{
127128
allocator->pre_alloc_obj<line_buf>(3);
128-
for (int i = 0; i < 3; ++i)
129-
allocator->pre_alloc_data<si32>(width, 0);
129+
if (cdp->access_atk()->is_reversible())
130+
for (int i = 0; i < 3; ++i)
131+
allocator->pre_alloc_data<si32>(width, 0);
132+
else
133+
for (int i = 0; i < 3; ++i)
134+
allocator->pre_alloc_data<float>(width, 0);
130135
}
131136
}
132137

@@ -230,8 +235,14 @@ namespace ojph {
230235
{
231236
num_lines = 3;
232237
lines = allocator->post_alloc_obj<line_buf>(num_lines);
233-
for (int i = 0; i < 3; ++i)
234-
lines[i].wrap(allocator->post_alloc_data<si32>(width, 0), width, 0);
238+
if (reversible)
239+
for (int i = 0; i < 3; ++i)
240+
lines[i].wrap(
241+
allocator->post_alloc_data<si32>(width, 0), width, 0);
242+
else
243+
for (int i = 0; i < 3; ++i)
244+
lines[i].wrap(
245+
allocator->post_alloc_data<float>(width, 0), width, 0);
235246
}
236247
else
237248
{
@@ -273,13 +284,12 @@ namespace ojph {
273284
}
274285
else
275286
{
276-
float mul = 1.0f / (float)(1<<num_bits[comp_num]);
277-
const si32 *sp = line->i32 + line_offsets[comp_num];
278-
float *dp = tc->f32;
279-
if (is_signed[comp_num])
280-
cnvrt_si32_to_float(sp, dp, mul, comp_width);
287+
if (nlt_type3[comp_num] == type3)
288+
irv_convert_to_float_nlt_type3(line, line_offsets[comp_num],
289+
tc, num_bits[comp_num], is_signed[comp_num], comp_width);
281290
else
282-
cnvrt_si32_to_float_shftd(sp, dp, mul, comp_width);
291+
irv_convert_to_float(line, line_offsets[comp_num],
292+
tc, num_bits[comp_num], is_signed[comp_num], comp_width);
283293
}
284294
comps[comp_num].push_line();
285295
}
@@ -311,13 +321,14 @@ namespace ojph {
311321
}
312322
else
313323
{
314-
float mul = 1.0f / (float)(1<<num_bits[comp_num]);
315-
const si32 *sp = line->i32 + line_offsets[comp_num];
316-
float *dp = lines[comp_num].f32;
317-
if (is_signed[comp_num])
318-
cnvrt_si32_to_float(sp, dp, mul, comp_width);
324+
if (nlt_type3[comp_num] == type3)
325+
irv_convert_to_float_nlt_type3(line, line_offsets[comp_num],
326+
lines + comp_num, num_bits[comp_num], is_signed[comp_num],
327+
comp_width);
319328
else
320-
cnvrt_si32_to_float_shftd(sp, dp, mul, comp_width);
329+
irv_convert_to_float(line, line_offsets[comp_num],
330+
lines + comp_num, num_bits[comp_num], is_signed[comp_num],
331+
comp_width);
321332
if (comp_num == 2)
322333
{ // irreversible color transform
323334
ict_forward(lines[0].f32, lines[1].f32, lines[2].f32,
@@ -364,13 +375,14 @@ namespace ojph {
364375
}
365376
else
366377
{
367-
float mul = (float)(1 << num_bits[comp_num]);
368-
const float *sp = src_line->f32;
369-
si32 *dp = tgt_line->i32 + line_offsets[comp_num];
370-
if (is_signed[comp_num])
371-
cnvrt_float_to_si32(sp, dp, mul, comp_width);
378+
if (nlt_type3[comp_num] == type3)
379+
irv_convert_to_integer_nlt_type3(src_line, tgt_line,
380+
line_offsets[comp_num], num_bits[comp_num],
381+
is_signed[comp_num], comp_width);
372382
else
373-
cnvrt_float_to_si32_shftd(sp, dp, mul, comp_width);
383+
irv_convert_to_integer(src_line, tgt_line,
384+
line_offsets[comp_num], num_bits[comp_num],
385+
is_signed[comp_num], comp_width);
374386
}
375387
}
376388
else
@@ -407,17 +419,19 @@ namespace ojph {
407419
}
408420
else
409421
{
410-
float mul = (float)(1 << num_bits[comp_num]);
411-
const float *sp;
422+
line_buf* lbp;
412423
if (comp_num < 3)
413-
sp = lines[comp_num].f32;
424+
lbp = lines + comp_num;
414425
else
415-
sp = comps[comp_num].pull_line()->f32;
416-
si32 *dp = tgt_line->i32 + line_offsets[comp_num];
417-
if (is_signed[comp_num])
418-
cnvrt_float_to_si32(sp, dp, mul, comp_width);
426+
lbp = comps[comp_num].pull_line();
427+
if (nlt_type3[comp_num] == type3)
428+
irv_convert_to_integer_nlt_type3(lbp, tgt_line,
429+
line_offsets[comp_num], num_bits[comp_num],
430+
is_signed[comp_num], comp_width);
419431
else
420-
cnvrt_float_to_si32_shftd(sp, dp, mul, comp_width);
432+
irv_convert_to_integer(lbp, tgt_line,
433+
line_offsets[comp_num], num_bits[comp_num],
434+
is_signed[comp_num], comp_width);
421435
}
422436
}
423437

src/core/common/ojph_mem.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,18 @@ namespace ojph {
138138
enum : ui32 {
139139
LFT_UNDEFINED = 0x00, // Type is undefined/uninitialized
140140
// These flags reflects data size in bytes
141-
LFT_BYTE = 0x01, // Set when data is 1 byte
142-
LFT_16BIT = 0x02, // Set when data is 2 bytes
141+
LFT_BYTE = 0x01, // Set when data is 1 byte (not used)
142+
LFT_16BIT = 0x02, // Set when data is 2 bytes (not used)
143143
LFT_32BIT = 0x04, // Set when data is 4 bytes
144144
LFT_64BIT = 0x08, // Set when data is 8 bytes
145-
LFT_REVERSIBLE = 0x10, // Set when data is used for reversible coding
146-
// Not all combinations are useful
145+
LFT_INTEGER = 0x10, // Set when data is an integer, in other words
146+
// 32bit integer, not 32bit float
147147
LFT_SIZE_MASK = 0x0F, // To extract data size
148148
};
149149

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

153-
template<typename T>
154-
void pre_alloc(mem_fixed_allocator *p, size_t num_ele, ui32 pre_size)
155-
{
156-
memset(this, 0, sizeof(line_buf));
157-
p->pre_alloc_data<T>(num_ele, pre_size);
158-
size = num_ele;
159-
this->pre_size = pre_size;
160-
}
161-
162-
template<typename T>
163-
void finalize_alloc(mem_fixed_allocator *p);
164-
165153
template<typename T>
166154
void wrap(T *buffer, size_t num_ele, ui32 pre_size);
167155

src/core/common/ojph_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535

3636
#define OPENJPH_VERSION_MAJOR 0
3737
#define OPENJPH_VERSION_MINOR 19
38-
#define OPENJPH_VERSION_PATCH 0
38+
#define OPENJPH_VERSION_PATCH 1

src/core/others/ojph_mem.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,14 @@ namespace ojph {
4949
//
5050
////////////////////////////////////////////////////////////////////////////
5151

52-
////////////////////////////////////////////////////////////////////////////
53-
template<>
54-
void line_buf::finalize_alloc<si32>(mem_fixed_allocator *p)
55-
{
56-
assert(p != 0 && size != 0);
57-
i32 = p->post_alloc_data<si32>(size, pre_size);
58-
}
59-
60-
////////////////////////////////////////////////////////////////////////////
61-
template<>
62-
void line_buf::finalize_alloc<float>(mem_fixed_allocator *p)
63-
{
64-
assert(p != 0 && size != 0);
65-
f32 = p->post_alloc_data<float>(size, pre_size);
66-
}
67-
68-
////////////////////////////////////////////////////////////////////////////
69-
template<>
70-
void line_buf::finalize_alloc<si64>(mem_fixed_allocator *p)
71-
{
72-
assert(p != 0 && size != 0);
73-
i64 = p->post_alloc_data<si64>(size, pre_size);
74-
}
75-
7652
////////////////////////////////////////////////////////////////////////////
7753
template<>
7854
void line_buf::wrap(si32 *buffer, size_t num_ele, ui32 pre_size)
7955
{
8056
this->i32 = buffer;
8157
this->size = num_ele;
8258
this->pre_size = pre_size;
83-
this->flags = LFT_32BIT | LFT_REVERSIBLE;
59+
this->flags = LFT_32BIT | LFT_INTEGER;
8460
}
8561

8662
////////////////////////////////////////////////////////////////////////////
@@ -100,7 +76,7 @@ namespace ojph {
10076
this->i64 = buffer;
10177
this->size = num_ele;
10278
this->pre_size = pre_size;
103-
this->flags = LFT_64BIT | LFT_REVERSIBLE;
79+
this->flags = LFT_64BIT | LFT_INTEGER;
10480
}
10581

10682
////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)