From fe003b2752c68cf78e563f3d5cff29134bdd032d Mon Sep 17 00:00:00 2001 From: Hombre Date: Sun, 22 May 2011 18:20:35 +0200 Subject: [PATCH] (Partially) solved issue 663 : UTF-8 support at Windows for stable branch_3.0 --- rtengine/safegtk.cc | 23 +- rtengine/safegtk.h | 2 +- rtgui/main.cc | 766 ++++++++++++++++++++++---------------------- rtgui/safegtk.cc | 213 ------------ 4 files changed, 396 insertions(+), 608 deletions(-) delete mode 100644 rtgui/safegtk.cc diff --git a/rtengine/safegtk.cc b/rtengine/safegtk.cc index 6ba18662e..0d1a1e307 100644 --- a/rtengine/safegtk.cc +++ b/rtengine/safegtk.cc @@ -50,19 +50,22 @@ Glib::RefPtr safe_create_from_file(const std::string& filename) return res; } -Cairo::RefPtr safe_create_from_png(const std::string& filename) +Cairo::RefPtr safe_create_from_png(const Glib::ustring& filename) { - Cairo::RefPtr res; + Cairo::RefPtr res; - if (!safe_file_test (filename, Glib::FILE_TEST_EXISTS)) { - printf ("ERROR: File \"%s\" not found.\n", filename.c_str()); - } else { + // files_test need a std::string which (as stated in its proto) but will only work if + // we use the Glib::ustring filename !? + if (!Glib::file_test (filename, Glib::FILE_TEST_EXISTS)) { + printf ("ERROR: (ustring) File \"%s\" not found.\n", filename.c_str()); + } else { 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 (...) {} - } - - return res; + } + + return res; } Glib::RefPtr safe_query_file_info (Glib::RefPtr &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) { return ::g_mkdir_with_parents(dirName.c_str(), mode); -} \ No newline at end of file +} diff --git a/rtengine/safegtk.h b/rtengine/safegtk.h index ae8c597f4..3303833f5 100644 --- a/rtengine/safegtk.h +++ b/rtengine/safegtk.h @@ -6,7 +6,7 @@ #include Glib::RefPtr safe_create_from_file(const std::string& filename); -Cairo::RefPtr safe_create_from_png(const std::string& filename); +Cairo::RefPtr safe_create_from_png(const Glib::ustring& filename); class FileMTimeInfo { diff --git a/rtgui/main.cc b/rtgui/main.cc index 44b999244..ecb92d156 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -1,387 +1,385 @@ -/* - * This file is part of RawTherapee. - * - * Copyright (c) 2004-2010 Gabor Horvath - * - * 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 . - */ -// generated 2004/6/3 19:15:32 CEST by gabor@darkstar.(none) -// using glademm V2.5.0 -// -// newer (non customized) versions of this file go to raw.cc_new +/* + * This file is part of RawTherapee. + * + * Copyright (c) 2004-2010 Gabor Horvath + * + * 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 . + */ +// generated 2004/6/3 19:15:32 CEST by gabor@darkstar.(none) +// using glademm V2.5.0 +// +// 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#include +#include +#include +#endif + +#include + +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 -#include -#include -#include -#include -#include -#include -#include -#include + // get the path where the rawtherapee executable is stored + argv0 = Glib::path_get_dirname(argv0_); -#ifndef WIN32 -#include -#include -#include -#include -#endif - -#include - -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) -{ - - std::string argv0_; - -#ifdef WIN32 - char exname[512]; - GetModuleFileName (NULL, exname, 512); - argv0_ = exname; - // get the path where the rawtherapee is stored - int i; - for (i=argv0_.size()-1; (argv0_[i]!='/' && argv0_[i]!='\\') && i>0; i--); - if (argv0_[i]=='/' || argv0_[i]=='\\') - argv0_ = argv0_.substr(0,i); -#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]; - int i; - for (i=argv0_.size()-1; (argv0_[i]!='/' && argv0_[i]!='\\') && i>0; i--); - if (argv0_[i]=='/' || argv0_[i]=='\\') - argv0_ = argv0_.substr(0,i); - } -#endif - - - -#ifdef GLIBMM_EXCEPTIONS_ENABLED - argv0 = Glib::filename_to_utf8 (argv0_); -#else - std::auto_ptr error; - argv0 = Glib::filename_to_utf8 (argv0_, error); -#endif //GLIBMM_EXCEPTIONS_ENABLED - - Glib::thread_init(); - gdk_threads_init(); - Gio::init (); - - 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 - - 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 rcfiles; - rcfiles.push_back (argv0+"/themes/"+options.theme); - // Set the font face and size - Gtk::RC::parse_string (Glib::ustring::compose( - "style \"clearlooks-default\" { font_name = \"%1\" }", options.font)); - Gtk::RC::set_default_files (rcfiles); - } - Gtk::Main m(&argc, &argv); - - RTWindow *rtWindow = new class RTWindow(); - gdk_threads_enter (); - m.run(*rtWindow); - gdk_threads_leave (); - delete rtWindow; - rtengine::cleanup(); - return 0; -} - - -int processLineParams( int argc, char **argv ) -{ - std::vector 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 names; - Glib::RefPtr 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 << "RawTherapee, " << VERSION << std::endl; - std::cerr << "Copyright (c)2004-2011 Gabor Horvath "<< std::endl << std::endl; - std::cerr << "Usage:"<< std::endl; - std::cerr << Glib::path_get_basename(argv[0]) << " [] : start RT GUI browser inside dir."<< std::endl; - std::cerr << Glib::path_get_basename(argv[0]) << " : start GUI editor with file."<< std::endl; - std::cerr << Glib::path_get_basename(argv[0]) << " -c | : 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 | -O ] [-s | -S | -p ] [-j[1-100]|-t|-n] -Y -c "<< std::endl; - std::cerr << " -o | : select output directory."<< std::endl; - std::cerr << " -O | : 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 : 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, 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; -} +#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_); + } +#endif + + + + Glib::thread_init(); + gdk_threads_init(); + Gio::init (); + + 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 + + simpleEditor=false; + if( !argv1.empty() ) + if( safe_file_test(argv1, Glib::FILE_TEST_EXISTS) && !safe_file_test(argv1, Glib::FILE_TEST_IS_DIR)) + simpleEditor = true; + + if (!options.useSystemTheme) + { + std::vector rcfiles; + rcfiles.push_back (argv0+"/themes/"+options.theme); + // Set the font face and size + Gtk::RC::parse_string (Glib::ustring::compose( + "style \"clearlooks-default\" { font_name = \"%1\" }", options.font)); + Gtk::RC::set_default_files (rcfiles); + } + Gtk::Main m(&argc, &argv); + + RTWindow *rtWindow = new class RTWindow(); + gdk_threads_enter (); + m.run(*rtWindow); + gdk_threads_leave (); + delete rtWindow; + rtengine::cleanup(); + return 0; +} + + +int processLineParams( int argc, char **argv ) +{ + std::vector 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 names; + Glib::RefPtr 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( safe_locale_to_utf8 (argv[iArg]) ); + } + } + break; + case 'h': + case '?': + default: + std::cerr << "RawTherapee, " << VERSION << std::endl; + std::cerr << "Copyright (c)2004-2011 Gabor Horvath "<< std::endl << std::endl; + std::cerr << "Usage:"<< std::endl; + std::cerr << Glib::path_get_basename(argv[0]) << " [] : start RT GUI browser inside dir."<< std::endl; + std::cerr << Glib::path_get_basename(argv[0]) << " : start GUI editor with file."<< std::endl; + std::cerr << Glib::path_get_basename(argv[0]) << " -c | : 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 | -O ] [-s | -S | -p ] [-j[1-100]|-t|-n] -Y -c "<< std::endl; + std::cerr << " -o | : select output directory."<< std::endl; + std::cerr << " -O | : 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 : 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 = safe_locale_to_utf8 ( argv[iArg] ); + if( outputDirectory ){ + options.savePathFolder = outputPath; + options.saveUsePathTemplate = false; + } + else { + options.saveUsePathTemplate = true; + if (!options.savePathTemplate.length()) + // If the save path template is empty, we use its default value + options.savePathTemplate = "%p1/converted/%f"; + } + 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. This image has been skipped." << 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, 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; +} diff --git a/rtgui/safegtk.cc b/rtgui/safegtk.cc deleted file mode 100644 index bc54ddde2..000000000 --- a/rtgui/safegtk.cc +++ /dev/null @@ -1,213 +0,0 @@ -/* - * This file is part of RawTherapee. - * - * Copyright (c) 2004-2010 Gabor Horvath - * Copyright (c) 2010 Sasha Vasko - * - * 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 . - */ - -#include -#include - -Glib::RefPtr safe_create_from_file(const std::string& filename) -{ - Glib::RefPtr 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 error; - res = Gdk::Pixbuf::create_from_file (filename, error); - if (error.get()) - printf ("%s\n", error->what().c_str()); -#endif - - return res; -} - -Cairo::RefPtr safe_create_from_png(const std::string& filename) -{ - Cairo::RefPtr 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 safe_query_file_info (Glib::RefPtr &file) -{ - Glib::RefPtr info; -#ifdef GLIBMM_EXCEPTIONS_ENABLED - try { info = file->query_info(); }catch (...) { } -#else - std::auto_ptr 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 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 error; Glib::RefPtr cancellable; \ - if ((dirList = dir->enumerate_children (cancellable, "*", Gio::FILE_QUERY_INFO_NONE, error))) \ - for (Glib::RefPtr 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 &dir, std::vector &flist) -{ - Glib::RefPtr 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 &dir, std::vector &names, const Glib::ustring &directory) -{ - Glib::RefPtr 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 &dir, std::vector &subDirs, bool add_hidden) -{ - Glib::RefPtr 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 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 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 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); -}