Merge pull request #4797 from Beep6581/rawcacorrection_iterate

Raw ca correction. Iterative processing and Avoid color shift.
This commit is contained in:
Ingo Weyrich 2018-09-15 00:15:57 +02:00 committed by GitHub
commit f9404901ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1218 additions and 998 deletions

View File

@ -748,6 +748,8 @@ HISTORY_MSG_PREPROCESS_LINEDENOISE_DIRECTION;Line noise filter direction
HISTORY_MSG_PREPROCESS_PDAFLINESFILTER;PDAF lines filter HISTORY_MSG_PREPROCESS_PDAFLINESFILTER;PDAF lines filter
HISTORY_MSG_PRSHARPEN_CONTRAST;PRS - Contrast threshold HISTORY_MSG_PRSHARPEN_CONTRAST;PRS - Contrast threshold
HISTORY_MSG_RAW_BORDER;Raw border 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_RESIZE_ALLOWUPSCALING;Resize - Allow upscaling
HISTORY_MSG_SHARPENING_CONTRAST;Sharpening - Contrast threshold HISTORY_MSG_SHARPENING_CONTRAST;Sharpening - Contrast threshold
HISTORY_MSG_SOFTLIGHT_ENABLED;Soft light 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_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_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_AUTO;Auto-correction
TP_RAWCACORR_AUTOIT;Iterations
TP_RAWCACORR_AVOIDCOLORSHIFT;Avoid color shift
TP_RAWCACORR_CABLUE;Blue TP_RAWCACORR_CABLUE;Blue
TP_RAWCACORR_CARED;Red TP_RAWCACORR_CARED;Red
TP_RAWCACORR_CASTR;Strength TP_RAWCACORR_CASTR;Strength

View File

