Added support for using RawTherapee as a GIMP plugin for opening RAW files

plugin code taken from Darktable
This commit is contained in:
Alberto Griggio
2017-05-18 15:59:56 +02:00
parent 3999bf179e
commit 54b66b7736
8 changed files with 876 additions and 13 deletions

View File

@@ -679,13 +679,17 @@ EditorPanel::EditorPanel (FilePanel* filePanel)
iops->attach_next_to (*vsep2, Gtk::POS_LEFT, 1, 1);
iops->attach_next_to (*progressLabel, Gtk::POS_LEFT, 1, 1);
iops->attach_next_to (*vsep1, Gtk::POS_LEFT, 1, 1);
iops->attach_next_to (*sendtogimp, Gtk::POS_LEFT, 1, 1);
if (!gimpPlugin) {
iops->attach_next_to (*sendtogimp, Gtk::POS_LEFT, 1, 1);
}
if (!simpleEditor) {
if (!gimpPlugin) {
iops->attach_next_to (*queueimg, Gtk::POS_LEFT, 1, 1);
}
iops->attach_next_to (*saveimgas, Gtk::POS_LEFT, 1, 1);
if (!gimpPlugin) {
iops->attach_next_to (*saveimgas, Gtk::POS_LEFT, 1, 1);
}
// Color management toolbar
@@ -1577,7 +1581,9 @@ bool EditorPanel::handleShortcutKey (GdkEventKey* event)
return true;
case GDK_KEY_s:
saveAsPressed();
if (!gimpPlugin) {
saveAsPressed();
}
return true;
case GDK_KEY_b:
@@ -1588,7 +1594,9 @@ bool EditorPanel::handleShortcutKey (GdkEventKey* event)
return true;
case GDK_KEY_e:
sendToGimpPressed();
if (!gimpPlugin) {
sendToGimpPressed();
}
return true;
case GDK_KEY_z:
@@ -1885,6 +1893,30 @@ void EditorPanel::sendToGimpPressed ()
}
bool EditorPanel::saveImmediately(const Glib::ustring &filename, SaveFormat sf)
{
rtengine::procparams::ProcParams pparams;
ipc->getParams (&pparams);
std::unique_ptr<rtengine::ProcessingJob> job(rtengine::ProcessingJob::create (ipc->getInitialImage(), pparams));
// save immediately
rtengine::IImage16 *img = rtengine::processImage(job.get(), err, nullptr, options.tunnelMetaData, false);
int err = 0;
if (sf.format == "tif") {
err = img->saveAsTIFF(filename, sf.tiffBits, sf.tiffUncompressed);
} else if (sf.format == "png") {
err = img->saveAsPNG(filename, sf.pngCompression, sf.pngBits);
} else if (sf.format == "jpg") {
err = img->saveAsJPEG(filename, sf.jpegQuality, sf.jpegSubSamp);
} else {
err = 1;
}
img->free();
return !err;
}
void EditorPanel::openPreviousEditorImage()
{
if (!simpleEditor && fPanel && !fname.empty()) {

View File

@@ -131,6 +131,8 @@ public:
void defaultMonitorProfileChanged(const Glib::ustring &profile_name, bool auto_monitor_profile);
bool saveImmediately(const Glib::ustring &filename, SaveFormat sf);
Gtk::Paned* catalogPane;
private:

View File

@@ -190,8 +190,13 @@ void FilePanel::init ()
dirBrowser->fillDirTree ();
placesBrowser->refreshPlacesList ();
if (argv1 != "" && Glib::file_test (argv1, Glib::FILE_TEST_IS_DIR)) {
dirBrowser->open (argv1);
//if (argv1 != "" && Glib::file_test (argv1, Glib::FILE_TEST_IS_DIR)) {
if (!argv1.empty() && Glib::file_test (argv1, Glib::FILE_TEST_EXISTS)) {
Glib::ustring d(argv1);
if (!Glib::file_test(d, Glib::FILE_TEST_IS_DIR)) {
d = Glib::path_get_dirname(d);
}
dirBrowser->open(d);
} else {
if (options.startupDir == STARTUPDIR_HOME) {
dirBrowser->open (PlacesBrowser::userPicturesDir ());

View File

@@ -60,7 +60,9 @@ Glib::ustring argv0;
Glib::ustring creditsPath;
Glib::ustring licensePath;
Glib::ustring argv1;
bool simpleEditor;
Glib::ustring argv2;
bool simpleEditor = false;
bool gimpPlugin = false;
Glib::RefPtr<Gtk::CssProvider> cssForced;
Glib::RefPtr<Gtk::CssProvider> cssRT;
//Glib::Threads::Thread* mainThread;
@@ -292,12 +294,23 @@ int main(int argc, char **argv)
#endif
simpleEditor = false;
//simpleEditor = false;
if( !argv1.empty() )
if (!argv1.empty()) {
if( Glib::file_test(argv1, Glib::FILE_TEST_EXISTS) && !Glib::file_test(argv1, Glib::FILE_TEST_IS_DIR)) {
simpleEditor = true;
}
}
if (gimpPlugin) {
if (!Glib::file_test(argv1, Glib::FILE_TEST_EXISTS) || Glib::file_test(argv1, Glib::FILE_TEST_IS_DIR)) {
printf("Error: argv1 doesn't exist\n");
return 1;
}
if (argv2.empty()) {
printf("Error: -gimp requires two arguments\n");
return 1;
}
}
Gtk::Main m(&argc, &argv);
@@ -385,7 +398,18 @@ int main(int argc, char **argv)
// opening the main window
m.run(*rtWindow);
if (gimpPlugin && rtWindow->epanel && rtWindow->epanel->isRealized()) {
SaveFormat sf;
sf.format = "tif";
sf.tiffBits = 16;
sf.tiffUncompressed = true;
sf.saveParams = true;
rtWindow->epanel->saveImmediately(argv2, sf);
}
gdk_threads_leave ();
delete rtWindow;
rtengine::cleanup();
@@ -429,6 +453,16 @@ int processLineParams( int argc, char **argv )
case 'w': // This case is handled outside this function
break;
#endif
case 'g':
if (currParam == "-gimp") {
simpleEditor = true;
gimpPlugin = true;
break;
}
// no break here on purpose
case 'v':
return 0;
case 'h':
case '?':
@@ -455,16 +489,24 @@ int processLineParams( int argc, char **argv )
#ifdef WIN32
std::cout << " -w Do not open the Windows console" << std::endl;
#endif
std::cout << " -v Print RawTherapee version number and exit" << std::endl;
std::cout << " -h -? Display this help message" << std::endl;
return -1;
}
}
} else {
argv1 = Glib::ustring(fname_to_utf8(argv[iArg]));
if (argv1.empty()) {
argv1 = Glib::ustring(fname_to_utf8(argv[iArg]));
#if ECLIPSE_ARGS
argv1 = argv1.substr(1, argv1.length()-2);
argv1 = argv1.substr(1, argv1.length()-2);
#endif
break;
} else if (gimpPlugin) {
argv2 = Glib::ustring(fname_to_utf8(argv[iArg]));
break;
}
if (!gimpPlugin) {
break;
}
}
}

View File

@@ -358,6 +358,7 @@ extern Options options;
extern Glib::ustring argv0;
extern Glib::ustring argv1;
extern bool simpleEditor;
extern bool gimpPlugin;
extern Glib::ustring versionString;
extern Glib::ustring paramFileExtension;

View File

@@ -282,6 +282,14 @@ RTWindow::RTWindow ()
show_all ();
bpanel->init (this);
if (!argv1.empty()) {
Thumbnail* thm = cacheMgr->getEntry(argv1);
if (thm) {
std::vector<Thumbnail *> entries(1, thm);
fpanel->fileCatalog->openRequested(entries);
}
}
}
if (!isSingleTabMode() && !simpleEditor) {
@@ -646,6 +654,7 @@ bool RTWindow::on_delete_event(GdkEventAny* event)
Options::save ();
hide();
on_delete_has_run = true;
return false;
}