327 char *&output_filename,
char *&progression_order,
328 char *&profile_string,
ojph::ui32 &num_decompositions,
329 float &quantization_step,
bool &reversible,
330 int &employ_color_transform,
331 const int max_num_precincts,
int &num_precincts,
341 interpreter.
init(argc, argv);
345 interpreter.
reinterpret(
"-prog_order", progression_order);
346 interpreter.
reinterpret(
"-profile", profile_string);
347 interpreter.
reinterpret(
"-num_decomps", num_decompositions);
348 interpreter.
reinterpret(
"-qstep", quantization_step);
349 interpreter.
reinterpret(
"-reversible", reversible);
359 throw "more than 255 components is not supported";
360 if (num_comps > max_num_comps)
362 max_num_comps = num_comps;
384 interpreter.
reinterpret(
"-block_size", &block_interpreter);
385 interpreter.
reinterpret(
"-dims", &dims_interpreter);
386 interpreter.
reinterpret(
"-image_offset", &img_off_interpreter);
387 interpreter.
reinterpret(
"-tile_size", &tile_size_interpreter);
388 interpreter.
reinterpret(
"-tile_offset", &tile_off_interpreter);
394 catch (
const char *s)
401 printf(
"The following arguments were not interpreted:\n");
405 printf(
"%s\n", t.
arg);
429int main(
int argc,
char * argv[]) {
430 char *input_filename = NULL;
431 char *output_filename = NULL;
432 char prog_order_store[] =
"RPCL";
433 char *prog_order = prog_order_store;
434 char profile_string_store[] =
"";
435 char *profile_string = profile_string_store;
437 float quantization_step = -1.0f;
438 bool reversible =
false;
439 int employ_color_transform = -1;
441 const int max_precinct_sizes = 33;
443 int num_precincts = -1;
454 ojph::si32 is_signed_store[initial_num_comps] = {-1, -1, -1, -1};
457 ojph::ui32 bit_depth_store[initial_num_comps] = {0, 0, 0, 0};
461 ojph::point *comp_downsampling = downsampling_store;
465 "\nThe following arguments are necessary:\n"
466#ifdef OJPH_ENABLE_TIFF_SUPPORT
467 " -i input file name (either pgm, ppm, tif(f), or raw(yuv))\n"
469 " -i input file name (either pgm, ppm, or raw(yuv))\n"
471 " -o output file name\n\n"
473 "The following option has a default value (optional):\n"
474 " -num_decomps (5) number of decompositions\n"
475 " -qstep (0.00001...0.5) quantization step size for lossy\n"
476 " compression; quantization steps size for all subbands are\n"
477 " derived from this value. {The default value for 8bit\n"
478 " images is 0.0039}\n"
479 " -reversible (false) for irreversible; this should be false to perform\n"
480 " lossy compression using the 9/7 wavelet transform;\n"
481 " or true to perform reversible compression, where\n"
482 " the 5/3 wavelet is employed with lossless compression.\n"
483 " -colour_trans (true) this option employs a color transform, to\n"
484 " transform RGB color images into the YUV domain.\n"
485 " This option should not be used with YUV images, because\n"
486 " they have already been transformed.\n"
487 " If there are three color components that are\n"
488 " downsampled by the same amount then the color transform\n"
489 " can be true or false. This option is also available\n"
490 " when there are more than three colour components,\n"
491 " where it is applied to the first three colour\n"
493 " it has already been applied to convert the original RGB\n"
494 " or whatever the original format to YUV.\n"
495 " -prog_order (RPCL) is the progression order, and can be one of:\n"
496 " LRCP, RLCP, RPCL, PCRL, CPRL\n"
497 " -block_size {x,y} (64,64) where x and y are the height and width of\n"
498 " a codeblock. In unix-like environment, { and } must be\n"
499 " proceeded by a ""\\""\n"
500 " -precincts {x,y},{x,y},...,{x,y} where {x,y} is the precinct size\n"
501 " starting from the coarest resolution; the last precinct\n"
502 " is repeated for all finer resolutions\n"
503 " -tile_offset {x,y} tile offset. \n"
504 " -tile_size {x,y} tile width and height. \n"
505 " -image_offset {x,y} image offset from origin. \n"
506 " -profile (None) is the profile, the code will check if the \n"
507 " selected options meet the profile. Currently only \n"
508 " BROADCAST and IMF are supported\n"
511 "When the input file is a YUV file, these arguments need to be \n"
513 " -dims {x,y} x is image width, y is height\n"
514 " -num_comps number of components\n"
515 " -signed a comma-separated list of true or false parameters, one\n"
516 " for each component; for example: true,false,false\n"
517 " -bit_depth a comma-separated list of bit depth values, one per \n"
518 " component; for example: 12,10,10\n"
519 " -downsamp {x,y},{x,y},...,{x,y} a list of x,y points, one for each\n"
520 " component; for example {1,1},{2,2},{2,2}\n\n"
524 if (!
get_arguments(argc, argv, input_filename, output_filename,
525 prog_order, profile_string, num_decompositions,
526 quantization_step, reversible, employ_color_transform,
527 max_precinct_sizes, num_precincts, precinct_size,
528 block_size, dims, image_offset, tile_size, tile_offset,
529 max_num_comps, num_components,
530 num_comp_downsamps, comp_downsampling,
531 num_bit_depths, bit_depth, num_is_signed, is_signed))
536 clock_t begin = clock();
544#ifdef OJPH_ENABLE_TIFF_SUPPORT
548 if (input_filename == NULL)
549 OJPH_ERROR(0x01000007,
"please specify an input file name using"
550 " the -i command line option");
551 if (output_filename == NULL)
552 OJPH_ERROR(0x01000008,
"please specify an output file name using"
553 " the -o command line option");
558 if (strncmp(
".pgm", v, 4) == 0)
560 ppm.
open(input_filename);
565 assert(num_comps == 1);
577 if (num_precincts != -1)
582 if (!reversible && quantization_step != -1.0f)
584 if (profile_string[0] !=
'\0')
587 if (employ_color_transform != -1)
589 "-colour_trans option is not needed and was not used\n");
590 if (dims.
w != 0 || dims.
h != 0)
592 "-dims option is not needed and was not used\n");
593 if (num_components != 0)
595 "-num_comps is not needed and was not used\n");
596 if (is_signed[0] != -1)
598 "-signed is not needed and was not used\n");
599 if (bit_depth[0] != 0)
601 "-bit_depth is not needed and was not used\n");
602 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
604 "-downsamp is not needed and was not used\n");
608 else if (strncmp(
".ppm", v, 4) == 0)
610 ppm.
open(input_filename);
615 assert(num_comps == 3);
627 if (num_precincts != -1)
630 if (employ_color_transform == -1)
635 if (!reversible && quantization_step != -1.0f)
638 if (profile_string[0] !=
'\0')
641 if (dims.
w != 0 || dims.
h != 0)
643 "-dims option is not needed and was not used\n");
644 if (num_components != 0)
646 "-num_comps is not needed and was not used\n");
647 if (is_signed[0] != -1)
649 "-signed is not needed and was not used\n");
650 if (bit_depth[0] != 0)
652 "-bit_depth is not needed and was not used\n");
653 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
655 "-downsamp is not needed and was not used\n");
659#ifdef OJPH_ENABLE_TIFF_SUPPORT
660 else if (strncmp(
".tif", v, 4) == 0 || strncmp(
".tiff", v, 5) == 0)
662 tif.
open(input_filename);
665 image_offset.
y + tif.get_size().h));
666 ojph::ui32 num_comps = tif.get_num_components();
668 if(num_bit_depths > 0 )
669 tif.set_bit_depth(num_bit_depths, bit_depth);
672 tif.get_bit_depth(c), tif.get_is_signed(c));
680 if (num_precincts != -1)
683 if (employ_color_transform == -1 && num_comps >= 3)
688 if (!reversible && quantization_step != -1)
691 if (profile_string[0] !=
'\0')
694 if (dims.
w != 0 || dims.
h != 0)
696 "-dims option is not needed and was not used\n");
697 if (num_components != 0)
699 "-num_comps is not needed and was not used\n");
700 if (is_signed[0] != -1)
702 "-signed is not needed and was not used\n");
703 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
705 "-downsamp is not needed and was not used\n");
710 else if (strncmp(
".yuv", v, 4) == 0 || strncmp(
".raw", v, 4) == 0)
713 if (dims.
w == 0 || dims.
h == 0)
715 "-dims option must have positive dimensions\n");
717 image_offset.
y + dims.
h));
718 if (num_components <= 0)
720 "-num_comps option is missing and must be provided\n");
721 if (num_is_signed <= 0)
723 "-signed option is missing and must be provided\n");
724 if (num_bit_depths <= 0)
726 "-bit_depth option is missing and must be provided\n");
727 if (num_comp_downsamps <= 0)
729 "-downsamp option is missing and must be provided\n");
735 ojph::ui32 last_signed_idx = 0, last_bit_depth_idx = 0;
738 for (
ojph::ui32 c = 0; c < num_components; ++c)
741 [c < num_comp_downsamps ? c : last_downsamp_idx];
742 last_downsamp_idx += last_downsamp_idx+1 < num_comp_downsamps ? 1:0;
743 ojph::ui32 bd = bit_depth[c<num_bit_depths ? c : last_bit_depth_idx];
744 last_bit_depth_idx += last_bit_depth_idx + 1 < num_bit_depths ? 1:0;
745 int is = is_signed[c < num_is_signed ? c : last_signed_idx];
746 last_signed_idx += last_signed_idx + 1 < num_is_signed ? 1 : 0;
756 if (num_precincts != -1)
759 if (employ_color_transform == -1)
763 "We currently do not support color transform on raw(yuv) files."
764 " In any case, this not a normal usage scenario. The OpenJPH "
765 "library however does support that, but ojph_compress.cpp must be "
766 "modified to send all lines from one component before moving to "
767 "the next component; this requires buffering components outside"
768 " of the OpenJPH library");
770 if (!reversible && quantization_step != -1.0f)
773 if (profile_string[0] !=
'\0')
776 yuv.
open(input_filename);
780#ifdef OJPH_ENABLE_TIFF_SUPPORT
782 "unknown input file extension; only pgm, ppm, tif(f), or"
783 " raw(yuv) are supported\n");
786 "unknown input file extension; only pgm, ppm, and raw(yuv)) are"
792 "Please supply a proper input filename with a proper three-letter "
796 j2c_file.
open(output_filename);
811 assert(c == next_comp);
812 base->
read(cur_line, next_comp);
813 cur_line = codestream.
exchange(cur_line, next_comp);
826 assert(c == next_comp);
827 base->
read(cur_line, next_comp);
828 cur_line = codestream.
exchange(cur_line, next_comp);
837 if (max_num_comps != initial_num_comps)
839 delete[] comp_downsampling;
844 catch (
const std::exception& e)
846 const char *p = e.what();
847 if (strncmp(p,
"ojph error", 10) != 0)
852 clock_t end = clock();
853 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
854 printf(
"Elapsed time = %f\n", elapsed_secs);
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)