@ -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) 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: September 8, 2018
// code dated: November 26, 2010
// //
// CA_correct_RT.cc is free software: you can redistribute it and/or modify // 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 // 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/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "rtengine.h" #include "rtengine.h"
#include "rawimagesource.h" #include "rawimagesource.h"
#include "rt_math.h" #include "rt_math.h"
#include "gauss.h"
#include "median.h" #include "median.h"
//#define BENCHMARK
#include "StopWatch.h" #include "StopWatch.h"
namespace { namespace {
@ -49,21 +50,21 @@ bool LinEqSolve(int nDim, double* pfMatr, double* pfVect, double* pfSolution)
int i, j, k; int i, j, k;
for(k = 0; k < (nDim - 1); k++) { // base row of matrix for (k = 0; k < (nDim - 1); k++) { // base row of matrix
// search of line with max element // search of line with max element
double fMaxElem = fabs( pfMatr[k * nDim + k] ); double fMaxElem = fabs(pfMatr[k * nDim + k]);
int m = k; int m = k;
for (i = k + 1; i < nDim; i++) { for (i = k + 1; i < nDim; i++) {
if(fMaxElem < fabs(pfMatr[i * nDim + k]) ) { if (fMaxElem < fabs(pfMatr[i * nDim + k])) {
fMaxElem = pfMatr[i * nDim + k]; fMaxElem = pfMatr[i * nDim + k];
m = i; m = i;
} }
} }
// permutation of base line (index k) and max element line(index m) // permutation of base line (index k) and max element line(index m)
if(m != k) { if (m != k) {
for(i = k; i < nDim; i++) { for (i = k; i < nDim; i++) {
fAcc = pfMatr[k * nDim + i]; fAcc = pfMatr[k * nDim + i];
pfMatr[k * nDim + i] = pfMatr[m * nDim + i]; pfMatr[k * nDim + i] = pfMatr[m * nDim + i];
pfMatr[m * nDim + i] = fAcc; pfMatr[m * nDim + i] = fAcc;
@ -74,16 +75,16 @@ bool LinEqSolve(int nDim, double* pfMatr, double* pfVect, double* pfSolution)
pfVect[m] = fAcc; pfVect[m] = fAcc;
} }
if( pfMatr[k * nDim + k] == 0.) { if (pfMatr[k * nDim + k] == 0.) {
//linear system has no solution //linear system has no solution
return false; // needs improvement !!! return false; // needs improvement !!!
} }
// triangulation of matrix with coefficients // triangulation of matrix with coefficients
for(j = (k + 1); j < nDim; j++) { // current row of matrix for (j = (k + 1); j < nDim; j++) { // current row of matrix
fAcc = - pfMatr[j * nDim + k] / pfMatr[k * nDim + k]; fAcc = - pfMatr[j * nDim + k] / pfMatr[k * nDim + k];
for(i = k; i < nDim; i++) { for (i = k; i < nDim; i++) {
pfMatr[j * nDim + i] = pfMatr[j * nDim + i] + fAcc * pfMatr[k * nDim + i]; pfMatr[j * nDim + i] = pfMatr[j * nDim + i] + fAcc * pfMatr[k * nDim + i];
} }
@ -91,10 +92,10 @@ bool LinEqSolve(int nDim, double* pfMatr, double* pfVect, double* pfSolution)
} }
} }
for(k = (nDim - 1); k >= 0; k--) { for (k = (nDim - 1); k >= 0; k--) {
pfSolution[k] = pfVect[k]; pfSolution[k] = pfVect[k];
for(i = (k + 1); i < nDim; i++) { for (i = (k + 1); i < nDim; i++) {
pfSolution[k] -= (pfMatr[k * nDim + i] * pfSolution[i]); pfSolution[k] -= (pfMatr[k * nDim + i] * pfSolution[i]);
} }
@ -104,32 +105,61 @@ bool LinEqSolve(int nDim, double* pfMatr, double* pfVect, double* pfSolution)
return true; return true;
} }
//end of linear equation solver //end of linear equation solver
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
} }
using namespace std; using namespace std;
using namespace rtengine; 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 // multithreaded and vectorized by Ingo Weyrich
constexpr int ts = 128; constexpr int ts = 128;
constexpr int tsh = ts / 2; 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; 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 // Test for RGB cfa
for(int i = 0; i < 2; i++) for (int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) for (int j = 0; j < 2; j++) {
if(FC(i, j) == 3) { 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; 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];
}
}
}
if(plistener) { double progress = 0.0;
if (plistener) {
plistener->setProgress (progress); plistener->setProgress (progress);
} }
@ -147,32 +177,42 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
if (!buffer) { if (!buffer) {
buffer = static_cast<float*>(malloc ((height * width + vblsz * hblsz * (2 * 2 + 1)) * sizeof(float))); buffer = static_cast<float*>(malloc ((height * width + vblsz * hblsz * (2 * 2 + 1)) * sizeof(float)));
} }
float *Gtmp = buffer; float* Gtmp = buffer;
float *RawDataTmp = buffer + (height * width) / 2; float* RawDataTmp = buffer + (height * width) / 2;
//block CA shift values and weight assigned to block //block CA shift values and weight assigned to block
float *const blockwt = buffer + (height * width); float* const blockwt = buffer + (height * width);
memset(blockwt, 0, vblsz * hblsz * (2 * 2 + 1) * sizeof(float)); memset(blockwt, 0, vblsz * hblsz * (2 * 2 + 1) * sizeof(float));
float (*blockshifts)[2][2] = (float (*)[2][2])(blockwt + vblsz * hblsz); 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 // Because we can't break parallel processing, we need a switch do handle the errors
bool processpasstwo = true; bool processpasstwo = true;
double fitparams[2][2][16]; double fitparams[2][2][16];
const bool fitParamsSet = fitParamsTransfer && fitParamsIn;
if(autoCA && fitParamsSet) { 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 // use stored parameters
int index = 0; int index = 0;
for(int c = 0; c < 2; ++c) { for (int c = 0; c < 2; ++c) {
for(int d = 0; d < 2; ++d) { for (int d = 0; d < 2; ++d) {
for(int e = 0; e < 16; ++e) { for (int e = 0; e < 16; ++e) {
fitparams[c][d][e] = fitParamsTransfer[index++]; fitparams[c][d][e] = fitParamsTransfer[index++];
} }
} }
} }
} }
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 //order of 2d polynomial fit (polyord), and numpar=polyord^2
int polyord = 4, numpar = 16; int polyord = 4, numpar = 16;
@ -196,29 +236,30 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
constexpr int buffersizePassTwo = sizeof(float) * ts * ts + 4 * sizeof(float) * ts * tsh + 4 * 64 + 63; constexpr int buffersizePassTwo = sizeof(float) * ts * ts + 4 * sizeof(float) * ts * tsh + 4 * 64 + 63;
char * const bufferThr = (char *) malloc((autoCA && !fitParamsSet) ? buffersize : buffersizePassTwo); char * const bufferThr = (char *) malloc((autoCA && !fitParamsSet) ? buffersize : buffersizePassTwo);
char * const data = (char*)( ( uintptr_t(bufferThr) + uintptr_t(63)) / 64 * 64); char * const data = (char*)((uintptr_t(bufferThr) + uintptr_t(63)) / 64 * 64);
// shift the beginning of all arrays but the first by 64 bytes to avoid cache miss conflicts on CPUs which have <= 4-way associative L1-Cache // shift the beginning of all arrays but the first by 64 bytes to avoid cache miss conflicts on CPUs which have <= 4-way associative L1-Cache
//rgb data in a tile //rgb data in a tile
float* rgb[3]; float* rgb[3];
rgb[0] = (float (*)) data; rgb[0] = (float*) data;
rgb[1] = (float (*)) (data + sizeof(float) * ts * tsh + 1 * 64); rgb[1] = (float*) (data + sizeof(float) * ts * tsh + 1 * 64);
rgb[2] = (float (*)) (data + sizeof(float) * (ts * ts + ts * tsh) + 2 * 64); rgb[2] = (float*) (data + sizeof(float) * (ts * ts + ts * tsh) + 2 * 64);
if (autoCA && !fitParamsSet) { if (autoCA && !fitParamsSet) {
constexpr float caAutostrength = 8.f;
//high pass filter for R/B in vertical direction //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 //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 //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 //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 //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 //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 // Main algorithm: Tile loop calculating correction parameters per tile
//local quadratic fit to shift data within a 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]; float CAshift[2][2];
//per thread data for evaluation of block CA shift variance //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 #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) { for (int left = -border; left < width - (W & 1); left += ts - border2) {
memset(bufferThr, 0, buffersize); memset(bufferThr, 0, buffersize);
const int vblock = ((top + border) / (ts - border2)) + 1; const int vblock = (top + border) / (ts - border2) + 1;
const int hblock = ((left + border) / (ts - border2)) + 1; const int hblock = (left + border) / (ts - border2) + 1;
const int bottom = min(top + ts, height + border); const int bottom = min(top + ts, height + border);
const int right = min(left + ts, width - (W & 1) + border); const int right = min(left + ts, width - (W & 1) + border);
const int rr1 = bottom - top; const int rr1 = bottom - top;
@ -258,7 +301,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
int col = cc + left; int col = cc + left;
#ifdef __SSE2__ #ifdef __SSE2__
int c0 = FC(rr, cc); int c0 = FC(rr, cc);
if(c0 == 1) { if (c0 == 1) {
rgb[c0][rr * ts + cc] = rawData[row][col] / 65535.f; rgb[c0][rr * ts + cc] = rawData[row][col] / 65535.f;
cc++; cc++;
col++; col++;
@ -268,7 +311,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
for (; cc < ccmax - 7; cc+=8, col+=8, indx1 += 8) { for (; cc < ccmax - 7; cc+=8, col+=8, indx1 += 8) {
vfloat val1 = LVFU(rawData[row][col]) / c65535v; vfloat val1 = LVFU(rawData[row][col]) / c65535v;
vfloat val2 = LVFU(rawData[row][col + 4]) / c65535v; vfloat val2 = LVFU(rawData[row][col + 4]) / c65535v;
vfloat nonGreenv = _mm_shuffle_ps(val1,val2,_MM_SHUFFLE( 2,0,2,0 )); vfloat nonGreenv = _mm_shuffle_ps(val1,val2,_MM_SHUFFLE(2,0,2,0));
STVFU(rgb[c0][indx1 >> 1], nonGreenv); STVFU(rgb[c0][indx1 >> 1], nonGreenv);
STVFU(rgb[1][indx1], val1); STVFU(rgb[1][indx1], val1);
STVFU(rgb[1][indx1 + 4], val2); STVFU(rgb[1][indx1 + 4], val2);
@ -281,78 +324,83 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
} }
} }
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//fill borders //fill borders
if (rrmin > 0) { if (rrmin > 0) {
for (int rr = 0; rr < border; rr++) for (int rr = 0; rr < border; rr++) {
for (int cc = ccmin; cc < ccmax; cc++) { for (int cc = ccmin; cc < ccmax; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][((border2 - rr) * ts + cc) >> ((c & 1) ^ 1)]; rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][((border2 - rr) * ts + cc) >> ((c & 1) ^ 1)];
} }
} }
}
if (rrmax < rr1) { if (rrmax < rr1) {
for (int rr = 0; rr < border; rr++) for (int rr = 0; rr < border; rr++) {
for (int cc = ccmin; cc < ccmax; cc++) { for (int cc = ccmin; cc < ccmax; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][left + cc] / 65535.f; rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][left + cc] / 65535.f;
} }
} }
}
if (ccmin > 0) { if (ccmin > 0) {
for (int rr = rrmin; rr < rrmax; rr++) for (int rr = rrmin; rr < rrmax; rr++) {
for (int cc = 0; cc < border; cc++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][(rr * ts + border2 - cc) >> ((c & 1) ^ 1)]; rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][(rr * ts + border2 - cc) >> ((c & 1) ^ 1)];
} }
} }
}
if (ccmax < cc1) { if (ccmax < cc1) {
for (int rr = rrmin; rr < rrmax; rr++) for (int rr = rrmin; rr < rrmax; rr++) {
for (int cc = 0; cc < border; cc++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(top + rr)][(width - cc - 2)] / 65535.f; rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(top + rr)][(width - cc - 2)] / 65535.f;
} }
} }
}
//also, fill the image corners //also, fill the image corners
if (rrmin > 0 && ccmin > 0) { 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++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rawData[border2 - rr][border2 - cc] / 65535.f; rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rawData[border2 - rr][border2 - cc] / 65535.f;
} }
} }
}
if (rrmax < rr1 && ccmax < cc1) { 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++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, 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; rgb[c][((rrmax + rr)*ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][(width - cc - 2)] / 65535.f;
} }
} }
}
if (rrmin > 0 && ccmax < cc1) { 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++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(border2 - rr)][(width - cc - 2)] / 65535.f; rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = rawData[(border2 - rr)][(width - cc - 2)] / 65535.f;
} }
} }
}
if (rrmax < rr1 && ccmin > 0) { 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++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][(border2 - cc)] / 65535.f; rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = rawData[(height - rr - 2)][(border2 - cc)] / 65535.f;
} }
} }
}
//end of border fill //end of border fill
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//end of initialization //end of initialization
#ifdef __SSE2__ #ifdef __SSE2__
vfloat onev = F2V(1.f); vfloat onev = F2V(1.f);
vfloat epsv = F2V(eps); vfloat epsv = F2V(eps);
@ -398,17 +446,16 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
int col = max(left + 3, 0) + offset; int col = max(left + 3, 0) + offset;
int indx = rr * ts + 3 - (left < 0 ? (left+3) : 0) + offset; int indx = rr * ts + 3 - (left < 0 ? (left+3) : 0) + offset;
#ifdef __SSE2__ #ifdef __SSE2__
for(; col < min(cc1 + left - 3, width) - 7; col+=8, indx+=8) { for (; col < min(cc1 + left - 3, width) - 7; col+=8, indx+=8) {
STVFU(Gtmp[(row * width + col) >> 1], LC2VFU(rgb[1][indx])); STVFU(Gtmp[(row * width + col) >> 1], LC2VFU(rgb[1][indx]));
} }
#endif #endif
for(; col < min(cc1 + left - 3, width); col+=2, indx+=2) { for (; col < min(cc1 + left - 3, width); col+=2, indx+=2) {
Gtmp[(row * width + col) >> 1] = rgb[1][indx]; Gtmp[(row * width + col) >> 1] = rgb[1][indx];
} }
} }
} }
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef __SSE2__ #ifdef __SSE2__
vfloat zd25v = F2V(0.25f); vfloat zd25v = F2V(0.25f);
#endif #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(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])))); STVFU(grblpfh[indx >> 1], zd25v * (glpfhv + (rgbcv + LVFU(rgb[c][(indx + 2) >> 1]) + LVFU(rgb[c][(indx - 2) >> 1]))));
} }
#endif #endif
for (; cc < cc1 - 4; cc += 2, indx += 2) { 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])) + 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 coeff11v = ZEROV;
vfloat coeff12v = ZEROV; vfloat coeff12v = ZEROV;
for (; cc < cc1 - 14; cc += 8, indx += 8) { for (; cc < cc1 - 14; cc += 8, indx += 8) {
//in linear interpolation, colour differences are a quadratic function of interpolation position; //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 //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 #endif
for (; cc < cc1 - 8; cc += 2, indx += 2) { for (; cc < cc1 - 8; cc += 2, indx += 2) {
//in linear interpolation, colour differences are a quadratic function of interpolation position; //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 //solve for the interpolation position that minimizes colour difference variance over the tile
@ -534,7 +578,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
float gdiff = (rgb[1][indx + ts] - rgb[1][indx - ts]) + 0.3f * (rgb[1][indx + ts + 1] - rgb[1][indx - ts + 1] + rgb[1][indx + ts - 1] - rgb[1][indx - ts - 1]); float gdiff = (rgb[1][indx + ts] - rgb[1][indx - ts]) + 0.3f * (rgb[1][indx + ts + 1] - rgb[1][indx - ts + 1] + rgb[1][indx + ts - 1] - rgb[1][indx - ts - 1]);
float deltgrb = (rgb[c][indx >> 1] - rgb[1][indx]); float deltgrb = (rgb[c][indx >> 1] - rgb[1][indx]);
float gradwt = (rbhpfv[indx >> 1] + 0.5f * (rbhpfv[(indx >> 1) + 1] + rbhpfv[(indx >> 1) - 1]) ) * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) / (eps + 0.1f * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) + rblpfv[(indx >> 1) - v1] + rblpfv[(indx >> 1) + v1]); float gradwt = (rbhpfv[indx >> 1] + 0.5f * (rbhpfv[(indx >> 1) + 1] + rbhpfv[(indx >> 1) - 1])) * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) / (eps + 0.1f * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) + rblpfv[(indx >> 1) - v1] + rblpfv[(indx >> 1) + v1]);
coeff[0][0][c>>1] += gradwt * deltgrb * deltgrb; coeff[0][0][c>>1] += gradwt * deltgrb * deltgrb;
coeff[0][1][c>>1] += gradwt * gdiff * deltgrb; coeff[0][1][c>>1] += gradwt * gdiff * deltgrb;
@ -543,7 +587,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
//horizontal //horizontal
gdiff = (rgb[1][indx + 1] - rgb[1][indx - 1]) + 0.3f * (rgb[1][indx + 1 + ts] - rgb[1][indx - 1 + ts] + rgb[1][indx + 1 - ts] - rgb[1][indx - 1 - ts]); gdiff = (rgb[1][indx + 1] - rgb[1][indx - 1]) + 0.3f * (rgb[1][indx + 1 + ts] - rgb[1][indx - 1 + ts] + rgb[1][indx + 1 - ts] - rgb[1][indx - 1 - ts]);
gradwt = (rbhpfh[indx >> 1] + 0.5f * (rbhpfh[(indx >> 1) + v1] + rbhpfh[(indx >> 1) - v1]) ) * (grblpfh[(indx >> 1) - 1] + grblpfh[(indx >> 1) + 1]) / (eps + 0.1f * (grblpfh[(indx >> 1) - 1] + grblpfh[(indx >> 1) + 1]) + rblpfh[(indx >> 1) - 1] + rblpfh[(indx >> 1) + 1]); gradwt = (rbhpfh[indx >> 1] + 0.5f * (rbhpfh[(indx >> 1) + v1] + rbhpfh[(indx >> 1) - v1])) * (grblpfh[(indx >> 1) - 1] + grblpfh[(indx >> 1) + 1]) / (eps + 0.1f * (grblpfh[(indx >> 1) - 1] + grblpfh[(indx >> 1) + 1]) + rblpfh[(indx >> 1) - 1] + rblpfh[(indx >> 1) + 1]);
coeff[1][0][c>>1] += gradwt * deltgrb * deltgrb; coeff[1][0][c>>1] += gradwt * deltgrb * deltgrb;
coeff[1][1][c>>1] += gradwt * gdiff * deltgrb; coeff[1][1][c>>1] += gradwt * gdiff * deltgrb;
@ -560,9 +604,9 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
for (int k = 0; k < 3; k++) { for (int k = 0; k < 3; k++) {
for (int c = 0; c < 2; c++) { for (int c = 0; c < 2; c++) {
coeff[dir][k][c] *= 0.25f; coeff[dir][k][c] *= 0.25f;
if(k == 1) { if (k == 1) {
coeff[dir][k][c] *= 0.3125f; coeff[dir][k][c] *= 0.3125f;
} else if(k == 2) { } else if (k == 2) {
coeff[dir][k][c] *= SQR(0.3125f); coeff[dir][k][c] *= SQR(0.3125f);
} }
} }
@ -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 //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 blockshifts[vblock * hblsz + hblock][c][dir] = CAshift[dir][c]; //vert/hor CA shift for R/B
}//vert/hor }//vert/hor
}//colour }//colour
if(plistener) { if (plistener) {
progresscounter++; progresscounter++;
if(progresscounter % 8 == 0) if (progresscounter % 8 == 0) {
#pragma omp critical (cadetectpass1) #pragma omp critical (cadetectpass1)
{ {
progress += (double)(8.0 * (ts - border2) * (ts - border2)) / (2 * height * width); progress += 4.0 * SQR(ts - border2) / (iterations * height * width);
progress = std::min(progress, 1.0);
if (progress > 1.0) {
progress = 1.0;
}
plistener->setProgress(progress); plistener->setProgress(progress);
} }
} }
} }
}
}
//end of diagnostic pass //end of diagnostic pass
#pragma omp critical (cadetectpass2) #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++) { for (int c = 0; c < 2; c++) {
blockdenom[dir][c] += blockdenomthr[dir][c]; blockdenom[dir][c] += blockdenomthr[dir][c];
blocksqave[dir][c] += blocksqavethr[dir][c]; blocksqave[dir][c] += blocksqavethr[dir][c];
blockave[dir][c] += blockavethr[dir][c]; blockave[dir][c] += blockavethr[dir][c];
} }
} }
}
#pragma omp barrier #pragma omp barrier
#pragma omp single #pragma omp single
@ -636,16 +676,14 @@ 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]); blockvar[dir][c] = blocksqave[dir][c] / blockdenom[dir][c] - SQR(blockave[dir][c] / blockdenom[dir][c]);
} else { } else {
processpasstwo = false; processpasstwo = false;
printf ("blockdenom vanishes \n"); std::cout << "blockdenom vanishes" << std::endl;
break; break;
} }
} }
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//now prepare for CA correction pass //now prepare for CA correction pass
//first, fill border blocks of blockshift array //first, fill border blocks of blockshift array
if(processpasstwo) { if (processpasstwo) {
for (int vblock = 1; vblock < vblsz - 1; vblock++) { //left and right sides for (int vblock = 1; vblock < vblsz - 1; vblock++) { //left and right sides
for (int c = 0; c < 2; c++) { for (int c = 0; c < 2; c++) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -679,7 +717,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
int numblox[2] = {0, 0}; 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++) { for (int hblock = 1; hblock < hblsz - 1; hblock++) {
// block 3x3 median of blockshifts for robustness // block 3x3 median of blockshifts for robustness
for (int c = 0; c < 2; c ++) { 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); bstemp[dir] = median(p);
} }
//now prepare coefficient matrix; use only data points within caautostrength/2 std devs of zero //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]) { if (SQR(bstemp[0]) > caAutostrength * blockvar[0][c] || SQR(bstemp[1]) > caAutostrength * blockvar[1][c]) {
continue; continue;
} }
@ -729,7 +767,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
}//dir }//dir
}//c }//c
}//blocks }//blocks
}
numblox[1] = min(numblox[0], numblox[1]); numblox[1] = min(numblox[0], numblox[1]);
//if too few data points, restrict the order of the fit to linear //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; numpar = 4;
if (numblox[1] < 10) { if (numblox[1] < 10) {
std::cout << "numblox = " << numblox[1] << std::endl;
printf ("numblox = %d \n", numblox[1]);
processpasstwo = false; processpasstwo = false;
} }
} }
if(processpasstwo) if (processpasstwo) {
//fit parameters to blockshifts //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++) { for (int dir = 0; dir < 2; dir++) {
if (!LinEqSolve(numpar, polymat[c][dir], shiftmat[c][dir], fitparams[c][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; processpasstwo = false;
} }
} }
} }
}
}
//fitparams[polyord*i+j] gives the coefficients of (vblock^i hblock^j) in a polynomial fit for i,j<=4 //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 //end of initialization for CA correction pass
@ -763,13 +800,12 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
} }
// Main algorithm: Tile loop // Main algorithm: Tile loop
if(processpasstwo) { if (processpasstwo) {
float *grbdiff = (float (*)) (data + 2 * sizeof(float) * ts * ts + 3 * 64); // there is no overlap in buffer usage => share 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 //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 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 #pragma omp for schedule(dynamic) collapse(2)
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) { for (int left = -border; left < width - (W & 1); left += ts - border2) {
memset(bufferThr, 0, buffersizePassTwo); memset(bufferThr, 0, buffersizePassTwo);
float lblockshifts[2][2]; float lblockshifts[2][2];
@ -801,7 +837,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
int indx1 = rr * ts + cc; int indx1 = rr * ts + cc;
#ifdef __SSE2__ #ifdef __SSE2__
int c = FC(rr, cc); int c = FC(rr, cc);
if(c & 1) { if (c & 1) {
rgb[1][indx1] = rawData[row][col] / 65535.f; rgb[1][indx1] = rawData[row][col] / 65535.f;
indx++; indx++;
indx1++; indx1++;
@ -827,19 +863,20 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
} }
} }
} }
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//fill borders //fill borders
if (rrmin > 0) { if (rrmin > 0) {
for (int rr = 0; rr < border; rr++) for (int rr = 0; rr < border; rr++) {
for (int cc = ccmin; cc < ccmax; cc++) { for (int cc = ccmin; cc < ccmax; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][((border2 - rr) * ts + cc) >> ((c & 1) ^ 1)]; 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]; rgb[1][rr * ts + cc] = rgb[1][(border2 - rr) * ts + cc];
} }
} }
}
if (rrmax < rr1) { 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++) { for (int cc = ccmin; cc < ccmax; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = (rawData[(height - rr - 2)][left + cc]) / 65535.f; 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) { if (ccmin > 0) {
for (int rr = rrmin; rr < rrmax; rr++) for (int rr = rrmin; rr < rrmax; rr++) {
for (int cc = 0; cc < border; cc++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = rgb[c][(rr * ts + border2 - cc) >> ((c & 1) ^ 1)]; 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]; rgb[1][rr * ts + cc] = rgb[1][rr * ts + border2 - cc];
} }
} }
}
if (ccmax < cc1) { 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++) { for (int cc = 0; cc < std::min(border, cc1 - ccmax); cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = (rawData[(top + rr)][(width - cc - 2)]) / 65535.f; 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 //also, fill the image corners
if (rrmin > 0 && ccmin > 0) { 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++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + cc) >> ((c & 1) ^ 1)] = (rawData[border2 - rr][border2 - cc]) / 65535.f; 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) { 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++) { for (int cc = 0; cc < std::min(border, cc1 - ccmax); cc++) {
int c = FC(rr, 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; 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) { 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++) { for (int cc = 0; cc < std::min(border, cc1 - ccmax); cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][(rr * ts + ccmax + cc) >> ((c & 1) ^ 1)] = (rawData[(border2 - rr)][(width - cc - 2)]) / 65535.f; 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) { 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++) { for (int cc = 0; cc < border; cc++) {
int c = FC(rr, cc); int c = FC(rr, cc);
rgb[c][((rrmax + rr)*ts + cc) >> ((c & 1) ^ 1)] = (rawData[(height - rr - 2)][(border2 - cc)]) / 65535.f; 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 //end of border fill
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (!autoCA || fitParamsIn) { if (!autoCA || fitParamsIn) {
#ifdef __SSE2__ #ifdef __SSE2__
const vfloat onev = F2V(1.f); const vfloat onev = F2V(1.f);
const vfloat epsv = F2V(eps); const vfloat epsv = F2V(eps);
#endif #endif
//manual CA correction; use red/blue slider values to set CA shift parameters //manual CA correction; use red/blue slider values to set CA shift parameters
for (int rr = 3; rr < rr1 - 3; rr++) { for (int rr = 3; rr < rr1 - 3; rr++) {
int cc = 3 + FC(rr, 1), c = FC(rr,cc), indx = rr * ts + cc; 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) { if (!autoCA) {
float hfrac = -((float)(hblock - 0.5) / (hblsz - 2) - 0.5); float hfrac = -((float)(hblock - 0.5) / (hblsz - 2) - 0.5);
float vfrac = -((float)(vblock - 0.5) / (vblsz - 2) - 0.5) * height / width; 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); lblockshifts[1][1] = LIM(lblockshifts[1][1], -bslim, bslim);
}//end of setting CA shift parameters }//end of setting CA shift parameters
for (int c = 0; c < 3; c += 2) { for (int c = 0; c < 3; c += 2) {
//some parameters for the bilinear interpolation //some parameters for the bilinear interpolation
shiftvfloor[c] = floor((float)lblockshifts[c>>1][0]); shiftvfloor[c] = floor((float)lblockshifts[c>>1][0]);
shiftvceil[c] = ceil((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]); shifthfloor[c] = floor((float)lblockshifts[c>>1][1]);
shifthceil[c] = ceil((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[0][c] = lblockshifts[c>>1][0] > 0 ? 2 : -2;
GRBdir[1][c] = lblockshifts[c>>1][1] > 0 ? 2 : -2; GRBdir[1][c] = lblockshifts[c>>1][1] > 0 ? 2 : -2;
} }
for (int rr = 4; rr < rr1 - 4; rr++) { for (int rr = 4; rr < rr1 - 4; rr++) {
int cc = 4 + (FC(rr, 2) & 1); int cc = 4 + (FC(rr, 2) & 1);
int c = FC(rr, cc); int c = FC(rr, cc);
@ -1070,7 +1115,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
vfloat rinv = LC2VFU(rgb[1][indx]); vfloat rinv = LC2VFU(rgb[1][indx]);
vfloat RBint = rinv - grbdiffint; vfloat RBint = rinv - grbdiffint;
vmask cmask = vmaskf_ge(vabsf(RBint - cinv), zd25v * (RBint + cinv)); vmask cmask = vmaskf_ge(vabsf(RBint - cinv), zd25v * (RBint + cinv));
if(_mm_movemask_ps((vfloat)cmask)) { if (_mm_movemask_ps((vfloat)cmask)) {
// if for any of the 4 pixels the condition is true, do the math for all 4 pixels and mask the unused out at the end // if for any of the 4 pixels the condition is true, do the math for all 4 pixels and mask the unused out at the end
//gradient weights using difference from G at CA shift points and G at grid points //gradient weights using difference from G at CA shift points and G at grid points
vfloat p0 = onev / (epsv + vabsf(rinv - LVFU(gshift[indx >> 1]))); vfloat p0 = onev / (epsv + vabsf(rinv - LVFU(gshift[indx >> 1])));
@ -1102,7 +1147,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
float RBint = rgb[1][indx] - grbdiffint; float RBint = rgb[1][indx] - grbdiffint;
if (fabsf(RBint - rgb[c][indx >> 1]) < 0.25f * (RBint + rgb[c][indx >> 1])) { if (fabsf(RBint - rgb[c][indx >> 1]) < 0.25f * (RBint + rgb[c][indx >> 1])) {
if (fabsf(grbdiffold) > fabsf(grbdiffint) ) { if (fabsf(grbdiffold) > fabsf(grbdiffint)) {
rgb[c][indx >> 1] = RBint; rgb[c][indx >> 1] = RBint;
} }
} else { } else {
@ -1117,7 +1162,7 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
p2 * grbdiff[((rr - GRBdir0) * ts + cc) >> 1] + p3 * grbdiff[((rr - GRBdir0) * ts + cc - GRBdir1) >> 1]) / (p0 + p1 + p2 + p3) ; p2 * grbdiff[((rr - GRBdir0) * ts + cc) >> 1] + p3 * grbdiff[((rr - GRBdir0) * ts + cc - GRBdir1) >> 1]) / (p0 + p1 + p2 + p3) ;
//now determine R/B at grid points using interpolated colour differences and interpolated G value at grid point //now determine R/B at grid points using interpolated colour differences and interpolated G value at grid point
if (fabsf(grbdiffold) > fabsf(grbdiffint) ) { if (fabsf(grbdiffold) > fabsf(grbdiffint)) {
rgb[c][indx >> 1] = rgb[1][indx] - grbdiffint; rgb[c][indx >> 1] = rgb[1][indx] - grbdiffint;
} }
} }
@ -1146,65 +1191,139 @@ float* RawImageSource::CA_correct_RT(const bool autoCA, const double cared, cons
} }
} }
if(plistener) { if (plistener) {
progresscounter++; progresscounter++;
if(progresscounter % 8 == 0) if (progresscounter % 8 == 0)
#pragma omp critical (cacorrect) #pragma omp critical (cacorrect)
{ {
progress += (double)(8.0 * (ts - border2) * (ts - border2)) / (2 * height * width); progress += 4.0 * SQR(ts - border2) / (iterations * height * width);
progress = std::min(progress, 1.0);
if (progress > 1.0) {
progress = 1.0;
}
plistener->setProgress(progress); plistener->setProgress(progress);
} }
} }
}
} }
#pragma omp barrier // copy temporary image matrix back to image matrix
// copy temporary image matrix back to image matrix
#pragma omp for #pragma omp for
for(int row = 0; row < height; row++) { for (int row = 0; row < height; row++) {
int col = FC(row, 0) & 1; int col = FC(row, 0) & 1;
int indx = (row * width + col) >> 1; int indx = (row * width + col) >> 1;
#ifdef __SSE2__ #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])); STC2VFU(rawData[row][col], LVFU(RawDataTmp[indx]));
} }
#endif #endif
for(; col < width - (W & 1); col += 2, indx++) { for (; col < width - (3 * (W & 1)); col += 2, indx++) {
rawData[row][col] = RawDataTmp[indx]; rawData[row][col] = RawDataTmp[indx];
} }
} }
} }
// clean up // clean up
free(bufferThr); 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
if(autoCA && fitParamsTransfer && fitParamsOut) { #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 // store calculated parameters
int index = 0; int index = 0;
for(int c = 0; c < 2; ++c) { for (int c = 0; c < 2; ++c) {
for(int d = 0; d < 2; ++d) { for (int d = 0; d < 2; ++d) {
for(int e = 0; e < 16; ++e) { for (int e = 0; e < 16; ++e) {
fitParamsTransfer[index++] = fitparams[c][d][e]; fitParamsTransfer[index++] = fitparams[c][d][e];
} }
} }
} }
} }
if(freeBuffer) { if (freeBuffer) {
free(buffer); free(buffer);
buffer = nullptr; buffer = nullptr;
} }
if(plistener) { if (avoidColourshift) {
delete oldraw;
delete redFactor;
delete blueFactor;
}
if (plistener) {
plistener->setProgress(1.0); plistener->setProgress(1.0);
} }
return buffer; return buffer;

