(Partially) solved issue 663 : UTF-8 support at Windows for stable branch_3.0

This commit is contained in:
Hombre
2011-05-22 18:20:35 +02:00
parent 49a2b9237e
commit fe003b2752
4 changed files with 396 additions and 608 deletions

View File

@@ -50,19 +50,22 @@ Glib::RefPtr<Gdk::Pixbuf> safe_create_from_file(const std::string& filename)
return res; return res;
} }
Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const std::string& filename) Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const Glib::ustring& filename)
{ {
Cairo::RefPtr<Cairo::ImageSurface> res; Cairo::RefPtr<Cairo::ImageSurface> res;
if (!safe_file_test (filename, Glib::FILE_TEST_EXISTS)) { // files_test need a std::string which (as stated in its proto) but will only work if
printf ("ERROR: File \"%s\" not found.\n", filename.c_str()); // we use the Glib::ustring filename !?
} else { if (!Glib::file_test (filename, Glib::FILE_TEST_EXISTS)) {
printf ("ERROR: (ustring) File \"%s\" not found.\n", filename.c_str());
} else {
try { try {
res = Cairo::ImageSurface::create_from_png (filename); // create_from_png need a std::string converted from UTF8 with safe_locale_from_utf8
res = Cairo::ImageSurface::create_from_png (safe_locale_from_utf8(filename));
} catch (...) {} } catch (...) {}
} }
return res; return res;
} }
Glib::RefPtr<Gio::FileInfo> safe_query_file_info (Glib::RefPtr<Gio::File> &file) Glib::RefPtr<Gio::FileInfo> safe_query_file_info (Glib::RefPtr<Gio::File> &file)
@@ -286,4 +289,4 @@ int safe_g_rename(const Glib::ustring& oldFilename, const Glib::ustring& newFile
int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode) int safe_g_mkdir_with_parents(const Glib::ustring& dirName, int mode)
{ {
return ::g_mkdir_with_parents(dirName.c_str(), mode); return ::g_mkdir_with_parents(dirName.c_str(), mode);
} }

View File

