Skip to content

Commit

Permalink
A few bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Sep 30, 2019
1 parent 31d83e6 commit bd98d24
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.DS_Store
test/*
mytest/*
others/*
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<VariablesViewState
version = "1.0">
<ContextStates>
<ContextState
contextName = "ojph::local::ojph_decode_codeblock(unsigned char*, int*, int, int, int, int, int, int, int):ojph_block_decoder.cpp">
<PersistentStrings>
<PersistentString
value = "sigma1[0]">
</PersistentString>
<PersistentString
value = "mbr1[0]">
</PersistentString>
<PersistentString
value = "sigma2[0]">
</PersistentString>
<PersistentString
value = "mbr2[0]">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,16 +36,16 @@
ReferencedContainer = "container:apps.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "YES"
customWorkingDirectory = "/Users/aous/Google Drive/OpenJPH/test"
customWorkingDirectory = "/Users/aous/Google Drive/OpenJPH/mytest"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
Expand All @@ -64,9 +62,33 @@
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-i ARRI_AlexaDrums_3840x2160p_24_8b_P3_444_00000.ppm"
argument = "-i ARRI_AlexaDrums_3840x2160p_24_8b_P3_444_00000.ppm -o test.j2c -num_decomps 5 -block_size \{64,64\} -precincts \{1024,2\} -prog_order CPRL -colour_trans true -tile_size \{343,121\} -image_offset \{37,21\} -tile_offset \{2,11\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ARRI_AlexaDrums_3840x2160p_24_8b_P3_444_00000.ppm -o test.j2c -num_decomps 5 -block_size \{64,64\} -precincts \{128,128\},\{256,256\}"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-i t5-334.pgm -o test.j2c -num_decomps 2 -block_size \{64,64\} -precincts \{1024,2\} -prog_order CPRL -image_offset \{1717,374\} -tile_offset \{1717,374\} -tile_size \{343,121\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i t5-334.pgm -o test.j2c -num_decomps 2 -block_size \{64,64\} -precincts \{1024,2\} -prog_order CPRL -image_offset \{1717,374\} -tile_offset \{1717,374\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i lena.pgm -o test.j2c -num_decomps 1 -block_size \{8,8\} -prog_order CPRL -image_offset \{37,21\} -precincts \{16,16\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i lena.pgm -o test.j2c -num_decomps 1 -block_size \{8,8\} -prog_order CPRL -image_offset \{37,21\} -precincts \{16,16\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i ARRI_AlexaDrums_3840x2160p_24_8b_P3_444_00000.ppm"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i VQEG_CrowdRun_3840x2160p_50_10b_bt709_422_07111.yuv"
isEnabled = "NO">
Expand Down Expand Up @@ -145,11 +167,11 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-o test.j2c"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-num_decomps 5"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-num_decomps 2"
Expand All @@ -173,7 +195,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-prog_order RPCL"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-prog_order PCRL"
Expand All @@ -185,7 +207,11 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-block_size \{4,1024\}"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-block_size \{64,64\}"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-block_size \{1024,4\}"
Expand Down Expand Up @@ -236,8 +262,6 @@
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,16 +36,16 @@
ReferencedContainer = "container:apps.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "YES"
customWorkingDirectory = "/Users/aous/Google Drive/OpenJPH/test"
customWorkingDirectory = "/Users/aous/Google Drive/OpenJPH/mytest"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
Expand Down Expand Up @@ -80,8 +78,6 @@
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "92C6DAC5-480B-4E33-888F-488026E2EFC1"
type = "1"
version = "2.0">
</Bucket>
4 changes: 2 additions & 2 deletions src/apps/ojph_compress/ojph_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ int main(int argc, char * argv[]) {

ojph::param_cod_t cod = codestream.access_cod();
cod.set_num_decomposition(num_decompositions);
cod.set_block_dims((ojph::ui8)block_size.w, (ojph::ui8)block_size.h);
cod.set_block_dims(block_size.w, block_size.h);
if (num_precints != -1)
cod.set_precinct_size(num_precints, precinct_size);
cod.set_progression_order(prog_order);
Expand Down Expand Up @@ -639,7 +639,7 @@ int main(int argc, char * argv[]) {

ojph::param_cod_t cod = codestream.access_cod();
cod.set_num_decomposition(num_decompositions);
cod.set_block_dims((ojph::ui8)block_size.w, (ojph::ui8)block_size.h);
cod.set_block_dims(block_size.w, block_size.h);
if (num_precints != -1)
cod.set_precinct_size(num_precints, precinct_size);
cod.set_progression_order(prog_order);
Expand Down
92 changes: 49 additions & 43 deletions src/core/codestream/ojph_codestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace ojph {
tile_rect.org.x += index.x * sz.get_tile_size().w;
t = tile_rect.org.x + sz.get_tile_size().w; //end of tile
//restrict tile
tile_rect.org.x =ojph_max(tile_rect.org.x,sz.get_image_offset().x);
tile_rect.org.x = ojph_max(tile_rect.org.x,sz.get_image_offset().x);
tile_rect.siz.w = ojph_min(t, sz.get_image_extent().x);
tile_rect.siz.w -= tile_rect.org.x;

Expand Down Expand Up @@ -376,7 +376,7 @@ namespace ojph {
if (!qcd.write(file))
throw "Error writing to file";

char buf[] = " OpenJPH Ver 0.1.0";
char buf[] = " OpenJPH Ver 0.1.1";
size_t len = strlen(buf);
*(ui16*)buf = swap_byte(JP2K_MARKER::COM);
*(ui16*)(buf + 2) = swap_byte((ui16)(len - 2));
Expand Down Expand Up @@ -795,8 +795,7 @@ namespace ojph {
comp_rects[i].siz.w = tcx1 - tcx0;
comp_rects[i].siz.h = tcy1 - tcy0;

comps[i].finalize_alloc(codestream, this, i, comp_rects[i],
tile_rect);
comps[i].finalize_alloc(codestream, this, i, comp_rects[i]);
width = ojph_max(width, comp_rects[i].siz.w);

num_bits[i] = sz.get_bit_depth(i);
Expand Down Expand Up @@ -1239,8 +1238,7 @@ namespace ojph {

//////////////////////////////////////////////////////////////////////////
void tile_comp::finalize_alloc(codestream *codestream, tile *parent,
int comp_num, const rect& comp_rect,
const rect& tile_rect)
int comp_num, const rect& comp_rect)
{
mem_fixed_allocator* allocator = codestream->get_allocator();

Expand All @@ -1256,7 +1254,7 @@ namespace ojph {
this->comp_num = comp_num;
res = allocator->post_alloc_obj<resolution>(1);
res->finalize_alloc(codestream, comp_rect, num_decomps, comp_downsamp,
this, NULL, tile_rect);
this, NULL);
}

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1489,8 +1487,7 @@ namespace ojph {
const rect& res_rect, int res_num,
point comp_downsamp,
tile_comp *parent_tile,
resolution *parent_res,
const rect& tile_rect)
resolution *parent_res)
{
mem_fixed_allocator* allocator = codestream->get_allocator();
elastic = codestream->get_elastic_alloc();
Expand All @@ -1501,7 +1498,6 @@ namespace ojph {
this->parent = parent_tile;
this->parent_res = parent_res;
this->res_rect = res_rect;
this->tile_rect = tile_rect;
this->res_num = res_num;
//finalize next resolution
if (res_num > 0)
Expand All @@ -1519,8 +1515,7 @@ namespace ojph {
next_res_rect.siz.h = try1 - try0;

child_res->finalize_alloc(codestream, next_res_rect, res_num - 1,
comp_downsamp, parent_tile, this,
tile_rect);
comp_downsamp, parent_tile, this);
}
else
child_res = NULL;
Expand Down Expand Up @@ -1555,7 +1550,7 @@ namespace ojph {
}

//finalize precincts
size log_PP = cd.get_log_precinct_size(res_num);
log_PP = cd.get_log_precinct_size(res_num);
num_precincts.w = (trx1 + (1<<log_PP.w) - 1) >> log_PP.w;
num_precincts.w -= trx0 >> log_PP.w;
num_precincts.h = (try1 + (1<<log_PP.h) - 1) >> log_PP.h;
Expand All @@ -1564,7 +1559,9 @@ namespace ojph {
memset(precincts, 0, sizeof(precinct) * num_precincts.area());

int x_lower_bound = (trx0 >> log_PP.w) << log_PP.w;
int y_lower_bound = (try0 >> log_PP.w) << log_PP.w;
int y_lower_bound = (try0 >> log_PP.h) << log_PP.h;
bool test_x = x_lower_bound != trx0;
bool test_y = y_lower_bound != try0;

point proj_factor;
proj_factor.x = comp_downsamp.x * (1<<(num_decomps - res_num));
Expand All @@ -1578,6 +1575,8 @@ namespace ojph {
int ppx0 = x_lower_bound + (x << log_PP.w);
pp->img_point.x = proj_factor.x * ppx0;
pp->img_point.y = proj_factor.y * ppy0;
pp->special_x = test_x && x == 0;
pp->special_y = test_y && y == 0;
pp->num_bands = num_bands;
pp->bands = bands;
}
Expand Down Expand Up @@ -2054,7 +2053,9 @@ namespace ojph {
int idx = cur_precinct_loc.x + cur_precinct_loc.y * num_precincts.w;
if (idx < (int)num_precincts.area())
{
top_left = precincts[idx].img_point;
point t = precincts[idx].img_point;
top_left.x = precincts[idx].special_x ? 0 : t.x;
top_left.y = precincts[idx].special_y ? 0 : t.y;
return true;
}
return false;
Expand Down Expand Up @@ -2902,42 +2903,47 @@ namespace ojph {
num_blocks.h = (tby1 + (1 << ycb_prime) - 1) >> ycb_prime;
num_blocks.h -= tby0 >> ycb_prime;

blocks = allocator->post_alloc_obj<codeblock>(num_blocks.w);
//allocate codeblock headers
coded_cb_header *cp = coded_cbs =
allocator->post_alloc_obj<coded_cb_header>(num_blocks.area());
memset(coded_cbs, 0, sizeof(coded_cb_header) * num_blocks.area());
for (int i = (int)num_blocks.area(); i > 0; --i, ++cp)
cp->Kmax = K_max;

int x_lower_bound = (tbx0 >> xcb_prime) << xcb_prime;
int y_lower_bound = (tby0 >> ycb_prime) << ycb_prime;

size cb_size;
cb_size.h = ojph_min(tby1, y_lower_bound + nominal.h) - tby0;
cur_cb_height = cb_size.h;
int line_offset = 0;
for (int i = 0; i < num_blocks.w; ++i)
if (num_blocks.area())
{
int cbx0 = ojph_max(tbx0, x_lower_bound + i * nominal.w);
int cbx1 = ojph_min(tbx1, x_lower_bound + (i + 1) * nominal.w);
cb_size.w = cbx1 - cbx0;
blocks[i].finalize_alloc(codestream, this, nominal, cb_size,
coded_cbs + i, K_max, line_offset);
line_offset += cb_size.w;
}
blocks = allocator->post_alloc_obj<codeblock>(num_blocks.w);
//allocate codeblock headers
coded_cb_header *cp = coded_cbs =
allocator->post_alloc_obj<coded_cb_header>(num_blocks.area());
memset(coded_cbs, 0, sizeof(coded_cb_header) * num_blocks.area());
for (int i = (int)num_blocks.area(); i > 0; --i, ++cp)
cp->Kmax = K_max;

int x_lower_bound = (tbx0 >> xcb_prime) << xcb_prime;
int y_lower_bound = (tby0 >> ycb_prime) << ycb_prime;

size cb_size;
cb_size.h = ojph_min(tby1, y_lower_bound + nominal.h) - tby0;
cur_cb_height = cb_size.h;
int line_offset = 0;
for (int i = 0; i < num_blocks.w; ++i)
{
int cbx0 = ojph_max(tbx0, x_lower_bound + i * nominal.w);
int cbx1 = ojph_min(tbx1, x_lower_bound + (i + 1) * nominal.w);
cb_size.w = cbx1 - cbx0;
blocks[i].finalize_alloc(codestream, this, nominal, cb_size,
coded_cbs + i, K_max, line_offset);
line_offset += cb_size.w;
}

//allocate lines
lines = allocator->post_alloc_obj<line_buf>(1);
//allocate line_buf
int width = band_rect.siz.w + 1;
lines->wrap(allocator->post_alloc_data<si32>(width,1),width,1);
//allocate lines
lines = allocator->post_alloc_obj<line_buf>(1);
//allocate line_buf
int width = band_rect.siz.w + 1;
lines->wrap(allocator->post_alloc_data<si32>(width,1),width,1);
}
}

//////////////////////////////////////////////////////////////////////////
void subband::get_cb_indices(const size& num_precincts,
precinct *precincts)
{
if (num_precincts.area() == 0)
return;
rect res_rect = parent->get_rect();
int trx0 = res_rect.org.x;
int try0 = res_rect.org.y;
Expand Down
Loading

0 comments on commit bd98d24

Please sign in to comment.