cppcheck clean rtengine/badpixels.cc

This commit is contained in:
Ingo Weyrich 2021-05-22 11:32:10 +02:00
parent 35064451d6
commit 9972c2e990

View File

@ -182,7 +182,7 @@ int RawImageSource::interpolateBadPixelsBayer(const PixelsMap &bitmapBads, array
/* interpolateBadPixelsNcolors: correct raw pixels looking at the bitmap /* interpolateBadPixelsNcolors: correct raw pixels looking at the bitmap
* takes into consideration if there are multiple bad pixels in the neighborhood * takes into consideration if there are multiple bad pixels in the neighborhood
*/ */
int RawImageSource::interpolateBadPixelsNColours(const PixelsMap &bitmapBads, const int colors) int RawImageSource::interpolateBadPixelsNColours(const PixelsMap &bitmapBads, const int colours)
{ {
constexpr float eps = 1.f; constexpr float eps = 1.f;
int counter = 0; int counter = 0;
@ -204,9 +204,9 @@ int RawImageSource::interpolateBadPixelsNColours(const PixelsMap &bitmapBads, co
continue; continue;
} }
float wtdsum[colors]; float wtdsum[colours];
float norm[colors]; float norm[colours];
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
wtdsum[c] = norm[c] = 0.f; wtdsum[c] = norm[c] = 0.f;
} }
@ -216,41 +216,41 @@ int RawImageSource::interpolateBadPixelsNColours(const PixelsMap &bitmapBads, co
continue; continue;
} }
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
const float dirwt = 0.70710678f / (fabsf(rawData[row - 1][(col + dx) * colors + c] - rawData[row + 1][(col - dx) * colors + c]) + eps); const float dirwt = 0.70710678f / (fabsf(rawData[row - 1][(col + dx) * colours + c] - rawData[row + 1][(col - dx) * colours + c]) + eps);
wtdsum[c] += dirwt * (rawData[row - 1][(col + dx) * colors + c] + rawData[row + 1][(col - dx) * colors + c]); wtdsum[c] += dirwt * (rawData[row - 1][(col + dx) * colours + c] + rawData[row + 1][(col - dx) * colours + c]);
norm[c] += dirwt; norm[c] += dirwt;
} }
} }
// horizontal interpolation // horizontal interpolation
if (!(bitmapBads.get(col - 1, row) || bitmapBads.get(col + 1, row))) { if (!(bitmapBads.get(col - 1, row) || bitmapBads.get(col + 1, row))) {
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
const float dirwt = 1.f / (fabsf(rawData[row][(col - 1) * colors + c] - rawData[row][(col + 1) * colors + c]) + eps); const float dirwt = 1.f / (fabsf(rawData[row][(col - 1) * colours + c] - rawData[row][(col + 1) * colours + c]) + eps);
wtdsum[c] += dirwt * (rawData[row][(col - 1) * colors + c] + rawData[row][(col + 1) * colors + c]); wtdsum[c] += dirwt * (rawData[row][(col - 1) * colours + c] + rawData[row][(col + 1) * colours + c]);
norm[c] += dirwt; norm[c] += dirwt;
} }
} }
// vertical interpolation // vertical interpolation
if (!(bitmapBads.get(col, row - 1) || bitmapBads.get(col, row + 1))) { if (!(bitmapBads.get(col, row - 1) || bitmapBads.get(col, row + 1))) {
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
const float dirwt = 1.f / (fabsf(rawData[row - 1][col * colors + c] - rawData[row + 1][col * colors + c]) + eps); const float dirwt = 1.f / (fabsf(rawData[row - 1][col * colours + c] - rawData[row + 1][col * colours + c]) + eps);
wtdsum[c] += dirwt * (rawData[row - 1][col * colors + c] + rawData[row + 1][col * colors + c]); wtdsum[c] += dirwt * (rawData[row - 1][col * colours + c] + rawData[row + 1][col * colours + c]);
norm[c] += dirwt; norm[c] += dirwt;
} }
} }
if (LIKELY(norm[0] > 0.f)) { // This means, we found at least one pair of valid pixels in the steps above, likelihood of this case is about 99.999% if (LIKELY(norm[0] > 0.f)) { // This means, we found at least one pair of valid pixels in the steps above, likelihood of this case is about 99.999%
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
rawData[row][col * colors + c] = wtdsum[c] / (2.f * norm[c]); //gradient weighted average, Factor of 2.f is an optimization to avoid multiplications in former steps rawData[row][col * colours + c] = wtdsum[c] / (2.f * norm[c]); //gradient weighted average, Factor of 2.f is an optimization to avoid multiplications in former steps
} }
counter++; counter++;
} else { //backup plan -- simple average. Same method for all channels. We could improve this, but it's really unlikely that this case happens } else { //backup plan -- simple average. Same method for all channels. We could improve this, but it's really unlikely that this case happens
int tot = 0; int tot = 0;
float sum[colors]; float sum[colours];
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
sum[c] = 0.f; sum[c] = 0.f;
} }
@ -260,8 +260,8 @@ int RawImageSource::interpolateBadPixelsNColours(const PixelsMap &bitmapBads, co
continue; continue;
} }
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
sum[c] += rawData[row + dy][(col + dx) * colors + c]; sum[c] += rawData[row + dy][(col + dx) * colours + c];
} }
tot++; tot++;
@ -269,8 +269,8 @@ int RawImageSource::interpolateBadPixelsNColours(const PixelsMap &bitmapBads, co
} }
if (tot > 0) { if (tot > 0) {
for (int c = 0; c < colors; ++c) { for (int c = 0; c < colours; ++c) {
rawData[row][col * colors + c] = sum[c] / tot; rawData[row][col * colours + c] = sum[c] / tot;
} }
counter ++; counter ++;