@@ -6,7 +6,7 @@
#include <giomm.h> #include <giomm.h>
Glib::RefPtr<Gdk::Pixbuf> safe_create_from_file(const std::string& filename); Glib::RefPtr<Gdk::Pixbuf> safe_create_from_file(const std::string& filename);
Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const std::string& filename); Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const Glib::ustring& filename);
class FileMTimeInfo { class FileMTimeInfo {

View File

@@ -1,387 +1,385 @@
/* /*
* This file is part of RawTherapee. * This file is part of RawTherapee.
* *
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com> * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
* *
* RawTherapee is free software: you can redistribute it and/or modify * RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* RawTherapee is distributed in the hope that it will be useful, * RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/ */
// generated 2004/6/3 19:15:32 CEST by gabor@darkstar.(none) // generated 2004/6/3 19:15:32 CEST by gabor@darkstar.(none)
// using glademm V2.5.0 // using glademm V2.5.0
// //
// newer (non customized) versions of this file go to raw.cc_new // newer (non customized) versions of this file go to raw.cc_new
// This file is for your program, I won't touch it again!
//#include <config.h>
#include <gtkmm.h>
#include <giomm.h>
#include <iostream>
#include <rtwindow.h>
#include <string.h>
#include <stdlib.h>
#include <options.h>
#include <version.h>
#ifndef WIN32
#include <config.h>
#include <glibmm/fileutils.h>
#include <glib.h>
#include <glib/gstdio.h>
#endif
#include <safegtk.h>
extern Options options;
// 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)
{
Glib::ustring argv0_;
#ifdef WIN32
// This file is for your program, I won't touch it again! WCHAR exnameU[512] = {0};
char exname[512] = {0};
GetModuleFileNameW (NULL, exnameU, 512);
WideCharToMultiByte(CP_UTF8,0,exnameU,-1,exname,512,0,0 );
argv0_ = exname;
//#include <config.h> // get the path where the rawtherapee executable is stored
#include <gtkmm.h> argv0 = Glib::path_get_dirname(argv0_);
#include <giomm.h>
#include <iostream>
#include <rtwindow.h>
#include <string.h>
#include <stdlib.h>
#include <options.h>
#include <version.h>
#ifndef WIN32 #else
#include <config.h> // get the path to data (defined in config.h which is generated by cmake)
#include <glibmm/fileutils.h> argv0 = DATA_SEARCH_PATH;
#include <glib.h> // check if path exists, otherwise revert back to behavior similar to windows
#include <glib/gstdio.h> try {
#endif Glib::Dir dir(DATA_SEARCH_PATH);
} catch (Glib::FileError) {
#include <safegtk.h> argv0_ = argv[0];
argv0 = Glib::path_get_dirname(argv0_);
extern Options options; }
#endif
// stores path to data files
Glib::ustring argv0;
Glib::ustring argv1;
bool simpleEditor; Glib::thread_init();
gdk_threads_init();
/* Process line command options Gio::init ();
* Returns
* 0 if process in batch has executed Options::load ();
* 1 to start GUI (with a dir or file option)
* 2 to start GUI because no files found if (argc>1){
* -1 if there is an error in parameters int ret = processLineParams( argc, argv);
* -2 if an error occurred during processing */ if( ret <= 0 )
int processLineParams( int argc, char **argv ); return ret;
}
int main(int argc, char **argv)
{ #ifndef _WIN32
// Move the old path to the new one if the new does not exist
std::string argv0_; 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);
#ifdef WIN32 #endif
char exname[512];
GetModuleFileName (NULL, exname, 512); simpleEditor=false;
argv0_ = exname; if( !argv1.empty() )
// get the path where the rawtherapee is stored if( safe_file_test(argv1, Glib::FILE_TEST_EXISTS) && !safe_file_test(argv1, Glib::FILE_TEST_IS_DIR))
int i; simpleEditor = true;
for (i=argv0_.size()-1; (argv0_[i]!='/' && argv0_[i]!='\\') && i>0; i--);
if (argv0_[i]=='/' || argv0_[i]=='\\') if (!options.useSystemTheme)
argv0_ = argv0_.substr(0,i); {
#else std::vector<Glib::ustring> rcfiles;
// get the path to data (defined in config.h which is generated by cmake) rcfiles.push_back (argv0+"/themes/"+options.theme);
argv0_ = DATA_SEARCH_PATH; // Set the font face and size
// check if path exists, otherwise revert back to behavior similar to windows Gtk::RC::parse_string (Glib::ustring::compose(
try { "style \"clearlooks-default\" { font_name = \"%1\" }", options.font));
Glib::Dir dir(DATA_SEARCH_PATH); Gtk::RC::set_default_files (rcfiles);
} catch (Glib::FileError) { }
argv0_ = argv[0]; Gtk::Main m(&argc, &argv);
int i;
for (i=argv0_.size()-1; (argv0_[i]!='/' && argv0_[i]!='\\') && i>0; i--); RTWindow *rtWindow = new class RTWindow();
if (argv0_[i]=='/' || argv0_[i]=='\\') gdk_threads_enter ();
argv0_ = argv0_.substr(0,i); m.run(*rtWindow);
} gdk_threads_leave ();
#endif delete rtWindow;
rtengine::cleanup();
return 0;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
argv0 = Glib::filename_to_utf8 (argv0_);
#else int processLineParams( int argc, char **argv )
std::auto_ptr<Glib::Error> error; {
argv0 = Glib::filename_to_utf8 (argv0_, error); std::vector<Glib::ustring> inputFiles;
#endif //GLIBMM_EXCEPTIONS_ENABLED Glib::ustring outputPath = "";
Glib::ustring processingParams = "";
Glib::thread_init(); bool isDirectory=false;
gdk_threads_init(); bool outputDirectory=false;
Gio::init (); bool overwriteFiles=false;
bool sideProcParams=false;
Options::load (); bool copyParamsFile=false;
bool useDefaultIfAbsent=true;
if (argc>1){ int compression=100;
int ret = processLineParams( argc, argv); int bits=-1;
if( ret <= 0 ) std::string outputType = "";
return ret; unsigned errors=0;
} for( int iArg=1; iArg<argc; iArg++){
if( argv[iArg][0]=='-' ){
#ifndef _WIN32 switch( argv[iArg][1]){
// Move the old path to the new one if the new does not exist case 'O':
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)) copyParamsFile = true;
safe_g_rename(Glib::build_filename(options.rtdir,"cache"), options.cacheBaseDir); case 'o': // outputfile or dir
#endif if( iArg+1 <argc ){
iArg++;
simpleEditor=false; outputPath = safe_locale_to_utf8 (argv[iArg]);
if( !argv1.empty() ) if( safe_file_test (outputPath, Glib::FILE_TEST_IS_DIR))
if( Glib::file_test(argv1, Glib::FILE_TEST_EXISTS) && !Glib::file_test(argv1, Glib::FILE_TEST_IS_DIR)) outputDirectory=true;
simpleEditor = true; }
break;
if (!options.useSystemTheme) case 'p': // processing parameters for all inputs
{ if( iArg+1 <argc ){
std::vector<std::string> rcfiles; iArg++;
rcfiles.push_back (argv0+"/themes/"+options.theme); processingParams = safe_locale_to_utf8 ( argv[iArg] );
// Set the font face and size }
Gtk::RC::parse_string (Glib::ustring::compose( break;
"style \"clearlooks-default\" { font_name = \"%1\" }", options.font)); case 'S':
Gtk::RC::set_default_files (rcfiles); useDefaultIfAbsent=false;
} case 's': // Processing params next to file (.pp3 appended)
Gtk::Main m(&argc, &argv); sideProcParams = true;
break;
RTWindow *rtWindow = new class RTWindow(); case 'Y':
gdk_threads_enter (); overwriteFiles =true;
m.run(*rtWindow); break;
gdk_threads_leave (); case 'j':
delete rtWindow; outputType = "jpg";
rtengine::cleanup(); sscanf(&argv[iArg][2],"%d",&compression);
return 0; break;
} case 't':
outputType = "tif";
compression = ((argv[iArg][2]!='1')?0:1);
int processLineParams( int argc, char **argv ) break;
{ case 'n':
std::vector<Glib::ustring> inputFiles; outputType = "png";
Glib::ustring outputPath; compression = -1;
Glib::ustring processingParams; break;
bool isDirectory=false; case 'c': // MUST be last option
bool outputDirectory=false; while( iArg+1 <argc ){
bool overwriteFiles=false; iArg++;
bool sideProcParams=false; if( !safe_file_test( safe_locale_to_utf8(argv[iArg]), Glib::FILE_TEST_EXISTS )){
bool copyParamsFile=false; std::cerr << argv[iArg] << " doesn't exist."<< std::endl;
bool useDefaultIfAbsent=true; continue;
int compression=100; }
int bits=-1; if( safe_file_test( safe_locale_to_utf8(argv[iArg]), Glib::FILE_TEST_IS_DIR )){
std::string outputType; isDirectory = true;
unsigned errors=0; std::vector<Glib::ustring> names;
for( int iArg=1; iArg<argc; iArg++){ Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path ( argv[iArg] );
if( argv[iArg][0]=='-' ){ safe_build_file_list (dir, names, argv[iArg] );
switch( argv[iArg][1]){ for(size_t iFile=0; iFile< names.size(); iFile++ ){
case 'O': if( !safe_file_test( names[iFile] , Glib::FILE_TEST_IS_DIR)){
copyParamsFile = true; // skip files without extension and pp3 files
case 'o': // outputfile or dir Glib::ustring s(names[iFile]);
if( iArg+1 <argc ){ Glib::ustring::size_type ext= s.find_last_of('.');
iArg++; if( Glib::ustring::npos == ext )
outputPath = Glib::filename_to_utf8 (argv[iArg]); continue;
if( safe_file_test (outputPath, Glib::FILE_TEST_IS_DIR)) if( ! s.substr(ext).compare( paramFileExtension ))
outputDirectory=true; continue;
} inputFiles.push_back( names[iFile] );
break; }
case 'p': // processing parameters for all inputs }
if( iArg+1 <argc ){ }else{
iArg++; inputFiles.push_back( safe_locale_to_utf8 (argv[iArg]) );
processingParams = Glib::filename_to_utf8 ( argv[iArg] ); }
} }
break; break;
case 'S': case 'h':
useDefaultIfAbsent=false; case '?':
case 's': // Processing params next to file (.pp3 appended) default:
sideProcParams = true; std::cerr << "RawTherapee, " << VERSION << std::endl;
break; std::cerr << "Copyright (c)2004-2011 Gabor Horvath <hgabor@rawtherapee.com>"<< std::endl << std::endl;
case 'Y': std::cerr << "Usage:"<< std::endl;
overwriteFiles =true; std::cerr << Glib::path_get_basename(argv[0]) << " [<selected dir>] : start RT GUI browser inside dir."<< std::endl;
break; std::cerr << Glib::path_get_basename(argv[0]) << " <file> : start GUI editor with file."<< std::endl;
case 'j': std::cerr << Glib::path_get_basename(argv[0]) << " -c <inputDir>|<file list> : convert files in batch with default parameters."<< std::endl<< std::endl;
outputType = "jpg"; std::cerr << "Other options used with -c (that must be last option) "<< std::endl;
sscanf(&argv[iArg][2],"%d",&compression); 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;
break; std::cerr << " -o <outputFile>|<outputDir> : select output directory."<< std::endl;
case 't': std::cerr << " -O <outputFile>|<outputDir> : select output dir and copy pp3 file into it"<< std::endl;
outputType = "tif"; std::cerr << " -s : select parameters to be pp3 file next to input file (with same name)"<< std::endl;
compression = ((argv[iArg][2]!='1')?0:1); std::cerr << " ex: for IMG001.NEF there should be IMG001.NEF.pp3 in the same dir" << std::endl;
break; std::cerr << " if absent use default" << std::endl;
case 'n': std::cerr << " -S : like -s but skip if pp3 file not found." << std::endl;
outputType = "png"; std::cerr << " -p <file.pp3> : specify pp3 file to be used for all conversions."<< std::endl;
compression = -1; std::cerr << " -j[compression] : specify output to be jpeg.(default)"<< std::endl;
break; std::cerr << " -t : specify output to be tif."<< std::endl;
case 'c': // MUST be last option std::cerr << " -n : specify output to be png."<< std::endl;
while( iArg+1 <argc ){ std::cerr << " -Y : overwrite output if present."<< std::endl;
iArg++; return -1;
if( !safe_file_test( argv[iArg], Glib::FILE_TEST_EXISTS )){ }
std::cerr << argv[iArg] << " doesn't exist."<< std::endl; }else{
continue; argv1 = safe_locale_to_utf8 ( argv[iArg] );
} if( outputDirectory ){
if( safe_file_test( argv[iArg], Glib::FILE_TEST_IS_DIR )){ options.savePathFolder = outputPath;
isDirectory = true; options.saveUsePathTemplate = false;
std::vector<Glib::ustring> names; }
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path ( argv[iArg] ); else {
safe_build_file_list (dir, names, argv[iArg] ); options.saveUsePathTemplate = true;
for(size_t iFile=0; iFile< names.size(); iFile++ ){ if (!options.savePathTemplate.length())
if( !safe_file_test( names[iFile] , Glib::FILE_TEST_IS_DIR)){ // If the save path template is empty, we use its default value
// skip files without extension and pp3 files options.savePathTemplate = "%p1/converted/%f";
Glib::ustring s(names[iFile]); }
Glib::ustring::size_type ext= s.find_last_of('.'); if (outputType == "jpg") {
if( Glib::ustring::npos == ext ) options.saveFormat.format = outputType;
continue; options.saveFormat.jpegQuality = compression;
if( ! s.substr(ext).compare( paramFileExtension )) } else if (outputType == "tif") {
continue; options.saveFormat.format = outputType;
inputFiles.push_back( names[iFile] ); } else if (outputType == "png") {
} options.saveFormat.format = outputType;
} }
}else{ break;
inputFiles.push_back( Glib::filename_to_utf8 (argv[iArg]) ); }
} }
} if( !argv1.empty() )
break; return 1;
case 'h': if( !inputFiles.size() )
case '?': return 2;
default:
std::cerr << "RawTherapee, " << VERSION << std::endl; rtengine::procparams::ProcParams params,paramsRaw,paramsImg, *currentParams;
std::cerr << "Copyright (c)2004-2011 Gabor Horvath <hgabor@rawtherapee.com>"<< std::endl << std::endl; if( !sideProcParams ){
std::cerr << "Usage:"<< std::endl; if( processingParams.length()>0 )
std::cerr << Glib::path_get_basename(argv[0]) << " [<selected dir>] : start RT GUI browser inside dir."<< std::endl; params.load ( processingParams );
std::cerr << Glib::path_get_basename(argv[0]) << " <file> : start GUI editor with file."<< std::endl; else{
std::cerr << Glib::path_get_basename(argv[0]) << " -c <inputDir>|<file list> : convert files in batch with default parameters."<< std::endl<< std::endl; paramsRaw.load(options.profilePath+"/"+options.defProfRaw+paramFileExtension);
std::cerr << "Other options used with -c (that must be last option) "<< std::endl; paramsImg.load(options.profilePath+"/"+options.defProfImg+paramFileExtension);
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; for( size_t iFile=0; iFile< inputFiles.size(); iFile++){
std::cerr << " ex: for IMG001.NEF there should be IMG001.NEF.pp3 in the same dir" << std::endl; Glib::ustring inputFile = inputFiles[iFile];
std::cerr << " if absent use default" << std::endl; std::cout << "Processing: " << inputFile << 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; rtengine::InitialImage* ii=NULL;
std::cerr << " -j[compression] : specify output to be jpeg.(default)"<< std::endl; rtengine::ProcessingJob* job =NULL;
std::cerr << " -t : specify output to be tif."<< std::endl; int errorCode;
std::cerr << " -n : specify output to be png."<< std::endl; bool isRaw=false;
std::cerr << " -Y : overwrite output if present."<< std::endl;
return -1; Glib::ustring outputFile;
} if( outputType.empty() )
}else{ outputType = "jpg";
argv1 = Glib::filename_to_utf8 ( argv[iArg] ); if( outputPath.empty() ){
if( outputDirectory ){ Glib::ustring s = inputFile;
options.savePathFolder = outputPath; Glib::ustring::size_type ext= s.find_last_of('.');
options.saveUsePathTemplate = false; outputFile = s.substr(0,ext)+ "." + outputType;
} }else if( outputDirectory ){
if (outputType == "jpg") { Glib::ustring s = Glib::path_get_basename( inputFile );
options.saveFormat.format = outputType; Glib::ustring::size_type ext= s.find_last_of('.');
options.saveFormat.jpegQuality = compression; outputFile = outputPath + "/" + s.substr(0,ext) + "." + outputType;
} else if (outputType == "tif") { }else{
options.saveFormat.format = outputType; Glib::ustring s = outputPath;
} else if (outputType == "png") { Glib::ustring::size_type ext= s.find_last_of('.');
options.saveFormat.format = outputType; outputFile = s.substr(0,ext) + "." + outputType;
} }
break; if( inputFile == outputFile){
} std::cerr << "Cannot overwrite: " << inputFile << std::endl;
} continue;
if( !argv1.empty() ) }
return 1; if( !overwriteFiles && safe_file_test( outputFile , Glib::FILE_TEST_EXISTS ) ){
if( !inputFiles.size() ) std::cerr << outputFile <<" already exists: use -Y option to overwrite. This image has been skipped." << std::endl;
return 2; continue;
}
rtengine::procparams::ProcParams params,paramsRaw,paramsImg, *currentParams;
if( !sideProcParams ){ // Load the image
if( processingParams.length()>0 ) ii = rtengine::InitialImage::load ( inputFile, true, &errorCode, NULL );
params.load ( processingParams ); if (ii)
else{ isRaw=true;
paramsRaw.load(options.profilePath+"/"+options.defProfRaw+paramFileExtension); else
paramsImg.load(options.profilePath+"/"+options.defProfImg+paramFileExtension); ii = rtengine::InitialImage::load ( inputFile , false, &errorCode, NULL );
} if (!ii) {
} errors++;
std::cerr << "Error loading file: "<< inputFile << std::endl;
for( size_t iFile=0; iFile< inputFiles.size(); iFile++){ continue;
Glib::ustring inputFile = inputFiles[iFile]; }
std::cout << "Processing: " << inputFile << std::endl; if( sideProcParams ){
Glib::ustring sideProcessingParams = inputFile + paramFileExtension;
rtengine::InitialImage* ii=NULL; if( !safe_file_test( sideProcessingParams, Glib::FILE_TEST_EXISTS ) || params.load ( sideProcessingParams )){
rtengine::ProcessingJob* job =NULL; if( useDefaultIfAbsent ){
int errorCode; currentParams = isRaw? &paramsRaw: &paramsImg;
bool isRaw=false; }else{
delete ii;
Glib::ustring outputFile; errors++;
if( outputType.empty() ) std::cerr << "Error loading processing params: "<< sideProcessingParams << std::endl;
outputType = "jpg"; continue;
if( outputPath.empty() ){ }
Glib::ustring s = inputFile; }else
Glib::ustring::size_type ext= s.find_last_of('.'); currentParams = &params;
outputFile = s.substr(0,ext)+ "." + outputType; }else if( processingParams.length()>0 ){
}else if( outputDirectory ){ currentParams = &params;
Glib::ustring s = Glib::path_get_basename( inputFile ); }else if(isRaw ){
Glib::ustring::size_type ext= s.find_last_of('.'); currentParams = &paramsRaw;
outputFile = outputPath + "/" + s.substr(0,ext) + "." + outputType; }else{
}else{ currentParams = &paramsImg;
Glib::ustring s = outputPath; }
Glib::ustring::size_type ext= s.find_last_of('.'); job = rtengine::ProcessingJob::create (ii, *currentParams);
outputFile = s.substr(0,ext) + "." + outputType; if( !job ){
} errors++;
if( inputFile == outputFile){ std::cerr << "Error creating processing for: "<< inputFile << std::endl;
std::cerr << "Cannot overwrite:" << inputFile << std::endl; ii->decreaseRef();
continue; continue;
} }
if( !overwriteFiles && safe_file_test( outputFile , Glib::FILE_TEST_EXISTS ) ){
std::cerr << outputFile <<" already exists: use -Y option to overwrite:" << std::endl; // Process image
continue; rtengine::IImage16* resultImage = rtengine::processImage (job, errorCode, NULL, options.tunnelMetaData);
} if( !resultImage ){
errors++;
// Load the image std::cerr << "Error processing: "<< inputFile << std::endl;
ii = rtengine::InitialImage::load ( inputFile, true, &errorCode, NULL ); rtengine::ProcessingJob::destroy( job );
if (ii) continue;
isRaw=true; }
else // save image to disk
ii = rtengine::InitialImage::load ( inputFile , false, &errorCode, NULL ); if( outputType=="jpg" )
if (!ii) { errorCode = resultImage->saveAsJPEG( outputFile, compression );
errors++; else if( outputType=="tif" )
std::cerr << "Error loading file:"<< inputFile << std::endl; errorCode = resultImage->saveAsTIFF( outputFile, bits, compression==0 );
continue; else if( outputType=="png" )
} errorCode = resultImage->saveAsPNG( outputFile,compression, bits );
if( sideProcParams ){ else
Glib::ustring sideProcessingParams = inputFile + paramFileExtension; errorCode = resultImage->saveToFile (outputFile);
if( !safe_file_test( sideProcessingParams, Glib::FILE_TEST_EXISTS ) || params.load ( sideProcessingParams )){
if( useDefaultIfAbsent ){ if(errorCode){
currentParams = isRaw? &paramsRaw: &paramsImg; errors++;
}else{ std::cerr << "Error saving to: "<< outputFile << std::endl;
delete ii; }else{
errors++; if( copyParamsFile ){
std::cerr << "Error loading processing params:"<< sideProcessingParams << std::endl; Glib::ustring outputProcessingParams = outputFile + paramFileExtension;
continue; currentParams->save( outputProcessingParams );
} }
}else }
currentParams = &params;
}else if( processingParams.length()>0 ){ ii->decreaseRef();
currentParams = &params; resultImage->free();
}else if(isRaw ){ }
currentParams = &paramsRaw; return errors>0?-2:0;
}else{ }
currentParams = &paramsImg;
}
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, options.tunnelMetaData);
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;
}

