@@ -361,7 +361,7 @@ static
361361bool get_arguments (int argc, char *argv[], char *&input_filename,
362362 char *&output_filename, char *&progression_order,
363363 char *&profile_string, ojph::ui32 &num_decompositions,
364- float &quantization_step, bool &reversible,
364+ float &quantization_step, int &qfactor, bool &reversible,
365365 int &employ_color_transform,
366366 const int max_num_precincts, int &num_precincts,
367367 ojph::size *precinct_size, ojph::size& block_size,
@@ -383,6 +383,7 @@ bool get_arguments(int argc, char *argv[], char *&input_filename,
383383 interpreter.reinterpret (" -profile" , profile_string);
384384 interpreter.reinterpret (" -num_decomps" , num_decompositions);
385385 interpreter.reinterpret (" -qstep" , quantization_step);
386+ interpreter.reinterpret (" -qfactor" , qfactor);
386387 interpreter.reinterpret (" -reversible" , reversible);
387388 interpreter.reinterpret_to_bool (" -colour_trans" , employ_color_transform);
388389 interpreter.reinterpret (" -num_comps" , num_comps);
@@ -498,6 +499,7 @@ int main(int argc, char * argv[]) {
498499 char *com_string = NULL ;
499500 ojph::ui32 num_decompositions = 5 ;
500501 float quantization_step = -1 .0f ;
502+ int qfactor = -1 ;
501503 bool reversible = false ;
502504 int employ_color_transform = -1 ;
503505
@@ -542,6 +544,10 @@ int main(int argc, char * argv[]) {
542544 " compression; quantization steps size for all subbands are\n "
543545 " derived from this value. {The default value for 8bit\n "
544546 " images is 0.0039}\n "
547+ " -qfactor (1...100) compression quality factor; 1 is worst\n "
548+ " quality and 100 is best quality. Only valid for\n "
549+ " images with 1 or 3 components. Cannot be used\n "
550+ " together with -qstep.\n "
545551 " -reversible <true | false> If this is 'false', an irreversible or\n "
546552 " lossy compression is employed, using the 9/7 wavelet\n "
547553 " transform; if 'true', a reversible compression is\n "
@@ -622,7 +628,8 @@ int main(int argc, char * argv[]) {
622628 }
623629 if (!get_arguments (argc, argv, input_filename, output_filename,
624630 prog_order, profile_string, num_decompositions,
625- quantization_step, reversible, employ_color_transform,
631+ quantization_step, qfactor, reversible,
632+ employ_color_transform,
626633 max_precinct_sizes, num_precincts, precinct_size,
627634 block_size, dims, image_offset, tile_size, tile_offset,
628635 max_num_comps, num_components,
@@ -634,6 +641,13 @@ int main(int argc, char * argv[]) {
634641 return -1 ;
635642 }
636643
644+ if (qfactor != -1 && quantization_step != -1 .0f )
645+ OJPH_ERROR (0x010000A1 ,
646+ " -qfactor and -qstep cannot be used together\n " );
647+ if (qfactor != -1 && (qfactor < 1 || qfactor > 100 ))
648+ OJPH_ERROR (0x010000A2 ,
649+ " -qfactor must be between 1 and 100\n " );
650+
637651 clock_t begin = clock ();
638652
639653 try
@@ -686,6 +700,9 @@ int main(int argc, char * argv[]) {
686700 cod.set_reversible (reversible);
687701 if (!reversible && quantization_step != -1 .0f )
688702 codestream.access_qcd ().set_irrev_quant (quantization_step);
703+ if (!reversible && qfactor != -1 )
704+ codestream.access_qcd ().set_qfactor (0 ,
705+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
689706 if (profile_string[0 ] != ' \0 ' )
690707 codestream.set_profile (profile_string);
691708 codestream.set_tilepart_divisions (tileparts_at_resolutions,
@@ -742,6 +759,12 @@ int main(int argc, char * argv[]) {
742759 cod.set_reversible (reversible);
743760 if (!reversible && quantization_step != -1 .0f )
744761 codestream.access_qcd ().set_irrev_quant (quantization_step);
762+ if (!reversible && qfactor != -1 ) {
763+ ojph::param_qcd qcd = codestream.access_qcd ();
764+ qcd.set_qfactor (0 , ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
765+ qcd.set_qfactor (1 , ojph::param_qcd::OJPH_COMP_CB , (ojph::ui8)qfactor);
766+ qcd.set_qfactor (2 , ojph::param_qcd::OJPH_COMP_CR , (ojph::ui8)qfactor);
767+ }
745768 codestream.set_planar (false );
746769 if (profile_string[0 ] != ' \0 ' )
747770 codestream.set_profile (profile_string);
@@ -820,7 +843,20 @@ int main(int argc, char * argv[]) {
820843 cod.set_color_transform (employ_color_transform == 1 );
821844 }
822845 cod.set_reversible (reversible);
823- if (!reversible) {
846+ if (!reversible && qfactor != -1 ) {
847+ ojph::param_qcd qcd = codestream.access_qcd ();
848+ if (num_comps == 1 ) {
849+ qcd.set_qfactor (0 ,
850+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
851+ } else {
852+ qcd.set_qfactor (0 ,
853+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
854+ qcd.set_qfactor (1 ,
855+ ojph::param_qcd::OJPH_COMP_CB , (ojph::ui8)qfactor);
856+ qcd.set_qfactor (2 ,
857+ ojph::param_qcd::OJPH_COMP_CR , (ojph::ui8)qfactor);
858+ }
859+ } else if (!reversible) {
824860 const float min_step = 1 .0f / 16384 .0f ;
825861 if (quantization_step == -1 .0f )
826862 quantization_step = min_step;
@@ -898,6 +934,24 @@ int main(int argc, char * argv[]) {
898934 cod.set_reversible (reversible);
899935 if (!reversible && quantization_step != -1 )
900936 codestream.access_qcd ().set_irrev_quant (quantization_step);
937+ if (!reversible && qfactor != -1 ) {
938+ if (num_comps != 1 && num_comps != 3 )
939+ OJPH_ERROR (0x010000A3 ,
940+ " -qfactor is only supported for images with 1 or 3 "
941+ " components\n " );
942+ ojph::param_qcd qcd = codestream.access_qcd ();
943+ if (num_comps == 1 ) {
944+ qcd.set_qfactor (0 ,
945+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
946+ } else {
947+ qcd.set_qfactor (0 ,
948+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
949+ qcd.set_qfactor (1 ,
950+ ojph::param_qcd::OJPH_COMP_CB , (ojph::ui8)qfactor);
951+ qcd.set_qfactor (2 ,
952+ ojph::param_qcd::OJPH_COMP_CR , (ojph::ui8)qfactor);
953+ }
954+ }
901955 codestream.set_planar (false );
902956 if (profile_string[0 ] != ' \0 ' )
903957 codestream.set_profile (profile_string);
@@ -983,6 +1037,24 @@ int main(int argc, char * argv[]) {
9831037 cod.set_reversible (reversible);
9841038 if (!reversible && quantization_step != -1 .0f )
9851039 codestream.access_qcd ().set_irrev_quant (quantization_step);
1040+ if (!reversible && qfactor != -1 ) {
1041+ if (num_components != 1 && num_components != 3 )
1042+ OJPH_ERROR (0x010000A4 ,
1043+ " -qfactor is only supported for images with 1 or 3 "
1044+ " components\n " );
1045+ ojph::param_qcd qcd = codestream.access_qcd ();
1046+ if (num_components == 1 ) {
1047+ qcd.set_qfactor (0 ,
1048+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
1049+ } else {
1050+ qcd.set_qfactor (0 ,
1051+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
1052+ qcd.set_qfactor (1 ,
1053+ ojph::param_qcd::OJPH_COMP_CB , (ojph::ui8)qfactor);
1054+ qcd.set_qfactor (2 ,
1055+ ojph::param_qcd::OJPH_COMP_CR , (ojph::ui8)qfactor);
1056+ }
1057+ }
9861058 codestream.set_planar (true );
9871059 if (profile_string[0 ] != ' \0 ' )
9881060 codestream.set_profile (profile_string);
@@ -1035,6 +1107,9 @@ int main(int argc, char * argv[]) {
10351107 cod.set_reversible (reversible);
10361108 if (!reversible && quantization_step != -1 .0f )
10371109 codestream.access_qcd ().set_irrev_quant (quantization_step);
1110+ if (!reversible && qfactor != -1 )
1111+ codestream.access_qcd ().set_qfactor (0 ,
1112+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
10381113 codestream.set_planar (true );
10391114 if (profile_string[0 ] != ' \0 ' )
10401115 codestream.set_profile (profile_string);
@@ -1075,6 +1150,24 @@ int main(int argc, char * argv[]) {
10751150 cod.set_reversible (reversible);
10761151 if (!reversible && quantization_step != -1 )
10771152 codestream.access_qcd ().set_irrev_quant (quantization_step);
1153+ if (!reversible && qfactor != -1 ) {
1154+ if (num_comps != 1 && num_comps != 3 )
1155+ OJPH_ERROR (0x010000A5 ,
1156+ " -qfactor is only supported for images with 1 or 3 "
1157+ " components\n " );
1158+ ojph::param_qcd qcd = codestream.access_qcd ();
1159+ if (num_comps == 1 ) {
1160+ qcd.set_qfactor (0 ,
1161+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
1162+ } else {
1163+ qcd.set_qfactor (0 ,
1164+ ojph::param_qcd::OJPH_COMP_Y , (ojph::ui8)qfactor);
1165+ qcd.set_qfactor (1 ,
1166+ ojph::param_qcd::OJPH_COMP_CB , (ojph::ui8)qfactor);
1167+ qcd.set_qfactor (2 ,
1168+ ojph::param_qcd::OJPH_COMP_CR , (ojph::ui8)qfactor);
1169+ }
1170+ }
10781171 codestream.set_planar (false );
10791172 if (profile_string[0 ] != ' \0 ' )
10801173 codestream.set_profile (profile_string);
0 commit comments