Merge from default. Hope I did it right...

This commit is contained in:
Emil Martinec
2012-03-08 20:27:30 -06:00
parent 380728e1f0
commit f47b4b5bb0
262 changed files with 41736 additions and 37104 deletions

View File

@@ -23,7 +23,7 @@
// This file is for your program, I won't touch it again!
//#include "config.h"
#include "config.h"
#include <gtkmm.h>
#include <giomm.h>
#include <iostream>
@@ -36,7 +36,6 @@
#include "version.h"
#ifndef WIN32
#include "../rtgui/config.h"
#include <glibmm/fileutils.h>
#include <glib.h>
#include <glib/gstdio.h>
@@ -48,6 +47,8 @@ extern Options options;
// stores path to data files
Glib::ustring argv0;
Glib::ustring creditsPath;
Glib::ustring licensePath;
Glib::ustring argv1;
bool simpleEditor;
@@ -57,38 +58,48 @@ 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)
{
Glib::ustring argv0_;
#ifdef WIN32
WCHAR exnameU[512] = {0};
char exname[512] = {0};
GetModuleFileNameW (NULL, exnameU, 512);
WideCharToMultiByte(CP_UTF8,0,exnameU,-1,exname,512,0,0 );
argv0_ = exname;
// get the path where the rawtherapee executable is stored
argv0 = Glib::path_get_dirname(argv0_);
{
#ifdef BUILD_BUNDLE
char exname[512] = {0};
Glib::ustring exePath;
// get the path where the rawtherapee executable is stored
#ifdef WIN32
WCHAR exnameU[512] = {0};
GetModuleFileNameW (NULL, exnameU, 512);
WideCharToMultiByte(CP_UTF8,0,exnameU,-1,exname,512,0,0 );
#else
if (readlink("/proc/self/exe", exname, 512) < 0) {
strncpy(exname, argv[0], 512);
}
#endif
exePath = Glib::path_get_dirname(exname);
// set paths
if (Glib::path_is_absolute(DATA_SEARCH_PATH)) {
argv0 = DATA_SEARCH_PATH;
} else {
argv0 = Glib::build_filename(exePath, DATA_SEARCH_PATH);
}
if (Glib::path_is_absolute(CREDITS_SEARCH_PATH)) {
creditsPath = CREDITS_SEARCH_PATH;
} else {
creditsPath = Glib::build_filename(exePath, CREDITS_SEARCH_PATH);
}
if (Glib::path_is_absolute(LICENCE_SEARCH_PATH)) {
licensePath = LICENCE_SEARCH_PATH;
} else {
licensePath = Glib::build_filename(exePath, LICENCE_SEARCH_PATH);
}
#else
// get the path to data (defined in config.h which is generated by cmake)
argv0 = DATA_SEARCH_PATH;
// check if path exists, otherwise revert back to behavior similar to windows
try {
Glib::Dir dir(DATA_SEARCH_PATH);
} catch (Glib::FileError) {
argv0_ = argv[0];
argv0 = Glib::path_get_dirname(argv0_);
}
argv0 = DATA_SEARCH_PATH;
creditsPath = CREDITS_SEARCH_PATH;
licensePath = LICENCE_SEARCH_PATH;
#endif
Glib::thread_init();
gdk_threads_init();
@@ -154,25 +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
@@ -183,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;
@@ -223,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 )
@@ -241,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 ){
@@ -287,20 +342,36 @@ int processLineParams( int argc, char **argv )
}
if( !argv1.empty() )
return 1;
if( !inputFiles.size() )
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;
@@ -345,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;
@@ -397,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;
}