View File

@@ -1,213 +0,0 @@
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
* Copyright (c) 2010 Sasha Vasko <sasha@aftercode.net>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <safegtk.h>
#include <guiutils.h>
Glib::RefPtr<Gdk::Pixbuf> safe_create_from_file(const std::string& filename)
{
Glib::RefPtr<Gdk::Pixbuf> res;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try {
res = Gdk::Pixbuf::create_from_file (filename);
}
catch (Glib::Exception& ex) {
printf ("%s\n", ex.what().c_str());
}
#else
std::auto_ptr<Glib::Error> error;
res = Gdk::Pixbuf::create_from_file (filename, error);
if (error.get())
printf ("%s\n", error->what().c_str());
#endif
return res;
}
Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const std::string& filename)
{
Cairo::RefPtr<Cairo::ImageSurface> res;
if (!Glib::file_test (filename, Glib::FILE_TEST_EXISTS)) {
printf ("ERROR: File \"%s\" not found.\n", filename.c_str());
} else {
try {
res = Cairo::ImageSurface::create_from_png (filename);
} catch (...) {}
}
return res;
}
Glib::RefPtr<Gio::FileInfo> safe_query_file_info (Glib::RefPtr<Gio::File> &file)
{
Glib::RefPtr<Gio::FileInfo> info;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try { info = file->query_info(); }catch (...) { }
#else
std::auto_ptr<Glib::Error> error;
info = file->query_info("*", Gio::FILE_QUERY_INFO_NONE, error);
#endif
return info;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
# define SAFE_ENUMERATOR_CODE_START \
do{try { if ((dirList = dir->enumerate_children ())) \
for (Glib::RefPtr<Gio::FileInfo> info = dirList->next_file(); info; info = dirList->next_file()) {
# define SAFE_ENUMERATOR_CODE_END \
}} catch (Glib::Exception& ex) { printf ("%s\n", ex.what().c_str()); }}while(0)
#else
# define SAFE_ENUMERATOR_CODE_START \
do{std::auto_ptr<Glib::Error> error; Glib::RefPtr<Gio::Cancellable> cancellable; \
if ((dirList = dir->enumerate_children (cancellable, "*", Gio::FILE_QUERY_INFO_NONE, error))) \
for (Glib::RefPtr<Gio::FileInfo> info = dirList->next_file(cancellable, error); !error.get() && info; info = dirList->next_file(cancellable, error)) {
# define SAFE_ENUMERATOR_CODE_END } if (error.get()) printf ("%s\n", error->what().c_str());}while (0)
#endif
void safe_build_file_list (Glib::RefPtr<Gio::File> &dir, std::vector<FileMTimeInfo> &flist)
{
Glib::RefPtr<Gio::FileEnumerator> dirList;
if (dir) {
SAFE_ENUMERATOR_CODE_START
flist.push_back (FileMTimeInfo (removeExtension(info->get_name()), info->modification_time()));
SAFE_ENUMERATOR_CODE_END;
}
}
void safe_build_file_list (Glib::RefPtr<Gio::File> &dir, std::vector<Glib::ustring> &names, const Glib::ustring &directory)
{
Glib::RefPtr<Gio::FileEnumerator> dirList;
if (dir) {
SAFE_ENUMERATOR_CODE_START
names.push_back (Glib::build_filename (directory, info->get_name()));
SAFE_ENUMERATOR_CODE_END;
}
}
void safe_build_subdir_list (Glib::RefPtr<Gio::File> &dir, std::vector<Glib::ustring> &subDirs, bool add_hidden)
{
Glib::RefPtr<Gio::FileEnumerator> dirList;
if (dir)
{
// CD-ROMs with no drive inserted are reported, but do not exist, causing RT to crash
if (!Glib::file_test(dir->get_path(),Glib::FILE_TEST_EXISTS)) return;
SAFE_ENUMERATOR_CODE_START
if (info->get_file_type() == Gio::FILE_TYPE_DIRECTORY && (!info->is_hidden() || add_hidden))
subDirs.push_back (info->get_name());
SAFE_ENUMERATOR_CODE_END;
}
}
Glib::ustring safe_locale_to_utf8 (const std::string& src)
{
Glib::ustring utf8_str;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try {
utf8_str = Glib::locale_to_utf8(src);
}
catch (const Glib::ConvertError& e) {
utf8_str = Glib::convert_with_fallback(src, "UTF8", "LATIN1","?");
}
#else
{
std::auto_ptr<Glib::Error> error;
utf8_str = locale_to_utf8(src, error);
if (error.get())
utf8_str = Glib::convert_with_fallback(src, "UTF8", "LATIN1","?", error);
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return utf8_str;
}
std::string safe_locale_from_utf8 (const Glib::ustring& utf8_str)
{
std::string str;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try {
str = Glib::locale_from_utf8(utf8_str);
}
catch (const Glib::ConvertError& e) {
//str = Glib::convert_with_fallback(utf8_str, "LATIN1", "UTF8", "?");
}
#else
{
std::auto_ptr<Glib::Error> error;
str = Glib::locale_from_utf8(utf8_str, error);
/*if (error.get())
{str = Glib::convert_with_fallback(utf8_str, "LATIN1", "UTF8", "?", error);}*/
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return str;
}
bool safe_spawn_command_line_async (const Glib::ustring& cmd_utf8)
{
std::string cmd;
bool success = false;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try {
cmd = Glib::filename_from_utf8(cmd_utf8);
printf ("command line: |%s|\n", cmd.c_str());
Glib::spawn_command_line_async (cmd);
success = true;
} catch (Glib::Exception& ex) {
printf ("%s\n", ex.what().c_str());
}
#else
std::auto_ptr<Glib::Error> error;
cmd = Glib::filename_from_utf8(cmd_utf8, error);
if (!error.get()) {
printf ("command line: |%s|\n", cmd.c_str());
Glib::spawn_command_line_async (cmd, error);
}
if (error.get())
printf ("%s\n", error->what().c_str());
else
success = true;
#endif
return success;
}
bool safe_spawn_command_line_sync (const Glib::ustring& cmd_utf8)
{
std::string cmd;
std::string stdOut;
std::string stdErr;
bool success = false;
int exitStatus=-1;
try {
cmd = Glib::filename_from_utf8(cmd_utf8);
printf ("command line: |%s|\n", cmd.c_str());
// if it crashes here on windows, make sure you have the GTK runtime files gspawn-win32-helper*.exe files in RT directory
Glib::spawn_command_line_sync (cmd,NULL,NULL, &exitStatus);
} catch (Glib::Exception& ex) {
printf ("%s\n", ex.what().c_str());
}
return (exitStatus==0);
}