@@ -788,33 +788,20 @@ int main(int argc, char * argv[]) {
788788 if (num_bit_depths < num_comps) // but if not enough, repeat
789789 for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
790790 bit_depth[c] = bit_depth[num_bit_depths - 1 ];
791- if (is_signed[0 ] != -1 ) // one was set
792- if (num_is_signed < num_comps) // but if not enough, repeat
793- for (ojph::ui32 c = num_is_signed; c < num_comps; ++c)
794- is_signed[c] = is_signed[num_is_signed - 1 ];
795791
796792 bool all_the_same = true ;
797793 if (num_comps == 3 )
798- {
799794 all_the_same = all_the_same
800795 && bit_depth[0 ] == bit_depth[1 ]
801796 && bit_depth[1 ] == bit_depth[2 ];
802- all_the_same = all_the_same
803- && is_signed[0 ] == is_signed[1 ]
804- && is_signed[1 ] == is_signed[2 ];
805- }
806797
807- pfm.configure (bit_depth);
808- ojph::point ds (1 , 1 );
809798 for (ojph::ui32 c = 0 ; c < num_comps; ++c) {
810- ojph::ui32 bd = 32 ;
811- if (bit_depth[c] != 0 )
812- bd = bit_depth[c];
813- bool is = true ;
814- if (is_signed[c] != -1 )
815- is = is_signed[c] != 0 ;
816- siz.set_component (c, ds, bd, is);
799+ if (bit_depth[c] == 0 )
800+ bit_depth[c] = 32 ;
801+ siz.set_component (c, ojph::point (1 ,1 ), bit_depth[c], true );
817802 }
803+ pfm.configure (bit_depth);
804+
818805 siz.set_image_offset (image_offset);
819806 siz.set_tile_size (tile_size);
820807 siz.set_tile_offset (tile_offset);
@@ -828,7 +815,7 @@ int main(int argc, char * argv[]) {
828815 if (num_comps == 1 )
829816 {
830817 if (employ_color_transform != -1 )
831- OJPH_WARN (0x01000092 ,
818+ OJPH_WARN (0x01000091 ,
832819 " -colour_trans option is not needed and was not used; "
833820 " this is because the image has one component only\n " );
834821 }
@@ -840,29 +827,30 @@ int main(int argc, char * argv[]) {
840827 cod.set_color_transform (employ_color_transform == 1 );
841828 }
842829 cod.set_reversible (reversible);
843- if (!reversible && quantization_step != -1 .0f )
830+ if (!reversible) {
831+ const float min_step = 1 .0f / 16384 .0f ;
832+ if (quantization_step == -1 .0f )
833+ quantization_step = min_step;
834+ else
835+ quantization_step = ojph_max (quantization_step, min_step);
844836 codestream.access_qcd ().set_irrev_quant (quantization_step);
837+ }
845838
839+ // Note: Even if only ALL_COMPS is set to
840+ // OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
841+ // one ALL_COMPS NLT marker segment is needed, or multiple
842+ // per component NLT marker segments are needed (when the components
843+ // have different bit depths or signedness).
844+ // Of course for .pfm images all components should have the same
845+ // bit depth and signedness.
846846 ojph::param_nlt nlt = codestream.access_nlt ();
847- if (reversible) {
848- // Note: Even if only ALL_COMPS is set to
849- // OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
850- // one ALL_COMPS NLT marker segment is needed, or multiple
851- // per component NLT marker segments are needed (when the components
852- // have different bit depths or signedness).
853- // Of course for .pfm images all components should have the same
854- // bit depth and signedness.
855- if (all_the_same)
856- nlt.set_nonlinear_transform (ojph::param_nlt::ALL_COMPS,
857- ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
858- else
859- for (ojph::ui32 c = 0 ; c < num_comps; ++c)
860- nlt.set_nonlinear_transform (c,
861- ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
862- }
847+ if (all_the_same)
848+ nlt.set_nonlinear_transform (ojph::param_nlt::ALL_COMPS,
849+ ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
863850 else
864- OJPH_ERROR (0x01000093 , " We currently support lossless only for "
865- " pfm images; this may change in the future." );
851+ for (ojph::ui32 c = 0 ; c < num_comps; ++c)
852+ nlt.set_nonlinear_transform (c,
853+ ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
866854
867855 codestream.set_planar (false );
868856 if (profile_string[0 ] != ' \0 ' )
@@ -872,13 +860,16 @@ int main(int argc, char * argv[]) {
872860 codestream.request_tlm_marker (tlm_marker);
873861
874862 if (dims.w != 0 || dims.h != 0 )
875- OJPH_WARN (0x01000094 ,
863+ OJPH_WARN (0x01000092 ,
876864 " -dims option is not needed and was not used\n " );
877865 if (num_components != 0 )
878- OJPH_WARN (0x01000095 ,
866+ OJPH_WARN (0x01000093 ,
879867 " -num_comps is not needed and was not used\n " );
868+ if (is_signed[0 ] != -1 )
869+ OJPH_WARN (0x01000094 ,
870+ " -signed is not needed and was not used\n " );
880871 if (comp_downsampling[0 ].x != 0 || comp_downsampling[0 ].y != 0 )
881- OJPH_WARN (0x01000096 ,
872+ OJPH_WARN (0x01000095 ,
882873 " -downsamp is not needed and was not used\n " );
883874
884875 base = &pfm;
0 commit comments