From f7792aa936143ff56f270fa22b4a934eed62392c Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Thu, 27 Feb 2020 21:22:34 +0100 Subject: [PATCH 01/13] some cleanups --- rtengine/imagesource.h | 3 +- rtengine/procparams.cc | 7 - rtengine/rawimagesource.cc | 836 ++++++++++++------------------------- rtengine/rawimagesource.h | 3 +- rtengine/simpleprocess.cc | 3 +- rtengine/stdimagesource.cc | 2 +- rtengine/stdimagesource.h | 2 +- 7 files changed, 282 insertions(+), 574 deletions(-) diff --git a/rtengine/imagesource.h b/rtengine/imagesource.h index f01d52059..22b8cdc08 100644 --- a/rtengine/imagesource.h +++ b/rtengine/imagesource.h @@ -98,8 +98,7 @@ public: virtual void retinex (const procparams::ColorManagementParams& cmp, const procparams::RetinexParams &deh, const procparams::ToneCurveParams& Tc, LUTf & cdcurve, LUTf & mapcurve, const RetinextransmissionCurve & dehatransmissionCurve, const RetinexgaintransmissionCurve & dehagaintransmissionCurve, multi_array2D &conversionBuffer, bool dehacontlutili, bool mapcontlutili, bool useHsl, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax, LUTu &histLRETI) {}; virtual void retinexPrepareCurves (const procparams::RetinexParams &retinexParams, LUTf &cdcurve, LUTf &mapcurve, RetinextransmissionCurve &retinextransmissionCurve, RetinexgaintransmissionCurve &retinexgaintransmissionCurve, bool &retinexcontlutili, bool &mapcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI) {}; virtual void retinexPrepareBuffers (const procparams::ColorManagementParams& cmp, const procparams::RetinexParams &retinexParams, multi_array2D &conversionBuffer, LUTu &lhist16RETI) {}; - virtual void flushRawData () {}; - virtual void flushRGB () {}; + virtual void flush () = 0; virtual void HLRecovery_Global (const procparams::ToneCurveParams &hrp) {}; virtual void HLRecovery_inpaint (float** red, float** green, float** blue) {}; diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 88178d0e0..40a5ae68a 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1309,15 +1309,8 @@ const std::vector& WBParams::getWbEntries() static const std::vector wb_entries = { {"Camera", WBEntry::Type::CAMERA, M("TP_WBALANCE_CAMERA"), 0, 1.f, 1.f, 0.f}, - // {"Auto", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTO"), 0, 1.f, 1.f, 0.f}, {"autitcgreen", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOITCGREEN"), 0, 1.f, 1.f, 0.f}, {"autold", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOOLD"), 0, 1.f, 1.f, 0.f}, - // {"aut", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTODEM"), 0, 1.f, 1.f, 0.f}, - // {"autedg", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOEDGE"), 0, 1.f, 1.f, 0.f}, - // {"autorobust", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOROB"), 0, 1.f, 1.f, 0.f}, - // {"autosdw", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOSDW"), 0, 1.f, 1.f, 0.f}, - // {"autedgsdw", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOEDGESW"), 0, 1.f, 1.f, 0.f}, - // {"autedgrob", WBEntry::Type::AUTO, M("TP_WBALANCE_AUTOEDGEROB"), 0, 1.f, 1.f, 0.f}, {"Daylight", WBEntry::Type::DAYLIGHT, M("TP_WBALANCE_DAYLIGHT"), 5300, 1.f, 1.f, 0.f}, {"Cloudy", WBEntry::Type::CLOUDY, M("TP_WBALANCE_CLOUDY"), 6200, 1.f, 1.f, 0.f}, {"Shade", WBEntry::Type::SHADE, M("TP_WBALANCE_SHADE"), 7600, 1.f, 1.f, 0.f}, diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 3cabaf5b2..b55ec4bf1 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -196,7 +196,7 @@ void transLineD1x (const float* const red, const float* const green, const float } if(i == 2 && oddHeight) { - int row = 2 * imheight; + row = 2 * imheight; for (int j = 0; j < imwidth; j++) { int col = imwidth - 1 - j; @@ -448,6 +448,7 @@ RawImageSource::RawImageSource () , initialGain(0.0) , camInitialGain(0.0) , defGain(0.0) + , camProfile(nullptr) , ri(nullptr) , rawData(0, 0) , green(0, 0) @@ -462,7 +463,6 @@ RawImageSource::RawImageSource () , rawDirty(true) , histMatchingParams(new procparams::ColorManagementParams) { - camProfile = nullptr; embProfile = nullptr; rgbSourceModified = false; for(int i = 0; i < 4; ++i) { @@ -488,9 +488,6 @@ RawImageSource::~RawImageSource () delete rawDataBuffer[i]; } - flushRGB(); - flushRawData(); - if (camProfile) { cmsCloseProfile (camProfile); } @@ -897,9 +894,9 @@ void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* ima } // last row - int b = (a == 1 && image->getHeight() % 2) || (a == 0 && image->getHeight() % 2 == 0); + int offset = (a == 1 && image->getHeight() % 2) || (a == 0 && image->getHeight() % 2 == 0); - for (int j = 1 + b; j < image->getWidth() - 1; j += 2) { + for (int j = 1 + offset; j < image->getWidth() - 1; j += 2) { image->r(image->getHeight() - 1, j) = (image->r(image->getHeight() - 2, j) + image->r(image->getHeight() - 1, j + 1) + image->r(image->getHeight() - 1, j - 1)) / 3; image->g(image->getHeight() - 1, j) = (image->g(image->getHeight() - 2, j) + image->g(image->getHeight() - 1, j + 1) + image->g(image->getHeight() - 1, j - 1)) / 3; image->b(image->getHeight() - 1, j) = (image->b(image->getHeight() - 2, j) + image->b(image->getHeight() - 1, j + 1) + image->b(image->getHeight() - 1, j - 1)) / 3; @@ -2208,7 +2205,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara { float aa = conversionBuffer[0][i - border][j - border]; float bb = conversionBuffer[1][i - border][j - border]; - float Chprov1 = sqrt(SQR(aa) + SQR(bb)) / 327.68f; + float Chprov1 = std::sqrt(SQR(aa) + SQR(bb)) / 327.68f; sqrtBuffer[j - border] = Chprov1; float HH = xatan2f(bb, aa); atan2Buffer[j - border] = HH; @@ -2236,7 +2233,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #else float aa = conversionBuffer[0][i - border][j - border]; float bb = conversionBuffer[1][i - border][j - border]; - float Chprov1 = sqrt(SQR(aa) + SQR(bb)) / 327.68f; + float Chprov1 = std::sqrt(SQR(aa) + SQR(bb)) / 327.68f; float HH = xatan2f(bb, aa); float2 sincosval;// = xsincosf(HH); @@ -2350,15 +2347,16 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara } -void RawImageSource::flushRawData() +void RawImageSource::flush() { + for(size_t i = 0; i + 1 < numFrames; ++i) { + delete rawDataBuffer[i]; + rawDataBuffer[i] = nullptr; + } + if (rawData) { rawData(0, 0); } -} - -void RawImageSource::flushRGB() -{ if (green) { green(0, 0); } @@ -2382,7 +2380,6 @@ void RawImageSource::flushRGB() if (blueloc) { blueloc(0, 0); } - } void RawImageSource::HLRecovery_Global(const ToneCurveParams &hrp) @@ -2435,6 +2432,7 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw } } } else { + #ifdef _OPENMP #pragma omp parallel for #endif @@ -3409,8 +3407,6 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi constexpr float trans[ColorCount][ColorCount] = { { 1, 1, 1 }, { 1.7320508, -1.7320508, 0 }, { -1, -1, 2 } }; constexpr float itrans[ColorCount][ColorCount] = { { 1, 0.8660254, -0.5 }, { 1, -0.8660254, -0.5 }, { 1, 0, 1 } }; -#define FOREACHCOLOR for (int c=0; c < ColorCount; c++) - float minpt = min(hlmax[0], hlmax[1], hlmax[2]); //min of the raw clip points //float maxpt=max(hlmax[0],hlmax[1],hlmax[2]);//max of the raw clip points //float medpt=hlmax[0]+hlmax[1]+hlmax[2]-minpt-maxpt;//median of the raw clip points @@ -3421,7 +3417,9 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi const float satthresh = 0.5; float clip[3]; - FOREACHCOLOR clip[c] = min(maxave, hlmax[c]); + for (int c = 0; c < ColorCount; ++c) { + clip[c] = min(maxave, hlmax[c]); + } // Determine the maximum level (clip) of all channels const float clippt = clipthresh * maxval; @@ -3438,20 +3436,20 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi rgb[2] = bin[col]; // If no channel is clipped, do nothing on pixel - int c; + int cc; - for (c = 0; c < ColorCount; c++) { - if (rgb[c] > clippt) { + for (cc = 0; cc < ColorCount; ++cc) { + if (rgb[cc] > clippt) { break; } } - if (c == ColorCount) { + if (cc == ColorCount) { continue; } // Initialize cam with raw input [0] and potentially clipped input [1] - FOREACHCOLOR { + for (int c = 0; c < ColorCount; ++c) { lratio += min(rgb[c], clip[c]); cam[0][c] = rgb[c]; cam[1][c] = min(cam[0][c], maxval); @@ -3459,7 +3457,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi // Calculate the lightness correction ratio (chratio) for (int i = 0; i < 2; i++) { - FOREACHCOLOR { + for (int c = 0; c < ColorCount; ++c) { lab[i][c] = 0; for (int j = 0; j < ColorCount; j++) @@ -3475,7 +3473,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi } } - chratio = (sqrt(sum[1] / sum[0])); + chratio = (std::sqrt(sum[1] / sum[0])); // Apply ratio to lightness in LCH space for (int c = 1; c < ColorCount; c++) { @@ -3483,7 +3481,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi } // Transform back from LCH to RGB - FOREACHCOLOR { + for (int c = 0; c < ColorCount; ++c) { cam[0][c] = 0; for (int j = 0; j < ColorCount; j++) @@ -3491,7 +3489,9 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi cam[0][c] += itrans[c][j] * lab[0][j]; } } - FOREACHCOLOR rgb[c] = cam[0][c] / ColorCount; + for (int c = 0; c < ColorCount; ++c) { + rgb[c] = cam[0][c] / ColorCount; + } // Copy converted pixel back if (rin[col] > fixpt) { @@ -3545,7 +3545,7 @@ void RawImageSource::HLRecovery_Luminance (float* rin, float* gin, float* bin, f double Ho = 2 * bo - ro - go; if (r != g && g != b) { - double ratio = sqrt ((Co * Co + Ho * Ho) / (C * C + H * H)); + double ratio = std::sqrt ((Co * Co + Ho * Ho) / (C * C + H * H)); C *= ratio; H *= ratio; } @@ -3759,7 +3759,7 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU #ifdef _OPENMP int numThreads; // reduce the number of threads under certain conditions to avoid overhead of too many critical regions - numThreads = sqrt((((H - 2 * border) * (W - 2 * border)) / 262144.f)); + numThreads = std::sqrt((((H - 2 * border) * (W - 2 * border)) / 262144.f)); numThreads = std::min(std::max(numThreads, 1), omp_get_max_threads()); #pragma omp parallel num_threads(numThreads) @@ -3895,12 +3895,10 @@ void RawImageSource::getRowStartEnd (int x, int &start, int &end) } -static void histoxyY(int bfhitc, int bfwitc, array2D & xc, array2D & yc, array2D & Yc, float *xxx, float * yyy, float * YYY, int * histxy, float * area, int * inter) +static void histoxyY(int bfhitc, int bfwitc, const array2D & xc, const array2D & yc, const array2D & Yc, float *xxx, float * yyy, float * YYY, int * histxy, float * area, int * inter) { - int nh = 0; -// int nc = 0; - // int nc2 = 0; + int nh; for (int y = 0; y < bfhitc ; y++) { for (int x = 0; x < bfwitc ; x++) { @@ -5407,7 +5405,7 @@ static void histoxyY(int bfhitc, int bfwitc, array2D & xc, array2D -void static studentXY(array2D & YYcurr, array2D & reffYY, int sizcurr, int Nc, int tt, float & student) +void static studentXY(const array2D & YYcurr, const array2D & reffYY, int sizcurr, int Nc, int tt, float & student) { //calculate Student coeff YY float somcurrY = 0.f; @@ -5448,7 +5446,7 @@ void static studentXY(array2D & YYcurr, array2D & reffYY, int siz somsquecreffY = somreff2Y - (SQR(somreffY)) / sizestureffY; //sum sqr differences second - float diviY = sqrt(((somsqueccurrY + somsquecreffY) * (1.f / (float)sizestucurrY + 1.f / (float)sizestureffY)) / (sizestucurrY + sizestureffY - 2)); + float diviY = std::sqrt(((somsqueccurrY + somsquecreffY) * (1.f / (float)sizestucurrY + 1.f / (float)sizestureffY)) / (sizestucurrY + sizestureffY - 2)); //divisor student float numerY = ((float)somcurrY / (float)sizestucurrY) - ((float)somreffY / (float)sizestureffY); //numerator student @@ -5567,15 +5565,15 @@ static void SdwWB(const array2D &redloc, const array2D &greenloc, SigmaB[i] = sigmab; if (ng > 0) { - SigmaG[i] = sqrt(SigmaG[i] / ng); + SigmaG[i] = std::sqrt(SigmaG[i] / ng); } if (nr > 0) { - SigmaR[i] = sqrt(SigmaR[i] / nr); + SigmaR[i] = std::sqrt(SigmaR[i] / nr); } if (nb > 0) { - SigmaB[i] = sqrt(SigmaB[i] / nb); + SigmaB[i] = std::sqrt(SigmaB[i] / nb); } #ifdef _OPENMP @@ -5830,9 +5828,9 @@ static void SobelWB(array2D &redsobel, array2D &greensobel, array2 //Edge strength //we can add if need teta = atan2 (sumYr, sumXr) - redsobel[y][x] = CLIP(sqrt(SQR(sumXr) + SQR(sumYr))); - greensobel[y][x] = CLIP(sqrt(SQR(sumXg) + SQR(sumYg))); - bluesobel[y][x] = CLIP(sqrt(SQR(sumXb) + SQR(sumYb))); + redsobel[y][x] = CLIP(std::sqrt(SQR(sumXr) + SQR(sumYr))); + greensobel[y][x] = CLIP(std::sqrt(SQR(sumXg) + SQR(sumYg))); + bluesobel[y][x] = CLIP(std::sqrt(SQR(sumXb) + SQR(sumYb))); } } } @@ -5964,7 +5962,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double float snedecor;//1. actually but put in case of confiance interval } WbGreen; - WbGreen gree[118] = {//symetric coefficient between 0.717 and 1.40 + constexpr WbGreen gree[118] = {//symetric coefficient between 0.717 and 1.40 {0.400, 1.f}, {0.500, 1.f}, {0.550, 1.f}, @@ -6130,7 +6128,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } WbTxyz; //we can change step to increase precision if need - also in Colortemp.cc with same changes //I don't know how to pass this structure to Colortemp ! - WbTxyz Txyz[118] = {//temperature Xwb Zwb 118 values x wb and y wb are calculated after + constexpr WbTxyz Txyz[118] = {//temperature Xwb Zwb 118 values x wb and y wb are calculated after {2001., 1.273842, 0.145295}, {2101., 1.244008, 0.167533}, {2201., 1.217338, 0.190697}, @@ -6325,7 +6323,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double bmm = new float [N_t]; int siza = 167;//size of histogram - int maxval = 25; //tempref and greenref are camera wb values. // I used them by default to select good spectral values !! @@ -6363,7 +6360,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double gm = new_scale_mul[1] / scale_mul[1] * gain; bm = new_scale_mul[2] / scale_mul[2] * gain; rmm[tt] = rm / gm; - gmm[tt] = gm / gm; + gmm[tt] = 1.f; bmm[tt] = bm / gm; } @@ -6431,270 +6428,261 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double //here we select the good spectral color inside the 113 values //call tempxy to calculate for 114 color references Temp and XYZ with cat02 - if (separated) { - ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants + ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants - //find the good spectral values - //calculate xy reference spectral for tempref - for (int j = 0; j < Nc ; j++) { - reff_spect_xx_camera[j][repref] = TX[j] / (TX[j] + TY[j] + TZ[j]); // x from xyY - reff_spect_yy_camera[j][repref] = TY[j] / (TX[j] + TY[j] + TZ[j]); // y from xyY + //find the good spectral values + //calculate xy reference spectral for tempref + for (int j = 0; j < Nc ; j++) { + reff_spect_xx_camera[j][repref] = TX[j] / (TX[j] + TY[j] + TZ[j]); // x from xyY + reff_spect_yy_camera[j][repref] = TY[j] / (TX[j] + TY[j] + TZ[j]); // y from xyY + } + + int deltarepref = settings->itcwb_delta; + + for (int nn = 0; nn <= 2; nn++) { + //three loop to refine color if temp camera is probably not very good + int drep = 0; + + if (nn == 0) { + drep = -deltarepref; } - int deltarepref = settings->itcwb_delta; - - for (int nn = 0; nn <= 2; nn++) { - //three loop to refine color if temp camera is probably not very good - int drep = 0; - - if (nn == 0) { - drep = -deltarepref; - } - - if (nn == 2) { - drep = +deltarepref; - } - - int rep = repref + drep; - - if (rep > N_t) { - rep = N_t; - } - - if (rep < 0) { - rep = 0; - } - - //initialize calculation of xy current for tempref - for (int y = 0; y < bfh ; y += 10) { - for (int x = 0; x < bfw ; x += 10) { - int yy = y / 10; - int xx = x / 10 ; - float x_c = 0.f, y_c = 0.f, Y_c = 0.f; - float x_x = 0.f, y_y = 0.f, z_z = 0.f; - float RR = rmm[rep] * redloc[y][x]; - float GG = gmm[rep] * greenloc[y][x]; - float BB = bmm[rep] * blueloc[y][x]; - Color::rgbxyY(RR, GG, BB, x_c, y_c, Y_c, x_x, y_y, z_z, wp); - xc[yy][xx] = x_c; - yc[yy][xx] = y_c; - Yc[yy][xx] = Y_c; - } - - } - - //histogram xy depend of temp...but in most cases D45 ..D65.. - //calculate for this image the mean values for each family of color, near histogram x y (number) - //xy vary from x 0..0.77 y 0..0.82 - //neutral values are near x=0.34 0.33 0.315 0.37 y =0.35 0.36 0.34 - //skin are about x 0.45 0.49 y 0.4 0.47 - //blue sky x=0.25 y=0.28 and x=0.29 y=0.32 - // step about 0.02 x 0.32 0.34 y= 0.34 0.36 skin -- sky x 0.24 0.30 y 0.28 0.32 - //big step about 0.2 - - histoxyY(bfhitc, bfwitc, xc, yc, Yc, xxx, yyy, YYY, histxy, area, inter); + if (nn == 2) { + drep = +deltarepref; } - //calculate x y Y - int sizcurrref = siza;//choice of number of correlate colors in image - histcurrref(N_t, sizcurrref); - xx_curref(N_t, sizcurrref); - yy_curref(N_t, sizcurrref); - YY_curref(N_t, sizcurrref); - xx_curref_reduc(N_t, sizcurrref); - yy_curref_reduc(N_t, sizcurrref); - YY_curref_reduc(N_t, sizcurrref); - R_curref_reduc(N_t, sizcurrref); - G_curref_reduc(N_t, sizcurrref); - B_curref_reduc(N_t, sizcurrref); + int rep = repref + drep; - - hiss Wbhis [siza]; - int n1 = 0; - int n4 = 0; - int n15 = 0; - int n30 = 0; - int ntr = 0; - - for (int nh = 0; nh < siza; nh++) { - Wbhis[nh].histnum = histxy[nh]; - Wbhis[nh].index = nh; - Wbhis[nh].interest = inter[nh]; + if (rep > N_t) { + rep = N_t; } - //sort in ascending order - std::sort(Wbhis, Wbhis + siza, Wbhis[0]); + if (rep < 0) { + rep = 0; + } - for (int nh = 0; nh < siza; nh++) { + //initialize calculation of xy current for tempref + for (int y = 0; y < bfh ; y += 10) { + for (int x = 0; x < bfw ; x += 10) { + int yy = y / 10; + int xx = x / 10 ; + float x_c = 0.f, y_c = 0.f, Y_c = 0.f; + float x_x = 0.f, y_y = 0.f, z_z = 0.f; + float RR = rmm[rep] * redloc[y][x]; + float GG = gmm[rep] * greenloc[y][x]; + float BB = bmm[rep] * blueloc[y][x]; + Color::rgbxyY(RR, GG, BB, x_c, y_c, Y_c, x_x, y_y, z_z, wp); + xc[yy][xx] = x_c; + yc[yy][xx] = y_c; + Yc[yy][xx] = Y_c; + } + + } + + //histogram xy depend of temp...but in most cases D45 ..D65.. + //calculate for this image the mean values for each family of color, near histogram x y (number) + //xy vary from x 0..0.77 y 0..0.82 + //neutral values are near x=0.34 0.33 0.315 0.37 y =0.35 0.36 0.34 + //skin are about x 0.45 0.49 y 0.4 0.47 + //blue sky x=0.25 y=0.28 and x=0.29 y=0.32 + // step about 0.02 x 0.32 0.34 y= 0.34 0.36 skin -- sky x 0.24 0.30 y 0.28 0.32 + //big step about 0.2 + + histoxyY(bfhitc, bfwitc, xc, yc, Yc, xxx, yyy, YYY, histxy, area, inter); + } + + //calculate x y Y + int sizcurrref = siza;//choice of number of correlate colors in image + histcurrref(N_t, sizcurrref); + xx_curref(N_t, sizcurrref); + yy_curref(N_t, sizcurrref); + YY_curref(N_t, sizcurrref); + xx_curref_reduc(N_t, sizcurrref); + yy_curref_reduc(N_t, sizcurrref); + YY_curref_reduc(N_t, sizcurrref); + R_curref_reduc(N_t, sizcurrref); + G_curref_reduc(N_t, sizcurrref); + B_curref_reduc(N_t, sizcurrref); + + + hiss Wbhis [siza]; + int n1 = 0; + int n4 = 0; + int n15 = 0; + int n30 = 0; + int ntr = 0; + + for (int nh = 0; nh < siza; nh++) { + Wbhis[nh].histnum = histxy[nh]; + Wbhis[nh].index = nh; + Wbhis[nh].interest = inter[nh]; + } + + //sort in ascending order + std::sort(Wbhis, Wbhis + siza, Wbhis[0]); + + for (int nh = 0; nh < siza; nh++) { // printf("nh=%i", Wbhis[nh].index); + } + + //part to improve + for (int nh = 0; nh < siza; nh++) { + if (Wbhis[nh].histnum < 1) { + n1++; //keep only existing color but avoid to small } - //part to improve - for (int nh = 0; nh < siza; nh++) { - if (Wbhis[nh].histnum < 1) { - n1++; //keep only existing color but avoid to small - } - - if (Wbhis[nh].histnum < 4) { - n4++; //keep only existing color but avoid to small - } - - if (Wbhis[nh].histnum < 15) { - n15++; //keep only existing color but avoid to small - } - - if (Wbhis[nh].histnum < 30) { - n30++; //keep only existing color but avoid to small - } + if (Wbhis[nh].histnum < 4) { + n4++; //keep only existing color but avoid to small + } + if (Wbhis[nh].histnum < 15) { + n15++; //keep only existing color but avoid to small + } + if (Wbhis[nh].histnum < 30) { + n30++; //keep only existing color but avoid to small } - ntr = n30; - - if (ntr > (siza - 25)) { - ntr = n15; //if to less elements 25 elements mini - } - - if (ntr > (siza - 23)) { - ntr = n4; //if to less elements 25 elements mini - } - - if (ntr > (siza - 20)) { - ntr = n1; //if to less elements 20 elements mini - normally never be used ! - } - - int sizcurr2ref = sizcurrref - ntr; - int sizcu30 = sizcurrref - n30; - int sizcu4 = sizcurrref - n4; - -// printf("sizcurr2ref=%i sizcur_30=%i siecur_4=%i \n", sizcurr2ref, sizcu30, sizcu4); - sizcu4 = sizcu30;//arbitrary mini size if 30 result, ==> in full image 3000 pixels - - if (sizcu4 > 55) { - sizcu4 = 55; - } - - chrom wbchro[sizcu4]; - double swpr = (Txyz[repref].XX + Txyz[repref].ZZ + 1.); - double xwpr = Txyz[repref].XX / swpr;//white point for tt in xy coordiantes - double ywpr = 1. / swpr; + } - for (int i = 0; i < sizcu4; i++) { //take the max values - int j = i; - histcurrref[j][repref] = (float) Wbhis[siza - (j + 1)].histnum; - xx_curref[j][repref] = xxx[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; - yy_curref[j][repref] = yyy[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; - YY_curref[j][repref] = YYY[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; + ntr = n30; + + if (ntr > (siza - 25)) { + ntr = n15; //if to less elements 25 elements mini + } + + if (ntr > (siza - 23)) { + ntr = n4; //if to less elements 25 elements mini + } + + if (ntr > (siza - 20)) { + ntr = n1; //if to less elements 20 elements mini - normally never be used ! + } + + int sizcurr2ref = sizcurrref - ntr; + const int sizcu30 = sizcurrref - n30; + const int sizcu4 = rtengine::min(sizcu30, 55); + + + chrom wbchro[sizcu4]; + double swpr = (Txyz[repref].XX + Txyz[repref].ZZ + 1.); + double xwpr = Txyz[repref].XX / swpr;//white point for tt in xy coordiantes + double ywpr = 1. / swpr; + + + for (int i = 0; i < sizcu4; i++) { //take the max values + int j = i; + histcurrref[j][repref] = (float) Wbhis[siza - (j + 1)].histnum; + xx_curref[j][repref] = xxx[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; + yy_curref[j][repref] = yyy[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; + YY_curref[j][repref] = YYY[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; // printf("xx=%f yy=%f\n", xx_curref[j][repref], yy_curref[j][repref]); - } + } - estimchrom = 0.f; + estimchrom = 0.f; - for (int nh = 0; nh < sizcu4; nh++) { - float chxy = sqrt(SQR(xx_curref[nh][repref] - xwpr) + SQR(yy_curref[nh][repref] - ywpr)); - wbchro[nh].chroxy_number = chxy * sqrt(histcurrref[nh][repref]); - wbchro[nh].chroxy = sqrt(chxy); - wbchro[nh].chrox = xx_curref[nh][repref]; - wbchro[nh].chroy = yy_curref[nh][repref]; - wbchro[nh].Y = YY_curref[nh][repref]; - wbchro[nh].index = nh; - estimchrom += chxy; - } + for (int nh = 0; nh < sizcu4; nh++) { + float chxy = std::sqrt(SQR(xx_curref[nh][repref] - xwpr) + SQR(yy_curref[nh][repref] - ywpr)); + wbchro[nh].chroxy_number = chxy * std::sqrt(histcurrref[nh][repref]); + wbchro[nh].chroxy = std::sqrt(chxy); + wbchro[nh].chrox = xx_curref[nh][repref]; + wbchro[nh].chroy = yy_curref[nh][repref]; + wbchro[nh].Y = YY_curref[nh][repref]; + wbchro[nh].index = nh; + estimchrom += chxy; + } - estimchrom /= sizcu4; - //printf("estimchrom=%f \n", estimchrom); + estimchrom /= sizcu4; + //printf("estimchrom=%f \n", estimchrom); - if (settings->itcwb_sort) { //sort in ascending with chroma values + if (settings->itcwb_sort) { //sort in ascending with chroma values - std::sort(wbchro, wbchro + sizcu4, wbchro[0]); - } + std::sort(wbchro, wbchro + sizcu4, wbchro[0]); + } - /* - for (int nh = 0; nh < sizcu4; nh++) { - printf("nh=%i chroma_xy=%f chrox=%f chroy=%f\n", nh, wbchro[nh].chroxy, wbchro[nh].chrox, wbchro[nh].chroy); - } - */ - maxval = settings->itcwb_thres;//max values of color to find correllation - - if (maxval < 10) { - maxval = 10; - } - - if (maxval > 55) { - maxval = 55; - } - - if (sizcurr2ref > maxval) { - sizcurr2ref = maxval; //keep about the biggest values, - } - - - for (int i = 0; i < sizcurr2ref; i++) { - //is condition chroxy necessary ? - if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral - w++; - xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox; - yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy; - YY_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].Y; - // printf("xx_cu=%f yy_cu=%f Y=%f chro=%f\n", xx_curref_reduc[w][repref], yy_curref_reduc[w][repref], YY_curref_reduc[w][repref],sqrt(wbchro[sizcu4 - (i + 1)].chroxy)); + /* + for (int nh = 0; nh < sizcu4; nh++) { + printf("nh=%i chroma_xy=%f chrox=%f chroy=%f\n", nh, wbchro[nh].chroxy, wbchro[nh].chrox, wbchro[nh].chroy); } + */ + int maxval = settings->itcwb_thres;//max values of color to find correllation + + if (maxval < 10) { + maxval = 10; + } + + if (maxval > 55) { + maxval = 55; + } + + if (sizcurr2ref > maxval) { + sizcurr2ref = maxval; //keep about the biggest values, + } + + + for (int i = 0; i < sizcurr2ref; i++) { + //is condition chroxy necessary ? + if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral + w++; + xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox; + yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy; + YY_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].Y; + // printf("xx_cu=%f yy_cu=%f Y=%f chro=%f\n", xx_curref_reduc[w][repref], yy_curref_reduc[w][repref], YY_curref_reduc[w][repref],std::sqrt(wbchro[sizcu4 - (i + 1)].chroxy)); } + } - //calculate deltaE xx to find best values of spectrals datas - int maxnb = settings->itcwb_sizereference; + //calculate deltaE xx to find best values of spectrals datas + int maxnb = settings->itcwb_sizereference; - if (maxnb > 5) { - maxnb = 5; - } + if (maxnb > 5) { + maxnb = 5; + } - if (maxnb < 1) { - maxnb = 1; - } + if (maxnb < 1) { + maxnb = 1; + } - if (settings->itcwb_thres > 39) { - maxnb = 200 / settings->itcwb_thres; - } + if (settings->itcwb_thres > 39) { + maxnb = 200 / settings->itcwb_thres; + } - for (int nb = 1; nb <= maxnb; nb ++) { //max 5 iterations for Itcwb_thres=33, after trial 3 is good in most cases but in some cases 5 - for (int i = 0; i < w; i++) { - float mindeltaE = 100000.f; - int kN = 0; + for (int nb = 1; nb <= maxnb; nb ++) { //max 5 iterations for Itcwb_thres=33, after trial 3 is good in most cases but in some cases 5 + for (int i = 0; i < w; i++) { + float mindeltaE = 100000.f; + int kN = 0; - for (int j = 0; j < Nc ; j++) { - if (good_spectral[j] == 0) { - float deltaE = SQR(xx_curref_reduc[i][repref] - reff_spect_xx_camera[j][repref]) + SQR(yy_curref_reduc[i][repref] - reff_spect_yy_camera[j][repref]); + for (int j = 0; j < Nc ; j++) { + if (good_spectral[j] == 0) { + float deltaE = SQR(xx_curref_reduc[i][repref] - reff_spect_xx_camera[j][repref]) + SQR(yy_curref_reduc[i][repref] - reff_spect_yy_camera[j][repref]); - if (deltaE < mindeltaE) { - mindeltaE = deltaE; - kN = j; - } + if (deltaE < mindeltaE) { + mindeltaE = deltaE; + kN = j; } } - - good_spectral[kN] = 1;//good spectral are spectral color that match color histogram xy - //printf("k=%i ", kN); } + + good_spectral[kN] = 1;//good spectral are spectral color that match color histogram xy + //printf("k=%i ", kN); } + } //reconvert to RGB for "reduction" - for (int i = 0; i < w; i++) { - float X = 65535.f * xx_curref_reduc[i][repref] * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; - float Y = 65535.f * YY_curref_reduc[i][repref]; - float Z = 65535.f * (1.f - xx_curref_reduc[i][repref] - yy_curref_reduc[i][repref]) * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; - float r, g, b; - Color::xyz2rgb(X, Y, Z, r, g, b, wip); - r /= rmm[repref]; - g /= gmm[repref]; - b /= bmm[repref]; - R_curref_reduc[i][repref] = r; - G_curref_reduc[i][repref] = g; - B_curref_reduc[i][repref] = b; - - } + for (int i = 0; i < w; i++) { + float X = 65535.f * xx_curref_reduc[i][repref] * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; + float Y = 65535.f * YY_curref_reduc[i][repref]; + float Z = 65535.f * (1.f - xx_curref_reduc[i][repref] - yy_curref_reduc[i][repref]) * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; + float r, g, b; + Color::xyz2rgb(X, Y, Z, r, g, b, wip); + r /= rmm[repref]; + g /= gmm[repref]; + b /= bmm[repref]; + R_curref_reduc[i][repref] = r; + G_curref_reduc[i][repref] = g; + B_curref_reduc[i][repref] = b; } @@ -6706,8 +6694,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double separated = false; ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants - int kk = -1; - //calculate x y Y int sizcurr = siza;//choice of number of correlate colors in image histcurr(N_t, sizcurr); @@ -6720,7 +6706,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double YYcurr_reduc(N_t, sizcurr); //calculate x y z for each pixel with multiplier rmm gmm bmm - kk = -1; for (int tt = 0; tt < N_t; tt++) {//N_t // double swp = (Txyz[tt].XX + Txyz[tt].ZZ + 1.); @@ -6752,7 +6737,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } - kk = -1; + int kk = -1; for (int i = 0; i < Nc ; i++) { if (good_spectral[i] == 1) { @@ -6767,34 +6752,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } } - - /* - //cat02 not need and does not work well - float nnx, nny, nnz; - - if(wbpar.wbcat02Method == "cam") {//code no update... - for(int k=0;k < sizcurr3; k++) { - float nnx = xxyycurr[2 * k][tt]*YYcurr[k][tt] / xxyycurr[2 * k + 1][tt]; - float nny = YYcurr[k][tt]; - float nnz = (1.f -xxyycurr[2 * k][tt] - xxyycurr[2 * k + 1][tt] )*YYcurr[k][tt]/xxyycurr[2 * k + 1][tt]; - float CAM02BB00 = 1.0f, CAM02BB01=1.0f, CAM02BB02=1.0f, CAM02BB10=1.0f, CAM02BB11=1.0f, CAM02BB12=1.0f, CAM02BB20=1.0f, CAM02BB21=1.0f, CAM02BB22=1.0f; //for CIECAT02 - float Xwb = Txyz[20].XX; - float Ywb = 1.; - float Zwb = Txyz[20].ZZ; - float xn, yn, zn; - ColorTemp::icieCAT02float(Xwb, Ywb, Zwb, CAM02BB00, CAM02BB01, CAM02BB02, CAM02BB10, CAM02BB11, CAM02BB12, CAM02BB20, CAM02BB21, CAM02BB22, 1.0f); - - xn = CAM02BB00 * nnx + CAM02BB01 * nny + CAM02BB02 * nnz ; - yn = CAM02BB10 * nnx + CAM02BB11 * nny + CAM02BB12 * nnz ; - zn = CAM02BB20 * nnx + CAM02BB21 * nny + CAM02BB22 * nnz; - float som = xn + yn + zn; - xxyycurr[2 * k][tt] = xn / som; - xxyycurr[2 * k + 1][tt] = yn / som; - YYcurr[k][tt] = yn; - } - } - */ - float student = 0.f; @@ -6846,8 +6803,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double scantempend = N_t - 1; } - int kkg = -1; - for (int gr = Rangegreenused.begin; gr < Rangegreenused.end; gr++) { float minstudgr = 100000.f; int goodrefgr = 1; @@ -6871,7 +6826,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double gm = new_scale_mul[1] / scale_mul[1] * gain; bm = new_scale_mul[2] / scale_mul[2] * gain; rmm[tt] = rm / gm; - gmm[tt] = gm / gm; + gmm[tt] = 1.f; bmm[tt] = bm / gm; } @@ -6904,8 +6859,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } - kkg = -1; - //degrade correllation with color high chroma, but not too much...seems not good, but keep in case of?? if (estimchrom < 0.025f) {//very smal value of chroma for image @@ -6924,6 +6877,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } + int kkg = -1; for (int i = 0; i < Nc ; i++) { if (good_spectral[i] == 1) { kkg++; @@ -7083,43 +7037,6 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D { // BENCHFUN //auto white balance -// printf ("AUtoWB OK\n"); -/* - array2D redsobel; - array2D greensobel; - array2D bluesobel; - - redsobel(bfw, bfh); - greensobel(bfw, bfh); - bluesobel(bfw, bfh); -*/ - double avg_r = 0.; - double avg_g = 0.; - double avg_b = 0.; - int rn = 0, gn = 0, bn = 0; -// constexpr double clipHigh = 65500.0; -// constexpr double clipLow = 0; //1500.0; - bool edg = false; - bool greyn = false; - bool robust = false; - bool itc = false; - - if (wbpar.method == "autorobust") { - // printf("autorob\n"); - // RobustWB(redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm); - - } - - if (wbpar.method == "autedg") { - // printf("autoedge\n"); - // edg = true; - } - - if (wbpar.method == "aut") { -// greyn = true; - } - - if (wbpar.method == "autitcgreen") { bool extra = false; @@ -7135,134 +7052,16 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D extra = true; } - // greenref = wbpar.green; -// printf("gree=%f\n", greenref); tempitc = 5000.; -// greenitc = greenref; - itc = true; - if (itc) { - ItcWB(extra, tempref, greenref, tempitc, greenitc, studgood, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, cmp, raw, wbpar); - } + ItcWB(extra, tempref, greenref, tempitc, greenitc, studgood, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, cmp, raw, wbpar); } - - if (wbpar.method == "autedgsdw") { - // SobelWB(redsobel, greensobel, bluesobel, redloc, greenloc, blueloc, bfw, bfh); - // SdwWB(redsobel, greensobel, bluesobel, bfw, bfh, avg_rm, avg_gm, avg_bm); - - } - - if (wbpar.method == "autedgrob") { - // SobelWB(redsobel, greensobel, bluesobel, redloc, greenloc, blueloc, bfw, bfh); - // RobustWB(redsobel, greensobel, bluesobel, bfw, bfh, avg_rm, avg_gm, avg_bm); - - } - - if (wbpar.method == "autosdw") { - // SdwWB(redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm); - - - // printf("bfw=%i bfh=%i begx=%i begy=%i xEn=%i yEn=%i cx=%i\n", bfw, bfh, begx, begy, xEn, yEn, cx); - } - -/* - if (edg) { - SobelWB(redsobel, greensobel, bluesobel, redloc, greenloc, blueloc, bfw, bfh); - -#ifdef _OPENMP - #pragma omp parallel for reduction(+:avg_r, avg_g, avg_b, rn, gn, bn) -#endif - - for (int y = 0; y < bfh ; y++) { - for (int x = 0; x < bfw ; x++) { - if (redsobel[y][x] < clipHigh && redsobel[y][x] > clipLow) { - avg_r += redsobel[y][x]; - rn++; - } - - if (greensobel[y][x] < clipHigh && greensobel[y][x] > clipLow) { - avg_g += greensobel[y][x]; - gn++; - } - - if (bluesobel[y][x] < clipHigh && bluesobel[y][x] > clipLow) { - avg_b += bluesobel[y][x]; - bn++; - } - } - } - } -*/ -/* - if (greyn) { -#ifdef _OPENMP - #pragma omp parallel for reduction(+:avg_r, avg_g, avg_b, rn, gn, bn) -#endif - - for (int y = 0; y < bfh ; y++) { - for (int x = 0; x < bfw ; x++) { - if (redloc[y][x] < clipHigh && redloc[y][x] > clipLow) { - avg_r += redloc[y][x]; - rn++; - } - - if (greenloc[y][x] < clipHigh && greenloc[y][x] > clipLow) { - avg_g += greenloc[y][x]; - gn++; - } - - if (blueloc[y][x] < clipHigh && blueloc[y][x] > clipLow) { - avg_b += blueloc[y][x]; - bn++; - } - } - } - } -*/ -// float varir = localr.equal; -// float varib = 1.f - (varir - 1.f); - - - -//CAT02 inverse - -// - if (greyn || edg) { - avg_rm = avg_r / rn; - avg_gm = avg_g / gn; - avg_bm = avg_b / bn; - } - - /* - //inverse cat02 - if (localr.wbcamMethod == "cat" || localr.wbcamMethod == "gamcat") { - //printf("Inverse CAT02\n"); - float x, y, z; - // cat02_to_xyzfloatraw ( x, y, z, avg_rm, avg_gm, avg_bm); - Color::xyz2rgbraw (x, y, z, avg_rm, avg_gm, avg_bm, wip); - } - */ - if (edg) { - // printf("Local sobel avgr = % f avgg = % f avgb = % f \n", avg_rm, avg_gm, avg_bm); - } - - if (greyn || robust) { - // printf("Local rgb avgr = % f avgg = % f avgb = % f \n", avg_rm, avg_gm, avg_bm); - } - -/* - redsobel(0, 0); - greensobel(0, 0); - bluesobel(0, 0); -*/ } void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) { //used by auto WB local to calculate red, green, blue in local region - // printf("OK RGBLOC\n"); - // int bfh = bf_h + 3, bfw = bf_w + 3; int bfh = H, bfw = W; if (local) { @@ -7270,36 +7069,6 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in bfw = bf_w + 3; } - // printf ("bfh=%i bfw=%i H=%i W=%i \n", bf_h, bf_w, H, W); - ColorManagementParams cmp; - - //TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix(cmp.working); - // TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix (cmp.working); - /* - float toxyz[3][3] = { - { - static_cast ( wprof[0][0] / Color::D50x), - static_cast ( wprof[0][1] / Color::D50x), - static_cast ( wprof[0][2] / Color::D50x) - }, { - static_cast ( wprof[1][0]), - static_cast ( wprof[1][1]), - static_cast ( wprof[1][2]) - }, { - static_cast ( wprof[2][0] / Color::D50z), - static_cast ( wprof[2][1] / Color::D50z), - static_cast ( wprof[2][2] / Color::D50z) - } - }; - */ - /* - double wp[3][3] = { - {wprof[0][0], wprof[0][1], wprof[0][2]}, - {wprof[1][0], wprof[1][1], wprof[1][2]}, - {wprof[2][0], wprof[2][1], wprof[2][2]} - }; - */ -// printf("wp00=%f wp02=%f\n", wp[0][0], wp[0][2]); if (! greenloc) { greenloc(bfw, bfh); } @@ -7312,8 +7081,7 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in blueloc(bfw, bfh); } - float avgL = 0.f; - float redmm = 0.f, greenmm = 0.f, bluemm = 0.f; + double avgL = 0.0; //center data on normal values int nn = 0; @@ -7324,20 +7092,19 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in int loy = cy + i; if (!local) { - redmm = redloc[i][j] = red[i][j]; - greenmm = greenloc[i][j] = green[i][j]; - bluemm = blueloc[i][j] = blue[i][j]; - float LL = (0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm); - avgL += LL; + const float redmm = redloc[i][j] = red[i][j]; + const float greenmm = greenloc[i][j] = green[i][j]; + const float bluemm = blueloc[i][j] = blue[i][j]; + const float LL = (0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm); + avgL += static_cast(LL); nn++; } else { - if (lox >= begx && lox < xEn && loy >= begy && loy < yEn) { - redmm = redloc[loy - begy][lox - begx] = red[i][j]; - greenmm = greenloc[loy - begy][lox - begx] = green[i][j]; - bluemm = blueloc[loy - begy][lox - begx] = blue[i][j]; - float LL = (0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm); - avgL += LL; + const float redmm = redloc[loy - begy][lox - begx] = red[i][j]; + const float greenmm = greenloc[loy - begy][lox - begx] = green[i][j]; + const float bluemm = blueloc[loy - begy][lox - begx] = blue[i][j]; + const float LL = (0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm); + avgL += static_cast(LL); nn++; } } @@ -7345,7 +7112,6 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in avgL /= nn; - float sig = 0.f; float vari = 0.f; int mm = 0; @@ -7356,10 +7122,9 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in mm++; } - sig = sqrt(vari / mm); - float multip = 60000.f / (avgL + 2.f * sig); + const float sig = std::sqrt(vari / mm); + const float multip = 60000.f / (avgL + 2.f * sig); - // printf("multip=%f \n", multip); for (int i = 0; i < bfh; i++) for (int j = 0; j < bfw; j++) { redloc[i][j] *= multip; @@ -7368,8 +7133,6 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in } if (gamma) { - // printf("gamma loc\n"); - for (int i = 0; i < bfh; i++) for (int j = 0; j < bfw; j++) { redloc[i][j] = Color::gammatab_srgb[redloc[i][j]]; @@ -7401,7 +7164,6 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in } -//void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref, double & tempitc, double & greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double & rm, double & gm, double & bm, const WBParams & wbpar, const ColorManagementParams & cmp, const RAWParams & raw) { // BENCHFUN @@ -7411,30 +7173,14 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref rm = gm = bm = 1; return; } -/* - if (redAWBMul != -1.) { - rm = redAWBMul; - gm = greenAWBMul; - bm = blueAWBMul; - return; - } - if (!isWBProviderReady()) { - rm = -1.0; - gm = -1.0; - bm = -1.0; - return; - } -*/ double avg_r = 0; double avg_g = 0; double avg_b = 0; int rn = 0, gn = 0, bn = 0; double avg_rm, avg_gm, avg_bm; - // int bfh = bf_h + 3, bfw = bf_w + 3; int bfh = H, bfw = W; if (wbpar.method == "autold") { - // printf("OK auto OLD\n"); if (fuji) { for (int i = 32; i < H - 32; i++) { int fw = ri->get_FujiWidth(); @@ -7608,44 +7354,28 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref } } - if (wbpar.method == "aut" || wbpar.method == "autosdw" || wbpar.method == "autedgsdw" || wbpar.method == "autitcgreen" || wbpar.method == "autedgrob" || wbpar.method == "autedg" || wbpar.method == "autorobust") { + if (wbpar.method == "autitcgreen") { bool twotimes = false; - // printf("OK avant auto\n"); WBauto(tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, studgood, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw); - // printf("OK apres auto\n"); - } redloc(0, 0); greenloc(0, 0); blueloc(0, 0); - if( settings->verbose ) { + if (settings->verbose) { printf ("AVG: %g %g %g\n", avg_r / std::max(1, rn), avg_g / std::max(1, gn), avg_b / std::max(1, bn)); } - // return ColorTemp (pow(avg_r/rn, 1.0/6.0)*img_r, pow(avg_g/gn, 1.0/6.0)*img_g, pow(avg_b/bn, 1.0/6.0)*img_b); - double reds = 0., greens = 0., blues = 0.; - - if (wbpar.method == "aut" || wbpar.method == "autosdw" || wbpar.method == "autedgsdw" || wbpar.method == "autedgrob" || wbpar.method == "autedg" || wbpar.method == "autorobust") { - //twotimes = true; - reds = avg_rm * refwb_red; - greens = avg_gm * refwb_green; - blues = avg_bm * refwb_blue; - } - - if (wbpar.method == "autold") { - reds = avg_r / std::max(1, rn) * refwb_red; - greens = avg_g / std::max(1, gn) * refwb_green; - blues = avg_b / std::max(1, bn) * refwb_blue; - } - if (wbpar.method == "autitcgreen") { //not used redAWBMul = rm = avg_rm * refwb_red; greenAWBMul = gm = avg_gm * refwb_green; blueAWBMul = bm = avg_bm * refwb_blue; } else { + const double reds = avg_r / std::max(1, rn) * refwb_red; + const double greens = avg_g / std::max(1, gn) * refwb_green; + const double blues = avg_b / std::max(1, bn) * refwb_blue; redAWBMul = rm = imatrices.rgb_cam[0][0] * reds + imatrices.rgb_cam[0][1] * greens + imatrices.rgb_cam[0][2] * blues; greenAWBMul = gm = imatrices.rgb_cam[1][0] * reds + imatrices.rgb_cam[1][1] * greens + imatrices.rgb_cam[1][2] * blues; blueAWBMul = bm = imatrices.rgb_cam[2][0] * reds + imatrices.rgb_cam[2][1] * greens + imatrices.rgb_cam[2][2] * blues; @@ -7653,12 +7383,6 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref } - - - - - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) { // BENCHFUN @@ -7875,9 +7599,6 @@ void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) blueAWBMul = bm = imatrices.rgb_cam[2][0] * reds + imatrices.rgb_cam[2][1] * greens + imatrices.rgb_cam[2][2] * blues; } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector &green, std::vector &blue, int tran, double equal) { @@ -8090,9 +7811,6 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector &conversionBuffer, bool dehacontlutili, bool mapcontlutili, bool useHsl, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax, LUTu &histLRETI) override; void retinexPrepareCurves (const procparams::RetinexParams &retinexParams, LUTf &cdcurve, LUTf &mapcurve, RetinextransmissionCurve &retinextransmissionCurve, RetinexgaintransmissionCurve &retinexgaintransmissionCurve, bool &retinexcontlutili, bool &mapcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI) override; void retinexPrepareBuffers (const procparams::ColorManagementParams& cmp, const procparams::RetinexParams &retinexParams, multi_array2D &conversionBuffer, LUTu &lhist16RETI) override; - void flushRawData () override; - void flushRGB () override; + void flush () override; void HLRecovery_Global (const procparams::ToneCurveParams &hrp) override; void refinement(int PassCount); void setBorder(unsigned int rawBorder) override {border = rawBorder;} diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 779f2b33d..d097ead72 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -801,8 +801,7 @@ private: // commented out because it makes the application crash when batch processing... // TODO: find a better place to flush rawData and rawRGB if (flush) { - imgsrc->flushRawData(); - imgsrc->flushRGB(); + imgsrc->flush(); } return true; diff --git a/rtengine/stdimagesource.cc b/rtengine/stdimagesource.cc index 9da4417e2..763621171 100644 --- a/rtengine/stdimagesource.cc +++ b/rtengine/stdimagesource.cc @@ -366,7 +366,7 @@ ColorTemp StdImageSource::getSpotWB (std::vector &red, std::vectorallocate(0, 0); }; diff --git a/rtengine/stdimagesource.h b/rtengine/stdimagesource.h index b88db42c4..9f4fbdfbe 100644 --- a/rtengine/stdimagesource.h +++ b/rtengine/stdimagesource.h @@ -118,7 +118,7 @@ public: void getRawValues(int x, int y, int rotate, int &R, int &G, int &B) override { R = G = B = 0;} - void flushRGB () override; + void flush () override; void captureSharpening(const procparams::CaptureSharpeningParams &sharpeningParams, bool showMask, double &conrastThreshold, double &radius) override {}; }; From 28cff72eb0bd2f18db20c1935614c878034a966e Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Fri, 28 Feb 2020 20:18:45 +0100 Subject: [PATCH 02/13] rawimagesource.cc : cleanup, also speedup and bugfix for ItcWB, #5676, #5675 --- rtengine/LUT.h | 1 - rtengine/color.cc | 10 +- rtengine/color.h | 2 +- rtengine/rawimagesource.cc | 3322 +++++++++--------------------------- 4 files changed, 783 insertions(+), 2552 deletions(-) diff --git a/rtengine/LUT.h b/rtengine/LUT.h index a80e5996d..6ba7d570f 100644 --- a/rtengine/LUT.h +++ b/rtengine/LUT.h @@ -254,7 +254,6 @@ public: } // handy to sum up per thread histograms. #pragma omp simd speeds up the loop by about factor 3 for LUTu (uint32_t). - template::value>::type> LUT & operator+=(const LUT& rhs) { if (rhs.size == this->size) { diff --git a/rtengine/color.cc b/rtengine/color.cc index ed617057f..89be69e9d 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -941,12 +941,12 @@ void Color::rgbxyz (float r, float g, float b, float &x, float &y, float &z, con z = ((xyz_rgb[2][0] * r + xyz_rgb[2][1] * g + xyz_rgb[2][2] * b)) ; } -void Color::rgbxyY(float r, float g, float b, float &x, float &y, float &Y, float &xx, float &yy, float &zz, const double xyz_rgb[3][3]) +void Color::rgbxyY(float r, float g, float b, float &x, float &y, float &Y, const float xyz_rgb[3][3]) { - xx = ((xyz_rgb[0][0] * r + xyz_rgb[0][1] * g + xyz_rgb[0][2] * b)) ; - yy = ((xyz_rgb[1][0] * r + xyz_rgb[1][1] * g + xyz_rgb[1][2] * b)) ; - zz = ((xyz_rgb[2][0] * r + xyz_rgb[2][1] * g + xyz_rgb[2][2] * b)) ; - float som = xx + yy + zz; + const float xx = xyz_rgb[0][0] * r + xyz_rgb[0][1] * g + xyz_rgb[0][2] * b; + const float yy = xyz_rgb[1][0] * r + xyz_rgb[1][1] * g + xyz_rgb[1][2] * b; + const float zz = xyz_rgb[2][0] * r + xyz_rgb[2][1] * g + xyz_rgb[2][2] * b; + const float som = xx + yy + zz; x = xx / som; y = yy / som; Y = yy / 65535.f; diff --git a/rtengine/color.h b/rtengine/color.h index 3f63ad312..045e062ad 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -602,7 +602,7 @@ public: * @param xyz_rgb[3][3] transformation matrix to use for the conversion */ static void rgbxyz (float r, float g, float b, float &x, float &y, float &z, const double xyz_rgb[3][3]); - static void rgbxyY(float r, float g, float b, float &x, float &y, float &Y, float &xx, float &yy, float &zz, const double xyz_rgb[3][3]); + static void rgbxyY(float r, float g, float b, float &x, float &y, float &Y, const float xyz_rgb[3][3]); static void rgbxyz (float r, float g, float b, float &x, float &y, float &z, const float xyz_rgb[3][3]); #ifdef __SSE2__ static void rgbxyz (vfloat r, vfloat g, vfloat b, vfloat &x, vfloat &y, vfloat &z, const vfloat xyz_rgb[3][3]); diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index b55ec4bf1..765d0c0ac 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -195,7 +195,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->b(row, col) = (blue[j] + image->b(row + 1, col)) / 2; } - if(i == 2 && oddHeight) { + if (i == 2 && oddHeight) { row = 2 * imheight; for (int j = 0; j < imwidth; j++) { @@ -232,7 +232,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(row, col) = MAX(0.f, -0.0625f * (green[j] + image->g(row + 3, col)) + 0.5625f * (image->g(row - 1, col) + image->g(row + 1, col))); image->b(row, col) = MAX(0.f, -0.0625f * (blue[j] + image->b(row + 3, col)) + 0.5625f * (image->b(row - 1, col) + image->b(row + 1, col))); - if(clip) { + if (clip) { image->r(row, col) = MIN(image->r(row, col), rtengine::MAXVALF); image->g(row, col) = MIN(image->g(row, col), rtengine::MAXVALF); image->b(row, col) = MIN(image->b(row, col), rtengine::MAXVALF); @@ -243,7 +243,7 @@ void transLineD1x (const float* const red, const float* const green, const float break; case TR_R90: // rotate right - if( i == 0) { + if (i == 0) { for (int j = 0; j < imwidth; j++) { image->r(j, 2 * imheight - 1) = red[j]; image->g(j, 2 * imheight - 1) = green[j]; @@ -265,7 +265,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(j, col) = (green[j] + image->g(j, col + 1)) / 2; image->b(j, col) = (blue[j] + image->b(j, col + 1)) / 2; - if(oddHeight && i == 2) { + if (oddHeight && i == 2) { image->r(j, 2 * imheight) = (red[j] + image->r(j, 2 * imheight - 2)) / 2; image->g(j, 2 * imheight) = (green[j] + image->g(j, 2 * imheight - 2)) / 2; image->b(j, 2 * imheight) = (blue[j] + image->b(j, 2 * imheight - 2)) / 2; @@ -295,7 +295,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(j, col) = MAX(0.f, -0.0625f * (green[j] + image->g(j, col + 3)) + 0.5625f * (image->g(j, col - 1) + image->g(j, col + 1))); image->b(j, col) = MAX(0.f, -0.0625f * (blue[j] + image->b(j, col + 3)) + 0.5625f * (image->b(j, col - 1) + image->b(j, col + 1))); - if(clip) { + if (clip) { image->r(j, col) = MIN(image->r(j, col), rtengine::MAXVALF); image->g(j, col) = MIN(image->g(j, col), rtengine::MAXVALF); image->b(j, col) = MIN(image->b(j, col), rtengine::MAXVALF); @@ -327,7 +327,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(row, 2 * i - 3) = MAX(0.f, -0.0625f * (green[j] + image->g(row, 2 * i - 6)) + 0.5625f * (image->g(row, 2 * i - 2) + image->g(row, 2 * i - 4))); image->b(row, 2 * i - 3) = MAX(0.f, -0.0625f * (blue[j] + image->b(row, 2 * i - 6)) + 0.5625f * (image->b(row, 2 * i - 2) + image->b(row, 2 * i - 4))); - if(clip) { + if (clip) { image->r(row, 2 * i - 3) = MIN(image->r(row, 2 * i - 3), rtengine::MAXVALF); image->g(row, 2 * i - 3) = MIN(image->g(row, 2 * i - 3), rtengine::MAXVALF); image->b(row, 2 * i - 3) = MIN(image->b(row, 2 * i - 3), rtengine::MAXVALF); @@ -345,7 +345,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(row, 2 * i - 1) = MAX(0.f, -0.0625f * (green[j] + image->g(row, 2 * i - 4)) + 0.5625f * (image->g(row, 2 * i) + image->g(row, 2 * i - 2))); image->b(row, 2 * i - 1) = MAX(0.f, -0.0625f * (blue[j] + image->b(row, 2 * i - 4)) + 0.5625f * (image->b(row, 2 * i) + image->b(row, 2 * i - 2))); - if(clip) { + if (clip) { image->r(j, 2 * i - 1) = MIN(image->r(j, 2 * i - 1), rtengine::MAXVALF); image->g(j, 2 * i - 1) = MIN(image->g(j, 2 * i - 1), rtengine::MAXVALF); image->b(j, 2 * i - 1) = MIN(image->b(j, 2 * i - 1), rtengine::MAXVALF); @@ -383,7 +383,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(2 * i - 3, j) = MAX(0.f, -0.0625f * (green[j] + image->g(2 * i - 6, j)) + 0.5625f * (image->g(2 * i - 2, j) + image->g(2 * i - 4, j))); image->b(2 * i - 3, j) = MAX(0.f, -0.0625f * (blue[j] + image->b(2 * i - 6, j)) + 0.5625f * (image->b(2 * i - 2, j) + image->b(2 * i - 4, j))); - if(clip) { + if (clip) { image->r(2 * i - 3, j) = MIN(image->r(2 * i - 3, j), rtengine::MAXVALF); image->g(2 * i - 3, j) = MIN(image->g(2 * i - 3, j), rtengine::MAXVALF); image->b(2 * i - 3, j) = MIN(image->b(2 * i - 3, j), rtengine::MAXVALF); @@ -397,7 +397,7 @@ void transLineD1x (const float* const red, const float* const green, const float image->g(2 * i - 1, j) = MAX(0.f, -0.0625f * (green[j] + image->g(2 * i - 4, j)) + 0.5625f * (image->g(2 * i, j) + image->g(2 * i - 2, j))); image->b(2 * i - 1, j) = MAX(0.f, -0.0625f * (blue[j] + image->b(2 * i - 4, j)) + 0.5625f * (image->b(2 * i, j) + image->b(2 * i - 2, j))); - if(clip) { + if (clip) { image->r(2 * i - 1, j) = MIN(image->r(2 * i - 1, j), rtengine::MAXVALF); image->g(2 * i - 1, j) = MIN(image->g(2 * i - 1, j), rtengine::MAXVALF); image->b(2 * i - 1, j) = MIN(image->b(2 * i - 1, j), rtengine::MAXVALF); @@ -465,7 +465,7 @@ RawImageSource::RawImageSource () { embProfile = nullptr; rgbSourceModified = false; - for(int i = 0; i < 4; ++i) { + for (int i = 0; i < 4; ++i) { psRedBrightness[i] = psGreenBrightness[i] = psBlueBrightness[i] = 1.f; } } @@ -480,11 +480,11 @@ RawImageSource::~RawImageSource () delete greenCache; delete blueCache; - for(size_t i = 0; i < numFrames; ++i) { + for (size_t i = 0; i < numFrames; ++i) { delete riFrames[i]; } - for(size_t i = 0; i + 1 < numFrames; ++i) { + for (size_t i = 0; i + 1 < numFrames; ++i) { delete rawDataBuffer[i]; } @@ -550,11 +550,11 @@ void RawImageSource::transformRect (const PreviewProps &pp, int tran, int &ssx1, sh = w; } - if( pp_width > sw - 2 * border) { + if (pp_width > sw - 2 * border) { pp_width = sw - 2 * border; } - if( pp_height > sh - 2 * border) { + if (pp_height > sh - 2 * border) { pp_height = sh - 2 * border; } @@ -594,16 +594,16 @@ void RawImageSource::transformRect (const PreviewProps &pp, int tran, int &ssx1, // atszamoljuk a koordinatakat fuji-ra: // recalculate the coordinates fuji-ra: ssx1 = (sx1 + sy1) / 2; - ssy1 = (sy1 - sx2 ) / 2 + ri->get_FujiWidth(); + ssy1 = (sy1 - sx2) / 2 + ri->get_FujiWidth(); int ssx2 = (sx2 + sy2) / 2 + 1; int ssy2 = (sy2 - sx1) / 2 + ri->get_FujiWidth(); - fw = (sx2 - sx1) / 2 / pp.getSkip(); - width = (ssx2 - ssx1) / pp.getSkip() + ((ssx2 - ssx1) % pp.getSkip() > 0); + fw = (sx2 - sx1) / 2 / pp.getSkip(); + width = (ssx2 - ssx1) / pp.getSkip() + ((ssx2 - ssx1) % pp.getSkip() > 0); height = (ssy2 - ssy1) / pp.getSkip() + ((ssy2 - ssy1) % pp.getSkip() > 0); } else { ssx1 = sx1; ssy1 = sy1; - width = (sx2 + 1 - sx1) / pp.getSkip() + ((sx2 + 1 - sx1) % pp.getSkip() > 0); + width = (sx2 + 1 - sx1) / pp.getSkip() + ((sx2 + 1 - sx1) % pp.getSkip() > 0); height = (sy2 + 1 - sy1) / pp.getSkip() + ((sy2 + 1 - sy1) % pp.getSkip() > 0); } } @@ -636,7 +636,7 @@ float calculate_scale_mul(float scale_mul[4], const float pre_mul_[4], const flo return gain; } -void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const ToneCurveParams &hrp, const RAWParams &raw ) +void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const ToneCurveParams &hrp, const RAWParams &raw) { MyMutex::MyLock lock(getImageMutex); @@ -841,9 +841,9 @@ void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* ima hlRecovery (hrp.method, line_red, line_grn, line_blue, imwidth, hlmax); } - if(d1x) { + if (d1x) { transLineD1x (line_red, line_grn, line_blue, ix, image, tran, imwidth, imheight, d1xHeightOdd, doClip); - } else if(fuji) { + } else if (fuji) { transLineFuji (line_red, line_grn, line_blue, ix, image, tran, imheight, fw); } else { transLineStandard (line_red, line_grn, line_blue, ix, image, tran, imwidth, imheight); @@ -913,7 +913,7 @@ void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* ima } // Colour correction (only when running on full resolution) - if(pp.getSkip() == 1) { + if (pp.getSkip() == 1) { switch(ri->getSensorType()) { case ST_BAYER: processFalseColorCorrection (image, raw.bayersensor.ccSteps); @@ -1029,7 +1029,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) errCode = 0; - if(numFrames >= 7) { + if (numFrames >= 7) { // special case to avoid crash when loading Hasselblad H6D-100cMS pixelshift files // limit to 6 frames and skip first frame, as first frame is not bayer if (firstFrameOnly) { @@ -1045,8 +1045,8 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) #ifdef _OPENMP #pragma omp for nowait #endif - for(unsigned int i = 0; i < numFrames; ++i) { - if(i == 0) { + for (unsigned int i = 0; i < numFrames; ++i) { + if (i == 0) { riFrames[i] = ri; errCodeThr = riFrames[i]->loadRaw (true, i + 1, true, plistener, 0.8); } else { @@ -1061,7 +1061,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) errCode = errCodeThr ? errCodeThr : errCode; } } - } else if(numFrames > 1) { + } else if (numFrames > 1) { #ifdef _OPENMP #pragma omp parallel #endif @@ -1070,8 +1070,8 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) #ifdef _OPENMP #pragma omp for nowait #endif - for(unsigned int i = 0; i < numFrames; ++i) { - if(i == 0) { + for (unsigned int i = 0; i < numFrames; ++i) { + if (i == 0) { riFrames[i] = ri; errCodeThr = riFrames[i]->loadRaw (true, i, true, plistener, 0.8); } else { @@ -1091,16 +1091,16 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) errCode = riFrames[0]->loadRaw (true, 0, true, plistener, 0.8); } - if(!errCode) { - for(unsigned int i = 0; i < numFrames; ++i) { + if (!errCode) { + for (unsigned int i = 0; i < numFrames; ++i) { riFrames[i]->compress_image(i); } } else { return errCode; } - if(numFrames > 1 ) { // this disables multi frame support for Fuji S5 until I found a solution to handle different dimensions - if(riFrames[0]->get_width() != riFrames[1]->get_width() || riFrames[0]->get_height() != riFrames[1]->get_height()) { + if (numFrames > 1) { // this disables multi frame support for Fuji S5 until I found a solution to handle different dimensions + if (riFrames[0]->get_width() != riFrames[1]->get_width() || riFrames[0]->get_height() != riFrames[1]->get_height()) { numFrames = 1; } } @@ -1123,15 +1123,15 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) // first arg is matrix, second arg is inverse inverse33 (imatrices.rgb_cam, imatrices.cam_rgb); - d1x = ! ri->get_model().compare("D1X"); + d1x = ! ri->get_model().compare("D1X"); - if(ri->getSensorType() == ST_FUJI_XTRANS) { + if (ri->getSensorType() == ST_FUJI_XTRANS) { border = 7; - } else if(ri->getSensorType() == ST_FOVEON) { + } else if (ri->getSensorType() == ST_FOVEON) { border = 0; } - if ( ri->get_profile() ) { + if (ri->get_profile()) { embProfile = cmsOpenProfileFromMem (ri->get_profile(), ri->get_profileLen()); } @@ -1150,7 +1150,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) // First we get the "as shot" ("Camera") white balance and store it float pre_mul[4]; // FIXME: get_colorsCoeff not so much used nowadays, when we have calculate_scale_mul() function here - ri->get_colorsCoeff( pre_mul, scale_mul, c_black, false);//modify for black level + ri->get_colorsCoeff(pre_mul, scale_mul, c_black, false);//modify for black level camInitialGain = max(scale_mul[0], scale_mul[1], scale_mul[2], scale_mul[3]) / min(scale_mul[0], scale_mul[1], scale_mul[2], scale_mul[3]); double camwb_red = ri->get_pre_mul(0) / pre_mul[0]; @@ -1166,7 +1166,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) { // ...then we re-get the constants but now with auto which gives us better demosaicing and CA auto-correct // performance for strange white balance settings (such as UniWB) - ri->get_colorsCoeff( ref_pre_mul, scale_mul, c_black, true); + ri->get_colorsCoeff(ref_pre_mul, scale_mul, c_black, true); refwb_red = ri->get_pre_mul(0) / ref_pre_mul[0]; refwb_green = ri->get_pre_mul(1) / ref_pre_mul[1]; refwb_blue = ri->get_pre_mul(2) / ref_pre_mul[2]; @@ -1187,9 +1187,9 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) ColorTemp d50wb = ColorTemp(5000.0, 1.0, 1.0, "Custom"); double rm,gm,bm,r,g,b; d50wb.getMultipliers(r, g, b); - camwb_red = imatrices.cam_rgb[0][0]*r + imatrices.cam_rgb[0][1]*g + imatrices.cam_rgb[0][2]*b; + camwb_red = imatrices.cam_rgb[0][0]*r + imatrices.cam_rgb[0][1]*g + imatrices.cam_rgb[0][2]*b; camwb_green = imatrices.cam_rgb[1][0]*r + imatrices.cam_rgb[1][1]*g + imatrices.cam_rgb[1][2]*b; - camwb_blue = imatrices.cam_rgb[2][0]*r + imatrices.cam_rgb[2][1]*g + imatrices.cam_rgb[2][2]*b; + camwb_blue = imatrices.cam_rgb[2][0]*r + imatrices.cam_rgb[2][1]*g + imatrices.cam_rgb[2][2]*b; double pre_mul[3], dmax = 0; pre_mul[0] = ri->get_pre_mul(0) / camwb_red; pre_mul[1] = ri->get_pre_mul(1) / camwb_green; @@ -1212,7 +1212,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) initialGain = 1.0 / min(pre_mul[0], pre_mul[1], pre_mul[2]); }*/ - for(unsigned int i = 0;i < numFrames; ++i) { + for (unsigned int i = 0;i < numFrames; ++i) { riFrames[i]->set_prefilters(); } @@ -1234,7 +1234,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly) plistener = nullptr; // This must be reset, because only load() is called through progressConnector t2.set(); - if( settings->verbose ) { + if (settings->verbose) { printf("Load %s: %d usec\n", fname.c_str(), t2.etime(t1)); } @@ -1253,27 +1253,27 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le RawImage *rid = nullptr; if (!raw.df_autoselect) { - if( !raw.dark_frame.empty()) { - rid = dfm.searchDarkFrame( raw.dark_frame ); + if (!raw.dark_frame.empty()) { + rid = dfm.searchDarkFrame(raw.dark_frame); } } else { rid = dfm.searchDarkFrame(idata->getMake(), idata->getModel(), idata->getISOSpeed(), idata->getShutterSpeed(), idata->getDateTimeAsTS()); } - if( rid && settings->verbose) { - printf( "Subtracting Darkframe:%s\n", rid->get_filename().c_str()); + if (rid && settings->verbose) { + printf("Subtracting Darkframe:%s\n", rid->get_filename().c_str()); } std::unique_ptr bitmapBads; int totBP = 0; // Hold count of bad pixels to correct - if(ri->zeroIsBad()) { // mark all pixels with value zero as bad, has to be called before FF and DF. dcraw sets this flag only for some cameras (mainly Panasonic and Leica) + if (ri->zeroIsBad()) { // mark all pixels with value zero as bad, has to be called before FF and DF. dcraw sets this flag only for some cameras (mainly Panasonic and Leica) bitmapBads.reset(new PixelsMap(W, H)); totBP = findZeroPixels(*(bitmapBads.get())); - if( settings->verbose) { - printf( "%d pixels with value zero marked as bad pixels\n", totBP); + if (settings->verbose) { + printf("%d pixels with value zero marked as bad pixels\n", totBP); } } @@ -1281,28 +1281,28 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le RawImage *rif = nullptr; if (!raw.ff_AutoSelect) { - if( !raw.ff_file.empty()) { - rif = ffm.searchFlatField( raw.ff_file ); + if (!raw.ff_file.empty()) { + rif = ffm.searchFlatField(raw.ff_file); } } else { - rif = ffm.searchFlatField( idata->getMake(), idata->getModel(), idata->getLens(), idata->getFocalLen(), idata->getFNumber(), idata->getDateTimeAsTS()); + rif = ffm.searchFlatField(idata->getMake(), idata->getModel(), idata->getLens(), idata->getFocalLen(), idata->getFNumber(), idata->getDateTimeAsTS()); } bool hasFlatField = (rif != nullptr); - if( hasFlatField && settings->verbose) { - printf( "Flat Field Correction:%s\n", rif->get_filename().c_str()); + if (hasFlatField && settings->verbose) { + printf("Flat Field Correction:%s\n", rif->get_filename().c_str()); } - if(numFrames == 4) { + if (numFrames == 4) { int bufferNumber = 0; - for(unsigned int i=0; i<4; ++i) { - if(i==currFrame) { + for (unsigned int i=0; i<4; ++i) { + if (i==currFrame) { copyOriginalPixels(raw, ri, rid, rif, rawData); rawDataFrames[i] = &rawData; } else { - if(!rawDataBuffer[bufferNumber]) { + if (!rawDataBuffer[bufferNumber]) { rawDataBuffer[bufferNumber] = new array2D; } rawDataFrames[i] = rawDataBuffer[bufferNumber]; @@ -1311,7 +1311,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } } } else if (numFrames == 2 && currFrame == 2) { // average the frames - if(!rawDataBuffer[0]) { + if (!rawDataBuffer[0]) { rawDataBuffer[0] = new array2D; } rawDataFrames[1] = rawDataBuffer[0]; @@ -1330,16 +1330,16 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le // Always correct camera badpixels from .badpixels file - std::vector *bp = dfm.getBadPixels( ri->get_maker(), ri->get_model(), idata->getSerialNumber() ); + std::vector *bp = dfm.getBadPixels(ri->get_maker(), ri->get_model(), idata->getSerialNumber()); - if( bp ) { - if(!bitmapBads) { + if (bp) { + if (!bitmapBads) { bitmapBads.reset(new PixelsMap(W, H)); } totBP += bitmapBads->set(*bp); - if( settings->verbose ) { + if (settings->verbose) { std::cout << "Correcting " << bp->size() << " pixels from .badpixels" << std::endl; } } @@ -1347,30 +1347,30 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le // If darkframe selected, correct hotpixels found on darkframe bp = nullptr; - if( raw.df_autoselect ) { + if (raw.df_autoselect) { bp = dfm.getHotPixels(idata->getMake(), idata->getModel(), idata->getISOSpeed(), idata->getShutterSpeed(), idata->getDateTimeAsTS()); - } else if( !raw.dark_frame.empty() ) { - bp = dfm.getHotPixels( raw.dark_frame ); + } else if (!raw.dark_frame.empty()) { + bp = dfm.getHotPixels(raw.dark_frame); } - if(bp) { - if(!bitmapBads) { + if (bp) { + if (!bitmapBads) { bitmapBads.reset(new PixelsMap(W, H)); } totBP += bitmapBads->set(*bp); - if( settings->verbose && !bp->empty()) { + if (settings->verbose && !bp->empty()) { std::cout << "Correcting " << bp->size() << " hotpixels from darkframe" << std::endl; } } - if(numFrames == 4) { - for(int i=0; i<4; ++i) { - scaleColors( 0, 0, W, H, raw, *rawDataFrames[i]); + if (numFrames == 4) { + for (int i=0; i<4; ++i) { + scaleColors(0, 0, W, H, raw, *rawDataFrames[i]); } } else { - scaleColors( 0, 0, W, H, raw, rawData); //+ + raw parameters for black level(raw.blackxx) + scaleColors(0, 0, W, H, raw, rawData); //+ + raw parameters for black level(raw.blackxx) } // Correct vignetting of lens profile @@ -1389,14 +1389,14 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le if (pmap) { LensCorrection &map = *pmap; if (ri->getSensorType() == ST_BAYER || ri->getSensorType() == ST_FUJI_XTRANS || ri->get_colors() == 1) { - if(numFrames == 4) { - for(int i = 0; i < 4; ++i) { + if (numFrames == 4) { + for (int i = 0; i < 4; ++i) { map.processVignette(W, H, *rawDataFrames[i]); } } else { map.processVignette(W, H, rawData); } - } else if(ri->get_colors() == 3) { + } else if (ri->get_colors() == 3) { map.processVignette3Channels(W, H, rawData); } } @@ -1404,21 +1404,21 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le defGain = 0.0;//log(initialGain) / log(2.0); - if ( ri->getSensorType() == ST_BAYER && (raw.hotPixelFilter > 0 || raw.deadPixelFilter > 0)) { + if (ri->getSensorType() == ST_BAYER && (raw.hotPixelFilter > 0 || raw.deadPixelFilter > 0)) { if (plistener) { plistener->setProgressStr ("PROGRESSBAR_HOTDEADPIXELFILTER"); plistener->setProgress (0.0); } - if(!bitmapBads) { + if (!bitmapBads) { bitmapBads.reset(new PixelsMap(W, H)); } - int nFound = findHotDeadPixels(*(bitmapBads.get()), raw.hotdeadpix_thresh, raw.hotPixelFilter, raw.deadPixelFilter ); + int nFound = findHotDeadPixels(*(bitmapBads.get()), raw.hotdeadpix_thresh, raw.hotPixelFilter, raw.deadPixelFilter); totBP += nFound; - if( settings->verbose && nFound > 0) { - printf( "Correcting %d hot/dead pixels found inside image\n", nFound ); + if (settings->verbose && nFound > 0) { + printf("Correcting %d hot/dead pixels found inside image\n", nFound); } } @@ -1457,13 +1457,13 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le return cc && cc->get_globalGreenEquilibration(); }; - if ( ri->getSensorType() == ST_BAYER && (raw.bayersensor.greenthresh || (globalGreenEq() && raw.bayersensor.method != RAWParams::BayerSensor::getMethodString( RAWParams::BayerSensor::Method::VNG4))) ) { + if (ri->getSensorType() == ST_BAYER && (raw.bayersensor.greenthresh || (globalGreenEq() && raw.bayersensor.method != RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::VNG4)))) { if (settings->verbose) { printf("Performing global green equilibration...\n"); } // global correction - if(numFrames == 4) { - for(int i = 0; i < 4; ++i) { + if (numFrames == 4) { + for (int i = 0; i < 4; ++i) { green_equilibrate_global(*rawDataFrames[i]); } } else { @@ -1471,7 +1471,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } } - if ( ri->getSensorType() == ST_BAYER && raw.bayersensor.greenthresh > 0) { + if (ri->getSensorType() == ST_BAYER && raw.bayersensor.greenthresh > 0) { if (plistener) { plistener->setProgressStr ("PROGRESSBAR_GREENEQUIL"); plistener->setProgress (0.0); @@ -1479,8 +1479,8 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le GreenEqulibrateThreshold thresh(0.01 * raw.bayersensor.greenthresh); - if(numFrames == 4) { - for(int i = 0; i < 4; ++i) { + if (numFrames == 4) { + for (int i = 0; i < 4; ++i) { green_equilibrate(thresh, *rawDataFrames[i]); } } else { @@ -1489,23 +1489,23 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } - if( totBP ) { - if ( ri->getSensorType() == ST_BAYER ) { - if(numFrames == 4) { - for(int i = 0; i < 4; ++i) { + if (totBP) { + if (ri->getSensorType() == ST_BAYER) { + if (numFrames == 4) { + for (int i = 0; i < 4; ++i) { interpolateBadPixelsBayer(*(bitmapBads.get()), *rawDataFrames[i]); } } else { interpolateBadPixelsBayer(*(bitmapBads.get()), rawData); } - } else if ( ri->getSensorType() == ST_FUJI_XTRANS ) { + } else if (ri->getSensorType() == ST_FUJI_XTRANS) { interpolateBadPixelsXtrans(*(bitmapBads.get())); } else { interpolateBadPixelsNColours(*(bitmapBads.get()), ri->get_colors()); } } - if ( ri->getSensorType() == ST_BAYER && raw.bayersensor.linenoise > 0 ) { + if (ri->getSensorType() == ST_BAYER && raw.bayersensor.linenoise > 0) { if (plistener) { plistener->setProgressStr ("PROGRESSBAR_LINEDENOISE"); plistener->setProgress (0.0); @@ -1522,15 +1522,15 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le cfa_linedn(0.00002 * (raw.bayersensor.linenoise), int(raw.bayersensor.linenoiseDirection) & int(RAWParams::BayerSensor::LineNoiseDirection::VERTICAL), int(raw.bayersensor.linenoiseDirection) & int(RAWParams::BayerSensor::LineNoiseDirection::HORIZONTAL), *line_denoise_rowblender); } - if ( (raw.ca_autocorrect || fabs(raw.cared) > 0.001 || fabs(raw.cablue) > 0.001) && ri->getSensorType() == ST_BAYER ) { // Auto CA correction disabled for X-Trans, for now... + if ((raw.ca_autocorrect || std::fabs(raw.cared) > 0.001 || std::fabs(raw.cablue) > 0.001) && ri->getSensorType() == ST_BAYER) { // Auto CA correction disabled for X-Trans, for now... if (plistener) { plistener->setProgressStr ("PROGRESSBAR_RAWCACORR"); plistener->setProgress (0.0); } - if(numFrames == 4) { + if (numFrames == 4) { double fitParams[64]; float *buffer = CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, raw.ca_avoidcolourshift, *rawDataFrames[0], fitParams, false, true, nullptr, false, options.chunkSizeCA, options.measure); - for(int i = 1; i < 3; ++i) { + for (int i = 1; i < 3; ++i) { CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, raw.ca_avoidcolourshift, *rawDataFrames[i], fitParams, true, false, buffer, false, options.chunkSizeCA, options.measure); } CA_correct_RT(raw.ca_autocorrect, raw.caautoiterations, raw.cared, raw.cablue, raw.ca_avoidcolourshift, *rawDataFrames[3], fitParams, true, false, buffer, true, options.chunkSizeCA, options.measure); @@ -1539,7 +1539,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } } - if(prepareDenoise && dirpyrdenoiseExpComp == RT_INFINITY) { + if (prepareDenoise && dirpyrdenoiseExpComp == RT_INFINITY) { LUTu aehist; int aehistcompr; double clip = 0; @@ -1550,7 +1550,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le t2.set(); - if( settings->verbose ) { + if (settings->verbose) { printf("Preprocessing: %d usec\n", t2.etime(t1)); } @@ -1565,13 +1565,13 @@ void RawImageSource::demosaic(const RAWParams &raw, bool autoContrast, double &c t1.set(); if (ri->getSensorType() == ST_BAYER) { - if ( raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::HPHD) ) { + if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::HPHD)) { hphd_demosaic (); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::VNG4) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::VNG4)) { vng4_demosaic (rawData, red, green, blue); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::AHD) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::AHD)) { ahd_demosaic (); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::AMAZE) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::AMAZE)) { amaze_demosaic_RT (0, 0, W, H, rawData, red, green, blue, options.chunkSizeAMAZE, options.measure); } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::AMAZEVNG4) || raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::DCBVNG4) @@ -1582,9 +1582,9 @@ void RawImageSource::demosaic(const RAWParams &raw, bool autoContrast, double &c } else { dual_demosaic_RT (true, raw, W, H, rawData, red, green, blue, contrastThreshold, true); } - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::PIXELSHIFT) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::PIXELSHIFT)) { pixelshift(0, 0, W, H, raw, currFrame, ri->get_maker(), ri->get_model(), raw.expos); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::DCB) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::DCB)) { dcb_demosaic(raw.bayersensor.dcb_iterations, raw.bayersensor.dcb_enhance); } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::EAHD)) { eahd_demosaic (); @@ -1592,21 +1592,21 @@ void RawImageSource::demosaic(const RAWParams &raw, bool autoContrast, double &c igv_interpolate(W, H); } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::LMMSE)) { lmmse_interpolate_omp(W, H, rawData, red, green, blue, raw.bayersensor.lmmse_iterations); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST)) { fast_demosaic(); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)) { nodemosaic(true); - } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::RCD) ) { + } else if (raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::RCD)) { rcd_demosaic(options.chunkSizeRCD, options.measure); } else { nodemosaic(false); } } else if (ri->getSensorType() == ST_FUJI_XTRANS) { - if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST) ) { + if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST)) { fast_xtrans_interpolate(rawData, red, green, blue); } else if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::ONE_PASS)) { xtrans_interpolate(1, false, options.chunkSizeXT, options.measure); - } else if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::THREE_PASS) ) { + } else if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::THREE_PASS)) { xtrans_interpolate(3, true, options.chunkSizeXT, options.measure); } else if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FOUR_PASS) || raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::TWO_PASS)) { if (!autoContrast) { @@ -1615,7 +1615,7 @@ void RawImageSource::demosaic(const RAWParams &raw, bool autoContrast, double &c } else { dual_demosaic_RT (false, raw, W, H, rawData, red, green, blue, contrastThreshold, true); } - } else if(raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO) ) { + } else if (raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) { nodemosaic(true); } else { nodemosaic(false); @@ -1673,7 +1673,7 @@ void RawImageSource::demosaic(const RAWParams &raw, bool autoContrast, double &c delete blueCache; blueCache = nullptr; } - if( settings->verbose ) { + if (settings->verbose) { if (getSensorType() == ST_BAYER) { printf("Demosaicing Bayer data: %s - %d usec\n", raw.bayersensor.method.c_str(), t2.etime(t1)); } else if (getSensorType() == ST_FUJI_XTRANS) { @@ -1695,20 +1695,20 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con LUTf *retinexgamtab = nullptr;//gamma before and after Retinex to restore tones LUTf lutTonereti; - if(retinexParams.gammaretinex == "low") { + if (retinexParams.gammaretinex == "low") { retinexgamtab = &(Color::gammatab_115_2); - } else if(retinexParams.gammaretinex == "mid") { + } else if (retinexParams.gammaretinex == "mid") { retinexgamtab = &(Color::gammatab_13_2); - } else if(retinexParams.gammaretinex == "hig") { + } else if (retinexParams.gammaretinex == "hig") { retinexgamtab = &(Color::gammatab_145_3); - } else if(retinexParams.gammaretinex == "fre") { + } else if (retinexParams.gammaretinex == "fre") { GammaValues g_a; double pwr = 1.0 / retinexParams.gam; double gamm = retinexParams.gam; double ts = retinexParams.slope; double gamm2 = retinexParams.gam; - if(gamm2 < 1.) { + if (gamm2 < 1.) { std::swap(pwr, gamm); } @@ -1719,7 +1719,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con double start; double add; - if(gamm2 < 1.) { + if (gamm2 < 1.) { start = g_a[2]; add = g_a[4]; } else { @@ -1735,7 +1735,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con double val = (i) / 65535.; double x; - if(gamm2 < 1.) { + if (gamm2 < 1.) { x = Color::igammareti (val, gamm, start, ts, mul , add); } else { x = Color::gammareti (val, gamm, start, ts, mul , add); @@ -1764,15 +1764,15 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con printf("rr2=%f gg2=%f bb2=%f \n",rr,gg,bb); */ /* - if(retinexParams.highlig < 100 && retinexParams.retinexMethod == "highliplus") {//try to recover magenta...very difficult ! + if (retinexParams.highlig < 100 && retinexParams.retinexMethod == "highliplus") {//try to recover magenta...very difficult ! float hig = ((float)retinexParams.highlig)/100.f; float higgb = ((float)retinexParams.grbl)/100.f; #ifdef _OPENMP #pragma omp parallel for #endif - for (int i = border; i < H - border; i++ ) { - for (int j = border; j < W - border; j++ ) { + for (int i = border; i < H - border; i++) { + for (int j = border; j < W - border; j++) { float R_,G_,B_; R_=red[i][j]; G_=green[i][j]; @@ -1780,20 +1780,20 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con //empirical method to find highlight magenta with no conversion RGB and no white balance //red = master Gr and Bl default higgb=0.5 - // if(R_>65535.f*hig && G_ > 65535.f*higgb && B_ > 65535.f*higgb) conversionBuffer[3][i - border][j - border] = R_; + // if (R_>65535.f*hig && G_ > 65535.f*higgb && B_ > 65535.f*higgb) conversionBuffer[3][i - border][j - border] = R_; // else conversionBuffer[3][i - border][j - border] = 0.f; } } } */ - if(retinexParams.gammaretinex != "none" && retinexParams.str != 0 && retinexgamtab) {//gamma + if (retinexParams.gammaretinex != "none" && retinexParams.str != 0 && retinexgamtab) {//gamma #ifdef _OPENMP #pragma omp parallel for #endif - for (int i = border; i < H - border; i++ ) { - for (int j = border; j < W - border; j++ ) { + for (int i = border; i < H - border; i++) { + for (int j = border; j < W - border; j++) { float R_, G_, B_; R_ = red[i][j]; G_ = green[i][j]; @@ -1806,7 +1806,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con } } - if(useHsl) { + if (useHsl) { #ifdef _OPENMP #pragma omp parallel #endif @@ -1814,7 +1814,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con // one LUT per thread LUTu lhist16RETIThr; - if(lhist16RETI) + if (lhist16RETI) { lhist16RETIThr(lhist16RETI.getSize()); lhist16RETIThr.clear(); @@ -1827,7 +1827,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con #pragma omp for #endif - for (int i = border; i < H - border; i++ ) + for (int i = border; i < H - border; i++) { int j = border; #ifdef __SSE2__ @@ -1841,9 +1841,9 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con STVFU(conversionBuffer[2][i - border][j - border], L); STVFU(conversionBuffer[3][i - border][j - border], H); - if(lhist16RETI) { - for(int p = 0; p < 4; p++) { - int pos = ( conversionBuffer[2][i - border][j - border + p]);//histogram in curve HSL + if (lhist16RETI) { + for (int p = 0; p < 4; p++) { + int pos = (conversionBuffer[2][i - border][j - border + p]);//histogram in curve HSL lhist16RETIThr[pos]++; } } @@ -1858,7 +1858,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con L *= 32768.f; conversionBuffer[2][i - border][j - border] = L; - if(lhist16RETI) { + if (lhist16RETI) { int pos = L; lhist16RETIThr[pos]++; } @@ -1868,7 +1868,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con #ifdef _OPENMP #pragma omp critical { - if(lhist16RETI) + if (lhist16RETI) { lhist16RETI += lhist16RETIThr; // Add per Thread LUT to global LUT } @@ -1893,7 +1893,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con // one LUT per thread LUTu lhist16RETIThr; - if(lhist16RETI) { + if (lhist16RETI) { lhist16RETIThr(lhist16RETI.getSize()); lhist16RETIThr.clear(); } @@ -1902,7 +1902,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con #pragma omp for schedule(dynamic,16) #endif - for (int i = border; i < H - border; i++ ) + for (int i = border; i < H - border; i++) for (int j = border; j < W - border; j++) { float X, Y, Z, L, aa, bb; //rgb=>lab @@ -1914,9 +1914,9 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con conversionBuffer[2][i - border][j - border] = L; conversionBuffer[3][i - border][j - border] = xatan2f(bb, aa); -// if(R_>40000.f && G_ > 30000.f && B_ > 30000.f) conversionBuffer[3][i - border][j - border] = R_; +// if (R_>40000.f && G_ > 30000.f && B_ > 30000.f) conversionBuffer[3][i - border][j - border] = R_; // else conversionBuffer[3][i - border][j - border] = 0.f; - if(lhist16RETI) { + if (lhist16RETI) { int pos = L; lhist16RETIThr[pos]++;//histogram in Curve Lab } @@ -1925,7 +1925,7 @@ void RawImageSource::retinexPrepareBuffers(const ColorManagementParams& cmp, con #ifdef _OPENMP #pragma omp critical { - if(lhist16RETI) { + if (lhist16RETI) { lhist16RETI += lhist16RETIThr; // Add per Thread LUT to global LUT } } @@ -1942,7 +1942,7 @@ void RawImageSource::retinexPrepareCurves(const RetinexParams &retinexParams, LU { useHsl = (retinexParams.retinexcolorspace == "HSLLOG" || retinexParams.retinexcolorspace == "HSLLIN"); - if(useHsl) { + if (useHsl) { CurveFactory::curveDehaContL (retinexcontlutili, retinexParams.cdHcurve, cdcurve, 1, lhist16RETI, histLRETI); } else { CurveFactory::curveDehaContL (retinexcontlutili, retinexParams.cdcurve, cdcurve, 1, lhist16RETI, histLRETI); @@ -1967,13 +1967,13 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara LUTf *retinexigamtab = nullptr;//gamma before and after Retinex to restore tones - if(deh.gammaretinex == "low") { + if (deh.gammaretinex == "low") { retinexigamtab = &(Color::igammatab_115_2); - } else if(deh.gammaretinex == "mid") { + } else if (deh.gammaretinex == "mid") { retinexigamtab = &(Color::igammatab_13_2); - } else if(deh.gammaretinex == "hig") { + } else if (deh.gammaretinex == "hig") { retinexigamtab = &(Color::igammatab_145_3); - } else if(deh.gammaretinex == "fre") { + } else if (deh.gammaretinex == "fre") { GammaValues g_a; double pwr = 1.0 / deh.gam; double gamm = deh.gam; @@ -1981,7 +1981,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara double ts = deh.slope; int mode = 0; - if(gamm2 < 1.) { + if (gamm2 < 1.) { std::swap(pwr, gamm); } @@ -1991,7 +1991,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara double add; double start; - if(gamm2 < 1.) { + if (gamm2 < 1.) { start = g_a[3]; add = g_a[3]; } else { @@ -2004,7 +2004,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara double val = (i) / 65535.; double x; - if(gamm2 < 1.) { + if (gamm2 < 1.) { x = Color::gammareti (val, gamm, start, ts, mul , add); } else { x = Color::igammareti (val, gamm, start, ts, mul , add); @@ -2026,7 +2026,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara LUTf dLcurve; LUTu hist16RET; - if(dehacontlutili && histLRETI) { + if (dehacontlutili && histLRETI) { hist16RET(32768); hist16RET.clear(); histLRETI.clear(); @@ -2058,7 +2058,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara // one LUT per thread LUTu hist16RETThr; - if(hist16RET) { + if (hist16RET) { hist16RETThr(hist16RET.getSize()); hist16RETThr.clear(); } @@ -2067,12 +2067,12 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #pragma omp for #endif - for (int i = 0; i < H - 2 * border; i++ ) - if(dehacontlutili) + for (int i = 0; i < H - 2 * border; i++) + if (dehacontlutili) for (int j = 0; j < W - 2 * border; j++) { LBuffer[i][j] = cdcurve[2.f * temp[i][j]] / 2.f; - if(histLRETI) { + if (histLRETI) { int pos = LBuffer[i][j]; hist16RETThr[pos]++; //histogram in Curve } @@ -2086,13 +2086,13 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #pragma omp critical #endif { - if(hist16RET) { + if (hist16RET) { hist16RET += hist16RETThr; // Add per Thread LUT to global LUT } } } - if(hist16RET) {//update histogram + if (hist16RET) {//update histogram // TODO : When rgbcurvesspeedup branch is merged into master, replace this by the following 1-liner // hist16RET.compressTo(histLRETI); // also remove declaration and init of dLcurve some lines above then and finally remove this comment :) @@ -2110,13 +2110,13 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara MSR(LBuffer, conversionBuffer[2], conversionBuffer[3], mapcurve, mapcontlutili, WNew, HNew, deh, dehatransmissionCurve, dehagaintransmissionCurve, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax); - if(useHsl) { - if(chutili) { + if (useHsl) { + if (chutili) { #ifdef _OPENMP #pragma omp parallel for #endif - for (int i = border; i < H - border; i++ ) { + for (int i = border; i < H - border; i++) { int j = border; for (; j < W - border; j++) { @@ -2132,7 +2132,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #pragma omp parallel for #endif - for (int i = border; i < H - border; i++ ) { + for (int i = border; i < H - border; i++) { int j = border; #ifdef __SSE2__ vfloat c32768 = F2V(32768.f); @@ -2180,7 +2180,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #pragma omp for #endif - for (int i = border; i < H - border; i++ ) { + for (int i = border; i < H - border; i++) { #ifdef __SSE2__ // vectorized precalculation { @@ -2210,7 +2210,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara float HH = xatan2f(bb, aa); atan2Buffer[j - border] = HH; - if(Chprov1 == 0.0f) { + if (Chprov1 == 0.0f) { sincosyBuffer[j - border] = 1.f; sincosxBuffer[j - border] = 0.0f; } else { @@ -2237,7 +2237,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara float HH = xatan2f(bb, aa); float2 sincosval;// = xsincosf(HH); - if(Chprov1 == 0.0f) { + if (Chprov1 == 0.0f) { sincosval.y = 1.f; sincosval.x = 0.0f; } else { @@ -2247,7 +2247,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #endif - if(chutili) { // c=f(H) + if (chutili) { // c=f(H) float valp = float((chcurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f)); Chprov1 *= (1.f + 2.f * valp); } @@ -2275,8 +2275,8 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #ifdef __SSE2__ vfloat wipv[3][3]; - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) { + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { wipv[i][j] = F2V(wiprof[i][j]); } @@ -2285,7 +2285,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara #pragma omp parallel for #endif - for (int i = border; i < H - border; i++ ) { + for (int i = border; i < H - border; i++) { int j = border; #ifdef __SSE2__ @@ -2319,13 +2319,13 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara delete chcurve; } - if(deh.gammaretinex != "none" && deh.str != 0) { //inverse gamma + if (deh.gammaretinex != "none" && deh.str != 0) { //inverse gamma #ifdef _OPENMP #pragma omp parallel for #endif - for (int i = border; i < H - border; i++ ) { - for (int j = border; j < W - border; j++ ) { + for (int i = border; i < H - border; i++) { + for (int j = border; j < W - border; j++) { float R_, G_, B_; R_ = red[i][j]; G_ = green[i][j]; @@ -2341,7 +2341,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara t5.set(); - if( settings->verbose ) { + if (settings->verbose) { printf("Retinex=%d usec\n", t5.etime(t4)); } @@ -2349,7 +2349,7 @@ void RawImageSource::retinex(const ColorManagementParams& cmp, const RetinexPara void RawImageSource::flush() { - for(size_t i = 0; i + 1 < numFrames; ++i) { + for (size_t i = 0; i + 1 < numFrames; ++i) { delete rawDataBuffer[i]; rawDataBuffer[i] = nullptr; } @@ -2385,7 +2385,7 @@ void RawImageSource::flush() void RawImageSource::HLRecovery_Global(const ToneCurveParams &hrp) { if (hrp.hrenabled && hrp.method == "Color") { - if(!rgbSourceModified) { + if (!rgbSourceModified) { if (settings->verbose) { printf ("Applying Highlight Recovery: Color propagation...\n"); } @@ -2400,7 +2400,7 @@ void RawImageSource::HLRecovery_Global(const ToneCurveParams &hrp) /* Copy original pixel data and * subtract dark frame (if present) from current image and apply flat field correction (if present) */ -void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, RawImage *riDark, RawImage *riFlatFile, array2D &rawData ) +void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, RawImage *riDark, RawImage *riFlatFile, array2D &rawData) { const float black[4] = { static_cast(ri->get_cblack(0)), static_cast(ri->get_cblack(1)), @@ -2419,9 +2419,9 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw #endif for (int row = 0; row < H; row++) { const int c0 = FC(row, 0); - const float black0 = black[(c0 == 1 && !(row & 1) ) ? 3 : c0]; + const float black0 = black[(c0 == 1 && !(row & 1)) ? 3 : c0]; const int c1 = FC(row, 1); - const float black1 = black[(c1 == 1 && !(row & 1) ) ? 3 : c1]; + const float black1 = black[(c1 == 1 && !(row & 1)) ? 3 : c1]; int col; for (col = 0; col < W - 1; col += 2) { rawData[row][col] = max(src->data[row][col] + black0 - riDark->data[row][col], 0.0f); @@ -2480,8 +2480,8 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw if (riDark && W == riDark->get_width() && H == riDark->get_height()) { for (int row = 0; row < H; row++) { for (int col = 0; col < W; col++) { - int c = FC(row, col); - int c4 = ( c == 1 && !(row & 1) ) ? 3 : c; + int c = FC(row, col); + int c4 = (c == 1 && !(row & 1)) ? 3 : c; rawData[row][3 * col + 0] = max(src->data[row][3 * col + 0] + black[c4] - riDark->data[row][3 * col + 0], 0.0f); rawData[row][3 * col + 1] = max(src->data[row][3 * col + 1] + black[c4] - riDark->data[row][3 * col + 1], 0.0f); rawData[row][3 * col + 2] = max(src->data[row][3 * col + 2] + black[c4] - riDark->data[row][3 * col + 2], 0.0f); @@ -2508,7 +2508,7 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R //adjust black level (eg Canon) bool isMono = false; - if (getSensorType() == ST_BAYER || getSensorType() == ST_FOVEON ) { + if (getSensorType() == ST_BAYER || getSensorType() == ST_FOVEON) { black_lev[0] = raw.bayersensor.black1; //R black_lev[1] = raw.bayersensor.black0; //G1 @@ -2526,8 +2526,8 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R isMono = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO) == raw.xtranssensor.method; } - for(int i = 0; i < 4 ; i++) { - cblacksom[i] = max( c_black[i] + black_lev[i], 0.0f ); // adjust black level + for (int i = 0; i < 4 ; i++) { + cblacksom[i] = max(c_black[i] + black_lev[i], 0.0f); // adjust black level } for (int i = 0; i < 4; ++i) { @@ -2537,7 +2537,7 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R initialGain = calculate_scale_mul(scale_mul, ref_pre_mul, c_white, cblacksom, isMono, ri->get_colors()); // recalculate scale colors with adjusted levels //fprintf(stderr, "recalc: %f [%f %f %f %f]\n", initialGain, scale_mul[0], scale_mul[1], scale_mul[2], scale_mul[3]); - for(int i = 0; i < 4 ; i++) { + for (int i = 0; i < 4 ; i++) { clmax[i] = (c_white[i] - cblacksom[i]) * scale_mul[i]; // raw clip level } @@ -2545,7 +2545,7 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R // scale image colors - if( ri->getSensorType() == ST_BAYER) { + if (ri->getSensorType() == ST_BAYER) { #ifdef _OPENMP #pragma omp parallel #endif @@ -2559,8 +2559,8 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R for (int row = winy; row < winy + winh; row ++) { for (int col = winx; col < winx + winw; col++) { - const int c = FC(row, col); // three colors, 0=R, 1=G, 2=B - const int c4 = ( c == 1 && !(row & 1) ) ? 3 : c; // four colors, 0=R, 1=G1, 2=B, 3=G2 + const int c = FC(row, col); // three colors, 0=R, 1=G, 2=B + const int c4 = (c == 1 && !(row & 1)) ? 3 : c; // four colors, 0=R, 1=G1, 2=B, 3=G2 const float val = max(0.f, rawData[row][col] - cblacksom[c4]) * scale_mul[c4]; rawData[row][col] = val; tmpchmax[c] = max(tmpchmax[c], val); @@ -2576,7 +2576,7 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R chmax[2] = max(tmpchmax[2], chmax[2]); } } - } else if ( ri->get_colors() == 1 ) { + } else if (ri->get_colors() == 1) { #ifdef _OPENMP #pragma omp parallel #endif @@ -2602,7 +2602,7 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R chmax[0] = chmax[1] = chmax[2] = chmax[3] = max(tmpchmax, chmax[0]); } } - } else if(ri->getSensorType() == ST_FUJI_XTRANS) { + } else if (ri->getSensorType() == ST_FUJI_XTRANS) { #ifdef _OPENMP #pragma omp parallel #endif @@ -3125,7 +3125,7 @@ void RawImageSource::colorSpaceConversion_ (Imagefloat* im, const ColorManagemen transform_via_pcs_lab = true; separate_pcs_lab_highlights = true; // We transform to Lab because we can and that we avoid getting an unnecessary unmatched gamma conversion which we would need to revert. - hTransform = cmsCreateTransform (in, TYPE_RGB_FLT, nullptr, TYPE_Lab_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE ); + hTransform = cmsCreateTransform (in, TYPE_RGB_FLT, nullptr, TYPE_Lab_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { @@ -3143,7 +3143,7 @@ void RawImageSource::colorSpaceConversion_ (Imagefloat* im, const ColorManagemen case CAMERA_ICC_TYPE_NIKON: case CAMERA_ICC_TYPE_GENERIC: default: - hTransform = cmsCreateTransform (in, TYPE_RGB_FLT, prophoto, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE ); // NOCACHE is important for thread safety + hTransform = cmsCreateTransform (in, TYPE_RGB_FLT, prophoto, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE); // NOCACHE is important for thread safety break; } @@ -3152,7 +3152,7 @@ void RawImageSource::colorSpaceConversion_ (Imagefloat* im, const ColorManagemen if (hTransform == nullptr) { // Fallback: create transform from camera profile. Should not happen normally. lcmsMutex->lock (); - hTransform = cmsCreateTransform (camprofile, TYPE_RGB_FLT, prophoto, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE ); + hTransform = cmsCreateTransform (camprofile, TYPE_RGB_FLT, prophoto, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE); lcmsMutex->unlock (); } @@ -3174,11 +3174,11 @@ void RawImageSource::colorSpaceConversion_ (Imagefloat* im, const ColorManagemen #pragma omp for schedule(static) #endif - for ( int h = 0; h < im->getHeight(); ++h ) { + for (int h = 0; h < im->getHeight(); ++h) { float *p = buffer.data, *pR = im->r(h), *pG = im->g(h), *pB = im->b(h); // Apply pre-processing - for ( int w = 0; w < im->getWidth(); ++w ) { + for (int w = 0; w < im->getWidth(); ++w) { float r = *(pR++); float g = *(pG++); float b = *(pB++); @@ -3261,7 +3261,7 @@ void RawImageSource::colorSpaceConversion_ (Imagefloat* im, const ColorManagemen pG = im->g(h); pB = im->b(h); - for ( int w = 0; w < im->getWidth(); ++w ) { + for (int w = 0; w < im->getWidth(); ++w) { float r, g, b, hr = 0.f, hg = 0.f, hb = 0.f; @@ -3328,9 +3328,9 @@ void RawImageSource::colorSpaceConversion_ (Imagefloat* im, const ColorManagemen // to a small space such as sRGB we may end up with negative values and values larger than max. if (!working_space_is_prophoto) { //convert from Prophoto to XYZ - float x = (toxyz[0][0] * r + toxyz[0][1] * g + toxyz[0][2] * b ) ; - float y = (toxyz[1][0] * r + toxyz[1][1] * g + toxyz[1][2] * b ) ; - float z = (toxyz[2][0] * r + toxyz[2][1] * g + toxyz[2][2] * b ) ; + float x = (toxyz[0][0] * r + toxyz[0][1] * g + toxyz[0][2] * b) ; + float y = (toxyz[1][0] * r + toxyz[1][1] * g + toxyz[1][2] * b) ; + float z = (toxyz[2][0] * r + toxyz[2][1] * g + toxyz[2][2] * b) ; //convert from XYZ to cmp.working (sRGB...Adobe...Wide..) r = ((torgb[0][0] * x + torgb[0][1] * y + torgb[0][2] * z)) ; g = ((torgb[1][0] * x + torgb[1][1] * y + torgb[1][2] * z)) ; @@ -3623,7 +3623,7 @@ void RawImageSource::HLRecovery_CIELab (float* rin, float* gin, float* bin, floa //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void RawImageSource::hlRecovery (const std::string &method, float* red, float* green, float* blue, int width, float* hlmax ) +void RawImageSource::hlRecovery (const std::string &method, float* red, float* green, float* blue, int width, float* hlmax) { if (method == "Luminance") { @@ -3673,7 +3673,7 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr) tmphistogram[(int)(refwb1 * rawData[i][j + 1])] += 4; } - if(j < end) { + if (j < end) { tmphistogram[(int)(refwb0 * rawData[i][j])] += 4; } } else if (ri->getSensorType() == ST_FUJI_XTRANS) { @@ -3793,23 +3793,23 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU if (ri->getSensorType() == ST_BAYER) { int j; int c1 = FC(i, start); - c1 = ( fourColours && c1 == 1 && !(i & 1) ) ? 3 : c1; + c1 = (fourColours && c1 == 1 && !(i & 1)) ? 3 : c1; int c2 = FC(i, start + 1); - c2 = ( fourColours && c2 == 1 && !(i & 1) ) ? 3 : c2; + c2 = (fourColours && c2 == 1 && !(i & 1)) ? 3 : c2; for (j = start; j < end - 1; j += 2) { 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 + if (j < end) { // last pixel of row if width is odd 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] * scale)]++; } - } else if(ri->getSensorType() == ST_FUJI_XTRANS) { + } 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] * scale)]++; @@ -3847,7 +3847,7 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU return f > 0.f ? (f < 1.f ? 1 : std::min(int(f), 255)) : 0; }; - for(int i = 0; i < histoSize; i++) { + for (int i = 0; i < histoSize; i++) { int idx = getidx(0, i); histRedRaw[idx] += hist[0][i]; @@ -3869,11 +3869,11 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU for (int i = 0; i < 256; i++) { histGreenRaw[i] >>= 1; } - else if(ri->getSensorType() == ST_FUJI_XTRANS) // since Xtrans has 2.5 as many greens, correct for it + else if (ri->getSensorType() == ST_FUJI_XTRANS) // since Xtrans has 2.5 as many greens, correct for it for (int i = 0; i < 256; i++) { histGreenRaw[i] = (histGreenRaw[i] * 2) / 5; } - else if(ri->get_colors() == 1) { // monochrome sensor => set all histograms equal + else if (ri->get_colors() == 1) { // monochrome sensor => set all histograms equal histGreenRaw += histRedRaw; histBlueRaw += histRedRaw; } @@ -3895,1516 +3895,403 @@ void RawImageSource::getRowStartEnd (int x, int &start, int &end) } -static void histoxyY(int bfhitc, int bfwitc, const array2D & xc, const array2D & yc, const array2D & Yc, float *xxx, float * yyy, float * YYY, int * histxy, float * area, int * inter) +static void histoxyY(int bfhitc, int bfwitc, const array2D & xc, const array2D & yc, const array2D & Yc, LUTf &xxx, LUTf &yyy, LUTf &YYY, LUTu &histxy) { - int nh; - - for (int y = 0; y < bfhitc ; y++) { - for (int x = 0; x < bfwitc ; x++) { - - if (xc[y][x] < 0.12f && xc[y][x] > 0.03f) { // near Prophoto - - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 0; - histxy[nh]++; - area[nh] = 50.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - - YYY[nh] += Yc[y][x]; - - // nc = 0; - //blue hard - } else if (yc[y][x] < 0.3f) { - nh = 1; - histxy[nh]++; - area[nh] = 60.f; - inter[nh] = 1; - YYY[nh] += Yc[y][x]; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - - // nc = 1; - - //blue - } else if (yc[y][x] < 0.4f) { - nh = 2; - histxy[nh]++; - area[nh] = 80.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - // nc = 1; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - //blue green - nh = 3; - histxy[nh]++; - area[nh] = 100.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 1; - - } else if (yc[y][x] < 0.6f) { - nh = 4; - histxy[nh]++; - area[nh] = 120.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 1; - - } else if (yc[y][x] < 0.82f) { - //green - nh = 5; - histxy[nh]++; - area[nh] = 240.f; - inter[nh] = 1; - // nc = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - +#ifdef _OPENMP + #pragma omp parallel +#endif + { + LUTu histxythr(histxy.getSize()); + histxythr.clear(); + LUTf xxxthr(xxx.getSize()); + xxxthr.clear(); + LUTf yyythr(yyy.getSize()); + yyythr.clear(); + LUTf YYYthr(YYY.getSize()); + YYYthr.clear(); +#ifdef _OPENMP + #pragma omp for schedule(dynamic, 4) nowait +#endif + for (int y = 0; y < bfhitc ; y++) { + for (int x = 0; x < bfwitc ; x++) { + int nh = -1; + if (xc[y][x] < 0.12f && xc[y][x] > 0.03f && yc[y][x] > 0.1f) { // near Prophoto + if (yc[y][x] < 0.2f) { + nh = 0; + //blue hard + } else if (yc[y][x] < 0.3f) { + nh = 1; + //blue + } else if (yc[y][x] < 0.4f) { + nh = 2; + } else if (yc[y][x] < 0.5f) { + //blue green + nh = 3; + } else if (yc[y][x] < 0.6f) { + nh = 4; + } else if (yc[y][x] < 0.82f) { + //green + nh = 5; + } + } else if (xc[y][x] < 0.24f && yc[y][x] > 0.05f) { + if (yc[y][x] < 0.2f) { + nh = 6; + } else if (yc[y][x] < 0.3f) { + nh = 7; + } else if (yc[y][x] < 0.4f) { + nh = 8; + } else if (yc[y][x] < 0.5f) { + nh = 9; + } else if (yc[y][x] < 0.6f) { + nh = 10; + } else if (yc[y][x] < 0.75f) { + nh = 11; + } + } else if (xc[y][x] < 0.28f && yc[y][x] > 0.1f) {//blue sky and other + if (yc[y][x] < 0.2f) { + nh = 12; + } else if (yc[y][x] < 0.25f) { + nh = 13; + } else if (yc[y][x] < 0.29f) { + nh = 14; + } else if (yc[y][x] < 0.33f) { + nh = 15; + } else if (yc[y][x] < 0.37f) { + nh = 16; + } else if (yc[y][x] < 0.4f) { + nh = 17; + } else if (yc[y][x] < 0.45f) { + nh = 18; + } else if (yc[y][x] < 0.5f) { + nh = 19; + } else if (yc[y][x] < 0.6f) { + nh = 20; + } else if (yc[y][x] < 0.75f) { + nh = 21; + } + } else if (xc[y][x] < 0.31f && yc[y][x] > 0.1f) {//near neutral others + if (yc[y][x] < 0.2f) { + nh = 22; + } else if (yc[y][x] < 0.24f) { + nh = 23; + } else if (yc[y][x] < 0.29f) { + nh = 24; + } else if (yc[y][x] < 0.32f) { + nh = 25; + } else if (yc[y][x] < 0.36f) { + nh = 26; + } else if (yc[y][x] < 0.4f) { + nh = 27; + } else if (yc[y][x] < 0.5f) { + nh = 28; + } else if (yc[y][x] < 0.7f) { + nh = 29; + } + } else if (xc[y][x] < 0.325f && yc[y][x] > 0.1f) {//neutral 34 + if (yc[y][x] < 0.2f) { + nh = 30; + } else if (yc[y][x] < 0.24f) { + nh = 31; + } else if (yc[y][x] < 0.29f) { + nh = 32; + } else if (yc[y][x] < 0.32f) { + nh = 33; + } else if (yc[y][x] < 0.34f) { + nh = 34; + } else if (yc[y][x] < 0.37f) { + nh = 35; + } else if (yc[y][x] < 0.4f) { + nh = 36; + } else if (yc[y][x] < 0.45f) { + nh = 37; + } else if (yc[y][x] < 0.5f) { + nh = 38; + } else if (yc[y][x] < 0.55f) { + nh = 39; + } else if (yc[y][x] < 0.7f) { + nh = 40; + } + } else if (xc[y][x] < 0.335f && yc[y][x] > 0.1f) {//neutral + if (yc[y][x] < 0.2f) { + nh = 41; + } else if (yc[y][x] < 0.24f) { + nh = 42; + } else if (yc[y][x] < 0.29f) { + nh = 43; + } else if (yc[y][x] < 0.32f) { + nh = 44; + } else if (yc[y][x] < 0.33f) { + nh = 45; + } else if (yc[y][x] < 0.34f) { + nh = 46; + } else if (yc[y][x] < 0.35f) { + nh = 47; + } else if (yc[y][x] < 0.36f) { + nh = 48; + } else if (yc[y][x] < 0.37f) { + nh = 47; + } else if (yc[y][x] < 0.38f) { + nh = 48; + } else if (yc[y][x] < 0.4f) { + nh = 49; + } else if (yc[y][x] < 0.45f) { + nh = 50; + } else if (yc[y][x] < 0.5f) { + nh = 51; + } else if (yc[y][x] < 0.55f) { + nh = 52; + } else if (yc[y][x] < 0.7f) { + nh = 53; + } + } else if (xc[y][x] < 0.345f && yc[y][x] > 0.1f) {//neutral 37 + if (yc[y][x] < 0.2f) { + nh = 54; + } else if (yc[y][x] < 0.24f) { + nh = 55; + } else if (yc[y][x] < 0.29f) { + nh = 56; + } else if (yc[y][x] < 0.32f) { + nh = 57; + } else if (yc[y][x] < 0.33f) {//34 + nh = 58; + } else if (yc[y][x] < 0.34f) { + nh = 59; + } else if (yc[y][x] < 0.35f) {//34 + nh = 60; + } else if (yc[y][x] < 0.36f) {//34 + nh = 61; + } else if (yc[y][x] < 0.37f) { + nh = 62; + } else if (yc[y][x] < 0.38f) { + nh = 63; + } else if (yc[y][x] < 0.39f) { + nh = 64; + } else if (yc[y][x] < 0.4f) { + nh = 65; + } else if (yc[y][x] < 0.42f) { + nh = 66; + } else if (yc[y][x] < 0.45f) { + nh = 67; + } else if (yc[y][x] < 0.48f) { + nh = 68; + } else if (yc[y][x] < 0.5f) { + nh = 69; + } else if (yc[y][x] < 0.55f) { + nh = 70; + } else if (yc[y][x] < 0.65f) { + nh = 71; + } + } else if (xc[y][x] < 0.355f && yc[y][x] > 0.1f) {//neutral 37 + if (yc[y][x] < 0.2f) { + nh = 72; + } else if (yc[y][x] < 0.24f) { + nh = 73; + } else if (yc[y][x] < 0.29f) { + nh = 74; + } else if (yc[y][x] < 0.32f) { + nh = 75; + } else if (yc[y][x] < 0.33f) {//34 + nh = 76; + } else if (yc[y][x] < 0.34f) { + nh = 77; + } else if (yc[y][x] < 0.35f) {//34 + nh = 78; + } else if (yc[y][x] < 0.36f) {//34 + nh = 79; + } else if (yc[y][x] < 0.37f) { + nh = 80; + } else if (yc[y][x] < 0.38f) { + nh = 81; + } else if (yc[y][x] < 0.39f) { + nh = 82; + } else if (yc[y][x] < 0.4f) { + nh = 83; + } else if (yc[y][x] < 0.42f) { + nh = 84; + } else if (yc[y][x] < 0.45f) { + nh = 85; + } else if (yc[y][x] < 0.48f) { + nh = 86; + } else if (yc[y][x] < 0.5f) { + nh = 87; + } else if (yc[y][x] < 0.55f) { + nh = 88; + } else if (yc[y][x] < 0.65f) { + nh = 89; + } + } else if (xc[y][x] < 0.365f && yc[y][x] > 0.15f) { //0.4 + if (yc[y][x] < 0.2f) { + nh = 90; + } else if (yc[y][x] < 0.24f) { + nh = 91; + } else if (yc[y][x] < 0.29f) { + nh = 92; + } else if (yc[y][x] < 0.32f) { + nh = 93; + } else if (yc[y][x] < 0.33f) { + nh = 94; + } else if (yc[y][x] < 0.34f) { + nh = 95; + } else if (yc[y][x] < 0.36f) { + nh = 96; + } else if (yc[y][x] < 0.37f) { + nh = 97; + } else if (yc[y][x] < 0.38f) { + nh = 98; + } else if (yc[y][x] < 0.39f) { + nh = 99; + } else if (yc[y][x] < 0.4f) { + nh = 100; + } else if (yc[y][x] < 0.42f) { + nh = 101; + } else if (yc[y][x] < 0.45f) { + nh = 102; + } else if (yc[y][x] < 0.5f) { + nh = 103; + } else if (yc[y][x] < 0.55f) { + nh = 104; + } else if (yc[y][x] < 0.63f) { + nh = 105; + } + } else if (xc[y][x] < 0.405f && yc[y][x] > 0.15f) {//45 + if (yc[y][x] < 0.2f) { + nh = 106; + } else if (yc[y][x] < 0.24f) { + nh = 107; + } else if (yc[y][x] < 0.29f) { + nh = 108; + } else if (yc[y][x] < 0.32f) { + nh = 109; + } else if (yc[y][x] < 0.34f) { + nh = 110; + } else if (yc[y][x] < 0.37f) { + nh = 111; + } else if (yc[y][x] < 0.4f) { + nh = 112; + } else if (yc[y][x] < 0.45f) { + nh = 113; + } else if (yc[y][x] < 0.5f) { + nh = 114; + } else if (yc[y][x] < 0.55f) { + nh = 115; + } else if (yc[y][x] < 0.6f) { + nh = 116; + } + } else if (xc[y][x] < 0.445f && yc[y][x] > 0.15f) {//45 + if (yc[y][x] < 0.2f) { + nh = 117; + } else if (yc[y][x] < 0.24f) { + nh = 118; + } else if (yc[y][x] < 0.29f) { + nh = 119; + } else if (yc[y][x] < 0.32f) { + nh = 120; + } else if (yc[y][x] < 0.34f) { + nh = 121; + } else if (yc[y][x] < 0.37f) { + nh = 122; + } else if (yc[y][x] < 0.4f) { + nh = 123; + } else if (yc[y][x] < 0.45f) { + nh = 124; + } else if (yc[y][x] < 0.5f) { + nh = 125; + } else if (yc[y][x] < 0.55f) { + nh = 126; + } else if (yc[y][x] < 0.58f) { + nh = 127; + } + } else if (xc[y][x] < 0.495f && yc[y][x] > 0.15f) { + if (yc[y][x] < 0.2f) { + nh = 128; + } else if (yc[y][x] < 0.24f) { + nh = 129; + } else if (yc[y][x] < 0.29f) { + nh = 130; + } else if (yc[y][x] < 0.32f) { + nh = 131; + } else if (yc[y][x] < 0.34f) { + nh = 132; + } else if (yc[y][x] < 0.37f) { + nh = 133; + } else if (yc[y][x] < 0.4f) { + nh = 134; + } else if (yc[y][x] < 0.45f) { + nh = 135; + } else if (yc[y][x] < 0.5f) { + nh = 136; + } else if (yc[y][x] < 0.55f) { + nh = 137; + } + } else if (xc[y][x] < 0.545f && yc[y][x] > 0.15f) { + if (yc[y][x] < 0.2f) { + nh = 138; + } else if (yc[y][x] < 0.24f) { + nh = 139; + } else if (yc[y][x] < 0.29f) { + nh = 140; + } else if (yc[y][x] < 0.32f) { + nh = 141; + } else if (yc[y][x] < 0.34f) { + nh = 142; + } else if (yc[y][x] < 0.37f) { + nh = 143; + } else if (yc[y][x] < 0.4f) { + nh = 144; + } else if (yc[y][x] < 0.45f) { + nh = 145; + } else if (yc[y][x] < 0.5f) { + nh = 146; + } + } else if (xc[y][x] < 0.595f && yc[y][x] > 0.15f) { + if (yc[y][x] < 0.22f) { + nh = 147; + } else if (yc[y][x] < 0.25f) { + nh = 148; + } else if (yc[y][x] < 0.3f) { + nh = 149; + } else if (yc[y][x] < 0.35f) { + nh = 150; + } else if (yc[y][x] < 0.4f) { + nh = 151; + } else if (yc[y][x] < 0.45f) { + nh = 152; + } + } else if (xc[y][x] < 0.65f && yc[y][x] > 0.12f) { + if (yc[y][x] < 0.25f) { + nh = 153; + } else if (yc[y][x] < 0.3f) { + nh = 154; + } else if (yc[y][x] < 0.35f) { + nh = 155; + } else if (yc[y][x] < 0.45f) { + nh = 156; + } + } else if (xc[y][x] < 0.75f && yc[y][x] > 0.1f) { + nh = 157; } - } else if (xc[y][x] < 0.24f) { - if (yc[y][x] < 0.2f && yc[y][x] > 0.05f) { - nh = 6; - histxy[nh]++; - area[nh] = 230.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 2; - - } else if (yc[y][x] < 0.3f) { - nh = 7; - histxy[nh]++; - area[nh] = 240.f; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 2; - - } else if (yc[y][x] < 0.4f) { - nh = 8; - histxy[nh]++; - area[nh] = 240.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 2; - - } else if (yc[y][x] < 0.5f) { - nh = 9; - histxy[nh]++; - area[nh] = 240.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 2; - // nc2 = 3; - - } else if (yc[y][x] < 0.6f) { - nh = 10; - histxy[nh]++; - area[nh] = 240.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - // nc = 3; - - } else if (yc[y][x] < 0.75f) { - nh = 11; - histxy[nh]++; - area[nh] = 400.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - // nc = 3; - + if (nh >= 0) { + histxythr[nh]++; + xxxthr[nh] += xc[y][x]; + yyythr[nh] += yc[y][x]; + YYYthr[nh] += Yc[y][x]; } - - } else if (xc[y][x] < 0.28f) {//blue sky and other - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 12; - histxy[nh]++; - area[nh] = 80.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.25f) { - nh = 13; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 14; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.33f) { - nh = 15; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 16; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 17; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 18; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.5f) { - nh = 19; - histxy[nh]++; - area[nh] = 25.f; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.6f) { - nh = 20; - histxy[nh]++; - area[nh] = 50.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.75f) { - nh = 21; - histxy[nh]++; - area[nh] = 60.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - } else if (xc[y][x] < 0.31f) {//near neutral others - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 22; - histxy[nh]++; - area[nh] = 50.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 23; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 24; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.32f) { - nh = 25; - histxy[nh]++; - area[nh] = 9.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.36f) { - nh = 26; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 27; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.5f) { - nh = 28; - histxy[nh]++; - area[nh] = 30.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.7f) { - nh = 29; - histxy[nh]++; - area[nh] = 45.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - } else if (xc[y][x] < 0.325f) {//neutral 34 - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 30; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 31; - histxy[nh]++; - area[nh] = 6.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 32; - histxy[nh]++; - area[nh] = 7.5f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 33; - histxy[nh]++; - area[nh] = 4.5f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.34f) { - nh = 34; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 35; - histxy[nh]++; - area[nh] = 4.5f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 36; - histxy[nh]++; - area[nh] = 4.5f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 37; - histxy[nh]++; - area[nh] = 7.5f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 38; - histxy[nh]++; - area[nh] = 7.5f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 39; - histxy[nh]++; - area[nh] = 7.5f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.7f) { - nh = 40; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.335f) {//neutral - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 41; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 42; - histxy[nh]++; - area[nh] = 4.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 43; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 44; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.33f) { - nh = 45; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.34f) { - nh = 46; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.35f) { - nh = 47; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.36f) { - nh = 48; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 47; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.38f) { - nh = 48; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 49; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 50; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 51; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 52; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.7f) { - nh = 53; - histxy[nh]++; - area[nh] = 10.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.345f) {//neutral 37 - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 54; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 55; - histxy[nh]++; - area[nh] = 4.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 56; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 57; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.33f) {//34 - nh = 58; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.34f) { - nh = 59; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.35f) {//34 - nh = 60; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.36f) {//34 - nh = 61; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 62; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.38f) { - nh = 63; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.39f) { - nh = 64; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 65; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.42f) { - nh = 66; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 67; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.48f) { - nh = 68; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 69; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 70; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.65f) { - nh = 71; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.355f) {//neutral 37 - if (yc[y][x] < 0.2f && yc[y][x] > 0.1f) { - nh = 72; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 73; - histxy[nh]++; - area[nh] = 4.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 74; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 75; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.33f) {//34 - nh = 76; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.34f) { - nh = 77; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.35f) {//34 - nh = 78; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.36f) {//34 - nh = 79; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 80; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.38f) { - nh = 81; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.39f) { - nh = 82; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 83; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.42f) { - nh = 84; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 85; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.48f) { - nh = 68; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 86; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 87; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.65f) { - nh = 88; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.365f) { //0.4 - if (yc[y][x] < 0.2f && yc[y][x] > 0.15f) { - nh = 89; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.24f) { - nh = 90; - histxy[nh]++; - area[nh] = 4.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 91; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 92; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.33f) { - nh = 93; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.34f) { - nh = 94; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.36f) { - nh = 95; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 5; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 96; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.38f) { - nh = 97; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.39f) { - nh = 98; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 99; - histxy[nh]++; - area[nh] = 1.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - } else if (yc[y][x] < 0.42f) { - nh = 100; - histxy[nh]++; - area[nh] = 2.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 101; - histxy[nh]++; - area[nh] = 3.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 102; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 103; - histxy[nh]++; - area[nh] = 5.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.63f) { - nh = 104; - histxy[nh]++; - area[nh] = 10.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.405f) {//45 - if (yc[y][x] < 0.2f && yc[y][x] > 0.15f) { - nh = 105; - histxy[nh]++; - area[nh] = 40.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 106; - histxy[nh]++; - area[nh] = 16.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 107; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 108; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.34f) { - nh = 109; - histxy[nh]++; - area[nh] = 8.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 110; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 111; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 112; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 113; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 114; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.6f) { - nh = 115; - histxy[nh]++; - area[nh] = 16.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.445f) {//45 - if (yc[y][x] < 0.2f && yc[y][x] > 0.15f) { - nh = 116; - histxy[nh]++; - area[nh] = 40.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 117; - histxy[nh]++; - area[nh] = 16.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 118; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 119; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.34f) { - nh = 120; - histxy[nh]++; - area[nh] = 8.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 121; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 122; - histxy[nh]++; - area[nh] = 12.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 123; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 124; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 125; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.58f) { - nh = 126; - histxy[nh]++; - area[nh] = 16.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.495f) { - if (yc[y][x] < 0.2f && yc[y][x] > 0.15f) { - nh = 127; - histxy[nh]++; - area[nh] = 40.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 128; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 129; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 130; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.34f) { - nh = 131; - histxy[nh]++; - area[nh] = 10.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 132; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 133; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 3; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 134; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 135; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.55f) { - nh = 136; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - } else if (xc[y][x] < 0.545f) { - if (yc[y][x] < 0.2f && yc[y][x] > 0.15f) { - nh = 137; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.24f) { - nh = 138; - histxy[nh]++; - area[nh] = 20.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.29f) { - nh = 139; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.32f) { - nh = 140; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.34f) { - nh = 141; - histxy[nh]++; - area[nh] = 10.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.37f) { - nh = 142; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 143; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.45f) { - nh = 144; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.5f) { - nh = 145; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - - } - - } else if (xc[y][x] < 0.595f) { - if (yc[y][x] < 0.22f && yc[y][x] > 0.15f) { - nh = 146; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.25f) { - nh = 147; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.3f) { - nh = 148; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.35f) { - nh = 149; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.4f) { - nh = 160; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.45f) { - nh = 161; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.65f) { - if (yc[y][x] < 0.25f && yc[y][x] > 0.12f) { - nh = 162; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.3f) { - nh = 163; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } else if (yc[y][x] < 0.35f) { - nh = 164; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 2; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - - } else if (yc[y][x] < 0.45f) { - nh = 165; - histxy[nh]++; - area[nh] = 15.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - - } else if (xc[y][x] < 0.75f && yc[y][x] > 0.1f) { - nh = 166; - histxy[nh]++; - area[nh] = 25.f; - inter[nh] = 1; - xxx[nh] += xc[y][x]; - yyy[nh] += yc[y][x]; - YYY[nh] += Yc[y][x]; - - } - + } +#ifdef _OPENMP + #pragma omp critical +#endif + { + histxy += histxythr; + xxx += xxxthr; + yyy += yyythr; + YYY += YYYthr; } } } - - - void static studentXY(const array2D & YYcurr, const array2D & reffYY, int sizcurr, int Nc, int tt, float & student) { //calculate Student coeff YY @@ -5456,388 +4343,6 @@ void static studentXY(const array2D & YYcurr, const array2D & reff //student coeeficient } -/* -static void SdwWB(const array2D &redloc, const array2D &greenloc, const array2D &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm) -{ - //Standard deviation weighted Gary World - from Lan rt al. - constexpr float clipHigh = 64000.f; - constexpr float clipLow = 1500.f; - - float MeanG[12] = { }; - float SigmaG[12] = { }; - - float MeanR[12] = { }; - float SigmaR[12] = { }; - - float MeanB[12] = { }; - float SigmaB[12] = { }; - - //divide in 12 areas - int partw, parth; - int yh, xw; - - if (bfw > bfh) { - partw = bfw / 4; - parth = bfh / 3; - xw = 4; - yh = 3; - } else { - partw = bfw / 3; - parth = bfh / 4; - xw = 3; - yh = 4; - } - - float SigmaGG = 0.f, SigmaRR = 0.f, SigmaBB = 0.f; - -#ifdef _OPENMP - #pragma omp parallel for schedule(dynamic) collapse(2) -#endif - - for (int w = 0; w < xw ; ++w) { - for (int h = 0; h < yh ; ++h) { - float meanr = 0.f; - float meang = 0.f; - float meanb = 0.f; - int nr = 0; - int ng = 0; - int nb = 0; - - for (int y = h * parth; y < (h + 1) * parth; ++y) { - for (int x = w * partw; x < (w + 1) * partw; ++x) { - if (greenloc[y][x] > clipLow && greenloc[y][x] < clipHigh) { - meang += greenloc[y][x]; - ng++; - } - - if (redloc[y][x] > clipLow && redloc[y][x] < clipHigh) { - meanr += redloc[y][x]; - nr++; - } - - if (blueloc[y][x] > clipLow && blueloc[y][x] < clipHigh) { - meanb += blueloc[y][x]; - nb++; - } - } - } - - int i = w + h * xw; - - if (ng > 0) { - meang /= ng; - } - - if (nr > 0) { - meanr /= nr; - } - - if (nb > 0) { - meanb /= nb; - } - - MeanG[i] = meang; - MeanR[i] = meanr; - MeanB[i] = meanb; - - float sigmar = 0.f; - float sigmag = 0.f; - float sigmab = 0.f; - - for (int y = h * parth; y < (h + 1) * parth; ++y) { - for (int x = w * partw; x < (w + 1) * partw; ++x) { - if (greenloc[y][x] > clipLow && greenloc[y][x] < clipHigh) { - sigmag += SQR(meang - greenloc[y][x]) ; - } - - if (redloc[y][x] > clipLow && redloc[y][x] < clipHigh) { - sigmar += SQR(meanr - redloc[y][x]); - } - - if (blueloc[y][x] > clipLow && blueloc[y][x] < clipHigh) { - sigmab += SQR(meanb - blueloc[y][x]); - } - } - } - - SigmaG[i] = sigmag; - SigmaR[i] = sigmar; - SigmaB[i] = sigmab; - - if (ng > 0) { - SigmaG[i] = std::sqrt(SigmaG[i] / ng); - } - - if (nr > 0) { - SigmaR[i] = std::sqrt(SigmaR[i] / nr); - } - - if (nb > 0) { - SigmaB[i] = std::sqrt(SigmaB[i] / nb); - } - -#ifdef _OPENMP - #pragma omp critical -#endif - { - SigmaGG += SigmaG[i]; - SigmaRR += SigmaR[i]; - SigmaBB += SigmaB[i]; - } - } - } - - float StdavgG = 0.f, StdavgR = 0.f, StdavgB = 0.f; - constexpr float epsilo = 0.01f; - - for (int k = 0; k < 12 ; k++) { - StdavgG += (SigmaG[k] * MeanG[k]) / (SigmaGG + epsilo); - StdavgR += (SigmaR[k] * MeanR[k]) / (SigmaRR + epsilo); - StdavgB += (SigmaB[k] * MeanB[k]) / (SigmaBB + epsilo); - - } - - avg_gm = (StdavgG + StdavgB + StdavgR) / (3 * StdavgG); - avg_rm = (StdavgG + StdavgB + StdavgR) / (3 * StdavgR); - avg_bm = (StdavgG + StdavgB + StdavgR) / (3 * StdavgB); - - avg_gm *= 10000.f; - avg_rm *= 10000.f; - avg_bm *= 10000.f; - -} -*/ - -/* -static void RobustWB(array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm) -{ - BENCHFUN - // inspired by "Robust automatic WB algorithm using grey colour points in Images" - // Jy Huo, Yl Chang, J.Wang Xx Wei - // robust = true; -// printf("Robust WB\n"); - const int bfwr = bfw / 4 + 1 ;//5 middle value to keep good result and reduce time - const int bfhr = bfh / 4 + 1; - - array2D rl(bfwr, bfhr); - array2D gl(bfwr, bfhr); - array2D bl(bfwr, bfhr); - - // copy data to smaller arrays to reduce memory pressure in do-while loop -#ifdef _OPENMP - #pragma omp parallel for -#endif - - for (int y = 0; y < bfh ; y += 4) { - int yy = y / 4; - - for (int x = 0; x < bfw ; x += 4) { - int xx = x / 4; - rl[yy][xx] = redloc[y][x]; - gl[yy][xx] = greenloc[y][x]; - bl[yy][xx] = blueloc[y][x]; - } - } - - float *Uba = new float [204]; - float *Vba = new float [204]; - - constexpr float Th = 0.1321f; //Threshold 0.1321f 0.097f 0.2753f if necessary - //wr, wb, wg multipliers for each channel RGB - float wr = 1.f; - float wg = 1.f; - float wb = 1.f; - constexpr float mu = 0.002f;//std variation - constexpr float mu2 = 0.0012f;//first reduce variation - constexpr float mu3 = 0.0007f;//second variation - int itera = 0; - int minim = 1; - int realitera = 1; - - int Kx = 0; - - do {//iterative WB - float Ubarohm = 0.f, Vbarohm = 0.f; - itera++; - int Nf = 0; -#ifdef _OPENMP - #pragma omp parallel for reduction(+:Ubarohm, Vbarohm, Nf) schedule(dynamic,16) -#endif - - for (int y = 0; y < bfhr ; ++y) { - for (int x = 0; x < bfwr ; ++x) { - - //calculate YUV from RGB and wr, wg, wb - float Y0 = 0.299f * wr * rl[y][x] + 0.587f * wg * gl[y][x] + 0.114f * wb * bl[y][x]; - float U0 = -0.14713f * wr * rl[y][x] - 0.28886f * wg * gl[y][x] + 0.436f * wb * bl[y][x]; - float V0 = 0.615f * wr * rl[y][x] - 0.51498f * wg * gl[y][x] - 0.10001f * wb * bl[y][x]; - - //FYUX function to detect grey points - if (fabs(U0) + fabs(V0) < Th * Y0) {//grey values - Nf++; - Ubarohm += U0; - Vbarohm += V0; - } - - - } - } - - Ubarohm /= Nf; - Uba[itera] = Ubarohm;//stock value Ubarohm - Vba[itera] = Vbarohm;//stock value Vbarohm - - if (itera > 5 && minim < 2) { - if ((fabs(Uba[itera] - Uba[itera - 2]) < 0.001f) && (fabs(Vba[itera] - Vba[itera - 2]) < 0.001f)) { - //printf("DUba=%f Dvba=%f\n", Uba[itera] - Uba[itera - 2], Vba[itera] - Vba[itera - 2]); - realitera = itera; - minim = 2; //accelerate convergence - not in original algorithm - } - } - - if (itera > 10 && minim == 2 && itera > realitera + 3) { - if ((fabs(Uba[itera] - Uba[itera - 2]) < 0.001f) && (fabs(Vba[itera] - Vba[itera - 2]) < 0.001f)) { - minim = 3; //accelerate second time if necessary convergence, - not in original algorithm - } - - } - - Vbarohm /= Nf; // QUESTION INGO: why is this not done before the value is saved to Vba[itera]? Bug or intentional? - // printf ("Nf=%i max=%i U=%f V=%f\n", Nf, bfh*bfw, Ubarohm, Vbarohm); - Kx = 0; - constexpr float aa = 0.8f;//superior limit if epsil > aa increase variation - constexpr float bb = 0.15f;//inferior limit if epsil < bb exit - int ind = 1; - - float phi = 0.f; - - if ((fabs(Ubarohm) > fabs(Vbarohm)) || (Ubarohm != 0.f && fabs(Ubarohm) == fabs(Vbarohm))) { - phi = Ubarohm; - ind = 1; - } else if (fabs(Ubarohm) < fabs(Vbarohm)) { - phi = Vbarohm; - ind = 2; - } else if (Ubarohm == 0.f && Vbarohm == 0.f) { - phi = 0.f; - ind = 3; - } - - int sign = SGN(-phi); - - if (fabs(phi) >= aa) { - Kx = 2 * sign; - } - - if (fabs(phi) < aa && fabs(phi) >= bb) { - Kx = sign; - } - - if (fabs(phi) < bb) { - Kx = 0; - } - - // - float mur = mu; - - if (minim == 2) { - mur = mu2; - } else if (minim == 3) { - mur = mu3; - } - - if (ind == 1) { - wb += mur * Kx; - } else if (ind == 2) { - wr += mur * Kx; - } - - //printf ("epsil=%f iter=%i wb=%f wr=%f U=%f V=%f mu=%f\n", fabs (epsil), itera, wb, wr, Ubarohm, Vbarohm, mur); - } while (Kx != 0 && itera <= 200); //stop iterations in normal case Kx =0, or if WB iteration do not converge - - delete Uba; - delete Vba; -// printf("epsil=%f iter=%i wb=%f wr=%f mu=%f\n", fabs(epsil), itera, wb, wr, mur); - - avg_rm = 10000.* wr; - avg_gm = 10000.* wg; - avg_bm = 10000.* wb; - // printf("Robust ar%f ag=%f ab=%f\n", avg_rm, avg_gm, avg_bm); - -} -*/ -/* -static void SobelWB(array2D &redsobel, array2D &greensobel, array2D &bluesobel, array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh) -{ - BENCHFUN - int GX[3][3]; - int GY[3][3]; - - //Sobel Horizontal - GX[0][0] = 1; - GX[0][1] = 0; - GX[0][2] = -1; - GX[1][0] = 2; - GX[1][1] = 0; - GX[1][2] = -2; - GX[2][0] = 1; - GX[2][1] = 0; - GX[2][2] = -1; - - //Sobel Vertical - GY[0][0] = 1; - GY[0][1] = 2; - GY[0][2] = 1; - GY[1][0] = 0; - GY[1][1] = 0; - GY[1][2] = 0; - GY[2][0] = -1; - GY[2][1] = -2; - GY[2][2] = -1; - // inspired from Chen Guanghua Zhang Xiaolong - // edge detection to improve auto WB - - { -#ifdef _OPENMP - #pragma omp parallel for -#endif - - for (int y = 0; y < bfh ; y++) { - for (int x = 0; x < bfw ; x++) { - if (y == 0 || y == bfh - 1 || x == 0 || x == bfw - 1) { - redsobel[y][x] = 0.f; - greensobel[y][x] = 0.f; - bluesobel[y][x] = 0.f; - } else { - float sumXr = 0.f; - float sumYr = 0.f; - float sumXg = 0.f; - float sumYg = 0.f; - float sumXb = 0.f; - float sumYb = 0.f; - - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - sumXr += GX[j + 1][i + 1] * redloc[y + i][x + j]; - sumXg += GX[j + 1][i + 1] * greenloc[y + i][x + j]; - sumXb += GX[j + 1][i + 1] * blueloc[y + i][x + j]; - sumYr += GY[j + 1][i + 1] * redloc[y + i][x + j]; - sumYg += GY[j + 1][i + 1] * greenloc[y + i][x + j]; - sumYb += GY[j + 1][i + 1] * blueloc[y + i][x + j]; - } - } - - //Edge strength - //we can add if need teta = atan2 (sumYr, sumXr) - redsobel[y][x] = CLIP(std::sqrt(SQR(sumXr) + SQR(sumYr))); - greensobel[y][x] = CLIP(std::sqrt(SQR(sumXg) + SQR(sumYg))); - bluesobel[y][x] = CLIP(std::sqrt(SQR(sumXb) + SQR(sumYb))); - } - } - } - } -} -*/ - void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, const ColorManagementParams &cmp, const RAWParams &raw, const WBParams & wbpar) { /* @@ -5845,41 +4350,41 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double This algorithm try to find temperature correlation between 20 to 200 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web. - I have test many many algo to find the first one that work :) - Probably (sure) there are improvment to do... + I have test many many algorithms to find the first one that work :) + Probably (sure) there are improvement to do... I have create a table temperature with temp and white point with 100 values between 2000K and 12000K we can obviously change these values, more...with different steps - I have create or recuparate and transformed 200 spectral colors from Colorchecker24, others color and my 468 colors target, or from web flowers, etc. with a step of 5nm, I think it is largey enough. + I have create or recuparate and transformed 200 spectral colors from Colorchecker24, others color and my 468 colors target, or from web flowers, etc. with a step of 5nm, I think it is large enough. I think this value of 200 is now complete: I tested correlation with 60, 90, 100, 120, 155...better student increase with number of color, but now it seems stabilized Of course we can increase this number :) - 1) for the cuurent raw file we create a table for each temp of RGB multipliers + 1) for the current raw file we create a table for each temp of RGB multipliers 2) then, I choose the "camera temp" to initialize calculation (why not) - 3) for this temp, I calculated XYZ values for the 200 spectrals datas + 3) for this temp, I calculated XYZ values for the 200 spectral datas 4) then I create for the image an "histogram", but for xyY (Cie 1931 color space) 5) for each pixel (in fact to accelerate only 1/10 for and 1/10 for y), I determine for each couple xy, the number of occurences 6) I sort this result in ascending order - 7) in option we can sort in another maner to take into account chroma : chromax = x - white point x, chromay = y - white point y + 7) in option we can sort in another manner to take into account chroma : chromax = x - white point x, chromay = y - white point y 8) then I compare this result, with spectral datas found above in 3) with deltaE (limited to chroma) 9) at this point we have xyY values that match Camera temp, and spectral datas associated 10) then I recalculate RGB values from xyY histogram 11) after, I vary temp, between 2000K to 12000K - 12) RGB values are recalcualted from 10) with RGB multipliers, and then xyY are calcualted for each temp - 13) spectral datas choose are recalculated with temp betwen 2000K to 12000K with matrix spectral calculation, that leeds to xyY values + 12) RGB values are recalculated from 10) with RGB multipliers, and then xyY are calculated for each temp + 13) spectral datas choose are recalculated with temp between 2000K to 12000K with matrix spectral calculation, that leads to xyY values 14) I calculated for each couple xy, Student correlation (without Snedecor test) 15) the good result, is the best correlation - 16) we have found the best temperature where color image and color refences are correlate + 16) we have found the best temperature where color image and color references are correlate 17) after we pass this value to improccoordinator 18) in a second part if camera green is out, I used an "extra" algorithm 19) we make vary green between 2 limits (settings in option) - 20) betwen these green limits, we make slightly vary temp (settings in options) and recalculated RGB multipliers + 20) between these green limits, we make slightly vary temp (settings in options) and recalculated RGB multipliers 21) with this multipliers for the RGB color find in histogram we recalculate xyY 22) we re-adjust references color for these xyY from 20) 23) we add if chroma image is very low, k colors to degrad correlation 24) then find all Student correlation for each couple green / temp 25) sort these Student values, and choose the minimum - 26) then for the 3 better couple "temp / green" choose the one wher grren is neraest from 1. + 26) then for the 3 better couple "temp / green" choose the one where green is nearest from 1. Some variables or function are not used, keep in case of I have test with cat02 but result are not stable enough ! why ??, therefore cat02 neutralized @@ -5892,22 +4397,22 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double You can change 4 parameters in option.cc Itcwb_thres : 34 by default ==> number of color used in final algorithm - between 10 and max 55 - Itcwb_sort : false by default, can improve algo if true, ==> sort value in something near chroma order, instead of histogram number + Itcwb_sort : false by default, can improve algorithm if true, ==> sort value in something near chroma order, instead of histogram number Itcwb_greenrange : 0 amplitude of green variation - between 0 to 2 Itcwb_greendeltatemp : 1 - delta temp in green iterate loop for "extra" - between 0 to 4 - Itcwb_forceextra : false - if true force algorithm "extra" ("extra" is used when cmaera wbsettings are wrong) to all images - Itcwb_sizereference : 3 by default, can be set to 5 ==> size of reference color comapre to size of histogram real color - itcwb_delta : 1 by defaut can be set between 0 to 5 ==> delta temp to build histogram xy - if camera temp is not probably good + Itcwb_forceextra : false - if true force algorithm "extra" ("extra" is used when camera wbsettings are wrong) to all images + Itcwb_sizereference : 3 by default, can be set to 5 ==> size of reference color compare to size of histogram real color + itcwb_delta : 1 by default can be set between 0 to 5 ==> delta temp to build histogram xy - if camera temp is not probably good */ // BENCHFUN // BENCHFUN TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix("sRGB"); - double wp[3][3] = { - {wprof[0][0], wprof[0][1], wprof[0][2]}, - {wprof[1][0], wprof[1][1], wprof[1][2]}, - {wprof[2][0], wprof[2][1], wprof[2][2]} + const float wp[3][3] = { + {static_cast(wprof[0][0]), static_cast(wprof[0][1]), static_cast(wprof[0][2])}, + {static_cast(wprof[1][0]), static_cast(wprof[1][1]), static_cast(wprof[1][2])}, + {static_cast(wprof[2][0]), static_cast(wprof[2][1]), static_cast(wprof[2][2])} }; TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix("sRGB"); @@ -5922,8 +4427,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double array2D yc; array2D Yc; - - array2D histcurr; array2D histcurrref; @@ -6248,87 +4751,28 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double {11001., 0.957747, 1.541281}, {12001., 0.960440, 1.601019} }; - int N_t = sizeof(Txyz) / sizeof(Txyz[0]); //number of temperature White point - int nbt = N_t; - float **Tx = nullptr; - float **Ty = nullptr; - float **Tz = nullptr; - float **Ta = nullptr; - float **Tb = nullptr; - float **TL = nullptr; - double *TX = nullptr; - double *TY = nullptr; - double *TZ = nullptr; - int *good_spectral = nullptr; - // float studgood = 1000.f; + const int N_t = sizeof(Txyz) / sizeof(Txyz[0]); //number of temperature White point + constexpr int Nc = 200 + 1;//200 number of reference spectral colors, I think it is enough to retrieve good values + array2D Tx(Nc, N_t); + array2D Ty(Nc, N_t); + array2D Tz(Nc, N_t); + array2D Ta(Nc, N_t); + array2D Tb(Nc, N_t); + array2D TL(Nc, N_t); + double TX[Nc]; + double TY[Nc]; + double TZ[Nc]; + std::vector good_spectral(Nc, false); - int Nc = 200 + 1;//200 number of reference spectral colors, I think it is enough to retrieve good values - Tx = new float*[Nc]; + float rmm[N_t]; + float gmm[N_t]; + float bmm[N_t]; - for (int i = 0; i < Nc; i++) { - Tx[i] = new float[nbt]; - } - - Ty = new float*[Nc]; - - for (int i = 0; i < Nc; i++) { - Ty[i] = new float[nbt]; - } - - Tz = new float*[Nc]; - - for (int i = 0; i < Nc; i++) { - Tz[i] = new float[nbt]; - } - - Ta = new float*[Nc]; - - for (int i = 0; i < Nc; i++) { - Ta[i] = new float[nbt]; - } - - Tb = new float*[Nc]; - - for (int i = 0; i < Nc; i++) { - Tb[i] = new float[nbt]; - } - - TL = new float*[Nc]; - - for (int i = 0; i < Nc; i++) { - TL[i] = new float[nbt]; - } - - TX = new double [Nc]; - - - TY = new double [Nc]; - - - TZ = new double [Nc]; - - good_spectral = new int [Nc]; - - for (int i = 0; i < Nc; i++) { - good_spectral[i] = 0; - } - - float *rmm = nullptr; - rmm = new float [N_t]; - - float *gmm = nullptr; - gmm = new float [N_t]; - - float *bmm = nullptr; - bmm = new float [N_t]; - - int siza = 167;//size of histogram + constexpr int siza = 158;//size of histogram //tempref and greenref are camera wb values. // I used them by default to select good spectral values !! - if (tempref > 12000.f) { - tempref = 12000.f; - } + tempref = rtengine::min(tempref, 12000.0); int repref = 0; @@ -6339,8 +4783,9 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } } - //calculate R G B multiplier in function illuminant and temperature + const bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) + || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); for (int tt = 0; tt < N_t; tt++) { double r, g, b; float rm, gm, bm; @@ -6352,9 +4797,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double const float new_pre_mul[4] = { ri->get_pre_mul(0) / rm, ri->get_pre_mul(1) / gm, ri->get_pre_mul(2) / bm, ri->get_pre_mul(3) / gm }; float new_scale_mul[4]; - bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) - || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); - float gain = calculate_scale_mul(new_scale_mul, new_pre_mul, c_white, cblacksom, isMono, ri->get_colors()); + const float gain = calculate_scale_mul(new_scale_mul, new_pre_mul, c_white, cblacksom, isMono, ri->get_colors()); rm = new_scale_mul[0] / scale_mul[0] * gain; gm = new_scale_mul[1] / scale_mul[1] * gain; @@ -6367,7 +4810,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double struct hiss { int histnum; int index; - int interest; bool operator()(const hiss& lhis, const hiss& rhis) { return lhis.histnum < rhis.histnum; @@ -6391,28 +4833,15 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } ; - int histxy[siza];//number of values for each pair xy + LUTu histxy(siza); //number of values for each pair xy + histxy.clear(); - float area[siza];//multiplier for compensation differences area ==> big areas are rare near limit prophotos or more - - int inter[siza]; //interest for photographie 1 = small (limit gamut) 2 = normal 3 = major (skin, sky, neutral) - - float xxx[siza];//for color references calculated ==> max in images "like histogram" - - float yyy[siza]; - - float YYY[siza];//not used directly, but necessary to keep good range - - for (int p = 0; p < siza; p++) { - histxy[p] = 0; - area[p] = 20.f; - inter[p] = 1; - xxx[p] = 0.f; - yyy[p] = 0.f; - YYY[p] = 0.f; - } - - float estimchrom = 0.f; + LUTf xxx(siza);//for color references calculated ==> max in images "like histogram" + xxx.clear(); + LUTf yyy(siza); + yyy.clear(); + LUTf YYY(siza);//not used directly, but necessary to keep good range + YYY.clear(); bool separated = true; int w = -1; @@ -6422,9 +4851,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double reff_spect_yy_camera(N_t, 2 * Nc + 2); reff_spect_xx_camera(N_t, 2 * Nc + 2); - // reffYY(N_t, 2 * Nc);//in case of - //reffYY_prov(N_t, 2 * Nc); - //here we select the good spectral color inside the 113 values //call tempxy to calculate for 114 color references Temp and XYZ with cat02 @@ -6437,48 +4863,28 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double reff_spect_yy_camera[j][repref] = TY[j] / (TX[j] + TY[j] + TZ[j]); // y from xyY } - int deltarepref = settings->itcwb_delta; + const int deltarepref = settings->itcwb_delta; - for (int nn = 0; nn <= 2; nn++) { + StopWatch Stop1("Loop 1"); + for (int nn = 0, drep = -deltarepref; nn <= 2; ++nn, drep += deltarepref) { //three loop to refine color if temp camera is probably not very good - int drep = 0; - - if (nn == 0) { - drep = -deltarepref; - } - - if (nn == 2) { - drep = +deltarepref; - } - - int rep = repref + drep; - - if (rep > N_t) { - rep = N_t; - } - - if (rep < 0) { - rep = 0; - } + const int rep = rtengine::LIM(repref + drep, 0, N_t); + StopWatch Stop2("Loop 2"); //initialize calculation of xy current for tempref +#ifdef _OPENMP + #pragma omp parallel for +#endif for (int y = 0; y < bfh ; y += 10) { - for (int x = 0; x < bfw ; x += 10) { - int yy = y / 10; - int xx = x / 10 ; - float x_c = 0.f, y_c = 0.f, Y_c = 0.f; - float x_x = 0.f, y_y = 0.f, z_z = 0.f; - float RR = rmm[rep] * redloc[y][x]; - float GG = gmm[rep] * greenloc[y][x]; - float BB = bmm[rep] * blueloc[y][x]; - Color::rgbxyY(RR, GG, BB, x_c, y_c, Y_c, x_x, y_y, z_z, wp); - xc[yy][xx] = x_c; - yc[yy][xx] = y_c; - Yc[yy][xx] = Y_c; + int yy = y / 10; + for (int x = 0, xx = 0; x < bfw ; x += 10, ++xx) { + const float RR = rmm[rep] * redloc[y][x]; + const float GG = gmm[rep] * greenloc[y][x]; + const float BB = bmm[rep] * blueloc[y][x]; + Color::rgbxyY(RR, GG, BB, xc[yy][xx], yc[yy][xx], Yc[yy][xx], wp); } - } - + Stop2.stop(); //histogram xy depend of temp...but in most cases D45 ..D65.. //calculate for this image the mean values for each family of color, near histogram x y (number) //xy vary from x 0..0.77 y 0..0.82 @@ -6488,11 +4894,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double // step about 0.02 x 0.32 0.34 y= 0.34 0.36 skin -- sky x 0.24 0.30 y 0.28 0.32 //big step about 0.2 - histoxyY(bfhitc, bfwitc, xc, yc, Yc, xxx, yyy, YYY, histxy, area, inter); + histoxyY(bfhitc, bfwitc, xc, yc, Yc, xxx, yyy, YYY, histxy); } + Stop1.stop(); //calculate x y Y - int sizcurrref = siza;//choice of number of correlate colors in image + const int sizcurrref = siza;//choice of number of correlate colors in image histcurrref(N_t, sizcurrref); xx_curref(N_t, sizcurrref); yy_curref(N_t, sizcurrref); @@ -6506,48 +4913,36 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double hiss Wbhis [siza]; - int n1 = 0; - int n4 = 0; - int n15 = 0; - int n30 = 0; - int ntr = 0; for (int nh = 0; nh < siza; nh++) { Wbhis[nh].histnum = histxy[nh]; Wbhis[nh].index = nh; - Wbhis[nh].interest = inter[nh]; } //sort in ascending order std::sort(Wbhis, Wbhis + siza, Wbhis[0]); - for (int nh = 0; nh < siza; nh++) { -// printf("nh=%i", Wbhis[nh].index); - } - + int n1 = 0; + int n4 = 0; + int n15 = 0; + int n30 = 0; //part to improve for (int nh = 0; nh < siza; nh++) { - if (Wbhis[nh].histnum < 1) { - n1++; //keep only existing color but avoid to small - } - - if (Wbhis[nh].histnum < 4) { - n4++; //keep only existing color but avoid to small - } - - if (Wbhis[nh].histnum < 15) { - n15++; //keep only existing color but avoid to small - } - if (Wbhis[nh].histnum < 30) { n30++; //keep only existing color but avoid to small + if (Wbhis[nh].histnum < 15) { + n15++; //keep only existing color but avoid to small + if (Wbhis[nh].histnum < 4) { + n4++; //keep only existing color but avoid to small + if (Wbhis[nh].histnum < 1) { + n1++; //keep only existing color but avoid to small + } + } + } } - - } - - ntr = n30; + int ntr = n30; if (ntr > (siza - 25)) { ntr = n15; //if to less elements 25 elements mini @@ -6567,24 +4962,22 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double chrom wbchro[sizcu4]; - double swpr = (Txyz[repref].XX + Txyz[repref].ZZ + 1.); - double xwpr = Txyz[repref].XX / swpr;//white point for tt in xy coordiantes - double ywpr = 1. / swpr; + const double swpr = (Txyz[repref].XX + Txyz[repref].ZZ + 1.); + const double xwpr = Txyz[repref].XX / swpr;//white point for tt in xy coordiantes + const double ywpr = 1. / swpr; - for (int i = 0; i < sizcu4; i++) { //take the max values - int j = i; - histcurrref[j][repref] = (float) Wbhis[siza - (j + 1)].histnum; - xx_curref[j][repref] = xxx[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; - yy_curref[j][repref] = yyy[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; - YY_curref[j][repref] = YYY[Wbhis[siza - (j + 1)].index] / histcurrref[j][repref]; -// printf("xx=%f yy=%f\n", xx_curref[j][repref], yy_curref[j][repref]); + for (int i = 0; i < sizcu4; ++i) { //take the max values + histcurrref[i][repref] = (float) Wbhis[siza - (i + 1)].histnum; + xx_curref[i][repref] = xxx[Wbhis[siza - (i + 1)].index] / histcurrref[i][repref]; + yy_curref[i][repref] = yyy[Wbhis[siza - (i + 1)].index] / histcurrref[i][repref]; + YY_curref[i][repref] = YYY[Wbhis[siza - (i + 1)].index] / histcurrref[i][repref]; } - estimchrom = 0.f; + float estimchrom = 0.f; - for (int nh = 0; nh < sizcu4; nh++) { - float chxy = std::sqrt(SQR(xx_curref[nh][repref] - xwpr) + SQR(yy_curref[nh][repref] - ywpr)); + for (int nh = 0; nh < sizcu4; ++nh) { + const float chxy = std::sqrt(SQR(xx_curref[nh][repref] - xwpr) + SQR(yy_curref[nh][repref] - ywpr)); wbchro[nh].chroxy_number = chxy * std::sqrt(histcurrref[nh][repref]); wbchro[nh].chroxy = std::sqrt(chxy); wbchro[nh].chrox = xx_curref[nh][repref]; @@ -6595,68 +4988,40 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } estimchrom /= sizcu4; - //printf("estimchrom=%f \n", estimchrom); if (settings->itcwb_sort) { //sort in ascending with chroma values - std::sort(wbchro, wbchro + sizcu4, wbchro[0]); } - /* - for (int nh = 0; nh < sizcu4; nh++) { - printf("nh=%i chroma_xy=%f chrox=%f chroy=%f\n", nh, wbchro[nh].chroxy, wbchro[nh].chrox, wbchro[nh].chroy); - } - */ - int maxval = settings->itcwb_thres;//max values of color to find correllation + const int maxval = rtengine::LIM(settings->itcwb_thres, 10, 55);//max values of color to find correllation - if (maxval < 10) { - maxval = 10; - } + sizcurr2ref = rtengine::min(sizcurr2ref, maxval); //keep about the biggest values, - if (maxval > 55) { - maxval = 55; - } - - if (sizcurr2ref > maxval) { - sizcurr2ref = maxval; //keep about the biggest values, - } - - - for (int i = 0; i < sizcurr2ref; i++) { + for (int i = 0; i < sizcurr2ref; ++i) { //is condition chroxy necessary ? if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral w++; xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox; yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy; YY_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].Y; - // printf("xx_cu=%f yy_cu=%f Y=%f chro=%f\n", xx_curref_reduc[w][repref], yy_curref_reduc[w][repref], YY_curref_reduc[w][repref],std::sqrt(wbchro[sizcu4 - (i + 1)].chroxy)); } } //calculate deltaE xx to find best values of spectrals datas - int maxnb = settings->itcwb_sizereference; - - if (maxnb > 5) { - maxnb = 5; - } - - if (maxnb < 1) { - maxnb = 1; - } - + int maxnb = rtengine::LIM(settings->itcwb_sizereference, 1, 5); if (settings->itcwb_thres > 39) { maxnb = 200 / settings->itcwb_thres; } - for (int nb = 1; nb <= maxnb; nb ++) { //max 5 iterations for Itcwb_thres=33, after trial 3 is good in most cases but in some cases 5 - for (int i = 0; i < w; i++) { + for (int nb = 1; nb <= maxnb; ++nb) { //max 5 iterations for Itcwb_thres=33, after trial 3 is good in most cases but in some cases 5 + for (int i = 0; i < w; ++i) { float mindeltaE = 100000.f; int kN = 0; for (int j = 0; j < Nc ; j++) { - if (good_spectral[j] == 0) { - float deltaE = SQR(xx_curref_reduc[i][repref] - reff_spect_xx_camera[j][repref]) + SQR(yy_curref_reduc[i][repref] - reff_spect_yy_camera[j][repref]); + if (!good_spectral[j]) { + const float deltaE = SQR(xx_curref_reduc[i][repref] - reff_spect_xx_camera[j][repref]) + SQR(yy_curref_reduc[i][repref] - reff_spect_yy_camera[j][repref]); if (deltaE < mindeltaE) { mindeltaE = deltaE; @@ -6665,31 +5030,26 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } } - good_spectral[kN] = 1;//good spectral are spectral color that match color histogram xy - //printf("k=%i ", kN); + good_spectral[kN] = true;//good spectral are spectral color that match color histogram xy } } //reconvert to RGB for "reduction" for (int i = 0; i < w; i++) { - float X = 65535.f * xx_curref_reduc[i][repref] * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; - float Y = 65535.f * YY_curref_reduc[i][repref]; - float Z = 65535.f * (1.f - xx_curref_reduc[i][repref] - yy_curref_reduc[i][repref]) * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; + const float X = 65535.f * xx_curref_reduc[i][repref] * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; + const float Y = 65535.f * YY_curref_reduc[i][repref]; + const float Z = 65535.f * (1.f - xx_curref_reduc[i][repref] - yy_curref_reduc[i][repref]) * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; float r, g, b; Color::xyz2rgb(X, Y, Z, r, g, b, wip); - r /= rmm[repref]; - g /= gmm[repref]; - b /= bmm[repref]; - R_curref_reduc[i][repref] = r; - G_curref_reduc[i][repref] = g; - B_curref_reduc[i][repref] = b; + R_curref_reduc[i][repref] = r / rmm[repref]; + G_curref_reduc[i][repref] = g / gmm[repref]; + B_curref_reduc[i][repref] = b / bmm[repref]; } //end first part - //Now begin real calculations separated = false; ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants @@ -6707,57 +5067,37 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double //calculate x y z for each pixel with multiplier rmm gmm bmm - for (int tt = 0; tt < N_t; tt++) {//N_t - // double swp = (Txyz[tt].XX + Txyz[tt].ZZ + 1.); - // double xwp = Txyz[tt].XX / swp; - // double ywp = 1. / swp; - - - for (int i = 0; i < w; i++) { - float x_c = 0.f, y_c = 0.f, Y_c = 0.f; - float x_x = 0.f, y_y = 0.f, z_z = 0.f; - - float RR = rmm[tt] * R_curref_reduc[i][repref]; - float GG = gmm[tt] * G_curref_reduc[i][repref]; - float BB = bmm[tt] * B_curref_reduc[i][repref]; - Color::rgbxyY(RR, GG, BB, x_c, y_c, Y_c, x_x, y_y, z_z, wp); - // xxyycurr_reduc[2 * i][tt] = fabs(x_c - xwp); - // xxyycurr_reduc[2 * i + 1][tt] = fabs(y_c - ywp); - xxyycurr_reduc[2 * i][tt] = x_c; - xxyycurr_reduc[2 * i + 1][tt] = y_c; - // printf("w=%i tt=%i xx=%f yy=%f\n",i, tt, xxyycurr_reduc[2 * i][tt], xxyycurr_reduc[2 * i +1][tt]); + for (int tt = 0; tt < N_t; ++tt) {//N_t + for (int i = 0; i < w; ++i) { + float unused; + const float RR = rmm[tt] * R_curref_reduc[i][repref]; + const float GG = gmm[tt] * G_curref_reduc[i][repref]; + const float BB = bmm[tt] * B_curref_reduc[i][repref]; + Color::rgbxyY(RR, GG, BB, xxyycurr_reduc[2 * i][tt], xxyycurr_reduc[2 * i + 1][tt], unused, wp); } - for (int j = 0; j < Nc ; j++) { + for (int j = 0; j < Nc ; ++j) { reff_spect_xxyy_prov[2 * j][tt] = Tx[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // x from xyY reff_spect_xxyy_prov[2 * j + 1][tt] = Ty[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // y from xyY - //reffYY_prov[j][tt] = Ty[j][tt];//Y - // printf("w=%i tt=%i xx=%f yy=%f\n",j, tt,reffxxyy_prov[2 * kk][tt] ,reffxxyy_prov[2 * kk + 1][tt]); - } int kk = -1; - for (int i = 0; i < Nc ; i++) { - if (good_spectral[i] == 1) { + for (int i = 0; i < Nc ; ++i) { + if (good_spectral[i]) { kk++; //we calculate now absolute chroma for each spectral color - // reffxxyy[2 * kk][tt] = fabs(reffxxyy_prov[2 * i][tt] - xwp); - // reffxxyy[2 * kk + 1][tt] = fabs(reffxxyy_prov[2 * i + 1][tt] - ywp); - reff_spect_xxyy[2 * kk][tt] = reff_spect_xxyy_prov[2 * i][tt]; + reff_spect_xxyy[2 * kk][tt] = reff_spect_xxyy_prov[2 * i][tt]; reff_spect_xxyy[2 * kk + 1][tt] = reff_spect_xxyy_prov[2 * i + 1][tt]; - //printf("w=%i tt=%i xx=%f yy=%f\n",i, tt,reffxxyy[2 * kk][tt] ,reffxxyy[2 * kk + 1][tt]); - // reffYY[kk][tt] = reffYY_prov[i][tt]; } } float student = 0.f; - studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kk, tt, student); //for xy - //printf("tt=%i st=%f\n", tt, student); - float abstud = fabs(student); + + const float abstud = std::fabs(student); if (abstud < minstud) { // find the minimum Student minstud = abstud; @@ -6778,49 +5118,34 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double }; Tempgreen Tgstud[N_g]; - for (int i = 0; i < N_g; i++) {//init variables with + for (int i = 0; i < N_g; ++i) {//init variables with Tgstud[i].student = 1000.f;//max value to initialize Tgstud[i].tempref = 57; Tgstud[i].greenref = 39; } - int dgoodref = settings->itcwb_greendeltatemp; + const int dgoodref = rtengine::min(settings->itcwb_greendeltatemp, 4); + const int scantempbeg = rtengine::max(goodref - (dgoodref + 1), 1); + const int scantempend = rtengine::min(goodref + dgoodref, N_t - 1); - if (dgoodref > 4) { - dgoodref = 4; - } - - int scantempbeg = goodref - (dgoodref + 1); - - if (scantempbeg < 1) { - scantempbeg = 1; - } - - int scantempend = goodref + dgoodref; - - if (scantempend > N_t - 1) { - scantempend = N_t - 1; - } - - for (int gr = Rangegreenused.begin; gr < Rangegreenused.end; gr++) { + const bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) + || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); + for (int gr = Rangegreenused.begin; gr < Rangegreenused.end; ++gr) { float minstudgr = 100000.f; int goodrefgr = 1; - for (int tt = scantempbeg; tt < scantempend; tt++) { + for (int tt = scantempbeg; tt < scantempend; ++tt) { double r, g, b; - float rm, gm, bm; - ColorTemp WBiter = ColorTemp(Txyz[tt].Tem, gree[gr].green, 1.f, "Custom"); + ColorTemp WBiter(Txyz[tt].Tem, gree[gr].green, 1.f, "Custom"); WBiter.getMultipliers(r, g, b); - rm = imatrices.cam_rgb[0][0] * r + imatrices.cam_rgb[0][1] * g + imatrices.cam_rgb[0][2] * b; - gm = imatrices.cam_rgb[1][0] * r + imatrices.cam_rgb[1][1] * g + imatrices.cam_rgb[1][2] * b; - bm = imatrices.cam_rgb[2][0] * r + imatrices.cam_rgb[2][1] * g + imatrices.cam_rgb[2][2] * b; + float rm = imatrices.cam_rgb[0][0] * r + imatrices.cam_rgb[0][1] * g + imatrices.cam_rgb[0][2] * b; + float gm = imatrices.cam_rgb[1][0] * r + imatrices.cam_rgb[1][1] * g + imatrices.cam_rgb[1][2] * b; + float bm = imatrices.cam_rgb[2][0] * r + imatrices.cam_rgb[2][1] * g + imatrices.cam_rgb[2][2] * b; const float new_pre_mul[4] = { ri->get_pre_mul(0) / rm, ri->get_pre_mul(1) / gm, ri->get_pre_mul(2) / bm, ri->get_pre_mul(3) / gm }; float new_scale_mul[4]; - bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) - || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); - float gain = calculate_scale_mul(new_scale_mul, new_pre_mul, c_white, cblacksom, isMono, ri->get_colors()); + const float gain = calculate_scale_mul(new_scale_mul, new_pre_mul, c_white, cblacksom, isMono, ri->get_colors()); rm = new_scale_mul[0] / scale_mul[0] * gain; gm = new_scale_mul[1] / scale_mul[1] * gain; @@ -6831,66 +5156,42 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } - for (int tt = scantempbeg; tt < scantempend; tt++) {//N_t - // double swp = (Txyz[tt].XX + Txyz[tt].ZZ + 1.); - // double xwp = Txyz[tt].XX / swp; - // double ywp = 1. / swp; - - - for (int i = 0; i < w; i++) { - float x_c = 0.f, y_c = 0.f, Y_c = 0.f; - float x_x = 0.f, y_y = 0.f, z_z = 0.f; - - float RR = rmm[tt] * R_curref_reduc[i][repref]; - float GG = gmm[tt] * G_curref_reduc[i][repref]; - float BB = bmm[tt] * B_curref_reduc[i][repref]; - Color::rgbxyY(RR, GG, BB, x_c, y_c, Y_c, x_x, y_y, z_z, wp); - xxyycurr_reduc[2 * i][tt] = x_c; - xxyycurr_reduc[2 * i + 1][tt] = y_c; - // printf("w=%i tt=%i xx=%f yy=%f\n",i, tt, xxyycurr_reduc[2 * i][tt], xxyycurr_reduc[2 * i +1][tt]); + for (int tt = scantempbeg; tt < scantempend; ++tt) {//N_t + for (int i = 0; i < w; ++i) { + float unused; + const float RR = rmm[tt] * R_curref_reduc[i][repref]; + const float GG = gmm[tt] * G_curref_reduc[i][repref]; + const float BB = bmm[tt] * B_curref_reduc[i][repref]; + Color::rgbxyY(RR, GG, BB, xxyycurr_reduc[2 * i][tt], xxyycurr_reduc[2 * i + 1][tt], unused, wp); } - for (int j = 0; j < Nc ; j++) { + for (int j = 0; j < Nc ; ++j) { reff_spect_xxyy_prov[2 * j][tt] = Tx[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // x from xyY reff_spect_xxyy_prov[2 * j + 1][tt] = Ty[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // y from xyY - // reffYY_prov[j][tt] = Ty[j][tt];//Y - // printf("w=%i tt=%i xx=%f yy=%f\n",j, tt,reffxxyy_prov[2 * kk][tt] ,reffxxyy_prov[2 * kk + 1][tt]); - } //degrade correllation with color high chroma, but not too much...seems not good, but keep in case of?? if (estimchrom < 0.025f) {//very smal value of chroma for image - good_spectral[0] = 1;//blue - //good_spectral[1] = 1;//blue - // good_spectral[97] = 1;//blue - // good_spectral[93] = 1;//purple - // good_spectral[7] = 1;//green - good_spectral[11] = 1;//green - //good_spectral[42] = 1;//green - // good_spectral[75] = 1;//green - // good_spectral[46] = 1;//red - good_spectral[62] = 1;//red - // good_spectral[63] = 1;//red - // good_spectral[91] = 1;//ora - + good_spectral[0] = true;//blue + good_spectral[11] = true;//green + good_spectral[62] = true;//red } int kkg = -1; - for (int i = 0; i < Nc ; i++) { - if (good_spectral[i] == 1) { + for (int i = 0; i < Nc ; ++i) { + if (good_spectral[i]) { kkg++; - reff_spect_xxyy[2 * kkg][tt] = reff_spect_xxyy_prov[2 * i][tt]; + reff_spect_xxyy[2 * kkg][tt] = reff_spect_xxyy_prov[2 * i][tt]; reff_spect_xxyy[2 * kkg + 1][tt] = reff_spect_xxyy_prov[2 * i + 1][tt]; - // reffYY[kkg][tt] = reffYY_prov[i][tt]; } } float studentgr = 0.f; studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kkg, tt, studentgr); //for xy - float abstudgr = fabs(studentgr); + const float abstudgr = std::fabs(studentgr); if (abstudgr < minstudgr) { // find the minimum Student minstudgr = abstudgr; @@ -6902,15 +5203,10 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double Tgstud[gr].student = minstudgr; } - } std::sort(Tgstud, Tgstud + N_g, Tgstud[0]); - for (int j = 0; j < 20; j++) { - // printf("reftemp=%i refgreen=%i stud=%f \n", Tgstud[j].tempref, Tgstud[j].greenref, Tgstud[j].student); - } - //now search the value of green the nearest of 1 with a good student value // I take the 3 first values //I admit a symetrie in green coefiicient for rgb multiplier...probably not excatly true @@ -6919,17 +5215,17 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double int greengoodprov; int goodrefprov; float studprov; - int goodref0 = Tgstud[0].tempref; - int greengood0 = Tgstud[0].greenref - 39;//39 green = 1 - float stud0 = Tgstud[0].student; - int goodref1 = Tgstud[1].tempref; - float stud1 = Tgstud[1].student; - int greengood1 = Tgstud[1].greenref - 39; - int goodref2 = Tgstud[2].tempref; - int greengood2 = Tgstud[2].greenref - 39; - float stud2 = Tgstud[2].student; + const int goodref0 = Tgstud[0].tempref; + const int greengood0 = Tgstud[0].greenref - 39;//39 green = 1 + const float stud0 = Tgstud[0].student; + const int goodref1 = Tgstud[1].tempref; + const float stud1 = Tgstud[1].student; + const int greengood1 = Tgstud[1].greenref - 39; + const int goodref2 = Tgstud[2].tempref; + const int greengood2 = Tgstud[2].greenref - 39; + const float stud2 = Tgstud[2].student; - if (fabs(greengood2) < fabs(greengood1)) { + if (std::fabs(greengood2) < std::fabs(greengood1)) { greengoodprov = greengood2; goodrefprov = goodref2; studprov = stud2; @@ -6940,7 +5236,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } - if (fabs(greengoodprov) < fabs(greengood0)) { + if (std::fabs(greengoodprov) < std::fabs(greengood0)) { goodref = goodrefprov; greengood = greengoodprov + 39; studgood = studprov; @@ -6956,32 +5252,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } - histcurr(0, 0); - histcurrref(0, 0); - xxyycurr(0, 0); - xxyycurr_reduc(0, 0); - xx_curref(0, 0); - yy_curref(0, 0); - YY_curref(0, 0); - - reff_spect_xxyy(0, 0); - YYcurr(0, 0); - YYcurr_reduc(0, 0); - reff_spect_yy_camera(0, 0); - reff_spect_xx_camera(0, 0); - xx_curref_reduc(0, 0); - yy_curref_reduc(0, 0); - YY_curref_reduc(0, 0); - - R_curref_reduc(0, 0); - G_curref_reduc(0, 0); - B_curref_reduc(0, 0); - - reff_spect_xxyy_prov(0, 0); - -// reffYY(0, 0); -// reffYY_prov(0, 0); - avg_rm = 10000.f * rmm[goodref]; avg_gm = 10000.* gmm[goodref]; avg_bm = 10000.f * bmm[goodref]; @@ -6990,47 +5260,9 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double tempitc = Txyz[goodref].Tem; } - if (settings->verbose) { printf("ITCWB tempitc=%f gritc=%f stud=%f \n", tempitc, greenitc, studgood); } - - - xc(0, 0); - yc(0, 0); - Yc(0, 0); - - - - for (int i = 0; i < Nc; i++) { - delete [] Tx[i]; - delete [] Ty[i]; - delete [] Tz[i]; - delete [] Ta[i]; - delete [] Tb[i]; - delete [] TL[i]; - - } - - delete [] Tx; - delete [] Ty; - delete [] Tz; - delete [] Ta; - delete [] Tb; - delete [] TL; - delete [] TX; - delete [] TY; - delete [] TZ; - delete [] good_spectral; - - - delete [] rmm; - delete [] gmm; - delete [] bmm; - - - - } void RawImageSource::WBauto(double & tempref, double & greenref, array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh, double & avg_rm, double & avg_gm, double & avg_bm, double & tempitc, double & greenitc, float & studgood, bool & twotimes, const WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const ColorManagementParams & cmp, const RAWParams & raw) @@ -7153,7 +5385,7 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in double Yr = Y / 65535.; double Zr = Z / 65535.; - Ciecam02::xyz_to_cat02float ( redloc[i][j], greenloc[i][j], blueloc[i][j], Xr, Yr, Zr, 1); + Ciecam02::xyz_to_cat02float (redloc[i][j], greenloc[i][j], blueloc[i][j], Xr, Yr, Zr, 1); redloc[i][j] *= 65535.f; greenloc[i][j] *= 65535.f; blueloc[i][j] *= 65535.f; @@ -7189,7 +5421,7 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref for (int j = start; j < end; j++) { if (ri->getSensorType() != ST_BAYER) { - double dr = CLIP(initialGain * (rawData[i][3 * j] )); + double dr = CLIP(initialGain * (rawData[i][3 * j] )); double dg = CLIP(initialGain * (rawData[i][3 * j + 1])); double db = CLIP(initialGain * (rawData[i][3 * j + 2])); @@ -7202,7 +5434,7 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref avg_b += db; rn = gn = ++bn; } else { - int c = FC( i, j); + int c = FC(i, j); double d = CLIP(initialGain * (rawData[i][j])); if (d > clipHigh) { @@ -7225,7 +5457,7 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref } } else { if (ri->getSensorType() != ST_BAYER) { - if(ri->getSensorType() == ST_FUJI_XTRANS) { + if (ri->getSensorType() == ST_FUJI_XTRANS) { const double compval = clipHigh / initialGain; #ifdef _OPENMP #pragma omp parallel @@ -7272,7 +5504,7 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref for (int j = 32; j < W - 32; j++) { // each loop read 1 rgb triplet value - double dr = CLIP(initialGain * (rawData[i][3 * j] )); + double dr = CLIP(initialGain * (rawData[i][3 * j] )); double dg = CLIP(initialGain * (rawData[i][3 * j + 1])); double db = CLIP(initialGain * (rawData[i][3 * j + 2])); @@ -7369,16 +5601,16 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref if (wbpar.method == "autitcgreen") { //not used - redAWBMul = rm = avg_rm * refwb_red; + redAWBMul = rm = avg_rm * refwb_red; greenAWBMul = gm = avg_gm * refwb_green; - blueAWBMul = bm = avg_bm * refwb_blue; + blueAWBMul = bm = avg_bm * refwb_blue; } else { - const double reds = avg_r / std::max(1, rn) * refwb_red; + const double reds = avg_r / std::max(1, rn) * refwb_red; const double greens = avg_g / std::max(1, gn) * refwb_green; - const double blues = avg_b / std::max(1, bn) * refwb_blue; - redAWBMul = rm = imatrices.rgb_cam[0][0] * reds + imatrices.rgb_cam[0][1] * greens + imatrices.rgb_cam[0][2] * blues; + const double blues = avg_b / std::max(1, bn) * refwb_blue; + redAWBMul = rm = imatrices.rgb_cam[0][0] * reds + imatrices.rgb_cam[0][1] * greens + imatrices.rgb_cam[0][2] * blues; greenAWBMul = gm = imatrices.rgb_cam[1][0] * reds + imatrices.rgb_cam[1][1] * greens + imatrices.rgb_cam[1][2] * blues; - blueAWBMul = bm = imatrices.rgb_cam[2][0] * reds + imatrices.rgb_cam[2][1] * greens + imatrices.rgb_cam[2][2] * blues; + blueAWBMul = bm = imatrices.rgb_cam[2][0] * reds + imatrices.rgb_cam[2][1] * greens + imatrices.rgb_cam[2][2] * blues; } } @@ -7420,7 +5652,7 @@ void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) for (int j = start; j < end; j++) { if (ri->getSensorType() != ST_BAYER) { - double dr = CLIP(initialGain * (rawData[i][3 * j] )); + double dr = CLIP(initialGain * (rawData[i][3 * j] )); double dg = CLIP(initialGain * (rawData[i][3 * j + 1])); double db = CLIP(initialGain * (rawData[i][3 * j + 2])); @@ -7433,7 +5665,7 @@ void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) avg_b += db; rn = gn = ++bn; } else { - int c = FC( i, j); + int c = FC(i, j); double d = CLIP(initialGain * (rawData[i][j])); if (d > clipHigh) { @@ -7456,7 +5688,7 @@ void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) } } else { if (ri->getSensorType() != ST_BAYER) { - if(ri->getSensorType() == ST_FUJI_XTRANS) { + if (ri->getSensorType() == ST_FUJI_XTRANS) { const double compval = clipHigh / initialGain; #ifdef _OPENMP #pragma omp parallel @@ -7503,7 +5735,7 @@ void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) for (int j = 32; j < W - 32; j++) { // each loop read 1 rgb triplet value - double dr = CLIP(initialGain * (rawData[i][3 * j] )); + double dr = CLIP(initialGain * (rawData[i][3 * j] )); double dg = CLIP(initialGain * (rawData[i][3 * j + 1])); double db = CLIP(initialGain * (rawData[i][3 * j + 2])); @@ -7584,19 +5816,19 @@ void RawImageSource::getAutoWBMultipliers (double &rm, double &gm, double &bm) } } - if( settings->verbose ) { + if (settings->verbose) { printf ("AVG: %g %g %g\n", avg_r / std::max(1, rn), avg_g / std::max(1, gn), avg_b / std::max(1, bn)); } // return ColorTemp (pow(avg_r/rn, 1.0/6.0)*img_r, pow(avg_g/gn, 1.0/6.0)*img_g, pow(avg_b/bn, 1.0/6.0)*img_b); - double reds = avg_r / std::max(1, rn) * refwb_red; + double reds = avg_r / std::max(1, rn) * refwb_red; double greens = avg_g / std::max(1, gn) * refwb_green; - double blues = avg_b / std::max(1, bn) * refwb_blue; + double blues = avg_b / std::max(1, bn) * refwb_blue; - redAWBMul = rm = imatrices.rgb_cam[0][0] * reds + imatrices.rgb_cam[0][1] * greens + imatrices.rgb_cam[0][2] * blues; + redAWBMul = rm = imatrices.rgb_cam[0][0] * reds + imatrices.rgb_cam[0][1] * greens + imatrices.rgb_cam[0][2] * blues; greenAWBMul = gm = imatrices.rgb_cam[1][0] * reds + imatrices.rgb_cam[1][1] * greens + imatrices.rgb_cam[1][2] * blues; - blueAWBMul = bm = imatrices.rgb_cam[2][0] * reds + imatrices.rgb_cam[2][1] * greens + imatrices.rgb_cam[2][2] * blues; + blueAWBMul = bm = imatrices.rgb_cam[2][0] * reds + imatrices.rgb_cam[2][1] * greens + imatrices.rgb_cam[2][2] * blues; } ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector &green, std::vector &blue, int tran, double equal) @@ -7608,7 +5840,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vectorgetSensorType() != ST_BAYER) { - if(ri->getSensorType() == ST_FUJI_XTRANS) { + if (ri->getSensorType() == ST_FUJI_XTRANS) { int d[9][2] = {{0, 0}, { -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; for (size_t i = 0; i < red.size(); i++) { @@ -7621,7 +5853,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector= 0 && yv >= 0 && xv < W && yv < H) { + if (xv >= 0 && yv >= 0 && xv < W && yv < H) { if (ri->ISXTRANSRED(yv, xv)) { //RED rloc += (rawData[yv][xv]); rnbrs++; @@ -7659,7 +5891,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector 52500 || + if (initialGain * (rawData[yr][3 * xr] ) > 52500 || initialGain * (rawData[yg][3 * xg + 1]) > 52500 || initialGain * (rawData[yb][3 * xb + 2]) > 52500) { continue; @@ -7671,7 +5903,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector= 0 && ymin >= 0 && xmax < W && ymax < H) { - reds += (rawData[yr][3 * xr] ); + reds += (rawData[yr][3 * xr] ); greens += (rawData[yg][3 * xg + 1]); blues += (rawData[yb][3 * xb + 2]); rn++; @@ -7694,7 +5926,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector= 0 && yv >= 0 && xv < W && yv < H) { + if (xv >= 0 && yv >= 0 && xv < W && yv < H) { if (c == 0) { //RED rloc += (rawData[yv][xv]); rnbrs++; @@ -7730,7 +5962,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector= 0 && yv >= 0 && xv < W && yv < H) { + if (xv >= 0 && yv >= 0 && xv < W && yv < H) { if (c == 0) { //RED rloc += (rawData[yv][xv]); rnbrs++; @@ -7766,7 +5998,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vector= 0 && yv >= 0 && xv < W && yv < H) { + if (xv >= 0 && yv >= 0 && xv < W && yv < H) { if (c == 0) { //RED rloc += (rawData[yv][xv]); rnbrs++; @@ -7880,7 +6112,7 @@ void RawImageSource::inverse33 (const double (*rgb_cam)[3], double (*cam_rgb)[3] { double nom = (rgb_cam[0][2] * rgb_cam[1][1] * rgb_cam[2][0] - rgb_cam[0][1] * rgb_cam[1][2] * rgb_cam[2][0] - rgb_cam[0][2] * rgb_cam[1][0] * rgb_cam[2][1] + rgb_cam[0][0] * rgb_cam[1][2] * rgb_cam[2][1] + - rgb_cam[0][1] * rgb_cam[1][0] * rgb_cam[2][2] - rgb_cam[0][0] * rgb_cam[1][1] * rgb_cam[2][2] ); + rgb_cam[0][1] * rgb_cam[1][0] * rgb_cam[2][2] - rgb_cam[0][0] * rgb_cam[1][1] * rgb_cam[2][2]); cam_rgb[0][0] = (rgb_cam[1][2] * rgb_cam[2][1] - rgb_cam[1][1] * rgb_cam[2][2]) / nom; cam_rgb[0][1] = -(rgb_cam[0][2] * rgb_cam[2][1] - rgb_cam[0][1] * rgb_cam[2][2]) / nom; cam_rgb[0][2] = (rgb_cam[0][2] * rgb_cam[1][1] - rgb_cam[0][1] * rgb_cam[1][2]) / nom; @@ -7940,7 +6172,7 @@ void RawImageSource::init () void RawImageSource::getRawValues(int x, int y, int rotate, int &R, int &G, int &B) { - if(d1x) { // Nikon D1x has special sensor. We just skip it + if (d1x) { // Nikon D1x has special sensor. We just skip it R = G = B = 0; return; } @@ -7963,9 +6195,9 @@ void RawImageSource::getRawValues(int x, int y, int rotate, int &R, int &G, int ynew = LIM(ynew, 0, H - 1); int c = ri->getSensorType() == ST_FUJI_XTRANS ? ri->XTRANSFC(ynew,xnew) : ri->FC(ynew,xnew); int val = round(rawData[ynew][xnew] / scale_mul[c]); - if(c == 0) { + if (c == 0) { R = val; G = 0; B = 0; - } else if(c == 2) { + } else if (c == 2) { R = 0; G = 0; B = val; } else { R = 0; G = val; B = 0; From 96ab9863ddfcb85bdd3f44e977971694fe9309b4 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 10:37:32 +0100 Subject: [PATCH 03/13] fix segfault in ItcWB. #5676 --- rtengine/rawimagesource.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index fdc122569..daba0be2a 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4753,12 +4753,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double }; const int N_t = sizeof(Txyz) / sizeof(Txyz[0]); //number of temperature White point constexpr int Nc = 200 + 1;//200 number of reference spectral colors, I think it is enough to retrieve good values - array2D Tx(Nc, N_t); - array2D Ty(Nc, N_t); - array2D Tz(Nc, N_t); - array2D Ta(Nc, N_t); - array2D Tb(Nc, N_t); - array2D TL(Nc, N_t); + array2D Tx(N_t, Nc); + array2D Ty(N_t, Nc); + array2D Tz(N_t, Nc); + array2D Ta(N_t, Nc); + array2D Tb(N_t, Nc); + array2D TL(N_t, Nc); double TX[Nc]; double TY[Nc]; double TZ[Nc]; @@ -4865,12 +4865,10 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double const int deltarepref = settings->itcwb_delta; - StopWatch Stop1("Loop 1"); for (int nn = 0, drep = -deltarepref; nn <= 2; ++nn, drep += deltarepref) { //three loop to refine color if temp camera is probably not very good const int rep = rtengine::LIM(repref + drep, 0, N_t); - StopWatch Stop2("Loop 2"); //initialize calculation of xy current for tempref #ifdef _OPENMP #pragma omp parallel for @@ -4884,7 +4882,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double Color::rgbxyY(RR, GG, BB, xc[yy][xx], yc[yy][xx], Yc[yy][xx], wp); } } - Stop2.stop(); //histogram xy depend of temp...but in most cases D45 ..D65.. //calculate for this image the mean values for each family of color, near histogram x y (number) //xy vary from x 0..0.77 y 0..0.82 @@ -4896,7 +4893,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double histoxyY(bfhitc, bfwitc, xc, yc, Yc, xxx, yyy, YYY, histxy); } - Stop1.stop(); //calculate x y Y const int sizcurrref = siza;//choice of number of correlate colors in image From be5e447f53b3b0614552d8d0e618d9bc7435845d Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 13:16:42 +0100 Subject: [PATCH 04/13] Itcwb : cleanup and speedup, #5676 --- rtengine/colortemp.cc | 252 ++++--------------------------------- rtengine/rawimagesource.cc | 174 ++++++++----------------- rtgui/colorappearance.cc | 1 - 3 files changed, 79 insertions(+), 348 deletions(-) diff --git a/rtengine/colortemp.cc b/rtengine/colortemp.cc index 0edd7aeb2..75efa7979 100644 --- a/rtengine/colortemp.cc +++ b/rtengine/colortemp.cc @@ -3210,8 +3210,8 @@ void ColorTemp::temp2mul (double temp, double green, double equal, double& rmul, //calculate spectral data for blackbody at temp! double ColorTemp::blackbody_spect(double wavelength, double temperature) { - double wlm = wavelength * 1e-9; /* Wavelength in meters */ - return (3.7417715247e-16 / pow(wlm, 5)) / //3.7417..= c1 = 2*Pi*h*c2 where h=Planck constant, c=velocity of light + const double wlm = wavelength * 1e-9; /* Wavelength in meters */ + return (3.7417715247e-16 / (wlm * rtengine::pow4(wlm))) / //3.7417..= c1 = 2*Pi*h*c2 where h=Planck constant, c=velocity of light (xexp(1.438786e-2 / (wlm * temperature)) - 1.0); //1.4387..= c2 = h*c/k where k=Boltzmann constant } @@ -3337,62 +3337,38 @@ void ColorTemp::spectrum_to_color_xyz_preset(const double* spec_color, const dou void ColorTemp::spectrum_to_color_xyz_daylight(const double* spec_color, double _m1, double _m2, double &xx, double &yy, double &zz) { int i; - double lambda, X = 0, Y = 0, Z = 0, Yo = 0; + double lambda, X = 0, Y = 0, Z = 0; for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) { - - double Me; - double Mc; - - Me = get_spectral_color(lambda, spec_color); - Mc = daylight_spect(lambda, _m1, _m2); + const double Me = spec_color[i]; + const double Mc = daylight_spect(lambda, _m1, _m2); X += Mc * cie_colour_match_jd[i][0] * Me; Y += Mc * cie_colour_match_jd[i][1] * Me; Z += Mc * cie_colour_match_jd[i][2] * Me; } - for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) { - - double Ms; - - Ms = daylight_spect(lambda, _m1, _m2); - Yo += cie_colour_match_jd[i][1] * Ms; - } - - xx = X / Yo; - yy = Y / Yo; - zz = Z / Yo; + xx = X / Y; + yy = 1.0; + zz = Z / Y; } //calculate XYZ from spectrum data (color) and illuminant : J.Desmis december 2011 void ColorTemp::spectrum_to_color_xyz_blackbody(const double* spec_color, double _temp, double &xx, double &yy, double &zz) { int i; - double lambda, X = 0, Y = 0, Z = 0, Yo = 0; + double lambda, X = 0, Y = 0, Z = 0; for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) { - - double Me; - double Mc; - - Me = get_spectral_color(lambda, spec_color); - Mc = blackbody_spect(lambda, _temp); + const double Me = spec_color[i]; + const double Mc = blackbody_spect(lambda, _temp); X += Mc * cie_colour_match_jd[i][0] * Me; Y += Mc * cie_colour_match_jd[i][1] * Me; Z += Mc * cie_colour_match_jd[i][2] * Me; } - for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) { - - double Ms; - - Ms = blackbody_spect(lambda, _temp); - Yo += cie_colour_match_jd[i][1] * Ms; - } - - xx = X / Yo; - yy = Y / Yo; - zz = Z / Yo; + xx = X / Y; + yy = 1.0; + zz = Z / Y; } double ColorTemp::daylight_spect(double wavelength, double m1, double m2) @@ -3483,7 +3459,7 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa double ZZ; } WbTxyz; //probbaly can be "passed" with rawimagesource.cc but I don't know how to do. - WbTxyz Txyz[118] = {//temperature Xwb Zwb 118 values x wb and y wb are calculated after + constexpr WbTxyz Txyz[118] = {//temperature Xwb Zwb 118 values x wb and y wb are calculated after {2001., 1.273842, 0.145295}, {2101., 1.244008, 0.167533}, {2201., 1.217338, 0.190697}, @@ -3612,68 +3588,22 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa double Zref; } XYZref; XYZref Refxyz[N_c + 1]; - typedef struct XYZrefcat02 { - double Xrefcat; - double Yrefcat; - double Zrefcat; - } XYZrefcat02; - XYZrefcat02 Refxyzcat02[N_c + 1]; for (int i = 0; i < N_c; i++) { Refxyz[i].Xref = 0.f; Refxyz[i].Yref = 0.f; Refxyz[i].Zref = 0.f; - Refxyzcat02[i].Xrefcat = 0.f; - Refxyzcat02[i].Yrefcat = 0.f; - Refxyzcat02[i].Zrefcat = 0.f; } - - struct chrom { - float chroab; - float chroa; - float chrob; - int nn; - float L; - bool operator()(const chrom& lchro, const chrom& rchro) - { - return lchro.chroab < rchro.chroab; - } - - } ; - - // chrom wbchro[N_c + 1]; - double tempw = 5000.; if (separated) { tempw = Txyz[repref].Tem; - // tempw = 5004.; if (tempw <= INITIALBLACKBODY) { - // float aa = 0.f; - // float bb = 0.f; - for (int i = 0; i < N_c; i++) { spectrum_to_color_xyz_blackbody(spec_colorforxcyc[i], tempw, TX[i], TY[i], TZ[i]); - /* float XX = TX[i] * 65535.f; - float YY = TY[i] * 65535.f; - float ZZ = TZ[i] * 65535.f; - float L, a, b; - Color::XYZ2Lab(XX, YY, ZZ, L, a, b);//only to see Lab values in console - printf("N=%i L=%f a=%f b=%f\n", i, L / 327.68f, a / 327.68f, b / 327.68f); - aa += (a / 327.68f); - bb += (b / 327.68f); - */ } - - /* - aa /= N_c; - bb /= N_c; - printf("aa=%f bb=%f\n", aa, bb); - */ - // } - } else { double m11, m22, x_DD, y_DD, interm2; @@ -3689,97 +3619,21 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD); m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2; m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2; - // float aa = 0.f; - // float bb = 0.f; for (int i = 0; i < N_c; i++) { spectrum_to_color_xyz_daylight(spec_colorforxcyc[i], m11, m22, TX[i], TY[i], TZ[i]); - -/* float XX = TX[i] * 65535.f; - float YY = TY[i] * 65535.f; - float ZZ = TZ[i] * 65535.f; - float L, a, b; - Color::XYZ2Lab(XX, YY, ZZ, L, a, b);//only to see Lab values in console - // printf("N=%i L=%f a=%f b=%f\n", i, L / 327.68f, a / 327.6 8f, b / 327.68f); - aa += (a / 327.68f); - bb += (b / 327.68f); - wbchro[i].chroab = (sqrt(SQR(a) + SQR(b))) / 327.68f; - wbchro[i].chroa = a / 327.68f; - wbchro[i].chrob = b / 327.68f; - wbchro[i].nn = i; -*/ - - } -/* - std::sort(wbchro, wbchro + N_c + 1, wbchro[0]); - float ab5 = 0.f; - int n5 = 0; - float ab15 = 0.f; - int n15 = 0; - float ab30 = 0.f; - int n30 = 0; - float ab50 = 0.f; - int n50 = 0; - float ab70 = 0.f; - int n70 = 0; - float ab120 = 0.f; - int n120 = 0; - - for (int i = 0; i < N_c; i++) { - if (wbchro[i].chroab < 5.f) { - ab5 += (wbchro[i].chroa + wbchro[i].chrob); - n5++; - } else if (wbchro[i].chroab < 15.f) { - ab15 += (wbchro[i].chroa + wbchro[i].chrob); - n15++; - } else if (wbchro[i].chroab < 30.f) { - ab30 += (wbchro[i].chroa + wbchro[i].chrob); - n30++; - } else if (wbchro[i].chroab < 50.f) { - ab50 += (wbchro[i].chroa + wbchro[i].chrob); - n50++; - } else if (wbchro[i].chroab < 70.f) { - ab70 += (wbchro[i].chroa + wbchro[i].chrob); - n70++; - } else if (wbchro[i].chroab < 120.f) { - ab120 += (wbchro[i].chroa + wbchro[i].chrob); - n120++; - } - - printf("N=%i nn=%i chr=%f cha=%f chb=%f\n", i, wbchro[i].nn, wbchro[i].chroab, wbchro[i].chroa, wbchro[i].chrob); - } - - printf("ab5=%f n5=%i\n", ab5 / n5, n5); - printf("ab15=%f n15=%i\n", ab15 / n15, n15); - printf("ab30=%f n30=%i\n", ab30 / n30, n30); - printf("ab50=%f n50=%i\n", ab50 / n50, n50); - printf("ab70=%f n70=%i\n", ab70 / n70, n70); - printf("ab120=%f n120=%i\n", ab120 / n120, n120); - aa /= N_c; - bb /= N_c; - printf("aa=%f bb=%f\n", aa, bb); - //very low 15 --, 16 -+, 17 + -, 18 +-, 20 ++, 22 -+, 73 ++, 98 ++, 99 -+, 101 -+, 129 ++, 130 -+, 131 --, - //low 8 +-, 9 --, 10 --, 12 --, 19 -+, 21 -+, 24 -+, 25 ++, 27 ++, 30 ++, 33++, 34 ++, 36 ++, 37++,38 +-, - */ } - } - - if (!separated) { - // std::string wbcat02Method = wbpar.wbcat02Method; - std::string wbcat02Method = "none"; - + } else { for (int tt = 0; tt < N_t; tt++) { tempw = Txyz[tt].Tem; if (tempw <= INITIALBLACKBODY) { - for (int i = 0; i < N_c; i++) { spectrum_to_color_xyz_blackbody(spec_colorforxcyc[i], tempw, Refxyz[i].Xref, Refxyz[i].Yref, Refxyz[i].Zref); } - } else { - double m11, m22, x_DD, y_DD, interm2; + double x_DD; if (tempw <= 7000) { x_DD = -4.6070e9 / (tempw * tempw * tempw) + 2.9678e6 / (tempw * tempw) + 0.09911e3 / tempw + 0.244063; @@ -3787,80 +3641,22 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa x_DD = -2.0064e9 / (tempw * tempw * tempw) + 1.9018e6 / (tempw * tempw) + 0.24748e3 / tempw + 0.237040; } - y_DD = -3.0 * x_DD * x_DD + 2.87 * x_DD - 0.275; + const double y_DD = -3.0 * x_DD * x_DD + 2.87 * x_DD - 0.275; //calculate D -daylight in function of s0, s1, s2 and temp ==> x_D y_D //S(lamda)=So(lambda)+m1*s1(lambda)+m2*s2(lambda) - interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD); - m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2; - m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2; + const double interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD); + const double m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2; + const double m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2; for (int i = 0; i < N_c; i++) { spectrum_to_color_xyz_daylight(spec_colorforxcyc[i], m11, m22, Refxyz[i].Xref, Refxyz[i].Yref, Refxyz[i].Zref); } } -//CAT02 - - float CAM02BB00 = 1.0, CAM02BB01 = 1.0, CAM02BB02 = 1.0, CAM02BB10 = 1.0, CAM02BB11 = 1.0, CAM02BB12 = 1.0, CAM02BB20 = 1.0, CAM02BB21 = 1.0, CAM02BB22 = 1.0; //for CIECAT02 - float Xwb = Txyz[tt].XX; - float Ywb = 1.; - float Zwb = Txyz[tt].ZZ; - - if (wbcat02Method == "icam") {//not used - icieCAT02float(Xwb, Ywb, Zwb, CAM02BB00, CAM02BB01, CAM02BB02, CAM02BB10, CAM02BB11, CAM02BB12, CAM02BB20, CAM02BB21, CAM02BB22, 1.0); - } - - if (wbcat02Method == "cam") { - - cieCAT02float(Xwb, Ywb, Zwb, CAM02BB00, CAM02BB01, CAM02BB02, CAM02BB10, CAM02BB11, CAM02BB12, CAM02BB20, CAM02BB21, CAM02BB22, 1.0); - } - - if (wbcat02Method == "none") { - - for (int i = 0; i < N_c; i++) { - Refxyzcat02[i].Xrefcat = CAM02BB00 * Refxyz[i].Xref + CAM02BB01 * Refxyz[i].Yref + CAM02BB02 * Refxyz[i].Zref ; - Refxyzcat02[i].Yrefcat = CAM02BB10 * Refxyz[i].Xref + CAM02BB11 * Refxyz[i].Yref + CAM02BB12 * Refxyz[i].Zref ; - Refxyzcat02[i].Zrefcat = CAM02BB20 * Refxyz[i].Xref + CAM02BB21 * Refxyz[i].Yref + CAM02BB22 * Refxyz[i].Zref; - } - } - -//end CAT02 - for (int i = 0; i < N_c; i++) { - /* float X = 65535.f * Refxyzcat02[i].Xrefcat; - float Y = 65535.f * Refxyzcat02[i].Yrefcat; - float Z = 65535.f * Refxyzcat02[i].Zrefcat; - float L, a, b; - Color::XYZ2Lab(X, Y, Z, L, a, b); - - double som = (Refxyzcat02[i].Xrefcat + Refxyzcat02[i].Yrefcat + Refxyzcat02[i].Zrefcat); - L /= 327.68f; - a /= 327.68f; - b /= 327.68f; - Ta[i][tt] = a; - Tb[i][tt] = b; - TL[i][tt] = L; - TX[i][tt] = X; - TY[i][tt] = Y; - TZ[i][tt] = Z; - */ - //som = 1.; -// Tx[i][tt] = (float) Refxyz[i].Xref; -// Ty[i][tt] = (float) Refxyz[i].Yref; -// Tz[i][tt] = (float) Refxyz[i].Zref; - -// if (wbpar.wbcat02Method == "none") { - if (wbcat02Method == "none") { - - Tx[i][tt] = (float) Refxyz[i].Xref; - Ty[i][tt] = (float) Refxyz[i].Yref; - Tz[i][tt] = (float) Refxyz[i].Zref; - } else { - Tx[i][tt] = (float) Refxyzcat02[i].Xrefcat; - Ty[i][tt] = (float) Refxyzcat02[i].Yrefcat; - Tz[i][tt] = (float) Refxyzcat02[i].Zrefcat; - } - + Tx[i][tt] = Refxyz[i].Xref; + Ty[i][tt] = Refxyz[i].Yref; + Tz[i][tt] = Refxyz[i].Zref; } } } diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index daba0be2a..9f7b9a850 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4292,54 +4292,49 @@ static void histoxyY(int bfhitc, int bfwitc, const array2D & xc, const ar } } -void static studentXY(const array2D & YYcurr, const array2D & reffYY, int sizcurr, int Nc, int tt, float & student) +float static studentXY(const array2D & YYcurr, const array2D & reffYY, int sizcurr, int Nc, int tt) { //calculate Student coeff YY float somcurrY = 0.f; float somreffY = 0.f; float somcurr2Y = 0.f; float somreff2Y = 0.f; - float somsqueccurrY = 0.f; - float somsquecreffY = 0.f; - int sizestucurrY = sizcurr; - int sizestureffY = Nc; - for (int i = 0; i < sizestucurrY; i++) { - somcurrY += 100.f * YYcurr[i][tt]; + for (int i = 0; i < sizcurr; i++) { + somcurrY += YYcurr[i][tt]; //sum observations first group } + somcurrY *= 100.f; - for (int i = 0; i < sizestureffY; i++) { - somreffY += 100.f * reffYY[i][tt]; + for (int i = 0; i < Nc; i++) { + somreffY += reffYY[i][tt]; //sum observations second group - } + somreffY *= 100.f; - - for (int i = 0; i < sizestucurrY; i++) { - somcurr2Y += SQR(100.f * YYcurr[i][tt]); + for (int i = 0; i < sizcurr; i++) { + somcurr2Y += SQR(YYcurr[i][tt]); //sum sqr observations first group - } + somreffY *= SQR(100.f); - for (int i = 0; i < sizestureffY; i++) { - somreff2Y += SQR(100.f * reffYY[i][tt]); + for (int i = 0; i < Nc; i++) { + somreff2Y += SQR(reffYY[i][tt]); //sum sqr observations second group - } + somreff2Y *= SQR(100.f); - somsqueccurrY = somcurr2Y - (SQR(somcurrY)) / sizestucurrY; + const float somsqueccurrY = somcurr2Y - (SQR(somcurrY)) / sizcurr; //sum sqr differences first - somsquecreffY = somreff2Y - (SQR(somreffY)) / sizestureffY; + const float somsquecreffY = somreff2Y - (SQR(somreffY)) / Nc; //sum sqr differences second - float diviY = std::sqrt(((somsqueccurrY + somsquecreffY) * (1.f / (float)sizestucurrY + 1.f / (float)sizestureffY)) / (sizestucurrY + sizestureffY - 2)); + const float diviY = std::sqrt(((somsqueccurrY + somsquecreffY) * (1.f / sizcurr + 1.f / Nc)) / (sizcurr + Nc - 2)); //divisor student - float numerY = ((float)somcurrY / (float)sizestucurrY) - ((float)somreffY / (float)sizestureffY); + const float numerY = somcurrY / sizcurr - somreffY / Nc; //numerator student -// printf("num=%f divY=%f \n", numerY, diviY); - student = numerY / diviY ; + return numerY / diviY ; //student coeeficient } @@ -4404,9 +4399,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double Itcwb_sizereference : 3 by default, can be set to 5 ==> size of reference color compare to size of histogram real color itcwb_delta : 1 by default can be set between 0 to 5 ==> delta temp to build histogram xy - if camera temp is not probably good */ - // BENCHFUN BENCHFUN - TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix("sRGB"); const float wp[3][3] = { @@ -4423,49 +4416,19 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double {wiprof[2][0], wiprof[2][1], wiprof[2][2]} }; - array2D xc; - array2D yc; - array2D Yc; + const int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 + const int bfhitc = bfh / 10 + 1; - array2D histcurr; - array2D histcurrref; - - array2D xxyycurr; - array2D xxyycurr_reduc; - array2D xx_curref; - array2D yy_curref; - array2D YY_curref; - array2D xx_curref_reduc; - array2D yy_curref_reduc; - array2D R_curref_reduc; - array2D G_curref_reduc; - array2D B_curref_reduc; - - array2D reff_spect_xxyy; - array2D reff_spect_xxyy_prov; - array2D YYcurr; - array2D YY_curref_reduc; - array2D YYcurr_reduc; - // array2D reffYY; - // array2D reffYY_prov; - - array2D reff_spect_yy_camera; - array2D reff_spect_xx_camera; - - - int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 - int bfhitc = bfh / 10 + 1; - - xc(bfwitc, bfhitc); - yc(bfwitc, bfhitc); - Yc(bfwitc, bfhitc); + array2D xc(bfwitc, bfhitc); + array2D yc(bfwitc, bfhitc); + array2D Yc(bfwitc, bfhitc); typedef struct WbGreen { double green; float snedecor;//1. actually but put in case of confiance interval } WbGreen; - constexpr WbGreen gree[118] = {//symetric coefficient between 0.717 and 1.40 + constexpr WbGreen gree[118] = {//symmetric coefficient between 0.717 and 1.40 {0.400, 1.f}, {0.500, 1.f}, {0.550, 1.f}, @@ -4585,7 +4548,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double {3.800, 1.f}, {4.000, 1.f} }; - int N_g = sizeof(gree) / sizeof(gree[0]); //number of green + const int N_g = sizeof(gree) / sizeof(gree[0]); //number of green typedef struct RangeGreen { int begin; @@ -4593,37 +4556,20 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double int ng; } RangeGreen; - RangeGreen Rangestandard; - Rangestandard.begin = 8; - Rangestandard.end = 70; - Rangestandard.ng = 62; - - RangeGreen Rangeextand; - Rangeextand.begin = 4; - Rangeextand.end = 77; - Rangeextand.ng = 73; - - RangeGreen Rangemax; - Rangemax.begin = 0; - Rangemax.end = N_g; - Rangemax.ng = N_g; + constexpr RangeGreen Rangestandard = {8, 70, 62}; + constexpr RangeGreen Rangeextand = {4, 77, 73}; + const RangeGreen Rangemax = {0, N_g, N_g}; RangeGreen Rangegreenused; if (settings->itcwb_greenrange == 0) { Rangegreenused = Rangestandard; - } - - else if (settings->itcwb_greenrange == 1) { + } else if (settings->itcwb_greenrange == 1) { Rangegreenused = Rangeextand; } else { Rangegreenused = Rangemax; } - // printf("rangemin=%i rangmax=%i\n", Rangegreenused.begin, Rangegreenused.end); - - - typedef struct WbTxyz { double Tem; double XX; @@ -4785,8 +4731,8 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double //calculate R G B multiplier in function illuminant and temperature const bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) - || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); - for (int tt = 0; tt < N_t; tt++) { + || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); + for (int tt = 0; tt < N_t; ++tt) { double r, g, b; float rm, gm, bm; ColorTemp WBiter = ColorTemp(Txyz[tt].Tem, greenitc, 1.f, "Custom"); @@ -4845,11 +4791,11 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double bool separated = true; int w = -1; - //printf("greenrefraw=%f\n", greenref); - reff_spect_xxyy(N_t, 2 * Nc + 2); - reff_spect_xxyy_prov(N_t, 2 * Nc + 2); - reff_spect_yy_camera(N_t, 2 * Nc + 2); - reff_spect_xx_camera(N_t, 2 * Nc + 2); + + array2D reff_spect_xxyy(N_t, 2 * Nc + 2); + array2D reff_spect_xxyy_prov(N_t, 2 * Nc + 2); + array2D reff_spect_yy_camera(N_t, 2 * Nc + 2); + array2D reff_spect_xx_camera(N_t, 2 * Nc + 2); //here we select the good spectral color inside the 113 values //call tempxy to calculate for 114 color references Temp and XYZ with cat02 @@ -4896,19 +4842,18 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double //calculate x y Y const int sizcurrref = siza;//choice of number of correlate colors in image - histcurrref(N_t, sizcurrref); - xx_curref(N_t, sizcurrref); - yy_curref(N_t, sizcurrref); - YY_curref(N_t, sizcurrref); - xx_curref_reduc(N_t, sizcurrref); - yy_curref_reduc(N_t, sizcurrref); - YY_curref_reduc(N_t, sizcurrref); - R_curref_reduc(N_t, sizcurrref); - G_curref_reduc(N_t, sizcurrref); - B_curref_reduc(N_t, sizcurrref); + array2D histcurrref(N_t, sizcurrref); + array2D xx_curref(N_t, sizcurrref); + array2D yy_curref(N_t, sizcurrref); + array2D YY_curref(N_t, sizcurrref); + array2D xx_curref_reduc(N_t, sizcurrref); + array2D yy_curref_reduc(N_t, sizcurrref); + array2D YY_curref_reduc(N_t, sizcurrref); + array2D R_curref_reduc(N_t, sizcurrref); + array2D G_curref_reduc(N_t, sizcurrref); + array2D B_curref_reduc(N_t, sizcurrref); - - hiss Wbhis [siza]; + hiss Wbhis[siza]; for (int nh = 0; nh < siza; nh++) { Wbhis[nh].histnum = histxy[nh]; @@ -4995,7 +4940,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double for (int i = 0; i < sizcurr2ref; ++i) { //is condition chroxy necessary ? - if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral + if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral w++; xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox; yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy; @@ -5045,21 +4990,20 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double //end first part - //Now begin real calculations separated = false; ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants //calculate x y Y int sizcurr = siza;//choice of number of correlate colors in image - histcurr(N_t, sizcurr); - xxyycurr(N_t, 2 * sizcurr); - xxyycurr_reduc(N_t, 2 * sizcurr); + array2D histcurr(N_t, sizcurr); + array2D xxyycurr(N_t, 2 * sizcurr); + array2D xxyycurr_reduc(N_t, 2 * sizcurr); float minstud = 100000.f; int goodref = 1; - YYcurr(N_t, sizcurr); - YYcurr_reduc(N_t, sizcurr); + array2D YYcurr(N_t, sizcurr); + array2D YYcurr_reduc(N_t, sizcurr); //calculate x y z for each pixel with multiplier rmm gmm bmm @@ -5089,17 +5033,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } } - float student = 0.f; - - studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kk, tt, student); //for xy - - const float abstud = std::fabs(student); + const float abstud = std::fabs(studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kk, tt)); if (abstud < minstud) { // find the minimum Student minstud = abstud; goodref = tt; } - } if (extra) { @@ -5184,10 +5123,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } } - float studentgr = 0.f; - - studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kkg, tt, studentgr); //for xy - const float abstudgr = std::fabs(studentgr); + const float abstudgr = std::fabs(studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kkg, tt)); if (abstudgr < minstudgr) { // find the minimum Student minstudgr = abstudgr; diff --git a/rtgui/colorappearance.cc b/rtgui/colorappearance.cc index eed1c074b..1e7f76b44 100644 --- a/rtgui/colorappearance.cc +++ b/rtgui/colorappearance.cc @@ -823,7 +823,6 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) nexttemp = pp->wb.temperature; nextgreen = pp->wb.green; - printf("temp=%f green=%f\n", nexttemp, nextgreen); if (pedited) { degree->setEditedState (pedited->colorappearance.degree ? Edited : UnEdited); degreeout->setEditedState (pedited->colorappearance.degreeout ? Edited : UnEdited); From 8e1bb5ba90bcbdef43073cda8b691111da60a32d Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 14:07:27 +0100 Subject: [PATCH 05/13] Fix broken cppcheck --- rtgui/options.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rtgui/options.h b/rtgui/options.h index 0bc421300..b8a71c9cb 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -20,12 +20,15 @@ #include #include +#if defined __has_include #if __has_include() #include #else #include #endif - +#else +#include +#endif #include "../rtengine/settings.h" #include From be765768ffe5a863d33a6ceaf989c3c0485d4114 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 14:19:06 +0100 Subject: [PATCH 06/13] further cleanups --- rtengine/colortemp.cc | 10 ++++------ rtengine/colortemp.h | 2 +- rtengine/rawimagesource.cc | 35 ++++------------------------------- rtengine/rt_math.h | 6 ++++++ 4 files changed, 15 insertions(+), 38 deletions(-) diff --git a/rtengine/colortemp.cc b/rtengine/colortemp.cc index 75efa7979..ec8641fc0 100644 --- a/rtengine/colortemp.cc +++ b/rtengine/colortemp.cc @@ -3211,7 +3211,7 @@ void ColorTemp::temp2mul (double temp, double green, double equal, double& rmul, double ColorTemp::blackbody_spect(double wavelength, double temperature) { const double wlm = wavelength * 1e-9; /* Wavelength in meters */ - return (3.7417715247e-16 / (wlm * rtengine::pow4(wlm))) / //3.7417..= c1 = 2*Pi*h*c2 where h=Planck constant, c=velocity of light + return (3.7417715247e-16 / rtengine::pow5(wlm)) / //3.7417..= c1 = 2*Pi*h*c2 where h=Planck constant, c=velocity of light (xexp(1.438786e-2 / (wlm * temperature)) - 1.0); //1.4387..= c2 = h*c/k where k=Boltzmann constant } @@ -3400,7 +3400,7 @@ double ColorTemp::daylight_spect(double wavelength, double m1, double m2) // we can change step for temperature and increase number for T > 7500K if necessary //these values Temp, x, y are references for all calculations and very precise. //copyright J.Desmis august 2017 and june 2018 -void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, float **Tz, float **Ta, float **Tb, float **TL, double *TX, double *TY, double *TZ, const procparams::WBParams & wbpar) +void ColorTemp::tempxy(bool separated, int repref, float **Tx, float **Ty, float **Tz, float **Ta, float **Tb, float **TL, double *TX, double *TY, double *TZ, const procparams::WBParams & wbpar) { const double* spec_colorforxcyc[] = {//color references JDC468_BluH10_spect, JDC468_BluD6_spect, ColorchechCyaF3_spect, JDC468_BluM5_spect, // 0 3 @@ -3595,10 +3595,8 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa Refxyz[i].Zref = 0.f; } - double tempw = 5000.; - if (separated) { - tempw = Txyz[repref].Tem; + const double tempw = Txyz[repref].Tem; if (tempw <= INITIALBLACKBODY) { for (int i = 0; i < N_c; i++) { @@ -3626,7 +3624,7 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa } } else { for (int tt = 0; tt < N_t; tt++) { - tempw = Txyz[tt].Tem; + const double tempw = Txyz[tt].Tem; if (tempw <= INITIALBLACKBODY) { for (int i = 0; i < N_c; i++) { diff --git a/rtengine/colortemp.h b/rtengine/colortemp.h index fd2796552..5feed9d26 100644 --- a/rtengine/colortemp.h +++ b/rtengine/colortemp.h @@ -54,7 +54,7 @@ public: explicit ColorTemp (double e) : temp(-1.), green(-1.), equal (e), method("Custom") {} ColorTemp (double t, double g, double e, const std::string &m); ColorTemp (double mulr, double mulg, double mulb, double e); - static void tempxy(bool separated, int &repref, float **Tx, float **Ty, float **Tz, float **Ta, float **Tb, float **TL, double *TX, double *TY, double *TZ, const procparams::WBParams & wbpar); + static void tempxy(bool separated, int repref, float **Tx, float **Ty, float **Tz, float **Ta, float **Tb, float **TL, double *TX, double *TY, double *TZ, const procparams::WBParams & wbpar); void update (const double rmul, const double gmul, const double bmul, const double equal, const double tempBias=0.0) { diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 9f7b9a850..1cbdf1140 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4553,12 +4553,11 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double typedef struct RangeGreen { int begin; int end; - int ng; } RangeGreen; - constexpr RangeGreen Rangestandard = {8, 70, 62}; - constexpr RangeGreen Rangeextand = {4, 77, 73}; - const RangeGreen Rangemax = {0, N_g, N_g}; + constexpr RangeGreen Rangestandard = {8, 70}; + constexpr RangeGreen Rangeextand = {4, 77}; + const RangeGreen Rangemax = {0, N_g}; RangeGreen Rangegreenused; @@ -5064,8 +5063,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double const int scantempbeg = rtengine::max(goodref - (dgoodref + 1), 1); const int scantempend = rtengine::min(goodref + dgoodref, N_t - 1); - const bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO)) - || (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO)); for (int gr = Rangegreenused.begin; gr < Rangegreenused.end; ++gr) { float minstudgr = 100000.f; int goodrefgr = 1; @@ -5185,7 +5182,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } avg_rm = 10000.f * rmm[goodref]; - avg_gm = 10000.* gmm[goodref]; + avg_gm = 10000.f * gmm[goodref]; avg_bm = 10000.f * bmm[goodref]; if (!extra) { @@ -5206,7 +5203,6 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D if (greenref > 0.77 && greenref < 1.3) { greenitc = greenref; - extra = false; if (settings->itcwb_forceextra) { extra = true; @@ -5222,7 +5218,6 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D } } - void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) { //used by auto WB local to calculate red, green, blue in local region @@ -5304,28 +5299,6 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in blueloc[i][j] = Color::gammatab_srgb[blueloc[i][j]]; } } - - if (cat02) {//CAT02 - /* - //not good threatment, I must wait merge branch cat02wb - for (int i = 0; i < bfh; i++) - for (int j = 0; j < bfw; j++) { - float X = 0.f, Y = 0.f, Z = 0.f; - Color::rgbxyz(redloc[i][j], greenloc[i][j], blueloc[i][j], X, Y, Z, wp); - double temp; - double Xr = X / 65535.; - double Yr = Y / 65535.; - double Zr = Z / 65535.; - - Ciecam02::xyz_to_cat02float (redloc[i][j], greenloc[i][j], blueloc[i][j], Xr, Yr, Zr, 1); - redloc[i][j] *= 65535.f; - greenloc[i][j] *= 65535.f; - blueloc[i][j] *= 65535.f; - //to do ciecam adaptation - } - */ - } - } void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref, double & tempitc, double & greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double & rm, double & gm, double & bm, const WBParams & wbpar, const ColorManagementParams & cmp, const RAWParams & raw) diff --git a/rtengine/rt_math.h b/rtengine/rt_math.h index 9342f5430..6d4799254 100644 --- a/rtengine/rt_math.h +++ b/rtengine/rt_math.h @@ -44,6 +44,12 @@ constexpr T pow4(T x) return SQR(SQR(x)); } +template +constexpr T pow5(T x) +{ + return x * pow4(x); +} + template constexpr const T& min(const T& a) { From 6029b29d89ba7e4bafc2d2a7ed2ff0bbd39efbac Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 14:59:26 +0100 Subject: [PATCH 07/13] fix copy/paste bug --- rtengine/rawimagesource.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 1cbdf1140..bf88b2955 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4316,7 +4316,7 @@ float static studentXY(const array2D & YYcurr, const array2D & ref somcurr2Y += SQR(YYcurr[i][tt]); //sum sqr observations first group } - somreffY *= SQR(100.f); + somcurr2Y *= SQR(100.f); for (int i = 0; i < Nc; i++) { somreff2Y += SQR(reffYY[i][tt]); @@ -4324,9 +4324,9 @@ float static studentXY(const array2D & YYcurr, const array2D & ref } somreff2Y *= SQR(100.f); - const float somsqueccurrY = somcurr2Y - (SQR(somcurrY)) / sizcurr; + const float somsqueccurrY = somcurr2Y - SQR(somcurrY) / sizcurr; //sum sqr differences first - const float somsquecreffY = somreff2Y - (SQR(somreffY)) / Nc; + const float somsquecreffY = somreff2Y - SQR(somreffY) / Nc; //sum sqr differences second const float diviY = std::sqrt(((somsqueccurrY + somsquecreffY) * (1.f / sizcurr + 1.f / Nc)) / (sizcurr + Nc - 2)); From 0a23e85868e19db1e4cbb5a6db4a00416c5d07e9 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 19:44:20 +0100 Subject: [PATCH 08/13] Further cleanups --- rtengine/rawimagesource.cc | 56 ++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index bf88b2955..55e31eeda 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -3896,7 +3896,6 @@ void RawImageSource::getRowStartEnd (int x, int &start, int &end) static void histoxyY(int bfhitc, int bfwitc, const array2D & xc, const array2D & yc, const array2D & Yc, LUTf &xxx, LUTf &yyy, LUTf &YYY, LUTu &histxy) - { #ifdef _OPENMP #pragma omp parallel @@ -4410,19 +4409,15 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix("sRGB"); //inverse matrix user select - double wip[3][3] = { - {wiprof[0][0], wiprof[0][1], wiprof[0][2]}, - {wiprof[1][0], wiprof[1][1], wiprof[1][2]}, - {wiprof[2][0], wiprof[2][1], wiprof[2][2]} + const float wip[3][3] = { + {static_cast(wiprof[0][0]), static_cast(wiprof[0][1]), static_cast(wiprof[0][2])}, + {static_cast(wiprof[1][0]), static_cast(wiprof[1][1]), static_cast(wiprof[1][2])}, + {static_cast(wiprof[2][0]), static_cast(wiprof[2][1]), static_cast(wiprof[2][2])} }; const int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 const int bfhitc = bfh / 10 + 1; - array2D xc(bfwitc, bfhitc); - array2D yc(bfwitc, bfhitc); - array2D Yc(bfwitc, bfhitc); - typedef struct WbGreen { double green; float snedecor;//1. actually but put in case of confiance interval @@ -4791,8 +4786,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double bool separated = true; int w = -1; - array2D reff_spect_xxyy(N_t, 2 * Nc + 2); - array2D reff_spect_xxyy_prov(N_t, 2 * Nc + 2); array2D reff_spect_yy_camera(N_t, 2 * Nc + 2); array2D reff_spect_xx_camera(N_t, 2 * Nc + 2); @@ -4808,6 +4801,10 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double reff_spect_yy_camera[j][repref] = TY[j] / (TX[j] + TY[j] + TZ[j]); // y from xyY } + array2D xc(bfwitc, bfhitc); + array2D yc(bfwitc, bfhitc); + array2D Yc(bfwitc, bfhitc); + const int deltarepref = settings->itcwb_delta; for (int nn = 0, drep = -deltarepref; nn <= 2; ++nn, drep += deltarepref) { @@ -4839,6 +4836,10 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double histoxyY(bfhitc, bfwitc, xc, yc, Yc, xxx, yyy, YYY, histxy); } + // free some memory + xc.free(); + yc.free(); + Yc.free(); //calculate x y Y const int sizcurrref = siza;//choice of number of correlate colors in image array2D histcurrref(N_t, sizcurrref); @@ -4848,9 +4849,6 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double array2D xx_curref_reduc(N_t, sizcurrref); array2D yy_curref_reduc(N_t, sizcurrref); array2D YY_curref_reduc(N_t, sizcurrref); - array2D R_curref_reduc(N_t, sizcurrref); - array2D G_curref_reduc(N_t, sizcurrref); - array2D B_curref_reduc(N_t, sizcurrref); hiss Wbhis[siza]; @@ -4900,15 +4898,13 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double const int sizcu30 = sizcurrref - n30; const int sizcu4 = rtengine::min(sizcu30, 55); - chrom wbchro[sizcu4]; - const double swpr = (Txyz[repref].XX + Txyz[repref].ZZ + 1.); - const double xwpr = Txyz[repref].XX / swpr;//white point for tt in xy coordiantes - const double ywpr = 1. / swpr; - + const float swpr = Txyz[repref].XX + Txyz[repref].ZZ + 1.f; + const float xwpr = Txyz[repref].XX / swpr;//white point for tt in xy coordiantes + const float ywpr = 1.f / swpr; for (int i = 0; i < sizcu4; ++i) { //take the max values - histcurrref[i][repref] = (float) Wbhis[siza - (i + 1)].histnum; + histcurrref[i][repref] = Wbhis[siza - (i + 1)].histnum; xx_curref[i][repref] = xxx[Wbhis[siza - (i + 1)].index] / histcurrref[i][repref]; yy_curref[i][repref] = yyy[Wbhis[siza - (i + 1)].index] / histcurrref[i][repref]; YY_curref[i][repref] = YYY[Wbhis[siza - (i + 1)].index] / histcurrref[i][repref]; @@ -4939,7 +4935,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double for (int i = 0; i < sizcurr2ref; ++i) { //is condition chroxy necessary ? - if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral + if (wbchro[sizcu4 - (i + 1)].chrox > 0.1f && wbchro[sizcu4 - (i + 1)].chroy > 0.1f && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral w++; xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox; yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy; @@ -4961,7 +4957,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double for (int j = 0; j < Nc ; j++) { if (!good_spectral[j]) { - const float deltaE = SQR(xx_curref_reduc[i][repref] - reff_spect_xx_camera[j][repref]) + SQR(yy_curref_reduc[i][repref] - reff_spect_yy_camera[j][repref]); + const float deltaE = SQR(xx_curref_reduc[i][repref] - reff_spect_xx_camera[j][repref]) + SQR(yy_curref_reduc[i][repref] - reff_spect_yy_camera[j][repref]); if (deltaE < mindeltaE) { mindeltaE = deltaE; @@ -4974,7 +4970,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } } -//reconvert to RGB for "reduction" + // reuse some buffers + array2D& R_curref_reduc = xx_curref_reduc; + array2D& G_curref_reduc = yy_curref_reduc; + array2D& B_curref_reduc = YY_curref_reduc; + + //reconvert to RGB for "reduction" for (int i = 0; i < w; i++) { const float X = 65535.f * xx_curref_reduc[i][repref] * YY_curref_reduc[i][repref] / yy_curref_reduc[i][repref]; const float Y = 65535.f * YY_curref_reduc[i][repref]; @@ -4992,18 +4993,15 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double //Now begin real calculations separated = false; ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants - //calculate x y Y int sizcurr = siza;//choice of number of correlate colors in image - array2D histcurr(N_t, sizcurr); - array2D xxyycurr(N_t, 2 * sizcurr); array2D xxyycurr_reduc(N_t, 2 * sizcurr); + array2D reff_spect_xxyy(N_t, 2 * Nc + 2); + array2D reff_spect_xxyy_prov(N_t, 2 * Nc + 2); + float minstud = 100000.f; int goodref = 1; - array2D YYcurr(N_t, sizcurr); - array2D YYcurr_reduc(N_t, sizcurr); - //calculate x y z for each pixel with multiplier rmm gmm bmm for (int tt = 0; tt < N_t; ++tt) {//N_t From cee41b97861923e1a2299b2d9a10ac90a0bd28a8 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sat, 29 Feb 2020 21:04:09 +0100 Subject: [PATCH 09/13] restore speed when not using auto itc wb and improve speed when using it --- rtengine/improccoordinator.cc | 13 ++--- rtengine/rawimagesource.cc | 96 ++++++++++++++++++++++++++--------- 2 files changed, 77 insertions(+), 32 deletions(-) diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index fc3b29b9f..e18c6177a 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -389,16 +389,11 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) } } - // bool autowb0 = false; - // autowb0 = (params->wb.method == "autold" || params->wb.method == "aut" || params->wb.method == "autosdw" || params->wb.method == "autedgsdw" || params->wb.method == "autitcgreen" || params->wb.method == "autedgrob" || params->wb.method == "autedg" || params->wb.method == "autorobust"); - // autowb0 = (params->wb.method == "autold" || params->wb.method == "autitcgreen");//in some cases autowb0 does not work ....params->wb.method still at "camera" instead of auto !!! - // printf("autowb0=%s \n", params->wb.method.c_str()); - - - - // if (autowb0) { + if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { + if (params->wb.method == "autitcgreen") { imgsrc->getrgbloc(false, false, false, 0, 0, fh, fw, 0, 0, fh, fw); - // } + } + } if ((todo & (M_RETINEX | M_INIT)) && params->retinex.enabled) { bool dehacontlutili = false; diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 55e31eeda..c052b41f7 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -3664,8 +3664,8 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr) if (ri->getSensorType() == ST_BAYER) { // precalculate factors to avoid expensive per pixel calculations - float refwb0 = refwb[ri->FC(i, start)]; - float refwb1 = refwb[ri->FC(i, start + 1)]; + float refwb0 = refwb[ri->FC(i, start)]; + float refwb1 = refwb[ri->FC(i, start + 1)]; int j; for (j = start; j < end - 1; j += 2) { @@ -3678,12 +3678,12 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr) } } else if (ri->getSensorType() == ST_FUJI_XTRANS) { // precalculate factors to avoid expensive per pixel calculations - float refwb0 = refwb[ri->XTRANSFC(i, start)]; - float refwb1 = refwb[ri->XTRANSFC(i, start + 1)]; - float refwb2 = refwb[ri->XTRANSFC(i, start + 2)]; - float refwb3 = refwb[ri->XTRANSFC(i, start + 3)]; - float refwb4 = refwb[ri->XTRANSFC(i, start + 4)]; - float refwb5 = refwb[ri->XTRANSFC(i, start + 5)]; + float refwb0 = refwb[ri->XTRANSFC(i, start)]; + float refwb1 = refwb[ri->XTRANSFC(i, start + 1)]; + float refwb2 = refwb[ri->XTRANSFC(i, start + 2)]; + float refwb3 = refwb[ri->XTRANSFC(i, start + 3)]; + float refwb4 = refwb[ri->XTRANSFC(i, start + 4)]; + float refwb5 = refwb[ri->XTRANSFC(i, start + 5)]; int j; for (j = start; j < end - 5; j += 6) { @@ -4853,7 +4853,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double hiss Wbhis[siza]; for (int nh = 0; nh < siza; nh++) { - Wbhis[nh].histnum = histxy[nh]; + Wbhis[nh].histnum = histxy[nh]; Wbhis[nh].index = nh; } @@ -5016,7 +5016,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double for (int j = 0; j < Nc ; ++j) { reff_spect_xxyy_prov[2 * j][tt] = Tx[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // x from xyY - reff_spect_xxyy_prov[2 * j + 1][tt] = Ty[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // y from xyY + reff_spect_xxyy_prov[2 * j + 1][tt] = Ty[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // y from xyY } int kk = -1; @@ -5098,7 +5098,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double for (int j = 0; j < Nc ; ++j) { reff_spect_xxyy_prov[2 * j][tt] = Tx[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // x from xyY - reff_spect_xxyy_prov[2 * j + 1][tt] = Ty[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // y from xyY + reff_spect_xxyy_prov[2 * j + 1][tt] = Ty[j][tt] / (Tx[j][tt] + Ty[j][tt] + Tz[j][tt]); // y from xyY } //degrade correllation with color high chroma, but not too much...seems not good, but keep in case of?? @@ -5142,13 +5142,13 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double int greengoodprov; int goodrefprov; float studprov; - const int goodref0 = Tgstud[0].tempref; + const int goodref0 = Tgstud[0].tempref; const int greengood0 = Tgstud[0].greenref - 39;//39 green = 1 const float stud0 = Tgstud[0].student; - const int goodref1 = Tgstud[1].tempref; + const int goodref1 = Tgstud[1].tempref; const float stud1 = Tgstud[1].student; const int greengood1 = Tgstud[1].greenref - 39; - const int goodref2 = Tgstud[2].tempref; + const int goodref2 = Tgstud[2].tempref; const int greengood2 = Tgstud[2].greenref - 39; const float stud2 = Tgstud[2].student; @@ -5243,16 +5243,57 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in //center data on normal values int nn = 0; - for (int i = 0; i < H; i ++) + if (!local) { +#ifdef _OPENMP + #pragma omp parallel sections +#endif + { +#ifdef _OPENMP + #pragma omp section +#endif + { + for (int i = 0; i < H; i ++) { + for (int j = 0; j < W; j++) { + redloc[i][j] = red[i][j]; + } + } + } +#ifdef _OPENMP + #pragma omp section +#endif + { + for (int i = 0; i < H; i ++) { + for (int j = 0; j < W; j++) { + greenloc[i][j] = green[i][j]; + } + } + } +#ifdef _OPENMP + #pragma omp section +#endif + { + for (int i = 0; i < H; i ++) { + for (int j = 0; j < W; j++) { + blueloc[i][j] = blue[i][j]; + } + } + } + } + } + +#ifdef _OPENMP + #pragma omp parallel for reduction(+:avgL, nn) +#endif + for (int i = 0; i < H; i ++) { for (int j = 0; j < W; j++) { int lox = cx + j; int loy = cy + i; if (!local) { - const float redmm = redloc[i][j] = red[i][j]; - const float greenmm = greenloc[i][j] = green[i][j]; - const float bluemm = blueloc[i][j] = blue[i][j]; - const float LL = (0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm); + const float redmm = redloc[i][j]; + const float greenmm = greenloc[i][j]; + const float bluemm = blueloc[i][j]; + const float LL = 0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm; avgL += static_cast(LL); nn++; } else { @@ -5260,21 +5301,24 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in const float redmm = redloc[loy - begy][lox - begx] = red[i][j]; const float greenmm = greenloc[loy - begy][lox - begx] = green[i][j]; const float bluemm = blueloc[loy - begy][lox - begx] = blue[i][j]; - const float LL = (0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm); + const float LL = 0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm; avgL += static_cast(LL); nn++; } } } - + } avgL /= nn; - float vari = 0.f; + double vari = 0.f; int mm = 0; +#ifdef _OPENMP + #pragma omp parallel for reduction(+:vari, mm) +#endif for (int i = 0; i < bfh; i++) for (int j = 0; j < bfw; j++) { - float LL = (0.299f * redloc[i][j] + 0.587f * greenloc[i][j] + 0.114f * blueloc[i][j]); + float LL = 0.299f * redloc[i][j] + 0.587f * greenloc[i][j] + 0.114f * blueloc[i][j]; vari += SQR(LL - avgL); mm++; } @@ -5282,6 +5326,9 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in const float sig = std::sqrt(vari / mm); const float multip = 60000.f / (avgL + 2.f * sig); +#ifdef _OPENMP + #pragma omp parallel for +#endif for (int i = 0; i < bfh; i++) for (int j = 0; j < bfw; j++) { redloc[i][j] *= multip; @@ -5290,6 +5337,9 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in } if (gamma) { +#ifdef _OPENMP + #pragma omp parallel for +#endif for (int i = 0; i < bfh; i++) for (int j = 0; j < bfw; j++) { redloc[i][j] = Color::gammatab_srgb[redloc[i][j]]; From 95b238ca5d5dd16ff54838eb982c733e7cc054bb Mon Sep 17 00:00:00 2001 From: Desmis Date: Sun, 1 Mar 2020 08:37:51 +0100 Subject: [PATCH 10/13] Added Ingo to copyright Itcwb --- rtengine/rawimagesource.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index c052b41f7..2779081d1 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4340,7 +4340,8 @@ float static studentXY(const array2D & YYcurr, const array2D & ref void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, const ColorManagementParams &cmp, const RAWParams &raw, const WBParams & wbpar) { /* - copyright Jacques Desmis 6 - 2018 jdesmis@gmail.com + Copyright (c) Jacques Desmis 6 - 2018 jdesmis@gmail.com + Copyright (c) Ingo Weirich 3 - 2020 (heckflosse67@gmx.de) This algorithm try to find temperature correlation between 20 to 200 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web. From d0034c880be2b96aea5d17dc8af89b83c50c82dc Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sun, 1 Mar 2020 11:50:58 +0100 Subject: [PATCH 11/13] further cleanups and speedups for ItcWB/getrgbloc --- rtengine/imagesource.h | 2 +- rtengine/improccoordinator.cc | 5 +- rtengine/rawimagesource.cc | 129 ++++++++-------------------------- rtengine/rawimagesource.h | 2 +- rtengine/stdimagesource.cc | 3 - rtengine/stdimagesource.h | 2 +- 6 files changed, 36 insertions(+), 107 deletions(-) diff --git a/rtengine/imagesource.h b/rtengine/imagesource.h index 22b8cdc08..d1008837d 100644 --- a/rtengine/imagesource.h +++ b/rtengine/imagesource.h @@ -123,7 +123,7 @@ public: virtual ColorTemp getWB () const = 0; virtual ColorTemp getSpotWB (std::vector &red, std::vector &green, std::vector &blue, int tran, double equal) = 0; virtual void WBauto(double &tempref, double &greenref, array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) = 0; - virtual void getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) = 0; + virtual void getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) = 0; virtual double getDefGain () const { diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index e18c6177a..15a8607d3 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -391,7 +391,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { if (params->wb.method == "autitcgreen") { - imgsrc->getrgbloc(false, false, false, 0, 0, fh, fw, 0, 0, fh, fw); + imgsrc->getrgbloc(0, 0, fh, fw, 0, 0, fh, fw); } } @@ -411,8 +411,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) } } - bool autowb = false; - autowb = (params->wb.method == "autold" || params->wb.method == "aut" || params->wb.method == "autosdw" || params->wb.method == "autedgsdw" || params->wb.method == "autitcgreen" || params->wb.method == "autedgrob" || params->wb.method == "autedg" || params->wb.method == "autorobust"); + const bool autowb = (params->wb.method == "autold" || params->wb.method == "autitcgreen"); if (settings->verbose) { printf("automethod=%s \n", params->wb.method.c_str()); } diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 2779081d1..1fac47ab4 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -3407,7 +3407,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi constexpr float trans[ColorCount][ColorCount] = { { 1, 1, 1 }, { 1.7320508, -1.7320508, 0 }, { -1, -1, 2 } }; constexpr float itrans[ColorCount][ColorCount] = { { 1, 0.8660254, -0.5 }, { 1, -0.8660254, -0.5 }, { 1, 0, 1 } }; - float minpt = min(hlmax[0], hlmax[1], hlmax[2]); //min of the raw clip points + float minpt = rtengine::min(hlmax[0], hlmax[1], hlmax[2]); //min of the raw clip points //float maxpt=max(hlmax[0],hlmax[1],hlmax[2]);//max of the raw clip points //float medpt=hlmax[0]+hlmax[1]+hlmax[2]-minpt-maxpt;//median of the raw clip points float maxave = (hlmax[0] + hlmax[1] + hlmax[2]) / 3; //ave of the raw clip points @@ -3418,7 +3418,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi float clip[3]; for (int c = 0; c < ColorCount; ++c) { - clip[c] = min(maxave, hlmax[c]); + clip[c] = rtengine::min(maxave, hlmax[c]); } // Determine the maximum level (clip) of all channels @@ -3473,7 +3473,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi } } - chratio = (std::sqrt(sum[1] / sum[0])); + chratio = std::sqrt(sum[1] / sum[0]); // Apply ratio to lightness in LCH space for (int c = 1; c < ColorCount; c++) { @@ -4341,7 +4341,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double { /* Copyright (c) Jacques Desmis 6 - 2018 jdesmis@gmail.com - Copyright (c) Ingo Weirich 3 - 2020 (heckflosse67@gmx.de) + Copyright (c) Ingo Weyrich 3 - 2020 (heckflosse67@gmx.de) This algorithm try to find temperature correlation between 20 to 200 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web. @@ -4416,8 +4416,8 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double {static_cast(wiprof[2][0]), static_cast(wiprof[2][1]), static_cast(wiprof[2][2])} }; - const int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 - const int bfhitc = bfh / 10 + 1; + const int bfwitc = bfw; + const int bfhitc = bfh; typedef struct WbGreen { double green; @@ -4552,7 +4552,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } RangeGreen; constexpr RangeGreen Rangestandard = {8, 70}; - constexpr RangeGreen Rangeextand = {4, 77}; + constexpr RangeGreen Rangeextended = {4, 77}; const RangeGreen Rangemax = {0, N_g}; RangeGreen Rangegreenused; @@ -4560,7 +4560,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double if (settings->itcwb_greenrange == 0) { Rangegreenused = Rangestandard; } else if (settings->itcwb_greenrange == 1) { - Rangegreenused = Rangeextand; + Rangegreenused = Rangeextended; } else { Rangegreenused = Rangemax; } @@ -4816,13 +4816,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double #ifdef _OPENMP #pragma omp parallel for #endif - for (int y = 0; y < bfh ; y += 10) { - int yy = y / 10; - for (int x = 0, xx = 0; x < bfw ; x += 10, ++xx) { + for (int y = 0; y < bfh ; ++y) { + for (int x = 0; x < bfw ; ++x) { const float RR = rmm[rep] * redloc[y][x]; const float GG = gmm[rep] * greenloc[y][x]; const float BB = bmm[rep] * blueloc[y][x]; - Color::rgbxyY(RR, GG, BB, xc[yy][xx], yc[yy][xx], Yc[yy][xx], wp); + Color::rgbxyY(RR, GG, BB, xc[y][x], yc[y][x], Yc[y][x], wp); } } //histogram xy depend of temp...but in most cases D45 ..D65.. @@ -5217,15 +5216,12 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D } } -void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) +void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) { + BENCHFUN //used by auto WB local to calculate red, green, blue in local region - int bfh = H, bfw = W; - - if (local) { - bfh = bf_h + 3; - bfw = bf_w + 3; - } + const int bfw = W / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 + const int bfh = H / 10 + 1; if (! greenloc) { greenloc(bfw, bfh); @@ -5240,73 +5236,17 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in } double avgL = 0.0; - //center data on normal values int nn = 0; - if (!local) { -#ifdef _OPENMP - #pragma omp parallel sections -#endif - { -#ifdef _OPENMP - #pragma omp section -#endif - { - for (int i = 0; i < H; i ++) { - for (int j = 0; j < W; j++) { - redloc[i][j] = red[i][j]; - } - } - } -#ifdef _OPENMP - #pragma omp section -#endif - { - for (int i = 0; i < H; i ++) { - for (int j = 0; j < W; j++) { - greenloc[i][j] = green[i][j]; - } - } - } -#ifdef _OPENMP - #pragma omp section -#endif - { - for (int i = 0; i < H; i ++) { - for (int j = 0; j < W; j++) { - blueloc[i][j] = blue[i][j]; - } - } - } - } - } - #ifdef _OPENMP #pragma omp parallel for reduction(+:avgL, nn) #endif for (int i = 0; i < H; i ++) { for (int j = 0; j < W; j++) { - int lox = cx + j; - int loy = cy + i; - - if (!local) { - const float redmm = redloc[i][j]; - const float greenmm = greenloc[i][j]; - const float bluemm = blueloc[i][j]; - const float LL = 0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm; - avgL += static_cast(LL); - nn++; - } else { - if (lox >= begx && lox < xEn && loy >= begy && loy < yEn) { - const float redmm = redloc[loy - begy][lox - begx] = red[i][j]; - const float greenmm = greenloc[loy - begy][lox - begx] = green[i][j]; - const float bluemm = blueloc[loy - begy][lox - begx] = blue[i][j]; - const float LL = 0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm; - avgL += static_cast(LL); - nn++; - } - } + const float LL = 0.299f * red[i][j] + 0.587f * green[i][j] + 0.114f * blue[i][j]; + avgL += static_cast(LL); + nn++; } } avgL /= nn; @@ -5317,9 +5257,9 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in #ifdef _OPENMP #pragma omp parallel for reduction(+:vari, mm) #endif - for (int i = 0; i < bfh; i++) - for (int j = 0; j < bfw; j++) { - float LL = 0.299f * redloc[i][j] + 0.587f * greenloc[i][j] + 0.114f * blueloc[i][j]; + for (int i = 0; i < H; i++) + for (int j = 0; j < W; j++) { + const float LL = 0.299f * red[i][j] + 0.587f * green[i][j] + 0.114f * blue[i][j]; vari += SQR(LL - avgL); mm++; } @@ -5330,23 +5270,15 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in #ifdef _OPENMP #pragma omp parallel for #endif - for (int i = 0; i < bfh; i++) - for (int j = 0; j < bfw; j++) { - redloc[i][j] *= multip; - greenloc[i][j] *= multip; - blueloc[i][j] *= multip; - } - - if (gamma) { -#ifdef _OPENMP - #pragma omp parallel for -#endif - for (int i = 0; i < bfh; i++) - for (int j = 0; j < bfw; j++) { - redloc[i][j] = Color::gammatab_srgb[redloc[i][j]]; - greenloc[i][j] = Color::gammatab_srgb[greenloc[i][j]]; - blueloc[i][j] = Color::gammatab_srgb[blueloc[i][j]]; + for (int i = 0; i < bfh; ++i) { + const int ii = i * 10; + if (ii < H) { + for (int j = 0, jj = 0; jj < W; ++j, jj += 10) { + redloc[i][j] = red[ii][jj] * multip; + greenloc[i][j] = green[ii][jj] * multip; + blueloc[i][j] = blue[ii][jj] * multip; } + } } } @@ -5365,7 +5297,6 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref double avg_b = 0; int rn = 0, gn = 0, bn = 0; double avg_rm, avg_gm, avg_bm; - int bfh = H, bfw = W; if (wbpar.method == "autold") { if (fuji) { for (int i = 32; i < H - 32; i++) { @@ -5542,6 +5473,8 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref if (wbpar.method == "autitcgreen") { bool twotimes = false; + const int bfw = W / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 + const int bfh = H / 10 + 1; WBauto(tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, studgood, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw); } diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index dd15a68e0..71478fbed 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -144,7 +144,7 @@ public: void scaleColors (int winx, int winy, int winw, int winh, const procparams::RAWParams &raw, array2D &rawData); // raw for cblack void WBauto(double &tempref, double &greenref, array2D &redloc, array2D &greenloc, array2D &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) override; void getAutoWBMultipliersitc(double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double &rm, double &gm, double &bm, const procparams::WBParams & wbpar, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) override; - void getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override; + void getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override; void getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const procparams::ToneCurveParams &hrp, const procparams::RAWParams &raw) override; eSensorType getSensorType () const override; diff --git a/rtengine/stdimagesource.cc b/rtengine/stdimagesource.cc index 763621171..8cb8fa792 100644 --- a/rtengine/stdimagesource.cc +++ b/rtengine/stdimagesource.cc @@ -315,9 +315,6 @@ void StdImageSource::WBauto(double &tempref, double &greenref, array2D &r { } -void StdImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) -{} - void StdImageSource::getAutoWBMultipliersitc(double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double &rm, double &gm, double &bm, const WBParams & wbpar, const ColorManagementParams &cmp, const RAWParams &raw) { if (redAWBMul != -1.) { diff --git a/rtengine/stdimagesource.h b/rtengine/stdimagesource.h index 9f4fbdfbe..f937188b4 100644 --- a/rtengine/stdimagesource.h +++ b/rtengine/stdimagesource.h @@ -58,7 +58,7 @@ public: int load (const Glib::ustring &fname) override; void getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const procparams::ToneCurveParams &hrp, const procparams::RAWParams &raw) override; - void getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override; + void getrgbloc (int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override {}; ColorTemp getWB () const override { return wb; From f85b2cc5bc7fa80fa1724e5d6cf5359c0894c223 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sun, 1 Mar 2020 12:22:15 +0100 Subject: [PATCH 12/13] small correction --- rtengine/rawimagesource.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 1fac47ab4..9ed217624 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -5220,8 +5220,8 @@ void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int { BENCHFUN //used by auto WB local to calculate red, green, blue in local region - const int bfw = W / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 - const int bfh = H / 10 + 1; + const int bfw = W / 10 + ((W % 10) > 0 ? 1 : 0);// 10 arbitrary value ; perhaps 4 or 5 or 20 + const int bfh = H / 10 + ((H % 10) > 0 ? 1 : 0); if (! greenloc) { greenloc(bfw, bfh); @@ -5473,8 +5473,8 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref if (wbpar.method == "autitcgreen") { bool twotimes = false; - const int bfw = W / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 - const int bfh = H / 10 + 1; + const int bfw = W / 10 + ((W % 10) > 0 ? 1 : 0);// 10 arbitrary value ; perhaps 4 or 5 or 20 + const int bfh = H / 10 + ((H % 10) > 0 ? 1 : 0); WBauto(tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, studgood, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw); } From c92c0c0c8a7029c776bd58b174109de201cea866 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sun, 1 Mar 2020 12:44:15 +0100 Subject: [PATCH 13/13] disabled BENCHFUN --- rtengine/rawimagesource.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 9ed217624..f5d31c435 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4399,7 +4399,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double Itcwb_sizereference : 3 by default, can be set to 5 ==> size of reference color compare to size of histogram real color itcwb_delta : 1 by default can be set between 0 to 5 ==> delta temp to build histogram xy - if camera temp is not probably good */ - BENCHFUN +// BENCHFUN TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix("sRGB"); const float wp[3][3] = { @@ -5218,7 +5218,7 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) { - BENCHFUN +// BENCHFUN //used by auto WB local to calculate red, green, blue in local region const int bfw = W / 10 + ((W % 10) > 0 ? 1 : 0);// 10 arbitrary value ; perhaps 4 or 5 or 20 const int bfh = H / 10 + ((H % 10) > 0 ? 1 : 0);