Skip to content

Commit

Permalink
Merge pull request #172 from aous72/supporting_differing_components
Browse files Browse the repository at this point in the history
This adds support for COC.
  • Loading branch information
aous72 authored Jan 29, 2025
2 parents 545acbd + 52a865e commit 02f3aa2
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 179 deletions.
8 changes: 4 additions & 4 deletions src/core/codestream/ojph_codeblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace ojph {
const size& cb_size,
coded_cb_header* coded_cb,
ui32 K_max, int line_offset,
ui32 precision)
ui32 precision, ui32 comp_idx)
{
mem_fixed_allocator* allocator = codestream->get_allocator();

Expand All @@ -101,10 +101,10 @@ namespace ojph {
this->K_max = K_max;
for (int i = 0; i < 4; ++i)
this->max_val64[i] = 0;
ojph::param_cod cod = codestream->access_cod();
this->reversible = cod.is_reversible();
const param_cod* coc = codestream->get_coc(comp_idx);
this->reversible = coc->is_reversible();
this->resilient = codestream->is_resilient();
this->stripe_causal = cod.get_block_vertical_causality();
this->stripe_causal = coc->get_block_vertical_causality();
this->zero_block = false;
this->coded_cb = coded_cb;

Expand Down
4 changes: 2 additions & 2 deletions src/core/codestream/ojph_codeblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace ojph {
ui32 precision);
void finalize_alloc(codestream *codestream, subband* parent,
const size& nominal, const size& cb_size,
coded_cb_header* coded_cb,
ui32 K_max, int tbx0, ui32 precision);
coded_cb_header* coded_cb, ui32 K_max,
int tbx0, ui32 precision, ui32 comp_idx);
void push(line_buf *line);
void encode(mem_elastic_allocator *elastic);
void recreate(const size& cb_size, coded_cb_header* coded_cb);
Expand Down
36 changes: 17 additions & 19 deletions src/core/codestream/ojph_codestream_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ namespace ojph {

precinct_scratch_needed_bytes = 0;

used_coc_fields = 0;
coc = coc_store;

atk = atk_store;
atk[0].init_irv97();
atk[0].link(atk_store + 1);
Expand Down Expand Up @@ -626,6 +623,9 @@ namespace ojph {
if (!cod.write(file))
OJPH_ERROR(0x00030025, "Error writing to file");

if (!cod.write_coc(file, num_comps))
OJPH_ERROR(0x0003002E, "Error writing to file");

if (!qcd.write(file))
OJPH_ERROR(0x00030026, "Error writing to file");

Expand Down Expand Up @@ -751,7 +751,7 @@ namespace ojph {
skip_marker(file, "CPF", NULL, OJPH_MSG_LEVEL::NO_MSG, false);
else if (marker_idx == 3)
{
cod.read(file, param_cod::COD_MAIN);
cod.read(file);
received_markers |= 1;
ojph::param_cod c(&cod);
int num_qlayers = c.get_num_layers();
Expand All @@ -762,12 +762,17 @@ namespace ojph {
}
else if (marker_idx == 4)
{
ui32 num_comps = siz.get_num_components();
if (coc == coc_store &&
num_comps * sizeof(param_cod) > sizeof(coc_store))
coc = new param_cod[num_comps];
coc[used_coc_fields++].read(
file, param_cod::COC_MAIN, num_comps, &cod);
param_cod* p = cod.add_coc_object(param_cod::OJPH_COD_UNKNOWN);
p->read_coc(file, siz.get_num_components(), &cod);
if (p->get_comp_idx() >= siz.get_num_components())
OJPH_INFO(0x00030056, "The codestream carries a COC marker "
"segment for a component indexed by %d, which is more than the "
"allowed index number, since the codestream has %d components",
p->get_comp_idx(), num_comps);
param_cod *q = cod.get_coc(p->get_comp_idx());
if (p != q && p->get_comp_idx() == q->get_comp_idx())
OJPH_ERROR(0x00030057, "The codestream has two COC marker "
"segments for one component of index %d", p->get_comp_idx());
}
else if (marker_idx == 5)
{
Expand All @@ -779,15 +784,14 @@ namespace ojph {
param_qcd* p = qcd.add_qcc_object(param_qcd::OJPH_QCD_UNKNOWN);
p->read_qcc(file, siz.get_num_components());
if (p->get_comp_idx() >= siz.get_num_components())
OJPH_ERROR(0x00030054, "The codestream carries a QCC narker "
OJPH_ERROR(0x00030054, "The codestream carries a QCC marker "
"segment for a component indexed by %d, which is more than the "
"allowed index number, since the codestream has %d components",
p->get_comp_idx(), num_comps);
param_qcd *q = qcd.get_qcc(p->get_comp_idx());
if (p != q && p->get_comp_idx() == q->get_comp_idx())
OJPH_ERROR(0x00030055, "The codestream has two QCC marker "
"segments for one component of index %d",
p->get_comp_idx());
"segments for one component of index %d", p->get_comp_idx());
}
else if (marker_idx == 7)
skip_marker(file, "RGN", "RGN is not supported yet",
Expand Down Expand Up @@ -827,12 +831,6 @@ namespace ojph {
}

cod.update_atk(atk);
for (int i = 0; i < used_coc_fields; ++i)
{
if (i == 0) cod.link_cod(coc);
else coc[i - 1].link_cod(coc + i);
coc[i].update_atk(atk);
}
siz.link(&cod);
if (dfs.exists())
siz.link(&dfs);
Expand Down
5 changes: 0 additions & 5 deletions src/core/codestream/ojph_codestream_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ namespace ojph {
param_tlm tlm; // tile-part lengths
param_nlt nlt; // non-linearity point transformation

private: // this is to handle qcc and coc
int used_coc_fields;
param_cod *coc; // coding style component
param_cod coc_store[4]; // we allocate 4, we allocate more if needed

private: // these are from Part 2 of the standard
param_dfs dfs; // downsmapling factor styles
param_atk* atk; // a pointer to atk
Expand Down
Loading

0 comments on commit 02f3aa2

Please sign in to comment.