View File

@ -2561,6 +2561,8 @@ RAWParams::RAWParams() :
ff_AutoClipControl(false), ff_AutoClipControl(false),
ff_clipControl(0), ff_clipControl(0),
ca_autocorrect(false), ca_autocorrect(false),
ca_avoidcolourshift(true),
caautoiterations(2),
cared(0.0), cared(0.0),
cablue(0.0), cablue(0.0),
expos(1.0), expos(1.0),
@ -2585,6 +2587,8 @@ bool RAWParams::operator ==(const RAWParams& other) const
&& ff_AutoClipControl == other.ff_AutoClipControl && ff_AutoClipControl == other.ff_AutoClipControl
&& ff_clipControl == other.ff_clipControl && ff_clipControl == other.ff_clipControl
&& ca_autocorrect == other.ca_autocorrect && ca_autocorrect == other.ca_autocorrect
&& ca_avoidcolourshift == other.ca_avoidcolourshift
&& caautoiterations == other.caautoiterations
&& cared == other.cared && cared == other.cared
&& cablue == other.cablue && cablue == other.cablue
&& expos == other.expos && 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_AutoClipControl, "RAW", "FlatFieldAutoClipControl", raw.ff_AutoClipControl, keyFile);
saveToKeyfile(!pedited || pedited->raw.ff_clipControl, "RAW", "FlatFieldClipControl", raw.ff_clipControl, 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_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.cared, "RAW", "CARed", raw.cared, keyFile);
saveToKeyfile(!pedited || pedited->raw.cablue, "RAW", "CABlue", raw.cablue, keyFile); saveToKeyfile(!pedited || pedited->raw.cablue, "RAW", "CABlue", raw.cablue, keyFile);
saveToKeyfile(!pedited || pedited->raw.hotPixelFilter, "RAW", "HotPixelFilter", raw.hotPixelFilter, 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); 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", "CARed", pedited, raw.cared, pedited->raw.cared);
assignFromKeyfile(keyFile, "RAW", "CABlue", pedited, raw.cablue, pedited->raw.cablue); assignFromKeyfile(keyFile, "RAW", "CABlue", pedited, raw.cablue, pedited->raw.cablue);
// For compatibility to elder pp3 versions // For compatibility to elder pp3 versions

