From 83ec0cd62f70888c90671ea91cd056ecb6095bc1 Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Mon, 4 Apr 2011 18:37:32 -0700 Subject: STORM-746 : add new arguments for precincts and blocks on output, region and level on input, add code for input loading restriction --- .../llimage_libtest/llimage_libtest.cpp | 126 +++++++++++++++++++-- 1 file changed, 119 insertions(+), 7 deletions(-) (limited to 'indra/integration_tests') diff --git a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp index 365f5f758c..10d6ffb685 100644 --- a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp +++ b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp @@ -53,12 +53,28 @@ static const char USAGE[] = "\n" " -o, --output OR \n" " List of image files to create (assumes same order as for input files)\n" " OR 3 letters file type extension to convert each input file into.\n" +" -r, --region \n" +" Crop region on the input file in pixel.\n" +" Only used for j2c images. Default is no region cropping.\n" +" -d, --discard_level \n" +" Discard level max used on input. 0 is high resolution. Max discard level is 5.\n" +" This allows the input image to be clamped in resolution when loading.\n" +" Only valid for j2c images. Default is no discard.\n" +" -p, --precincts \n" +" Dimension of precincts in pixels. Precincts are assumed square and identical for\n" +" all levels. Note that this oprion also uses PLT and tile markers, \n" +" as well as RPCL order. Power of 2 must be used.\n" +" Only valid for output j2c images. Default is no precincts used.\n" +" -b, --blocks \n" +" Dimension of coding blocks in pixels. Blocks are assumed square. Power of 2 must\n" +" be used. Blocks must be smaller than precincts.\n" +" Only valid for output j2c images. Default is 64.\n" " -log, --logmetrics \n" " Log performance data for . Results in .slp\n" " Note: so far, only ImageCompressionTester has been tested.\n" -" -r, --analyzeperformance\n" +" -a, --analyzeperformance\n" " Create a report comparing _baseline.slp with current .slp\n" -" Results in _report.csv" +" Results in _report.csv\n" " -s, --image-stats\n" " Output stats for each input and output image.\n" "\n"; @@ -110,10 +126,11 @@ void output_image_stats(LLPointer image, const std::string &fi } // Load an image from file and return a raw (decompressed) instance of its data -LLPointer load_image(const std::string &src_filename, bool output_stats) +LLPointer load_image(const std::string &src_filename, bool output_stats, bool use_discard_level, int discard_level, bool use_region, int* region) { LLPointer image = create_image(src_filename); - + + // This just load the image file stream into a buffer. No decoding done. if (!image->load(src_filename)) { return NULL; @@ -131,6 +148,17 @@ LLPointer load_image(const std::string &src_filename, bool output_st } LLPointer raw_image = new LLImageRaw; + + // Set the image restriction on load in the case of a j2c image + if ((image->getCodec() == IMG_CODEC_J2C) && (use_discard_level || use_region)) + { + int discard = (use_discard_level ? discard_level : -1); + int* reg = (use_region ? region : NULL); + // That method doesn't exist (and likely, doesn't make sense) for any other image file format + // hence the required cryptic cast. + ((LLImageJ2C*)(image.get()))->initDecode(*raw_image, discard, reg); + } + if (!image->decode(raw_image, 0.0f)) { return NULL; @@ -280,8 +308,17 @@ int main(int argc, char** argv) // List of input and output files std::list input_filenames; std::list output_filenames; + // Other optional parsed arguments bool analyze_performance = false; bool image_stats = false; + bool use_region = false; + int region[4]; + bool use_discard_level = false; + int discard_level = 0; + bool use_precincts = false; + int precincts_size; + bool use_blocks = false; + int blocks_size; // Init whatever is necessary ll_init_apr(); @@ -323,6 +360,81 @@ int main(int argc, char** argv) file_name = argv[arg+1]; // Next argument and loop over } } + else if ((!strcmp(argv[arg], "--region") || !strcmp(argv[arg], "-r")) && arg < argc-1) + { + std::string value_str = argv[arg+1]; + int index = 0; + while (value_str[0] != '-') // if arg starts with '-', it's the next option + { + int value = atoi(value_str.c_str()); + region[index++] = value; + arg += 1; // Definitely skip that arg now we know it's a number + if ((arg + 1) == argc) // Break out of the loop if we reach the end of the arg list + break; + if (index == 4) // Break out of the loop if we captured 4 values already + break; + value_str = argv[arg+1]; // Next argument and loop over + } + if (index == 4) + { + use_region = true; + } + else + { + std::cout << "--region arguments invalid" << std::endl; + } + } + else if (!strcmp(argv[arg], "--discard_level") || !strcmp(argv[arg], "-d")) + { + std::string value_str; + if ((arg + 1) < argc) + { + value_str = argv[arg+1]; + } + if (((arg + 1) >= argc) || (value_str[0] == '-')) + { + std::cout << "No valid --discard_level argument given, discard_level ignored" << std::endl; + } + else + { + use_discard_level = true; + discard_level = atoi(value_str.c_str()); + } + } + else if (!strcmp(argv[arg], "--precincts") || !strcmp(argv[arg], "-p")) + { + std::string value_str; + if ((arg + 1) < argc) + { + value_str = argv[arg+1]; + } + if (((arg + 1) >= argc) || (value_str[0] == '-')) + { + std::cout << "No valid --precincts argument given, precincts ignored" << std::endl; + } + else + { + use_precincts = true; + precincts_size = atoi(value_str.c_str()); + } + } + else if (!strcmp(argv[arg], "--blocks") || !strcmp(argv[arg], "-b")) + { + std::string value_str; + if ((arg + 1) < argc) + { + value_str = argv[arg+1]; + } + if (((arg + 1) >= argc) || (value_str[0] == '-')) + { + std::cout << "No valid --blocks argument given, blocks ignored" << std::endl; + } + else + { + use_blocks = true; + blocks_size = atoi(value_str.c_str()); + } + } else if (!strcmp(argv[arg], "--logmetrics") || !strcmp(argv[arg], "-log")) { // '--logmetrics' needs to be specified with a named test metric argument @@ -346,7 +458,7 @@ int main(int argc, char** argv) break; } } - else if (!strcmp(argv[arg], "--analyzeperformance") || !strcmp(argv[arg], "-r")) + else if (!strcmp(argv[arg], "--analyzeperformance") || !strcmp(argv[arg], "-a")) { analyze_performance = true; } @@ -364,7 +476,7 @@ int main(int argc, char** argv) } if (analyze_performance && !LLFastTimer::sMetricLog) { - std::cout << "Cannot create perf report if no perf gathered (i.e. use argument -log with -r) -> exit" << std::endl; + std::cout << "Cannot create perf report if no perf gathered (i.e. use argument -log with -a) -> exit" << std::endl; return 0; } @@ -385,7 +497,7 @@ int main(int argc, char** argv) for (; in_file != in_end; ++in_file) { // Load file - LLPointer raw_image = load_image(*in_file, image_stats); + LLPointer raw_image = load_image(*in_file, image_stats, use_discard_level, discard_level, use_region, region); if (!raw_image) { std::cout << "Error: Image " << *in_file << " could not be loaded" << std::endl; -- cgit v1.2.3 From e752e918283acf95c1ed33d92a7bf34bbca83071 Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Mon, 4 Apr 2011 23:49:40 -0700 Subject: STORM-746 : add precincts and blocks arguments taken into account in j2c output --- .../llimage_libtest/llimage_libtest.cpp | 50 +++++++++++----------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'indra/integration_tests') diff --git a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp index 10d6ffb685..31d3e18877 100644 --- a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp +++ b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp @@ -126,7 +126,7 @@ void output_image_stats(LLPointer image, const std::string &fi } // Load an image from file and return a raw (decompressed) instance of its data -LLPointer load_image(const std::string &src_filename, bool output_stats, bool use_discard_level, int discard_level, bool use_region, int* region) +LLPointer load_image(const std::string &src_filename, int discard_level, int* region, bool output_stats) { LLPointer image = create_image(src_filename); @@ -150,13 +150,11 @@ LLPointer load_image(const std::string &src_filename, bool output_st LLPointer raw_image = new LLImageRaw; // Set the image restriction on load in the case of a j2c image - if ((image->getCodec() == IMG_CODEC_J2C) && (use_discard_level || use_region)) + if ((image->getCodec() == IMG_CODEC_J2C) && ((discard_level != -1) || (region != NULL))) { - int discard = (use_discard_level ? discard_level : -1); - int* reg = (use_region ? region : NULL); // That method doesn't exist (and likely, doesn't make sense) for any other image file format // hence the required cryptic cast. - ((LLImageJ2C*)(image.get()))->initDecode(*raw_image, discard, reg); + ((LLImageJ2C*)(image.get()))->initDecode(*raw_image, discard_level, region); } if (!image->decode(raw_image, 0.0f)) @@ -168,10 +166,18 @@ LLPointer load_image(const std::string &src_filename, bool output_st } // Save a raw image instance into a file -bool save_image(const std::string &dest_filename, LLPointer raw_image, bool output_stats) +bool save_image(const std::string &dest_filename, LLPointer raw_image, int blocks_size, int precincts_size, bool output_stats) { LLPointer image = create_image(dest_filename); + // Set the image restriction on load in the case of a j2c image + if ((image->getCodec() == IMG_CODEC_J2C) && ((blocks_size != -1) || (precincts_size != -1))) + { + // That method doesn't exist (and likely, doesn't make sense) for any other image file format + // hence the required cryptic cast. + ((LLImageJ2C*)(image.get()))->initEncode(*raw_image, blocks_size, precincts_size); + } + if (!image->encode(raw_image, 0.0f)) { return false; @@ -311,14 +317,10 @@ int main(int argc, char** argv) // Other optional parsed arguments bool analyze_performance = false; bool image_stats = false; - bool use_region = false; - int region[4]; - bool use_discard_level = false; - int discard_level = 0; - bool use_precincts = false; - int precincts_size; - bool use_blocks = false; - int blocks_size; + int* region = NULL; + int discard_level = -1; + int precincts_size = -1; + int blocks_size = -1; // Init whatever is necessary ll_init_apr(); @@ -364,6 +366,7 @@ int main(int argc, char** argv) { std::string value_str = argv[arg+1]; int index = 0; + region = new int[4]; while (value_str[0] != '-') // if arg starts with '-', it's the next option { int value = atoi(value_str.c_str()); @@ -375,13 +378,11 @@ int main(int argc, char** argv) break; value_str = argv[arg+1]; // Next argument and loop over } - if (index == 4) - { - use_region = true; - } - else + if (index != 4) { std::cout << "--region arguments invalid" << std::endl; + delete [] region; + region = NULL; } } else if (!strcmp(argv[arg], "--discard_level") || !strcmp(argv[arg], "-d")) @@ -397,8 +398,9 @@ int main(int argc, char** argv) } else { - use_discard_level = true; discard_level = atoi(value_str.c_str()); + // Clamp to the values accepted by the viewer + discard_level = llclamp(discard_level,0,5); } } else if (!strcmp(argv[arg], "--precincts") || !strcmp(argv[arg], "-p")) @@ -414,8 +416,8 @@ int main(int argc, char** argv) } else { - use_precincts = true; precincts_size = atoi(value_str.c_str()); + // *TODO: make sure precincts_size is a power of 2 } } else if (!strcmp(argv[arg], "--blocks") || !strcmp(argv[arg], "-b")) @@ -431,8 +433,8 @@ int main(int argc, char** argv) } else { - use_blocks = true; blocks_size = atoi(value_str.c_str()); + // *TODO: make sure blocks_size is a power of 2 } } else if (!strcmp(argv[arg], "--logmetrics") || !strcmp(argv[arg], "-log")) @@ -497,7 +499,7 @@ int main(int argc, char** argv) for (; in_file != in_end; ++in_file) { // Load file - LLPointer raw_image = load_image(*in_file, image_stats, use_discard_level, discard_level, use_region, region); + LLPointer raw_image = load_image(*in_file, discard_level, region, image_stats); if (!raw_image) { std::cout << "Error: Image " << *in_file << " could not be loaded" << std::endl; @@ -507,7 +509,7 @@ int main(int argc, char** argv) // Save file if (out_file != out_end) { - if (!save_image(*out_file, raw_image, image_stats)) + if (!save_image(*out_file, raw_image, blocks_size, precincts_size, image_stats)) { std::cout << "Error: Image " << *out_file << " could not be saved" << std::endl; } -- cgit v1.2.3 From 379e2e138d801ebf7f13d29512f76298aacf3dc5 Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Thu, 7 Apr 2011 16:41:57 -0700 Subject: STORM-746 : Fix bug in performance report output --- .../llimage_libtest/llimage_libtest.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/integration_tests') diff --git a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp index 31d3e18877..1466e44324 100644 --- a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp +++ b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp @@ -521,25 +521,25 @@ int main(int argc, char** argv) } } - // Stop the perf gathering system if needed - if (LLFastTimer::sMetricLog) - { - LLMetricPerformanceTesterBasic::deleteTester(LLFastTimer::sLogName); - sAllDone = true; - } - // Output perf data if requested by user if (analyze_performance) { - std::cout << "Analyzing performance" << std::endl; - std::string baseline_name = LLFastTimer::sLogName + "_baseline.slp"; std::string current_name = LLFastTimer::sLogName + ".slp"; std::string report_name = LLFastTimer::sLogName + "_report.csv"; + std::cout << "Analyzing performance, check report in : " << report_name << std::endl; + LLMetricPerformanceTesterBasic::doAnalysisMetrics(baseline_name, current_name, report_name); } + // Stop the perf gathering system if needed + if (LLFastTimer::sMetricLog) + { + LLMetricPerformanceTesterBasic::deleteTester(LLFastTimer::sLogName); + sAllDone = true; + } + // Cleanup and exit LLImage::cleanupClass(); if (fast_timer_log_thread) -- cgit v1.2.3 From cd363e8c87e176776f5db8fbaf60c264eabdaa3b Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Thu, 7 Apr 2011 17:26:10 -0700 Subject: STORM-746 : Clean up typos in comments --- .../integration_tests/llimage_libtest/llimage_libtest.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'indra/integration_tests') diff --git a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp index 1466e44324..feb63e161d 100644 --- a/indra/integration_tests/llimage_libtest/llimage_libtest.cpp +++ b/indra/integration_tests/llimage_libtest/llimage_libtest.cpp @@ -54,20 +54,21 @@ static const char USAGE[] = "\n" " List of image files to create (assumes same order as for input files)\n" " OR 3 letters file type extension to convert each input file into.\n" " -r, --region \n" -" Crop region on the input file in pixel.\n" +" Crop region applied to the input files in pixels.\n" " Only used for j2c images. Default is no region cropping.\n" " -d, --discard_level \n" -" Discard level max used on input. 0 is high resolution. Max discard level is 5.\n" +" Discard level max used on input. 0 is highest resolution. Max discard level is 5.\n" " This allows the input image to be clamped in resolution when loading.\n" " Only valid for j2c images. Default is no discard.\n" " -p, --precincts \n" " Dimension of precincts in pixels. Precincts are assumed square and identical for\n" -" all levels. Note that this oprion also uses PLT and tile markers, \n" -" as well as RPCL order. Power of 2 must be used.\n" +" all levels. Note that this option also add PLT and tile markers to the codestream, \n" +" and uses RPCL order. Power of 2 must be used.\n" " Only valid for output j2c images. Default is no precincts used.\n" " -b, --blocks \n" " Dimension of coding blocks in pixels. Blocks are assumed square. Power of 2 must\n" -" be used. Blocks must be smaller than precincts.\n" +" be used. Blocks must be smaller than precincts. Like precincts, this option adds\n" +" PLT, tile markers and uses RPCL.\n" " Only valid for output j2c images. Default is 64.\n" " -log, --logmetrics \n" " Log performance data for . Results in .slp\n" @@ -130,7 +131,7 @@ LLPointer load_image(const std::string &src_filename, int discard_le { LLPointer image = create_image(src_filename); - // This just load the image file stream into a buffer. No decoding done. + // This just loads the image file stream into a buffer. No decoding done. if (!image->load(src_filename)) { return NULL; @@ -170,7 +171,7 @@ bool save_image(const std::string &dest_filename, LLPointer raw_imag { LLPointer image = create_image(dest_filename); - // Set the image restriction on load in the case of a j2c image + // Set the image codestream parameters on output in the case of a j2c image if ((image->getCodec() == IMG_CODEC_J2C) && ((blocks_size != -1) || (precincts_size != -1))) { // That method doesn't exist (and likely, doesn't make sense) for any other image file format -- cgit v1.2.3