From ddfe7e0c181b3a10e3ee68d9e936bbb0403a19d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Tue, 11 Sep 2018 22:02:09 +0200 Subject: [PATCH] Optimize SaveFormat selection (#4789) --- rtgui/options.h | 22 ++++++- rtgui/saveformatpanel.cc | 129 ++++++++++++++++++++++++++++----------- rtgui/saveformatpanel.h | 1 - 3 files changed, 114 insertions(+), 38 deletions(-) diff --git a/rtgui/options.h b/rtgui/options.h index ee95d5cb3..84e01fbf3 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -55,6 +55,26 @@ struct SaveFormat { saveParams (true) { } + SaveFormat( + const Glib::ustring& _format, + int _png_bits, + int _jpeg_quality, + int _jpeg_sub_samp, + int _tiff_bits, + bool _tiff_float, + bool _tiff_uncompressed, + bool _save_params + ) : + format(_format), + pngBits(_png_bits), + jpegQuality(_jpeg_quality), + jpegSubSamp(_jpeg_sub_samp), + tiffBits(_tiff_bits), + tiffFloat(_tiff_float), + tiffUncompressed(_tiff_uncompressed), + saveParams(_save_params) + { + } Glib::ustring format; int pngBits; @@ -272,7 +292,7 @@ public: int cropPPI; enum CropGuidesMode { CROP_GUIDE_NONE, CROP_GUIDE_FRAME, CROP_GUIDE_FULL }; CropGuidesMode cropGuides; - bool cropAutoFit; + bool cropAutoFit; // Performance options Glib::ustring clutsDir; diff --git a/rtgui/saveformatpanel.cc b/rtgui/saveformatpanel.cc index 755cb9239..f8b50b6bd 100644 --- a/rtgui/saveformatpanel.cc +++ b/rtgui/saveformatpanel.cc @@ -16,10 +16,90 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include + #include "saveformatpanel.h" #include "multilangmgr.h" #include "guiutils.h" +namespace +{ + +const std::array sf_templates = { + SaveFormat( + "jpg", + 8, + 90, + 2, + 8, + false, + true, + true + ), + SaveFormat( + "tif", + 8, + 90, + 2, + 8, + false, + true, + true + ), + SaveFormat( + "tif", + 8, + 90, + 2, + 16, + false, + true, + true + ), + SaveFormat( + "tif", + 8, + 90, + 2, + 16, + true, + true, + true + ), + SaveFormat( + "tif", + 8, + 90, + 2, + 32, + true, + true, + true + ), + SaveFormat( + "png", + 8, + 90, + 2, + 8, + false, + true, + true + ), + SaveFormat( + "png", + 16, + 90, + 2, + 8, + false, + true, + true + ) +}; + +} + SaveFormatPanel::SaveFormatPanel () : listener (nullptr) { @@ -45,14 +125,6 @@ SaveFormatPanel::SaveFormatPanel () : listener (nullptr) format->append ("PNG (8-bit)"); format->append ("PNG (16-bit)"); - fstr[0] = "jpg"; - fstr[1] = "tif"; - fstr[2] = "tif"; - fstr[3] = "tif"; - fstr[4] = "tif"; - fstr[5] = "png"; - fstr[6] = "png"; - hb1->attach (*flab, 0, 0, 1, 1); hb1->attach (*format, 1, 0, 1, 1); hb1->show_all(); @@ -148,45 +220,31 @@ void SaveFormatPanel::init (SaveFormat &sf) SaveFormat SaveFormatPanel::getFormat () { - SaveFormat sf; - int sel = format->get_active_row_number(); - sf.format = fstr[sel]; + const unsigned int sel = format->get_active_row_number(); - if (sel == 6) { - sf.pngBits = 16; - } else { - sf.pngBits = 8; + if (sel < sf_templates.size()) { + sf = sf_templates[sel]; } - if (sel == 2 || sel == 3) { - sf.tiffBits = 16; - } else if (sel == 4) { - sf.tiffBits = 32; - } else { - sf.tiffBits = 8; - } - - sf.tiffFloat = sel == 4 || sel == 3; - - sf.jpegQuality = (int) jpegQual->getValue (); - sf.jpegSubSamp = jpegSubSamp->get_active_row_number() + 1; + sf.jpegQuality = jpegQual->getValue(); + sf.jpegSubSamp = jpegSubSamp->get_active_row_number() + 1; sf.tiffUncompressed = tiffUncompressed->get_active(); - sf.saveParams = savesPP->get_active (); + sf.saveParams = savesPP->get_active(); + return sf; } void SaveFormatPanel::formatChanged () { + const unsigned int act = format->get_active_row_number(); - int act = format->get_active_row_number(); - - if (act < 0 || act > 6) { + if (act >= sf_templates.size()) { return; } - Glib::ustring fr = fstr[act]; + const Glib::ustring& fr = sf_templates[act].format; if (fr == "jpg") { jpegOpts->show_all(); @@ -206,14 +264,13 @@ void SaveFormatPanel::formatChanged () void SaveFormatPanel::adjusterChanged (Adjuster* a, double newval) { + const unsigned int act = format->get_active_row_number(); - int act = format->get_active_row_number(); - - if (act < 0 || act > 4) { + if (act >= sf_templates.size()) { return; } if (listener) { - listener->formatChanged (fstr[act]); + listener->formatChanged(sf_templates[act].format); } } diff --git a/rtgui/saveformatpanel.h b/rtgui/saveformatpanel.h index 788593d9e..47011be18 100644 --- a/rtgui/saveformatpanel.h +++ b/rtgui/saveformatpanel.h @@ -44,7 +44,6 @@ protected: Gtk::Grid* jpegOpts; Gtk::Label* jpegSubSampLabel; FormatChangeListener* listener; - Glib::ustring fstr[7]; Gtk::CheckButton* savesPP;