Skip to content

Commit 995744c

Browse files
Merge branch 'aous72:master' into feature/add-32bit-tif-support
2 parents ce42434 + aed95f6 commit 995744c

File tree

15 files changed

+780
-373
lines changed

15 files changed

+780
-373
lines changed

src/apps/ojph_compress/ojph_compress.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,20 @@ int main(int argc, char * argv[]) {
834834

835835
ojph::param_nlt nlt = codestream.access_nlt();
836836
if (reversible) {
837+
// Note: Even if only ALL_COMPS is set to
838+
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
839+
// one ALL_COMPS NLT marker segment is needed, or multiple
840+
// per component NLT marker segments are needed (when the components
841+
// have different bit depths or signedness).
842+
// Of course for .pfm images all components should have the same
843+
// bit depth and signedness.
837844
if (all_the_same)
838-
nlt.set_type3_transformation(ojph::param_nlt::ALL_COMPS, true);
845+
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
846+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
839847
else
840848
for (ojph::ui32 c = 0; c < num_comps; ++c)
841-
nlt.set_type3_transformation(c, true);
849+
nlt.set_nonlinear_transform(c,
850+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
842851
}
843852
else
844853
OJPH_ERROR(0x01000093, "We currently support lossless only for "

src/apps/ojph_expand/ojph_expand.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ int main(int argc, char *argv[]) {
269269
}
270270
else if (is_matching(".pfm", v))
271271
{
272+
OJPH_INFO(0x02000011, "Note: The .pfm implementation is "
273+
"experimental. It is developed for me the test NLT marker segments. "
274+
"For this reason, I am restricting it to images that employ the "
275+
"NLT marker segment, with the assumption that original values are "
276+
"floating-point numbers.");
277+
272278
codestream.set_planar(false);
273279
ojph::param_siz siz = codestream.access_siz();
274280
ojph::param_cod cod = codestream.access_cod();
@@ -294,8 +300,10 @@ int main(int argc, char *argv[]) {
294300
for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c) {
295301
ojph::ui8 bd = 0;
296302
bool is = true;
297-
bool result = nlt.get_type3_transformation(c, bd, is);
298-
if (result == false)
303+
ojph::ui8 nl_type;
304+
bool result = nlt.get_nonlinear_transform(c, bd, is, nl_type);
305+
if (result == false ||
306+
nl_type != ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT)
299307
OJPH_ERROR(0x0200000E,
300308
"This codestream is not supported; it does not have an "
301309
"NLT segment marker for this component (or no default NLT "

src/core/codestream/ojph_codeblock.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ namespace ojph {
5353
{
5454

5555
//////////////////////////////////////////////////////////////////////////
56-
void codeblock::pre_alloc(codestream *codestream, ui32 comp_num,
57-
const size& nominal)
56+
void codeblock::pre_alloc(codestream *codestream, const size& nominal,
57+
ui32 precision)
5858
{
5959
mem_fixed_allocator* allocator = codestream->get_allocator();
6060

6161
assert(byte_alignment / sizeof(ui32) > 1);
6262
const ui32 f = byte_alignment / sizeof(ui32) - 1;
6363
ui32 stride = (nominal.w + f) & ~f; // a multiple of 8
64-
65-
const param_siz* sz = codestream->get_siz();
66-
const param_cod* cd = codestream->get_cod(comp_num);
67-
ui32 precision = cd->propose_precision(sz, comp_num);
64+
6865
if (precision <= 32)
6966
allocator->pre_alloc_data<ui32>(nominal.h * (size_t)stride, 0);
7067
else
@@ -76,24 +73,21 @@ namespace ojph {
7673
subband *parent, const size& nominal,
7774
const size& cb_size,
7875
coded_cb_header* coded_cb,
79-
ui32 K_max, int line_offset)
76+
ui32 K_max, int line_offset,
77+
ui32 precision)
8078
{
8179
mem_fixed_allocator* allocator = codestream->get_allocator();
8280

8381
const ui32 f = byte_alignment / sizeof(ui32) - 1;
8482
this->stride = (nominal.w + f) & ~f; // a multiple of 8
8583
this->buf_size = this->stride * nominal.h;
8684

87-
ui32 comp_num = parent->get_parent()->get_comp_num();
88-
const param_siz* sz = codestream->get_siz();
89-
const param_cod* cd = codestream->get_cod(comp_num);
90-
ui32 bit_depth = cd->propose_precision(sz, comp_num);
91-
if (bit_depth <= 32) {
92-
precision = BUF32;
85+
if (precision <= 32) {
86+
this->precision = BUF32;
9387
this->buf32 = allocator->post_alloc_data<ui32>(this->buf_size, 0);
9488
}
9589
else {
96-
precision = BUF64;
90+
this->precision = BUF64;
9791
this->buf64 = allocator->post_alloc_data<ui64>(this->buf_size, 0);
9892
}
9993

src/core/codestream/ojph_codeblock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ namespace ojph {
7171
};
7272

7373
public:
74-
static void pre_alloc(codestream *codestream, ui32 comp_num,
75-
const size& nominal);
74+
static void pre_alloc(codestream *codestream, const size& nominal,
75+
ui32 precision);
7676
void finalize_alloc(codestream *codestream, subband* parent,
7777
const size& nominal, const size& cb_size,
7878
coded_cb_header* coded_cb,
79-
ui32 K_max, int tbx0);
79+
ui32 K_max, int tbx0, ui32 precision);
8080
void push(line_buf *line);
8181
void encode(mem_elastic_allocator *elastic);
8282
void recreate(const size& cb_size, coded_cb_header* coded_cb);

src/core/codestream/ojph_codestream_local.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ namespace ojph {
7979

8080
precinct_scratch_needed_bytes = 0;
8181

82-
used_qcc_fields = 0;
83-
qcc = qcc_store;
8482
used_coc_fields = 0;
8583
coc = coc_store;
8684

@@ -100,8 +98,6 @@ namespace ojph {
10098
////////////////////////////////////////////////////////////////////////////
10199
codestream::~codestream()
102100
{
103-
if (qcc_store != qcc)
104-
delete[] qcc;
105101
if (allocator)
106102
delete allocator;
107103
if (elastic_alloc)
@@ -633,6 +629,9 @@ namespace ojph {
633629
if (!qcd.write(file))
634630
OJPH_ERROR(0x00030026, "Error writing to file");
635631

632+
if (!qcd.write_qcc(file, num_comps))
633+
OJPH_ERROR(0x0003002D, "Error writing to file");
634+
636635
if (!nlt.write(file))
637636
OJPH_ERROR(0x00030027, "Error writing to file");
638637

@@ -766,9 +765,7 @@ namespace ojph {
766765
ui32 num_comps = siz.get_num_components();
767766
if (coc == coc_store &&
768767
num_comps * sizeof(param_cod) > sizeof(coc_store))
769-
{
770768
coc = new param_cod[num_comps];
771-
}
772769
coc[used_coc_fields++].read(
773770
file, param_cod::COC_MAIN, num_comps, &cod);
774771
}
@@ -779,13 +776,18 @@ namespace ojph {
779776
}
780777
else if (marker_idx == 6)
781778
{
782-
ui32 num_comps = siz.get_num_components();
783-
if (qcc == qcc_store &&
784-
num_comps * sizeof(param_qcc) > sizeof(qcc_store))
785-
{
786-
qcc = new param_qcc[num_comps];
787-
}
788-
qcc[used_qcc_fields++].read(file, num_comps);
779+
param_qcd* p = qcd.add_qcc_object(param_qcd::OJPH_QCD_UNKNOWN);
780+
p->read_qcc(file, siz.get_num_components());
781+
if (p->get_comp_idx() >= siz.get_num_components())
782+
OJPH_ERROR(0x00030054, "The codestream carries a QCC narker "
783+
"segment for a component indexed by %d, which is more than the "
784+
"allowed index number, since the codestream has %d components",
785+
p->get_comp_idx(), num_comps);
786+
param_qcd *q = qcd.get_qcc(p->get_comp_idx());
787+
if (p != q && p->get_comp_idx() == q->get_comp_idx())
788+
OJPH_ERROR(0x00030055, "The codestream has two QCC marker "
789+
"segments for one component of index %d",
790+
p->get_comp_idx());
789791
}
790792
else if (marker_idx == 7)
791793
skip_marker(file, "RGN", "RGN is not supported yet",

src/core/codestream/ojph_codestream_local.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,10 @@ namespace ojph {
8484
{ return ojph::param_cod(&cod); }
8585
const param_cod* get_cod() //return internal cod
8686
{ return &cod; }
87-
const param_cod* get_cod(ui32 comp_num) //return internal cod
88-
{ return cod.get_cod(comp_num); }
89-
param_qcd* access_qcd(ui32 comp_num)
90-
{
91-
if (used_qcc_fields > 0)
92-
for (int v = 0; v < used_qcc_fields; ++v)
93-
if (qcc[v].get_comp_num() == comp_num)
94-
return qcc + v;
95-
return &qcd;
96-
}
87+
const param_cod* get_coc(ui32 comp_num) //return internal cod
88+
{ return cod.get_coc(comp_num); }
89+
const param_qcd* access_qcd()
90+
{ return &qcd; }
9791
const param_dfs* access_dfs()
9892
{ if (dfs.exists()) return &dfs; else return NULL; }
9993
const param_nlt* get_nlt()
@@ -166,9 +160,6 @@ namespace ojph {
166160
param_nlt nlt; // non-linearity point transformation
167161

168162
private: // this is to handle qcc and coc
169-
int used_qcc_fields;
170-
param_qcc *qcc; // quantization component
171-
param_qcc qcc_store[4]; // we allocate 4, we allocate more if needed
172163
int used_coc_fields;
173164
param_cod *coc; // coding style component
174165
param_cod coc_store[4]; // we allocate 4, we allocate more if needed
@@ -178,8 +169,6 @@ namespace ojph {
178169
param_atk* atk; // a pointer to atk
179170
param_atk atk_store[3];// 0 and 1 are for DWT from Part 1, 2 onward are
180171
// for arbitrary transformation kernels
181-
182-
183172
private:
184173
mem_fixed_allocator *allocator;
185174
mem_elastic_allocator *elastic_alloc;

0 commit comments

Comments
 (0)