Committing patch from issue 1240: "Partial profile handling"

This commit is contained in:
natureh
2012-02-26 03:23:08 +01:00
parent c21fa69aea
commit dd93fff44c
60 changed files with 2243 additions and 2214 deletions

View File

@@ -58,7 +58,8 @@ bool simpleEditor;
* 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 */
* -2 if an error occurred during processing
* -3 if at least one required procparam file was not found */
int processLineParams( int argc, char **argv );
int main(int argc, char **argv)
@@ -164,24 +165,36 @@ int main(int argc, char **argv)
return 0;
}
void deleteProcParams(std::vector<rtengine::procparams::PartialProfile*> &pparams) {
for (unsigned int i=0; i<pparams.size(); i++) {
pparams[i]->deleteInstance();
delete pparams[i];
pparams[i] = NULL;
}
return;
}
int processLineParams( int argc, char **argv )
{
rtengine::procparams::PartialProfile *rawParams=NULL, *imgParams=NULL;
std::vector<Glib::ustring> inputFiles;
Glib::ustring outputPath = "";
Glib::ustring processingParams = "";
std::vector<rtengine::procparams::PartialProfile*> processingParams;
bool isDirectory=false;
bool outputDirectory=false;
bool overwriteFiles=false;
bool sideProcParams=false;
bool copyParamsFile=false;
bool useDefaultIfAbsent=true;
bool skipIfNoSidecar=false;
bool useDefault=false;
unsigned int sideCarFilePos = 0;
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]){
switch( argv[iArg][1] ){
case 'O':
copyParamsFile = true;
case 'o': // outputfile or dir
@@ -192,16 +205,35 @@ int processLineParams( int argc, char **argv )
outputDirectory=true;
}
break;
case 'p': // processing parameters for all inputs
case 'p': // processing parameters for all inputs; all set procparams are required, so
// RT stop if any of them can't be loaded for any reason.
if( iArg+1 <argc ){
iArg++;
processingParams = safe_filename_to_utf8 ( argv[iArg] );
Glib::ustring fname = safe_filename_to_utf8 ( argv[iArg] );
if (fname.at(0) == '-') {
std::cerr << "Error: filename missing next to the -p switch" << std::endl;
deleteProcParams(processingParams);
return -3;
}
rtengine::procparams::PartialProfile* currentParams = new rtengine::procparams::PartialProfile(true);
if (!(currentParams->load ( fname ))) {
processingParams.push_back(currentParams);
}
else {
std::cerr << "Error: \""<< fname <<"\" not found" << std::endl;
deleteProcParams(processingParams);
return -3;
}
}
break;
case 'S':
useDefaultIfAbsent=false;
case 's': // Processing params next to file (.pp3 appended)
skipIfNoSidecar=true;
case 's': // Processing params next to file (file extension appended)
sideProcParams = true;
sideCarFilePos = processingParams.size();
break;
case 'd':
useDefault = true;
break;
case 'Y':
overwriteFiles =true;
@@ -232,7 +264,7 @@ int processLineParams( int argc, char **argv )
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
// skip files without extension and without sidecar files
Glib::ustring s(names[iFile]);
Glib::ustring::size_type ext= s.find_last_of('.');
if( Glib::ustring::npos == ext )
@@ -250,27 +282,41 @@ int processLineParams( int argc, char **argv )
case 'h':
case '?':
default:
std::cerr << "RawTherapee, " << VERSION << std::endl;
std::cerr << "Copyright (c)2004-2011 Gabor Horvath <hgabor@rawtherapee.com>"<< std::endl << std::endl;
{
Glib::ustring pparamsExt = paramFileExtension.substr(1);
std::cerr << "RawTherapee, V" << VERSION << std::endl;
std::cerr << "Copyright (c)2004-2012 Gabor Horvath <hgabor@rawtherapee.com>"<< std::endl << std::endl;
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 << Glib::path_get_basename(argv[0]) <<" [-o <output> | -O <output>] [-s|-S] [-p <file>] [-d] [-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 << " -O <outputFile>|<outputDir> : select output dir and copy " << pparamsExt << " file into it"<< std::endl;
std::cerr << " -s : include the " << pparamsExt << " file next to the input file (with same name) to build the image's parameters"<< std::endl;
std::cerr << " ex: for IMG001.NEF there should be IMG001.NEF." << pparamsExt << " 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 << " -S : like -s but skip if " << pparamsExt << " file not found." << std::endl;
std::cerr << " -p <file." << pparamsExt << "> : specify " << pparamsExt << " file to be used for all conversions."<< std::endl;
std::cerr << " you can specify as much -p option as you want (see the note below)."<< std::endl;
std::cerr << " -d : use the default Raw or Image " << pparamsExt << " file to build the image's parameters"<< 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 << " -t : specify output to be uncompressed tiff."<< std::endl;
std::cerr << " -t1: specify output to be compressed tiff."<< std::endl;
std::cerr << " -n : specify output to be png."<< std::endl;
std::cerr << " -Y : overwrite output if present."<< std::endl;
std::cerr << " -Y : overwrite output if present."<< std::endl<<std::endl;
std::cerr << "NOTE: Your " << pparamsExt << " files can be incomplete, RawTherapee will set the values like that:"<< std::endl;
std::cerr << " - the " << pparamsExt << " file is built with internal default values;"<< std::endl;
std::cerr << " - then overrided by those found in the default Raw or Image " << pparamsExt << " file (if -d has been set);"<< std::endl;
std::cerr << " - then overrided by those found in the " << pparamsExt << " files provided by -p,"<< std::endl;
std::cerr << " each one overriding the previous values;" << std::endl;
std::cerr << " * then overrided by the sidecar file if -s is set and if the file exists;"<< std::endl;
std::cerr << " the time where the sidecar file is used depend of the position of the -s switch"<< std::endl;
std::cerr << " in the command line regarding to the -p parameters (e.g. \"-p first." << pparamsExt << " -p second." << pparamsExt << " -s -p fourth." << pparamsExt << "\")"<< std::endl;
return -1;
}
}
}else{
argv1 = safe_filename_to_utf8 ( argv[iArg] );
if( outputDirectory ){
@@ -299,17 +345,33 @@ int processLineParams( int argc, char **argv )
if( inputFiles.empty() )
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);
if (useDefault) {
rawParams = new rtengine::procparams::PartialProfile(true);
if (rawParams->load(options.profilePath+"/" + options.defProfRaw + paramFileExtension)) {
std::cerr << "Error: default Raw procparams file \""<< (options.profilePath+"/" + options.defProfRaw + paramFileExtension) << "\" not found" << std::endl;
rawParams->deleteInstance();
delete rawParams;
deleteProcParams(processingParams);
return -3;
}
imgParams = new rtengine::procparams::PartialProfile(true);
if (imgParams->load(options.profilePath+"/" + options.defProfImg + paramFileExtension)) {
std::cerr << "Error: default Image procparams file \""<< (options.profilePath+"/" + options.defProfImg + paramFileExtension) << "\" not found" << std::endl;
imgParams->deleteInstance();
delete imgParams;
rawParams->deleteInstance();
delete rawParams;
deleteProcParams(processingParams);
return -3;
}
}
ParamsEdited paramsEdited;
for( size_t iFile=0; iFile< inputFiles.size(); iFile++){
// Has to be reinstanciated at each profile to have a ProcParams object with default values
rtengine::procparams::ProcParams currentParams;
Glib::ustring inputFile = inputFiles[iFile];
std::cout << "Processing: " << inputFile << std::endl;
@@ -354,27 +416,48 @@ int processLineParams( int argc, char **argv )
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? &paramsRaw: &paramsImg;
}else{
delete ii;
errors++;
std::cerr << "Error loading processing params: "<< sideProcessingParams << std::endl;
continue;
}
}else
currentParams = &params;
}else if( processingParams.length()>0 ){
currentParams = &params;
}else if(isRaw ){
currentParams = &paramsRaw;
}else{
currentParams = &paramsImg;
if (useDefault) {
if (isRaw) {
std::cout << " Merging default Raw profile" << std::endl;
rawParams->applyTo(&currentParams);
}
else {
std::cout << " Merging default Image profile" << std::endl;
imgParams->applyTo(&currentParams);
}
}
job = rtengine::ProcessingJob::create (ii, *currentParams);
bool sideCarFound = false;
unsigned int i=0;
// Iterate the procparams file list in order to build the final ProcParams
do {
if (sideProcParams && i==sideCarFilePos) {
// using the sidecar file
Glib::ustring sideProcessingParams = inputFile + paramFileExtension;
// the "load" method don't reset the procparams values anymore, so values found in the procparam file override the one of currentParams
if( !safe_file_test( sideProcessingParams, Glib::FILE_TEST_EXISTS ) || currentParams.load ( sideProcessingParams ))
std::cerr << "Warning: sidecar file requested but not found for: "<< sideProcessingParams << std::endl;
else {
sideCarFound = true;
std::cout << " Merging sidecar procparams" << std::endl;
}
}
if( processingParams.size()>i ) {
std::cout << " Merging procparams #" << i << std::endl;
processingParams[i]->applyTo(&currentParams);
}
i++;
} while (i < processingParams.size()+(sideProcParams?1:0));
if( sideProcParams && !sideCarFound && skipIfNoSidecar ){
delete ii;
errors++;
std::cerr << "Error: no sidecar procparams found for: "<< inputFile << std::endl;
continue;
}
job = rtengine::ProcessingJob::create (ii, currentParams);
if( !job ){
errors++;
std::cerr << "Error creating processing for: "<< inputFile << std::endl;
@@ -406,12 +489,17 @@ int processLineParams( int argc, char **argv )
}else{
if( copyParamsFile ){
Glib::ustring outputProcessingParams = outputFile + paramFileExtension;
currentParams->save( outputProcessingParams );
currentParams.save( outputProcessingParams );
}
}
ii->decreaseRef();
resultImage->free();
}
if (imgParams) { imgParams->deleteInstance(); delete imgParams; }
if (rawParams) { rawParams->deleteInstance(); delete rawParams; }
deleteProcParams(processingParams);
return errors>0?-2:0;
}