merge with dev
This commit is contained in:
@@ -22,12 +22,39 @@
|
||||
#include "pixelsmap.h"
|
||||
#include "rawimage.h"
|
||||
#include "rawimagesource.h"
|
||||
//#define BENCHMARK
|
||||
#include "StopWatch.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
unsigned fc(const unsigned int cfa[2][2], int r, int c) {
|
||||
return cfa[r & 1][c & 1];
|
||||
}
|
||||
|
||||
inline void sum5x5(const array2D<float>& in, int col, float &sum) {
|
||||
#ifdef __SSE2__
|
||||
// sum up 5*4 = 20 values using SSE
|
||||
// 10 fabs function calls and 10 float additions with SSE
|
||||
const vfloat sumv = (vabsf(LVFU(in[0][col])) + vabsf(LVFU(in[1][col]))) +
|
||||
(vabsf(LVFU(in[2][col])) + vabsf(LVFU(in[3][col]))) +
|
||||
vabsf(LVFU(in[4][col]));
|
||||
// horizontally add the values and add the result to hfnbrave
|
||||
sum += vhadd(sumv);
|
||||
|
||||
// add remaining 5 values of last column
|
||||
sum += (fabsf(in[0][col + 4]) + fabsf(in[1][col + 4])) +
|
||||
(fabsf(in[2][col + 4]) + fabsf(in[3][col + 4])) +
|
||||
fabsf(in[4][col + 4]);
|
||||
#else
|
||||
// 25 fabs function calls and 25 float additions without SSE
|
||||
for (int nn = col; nn < col + 5; ++nn) {
|
||||
sum += (fabsf(in[0][nn]) + fabsf(in[1][nn])) +
|
||||
(fabsf(in[2][nn]) + fabsf(in[3][nn])) +
|
||||
fabsf(in[4][nn]);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace rtengine
|
||||
@@ -445,126 +472,124 @@ int RawImageSource::interpolateBadPixelsXtrans(const PixelsMap &bitmapBads)
|
||||
/* Search for hot or dead pixels in the image and update the map
|
||||
* For each pixel compare its value to the average of similar color surrounding
|
||||
* (Taken from Emil Martinec idea)
|
||||
* (Optimized by Ingo Weyrich 2013 and 2015)
|
||||
*/
|
||||
* (Optimized by Ingo Weyrich 2013, 2015, and 2019)
|
||||
*/
|
||||
int RawImageSource::findHotDeadPixels(PixelsMap &bpMap, const float thresh, const bool findHotPixels, const bool findDeadPixels) const
|
||||
{
|
||||
BENCHFUN
|
||||
const float varthresh = (20.0 * (thresh / 100.0) + 1.0) / 24.f;
|
||||
|
||||
// allocate temporary buffer
|
||||
float* cfablur = new float[H * W];
|
||||
|
||||
// counter for dead or hot pixels
|
||||
int counter = 0;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel
|
||||
#pragma omp parallel reduction(+:counter)
|
||||
#endif
|
||||
{
|
||||
array2D<float> cfablur(W, 5, ARRAY2D_CLEAR_DATA);
|
||||
int firstRow = -1;
|
||||
int lastRow = -1;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp for schedule(dynamic,16) nowait
|
||||
// note, static scheduling is important in this implementation
|
||||
#pragma omp for schedule(static) nowait
|
||||
#endif
|
||||
|
||||
for (int i = 2; i < H - 2; i++) {
|
||||
for (int j = 2; j < W - 2; j++) {
|
||||
for (int i = 2; i < H - 2; ++i) {
|
||||
if (firstRow == -1) {
|
||||
firstRow = i;
|
||||
if (firstRow > 2) {
|
||||
for (int row = firstRow - 2; row < firstRow; ++row) {
|
||||
const int destRow = row % 5;
|
||||
for (int j = 2; j < W - 2; ++j) {
|
||||
const float temp = median(rawData[row - 2][j - 2], rawData[row - 2][j], rawData[row - 2][j + 2],
|
||||
rawData[row][j - 2], rawData[row][j], rawData[row][j + 2],
|
||||
rawData[row + 2][j - 2], rawData[row + 2][j], rawData[row + 2][j + 2]);
|
||||
cfablur[destRow][j] = rawData[row][j] - temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastRow = i;
|
||||
const int destRow = i % 5;
|
||||
for (int j = 2; j < W - 2; ++j) {
|
||||
const float temp = median(rawData[i - 2][j - 2], rawData[i - 2][j], rawData[i - 2][j + 2],
|
||||
rawData[i][j - 2], rawData[i][j], rawData[i][j + 2],
|
||||
rawData[i + 2][j - 2], rawData[i + 2][j], rawData[i + 2][j + 2]);
|
||||
cfablur[i * W + j] = rawData[i][j] - temp;
|
||||
}
|
||||
cfablur[destRow][j] = rawData[i][j] - temp;
|
||||
}
|
||||
|
||||
// process borders. Former version calculated the median using mirrored border which does not make sense because the original pixel loses weight
|
||||
// Setting the difference between pixel and median for border pixels to zero should do the job not worse then former version
|
||||
#ifdef _OPENMP
|
||||
#pragma omp single
|
||||
#endif
|
||||
{
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < W; ++j) {
|
||||
cfablur[i * W + j] = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 2; i < H - 2; ++i) {
|
||||
for (int j = 0; j < 2; ++j) {
|
||||
cfablur[i * W + j] = 0.f;
|
||||
}
|
||||
|
||||
for (int j = W - 2; j < W; ++j) {
|
||||
cfablur[i * W + j] = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = H - 2; i < H; ++i) {
|
||||
for (int j = 0; j < W; ++j) {
|
||||
cfablur[i * W + j] = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp barrier // barrier because of nowait clause above
|
||||
|
||||
#pragma omp for reduction(+:counter) schedule(dynamic,16)
|
||||
#endif
|
||||
|
||||
//cfa pixel heat/death evaluation
|
||||
for (int rr = 2; rr < H - 2; ++rr) {
|
||||
for (int cc = 2, rrmWpcc = rr * W + 2; cc < W - 2; ++cc, ++rrmWpcc) {
|
||||
if (i - 1 > firstRow) {
|
||||
const int rr = i - 2;
|
||||
const int rr0 = rr % 5;
|
||||
for (int cc = 2; cc < W - 2; ++cc) {
|
||||
//evaluate pixel for heat/death
|
||||
float pixdev = cfablur[rrmWpcc];
|
||||
float pixdev = cfablur[rr0][cc];
|
||||
|
||||
if (pixdev == 0.f) {
|
||||
if (!findDeadPixels && pixdev <= 0.f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((!findDeadPixels) && pixdev < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((!findHotPixels) && pixdev > 0) {
|
||||
if (!findHotPixels && pixdev >= 0.f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pixdev = fabsf(pixdev);
|
||||
float hfnbrave = -pixdev;
|
||||
|
||||
#ifdef __SSE2__
|
||||
// sum up 5*4 = 20 values using SSE
|
||||
// 10 fabs function calls and 10 float additions with SSE
|
||||
vfloat sum = vabsf(LVFU(cfablur[(rr - 2) * W + cc - 2])) + vabsf(LVFU(cfablur[(rr - 1) * W + cc - 2]));
|
||||
sum += vabsf(LVFU(cfablur[(rr) * W + cc - 2]));
|
||||
sum += vabsf(LVFU(cfablur[(rr + 1) * W + cc - 2]));
|
||||
sum += vabsf(LVFU(cfablur[(rr + 2) * W + cc - 2]));
|
||||
// horizontally add the values and add the result to hfnbrave
|
||||
hfnbrave += vhadd(sum);
|
||||
|
||||
// add remaining 5 values of last column
|
||||
for (int mm = rr - 2; mm <= rr + 2; ++mm) {
|
||||
hfnbrave += fabsf(cfablur[mm * W + cc + 2]);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// 25 fabs function calls and 25 float additions without SSE
|
||||
for (int mm = rr - 2; mm <= rr + 2; ++mm) {
|
||||
for (int nn = cc - 2; nn <= cc + 2; ++nn) {
|
||||
hfnbrave += fabsf(cfablur[mm * W + nn]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
sum5x5(cfablur, cc - 2, hfnbrave);
|
||||
if (pixdev > varthresh * hfnbrave) {
|
||||
// mark the pixel as "bad"
|
||||
bpMap.set(cc, rr);
|
||||
counter++;
|
||||
++counter;
|
||||
}
|
||||
} //end of pixel evaluation
|
||||
}
|
||||
}
|
||||
|
||||
if (lastRow > 0 && lastRow < H - 2) {
|
||||
//cfa pixel heat/death evaluation
|
||||
for (int rr = lastRow - 1; rr < lastRow + 1; ++rr) {
|
||||
const int i = rr + 2;
|
||||
const int destRow = i % 5;
|
||||
if (i >= H - 2) {
|
||||
for (int j = 2; j < W - 2; j++) {
|
||||
cfablur[destRow][j] = 0.f;
|
||||
}
|
||||
} else {
|
||||
for (int j = 2; j < W - 2; ++j) {
|
||||
const float temp = median(rawData[i - 2][j - 2], rawData[i - 2][j], rawData[i - 2][j + 2],
|
||||
rawData[i][j - 2], rawData[i][j], rawData[i][j + 2],
|
||||
rawData[i + 2][j - 2], rawData[i + 2][j], rawData[i + 2][j + 2]);
|
||||
cfablur[destRow][j] = rawData[i][j] - temp;
|
||||
}
|
||||
}
|
||||
|
||||
const int rr0 = rr % 5;
|
||||
for (int cc = 2; cc < W - 2; ++cc) {
|
||||
//evaluate pixel for heat/death
|
||||
float pixdev = cfablur[rr0][cc];
|
||||
|
||||
if (!findDeadPixels && pixdev <= 0.f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!findHotPixels && pixdev >= 0.f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pixdev = fabsf(pixdev);
|
||||
float hfnbrave = -pixdev;
|
||||
sum5x5(cfablur, cc - 2, hfnbrave);
|
||||
if (pixdev > varthresh * hfnbrave) {
|
||||
// mark the pixel as "bad"
|
||||
bpMap.set(cc, rr);
|
||||
++counter;
|
||||
}
|
||||
}//end of pixel evaluation
|
||||
}
|
||||
}
|
||||
}//end of parallel processing
|
||||
delete [] cfablur;
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
@@ -66,14 +66,9 @@ void RawImageSource::dual_demosaic_RT(bool isBayer, const procparams::RAWParams
|
||||
return;
|
||||
}
|
||||
|
||||
array2D<float> redTmp(winw, winh);
|
||||
array2D<float> greenTmp(winw, winh);
|
||||
array2D<float> blueTmp(winw, winh);
|
||||
array2D<float> L(winw, winh);
|
||||
|
||||
if (isBayer) {
|
||||
vng4_demosaic(rawData, redTmp, greenTmp, blueTmp);
|
||||
|
||||
if (raw.bayersensor.method == procparams::RAWParams::BayerSensor::getMethodString(procparams::RAWParams::BayerSensor::Method::AMAZEVNG4) || raw.bayersensor.method == procparams::RAWParams::BayerSensor::getMethodString(procparams::RAWParams::BayerSensor::Method::PIXELSHIFT)) {
|
||||
amaze_demosaic_RT(0, 0, winw, winh, rawData, red, green, blue, options.chunkSizeAMAZE, options.measure);
|
||||
} else if (raw.bayersensor.method == procparams::RAWParams::BayerSensor::getMethodString(procparams::RAWParams::BayerSensor::Method::DCBVNG4) ) {
|
||||
@@ -87,7 +82,6 @@ void RawImageSource::dual_demosaic_RT(bool isBayer, const procparams::RAWParams
|
||||
} else {
|
||||
xtrans_interpolate (1, false, options.chunkSizeXT, options.measure);
|
||||
}
|
||||
fast_xtrans_interpolate(rawData, redTmp, greenTmp, blueTmp);
|
||||
}
|
||||
|
||||
const float xyz_rgb[3][3] = { // XYZ from RGB
|
||||
@@ -114,6 +108,17 @@ void RawImageSource::dual_demosaic_RT(bool isBayer, const procparams::RAWParams
|
||||
buildBlendMask(L, blend, winw, winh, contrastf, 1.f, autoContrast);
|
||||
contrast = contrastf * 100.f;
|
||||
|
||||
array2D<float>& redTmp = L; // L is not needed anymore => reuse it
|
||||
array2D<float> greenTmp(winw, winh);
|
||||
array2D<float> blueTmp(winw, winh);
|
||||
|
||||
if (isBayer) {
|
||||
vng4_demosaic(rawData, redTmp, greenTmp, blueTmp);
|
||||
} else {
|
||||
fast_xtrans_interpolate(rawData, redTmp, greenTmp, blueTmp);
|
||||
}
|
||||
|
||||
|
||||
// the following is split into 3 loops intentionally to avoid cache conflicts on CPUs with only 4-way cache
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
|
@@ -141,6 +141,8 @@ PartialPasteDlg::PartialPasteDlg (const Glib::ustring &title, Gtk::Window* paren
|
||||
raw_ca_avoid_colourshift = Gtk::manage (new Gtk::CheckButton (M("PARTIALPASTE_RAWCACORR_AVOIDCOLORSHIFT")));
|
||||
//...
|
||||
filmNegative = Gtk::manage (new Gtk::CheckButton (M("PARTIALPASTE_FILMNEGATIVE")) );
|
||||
//---
|
||||
captureSharpening = Gtk::manage (new Gtk::CheckButton (M("TP_PDSHARPENING_LABEL")) );
|
||||
Gtk::VBox* vboxes[9];
|
||||
Gtk::HSeparator* hseps[9];
|
||||
|
||||
@@ -254,7 +256,7 @@ PartialPasteDlg::PartialPasteDlg (const Glib::ustring &title, Gtk::Window* paren
|
||||
vboxes[8]->pack_start (*ff_AutoSelect, Gtk::PACK_SHRINK, 2);
|
||||
vboxes[8]->pack_start (*ff_BlurType, Gtk::PACK_SHRINK, 2);
|
||||
vboxes[8]->pack_start (*ff_BlurRadius, Gtk::PACK_SHRINK, 2);
|
||||
vboxes[8]->pack_start (*ff_ClipControl, Gtk::PACK_SHRINK, 2);
|
||||
vboxes[8]->pack_start (*captureSharpening, Gtk::PACK_SHRINK, 2);
|
||||
vboxes[8]->pack_start (*Gtk::manage (new Gtk::HSeparator ()), Gtk::PACK_SHRINK, 0);
|
||||
vboxes[8]->pack_start (*raw_ca_autocorrect, Gtk::PACK_SHRINK, 2);
|
||||
vboxes[8]->pack_start (*raw_caredblue, Gtk::PACK_SHRINK, 2);
|
||||
@@ -411,6 +413,8 @@ PartialPasteDlg::PartialPasteDlg (const Glib::ustring &title, Gtk::Window* paren
|
||||
raw_ca_avoid_colourshiftconn = raw_ca_avoid_colourshift->signal_toggled().connect (sigc::bind (sigc::mem_fun(*raw, &Gtk::CheckButton::set_inconsistent), true));
|
||||
//---
|
||||
filmNegativeConn = filmNegative->signal_toggled().connect (sigc::bind (sigc::mem_fun(*raw, &Gtk::CheckButton::set_inconsistent), true));
|
||||
//---
|
||||
captureSharpeningConn = captureSharpening->signal_toggled().connect (sigc::bind (sigc::mem_fun(*raw, &Gtk::CheckButton::set_inconsistent), true));
|
||||
|
||||
add_button (M("GENERAL_OK"), Gtk::RESPONSE_OK);
|
||||
add_button (M("GENERAL_CANCEL"), Gtk::RESPONSE_CANCEL);
|
||||
@@ -486,6 +490,7 @@ void PartialPasteDlg::rawToggled ()
|
||||
ConnectionBlocker raw_caredblueBlocker(raw_caredblueConn);
|
||||
ConnectionBlocker raw_ca_avoid_colourshiftBlocker(raw_ca_avoid_colourshiftconn);
|
||||
ConnectionBlocker filmNegativeBlocker(filmNegativeConn);
|
||||
ConnectionBlocker captureSharpeningBlocker(captureSharpeningConn);
|
||||
|
||||
raw->set_inconsistent (false);
|
||||
|
||||
@@ -515,6 +520,7 @@ void PartialPasteDlg::rawToggled ()
|
||||
raw_caredblue->set_active (raw->get_active ());
|
||||
raw_ca_avoid_colourshift->set_active (raw->get_active ());
|
||||
filmNegative->set_active (raw->get_active());
|
||||
captureSharpening->set_active (raw->get_active());
|
||||
}
|
||||
|
||||
void PartialPasteDlg::basicToggled ()
|
||||
@@ -1004,6 +1010,17 @@ void PartialPasteDlg::applyPaste (rtengine::procparams::ProcParams* dstPP, Param
|
||||
filterPE.filmNegative.blueRatio = falsePE.filmNegative.blueRatio;
|
||||
}
|
||||
|
||||
if (!captureSharpening->get_active ()) {
|
||||
filterPE.pdsharpening.enabled = falsePE.pdsharpening.enabled;
|
||||
filterPE.pdsharpening.contrast = falsePE.pdsharpening.contrast;
|
||||
filterPE.pdsharpening.autoContrast = falsePE.pdsharpening.autoContrast;
|
||||
filterPE.pdsharpening.autoRadius = falsePE.pdsharpening.autoRadius;
|
||||
filterPE.pdsharpening.deconvradius = falsePE.pdsharpening.deconvradius;
|
||||
filterPE.pdsharpening.deconvradiusOffset = falsePE.pdsharpening.deconvradiusOffset;
|
||||
filterPE.pdsharpening.deconviter = falsePE.pdsharpening.deconviter;
|
||||
filterPE.pdsharpening.deconvitercheck = falsePE.pdsharpening.deconvitercheck;
|
||||
}
|
||||
|
||||
if (dstPE) {
|
||||
*dstPE = filterPE;
|
||||
}
|
||||
|
@@ -142,6 +142,7 @@ public:
|
||||
Gtk::CheckButton* ff_ClipControl;
|
||||
|
||||
Gtk::CheckButton* filmNegative;
|
||||
Gtk::CheckButton* captureSharpening;
|
||||
|
||||
sigc::connection everythingConn, basicConn, detailConn, colorConn, lensConn, compositionConn, metaConn, rawConn, advancedConn;
|
||||
sigc::connection locallabConn;
|
||||
@@ -154,6 +155,7 @@ public:
|
||||
sigc::connection df_fileConn, df_AutoSelectConn, ff_fileConn, ff_AutoSelectConn, ff_BlurRadiusConn, ff_BlurTypeConn, ff_ClipControlConn;
|
||||
sigc::connection raw_caredblueConn, raw_ca_autocorrectConn, raw_ca_avoid_colourshiftconn, raw_hotpix_filtConn, raw_deadpix_filtConn, raw_pdaf_lines_filterConn, raw_linenoiseConn, raw_greenthreshConn, raw_ccStepsConn, raw_methodConn, raw_borderConn, raw_imagenumConn, raw_dcb_iterationsConn, raw_lmmse_iterationsConn, raw_pixelshiftConn, raw_dcb_enhanceConn, raw_exposConn, raw_blackConn;
|
||||
sigc::connection filmNegativeConn;
|
||||
sigc::connection captureSharpeningConn;
|
||||
|
||||
public:
|
||||
PartialPasteDlg (const Glib::ustring &title, Gtk::Window* parent);
|
||||
|
Reference in New Issue
Block a user