Merov Linden avatar Merov Linden committed 8f14c1c

STORM-987 : Add the --image-stats argument, make argument passing more consistent, fix typos in comments in llimage header

Comments (0)

Files changed (2)

indra/integration_tests/llimage_libtest/llimage_libtest.cpp

 static const char USAGE[] = "\n"
 "usage:\tllimage_libtest [options]\n"
 "\n"
-" --help                           print this help\n"
-" --in <file1 .. file2>            list of image files to load and convert, patterns can be used\n"
-" --out <file1 .. file2> OR <type> list of image files to create (assumes same order as --in files)\n"
-"                                  OR 3 letters file type extension to convert each input file into\n"
-" --logmetrics <metric>            log performance metric and data for <metric>\n"
-" --analyzeperformance             create report comparing baseline with current for <metric> provided in --logmetrics\n"
+" -h, --help\n"
+"        Print this help\n"
+" -i, --input <file1 .. file2>\n"
+"        List of image files to load and convert, patterns can be used\n"
+" -o, --output <file1 .. file2> OR <type>\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"
+" -log, --logmetrics <metric>\n"
+"        Log performance metric and data for <metric>\n"
+" -r, --analyzeperformance\n"
+"        Create report comparing baseline with current for <metric> provided in --logmetrics\n"
+" -s, --image-stats\n"
+"        Output stats for each input and output image\n"
 "\n";
 
 // true when all image loading is done. Used by metric logging thread to know when to stop the thread.
 	return image;
 }
 
+void output_image_stats(LLPointer<LLImageFormatted> image, const std::string &filename)
+{
+	// Print out some statistical data on the image
+	std::cout << "Image stats for : " << filename << ", extension : " << image->getExtension() << std::endl;
+
+	std::cout << "    with : " << (int)(image->getWidth())       << ", height : " << (int)(image->getHeight())       << std::endl;
+	std::cout << "    comp : " << (int)(image->getComponents())  << ", levels : " << (int)(image->getDiscardLevel()) << std::endl;
+	std::cout << "    head : " << (int)(image->calcHeaderSize()) << ",   data : " << (int)(image->getDataSize())     << std::endl;
+
+	return;
+}
+
 // Load an image from file and return a raw (decompressed) instance of its data
-LLPointer<LLImageRaw> load_image(const std::string &src_filename)
+LLPointer<LLImageRaw> load_image(const std::string &src_filename, bool output_stats)
 {
 	LLPointer<LLImageFormatted> image = create_image(src_filename);
 
 		return NULL;
 	}
 	
+	if (output_stats)
+	{
+		output_image_stats(image, src_filename);
+	}
+	
 	LLPointer<LLImageRaw> raw_image = new LLImageRaw;
 	if (!image->decode(raw_image, 0.0f))
 	{
 }
 
 // Save a raw image instance into a file
-bool save_image(const std::string &dest_filename, LLPointer<LLImageRaw> raw_image)
+bool save_image(const std::string &dest_filename, LLPointer<LLImageRaw> raw_image, bool output_stats)
 {
 	LLPointer<LLImageFormatted> image = create_image(dest_filename);
 	
 		return false;
 	}
 	
+	if (output_stats)
+	{
+		output_image_stats(image, dest_filename);
+	}
+
 	return image->save(dest_filename);
 }
 
 	std::list<std::string> input_filenames;
 	std::list<std::string> output_filenames;
 	bool analyze_performance = false;
+	bool image_stats = false;
 
 	// Init whatever is necessary
 	ll_init_apr();
 	// Analyze command line arguments
 	for (int arg = 1; arg < argc; ++arg)
 	{
-		if (!strcmp(argv[arg], "--help"))
+		if (!strcmp(argv[arg], "--help") || !strcmp(argv[arg], "-h"))
 		{
             // Send the usage to standard out
             std::cout << USAGE << std::endl;
 			return 0;
 		}
-		else if (!strcmp(argv[arg], "--in") && arg < argc-1)
+		else if ((!strcmp(argv[arg], "--input") || !strcmp(argv[arg], "-i")) && arg < argc-1)
 		{
 			std::string file_name = argv[arg+1];
 			while (file_name[0] != '-')		// if arg starts with '-', we consider it's not a file name but some other argument
 				file_name = argv[arg+1];	// Next argument and loop over
 			}
 		}
-		else if (!strcmp(argv[arg], "--out") && arg < argc-1)
+		else if ((!strcmp(argv[arg], "--output") || !strcmp(argv[arg], "-o")) && arg < argc-1)
 		{
 			std::string file_name = argv[arg+1];
 			while (file_name[0] != '-')		// if arg starts with '-', we consider it's not a file name but some other argument
 				file_name = argv[arg+1];	// Next argument and loop over
 			}
 		}
-		else if (!strcmp(argv[arg], "--logmetrics"))
+		else if (!strcmp(argv[arg], "--logmetrics") || !strcmp(argv[arg], "-log"))
 		{
 			// '--logmetrics' needs to be specified with a named test metric argument
 			// Note: for the moment, only ImageCompressionTester has been tested
 					break;
 			}
 		}
-		else if (!strcmp(argv[arg], "--analyzeperformance"))
+		else if (!strcmp(argv[arg], "--analyzeperformance") || !strcmp(argv[arg], "-r"))
 		{
 			analyze_performance = true;
 		}
+		else if (!strcmp(argv[arg], "--image-stats") || !strcmp(argv[arg], "-s"))
+		{
+			image_stats = true;
+		}
 	}
 		
 	// Analyze the list of (input,output) files
 	for (; in_file != in_end; ++in_file)
 	{
 		// Load file
-		LLPointer<LLImageRaw> raw_image = load_image(*in_file);
+		LLPointer<LLImageRaw> raw_image = load_image(*in_file, image_stats);
 		if (!raw_image)
 		{
 			std::cout << "Error: Image " << *in_file << " could not be loaded" << std::endl;
 		// Save file
 		if (out_file != out_end)
 		{
-			if (!save_image(*out_file, raw_image))
+			if (!save_image(*out_file, raw_image, image_stats))
 			{
 				std::cout << "Error: Image " << *out_file << " could not be saved" << std::endl;
 			}
 			}
 			++out_file;
 		}
-
-		// Output stats on each file
 	}
 	
 	sAllDone = true;

indra/llimage/llimage.h

 	// subclasses must return a prefered file extension (lowercase without a leading dot)
 	virtual std::string getExtension() = 0;
 	// calcHeaderSize() returns the maximum size of header;
-	//   0 indicates we don't know have a header and have to lead the entire file
+	//   0 indicates we don't have a header and have to read the entire file
 	virtual S32 calcHeaderSize() { return 0; };
 	// calcDataSize() returns how many bytes to read to load discard_level (including header)
 	virtual S32 calcDataSize(S32 discard_level);
 	// calcDiscardLevelBytes() returns the smallest valid discard level based on the number of input bytes
 	virtual S32 calcDiscardLevelBytes(S32 bytes);
-	// getRawDiscardLevel()by default returns mDiscardLevel, but may be overridden (LLImageJ2C)
+	// getRawDiscardLevel() by default returns mDiscardLevel, but may be overridden (LLImageJ2C)
 	virtual S8  getRawDiscardLevel() { return mDiscardLevel; }
 	
 	BOOL load(const std::string& filename);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.