@@ -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;
0 commit comments