View File

@ -1368,6 +1368,8 @@ struct RAWParams {
int ff_clipControl; int ff_clipControl;
bool ca_autocorrect; bool ca_autocorrect;
bool ca_avoidcolourshift;
int caautoiterations;
double cared; double cared;
double cablue; double cablue;

View File

@ -2009,13 +2009,13 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le
} }
if(numFrames == 4) { if(numFrames == 4) {
double fitParams[64]; 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) { 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 { } 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);
} }
} }

View File

@ -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 (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); 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 ddct8x8s(int isgn, float a[8][8]);
void processRawWhitepoint (float expos, float preser, array2D<float> &rawData); // exposure before interpolation void processRawWhitepoint (float expos, float preser, array2D<float> &rawData); // exposure before interpolation

View File

@ -431,6 +431,8 @@ void ParamsEdited::set(bool v)
raw.xtranssensor.exBlackGreen = v; raw.xtranssensor.exBlackGreen = v;
raw.xtranssensor.exBlackBlue = v; raw.xtranssensor.exBlackBlue = v;
raw.ca_autocorrect = v; raw.ca_autocorrect = v;
raw.ca_avoidcolourshift = v;
raw.caautoiterations = v;
raw.cablue = v; raw.cablue = v;
raw.cared = v; raw.cared = v;
raw.hotPixelFilter = 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.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.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_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.cared = raw.cared && p.raw.cared == other.raw.cared;
raw.cablue = raw.cablue && p.raw.cablue == other.raw.cablue; raw.cablue = raw.cablue && p.raw.cablue == other.raw.cablue;
raw.hotPixelFilter = raw.hotPixelFilter && p.raw.hotPixelFilter == other.raw.hotPixelFilter; 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; 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) { if (raw.cared) {
toEdit.raw.cared = dontforceSet && options.baBehav[ADDSET_RAWCACORR] ? toEdit.raw.cared + mods.raw.cared : mods.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 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; && df_autoselect && ff_file && ff_AutoSelect && ff_BlurRadius && ff_BlurType && exPos && exPreser && ff_AutoClipControl && ff_clipControl;
} }

