Skip to content

Commit

Permalink
Setting region of interest into param_siz
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Jan 11, 2024
1 parent 6255146 commit 2d62322
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
21 changes: 5 additions & 16 deletions src/apps/ojph_expand/ojph_expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,26 +388,15 @@ int main(int argc, char *argv[]) {
ojph::point o = siz.get_image_offset();
if (region_set) // convert region to abs_region
{
ojph::size s;
s.w = e.x - o.x;
s.h = e.y - o.y;
ojph::size s(e.x - o.x, e.y - o.y);
double t;
// top
t = (double)o.y + region[0] * (double)s.h;
t = (double)o.y + region[0] * (double)s.h; // top
abs_region.org.y = (ojph::ui32)floor(t);
// left
t = (double)o.x + region[1] * (double)s.w;
t = (double)o.x + region[1] * (double)s.w; // left
abs_region.org.x = (ojph::ui32)floor(t);
// bottom

// right

abs_region.siz.h = (ojph::ui32)ceil(region[2] * (double)s.h);//bottom
abs_region.siz.w = (ojph::ui32)ceil(region[3] * (double)s.w); //right
}
abs_region.org.y = ojph_max(abs_region.org.y, o.y);
abs_region.org.y = ojph_min(abs_region.org.y, e.y);
abs_region.org.x = ojph_max(abs_region.org.x, o.x);
abs_region.org.x = ojph_min(abs_region.org.x, e.x);

codestream.restrict_recon_region(abs_region);
}

Expand Down
32 changes: 30 additions & 2 deletions src/core/codestream/ojph_codestream_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,37 @@ namespace ojph {
}

//////////////////////////////////////////////////////////////////////////
void codestream::restrict_recon_region(const rect& region)
void codestream::restrict_recon_region(rect region)
{

ojph::param_siz sz = access_siz();
point o = sz.get_image_offset();
point e = sz.get_image_extent();

ui32 ex = region.org.x + region.siz.w;
ui32 ey = region.org.y + region.siz.h;

region.org.x = ojph_max(region.org.x, o.x);
region.org.x = ojph_min(region.org.x, e.x);
region.org.y = ojph_max(region.org.y, o.y);
region.org.y = ojph_min(region.org.y, e.y);

ex = ojph_max(ex, o.x);
ex = ojph_min(ex, e.x);
ey = ojph_max(ey, o.y);
ey = ojph_min(ey, e.y);

region.siz.w = ex - region.org.x;
region.siz.h = ey - region.org.y;

if (region.siz.w <= 0 || region.siz.h <= 0)
OJPH_ERROR(0x000300D1, "Error in region specifications. After "
"calculation, the region requested is (top,left),(height,width) "
"is (%d,%d),(%d,%d), when the image offset (x,y) and extent "
"are (x,y) are (%d,%d) and (%d,%d)\n",
region.org.y, region.org.x, region.siz.h, region.siz.w,
o.x, o.y, e.x, e.y);

siz.set_recon_region(region);
}

//////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/core/codestream/ojph_codestream_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace ojph {
void read_headers(infile_base *file);
void restrict_input_resolution(ui32 skipped_res_for_data,
ui32 skipped_res_for_recon);
void restrict_recon_region(const rect& region);
void restrict_recon_region(rect region);
void read();
void set_planar(int planar);
void set_profile(const char *s);
Expand Down
5 changes: 5 additions & 0 deletions src/core/codestream/ojph_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ namespace ojph {
if (file->read(&cptr[c].YRsiz, 1) != 1)
OJPH_ERROR(0x00050053, "error reading SIZ marker");
}

recon_region.org.x = XOsiz;
recon_region.org.y = YOsiz;
recon_region.siz.w = Xsiz - XOsiz;
recon_region.siz.h = Ysiz - YOsiz;
}

//////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions src/core/codestream/ojph_params_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ namespace ojph {
ui32 t = ojph_div_ceil(Ysiz, ds) - ojph_div_ceil(YOsiz, ds);
return t;
}
void set_recon_region(const rect& region)
{
this->recon_region = region;
}

private:
ui16 Lsiz;
Expand All @@ -273,6 +277,7 @@ namespace ojph {

private:
ui32 skipped_resolutions;
rect recon_region;
int old_Csiz;
siz_comp_info store[4];
param_siz(const param_siz&) = delete; //prevent copy constructor
Expand Down

0 comments on commit 2d62322

Please sign in to comment.