From 7ccab91434bc75596826e124513a66b315ad5587 Mon Sep 17 00:00:00 2001 From: Daniel Gao Date: Mon, 11 Nov 2024 22:13:38 -0500 Subject: [PATCH] Implement drawing border for framing tool * Draws border after all resize operations are complete * Update the RGB sliders for 16-bit channels --- rtengine/improcfun.h | 2 ++ rtengine/ipresize.cc | 59 ++++++++++++++++++++++++++++++++++++++- rtengine/simpleprocess.cc | 4 ++- rtgui/framing.cc | 6 ++-- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 578704a50..6200f177d 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -237,6 +237,8 @@ enum class BlurType { int framedHeight = 0; }; FramingData framing(const FramingArgs& args) const; + Imagefloat* drawFrame(Imagefloat* rgb, const procparams::FramingParams& params, + const FramingData& dims) const; void deconvsharpening(float** luminance, float** buffer, const float* const * blend, int W, int H, const procparams::SharpeningParams &sharpenParam, double Scale); void deconvsharpeningloc(float** luminance, float** buffer, int W, int H, float** loctemp, int damp, double radi, int ite, int amo, int contrast, double blurrad, int sk); diff --git a/rtengine/ipresize.cc b/rtengine/ipresize.cc index 784d77055..16adff2ca 100644 --- a/rtengine/ipresize.cc +++ b/rtengine/ipresize.cc @@ -20,6 +20,7 @@ #include "improcfun.h" #include "alignedbuffer.h" +#include "color.h" #include "imagefloat.h" #include "labimage.h" #include "opthelper.h" @@ -1065,4 +1066,60 @@ ImProcFunctions::FramingData ImProcFunctions::framing(const FramingArgs& args) c return result; } -} // namespace rtengine \ No newline at end of file +// Draws the border around the input image. +// It should be called after gamma correction. +Imagefloat* ImProcFunctions::drawFrame(Imagefloat* rgb, const FramingParams& params, + const FramingData& dims) const +{ + if (rgb->getWidth() > dims.framedWidth || rgb->getHeight() > dims.framedHeight) { + return rgb; + } + if (rgb->getWidth() == dims.framedWidth && rgb->getHeight() == dims.framedHeight) { + return rgb; + } + + Imagefloat* framed = new Imagefloat(dims.framedWidth, dims.framedHeight); + + auto clip = [](int v) { return std::max(0, std::min(v, 65535)); }; + + float r = Color::gamma2curve[clip(params.borderRed)]; + float g = Color::gamma2curve[clip(params.borderGreen)]; + float b = Color::gamma2curve[clip(params.borderBlue)]; + +#ifdef _OPENMP + #pragma omp parallel for if (multiThread) +#endif + for (int i = 0; i < framed->getHeight(); i++) { + for (int j = 0; j < framed->getWidth(); j++) { + framed->r(i, j) = r; + framed->g(i, j) = g; + framed->b(i, j) = b; + } + } + + auto offset = [](int inner, int outer) { + double u = inner; + double v = outer; + return static_cast(std::round((v - u) / 2.0)); + }; + int rowOffset = offset(rgb->getHeight(), framed->getHeight()); + int colOffset = offset(rgb->getWidth(), framed->getWidth()); + +#ifdef _OPENMP + #pragma omp parallel for if (multiThread) +#endif + for (int i = 0; i < rgb->getHeight(); i++) { + for (int j = 0; j < rgb->getWidth(); j++) { + int row = i + rowOffset; + int col = j + colOffset; + + framed->r(row, col) = rgb->r(i, j); + framed->g(row, col) = rgb->g(i, j); + framed->b(row, col) = rgb->b(i, j); + } + } + + return framed; +} + +} // namespace rtengine diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 0c695c6a0..d5a94ea98 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -2027,7 +2027,9 @@ private: } } - // TODO: Blit framing border + image + if (framingData.enabled) { + readyImg = ipf.drawFrame(readyImg, params.framing, framingData); + } Exiv2Metadata info(imgsrc->getFileName()); diff --git a/rtgui/framing.cc b/rtgui/framing.cc index 677a63050..033e17578 100644 --- a/rtgui/framing.cc +++ b/rtgui/framing.cc @@ -449,11 +449,11 @@ 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, 255, 1, 255)); + redAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_RED"), 0, 65535, 1, 65535)); box->add(*redAdj); - greenAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_GREEN"), 0, 255, 1, 255)); + greenAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_GREEN"), 0, 65535, 1, 65535)); box->add(*greenAdj); - blueAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_BLUE"), 0, 255, 1, 255)); + blueAdj = Gtk::manage(new Adjuster(M("TP_FRAMING_BLUE"), 0, 65535, 1, 65535)); box->add(*blueAdj); frame->add(*box);