View File

@ -787,6 +787,8 @@ public:
XTransSensor xtranssensor; XTransSensor xtranssensor;
bool ca_autocorrect; bool ca_autocorrect;
bool ca_avoidcolourshift;
bool caautoiterations;
bool cared; bool cared;
bool cablue; bool cablue;
bool hotPixelFilter; bool hotPixelFilter;

View File

@ -901,6 +901,7 @@ void PartialPasteDlg::applyPaste (rtengine::procparams::ProcParams* dstPP, Param
if (!raw_ca_autocorrect->get_active ()) { if (!raw_ca_autocorrect->get_active ()) {
filterPE.raw.ca_autocorrect = falsePE.raw.ca_autocorrect; filterPE.raw.ca_autocorrect = falsePE.raw.ca_autocorrect;
filterPE.raw.caautoiterations = falsePE.raw.caautoiterations;
} }
if (!raw_caredblue->get_active ()) { if (!raw_caredblue->get_active ()) {

View File

@ -1,11 +1,15 @@
#pragma once #pragma once
// This number has to be incremented whenever the PP3 file format is modified or the behaviour of a tool changes // 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 #define PPVERSION_AEXP 301 //value of PPVERSION when auto exposure algorithm was modified
/* /*
Log of version changes 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 341 2018-07-22
[ICM] enhanced custom output profile [ICM] enhanced custom output profile
340 2018-07-08 340 2018-07-08

View File

@ -17,6 +17,7 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "rawcacorrection.h" #include "rawcacorrection.h"
#include "eventmapper.h"
#include "guiutils.h" #include "guiutils.h"
#include "rtimage.h" #include "rtimage.h"
@ -25,6 +26,11 @@ using namespace rtengine::procparams;
RAWCACorr::RAWCACorr () : FoldableToolPanel(this, "rawcacorrection", M("TP_CHROMATABERR_LABEL")) 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* icaredL = Gtk::manage (new RTImage ("circle-red-cyan-small.png"));
Gtk::Image* icaredR = Gtk::manage (new RTImage ("circle-cyan-red-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")); 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 = Gtk::manage (new CheckBox(M("TP_RAWCACORR_AUTO"), multiImage));
caAutocorrect->setCheckBoxListener (this); 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 = Gtk::manage(new Adjuster (M("TP_RAWCACORR_CARED"), -8.0, 8.0, 0.1, 0, icaredL, icaredR));
caRed->setAdjusterListener (this); caRed->setAdjusterListener (this);
@ -51,9 +64,15 @@ RAWCACorr::RAWCACorr () : FoldableToolPanel(this, "rawcacorrection", M("TP_CHROM
caBlue->show(); caBlue->show();
pack_start( *caAutocorrect, Gtk::PACK_SHRINK, 4); pack_start( *caAutocorrect, Gtk::PACK_SHRINK, 4);
pack_start( *caAutoiterations, Gtk::PACK_SHRINK, 4);
pack_start( *caRed, Gtk::PACK_SHRINK, 4); pack_start( *caRed, Gtk::PACK_SHRINK, 4);
pack_start( *caBlue, 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) 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 ) { if(pedited ) {
caAutocorrect->setEdited(pedited->raw.ca_autocorrect); 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 ); caRed->setEditedState( pedited->raw.cared ? Edited : UnEdited );
caBlue->setEditedState( pedited->raw.cablue ? Edited : UnEdited ); caBlue->setEditedState( pedited->raw.cablue ? Edited : UnEdited );
} }
// disable Red and Blue sliders when caAutocorrect is enabled // disable Red and Blue sliders when caAutocorrect is enabled
caAutoiterations->set_sensitive(pp->raw.ca_autocorrect);
caRed->set_sensitive(!pp->raw.ca_autocorrect); caRed->set_sensitive(!pp->raw.ca_autocorrect);
caBlue->set_sensitive(!pp->raw.ca_autocorrect); caBlue->set_sensitive(!pp->raw.ca_autocorrect);
caAutocorrect->setValue(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); caRed->setValue (pp->raw.cared);
caBlue->setValue (pp->raw.cablue); 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) void RAWCACorr::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited)
{ {
pp->raw.ca_autocorrect = caAutocorrect->getLastActive(); pp->raw.ca_autocorrect = caAutocorrect->getLastActive();
// pp->raw.ca_avoidcolourshift = caAvoidcolourshift->getLastActive();
pp->raw.caautoiterations = caAutoiterations->getValue();
pp->raw.cared = caRed->getValue(); pp->raw.cared = caRed->getValue();
pp->raw.cablue = caBlue->getValue(); pp->raw.cablue = caBlue->getValue();
if (pedited) { if (pedited) {
pedited->raw.ca_autocorrect = !caAutocorrect->get_inconsistent(); 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.cared = caRed->getEditedState ();
pedited->raw.cablue = caBlue->getEditedState (); pedited->raw.cablue = caBlue->getEditedState ();
} }
@ -97,7 +125,9 @@ void RAWCACorr::adjusterChanged (Adjuster* a, double newval)
Glib::ustring value = a->getTextValue(); Glib::ustring value = a->getTextValue();
if (a == caRed) { if (a == caAutoiterations) {
listener->panelChanged (EvPreProcessCAAutoiterations, value );
} else if (a == caRed) {
listener->panelChanged (EvPreProcessCARed, value ); listener->panelChanged (EvPreProcessCARed, value );
} else if (a == caBlue) { } else if (a == caBlue) {
listener->panelChanged (EvPreProcessCABlue, value ); listener->panelChanged (EvPreProcessCABlue, value );
@ -110,6 +140,7 @@ void RAWCACorr::checkBoxToggled (CheckBox* c, CheckValue newval)
if (c == caAutocorrect) { if (c == caAutocorrect) {
if (!batchMode) { if (!batchMode) {
// disable Red and Blue sliders when caAutocorrect is enabled // disable Red and Blue sliders when caAutocorrect is enabled
caAutoiterations->set_sensitive(caAutocorrect->getLastActive ());
caRed->set_sensitive(!caAutocorrect->getLastActive ()); caRed->set_sensitive(!caAutocorrect->getLastActive ());
caBlue->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")); 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) void RAWCACorr::setBatchMode(bool batchMode)
{ {
ToolPanel::setBatchMode (batchMode); ToolPanel::setBatchMode (batchMode);
caAutoiterations->showEditedCB ();
caRed->showEditedCB (); caRed->showEditedCB ();
caBlue->showEditedCB (); caBlue->showEditedCB ();
} }
void RAWCACorr::setDefaults(const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited) void RAWCACorr::setDefaults(const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited)
{ {
caAutoiterations->setDefault( defParams->raw.caautoiterations);
caRed->setDefault( defParams->raw.cared); caRed->setDefault( defParams->raw.cared);
caBlue->setDefault( defParams->raw.cablue); caBlue->setDefault( defParams->raw.cablue);
if (pedited) { if (pedited) {
caAutoiterations->setDefaultEditedState( pedited->raw.caautoiterations ? Edited : UnEdited);
caRed->setDefaultEditedState( pedited->raw.cared ? Edited : UnEdited); caRed->setDefaultEditedState( pedited->raw.cared ? Edited : UnEdited);
caBlue->setDefaultEditedState( pedited->raw.cablue ? Edited : UnEdited); caBlue->setDefaultEditedState( pedited->raw.cablue ? Edited : UnEdited);
} else { } else {
caAutoiterations->setDefaultEditedState( Irrelevant );
caRed->setDefaultEditedState( Irrelevant ); caRed->setDefaultEditedState( Irrelevant );
caBlue->setDefaultEditedState( Irrelevant ); caBlue->setDefaultEditedState( Irrelevant );
} }
@ -150,6 +190,7 @@ void RAWCACorr::setAdjusterBehavior (bool caadd)
void RAWCACorr::trimValues (rtengine::procparams::ProcParams* pp) void RAWCACorr::trimValues (rtengine::procparams::ProcParams* pp)
{ {
caAutoiterations->trimValue(pp->raw.caautoiterations);
caRed->trimValue(pp->raw.cared); caRed->trimValue(pp->raw.cared);
caBlue->trimValue(pp->raw.cablue); caBlue->trimValue(pp->raw.cablue);
} }

View File

@ -29,8 +29,14 @@ class RAWCACorr : public ToolParamBlock, public AdjusterListener, public CheckBo
protected: protected:
CheckBox* caAutocorrect; CheckBox* caAutocorrect;
Adjuster* caAutoiterations;
Adjuster* caRed; Adjuster* caRed;
Adjuster* caBlue; Adjuster* caBlue;
// CheckBox* caAvoidcolourshift;
rtengine::ProcEvent EvPreProcessCAAutoiterations;
// rtengine::ProcEvent EvPreProcessCAColourshift;
// rtengine::ProcEvent EvPreProcessCAColourshiftHistory;
public: public: