Skip to content

Commit 57e5931

Browse files
authored
Merge pull request #178 from aous72/update_for_lossy_compression
Support for lossy floating point with NLT segment marker.
2 parents dd9bd6d + 5b50d46 commit 57e5931

File tree

3 files changed

+40
-78
lines changed

3 files changed

+40
-78
lines changed

src/apps/ojph_compress/ojph_compress.cpp

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -777,33 +777,20 @@ int main(int argc, char * argv[]) {
777777
if (num_bit_depths < num_comps) // but if not enough, repeat
778778
for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
779779
bit_depth[c] = bit_depth[num_bit_depths - 1];
780-
if (is_signed[0] != -1) // one was set
781-
if (num_is_signed < num_comps) // but if not enough, repeat
782-
for (ojph::ui32 c = num_is_signed; c < num_comps; ++c)
783-
is_signed[c] = is_signed[num_is_signed - 1];
784780

785781
bool all_the_same = true;
786782
if (num_comps == 3)
787-
{
788783
all_the_same = all_the_same
789784
&& bit_depth[0] == bit_depth[1]
790785
&& bit_depth[1] == bit_depth[2];
791-
all_the_same = all_the_same
792-
&& is_signed[0] == is_signed[1]
793-
&& is_signed[1] == is_signed[2];
794-
}
795786

796-
pfm.configure(bit_depth);
797-
ojph::point ds(1, 1);
798787
for (ojph::ui32 c = 0; c < num_comps; ++c) {
799-
ojph::ui32 bd = 32;
800-
if (bit_depth[c] != 0)
801-
bd = bit_depth[c];
802-
bool is = true;
803-
if (is_signed[c] != -1)
804-
is = is_signed[c] != 0;
805-
siz.set_component(c, ds, bd, is);
788+
if (bit_depth[c] == 0)
789+
bit_depth[c] = 32;
790+
siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
806791
}
792+
pfm.configure(bit_depth);
793+
807794
siz.set_image_offset(image_offset);
808795
siz.set_tile_size(tile_size);
809796
siz.set_tile_offset(tile_offset);
@@ -817,7 +804,7 @@ int main(int argc, char * argv[]) {
817804
if (num_comps == 1)
818805
{
819806
if (employ_color_transform != -1)
820-
OJPH_WARN(0x01000092,
807+
OJPH_WARN(0x01000091,
821808
"-colour_trans option is not needed and was not used; "
822809
"this is because the image has one component only\n");
823810
}
@@ -829,29 +816,30 @@ int main(int argc, char * argv[]) {
829816
cod.set_color_transform(employ_color_transform == 1);
830817
}
831818
cod.set_reversible(reversible);
832-
if (!reversible && quantization_step != -1.0f)
819+
if (!reversible) {
820+
const float min_step = 1.0f / 16384.0f;
821+
if (quantization_step == -1.0f)
822+
quantization_step = min_step;
823+
else
824+
quantization_step = ojph_max(quantization_step, min_step);
833825
codestream.access_qcd().set_irrev_quant(quantization_step);
826+
}
834827

828+
// Note: Even if only ALL_COMPS is set to
829+
// OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
830+
// one ALL_COMPS NLT marker segment is needed, or multiple
831+
// per component NLT marker segments are needed (when the components
832+
// have different bit depths or signedness).
833+
// Of course for .pfm images all components should have the same
834+
// bit depth and signedness.
835835
ojph::param_nlt nlt = codestream.access_nlt();
836-
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.
844-
if (all_the_same)
845-
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
846-
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
847-
else
848-
for (ojph::ui32 c = 0; c < num_comps; ++c)
849-
nlt.set_nonlinear_transform(c,
850-
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
851-
}
836+
if (all_the_same)
837+
nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
838+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
852839
else
853-
OJPH_ERROR(0x01000093, "We currently support lossless only for "
854-
"pfm images; this may change in the future.");
840+
for (ojph::ui32 c = 0; c < num_comps; ++c)
841+
nlt.set_nonlinear_transform(c,
842+
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
855843

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

863851
if (dims.w != 0 || dims.h != 0)
864-
OJPH_WARN(0x01000094,
852+
OJPH_WARN(0x01000092,
865853
"-dims option is not needed and was not used\n");
866854
if (num_components != 0)
867-
OJPH_WARN(0x01000095,
855+
OJPH_WARN(0x01000093,
868856
"-num_comps is not needed and was not used\n");
857+
if (is_signed[0] != -1)
858+
OJPH_WARN(0x01000094,
859+
"-signed is not needed and was not used\n");
869860
if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
870-
OJPH_WARN(0x01000096,
861+
OJPH_WARN(0x01000095,
871862
"-downsamp is not needed and was not used\n");
872863

873864
base = &pfm;

src/apps/ojph_expand/ojph_expand.cpp

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -269,60 +269,31 @@ 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 "
272+
OJPH_INFO(0x02000010, "Note: The .pfm implementation is "
273+
"experimental. Here, we are assuming that the original data is "
276274
"floating-point numbers.");
277275

278276
codestream.set_planar(false);
279277
ojph::param_siz siz = codestream.access_siz();
280-
ojph::param_cod cod = codestream.access_cod();
281-
ojph::param_nlt nlt = codestream.access_nlt();
282278

283279
ojph::ui32 num_comps = siz.get_num_components();
284280
if (num_comps != 3 && num_comps != 1)
285281
OJPH_ERROR(0x0200000C,
286282
"The file has %d color components; this cannot be saved to"
287-
" a .pfm file\n", num_comps);
283+
" a .pfm file", num_comps);
288284
bool all_same = true;
289285
ojph::point p = siz.get_downsampling(0);
290-
for (ojph::ui32 i = 1; i < siz.get_num_components(); ++i)
291-
{
286+
for (ojph::ui32 i = 1; i < siz.get_num_components(); ++i) {
292287
ojph::point p1 = siz.get_downsampling(i);
293288
all_same = all_same && (p1.x == p.x) && (p1.y == p.y);
294289
}
295290
if (!all_same)
296291
OJPH_ERROR(0x0200000D,
297292
"To save an image to ppm, all the components must have the "
298-
"same downsampling ratio\n");
293+
"same downsampling ratio");
299294
ojph::ui32 bit_depth[3];
300-
for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c) {
301-
ojph::ui8 bd = 0;
302-
bool is = true;
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)
307-
OJPH_ERROR(0x0200000E,
308-
"This codestream is not supported; it does not have an "
309-
"NLT segment marker for this component (or no default NLT "
310-
"settings) .\n");
311-
if (bd != siz.get_bit_depth(c) || is != siz.is_signed(c))
312-
OJPH_ERROR(0x0200000F,
313-
"There is discrepancy in component %d configuration between "
314-
"SIZ marker segment, which specifies bit_depth = %d and "
315-
"signedness = %s, and NLT marker segment, which specifies "
316-
"bit_depth = %d and signedness = %s.\n", c,
317-
siz.get_bit_depth(c), is != siz.is_signed(c) ? "True" : "False",
318-
bd, is ? "True" : "False");
319-
bit_depth[c] = bd;
320-
}
321-
if (!cod.is_reversible())
322-
OJPH_ERROR(0x02000010,
323-
"This codestream is lossy (not reversible), and we currently "
324-
"only support reversible codestreams for .pfm target files. "
325-
"This is only temporary and will be changed at some point.\n");
295+
for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c)
296+
bit_depth[c] = siz.get_bit_depth(c);
326297
pfm.configure(siz.get_recon_width(0), siz.get_recon_height(0),
327298
siz.get_num_components(), -1.0f, bit_depth);
328299
pfm.open(output_filename);

src/core/common/ojph_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
//***************************************************************************/
3535

3636
#define OPENJPH_VERSION_MAJOR 0
37-
#define OPENJPH_VERSION_MINOR 20
37+
#define OPENJPH_VERSION_MINOR 21
3838
#define OPENJPH_VERSION_PATCH 0

0 commit comments

Comments
 (0)