Added command line options
This commit is contained in:
277
rtgui/main.cc
277
rtgui/main.cc
@@ -43,18 +43,24 @@
|
||||
|
||||
extern Options options;
|
||||
|
||||
//#ifdef WIN32
|
||||
//#include <windows.h> // included for WinMain
|
||||
//#endif
|
||||
|
||||
// stores path to data files
|
||||
Glib::ustring argv0;
|
||||
Glib::ustring argv1;
|
||||
bool simpleEditor;
|
||||
|
||||
/* Process line command options
|
||||
* Returns
|
||||
* 0 if process in batch has executed
|
||||
* 1 to start GUI (with a dir or file option)
|
||||
* 2 to start GUI because no files found
|
||||
* -1 if there is an error in parameters
|
||||
* -2 if an error occurred during processing */
|
||||
int processLineParams( int argc, char **argv );
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
std::string argv0_, argv1_;
|
||||
std::string argv0_;
|
||||
|
||||
#ifdef WIN32
|
||||
char exname[512];
|
||||
@@ -81,18 +87,12 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
|
||||
if (argc>1)
|
||||
argv1_ = argv[1];
|
||||
else
|
||||
argv1_ = "";
|
||||
|
||||
#ifdef GLIBMM_EXCEPTIONS_ENABLED
|
||||
argv0 = Glib::filename_to_utf8 (argv0_);
|
||||
argv1 = Glib::filename_to_utf8 (argv1_);
|
||||
#else
|
||||
std::auto_ptr<Glib::Error> error;
|
||||
argv0 = Glib::filename_to_utf8 (argv0_, error);
|
||||
argv1 = Glib::filename_to_utf8 (argv1_, error);
|
||||
#endif //GLIBMM_EXCEPTIONS_ENABLED
|
||||
|
||||
Glib::thread_init();
|
||||
@@ -101,13 +101,23 @@ int main(int argc, char **argv)
|
||||
|
||||
Options::load ();
|
||||
|
||||
if (argc>1){
|
||||
int ret = processLineParams( argc, argv);
|
||||
if( ret <= 0 )
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// Move the old path to the new one if the new does not exist
|
||||
if (safe_file_test(Glib::build_filename(options.rtdir,"cache"), Glib::FILE_TEST_IS_DIR) && !safe_file_test(options.cacheBaseDir, Glib::FILE_TEST_IS_DIR))
|
||||
safe_g_rename(Glib::build_filename(options.rtdir,"cache"), options.cacheBaseDir);
|
||||
#endif
|
||||
|
||||
// Gtk::RC::add_default_file (argv0+"/themes/"+options.theme);
|
||||
simpleEditor=false;
|
||||
if( !argv1.empty() )
|
||||
if( Glib::file_test(argv1, Glib::FILE_TEST_EXISTS) && !Glib::file_test(argv1, Glib::FILE_TEST_IS_DIR))
|
||||
simpleEditor = true;
|
||||
|
||||
if (!options.useSystemTheme)
|
||||
{
|
||||
std::vector<std::string> rcfiles;
|
||||
@@ -118,7 +128,7 @@ int main(int argc, char **argv)
|
||||
Gtk::RC::set_default_files (rcfiles);
|
||||
}
|
||||
Gtk::Main m(&argc, &argv);
|
||||
// MainWindow *MainWindow = new class MainWindow();
|
||||
|
||||
RTWindow *rtWindow = new class RTWindow();
|
||||
gdk_threads_enter ();
|
||||
m.run(*rtWindow);
|
||||
@@ -128,5 +138,246 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
int processLineParams( int argc, char **argv )
|
||||
{
|
||||
std::vector<Glib::ustring> inputFiles;
|
||||
Glib::ustring outputPath;
|
||||
Glib::ustring processingParams;
|
||||
bool isDirectory=false;
|
||||
bool outputDirectory=false;
|
||||
bool overwriteFiles=false;
|
||||
bool sideProcParams=false;
|
||||
bool copyParamsFile=false;
|
||||
bool useDefaultIfAbsent=true;
|
||||
int compression=100;
|
||||
int bits=-1;
|
||||
std::string outputType;
|
||||
unsigned errors=0;
|
||||
for( int iArg=1; iArg<argc; iArg++){
|
||||
if( argv[iArg][0]=='-' ){
|
||||
switch( argv[iArg][1]){
|
||||
case 'O':
|
||||
copyParamsFile = true;
|
||||
case 'o': // outputfile or dir
|
||||
if( iArg+1 <argc ){
|
||||
iArg++;
|
||||
outputPath = Glib::filename_to_utf8 (argv[iArg]);
|
||||
if( safe_file_test (outputPath, Glib::FILE_TEST_IS_DIR))
|
||||
outputDirectory=true;
|
||||
}
|
||||
break;
|
||||
case 'p': // processing parameters for all inputs
|
||||
if( iArg+1 <argc ){
|
||||
iArg++;
|
||||
processingParams = Glib::filename_to_utf8 ( argv[iArg] );
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
useDefaultIfAbsent=false;
|
||||
case 's': // Processing params next to file (.pp3 appended)
|
||||
sideProcParams = true;
|
||||
break;
|
||||
case 'Y':
|
||||
overwriteFiles =true;
|
||||
break;
|
||||
case 'j':
|
||||
outputType = "jpg";
|
||||
sscanf(&argv[iArg][2],"%d",&compression);
|
||||
break;
|
||||
case 't':
|
||||
outputType = "tif";
|
||||
compression = ((argv[iArg][2]!='1')?0:1);
|
||||
break;
|
||||
case 'n':
|
||||
outputType = "png";
|
||||
compression = -1;
|
||||
break;
|
||||
case 'c': // MUST be last option
|
||||
while( iArg+1 <argc ){
|
||||
iArg++;
|
||||
if( !safe_file_test( argv[iArg], Glib::FILE_TEST_EXISTS )){
|
||||
std::cerr << argv[iArg] << " doesn't exist."<< std::endl;
|
||||
continue;
|
||||
}
|
||||
if( safe_file_test( argv[iArg], Glib::FILE_TEST_IS_DIR )){
|
||||
isDirectory = true;
|
||||
std::vector<Glib::ustring> names;
|
||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path ( argv[iArg] );
|
||||
safe_build_file_list (dir, names, argv[iArg] );
|
||||
for(size_t iFile=0; iFile< names.size(); iFile++ ){
|
||||
if( !safe_file_test( names[iFile] , Glib::FILE_TEST_IS_DIR)){
|
||||
// skip files without extension and pp3 files
|
||||
Glib::ustring s(names[iFile]);
|
||||
Glib::ustring::size_type ext= s.find_last_of('.');
|
||||
if( Glib::ustring::npos == ext )
|
||||
continue;
|
||||
if( ! s.substr(ext).compare( paramFileExtension ))
|
||||
continue;
|
||||
inputFiles.push_back( names[iFile] );
|
||||
}
|
||||
}
|
||||
}else{
|
||||
inputFiles.push_back( Glib::filename_to_utf8 (argv[iArg]) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
std::cerr << "Usage:"<< std::endl;
|
||||
std::cerr << Glib::path_get_basename(argv[0]) << " [<selected dir>] : start RT GUI browser inside dir."<< std::endl;
|
||||
std::cerr << Glib::path_get_basename(argv[0]) << " <file> : start GUI editor with file."<< std::endl;
|
||||
std::cerr << Glib::path_get_basename(argv[0]) << " -c <inputDir>|<file list> : convert files in batch with default parameters."<< std::endl<< std::endl;
|
||||
std::cerr << "Other options used with -c (that must be last option) "<< std::endl;
|
||||
std::cerr << Glib::path_get_basename(argv[0]) <<" [-o <output> | -O <output>] [-s | -S | -p <file>] [-j[1-100]|-t|-n] -Y -c <input>"<< std::endl;
|
||||
std::cerr << " -o <outputFile>|<outputDir> : select output directory."<< std::endl;
|
||||
std::cerr << " -O <outputFile>|<outputDir> : select output dir and copy pp3 file into it"<< std::endl;
|
||||
std::cerr << " -s : select parameters to be pp3 file next to input file (with same name)"<< std::endl;
|
||||
std::cerr << " ex: for IMG001.NEF there should be IMG001.NEF.pp3 in the same dir" << std::endl;
|
||||
std::cerr << " if absent use default" << std::endl;
|
||||
std::cerr << " -S : like -s but skip if pp3 file not found." << std::endl;
|
||||
std::cerr << " -p <file.pp3> : specify pp3 file to be used for all conversions."<< std::endl;
|
||||
std::cerr << " -j[compression] : specify output to be jpeg.(default)"<< std::endl;
|
||||
std::cerr << " -t : specify output to be tif."<< std::endl;
|
||||
std::cerr << " -n : specify output to be png."<< std::endl;
|
||||
std::cerr << " -Y : overwrite output if present."<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
argv1 = Glib::filename_to_utf8 ( argv[iArg] );
|
||||
if( outputDirectory ){
|
||||
options.savePathFolder = outputPath;
|
||||
options.saveUsePathTemplate = false;
|
||||
}
|
||||
if (outputType == "jpg") {
|
||||
options.saveFormat.format = outputType;
|
||||
options.saveFormat.jpegQuality = compression;
|
||||
} else if (outputType == "tif") {
|
||||
options.saveFormat.format = outputType;
|
||||
} else if (outputType == "png") {
|
||||
options.saveFormat.format = outputType;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !argv1.empty() )
|
||||
return 1;
|
||||
if( !inputFiles.size() )
|
||||
return 2;
|
||||
|
||||
rtengine::procparams::ProcParams params,paramsRaw,paramsImg, *currentParams;
|
||||
if( !sideProcParams ){
|
||||
if( processingParams.length()>0 )
|
||||
params.load ( processingParams );
|
||||
else{
|
||||
paramsRaw.load(options.profilePath+"/"+options.defProfRaw+paramFileExtension);
|
||||
paramsImg.load(options.profilePath+"/"+options.defProfImg+paramFileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
for( size_t iFile=0; iFile< inputFiles.size(); iFile++){
|
||||
Glib::ustring inputFile = inputFiles[iFile];
|
||||
std::cout << "Processing: " << inputFile << std::endl;
|
||||
|
||||
rtengine::InitialImage* ii=NULL;
|
||||
rtengine::ProcessingJob* job =NULL;
|
||||
int errorCode;
|
||||
bool isRaw=false;
|
||||
|
||||
Glib::ustring outputFile;
|
||||
if( outputType.empty() )
|
||||
outputType = "jpg";
|
||||
if( outputPath.empty() ){
|
||||
Glib::ustring s = inputFile;
|
||||
Glib::ustring::size_type ext= s.find_last_of('.');
|
||||
outputFile = s.substr(0,ext)+ "." + outputType;
|
||||
}else if( outputDirectory ){
|
||||
Glib::ustring s = Glib::path_get_basename( inputFile );
|
||||
Glib::ustring::size_type ext= s.find_last_of('.');
|
||||
outputFile = outputPath + "/" + s.substr(0,ext) + "." + outputType;
|
||||
}else{
|
||||
Glib::ustring s = outputPath;
|
||||
Glib::ustring::size_type ext= s.find_last_of('.');
|
||||
outputFile = s.substr(0,ext) + "." + outputType;
|
||||
}
|
||||
if( inputFile == outputFile){
|
||||
std::cerr << "Cannot overwrite:" << inputFile << std::endl;
|
||||
continue;
|
||||
}
|
||||
if( !overwriteFiles && safe_file_test( outputFile , Glib::FILE_TEST_EXISTS ) ){
|
||||
std::cerr << outputFile <<" already exists: use -Y option to overwrite:" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load the image
|
||||
ii = rtengine::InitialImage::load ( inputFile, true, &errorCode, NULL );
|
||||
if (ii)
|
||||
isRaw=true;
|
||||
else
|
||||
ii = rtengine::InitialImage::load ( inputFile , false, &errorCode, NULL );
|
||||
if (!ii) {
|
||||
errors++;
|
||||
std::cerr << "Error loading file:"<< inputFile << std::endl;
|
||||
continue;
|
||||
}
|
||||
if( sideProcParams ){
|
||||
Glib::ustring sideProcessingParams = inputFile + paramFileExtension;
|
||||
if( !safe_file_test( sideProcessingParams, Glib::FILE_TEST_EXISTS ) || params.load ( sideProcessingParams )){
|
||||
if( useDefaultIfAbsent ){
|
||||
currentParams = isRaw? ¶msRaw: ¶msImg;
|
||||
}else{
|
||||
delete ii;
|
||||
errors++;
|
||||
std::cerr << "Error loading processing params:"<< sideProcessingParams << std::endl;
|
||||
continue;
|
||||
}
|
||||
}else
|
||||
currentParams = ¶ms;
|
||||
}else if( processingParams.length()>0 ){
|
||||
currentParams = ¶ms;
|
||||
}else if(isRaw ){
|
||||
currentParams = ¶msRaw;
|
||||
}else{
|
||||
currentParams = ¶msImg;
|
||||
}
|
||||
job = rtengine::ProcessingJob::create (ii, *currentParams);
|
||||
if( !job ){
|
||||
errors++;
|
||||
std::cerr << "Error creating processing for:"<< inputFile << std::endl;
|
||||
ii->decreaseRef();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process image
|
||||
rtengine::IImage16* resultImage = rtengine::processImage (job, errorCode, NULL);
|
||||
if( !resultImage ){
|
||||
errors++;
|
||||
std::cerr << "Error processing:"<< inputFile << std::endl;
|
||||
rtengine::ProcessingJob::destroy( job );
|
||||
continue;
|
||||
}
|
||||
// save image to disk
|
||||
if( outputType=="jpg" )
|
||||
errorCode = resultImage->saveAsJPEG( outputFile, compression );
|
||||
else if( outputType=="tif" )
|
||||
errorCode = resultImage->saveAsTIFF( outputFile, bits, compression==0 );
|
||||
else if( outputType=="png" )
|
||||
errorCode = resultImage->saveAsPNG( outputFile,compression, bits );
|
||||
else
|
||||
errorCode = resultImage->saveToFile (outputFile);
|
||||
|
||||
if(errorCode){
|
||||
errors++;
|
||||
std::cerr << "Error saving to:"<< outputFile << std::endl;
|
||||
}else{
|
||||
if( copyParamsFile ){
|
||||
Glib::ustring outputProcessingParams = outputFile + paramFileExtension;
|
||||
currentParams->save( outputProcessingParams );
|
||||
}
|
||||
}
|
||||
|
||||
ii->decreaseRef();
|
||||
resultImage->free();
|
||||
}
|
||||
return errors>0?-2:0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user