Merge pull request #4797 from Beep6581/rawcacorrection_iterate
Raw ca correction. Iterative processing and Avoid color shift.
This commit is contained in:
commit
f9404901ff
@ -748,6 +748,8 @@ HISTORY_MSG_PREPROCESS_LINEDENOISE_DIRECTION;Line noise filter direction
|
||||
HISTORY_MSG_PREPROCESS_PDAFLINESFILTER;PDAF lines filter
|
||||
HISTORY_MSG_PRSHARPEN_CONTRAST;PRS - Contrast threshold
|
||||
HISTORY_MSG_RAW_BORDER;Raw border
|
||||
HISTORY_MSG_RAWCACORR_AUTOIT;Raw CA Correction - Iterations
|
||||
HISTORY_MSG_RAWCACORR_COLOURSHIFT;Raw CA Correction - Avoid color shift
|
||||
HISTORY_MSG_RESIZE_ALLOWUPSCALING;Resize - Allow upscaling
|
||||
HISTORY_MSG_SHARPENING_CONTRAST;Sharpening - Contrast threshold
|
||||
HISTORY_MSG_SOFTLIGHT_ENABLED;Soft light
|
||||
@ -1780,6 +1782,8 @@ TP_PREPROCESS_PDAFLINESFILTER_TOOLTIP;Tries to suppress stripe noise caused by o
|
||||
TP_PRSHARPENING_LABEL;Post-Resize Sharpening
|
||||
TP_PRSHARPENING_TOOLTIP;Sharpens the image after resizing. Only works when the "Lanczos" resizing method is used. It is impossible to preview the effects of this tool. See RawPedia for usage instructions.
|
||||
TP_RAWCACORR_AUTO;Auto-correction
|
||||
TP_RAWCACORR_AUTOIT;Iterations
|
||||
TP_RAWCACORR_AVOIDCOLORSHIFT;Avoid color shift
|
||||
TP_RAWCACORR_CABLUE;Blue
|
||||
TP_RAWCACORR_CARED;Red
|
||||
TP_RAWCACORR_CASTR;Strength
|
||||
|
@ -1,11 +1,11 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Chromatic Aberration Auto-correction
|
||||
// Chromatic Aberration correction on raw bayer cfa data
|
||||
//
|
||||
// copyright (c) 2008-2010 Emil Martinec <ejmartin@uchicago.edu>
|
||||
// copyright (c) for improvements (speedups, iterated correction and avoid colour shift) 2018 Ingo Weyrich <heckflosse67@gmx.de>
|
||||
//
|
||||
//
|
||||
// code dated: November 26, 2010
|
||||
// code dated: September 8, 2018
|
||||
//
|
||||
// CA_correct_RT.cc is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -21,12 +21,13 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
#include "rtengine.h"
|
||||
#include "rawimagesource.h"
|
||||
#include "rt_math.h"
|
||||
#include "gauss.h"
|
||||
#include "median.h"
|
||||
//#define BENCHMARK
|
||||
#include "StopWatch.h"
|
||||
namespace {
|
||||
|
||||
@ -104,30 +105,59 @@ bool LinEqSolve(int nDim, double* pfMatr, double* pfVect, double* pfSolution)
|
||||
return true;
|
||||
}
|
||||
//end of linear equation solver
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
using namespace rtengine;
|
||||
|
||||
float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, const double cablue, const double caautostrength, array2D<float> &rawData, double *fitParamsTransfer, bool fitParamsIn, bool fitParamsOut, float *buffer, bool freeBuffer)
|
||||
float* RawImageSource::CA_correct_RT(
|
||||
bool autoCA,
|
||||
size_t autoIterations,
|
||||
double cared,
|
||||
double cablue,
|
||||
bool avoidColourshift,
|
||||
const array2D<float> &rawData,
|
||||
double* fitParamsTransfer,
|
||||
bool fitParamsIn,
|
||||
bool fitParamsOut,
|
||||
float* buffer,
|
||||
bool freeBuffer
|
||||
)
|
||||
{
|
||||
BENCHFUN
|
||||
// multithreaded and vectorized by Ingo Weyrich
|
||||
constexpr int ts = 128;
|
||||
constexpr int tsh = ts / 2;
|
||||
//shifts to location of vertical and diagonal neighbors
|
||||
//shifts to location of vertical and diagonal neighbours
|
||||
constexpr int v1 = ts, v2 = 2 * ts, v3 = 3 * ts, v4 = 4 * ts; //, p1=-ts+1, p2=-2*ts+2, p3=-3*ts+3, m1=ts+1, m2=2*ts+2, m3=3*ts+3;
|
||||
|
||||
// Test for RGB cfa
|
||||
for(int i = 0; i < 2; i++)
|
||||
for(int j = 0; j < 2; j++)
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
if (FC(i, j) == 3) {
|
||||
printf("CA correction supports only RGB Colour filter arrays\n");
|
||||
std::cout << "CA correction supports only RGB Colour filter arrays" << std::endl;
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
volatile double progress = 0.0;
|
||||
array2D<float>* redFactor = nullptr;
|
||||
array2D<float>* blueFactor = nullptr;
|
||||
array2D<float>* oldraw = nullptr;
|
||||
if (avoidColourshift) {
|
||||
redFactor = new array2D<float>((W+1)/2, (H+1)/2);
|
||||
blueFactor = new array2D<float>((W+1)/2, (H+1)/2);
|
||||
oldraw = new array2D<float>((W + 1) / 2, H);
|
||||
// copy raw values before ca correction
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < H; ++i) {
|
||||
for (int j = FC(i, 0) & 1; j < W; j += 2) {
|
||||
(*oldraw)[i][j / 2] = rawData[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double progress = 0.0;
|
||||
|
||||
if (plistener) {
|
||||
plistener->setProgress (progress);
|
||||
@ -155,13 +185,16 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
memset(blockwt, 0, vblsz * hblsz * (2 * 2 + 1) * sizeof(float));
|
||||
float (*blockshifts)[2][2] = (float (*)[2][2])(blockwt + vblsz * hblsz);
|
||||
|
||||
float blockave[2][2] = {{0, 0}, {0, 0}}, blocksqave[2][2] = {{0, 0}, {0, 0}}, blockdenom[2][2] = {{0, 0}, {0, 0}}, blockvar[2][2];
|
||||
|
||||
// Because we can't break parallel processing, we need a switch do handle the errors
|
||||
bool processpasstwo = true;
|
||||
|
||||
double fitparams[2][2][16];
|
||||
const bool fitParamsSet = fitParamsTransfer && fitParamsIn;
|
||||
|
||||
const size_t iterations =
|
||||
autoCA
|
||||
? std::max<size_t>(autoIterations, 1)
|
||||
: 1;
|
||||
|
||||
const bool fitParamsSet = fitParamsTransfer && fitParamsIn && iterations < 2;
|
||||
if (autoCA && fitParamsSet) {
|
||||
// use stored parameters
|
||||
int index = 0;
|
||||
@ -173,6 +206,13 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t it = 0; it < iterations && processpasstwo; ++it) {
|
||||
float blockave[2][2] = {};
|
||||
float blocksqave[2][2] = {};
|
||||
float blockdenom[2][2] = {};
|
||||
float blockvar[2][2];
|
||||
|
||||
//order of 2d polynomial fit (polyord), and numpar=polyord^2
|
||||
int polyord = 4, numpar = 16;
|
||||
|
||||
@ -202,23 +242,24 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
|
||||
//rgb data in a tile
|
||||
float* rgb[3];
|
||||
rgb[0] = (float (*)) data;
|
||||
rgb[1] = (float (*)) (data + sizeof(float) * ts * tsh + 1 * 64);
|
||||
rgb[2] = (float (*)) (data + sizeof(float) * (ts * ts + ts * tsh) + 2 * 64);
|
||||
rgb[0] = (float*) data;
|
||||
rgb[1] = (float*) (data + sizeof(float) * ts * tsh + 1 * 64);
|
||||
rgb[2] = (float*) (data + sizeof(float) * (ts * ts + ts * tsh) + 2 * 64);
|
||||
|
||||
if (autoCA && !fitParamsSet) {
|
||||
constexpr float caAutostrength = 8.f;
|
||||
//high pass filter for R/B in vertical direction
|
||||
float *rbhpfh = (float (*)) (data + 2 * sizeof(float) * ts * ts + 3 * 64);
|
||||
float* rbhpfh = (float*) (data + 2 * sizeof(float) * ts * ts + 3 * 64);
|
||||
//high pass filter for R/B in horizontal direction
|
||||
float *rbhpfv = (float (*)) (data + 2 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 4 * 64);
|
||||
float* rbhpfv = (float*) (data + 2 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 4 * 64);
|
||||
//low pass filter for R/B in horizontal direction
|
||||
float *rblpfh = (float (*)) (data + 3 * sizeof(float) * ts * ts + 5 * 64);
|
||||
float* rblpfh = (float*) (data + 3 * sizeof(float) * ts * ts + 5 * 64);
|
||||
//low pass filter for R/B in vertical direction
|
||||
float *rblpfv = (float (*)) (data + 3 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 6 * 64);
|
||||
float* rblpfv = (float*) (data + 3 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 6 * 64);
|
||||
//low pass filter for colour differences in horizontal direction
|
||||
float *grblpfh = (float (*)) (data + 4 * sizeof(float) * ts * ts + 7 * 64);
|
||||
float* grblpfh = (float*) (data + 4 * sizeof(float) * ts * ts + 7 * 64);
|
||||
//low pass filter for colour differences in vertical direction
|
||||
float *grblpfv = (float (*)) (data + 4 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 8 * 64);
|
||||
float* grblpfv = (float*) (data + 4 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 8 * 64);
|
||||
// Main algorithm: Tile loop calculating correction parameters per tile
|
||||
|
||||
//local quadratic fit to shift data within a tile
|
||||
@ -227,14 +268,16 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
float CAshift[2][2];
|
||||
|
||||
//per thread data for evaluation of block CA shift variance
|
||||
float blockavethr[2][2] = {{0, 0}, {0, 0}}, blocksqavethr[2][2] = {{0, 0}, {0, 0}}, blockdenomthr[2][2] = {{0, 0}, {0, 0}};
|
||||
float blockavethr[2][2] = {};
|
||||
float blocksqavethr[2][2] = {};
|
||||
float blockdenomthr[2][2] = {};
|
||||
|
||||
#pragma omp for collapse(2) schedule(dynamic) nowait
|
||||
for (int top = -border ; top < height; top += ts - border2)
|
||||
for (int top = -border ; top < height; top += ts - border2) {
|
||||
for (int left = -border; left < width - (W & 1); left += ts - border2) {
|
||||
memset(bufferThr, 0, buffersize);
|
||||
const int vblock = ((top + border) / (ts - border2)) + 1;
|
||||
const int hblock = ((left + border) / (ts - border2)) + 1;
|
||||
const int vblock = (top + border) / (ts - border2) + 1;
|
||||
const int hblock = (left + border) / (ts - border2) + 1;
|
||||
const int bottom = min(top + ts, height + border);
|
||||
const int right = min(left + ts, width - (W & 1) + border);
|
||||
const int rr1 = bottom - top;
|
||||
@ -281,78 +324,83 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//fill borders
|
||||
if (rrmin > 0) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = ccmin; cc < ccmax; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][((border2 - rr) * ts + cc) >> ((c & 1) ^ 1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmax < rr1) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = ccmin; cc < ccmax; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][left + cc] / 65535.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ccmin > 0) {
|
||||
for (int rr = rrmin; rr < rrmax; rr++)
|
||||
for (int rr = rrmin; rr < rrmax; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][(rr * ts + border2 - cc) >> ((c & 1) ^ 1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ccmax < cc1) {
|
||||
for (int rr = rrmin; rr < rrmax; rr++)
|
||||
for (int rr = rrmin; rr < rrmax; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(top + rr)][(width - cc - 2)] / 65535.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//also, fill the image corners
|
||||
if (rrmin > 0 && ccmin > 0) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rawData[border2 - rr][border2 - cc] / 65535.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmax < rr1 && ccmax < cc1) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][((rrmax + rr)*ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][(width - cc - 2)] / 65535.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmin > 0 && ccmax < cc1) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(border2 - rr)][(width - cc - 2)] / 65535.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmax < rr1 && ccmin > 0) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][(border2 - cc)] / 65535.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//end of border fill
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//end of initialization
|
||||
|
||||
|
||||
#ifdef __SSE2__
|
||||
vfloat onev = F2V(1.f);
|
||||
vfloat epsv = F2V(eps);
|
||||
@ -406,9 +454,8 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
Gtmp[(row * width + col) >> 1] = rgb[1][indx];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
#ifdef __SSE2__
|
||||
vfloat zd25v = F2V(0.25f);
|
||||
#endif
|
||||
@ -443,7 +490,6 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
STVFU(grblpfv[indx >> 1], zd25v * (glpfvv + (rgbcv + LVFU(rgb[c][(indx + v2) >> 1]) + LVFU(rgb[c][(indx - v2) >> 1]))));
|
||||
STVFU(grblpfh[indx >> 1], zd25v * (glpfhv + (rgbcv + LVFU(rgb[c][(indx + 2) >> 1]) + LVFU(rgb[c][(indx - 2) >> 1]))));
|
||||
}
|
||||
|
||||
#endif
|
||||
for (; cc < cc1 - 4; cc += 2, indx += 2) {
|
||||
rbhpfv[indx >> 1] = fabsf(fabsf((rgb[1][indx] - rgb[c][indx >> 1]) - (rgb[1][indx + v4] - rgb[c][(indx + v4) >> 1])) +
|
||||
@ -491,7 +537,6 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
vfloat coeff11v = ZEROV;
|
||||
vfloat coeff12v = ZEROV;
|
||||
for (; cc < cc1 - 14; cc += 8, indx += 8) {
|
||||
|
||||
//in linear interpolation, colour differences are a quadratic function of interpolation position;
|
||||
//solve for the interpolation position that minimizes colour difference variance over the tile
|
||||
|
||||
@ -526,7 +571,6 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
|
||||
#endif
|
||||
for (; cc < cc1 - 8; cc += 2, indx += 2) {
|
||||
|
||||
//in linear interpolation, colour differences are a quadratic function of interpolation position;
|
||||
//solve for the interpolation position that minimizes colour difference variance over the tile
|
||||
|
||||
@ -594,38 +638,34 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
//evaluate the shifts to the location that minimizes CA within the tile
|
||||
blockshifts[vblock * hblsz + hblock][c][dir] = CAshift[dir][c]; //vert/hor CA shift for R/B
|
||||
|
||||
}//vert/hor
|
||||
}//colour
|
||||
|
||||
if (plistener) {
|
||||
progresscounter++;
|
||||
|
||||
if(progresscounter % 8 == 0)
|
||||
if (progresscounter % 8 == 0) {
|
||||
#pragma omp critical (cadetectpass1)
|
||||
{
|
||||
progress += (double)(8.0 * (ts - border2) * (ts - border2)) / (2 * height * width);
|
||||
|
||||
if (progress > 1.0) {
|
||||
progress = 1.0;
|
||||
}
|
||||
|
||||
progress += 4.0 * SQR(ts - border2) / (iterations * height * width);
|
||||
progress = std::min(progress, 1.0);
|
||||
plistener->setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//end of diagnostic pass
|
||||
#pragma omp critical (cadetectpass2)
|
||||
{
|
||||
for (int dir = 0; dir < 2; dir++)
|
||||
for (int dir = 0; dir < 2; dir++) {
|
||||
for (int c = 0; c < 2; c++) {
|
||||
blockdenom[dir][c] += blockdenomthr[dir][c];
|
||||
blocksqave[dir][c] += blocksqavethr[dir][c];
|
||||
blockave[dir][c] += blockavethr[dir][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma omp barrier
|
||||
|
||||
#pragma omp single
|
||||
@ -636,13 +676,11 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
blockvar[dir][c] = blocksqave[dir][c] / blockdenom[dir][c] - SQR(blockave[dir][c] / blockdenom[dir][c]);
|
||||
} else {
|
||||
processpasstwo = false;
|
||||
printf ("blockdenom vanishes \n");
|
||||
std::cout << "blockdenom vanishes" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
//now prepare for CA correction pass
|
||||
//first, fill border blocks of blockshift array
|
||||
if (processpasstwo) {
|
||||
@ -679,7 +717,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
|
||||
int numblox[2] = {0, 0};
|
||||
|
||||
for (int vblock = 1; vblock < vblsz - 1; vblock++)
|
||||
for (int vblock = 1; vblock < vblsz - 1; vblock++) {
|
||||
for (int hblock = 1; hblock < hblsz - 1; hblock++) {
|
||||
// block 3x3 median of blockshifts for robustness
|
||||
for (int c = 0; c < 2; c ++) {
|
||||
@ -700,8 +738,8 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
bstemp[dir] = median(p);
|
||||
}
|
||||
|
||||
//now prepare coefficient matrix; use only data points within caautostrength/2 std devs of zero
|
||||
if (SQR(bstemp[0]) > caautostrength * blockvar[0][c] || SQR(bstemp[1]) > caautostrength * blockvar[1][c]) {
|
||||
//now prepare coefficient matrix; use only data points within caAutostrength/2 std devs of zero
|
||||
if (SQR(bstemp[0]) > caAutostrength * blockvar[0][c] || SQR(bstemp[1]) > caAutostrength * blockvar[1][c]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -729,7 +767,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}//dir
|
||||
}//c
|
||||
}//blocks
|
||||
|
||||
}
|
||||
numblox[1] = min(numblox[0], numblox[1]);
|
||||
|
||||
//if too few data points, restrict the order of the fit to linear
|
||||
@ -738,24 +776,23 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
numpar = 4;
|
||||
|
||||
if (numblox[1] < 10) {
|
||||
|
||||
printf ("numblox = %d \n", numblox[1]);
|
||||
std::cout << "numblox = " << numblox[1] << std::endl;
|
||||
processpasstwo = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(processpasstwo)
|
||||
|
||||
if (processpasstwo) {
|
||||
//fit parameters to blockshifts
|
||||
for (int c = 0; c < 2; c++)
|
||||
for (int c = 0; c < 2; c++) {
|
||||
for (int dir = 0; dir < 2; dir++) {
|
||||
if (!LinEqSolve(numpar, polymat[c][dir], shiftmat[c][dir], fitparams[c][dir])) {
|
||||
printf("CA correction pass failed -- can't solve linear equations for colour %d direction %d...\n", c, dir);
|
||||
std::cout << "CA correction pass failed -- can't solve linear equations for colour %d direction " << c << std::endl;
|
||||
processpasstwo = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//fitparams[polyord*i+j] gives the coefficients of (vblock^i hblock^j) in a polynomial fit for i,j<=4
|
||||
}
|
||||
//end of initialization for CA correction pass
|
||||
@ -767,9 +804,8 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
float* grbdiff = (float (*)) (data + 2 * sizeof(float) * ts * ts + 3 * 64); // there is no overlap in buffer usage => share
|
||||
//green interpolated to optical sample points for R/B
|
||||
float* gshift = (float (*)) (data + 2 * sizeof(float) * ts * ts + sizeof(float) * ts * tsh + 4 * 64); // there is no overlap in buffer usage => share
|
||||
#pragma omp for schedule(dynamic) collapse(2) nowait
|
||||
|
||||
for (int top = -border; top < height; top += ts - border2)
|
||||
#pragma omp for schedule(dynamic) collapse(2)
|
||||
for (int top = -border; top < height; top += ts - border2) {
|
||||
for (int left = -border; left < width - (W & 1); left += ts - border2) {
|
||||
memset(bufferThr, 0, buffersizePassTwo);
|
||||
float lblockshifts[2][2];
|
||||
@ -827,19 +863,20 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
//fill borders
|
||||
if (rrmin > 0) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = ccmin; cc < ccmax; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][((border2 - rr) * ts + cc) >> ((c & 1) ^ 1)];
|
||||
rgb[1][rr * ts + cc] = rgb[1][(border2 - rr) * ts + cc];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmax < rr1) {
|
||||
for (int rr = 0; rr < std::min(border, rr1 - rrmax); rr++)
|
||||
for (int rr = 0; rr < std::min(border, rr1 - rrmax); rr++) {
|
||||
for (int cc = ccmin; cc < ccmax; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = (rawData[(height - rr - 2)][left + cc]) / 65535.f;
|
||||
@ -848,18 +885,20 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ccmin > 0) {
|
||||
for (int rr = rrmin; rr < rrmax; rr++)
|
||||
for (int rr = rrmin; rr < rrmax; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][(rr * ts + border2 - cc) >> ((c & 1) ^ 1)];
|
||||
rgb[1][rr * ts + cc] = rgb[1][rr * ts + border2 - cc];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ccmax < cc1) {
|
||||
for (int rr = rrmin; rr < rrmax; rr++)
|
||||
for (int rr = rrmin; rr < rrmax; rr++) {
|
||||
for (int cc = 0; cc < std::min(border, cc1 - ccmax); cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = (rawData[(top + rr)][(width - cc - 2)]) / 65535.f;
|
||||
@ -868,10 +907,11 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//also, fill the image corners
|
||||
if (rrmin > 0 && ccmin > 0) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = (rawData[border2 - rr][border2 - cc]) / 65535.f;
|
||||
@ -880,9 +920,10 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmax < rr1 && ccmax < cc1) {
|
||||
for (int rr = 0; rr < std::min(border, rr1 - rrmax); rr++)
|
||||
for (int rr = 0; rr < std::min(border, rr1 - rrmax); rr++) {
|
||||
for (int cc = 0; cc < std::min(border, cc1 - ccmax); cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][((rrmax + rr)*ts + ccmax + cc) >> ((c & 1) ^ 1)] = (rawData[(height - rr - 2)][(width - cc - 2)]) / 65535.f;
|
||||
@ -891,9 +932,10 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmin > 0 && ccmax < cc1) {
|
||||
for (int rr = 0; rr < border; rr++)
|
||||
for (int rr = 0; rr < border; rr++) {
|
||||
for (int cc = 0; cc < std::min(border, cc1 - ccmax); cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = (rawData[(border2 - rr)][(width - cc - 2)]) / 65535.f;
|
||||
@ -902,9 +944,10 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rrmax < rr1 && ccmin > 0) {
|
||||
for (int rr = 0; rr < std::min(border, rr1 - rrmax); rr++)
|
||||
for (int rr = 0; rr < std::min(border, rr1 - rrmax); rr++) {
|
||||
for (int cc = 0; cc < border; cc++) {
|
||||
int c = FC(rr, cc);
|
||||
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = (rawData[(height - rr - 2)][(border2 - cc)]) / 65535.f;
|
||||
@ -913,16 +956,14 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//end of border fill
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if (!autoCA || fitParamsIn) {
|
||||
#ifdef __SSE2__
|
||||
const vfloat onev = F2V(1.f);
|
||||
const vfloat epsv = F2V(eps);
|
||||
#endif
|
||||
|
||||
//manual CA correction; use red/blue slider values to set CA shift parameters
|
||||
for (int rr = 3; rr < rr1 - 3; rr++) {
|
||||
int cc = 3 + FC(rr, 1), c = FC(rr,cc), indx = rr * ts + cc;
|
||||
@ -952,6 +993,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!autoCA) {
|
||||
float hfrac = -((float)(hblock - 0.5) / (hblsz - 2) - 0.5);
|
||||
float vfrac = -((float)(vblock - 0.5) / (vblsz - 2) - 0.5) * height / width;
|
||||
@ -982,24 +1024,27 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
lblockshifts[1][1] = LIM(lblockshifts[1][1], -bslim, bslim);
|
||||
}//end of setting CA shift parameters
|
||||
|
||||
|
||||
for (int c = 0; c < 3; c += 2) {
|
||||
|
||||
//some parameters for the bilinear interpolation
|
||||
shiftvfloor[c] = floor((float)lblockshifts[c>>1][0]);
|
||||
shiftvceil[c] = ceil((float)lblockshifts[c>>1][0]);
|
||||
shiftvfrac[c] = lblockshifts[c>>1][0] - shiftvfloor[c];
|
||||
if (lblockshifts[c>>1][0] < 0.f) {
|
||||
std::swap(shiftvfloor[c], shiftvceil[c]);
|
||||
}
|
||||
shiftvfrac[c] = fabs(lblockshifts[c>>1][0] - shiftvfloor[c]);
|
||||
|
||||
shifthfloor[c] = floor((float)lblockshifts[c>>1][1]);
|
||||
shifthceil[c] = ceil((float)lblockshifts[c>>1][1]);
|
||||
shifthfrac[c] = lblockshifts[c>>1][1] - shifthfloor[c];
|
||||
if (lblockshifts[c>>1][1] < 0.f) {
|
||||
std::swap(shifthfloor[c], shifthceil[c]);
|
||||
}
|
||||
shifthfrac[c] = fabs(lblockshifts[c>>1][1] - shifthfloor[c]);
|
||||
|
||||
GRBdir[0][c] = lblockshifts[c>>1][0] > 0 ? 2 : -2;
|
||||
GRBdir[1][c] = lblockshifts[c>>1][1] > 0 ? 2 : -2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (int rr = 4; rr < rr1 - 4; rr++) {
|
||||
int cc = 4 + (FC(rr, 2) & 1);
|
||||
int c = FC(rr, cc);
|
||||
@ -1152,19 +1197,14 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
if (progresscounter % 8 == 0)
|
||||
#pragma omp critical (cacorrect)
|
||||
{
|
||||
progress += (double)(8.0 * (ts - border2) * (ts - border2)) / (2 * height * width);
|
||||
|
||||
if (progress > 1.0) {
|
||||
progress = 1.0;
|
||||
}
|
||||
|
||||
progress += 4.0 * SQR(ts - border2) / (iterations * height * width);
|
||||
progress = std::min(progress, 1.0);
|
||||
plistener->setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp barrier
|
||||
// copy temporary image matrix back to image matrix
|
||||
#pragma omp for
|
||||
|
||||
@ -1172,20 +1212,93 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
int col = FC(row, 0) & 1;
|
||||
int indx = (row * width + col) >> 1;
|
||||
#ifdef __SSE2__
|
||||
for(; col < width - 7; col += 8, indx += 4) {
|
||||
for (; col < width - 7 - (3 * (W & 1)); col += 8, indx += 4) {
|
||||
STC2VFU(rawData[row][col], LVFU(RawDataTmp[indx]));
|
||||
}
|
||||
#endif
|
||||
for(; col < width - (W & 1); col += 2, indx++) {
|
||||
for (; col < width - (3 * (W & 1)); col += 2, indx++) {
|
||||
rawData[row][col] = RawDataTmp[indx];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// clean up
|
||||
free(bufferThr);
|
||||
}
|
||||
if (avoidColourshift) {
|
||||
// to avoid or at least reduce the colour shift caused by raw ca correction we compute the per pixel difference factors
|
||||
// of red and blue channel and apply a gaussian blur to them.
|
||||
// Then we apply the resulting factors per pixel on the result of raw ca correction
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
#ifdef __SSE2__
|
||||
const vfloat onev = F2V(1.f);
|
||||
const vfloat twov = F2V(2.f);
|
||||
const vfloat zd5v = F2V(0.5f);
|
||||
#endif
|
||||
#pragma omp for
|
||||
for (int i = 0; i < H; ++i) {
|
||||
const int firstCol = FC(i, 0) & 1;
|
||||
const int colour = FC(i, firstCol);
|
||||
const array2D<float>* nonGreen = colour == 0 ? redFactor : blueFactor;
|
||||
int j = firstCol;
|
||||
#ifdef __SSE2__
|
||||
for (; j < W - 7; j += 8) {
|
||||
const vfloat newvals = LC2VFU(rawData[i][j]);
|
||||
const vfloat oldvals = LVFU((*oldraw)[i][j / 2]);
|
||||
vfloat factors = oldvals / newvals;
|
||||
factors = vself(vmaskf_le(newvals, onev), onev, factors);
|
||||
factors = vself(vmaskf_le(oldvals, onev), onev, factors);
|
||||
STVFU((*nonGreen)[i/2][j/2], LIMV(factors, zd5v, twov));
|
||||
}
|
||||
#endif
|
||||
for (; j < W; j += 2) {
|
||||
(*nonGreen)[i/2][j/2] = (rawData[i][j] <= 1.f || (*oldraw)[i][j / 2] <= 1.f) ? 1.f : rtengine::LIM((*oldraw)[i][j / 2] / rawData[i][j], 0.5f, 2.f);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp single
|
||||
{
|
||||
if (H % 2) {
|
||||
// odd height => factors for one channel are not set in last row => use values of preceding row
|
||||
const int firstCol = FC(0, 0) & 1;
|
||||
const int colour = FC(0, firstCol);
|
||||
const array2D<float>* nonGreen = colour == 0 ? blueFactor : redFactor;
|
||||
for (int j = 0; j < (W + 1) / 2; ++j) {
|
||||
(*nonGreen)[(H + 1) / 2 - 1][j] = (*nonGreen)[(H + 1) / 2 - 2][j];
|
||||
}
|
||||
}
|
||||
|
||||
if (W % 2) {
|
||||
// odd width => factors for one channel are not set in last column => use value of preceding column
|
||||
const int ngRow = 1 - (FC(0, 0) & 1);
|
||||
const int ngCol = FC(ngRow, 0) & 1;
|
||||
const int colour = FC(ngRow, ngCol);
|
||||
const array2D<float>* nonGreen = colour == 0 ? redFactor : blueFactor;
|
||||
for (int i = 0; i < (H + 1) / 2; ++i) {
|
||||
(*nonGreen)[i][(W + 1) / 2 - 1] = (*nonGreen)[i][(W + 1) / 2 - 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// blur correction factors
|
||||
gaussianBlur(*redFactor, *redFactor, (W+1)/2, (H+1)/2, 30.0);
|
||||
gaussianBlur(*blueFactor, *blueFactor, (W+1)/2, (H+1)/2, 30.0);
|
||||
|
||||
// apply correction factors to avoid (reduce) colour shift
|
||||
#pragma omp for
|
||||
for (int i = 0; i < H; ++i) {
|
||||
const int firstCol = FC(i, 0) & 1;
|
||||
const int colour = FC(i, firstCol);
|
||||
const array2D<float>* nonGreen = colour == 0 ? redFactor : blueFactor;
|
||||
for (int j = firstCol; j < W; j += 2) {
|
||||
rawData[i][j] *= (*nonGreen)[i/2][j/2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (autoCA && fitParamsTransfer && fitParamsOut) {
|
||||
// store calculated parameters
|
||||
@ -1204,6 +1317,12 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
|
||||
buffer = nullptr;
|
||||
}
|
||||
|
||||
if (avoidColourshift) {
|
||||
delete oldraw;
|
||||
delete redFactor;
|
||||
delete blueFactor;
|
||||
}
|
||||
|
||||
if (plistener) {
|
||||
plistener->setProgress(1.0);
|
||||
}
|
||||
|
@ -2561,6 +2561,8 @@ RAWParams::RAWParams() :
|
||||
ff_AutoClipControl(false),
|
||||
ff_clipControl(0),
|
||||
ca_autocorrect(false),
|
||||
ca_avoidcolourshift(true),
|
||||
caautoiterations(2),
|
||||
cared(0.0),
|
||||
cablue(0.0),
|
||||
expos(1.0),
|
||||
@ -2585,6 +2587,8 @@ bool RAWParams::operator ==(const RAWParams& other) const
|
||||
&& ff_AutoClipControl == other.ff_AutoClipControl
|
||||
&& ff_clipControl == other.ff_clipControl
|
||||
&& ca_autocorrect == other.ca_autocorrect
|
||||
&& ca_avoidcolourshift == other.ca_avoidcolourshift
|
||||
&& caautoiterations == other.caautoiterations
|
||||
&& cared == other.cared
|
||||
&& cablue == other.cablue
|
||||
&& expos == other.expos
|
||||
@ -3381,6 +3385,8 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo
|
||||
saveToKeyfile(!pedited || pedited->raw.ff_AutoClipControl, "RAW", "FlatFieldAutoClipControl", raw.ff_AutoClipControl, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.ff_clipControl, "RAW", "FlatFieldClipControl", raw.ff_clipControl, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.ca_autocorrect, "RAW", "CA", raw.ca_autocorrect, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.ca_avoidcolourshift, "RAW", "CAAvoidColourshift", raw.ca_avoidcolourshift, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.caautoiterations, "RAW", "CAAutoIterations", raw.caautoiterations, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.cared, "RAW", "CARed", raw.cared, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.cablue, "RAW", "CABlue", raw.cablue, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->raw.hotPixelFilter, "RAW", "HotPixelFilter", raw.hotPixelFilter, keyFile);
|
||||
@ -4753,6 +4759,17 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited)
|
||||
}
|
||||
|
||||
assignFromKeyfile(keyFile, "RAW", "CA", pedited, raw.ca_autocorrect, pedited->raw.ca_autocorrect);
|
||||
if (ppVersion >= 342) {
|
||||
assignFromKeyfile(keyFile, "RAW", "CAAutoIterations", pedited, raw.caautoiterations, pedited->raw.caautoiterations);
|
||||
} else {
|
||||
raw.caautoiterations = 1;
|
||||
}
|
||||
|
||||
if (ppVersion >= 343) {
|
||||
assignFromKeyfile(keyFile, "RAW", "CAAvoidColourshift", pedited, raw.ca_avoidcolourshift, pedited->raw.ca_avoidcolourshift);
|
||||
} else {
|
||||
raw.ca_avoidcolourshift = false;
|
||||
}
|
||||
assignFromKeyfile(keyFile, "RAW", "CARed", pedited, raw.cared, pedited->raw.cared);
|
||||
assignFromKeyfile(keyFile, "RAW", "CABlue", pedited, raw.cablue, pedited->raw.cablue);
|
||||
// For compatibility to elder pp3 versions
|
||||
|
@ -1368,6 +1368,8 @@ struct RAWParams {
|
||||
int ff_clipControl;
|
||||
|
||||
bool ca_autocorrect;
|
||||
bool ca_avoidcolourshift;
|
||||
int caautoiterations;
|
||||
double cared;
|
||||
double cablue;
|
||||
|
||||
|
@ -2009,13 +2009,13 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le
|
||||
}
|
||||
if(numFrames == 4) {
|
||||
double fitParams[64];
|
||||
float *buffer = CA_correct_RT(raw.ca_autocorrect, raw.cared, raw.cablue, 8.0, *rawDataFrames[0], fitParams, false, true, nullptr, false);
|
||||
float *buffer = CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, true, *rawDataFrames[0], fitParams, false, true, nullptr, false);
|
||||
for(int i = 1; i < 3; ++i) {
|
||||
CA_correct_RT(raw.ca_autocorrect, raw.cared, raw.cablue, 8.0, *rawDataFrames[i], fitParams, true, false, buffer, false);
|
||||
CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, true, *rawDataFrames[i], fitParams, true, false, buffer, false);
|
||||
}
|
||||
CA_correct_RT(raw.ca_autocorrect, raw.cared, raw.cablue, 8.0, *rawDataFrames[3], fitParams, true, false, buffer, true);
|
||||
CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, true, *rawDataFrames[3], fitParams, true, false, buffer, true);
|
||||
} else {
|
||||
CA_correct_RT(raw.ca_autocorrect, raw.cared, raw.cablue, 8.0, rawData, nullptr, false, false, nullptr, true);
|
||||
CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, true, rawData, nullptr, false, false, nullptr, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,19 @@ protected:
|
||||
inline void interpolate_row_rb (float* ar, float* ab, float* pg, float* cg, float* ng, int i);
|
||||
inline void interpolate_row_rb_mul_pp (const array2D<float> &rawData, float* ar, float* ab, float* pg, float* cg, float* ng, int i, float r_mul, float g_mul, float b_mul, int x1, int width, int skip);
|
||||
|
||||
float* CA_correct_RT (const bool autoCA, const double cared, const double cablue, const double caautostrength, array2D<float> &rawData, double *fitParamsTransfer, bool fitParamsIn, bool fitParamsOut, float * buffer, bool freeBuffer);
|
||||
float* CA_correct_RT(
|
||||
bool autoCA,
|
||||
size_t autoIterations,
|
||||
double cared,
|
||||
double cablue,
|
||||
bool avoidColourshift,
|
||||
const array2D<float> &rawData,
|
||||
double* fitParamsTransfer,
|
||||
bool fitParamsIn,
|
||||
bool fitParamsOut,
|
||||
float* buffer,
|
||||
bool freeBuffer
|
||||
);
|
||||
void ddct8x8s(int isgn, float a[8][8]);
|
||||
void processRawWhitepoint (float expos, float preser, array2D<float> &rawData); // exposure before interpolation
|
||||
|
||||
|
@ -431,6 +431,8 @@ void ParamsEdited::set(bool v)
|
||||
raw.xtranssensor.exBlackGreen = v;
|
||||
raw.xtranssensor.exBlackBlue = v;
|
||||
raw.ca_autocorrect = v;
|
||||
raw.ca_avoidcolourshift = v;
|
||||
raw.caautoiterations = v;
|
||||
raw.cablue = v;
|
||||
raw.cared = v;
|
||||
raw.hotPixelFilter = v;
|
||||
@ -986,6 +988,8 @@ void ParamsEdited::initFrom(const std::vector<rtengine::procparams::ProcParams>&
|
||||
raw.xtranssensor.exBlackGreen = raw.xtranssensor.exBlackGreen && p.raw.xtranssensor.blackgreen == other.raw.xtranssensor.blackgreen;
|
||||
raw.xtranssensor.exBlackBlue = raw.xtranssensor.exBlackBlue && p.raw.xtranssensor.blackblue == other.raw.xtranssensor.blackblue;
|
||||
raw.ca_autocorrect = raw.ca_autocorrect && p.raw.ca_autocorrect == other.raw.ca_autocorrect;
|
||||
raw.ca_avoidcolourshift = raw.ca_avoidcolourshift && p.raw.ca_avoidcolourshift == other.raw.ca_avoidcolourshift;
|
||||
raw.caautoiterations = raw.caautoiterations && p.raw.caautoiterations == other.raw.caautoiterations;
|
||||
raw.cared = raw.cared && p.raw.cared == other.raw.cared;
|
||||
raw.cablue = raw.cablue && p.raw.cablue == other.raw.cablue;
|
||||
raw.hotPixelFilter = raw.hotPixelFilter && p.raw.hotPixelFilter == other.raw.hotPixelFilter;
|
||||
@ -2626,6 +2630,14 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng
|
||||
toEdit.raw.ca_autocorrect = mods.raw.ca_autocorrect;
|
||||
}
|
||||
|
||||
if (raw.ca_avoidcolourshift) {
|
||||
toEdit.raw.ca_avoidcolourshift = mods.raw.ca_avoidcolourshift;
|
||||
}
|
||||
|
||||
if (raw.caautoiterations) {
|
||||
toEdit.raw.caautoiterations = dontforceSet && options.baBehav[ADDSET_RAWCACORR] ? toEdit.raw.caautoiterations + mods.raw.caautoiterations : mods.raw.caautoiterations;
|
||||
}
|
||||
|
||||
if (raw.cared) {
|
||||
toEdit.raw.cared = dontforceSet && options.baBehav[ADDSET_RAWCACORR] ? toEdit.raw.cared + mods.raw.cared : mods.raw.cared;
|
||||
}
|
||||
@ -3127,7 +3139,7 @@ bool RAWParamsEdited::XTransSensor::isUnchanged() const
|
||||
|
||||
bool RAWParamsEdited::isUnchanged() const
|
||||
{
|
||||
return bayersensor.isUnchanged() && xtranssensor.isUnchanged() && ca_autocorrect && cared && cablue && hotPixelFilter && deadPixelFilter && hotdeadpix_thresh && darkFrame
|
||||
return bayersensor.isUnchanged() && xtranssensor.isUnchanged() && ca_autocorrect && ca_avoidcolourshift && caautoiterations && cared && cablue && hotPixelFilter && deadPixelFilter && hotdeadpix_thresh && darkFrame
|
||||
&& df_autoselect && ff_file && ff_AutoSelect && ff_BlurRadius && ff_BlurType && exPos && exPreser && ff_AutoClipControl && ff_clipControl;
|
||||
}
|
||||
|
||||
|
@ -787,6 +787,8 @@ public:
|
||||
XTransSensor xtranssensor;
|
||||
|
||||
bool ca_autocorrect;
|
||||
bool ca_avoidcolourshift;
|
||||
bool caautoiterations;
|
||||
bool cared;
|
||||
bool cablue;
|
||||
bool hotPixelFilter;
|
||||
|
@ -901,6 +901,7 @@ void PartialPasteDlg::applyPaste (rtengine::procparams::ProcParams* dstPP, Param
|
||||
|
||||
if (!raw_ca_autocorrect->get_active ()) {
|
||||
filterPE.raw.ca_autocorrect = falsePE.raw.ca_autocorrect;
|
||||
filterPE.raw.caautoiterations = falsePE.raw.caautoiterations;
|
||||
}
|
||||
|
||||
if (!raw_caredblue->get_active ()) {
|
||||
|
@ -1,11 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
// This number has to be incremented whenever the PP3 file format is modified or the behaviour of a tool changes
|
||||
#define PPVERSION 340
|
||||
#define PPVERSION 343
|
||||
#define PPVERSION_AEXP 301 //value of PPVERSION when auto exposure algorithm was modified
|
||||
|
||||
/*
|
||||
Log of version changes
|
||||
343 2018-09-06
|
||||
raw auto ca correction avoid colour shift
|
||||
342 2018-09-05
|
||||
raw auto ca correction iterations
|
||||
341 2018-07-22
|
||||
[ICM] enhanced custom output profile
|
||||
340 2018-07-08
|
||||
|
@ -17,6 +17,7 @@
|
||||
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "rawcacorrection.h"
|
||||
#include "eventmapper.h"
|
||||
#include "guiutils.h"
|
||||
#include "rtimage.h"
|
||||
|
||||
@ -25,6 +26,11 @@ using namespace rtengine::procparams;
|
||||
|
||||
RAWCACorr::RAWCACorr () : FoldableToolPanel(this, "rawcacorrection", M("TP_CHROMATABERR_LABEL"))
|
||||
{
|
||||
auto m = ProcEventMapper::getInstance();
|
||||
EvPreProcessCAAutoiterations = m->newEvent(DARKFRAME, "HISTORY_MSG_RAWCACORR_AUTOIT");
|
||||
// EvPreProcessCAColourshift = m->newEvent(DARKFRAME, "HISTORY_MSG_RAWCACORR_COLOURSHIFT");
|
||||
// EvPreProcessCAColourshiftHistory = m->newEvent(M_VOID, "HISTORY_MSG_RAWCACORR_COLOURSHIFT");
|
||||
|
||||
Gtk::Image* icaredL = Gtk::manage (new RTImage ("circle-red-cyan-small.png"));
|
||||
Gtk::Image* icaredR = Gtk::manage (new RTImage ("circle-cyan-red-small.png"));
|
||||
Gtk::Image* icablueL = Gtk::manage (new RTImage ("circle-blue-yellow-small.png"));
|
||||
@ -33,6 +39,13 @@ RAWCACorr::RAWCACorr () : FoldableToolPanel(this, "rawcacorrection", M("TP_CHROM
|
||||
caAutocorrect = Gtk::manage (new CheckBox(M("TP_RAWCACORR_AUTO"), multiImage));
|
||||
caAutocorrect->setCheckBoxListener (this);
|
||||
|
||||
caAutoiterations = Gtk::manage(new Adjuster (M("TP_RAWCACORR_AUTOIT"), 1, 5, 1, 2));
|
||||
caAutoiterations->setAdjusterListener (this);
|
||||
|
||||
if (caAutoiterations->delay < options.adjusterMaxDelay) {
|
||||
caAutoiterations->delay = options.adjusterMaxDelay;
|
||||
}
|
||||
|
||||
caRed = Gtk::manage(new Adjuster (M("TP_RAWCACORR_CARED"), -8.0, 8.0, 0.1, 0, icaredL, icaredR));
|
||||
caRed->setAdjusterListener (this);
|
||||
|
||||
@ -51,9 +64,15 @@ RAWCACorr::RAWCACorr () : FoldableToolPanel(this, "rawcacorrection", M("TP_CHROM
|
||||
caBlue->show();
|
||||
|
||||
pack_start( *caAutocorrect, Gtk::PACK_SHRINK, 4);
|
||||
pack_start( *caAutoiterations, Gtk::PACK_SHRINK, 4);
|
||||
pack_start( *caRed, Gtk::PACK_SHRINK, 4);
|
||||
pack_start( *caBlue, Gtk::PACK_SHRINK, 4);
|
||||
|
||||
// caAvoidcolourshift = Gtk::manage (new CheckBox(M("TP_RAWCACORR_AVOIDCOLORSHIFT"), multiImage));
|
||||
// caAvoidcolourshift->setCheckBoxListener (this);
|
||||
// pack_start( *caAvoidcolourshift, Gtk::PACK_SHRINK, 4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RAWCACorr::read(const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited)
|
||||
@ -62,15 +81,20 @@ void RAWCACorr::read(const rtengine::procparams::ProcParams* pp, const ParamsEdi
|
||||
|
||||
if(pedited ) {
|
||||
caAutocorrect->setEdited(pedited->raw.ca_autocorrect);
|
||||
// caAvoidcolourshift->setEdited(pedited->raw.ca_avoidcolourshift);
|
||||
caAutoiterations->setEditedState( pedited->raw.caautoiterations ? Edited : UnEdited );
|
||||
caRed->setEditedState( pedited->raw.cared ? Edited : UnEdited );
|
||||
caBlue->setEditedState( pedited->raw.cablue ? Edited : UnEdited );
|
||||
}
|
||||
|
||||
// disable Red and Blue sliders when caAutocorrect is enabled
|
||||
caAutoiterations->set_sensitive(pp->raw.ca_autocorrect);
|
||||
caRed->set_sensitive(!pp->raw.ca_autocorrect);
|
||||
caBlue->set_sensitive(!pp->raw.ca_autocorrect);
|
||||
|
||||
caAutocorrect->setValue(pp->raw.ca_autocorrect);
|
||||
// caAvoidcolourshift->setValue(pp->raw.ca_avoidcolourshift);
|
||||
caAutoiterations->setValue (pp->raw.caautoiterations);
|
||||
caRed->setValue (pp->raw.cared);
|
||||
caBlue->setValue (pp->raw.cablue);
|
||||
|
||||
@ -80,11 +104,15 @@ void RAWCACorr::read(const rtengine::procparams::ProcParams* pp, const ParamsEdi
|
||||
void RAWCACorr::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited)
|
||||
{
|
||||
pp->raw.ca_autocorrect = caAutocorrect->getLastActive();
|
||||
// pp->raw.ca_avoidcolourshift = caAvoidcolourshift->getLastActive();
|
||||
pp->raw.caautoiterations = caAutoiterations->getValue();
|
||||
pp->raw.cared = caRed->getValue();
|
||||
pp->raw.cablue = caBlue->getValue();
|
||||
|
||||
if (pedited) {
|
||||
pedited->raw.ca_autocorrect = !caAutocorrect->get_inconsistent();
|
||||
// pedited->raw.ca_avoidcolourshift = !caAvoidcolourshift->get_inconsistent();
|
||||
pedited->raw.caautoiterations = caAutoiterations->getEditedState ();
|
||||
pedited->raw.cared = caRed->getEditedState ();
|
||||
pedited->raw.cablue = caBlue->getEditedState ();
|
||||
}
|
||||
@ -97,7 +125,9 @@ void RAWCACorr::adjusterChanged (Adjuster* a, double newval)
|
||||
|
||||
Glib::ustring value = a->getTextValue();
|
||||
|
||||
if (a == caRed) {
|
||||
if (a == caAutoiterations) {
|
||||
listener->panelChanged (EvPreProcessCAAutoiterations, value );
|
||||
} else if (a == caRed) {
|
||||
listener->panelChanged (EvPreProcessCARed, value );
|
||||
} else if (a == caBlue) {
|
||||
listener->panelChanged (EvPreProcessCABlue, value );
|
||||
@ -110,6 +140,7 @@ void RAWCACorr::checkBoxToggled (CheckBox* c, CheckValue newval)
|
||||
if (c == caAutocorrect) {
|
||||
if (!batchMode) {
|
||||
// disable Red and Blue sliders when caAutocorrect is enabled
|
||||
caAutoiterations->set_sensitive(caAutocorrect->getLastActive ());
|
||||
caRed->set_sensitive(!caAutocorrect->getLastActive ());
|
||||
caBlue->set_sensitive(!caAutocorrect->getLastActive ());
|
||||
}
|
||||
@ -117,24 +148,33 @@ void RAWCACorr::checkBoxToggled (CheckBox* c, CheckValue newval)
|
||||
listener->panelChanged (EvPreProcessAutoCA, caAutocorrect->getLastActive() ? M("GENERAL_ENABLED") : M("GENERAL_DISABLED"));
|
||||
}
|
||||
}
|
||||
// else if (c == caAvoidcolourshift) {
|
||||
// if (listener) {
|
||||
// listener->panelChanged ((caAutocorrect->getLastActive() || caRed->getValue() != 0 || caBlue->getValue() != 0) ? EvPreProcessCAColourshift : EvPreProcessCAColourshiftHistory, caAvoidcolourshift->getLastActive() ? M("GENERAL_ENABLED") : M("GENERAL_DISABLED"));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void RAWCACorr::setBatchMode(bool batchMode)
|
||||
{
|
||||
ToolPanel::setBatchMode (batchMode);
|
||||
caAutoiterations->showEditedCB ();
|
||||
caRed->showEditedCB ();
|
||||
caBlue->showEditedCB ();
|
||||
}
|
||||
|
||||
void RAWCACorr::setDefaults(const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited)
|
||||
{
|
||||
caAutoiterations->setDefault( defParams->raw.caautoiterations);
|
||||
caRed->setDefault( defParams->raw.cared);
|
||||
caBlue->setDefault( defParams->raw.cablue);
|
||||
|
||||
if (pedited) {
|
||||
caAutoiterations->setDefaultEditedState( pedited->raw.caautoiterations ? Edited : UnEdited);
|
||||
caRed->setDefaultEditedState( pedited->raw.cared ? Edited : UnEdited);
|
||||
caBlue->setDefaultEditedState( pedited->raw.cablue ? Edited : UnEdited);
|
||||
} else {
|
||||
caAutoiterations->setDefaultEditedState( Irrelevant );
|
||||
caRed->setDefaultEditedState( Irrelevant );
|
||||
caBlue->setDefaultEditedState( Irrelevant );
|
||||
}
|
||||
@ -150,6 +190,7 @@ void RAWCACorr::setAdjusterBehavior (bool caadd)
|
||||
void RAWCACorr::trimValues (rtengine::procparams::ProcParams* pp)
|
||||
{
|
||||
|
||||
caAutoiterations->trimValue(pp->raw.caautoiterations);
|
||||
caRed->trimValue(pp->raw.cared);
|
||||
caBlue->trimValue(pp->raw.cablue);
|
||||
}
|
||||
|
@ -29,8 +29,14 @@ class RAWCACorr : public ToolParamBlock, public AdjusterListener, public CheckBo
|
||||
|
||||
protected:
|
||||
CheckBox* caAutocorrect;
|
||||
Adjuster* caAutoiterations;
|
||||
Adjuster* caRed;
|
||||
Adjuster* caBlue;
|
||||
// CheckBox* caAvoidcolourshift;
|
||||
|
||||
rtengine::ProcEvent EvPreProcessCAAutoiterations;
|
||||
// rtengine::ProcEvent EvPreProcessCAColourshift;
|
||||
// rtengine::ProcEvent EvPreProcessCAColourshiftHistory;
|
||||
|
||||
public:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user