diff --git a/rtdata/languages/default b/rtdata/languages/default index 525195a53..6adf5601f 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -3956,7 +3956,7 @@ TP_RESIZE_FITBOX;Bounding Box TP_RESIZE_FULLIMAGE;Full Image TP_RESIZE_H;Height: TP_RESIZE_HEIGHT;Height -TP_RESIZE_LABEL;Resize +TP_RESIZE_LABEL;Resize & Framing TP_RESIZE_LANCZOS;Lanczos TP_RESIZE_LE;Long Edge: TP_RESIZE_LONG;Long Edge diff --git a/rtengine/ipresize.cc b/rtengine/ipresize.cc index 60a776637..043c302ec 100644 --- a/rtengine/ipresize.cc +++ b/rtengine/ipresize.cc @@ -1069,7 +1069,9 @@ Imagefloat* ImProcFunctions::drawFrame(Imagefloat* rgb, const FramingParams& par Imagefloat* framed = new Imagefloat(dims.framedWidth, dims.framedHeight); - auto clip = [](int v) { return std::max(0, std::min(v, 65535)); }; + // Color::gamma2curve expects a 16-bit value, but the GUI sliders are + // using 8-bit values. Step up the user value to 16-bits. + auto clip = [](int v) { return std::max(0, std::min(v, 255)) * 256; }; float r = Color::gamma2curve[clip(params.borderRed)]; float g = Color::gamma2curve[clip(params.borderGreen)]; diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index 289992653..5d3276ccd 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -35,6 +35,7 @@ set(NONCLISOURCEFILES colorappearance.cc coloredbar.cc colortoning.cc + colorpreview.cc controllines.cc controlspotpanel.cc coordinateadjuster.cc diff --git a/rtgui/colorpreview.cc b/rtgui/colorpreview.cc new file mode 100644 index 000000000..97fd53252 --- /dev/null +++ b/rtgui/colorpreview.cc @@ -0,0 +1,69 @@ +/* + * 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 . + * + * 2024-2024 Daniel Gao + */ + +#include "colorpreview.h" + +#include "rtscalable.h" + +ColorPreview::ColorPreview() : color_red(1.0), color_green(1.0), color_blue(1.0) +{ +} + +void ColorPreview::setRgb(double r, double g, double b) +{ + color_red = r; + color_green = g; + color_blue = b; + + queue_draw(); +} + +bool ColorPreview::on_draw(const Cairo::RefPtr& cr) +{ + cr->set_source_rgb(color_red, color_green, color_blue); + cr->paint(); + + return true; +} + +void ColorPreview::get_preferred_height_vfunc(int& minimum_height, int& natural_height) const +{ + minimum_height = RTScalable::scalePixelSize(10); + natural_height = RTScalable::scalePixelSize(100); +} + +void ColorPreview::get_preferred_width_vfunc(int& minimum_width, int& natural_width) const +{ + minimum_width = RTScalable::scalePixelSize(10); + natural_width = RTScalable::scalePixelSize(100); +} + +void ColorPreview::get_preferred_height_for_width_vfunc(int width, int& minimum_height, + int& natural_height) const +{ + get_preferred_height_vfunc(minimum_height, natural_height); +} + +void ColorPreview::get_preferred_width_for_height_vfunc(int height, int& minimum_width, + int& natural_width) const +{ + get_preferred_width_vfunc(minimum_width, natural_width); +} diff --git a/rtgui/colorpreview.h b/rtgui/colorpreview.h new file mode 100644 index 000000000..755d5fae1 --- /dev/null +++ b/rtgui/colorpreview.h @@ -0,0 +1,53 @@ +/* + * 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 . + * + * 2024-2024 Daniel Gao + */ + +#pragma once + +#include + +/** + * This widget displays a singular color as its contents. + */ +class ColorPreview : public Gtk::DrawingArea +{ +public: + ColorPreview(); + + // Values between 0.0 and 1.0 as in + // Cairo::Context::set_source_rgb() + void setRgb(double r, double g, double b); + + // Gtk::DrawingArea + bool on_draw(const Cairo::RefPtr& cr) override; + + // Gtk::Widget + void get_preferred_height_vfunc(int& minimum_height, int& natural_height) const override; + void get_preferred_width_vfunc(int& minimum_width, int& natural_width) const override; + void get_preferred_height_for_width_vfunc(int width, int& minimum_height, + int& natural_height) const override; + void get_preferred_width_for_height_vfunc(int height, int & minimum_width, + int& natural_width) const override; + +private: + double color_red; + double color_green; + double color_blue; +}; diff --git a/rtgui/framing.cc b/rtgui/framing.cc index d277f6eca..62587a518 100644 --- a/rtgui/framing.cc +++ b/rtgui/framing.cc @@ -15,16 +15,18 @@ * * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . - * + * * 2024-2024 Daniel Gao */ #include "framing.h" #include "aspectratios.h" +#include "colorpreview.h" #include "paramsedited.h" #include "resize.h" +#include "../rtengine/color.h" #include "../rtengine/procparams.h" #include @@ -211,6 +213,7 @@ FramingParams::Basis mapBasis(int comboIndex) constexpr int INITIAL_IMG_WIDTH = 100000; constexpr int INITIAL_IMG_HEIGHT = 100000; +constexpr int MAX_COLOR_VAL = 255; constexpr int ROW_SPACING = 4; constexpr float FRAME_LABEL_ALIGN_X = 0.025; @@ -457,16 +460,23 @@ void Framing::setupBorderColorsGui() frame->set_label_widget(*label); Gtk::Box* const box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL)); - redAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_RED"), 0, 65535, 1, 65535)); + redAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_RED"), 0, MAX_COLOR_VAL, 1, MAX_COLOR_VAL)); box->add(*redAdj); - greenAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_GREEN"), 0, 65535, 1, 65535)); + greenAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_GREEN"), 0, MAX_COLOR_VAL, 1, MAX_COLOR_VAL)); box->add(*greenAdj); - blueAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_BLUE"), 0, 65535, 1, 65535)); + blueAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_BLUE"), 0, MAX_COLOR_VAL, 1, MAX_COLOR_VAL)); box->add(*blueAdj); + Gtk::Frame* const colorFrame = Gtk::manage(new Gtk::Frame()); + colorPreview = Gtk::manage(new ColorPreview()); + colorFrame->add(*colorPreview); + box->add(*colorFrame); + frame->add(*box); pack_start(*frame); + updateBorderColorGui(); + redAdj->setAdjusterListener(this); greenAdj->setAdjusterListener(this); blueAdj->setAdjusterListener(this); @@ -502,6 +512,7 @@ void Framing::read(const rtengine::procparams::ProcParams* pp, const ParamsEdite updateFramingMethodGui(); updateBorderSizeGui(); + updateBorderColorGui(); setDimensions(); } @@ -827,8 +838,26 @@ void Framing::updateBorderSizeGui() minSizeFrameContent->set_sensitive(minSizeEnabled->get_active()); } +void Framing::updateBorderColorGui() +{ + auto gamma = [](double val) { + // adjuster is [0.0, 255.0] + // gamma2curve expects [0, 65535] + // setRgb expects [0.0, 1.0] + return Color::gamma2curve[val * (MAX_COLOR_VAL + 1)] / 65535.0; + }; + double r = gamma(redAdj->getValue()); + double g = gamma(greenAdj->getValue()); + double b = gamma(blueAdj->getValue()); + colorPreview->setRgb(r, g, b); +} + void Framing::adjusterChanged(Adjuster* adj, double newVal) { + if (adj == redAdj || adj == greenAdj || adj == blueAdj) { + updateBorderColorGui(); + } + if (listener && (getEnabled() || batchMode)) { Glib::ustring costr; if (adj == relativeBorderSize) { diff --git a/rtgui/framing.h b/rtgui/framing.h index 93ca6b65f..0d709c446 100644 --- a/rtgui/framing.h +++ b/rtgui/framing.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . - * + * * 2024-2024 Daniel Gao */ @@ -27,6 +27,8 @@ #include +class ColorPreview; + class Framing final : public ToolParamBlock, public AdjusterListener, @@ -106,6 +108,7 @@ private: void setDimensions(); void updateFramingMethodGui(); void updateBorderSizeGui(); + void updateBorderColorGui(); // Framing method MyComboBoxText* framingMethod; @@ -141,6 +144,7 @@ private: Adjuster* redAdj; Adjuster* greenAdj; Adjuster* blueAdj; + ColorPreview* colorPreview; IdleRegister idleRegister; std::unique_ptr aspectRatioData;