Some cleanups, also fix some fallouts from reduce_include_dependencies branch

This commit is contained in:
Ingo Weyrich
2019-11-05 20:31:17 +01:00
parent d3e7f6a591
commit 03c0d6c86c
16 changed files with 175 additions and 410 deletions

View File

@@ -30,6 +30,13 @@
using namespace std;
using namespace rtengine;
namespace
{
unsigned fc(const unsigned int cfa[2][2], int r, int c) {
return cfa[r & 1][c & 1];
}
}
#define TS 224
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -66,6 +73,7 @@ void RawImageSource::fast_demosaic()
}
const unsigned int cfarray[2][2] = {{FC(0,0), FC(0,1)}, {FC(1,0), FC(1,1)}};
const int bord = 5;
float clip_pt = 4 * 65535 * initialGain;
@@ -116,12 +124,12 @@ void RawImageSource::fast_demosaic()
for (int i1 = imin; i1 < imax; i1++)
for (int j1 = jmin; j1 < j + 2; j1++) {
int c = FC(i1, j1);
int c = fc(cfarray, i1, j1);
sum[c] += rawData[i1][j1];
sum[c + 3]++;
}
int c = FC(i, j);
int c = fc(cfarray, i, j);
if (c == 1) {
red[i][j] = sum[0] / sum[3];
@@ -149,12 +157,12 @@ void RawImageSource::fast_demosaic()
for (int i1 = imin; i1 < imax; i1++)
for (int j1 = j - 1; j1 < jmax; j1++) {
int c = FC(i1, j1);
int c = fc(cfarray, i1, j1);
sum[c] += rawData[i1][j1];
sum[c + 3]++;
}
int c = FC(i, j);
int c = fc(cfarray, i, j);
if (c == 1) {
red[i][j] = sum[0] / sum[3];
@@ -192,12 +200,12 @@ void RawImageSource::fast_demosaic()
for (int i1 = max(0, i - 1); i1 < i + 2; i1++)
for (int j1 = j - 1; j1 < j + 2; j1++) {
int c = FC(i1, j1);
int c = fc(cfarray, i1, j1);
sum[c] += rawData[i1][j1];
sum[c + 3]++;
}
int c = FC(i, j);
int c = fc(cfarray, i, j);
if (c == 1) {
red[i][j] = sum[0] / sum[3];
@@ -223,12 +231,12 @@ void RawImageSource::fast_demosaic()
for (int i1 = i - 1; i1 < min(i + 2, H); i1++)
for (int j1 = j - 1; j1 < j + 2; j1++) {
int c = FC(i1, j1);
int c = fc(cfarray, i1, j1);
sum[c] += rawData[i1][j1];
sum[c + 3]++;
}
int c = FC(i, j);
int c = fc(cfarray, i, j);
if (c == 1) {
red[i][j] = sum[0] / sum[3];
@@ -281,7 +289,7 @@ void RawImageSource::fast_demosaic()
vmask selmask;
vmask andmask = _mm_set_epi32( 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff );
if(FC(top, left) == 1) {
if(fc(cfarray, top, left) == 1) {
selmask = _mm_set_epi32( 0, 0xffffffff, 0, 0xffffffff );
} else {
selmask = _mm_set_epi32( 0xffffffff, 0, 0xffffffff, 0 );
@@ -311,7 +319,7 @@ void RawImageSource::fast_demosaic()
for (; j < right; j++, cc++) {
if (FC(i, j) == 1) {
if (fc(cfarray, i, j) == 1) {
greentile[rr * TS + cc] = rawData[i][j];
} else {
@@ -332,7 +340,7 @@ void RawImageSource::fast_demosaic()
#else
for (int j = left, cc = 0; j < right; j++, cc++) {
if (FC(i, j) == 1) {
if (fc(cfarray, i, j) == 1) {
greentile[rr * TS + cc] = rawData[i][j];
} else {
//compute directional weights using image gradients
@@ -358,7 +366,7 @@ void RawImageSource::fast_demosaic()
#endif
for (int i = top + 1, rr = 1; i < bottom - 1; i++, rr++) {
if (FC(i, left + (FC(i, 2) & 1) + 1) == 0)
if (fc(cfarray, i, left + (fc(cfarray, i, 2) & 1) + 1) == 0)
#ifdef __SSE2__
for (int j = left + 1, cc = 1; j < right - 1; j += 4, cc += 4) {
//interpolate B/R colors at R/B sites
@@ -368,7 +376,7 @@ void RawImageSource::fast_demosaic()
#else
for (int cc = (FC(i, 2) & 1) + 1, j = left + cc; j < right - 1; j += 2, cc += 2) {
for (int cc = (fc(cfarray, i, 2) & 1) + 1, j = left + cc; j < right - 1; j += 2, cc += 2) {
//interpolate B/R colors at R/B sites
bluetile[rr * TS + cc] = greentile[rr * TS + cc] - 0.25f * ((greentile[(rr - 1) * TS + (cc - 1)] + greentile[(rr - 1) * TS + (cc + 1)] + greentile[(rr + 1) * TS + cc + 1] + greentile[(rr + 1) * TS + cc - 1]) -
min(clip_pt, rawData[i - 1][j - 1] + rawData[i - 1][j + 1] + rawData[i + 1][j + 1] + rawData[i + 1][j - 1]));
@@ -385,7 +393,7 @@ void RawImageSource::fast_demosaic()
#else
for (int cc = (FC(i, 2) & 1) + 1, j = left + cc; j < right - 1; j += 2, cc += 2) {
for (int cc = (fc(cfarray, i, 2) & 1) + 1, j = left + cc; j < right - 1; j += 2, cc += 2) {
//interpolate B/R colors at R/B sites
redtile[rr * TS + cc] = greentile[rr * TS + cc] - 0.25f * ((greentile[(rr - 1) * TS + cc - 1] + greentile[(rr - 1) * TS + cc + 1] + greentile[(rr + 1) * TS + cc + 1] + greentile[(rr + 1) * TS + cc - 1]) -
min(clip_pt, rawData[i - 1][j - 1] + rawData[i - 1][j + 1] + rawData[i + 1][j + 1] + rawData[i + 1][j - 1]));
@@ -404,7 +412,7 @@ void RawImageSource::fast_demosaic()
for (int i = top + 2, rr = 2; i < bottom - 2; i++, rr++) {
#ifdef __SSE2__
for (int cc = 2 + (FC(i, 2) & 1), j = left + cc; j < right - 2; j += 4, cc += 4) {
for (int cc = 2 + (fc(cfarray, i, 2) & 1), j = left + cc; j < right - 2; j += 4, cc += 4) {
// no need to take care about the borders of the tile. There's enough free space.
//interpolate R and B colors at G sites
greenv = LVFU(greentile[rr * TS + cc]);
@@ -428,7 +436,7 @@ void RawImageSource::fast_demosaic()
#else
for (int cc = 2 + (FC(i, 2) & 1), j = left + cc; j < right - 2; j += 2, cc += 2) {
for (int cc = 2 + (fc(cfarray, i, 2) & 1), j = left + cc; j < right - 2; j += 2, cc += 2) {
//interpolate R and B colors at G sites
redtile[rr * TS + cc] = greentile[rr * TS + cc] - 0.25f * ((greentile[(rr - 1) * TS + cc] - redtile[(rr - 1) * TS + cc]) + (greentile[(rr + 1) * TS + cc] - redtile[(rr + 1) * TS + cc]) +
(greentile[rr * TS + cc - 1] - redtile[rr * TS + cc - 1]) + (greentile[rr * TS + cc + 1] - redtile[rr * TS + cc + 1]));