Merge pull request #4826 from Beep6581/rawhistogram_fixes
Don't use gamma for calculation of raw histogram values, #4667
This commit is contained in:
@@ -4720,10 +4720,14 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU
|
||||
histRedRaw.clear();
|
||||
histGreenRaw.clear();
|
||||
histBlueRaw.clear();
|
||||
const float mult[4] = { 255.0f / Color::gamma(ri->get_white(0) - cblacksom[0]),
|
||||
255.0f / Color::gamma(ri->get_white(1) - cblacksom[1]),
|
||||
255.0f / Color::gamma(ri->get_white(2) - cblacksom[2]),
|
||||
255.0f / Color::gamma(ri->get_white(3) - cblacksom[3])
|
||||
|
||||
const float maxWhite = rtengine::max(ri->get_white(0), ri->get_white(1), ri->get_white(2), ri->get_white(3));
|
||||
const float scale = maxWhite <= 1.f ? 65535.f : 1.f; // special case for float raw images in [0.0;1.0] range
|
||||
const float multScale = maxWhite <= 1.f ? 1.f / 255.f : 255.f;
|
||||
const float mult[4] = { multScale / (ri->get_white(0) - cblacksom[0]),
|
||||
multScale / (ri->get_white(1) - cblacksom[1]),
|
||||
multScale / (ri->get_white(2) - cblacksom[2]),
|
||||
multScale / (ri->get_white(3) - cblacksom[3])
|
||||
};
|
||||
|
||||
const bool fourColours = ri->getSensorType() == ST_BAYER && ((mult[1] != mult[3] || cblacksom[1] != cblacksom[3]) || FC(0, 0) == 3 || FC(0, 1) == 3 || FC(1, 0) == 3 || FC(1, 1) == 3);
|
||||
@@ -4787,26 +4791,26 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU
|
||||
c2 = ( fourColours && c2 == 1 && !(i & 1) ) ? 3 : c2;
|
||||
|
||||
for (j = start; j < end - 1; j += 2) {
|
||||
tmphist[c1][(int)ri->data[i][j]]++;
|
||||
tmphist[c2][(int)ri->data[i][j + 1]]++;
|
||||
tmphist[c1][(int)(ri->data[i][j] * scale)]++;
|
||||
tmphist[c2][(int)(ri->data[i][j + 1] * scale)]++;
|
||||
}
|
||||
|
||||
if(j < end) { // last pixel of row if width is odd
|
||||
tmphist[c1][(int)ri->data[i][j]]++;
|
||||
tmphist[c1][(int)(ri->data[i][j] * scale)]++;
|
||||
}
|
||||
} else if (ri->get_colors() == 1) {
|
||||
for (int j = start; j < end; j++) {
|
||||
tmphist[0][(int)ri->data[i][j]]++;
|
||||
tmphist[0][(int)(ri->data[i][j] * scale)]++;
|
||||
}
|
||||
} else if(ri->getSensorType() == ST_FUJI_XTRANS) {
|
||||
for (int j = start; j < end - 1; j += 2) {
|
||||
int c = ri->XTRANSFC(i, j);
|
||||
tmphist[c][(int)ri->data[i][j]]++;
|
||||
tmphist[c][(int)(ri->data[i][j] * scale)]++;
|
||||
}
|
||||
} else {
|
||||
for (int j = start; j < end; j++) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
tmphist[c][(int)ri->data[i][3 * j + c]]++;
|
||||
tmphist[c][(int)(ri->data[i][3 * j + c] * scale)]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4829,21 +4833,20 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU
|
||||
} // end of critical region
|
||||
} // end of parallel region
|
||||
|
||||
for(int i = 0; i < 65536; i++) {
|
||||
int idx;
|
||||
idx = (int)std::min(255.0f, mult[0] * Color::gamma(std::max(0.0f, i - cblacksom[0])));
|
||||
for(int i = 0; i < histoSize; i++) {
|
||||
int idx = std::min(255.f, mult[0] * std::max(0.f, i - cblacksom[0]));
|
||||
histRedRaw[idx] += hist[0][i];
|
||||
|
||||
if (ri->get_colors() > 1) {
|
||||
idx = (int)std::min(255.0f, mult[1] * Color::gamma(std::max(0.0f, i - cblacksom[1])));
|
||||
idx = std::min(255.f, mult[1] * std::max(0.f, i - cblacksom[1]));
|
||||
histGreenRaw[idx] += hist[1][i];
|
||||
|
||||
if (fourColours) {
|
||||
idx = (int)std::min(255.0f, mult[3] * Color::gamma(std::max(0.0f, i - cblacksom[3])));
|
||||
idx = std::min(255.f, mult[3] * std::max(0.f, i - cblacksom[3]));
|
||||
histGreenRaw[idx] += hist[3][i];
|
||||
}
|
||||
|
||||
idx = (int)std::min(255.0f, mult[2] * Color::gamma(std::max(0.0f, i - cblacksom[2])));
|
||||
idx = std::min(255.f, mult[2] * std::max(0.f, i - cblacksom[2]));
|
||||
histBlueRaw[idx] += hist[2][i];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user