362 char *&output_filename,
char *&progression_order,
363 char *&profile_string,
ojph::ui32 &num_decompositions,
364 float &quantization_step,
bool &reversible,
365 int &employ_color_transform,
366 const int max_num_precincts,
int &num_precincts,
374 bool& tlm_marker,
bool& tileparts_at_resolutions,
375 bool& tileparts_at_components,
char *&com_string)
378 interpreter.
init(argc, argv);
382 interpreter.
reinterpret(
"-prog_order", progression_order);
383 interpreter.
reinterpret(
"-profile", profile_string);
384 interpreter.
reinterpret(
"-num_decomps", num_decompositions);
385 interpreter.
reinterpret(
"-qstep", quantization_step);
386 interpreter.
reinterpret(
"-reversible", reversible);
389 interpreter.
reinterpret(
"-tlm_marker", tlm_marker);
398 throw "more than 255 components is not supported";
399 if (num_comps > max_num_comps)
401 max_num_comps = num_comps;
421 tileparts_at_components);
424 interpreter.
reinterpret(
"-block_size", &block_interpreter);
425 interpreter.
reinterpret(
"-dims", &dims_interpreter);
426 interpreter.
reinterpret(
"-image_offset", &img_off_interpreter);
427 interpreter.
reinterpret(
"-tile_size", &tile_size_interpreter);
428 interpreter.
reinterpret(
"-tile_offset", &tile_off_interpreter);
433 interpreter.
reinterpret(
"-tileparts", &tp_div_interpreter);
435 catch (
const char *s)
442 printf(
"The following arguments were not interpreted:\n");
446 printf(
"%s\n", t.
arg);
487int main(
int argc,
char * argv[]) {
488 char *input_filename = NULL;
489 char *output_filename = NULL;
490 char prog_order_store[] =
"RPCL";
491 char *prog_order = prog_order_store;
492 char profile_string_store[] =
"";
493 char *profile_string = profile_string_store;
494 char *com_string = NULL;
496 float quantization_step = -1.0f;
497 bool reversible =
false;
498 int employ_color_transform = -1;
500 const int max_precinct_sizes = 33;
502 int num_precincts = -1;
513 ojph::si32 is_signed_store[initial_num_comps] = {-1, -1, -1, -1};
516 ojph::ui32 bit_depth_store[initial_num_comps] = {0, 0, 0, 0};
520 ojph::point *comp_downsampling = downsampling_store;
521 bool tlm_marker =
false;
522 bool tileparts_at_resolutions =
false;
523 bool tileparts_at_components =
false;
527 "\nThe following arguments are necessary:\n"
528#ifdef OJPH_ENABLE_TIFF_SUPPORT
529 " -i input file name (either pgm, ppm, tif(f), or raw(yuv))\n"
531 " -i input file name (either pgm, ppm, or raw(yuv))\n"
533 " -o output file name\n\n"
535 "The following option has a default value (optional):\n"
536 " -num_decomps (5) number of decompositions\n"
537 " -qstep (0.00001...0.5) quantization step size for lossy\n"
538 " compression; quantization steps size for all subbands are\n"
539 " derived from this value. {The default value for 8bit\n"
540 " images is 0.0039}\n"
541 " -reversible (false) for irreversible; this should be false to perform\n"
542 " lossy compression using the 9/7 wavelet transform;\n"
543 " or true to perform reversible compression, where\n"
544 " the 5/3 wavelet is employed with lossless compression.\n"
545 " -colour_trans (true) this option employs a color transform, to\n"
546 " transform RGB color images into the YUV domain.\n"
547 " This option should not be used with YUV images, because\n"
548 " they have already been transformed.\n"
549 " If there are three color components that are\n"
550 " downsampled by the same amount then the color transform\n"
551 " can be true or false. This option is also available\n"
552 " when there are more than three colour components,\n"
553 " where it is applied to the first three colour\n"
555 " it has already been applied to convert the original RGB\n"
556 " or whatever the original format to YUV.\n"
557 " -prog_order (RPCL) is the progression order, and can be one of:\n"
558 " LRCP, RLCP, RPCL, PCRL, CPRL\n"
559 " -block_size {x,y} (64,64) where x and y are the height and width of\n"
560 " a codeblock. In unix-like environment, { and } must be\n"
561 " proceeded by a ""\\""\n"
562 " -precincts {x,y},{x,y},...,{x,y} where {x,y} is the precinct size\n"
563 " starting from the coarest resolution; the last precinct\n"
564 " is repeated for all finer resolutions\n"
565 " -tile_offset {x,y} tile offset. \n"
566 " -tile_size {x,y} tile width and height. \n"
567 " -image_offset {x,y} image offset from origin. \n"
568 " -tileparts (None) employ tilepart divisions at each resolution, \n"
569 " indicated by the letter R, and/or component, indicated \n"
570 " by the letter C. For both, use \"-tileparts RC\".\n"
571 " -tlm_marker (false) insert a TLM marker, either \"true\" or \"false\"\n"
572 " -profile (None) is the profile, the code will check if the \n"
573 " selected options meet the profile. Currently only \n"
574 " BROADCAST and IMF are supported. This automatically \n"
575 " sets tlm_marker to true and tileparts to C.\n"
576 " -com (None) if set, inserts a COM marker with the specified\n"
577 " string. If the string has spaces, please use\n"
578 " double quotes, as in -com \"This is a comment\"\n"
581 "When the input file is a YUV file, these arguments need to be \n"
583 " -dims {x,y} x is image width, y is height\n"
584 " -num_comps number of components\n"
585 " -signed a comma-separated list of true or false parameters, one\n"
586 " for each component; for example: true,false,false\n"
587 " -bit_depth a comma-separated list of bit depth values, one per \n"
588 " component; for example: 12,10,10\n"
589 " -downsamp {x,y},{x,y},...,{x,y} a list of x,y points, one for each\n"
590 " component; for example {1,1},{2,2},{2,2}\n\n"
594 if (!
get_arguments(argc, argv, input_filename, output_filename,
595 prog_order, profile_string, num_decompositions,
596 quantization_step, reversible, employ_color_transform,
597 max_precinct_sizes, num_precincts, precinct_size,
598 block_size, dims, image_offset, tile_size, tile_offset,
599 max_num_comps, num_components,
600 num_comp_downsamps, comp_downsampling,
601 num_bit_depths, bit_depth, num_is_signed, is_signed,
602 tlm_marker, tileparts_at_resolutions,
603 tileparts_at_components, com_string))
608 clock_t begin = clock();
618#ifdef OJPH_ENABLE_TIFF_SUPPORT
623 if (input_filename == NULL)
624 OJPH_ERROR(0x01000007,
"please specify an input file name using"
625 " the -i command line option");
626 if (output_filename == NULL)
627 OJPH_ERROR(0x01000008,
"please specify an output file name using"
628 " the -o command line option");
635 ppm.
open(input_filename);
640 assert(num_comps == 1);
652 if (num_precincts != -1)
657 if (!reversible && quantization_step != -1.0f)
659 if (profile_string[0] !=
'\0')
662 tileparts_at_components);
665 if (employ_color_transform != -1)
667 "-colour_trans option is not needed and was not used\n");
668 if (dims.
w != 0 || dims.
h != 0)
670 "-dims option is not needed and was not used\n");
671 if (num_components != 0)
673 "-num_comps is not needed and was not used\n");
674 if (is_signed[0] != -1)
676 "-signed is not needed and was not used\n");
677 if (bit_depth[0] != 0)
679 "-bit_depth is not needed and was not used\n");
680 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
682 "-downsamp is not needed and was not used\n");
688 ppm.
open(input_filename);
693 assert(num_comps == 3);
705 if (num_precincts != -1)
708 if (employ_color_transform == -1)
713 if (!reversible && quantization_step != -1.0f)
716 if (profile_string[0] !=
'\0')
719 tileparts_at_components);
722 if (dims.
w != 0 || dims.
h != 0)
724 "-dims option is not needed and was not used\n");
725 if (num_components != 0)
727 "-num_comps is not needed and was not used\n");
728 if (is_signed[0] != -1)
730 "-signed is not needed and was not used\n");
731 if (bit_depth[0] != 0)
733 "-bit_depth is not needed and was not used\n");
734 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
736 "-downsamp is not needed and was not used\n");
740#ifdef OJPH_ENABLE_TIFF_SUPPORT
743 tif.
open(input_filename);
746 image_offset.
y + tif.get_size().h));
747 ojph::ui32 num_comps = tif.get_num_components();
749 if(num_bit_depths > 0 )
750 tif.set_bit_depth(num_bit_depths, bit_depth);
753 tif.get_bit_depth(c), tif.get_is_signed(c));
761 if (num_precincts != -1)
764 if (employ_color_transform == -1 && num_comps >= 3)
769 if (!reversible && quantization_step != -1)
772 if (profile_string[0] !=
'\0')
775 tileparts_at_components);
778 if (dims.
w != 0 || dims.
h != 0)
780 "-dims option is not needed and was not used\n");
781 if (num_components != 0)
783 "-num_comps is not needed and was not used\n");
784 if (is_signed[0] != -1)
786 "-signed is not needed and was not used\n");
787 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
789 "-downsamp is not needed and was not used\n");
797 if (dims.
w == 0 || dims.
h == 0)
799 "-dims option must have positive dimensions\n");
801 image_offset.
y + dims.
h));
802 if (num_components <= 0)
804 "-num_comps option is missing and must be provided\n");
805 if (num_is_signed <= 0)
807 "-signed option is missing and must be provided\n");
808 if (num_bit_depths <= 0)
810 "-bit_depth option is missing and must be provided\n");
811 if (num_comp_downsamps <= 0)
813 "-downsamp option is missing and must be provided\n");
819 ojph::ui32 last_signed_idx = 0, last_bit_depth_idx = 0;
822 for (
ojph::ui32 c = 0; c < num_components; ++c)
825 [c < num_comp_downsamps ? c : last_downsamp_idx];
826 last_downsamp_idx += last_downsamp_idx+1 < num_comp_downsamps ? 1:0;
827 ojph::ui32 bd = bit_depth[c<num_bit_depths ? c : last_bit_depth_idx];
828 last_bit_depth_idx += last_bit_depth_idx + 1 < num_bit_depths ? 1:0;
829 int is = is_signed[c < num_is_signed ? c : last_signed_idx];
830 last_signed_idx += last_signed_idx + 1 < num_is_signed ? 1 : 0;
840 if (num_precincts != -1)
843 if (employ_color_transform == -1)
847 "We currently do not support color transform on raw(yuv) files."
848 " In any case, this not a normal usage scenario. The OpenJPH "
849 "library however does support that, but ojph_compress.cpp must be "
850 "modified to send all lines from one component before moving to "
851 "the next component; this requires buffering components outside"
852 " of the OpenJPH library");
854 if (!reversible && quantization_step != -1.0f)
857 if (profile_string[0] !=
'\0')
860 tileparts_at_components);
863 yuv.
open(input_filename);
869 if (dims.
w == 0 || dims.
h == 0)
871 "-dims option must have positive dimensions\n");
873 image_offset.
y + dims.
h));
874 if (num_components != 1)
876 "-num_comps must be 1\n");
877 if (num_is_signed <= 0)
879 "-signed option is missing and must be provided\n");
880 if (num_bit_depths <= 0)
882 "-bit_depth option is missing and must be provided\n");
883 if (num_comp_downsamps <= 0)
885 "-downsamp option is missing and must be provided\n");
890 siz.
set_component(0, comp_downsampling[0], bit_depth[0], is_signed[0]);
898 if (num_precincts != -1)
901 if (employ_color_transform != -1)
903 "color transform is not meaningless since .raw files are single "
906 if (!reversible && quantization_step != -1.0f)
909 if (profile_string[0] !=
'\0')
912 tileparts_at_components);
915 raw.
open(input_filename);
920 dpx.
open(input_filename);
938 if (num_precincts != -1)
941 if (employ_color_transform == -1 && num_comps >= 3)
946 if (!reversible && quantization_step != -1)
949 if (profile_string[0] !=
'\0')
952 tileparts_at_components);
955 if (dims.
w != 0 || dims.
h != 0)
957 "-dims option is not needed and was not used\n");
958 if (num_components != 0)
960 "-num_comps is not needed and was not used\n");
961 if (is_signed[0] != -1)
963 "-signed is not needed and was not used\n");
964 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
966 "-downsamp is not needed and was not used\n");
971#if defined( OJPH_ENABLE_TIFF_SUPPORT)
973 "unknown input file extension; only pgm, ppm, dpx, tif(f),"
974 " or raw(yuv) are supported\n");
977 "unknown input file extension; only pgm, ppm, dpx,"
978 " or raw(yuv) are supported\n");
983 "Please supply a proper input filename with a proper three-letter "
990 j2c_file.
open(output_filename);
991 codestream.
write_headers(&j2c_file, &com_ex, com_string ? 1 : 0);
1005 assert(c == next_comp);
1006 base->
read(cur_line, next_comp);
1007 cur_line = codestream.
exchange(cur_line, next_comp);
1020 assert(c == next_comp);
1021 base->
read(cur_line, next_comp);
1022 cur_line = codestream.
exchange(cur_line, next_comp);
1031 if (max_num_comps != initial_num_comps)
1033 delete[] comp_downsampling;
1038 catch (
const std::exception& e)
1040 const char *p = e.what();
1041 if (strncmp(p,
"ojph error", 10) != 0)
1046 clock_t end = clock();
1047 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
1048 printf(
"Elapsed time = %f\n", elapsed_secs);
static bool get_arguments(int argc, char *argv[], char *&input_filename, char *&output_filename, char *&progression_order, char *&profile_string, ojph::ui32 &num_decompositions, float &quantization_step, bool &reversible, int &employ_color_transform, const int max_num_precincts, int &num_precincts, ojph::size *precinct_size, ojph::size &block_size, ojph::size &dims, ojph::point &image_offset, ojph::size &tile_size, ojph::point &tile_offset, ojph::ui32 &max_num_comps, ojph::ui32 &num_comps, ojph::ui32 &num_comp_downsamps, ojph::point *&comp_downsamp, ojph::ui32 &num_bit_depths, ojph::ui32 *&bit_depth, ojph::ui32 &num_is_signed, ojph::si32 *&is_signed, bool &tlm_marker, bool &tileparts_at_resolutions, bool &tileparts_at_components, char *&com_string)