diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 6d9d6fd6c..ab2ee58e6 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -59,6 +59,16 @@ namespace { +float clipitc(float x) +{ + if (std::isnan(x)) { + x = 0.1f; + } else { + x = rtengine::LIM(x, 0.1f, 65534.9f);//White balance Itcwb - limit values + } + return x; +} + void rotateLine(const float* const line, rtengine::PlanarPtr &channel, const int tran, const int i, const int w, const int h) { switch (tran & TR_ROT) { @@ -6221,12 +6231,20 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } if (oldsampling == false) { + if (settings->verbose) { + printf("size rgb loc - bfh=%i bfw=%i repref=%i\n", bfh, bfw, repref); + } + #ifdef _OPENMP #pragma omp parallel for #endif for (int y = 0; y < bfh ; ++y) { for (int x = 0; x < bfw ; ++x) { + redloc[y][x] = clipitc(redloc[y][x]); + greenloc[y][x] = clipitc(greenloc[y][x]); + blueloc[y][x] = clipitc(blueloc[y][x]); + const float RR = rmm[repref] * redloc[y][x]; const float GG = gmm[repref] * greenloc[y][x]; const float BB = bmm[repref] * blueloc[y][x]; @@ -7451,17 +7469,11 @@ void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int const int bfw = W / precision + ((W % precision) > 0 ? 1 : 0);// 5 arbitrary value can be change to 3 or 9 ; const int bfh = H / precision + ((H % precision) > 0 ? 1 : 0); - if (! greenloc) { - greenloc(bfw, bfh); - } + greenloc(bfw, bfh); - if (! redloc) { - redloc(bfw, bfh); - } + redloc(bfw, bfh); - if (! blueloc) { - blueloc(bfw, bfh); - } + blueloc(bfw, bfh); double avgL = 0.0; //center data on normal values @@ -7496,8 +7508,10 @@ void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int } const float sig = std::sqrt(vari / mm); - const float multip = 60000.f / (avgL + 2.f * sig); - //multip to put red, blue, green in a good range + float multip = 60000.f / (avgL + 2.f * sig); + if(std::isnan(multip)) {//if very bad datas with avgl and sig + multip = 1.f; + } #ifdef _OPENMP #pragma omp parallel for #endif @@ -7506,7 +7520,7 @@ void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int const int ii = i * precision; if (ii < H) { - for (int j = 0, jj = 0; j < bfw; ++j, jj += precision) { + for (int j = 0, jj = 0; j < bfw; ++j, jj += precision) {//isnan and <0 and > 65535 in case of redloc[i][j] = red[ii][jj] * multip; greenloc[i][j] = green[ii][jj] * multip; blueloc[i][j] = blue[ii][jj] * multip; @@ -7722,9 +7736,6 @@ void RawImageSource::getAutoWBMultipliersitc(bool extra, double & tempref, doubl WBauto(extra, tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, temp0, delta, bia, dread, kcam, nocam, studgood, minchrom, kmin, minhist, maxhist, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw, hrp); } - redloc(0, 0); - greenloc(0, 0); - blueloc(0, 0); if (settings->verbose && wbpar.method != "autitcgreen") { printf("RGB grey AVG: %g %g %g\n", avg_r / std::max(1, rn), avg_g / std::max(1, gn), avg_b / std::max(1, bn));