From f95acfe74ec940482d02011a970eb0cb61630d5d Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Mon, 2 Dec 2019 17:32:13 +0100 Subject: [PATCH] Multithread lensfun vignetting correction --- rtengine/lcp.cc | 22 +++++++++++++++++ rtengine/lcp.h | 11 +++++---- rtengine/rawimagesource.cc | 25 +++----------------- rtengine/rtlensfun.cc | 48 ++++++++++++++++++++++---------------- rtengine/rtlensfun.h | 5 ++-- 5 files changed, 62 insertions(+), 49 deletions(-) diff --git a/rtengine/lcp.cc b/rtengine/lcp.cc index 7fec79717..c80a126f5 100644 --- a/rtengine/lcp.cc +++ b/rtengine/lcp.cc @@ -1135,6 +1135,17 @@ void rtengine::LCPMapper::correctCA(double& x, double& y, int cx, int cy, int ch y -= cy; } +void rtengine::LCPMapper::processVignette(int width, int height, float** rawData) const +{ +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) +#endif + + for (int y = 0; y < height; ++y) { + processVignetteLine(width, y, rawData[y]); + } +} + void rtengine::LCPMapper::processVignetteLine(int width, int y, float* line) const { // No need for swapXY, since vignette is in RAW and always before rotation @@ -1173,6 +1184,17 @@ void rtengine::LCPMapper::processVignetteLine(int width, int y, float* line) con } } +void rtengine::LCPMapper::processVignette3Channels(int width, int height, float** rawData) const +{ +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) +#endif + + for (int y = 0; y < height; ++y) { + processVignetteLine3Channels(width, y, rawData[y]); + } +} + void rtengine::LCPMapper::processVignetteLine3Channels(int width, int y, float* line) const { // No need for swapXY, since vignette is in RAW and always before rotation diff --git a/rtengine/lcp.h b/rtengine/lcp.h index 69fd43932..a54d25148 100644 --- a/rtengine/lcp.h +++ b/rtengine/lcp.h @@ -172,8 +172,8 @@ public: virtual void correctDistortion(double &x, double &y, int cx, int cy, double scale) const = 0; virtual bool isCACorrectionAvailable() const = 0; virtual void correctCA(double &x, double &y, int cx, int cy, int channel) const = 0; - virtual void processVignetteLine(int width, int y, float *line) const = 0; - virtual void processVignetteLine3Channels(int width, int y, float *line) const = 0; + virtual void processVignette(int width, int height, float** rawData) const = 0; + virtual void processVignette3Channels(int width, int height, float** rawData) const = 0; }; @@ -200,8 +200,8 @@ public: void correctDistortion(double &x, double &y, int cx, int cy, double scale) const override; // MUST be the first stage bool isCACorrectionAvailable() const override; void correctCA(double& x, double& y, int cx, int cy, int channel) const override; - void processVignetteLine(int width, int y, float* line) const override; - void processVignetteLine3Channels(int width, int y, float* line) const override; + void processVignette(int width, int height, float** rawData) const override; + void processVignette3Channels(int width, int height, float** rawData) const override; private: bool enableCA; // is the mapper capable if CA correction? @@ -210,6 +210,9 @@ private: LCPModelCommon mc; LCPModelCommon chrom[3]; // in order RedGreen/Green/BlueGreen bool isFisheye; + + void processVignetteLine(int width, int y, float* line) const; + void processVignetteLine3Channels(int width, int y, float* line) const; }; } diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 265c226b3..ea3152918 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -1399,32 +1399,13 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le if (ri->getSensorType() == ST_BAYER || ri->getSensorType() == ST_FUJI_XTRANS || ri->get_colors() == 1) { if(numFrames == 4) { for(int i = 0; i < 4; ++i) { -#ifdef _OPENMP - #pragma omp parallel for schedule(dynamic,16) -#endif - - for (int y = 0; y < H; y++) { - map.processVignetteLine(W, y, (*rawDataFrames[i])[y]); - } + map.processVignette(W, H, *rawDataFrames[i]); } } else { - -#ifdef _OPENMP - #pragma omp parallel for schedule(dynamic,16) -#endif - - for (int y = 0; y < H; y++) { - map.processVignetteLine(W, y, rawData[y]); - } + map.processVignette(W, H, rawData); } } else if(ri->get_colors() == 3) { -#ifdef _OPENMP - #pragma omp parallel for schedule(dynamic,16) -#endif - - for (int y = 0; y < H; y++) { - map.processVignetteLine3Channels(W, y, rawData[y]); - } + map.processVignette3Channels(W, H, rawData); } } } diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index 51b98080a..1596616dd 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -35,7 +35,6 @@ namespace rtengine LFModifier::~LFModifier() { if (data_) { - MyMutex::MyLock lock(lfModifierMutex); data_->Destroy(); } } @@ -78,11 +77,6 @@ bool LFModifier::isCACorrectionAvailable() const return (flags_ & LF_MODIFY_TCA); } -#ifdef __GNUC__ // silence warning, can be removed when function is implemented -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#endif - void LFModifier::correctCA(double &x, double &y, int cx, int cy, int channel) const { assert(channel >= 0 && channel <= 2); @@ -108,25 +102,39 @@ void LFModifier::correctCA(double &x, double &y, int cx, int cy, int channel) co y -= cy; } -#ifdef __GNUC__ -#pragma GCC diagnostic pop +#ifdef _OPENMP +void LFModifier::processVignette(int width, int height, float** rawData) const +{ + #pragma omp parallel for schedule(dynamic,16) + + for (int y = 0; y < height; ++y) { + data_->ApplyColorModification(rawData[y], 0, y, width, 1, LF_CR_1(INTENSITY), 0); + } +} +#else +void LFModifier::processVignette(int width, int height, float** rawData) const +{ + data_->ApplyColorModification(rawData[0], 0, 0, width, height, LF_CR_1(INTENSITY), width * sizeof(float)); +} + #endif - -void LFModifier::processVignetteLine(int width, int y, float *line) const +#ifdef _OPENMP +void LFModifier::processVignette3Channels(int width, int height, float** rawData) const { - MyMutex::MyLock lock(lfModifierMutex); - data_->ApplyColorModification(line, 0, y, width, 1, LF_CR_1(INTENSITY), 0); + #pragma omp parallel for schedule(dynamic,16) + + for (int y = 0; y < height; ++y) { + data_->ApplyColorModification(rawData[y], 0, y, width, 1, LF_CR_3(RED, GREEN, BLUE), 0); + } +} +#else +void LFModifier::processVignette3Channels(int width, int height, float** rawData) const +{ + data_->ApplyColorModification(rawData[y], 0, 0, width, height, LF_CR_3(RED, GREEN, BLUE), width * 3 * sizeof(float)); } - -void LFModifier::processVignetteLine3Channels(int width, int y, float *line) const -{ - MyMutex::MyLock lock(lfModifierMutex); - data_->ApplyColorModification(line, 0, y, width, 1, LF_CR_3(RED, GREEN, BLUE), 0); -} - - +#endif Glib::ustring LFModifier::getDisplayString() const { if (!data_) { diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h index 06434c358..2f3e4677d 100644 --- a/rtengine/rtlensfun.h +++ b/rtengine/rtlensfun.h @@ -56,8 +56,8 @@ public: void correctDistortion(double &x, double &y, int cx, int cy, double scale) const override; bool isCACorrectionAvailable() const override; void correctCA(double &x, double &y, int cx, int cy, int channel) const override; - void processVignetteLine(int width, int y, float *line) const override; - void processVignetteLine3Channels(int width, int y, float *line) const override; + void processVignette(int width, int height, float** rawData) const override; + void processVignette3Channels(int width, int height, float** rawData) const override; Glib::ustring getDisplayString() const; @@ -68,7 +68,6 @@ private: lfModifier *data_; bool swap_xy_; int flags_; - mutable MyMutex lfModifierMutex; }; class LFCamera final