Skip to content

Commit

Permalink
Updated apps, and version bump for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Feb 2, 2025
1 parent dd9bd6d commit c74721a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 77 deletions.
73 changes: 32 additions & 41 deletions src/apps/ojph_compress/ojph_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,33 +777,20 @@ int main(int argc, char * argv[]) {
if (num_bit_depths < num_comps) // but if not enough, repeat
for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
bit_depth[c] = bit_depth[num_bit_depths - 1];
if (is_signed[0] != -1) // one was set
if (num_is_signed < num_comps) // but if not enough, repeat
for (ojph::ui32 c = num_is_signed; c < num_comps; ++c)
is_signed[c] = is_signed[num_is_signed - 1];

bool all_the_same = true;
if (num_comps == 3)
{
all_the_same = all_the_same
&& bit_depth[0] == bit_depth[1]
&& bit_depth[1] == bit_depth[2];
all_the_same = all_the_same
&& is_signed[0] == is_signed[1]
&& is_signed[1] == is_signed[2];
}

pfm.configure(bit_depth);
ojph::point ds(1, 1);
for (ojph::ui32 c = 0; c < num_comps; ++c) {
ojph::ui32 bd = 32;
if (bit_depth[c] != 0)
bd = bit_depth[c];
bool is = true;
if (is_signed[c] != -1)
is = is_signed[c] != 0;
siz.set_component(c, ds, bd, is);
if (bit_depth[c] == 0)
bit_depth[c] = 32;
siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
}
pfm.configure(bit_depth);

siz.set_image_offset(image_offset);
siz.set_tile_size(tile_size);
siz.set_tile_offset(tile_offset);
Expand All @@ -817,7 +804,7 @@ int main(int argc, char * argv[]) {
if (num_comps == 1)
{
if (employ_color_transform != -1)
OJPH_WARN(0x01000092,
OJPH_WARN(0x01000091,
"-colour_trans option is not needed and was not used; "
"this is because the image has one component only\n");
}
Expand All @@ -829,29 +816,30 @@ int main(int argc, char * argv[]) {
cod.set_color_transform(employ_color_transform == 1);
}
cod.set_reversible(reversible);
if (!reversible && quantization_step != -1.0f)
if (!reversible) {
const float min_step = 1.0f / 16384.0f;
if (quantization_step == -1.0f)
quantization_step = min_step;
else
quantization_step = ojph_max(quantization_step, min_step);
codestream.access_qcd().set_irrev_quant(quantization_step);
}

// Note: Even if only ALL_COMPS is set to
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
// one ALL_COMPS NLT marker segment is needed, or multiple
// per component NLT marker segments are needed (when the components
// have different bit depths or signedness).
// Of course for .pfm images all components should have the same
// bit depth and signedness.
ojph::param_nlt nlt = codestream.access_nlt();
if (reversible) {
// Note: Even if only ALL_COMPS is set to
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
// one ALL_COMPS NLT marker segment is needed, or multiple
// per component NLT marker segments are needed (when the components
// have different bit depths or signedness).
// Of course for .pfm images all components should have the same
// bit depth and signedness.
if (all_the_same)
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
else
for (ojph::ui32 c = 0; c < num_comps; ++c)
nlt.set_nonlinear_transform(c,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
}
if (all_the_same)
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
else
OJPH_ERROR(0x01000093, "We currently support lossless only for "
"pfm images; this may change in the future.");
for (ojph::ui32 c = 0; c < num_comps; ++c)
nlt.set_nonlinear_transform(c,
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);

codestream.set_planar(false);
if (profile_string[0] != '\0')
Expand All @@ -861,13 +849,16 @@ int main(int argc, char * argv[]) {
codestream.request_tlm_marker(tlm_marker);

if (dims.w != 0 || dims.h != 0)
OJPH_WARN(0x01000094,
OJPH_WARN(0x01000092,
"-dims option is not needed and was not used\n");
if (num_components != 0)
OJPH_WARN(0x01000095,
OJPH_WARN(0x01000093,
"-num_comps is not needed and was not used\n");
if (is_signed[0] != -1)
OJPH_WARN(0x01000094,
"-signed is not needed and was not used\n");
if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
OJPH_WARN(0x01000096,
OJPH_WARN(0x01000095,
"-downsamp is not needed and was not used\n");

base = &pfm;
Expand Down
42 changes: 7 additions & 35 deletions src/apps/ojph_expand/ojph_expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,60 +269,32 @@ int main(int argc, char *argv[]) {
}
else if (is_matching(".pfm", v))
{
OJPH_INFO(0x02000011, "Note: The .pfm implementation is "
"experimental. It is developed for me the test NLT marker segments. "
"For this reason, I am restricting it to images that employ the "
"NLT marker segment, with the assumption that original values are "
OJPH_INFO(0x02000010, "Note: The .pfm implementation is "
"experimental. Here, we are assuming that the original data is "
"floating-point numbers.");

codestream.set_planar(false);
ojph::param_siz siz = codestream.access_siz();
ojph::param_cod cod = codestream.access_cod();
ojph::param_nlt nlt = codestream.access_nlt();

ojph::ui32 num_comps = siz.get_num_components();
if (num_comps != 3 && num_comps != 1)
OJPH_ERROR(0x0200000C,
"The file has %d color components; this cannot be saved to"
" a .pfm file\n", num_comps);
" a .pfm file", num_comps);
bool all_same = true;
ojph::point p = siz.get_downsampling(0);
for (ojph::ui32 i = 1; i < siz.get_num_components(); ++i)
{
for (ojph::ui32 i = 1; i < siz.get_num_components(); ++i) {
ojph::point p1 = siz.get_downsampling(i);
all_same = all_same && (p1.x == p.x) && (p1.y == p.y);
}
if (!all_same)
OJPH_ERROR(0x0200000D,
"To save an image to ppm, all the components must have the "
"same downsampling ratio\n");
"same downsampling ratio");
ojph::ui32 bit_depth[3];
for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c) {
ojph::ui8 bd = 0;
bool is = true;
ojph::ui8 nl_type;
bool result = nlt.get_nonlinear_transform(c, bd, is, nl_type);
if (result == false ||
nl_type != ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT)
OJPH_ERROR(0x0200000E,
"This codestream is not supported; it does not have an "
"NLT segment marker for this component (or no default NLT "
"settings) .\n");
if (bd != siz.get_bit_depth(c) || is != siz.is_signed(c))
OJPH_ERROR(0x0200000F,
"There is discrepancy in component %d configuration between "
"SIZ marker segment, which specifies bit_depth = %d and "
"signedness = %s, and NLT marker segment, which specifies "
"bit_depth = %d and signedness = %s.\n", c,
siz.get_bit_depth(c), is != siz.is_signed(c) ? "True" : "False",
bd, is ? "True" : "False");
bit_depth[c] = bd;
}
if (!cod.is_reversible())
OJPH_ERROR(0x02000010,
"This codestream is lossy (not reversible), and we currently "
"only support reversible codestreams for .pfm target files. "
"This is only temporary and will be changed at some point.\n");
for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c)
bit_depth[c] = siz.get_bit_depth(c);
pfm.configure(siz.get_recon_width(0), siz.get_recon_height(0),
siz.get_num_components(), -1.0f, bit_depth);
pfm.open(output_filename);
Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
//***************************************************************************/

#define OPENJPH_VERSION_MAJOR 0
#define OPENJPH_VERSION_MINOR 20
#define OPENJPH_VERSION_MINOR 21
#define OPENJPH_VERSION_PATCH 0

0 comments on commit c74721a

Please sign in to comment.