From 2a444e260a8017e44032385461d6c6e1b9a94371 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 17 Jun 2017 14:43:48 +0200 Subject: [PATCH] Fix some coverity issues. Pixel Shift: calculate per frame brightness factors only once after preprocessing --- rtengine/dcraw.h | 2 +- rtengine/imagesource.h | 2 +- rtengine/pixelshift.cc | 137 ++++++++++++++++++++----------------- rtengine/rawimagesource.cc | 7 +- rtengine/rawimagesource.h | 6 +- rtexif/pentaxattribs.cc | 16 ++--- 6 files changed, 97 insertions(+), 73 deletions(-) diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h index 6a1a83391..c467ad5c0 100644 --- a/rtengine/dcraw.h +++ b/rtengine/dcraw.h @@ -345,7 +345,7 @@ void nokia_load_raw(); // pana_bits(int nbits); class pana_bits_t{ public: - pana_bits_t(IMFILE *&i,unsigned &u):ifp(i),load_flags(u){} + pana_bits_t(IMFILE *&i,unsigned &u):ifp(i),load_flags(u),vbits(0){} unsigned operator()(int nbits); private: IMFILE *&ifp; diff --git a/rtengine/imagesource.h b/rtengine/imagesource.h index d6d0a618f..b1de9d31f 100644 --- a/rtengine/imagesource.h +++ b/rtengine/imagesource.h @@ -69,7 +69,7 @@ public: virtual int load (const Glib::ustring &fname, int imageNum = 0, bool batch = false) = 0; virtual void preprocess (const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse, bool prepareDenoise = true) {}; virtual void demosaic (const RAWParams &raw) {}; - virtual void retinex (ColorManagementParams cmp, RetinexParams deh, 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 retinex (ColorManagementParams cmp, const RetinexParams &deh, 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 (RetinexParams retinexParams, LUTf &cdcurve, LUTf &mapcurve, RetinextransmissionCurve &retinextransmissionCurve, RetinexgaintransmissionCurve &retinexgaintransmissionCurve, bool &retinexcontlutili, bool &mapcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI) {}; virtual void retinexPrepareBuffers (ColorManagementParams cmp, RetinexParams retinexParams, multi_array2D &conversionBuffer, LUTu &lhist16RETI) {}; virtual void flushRawData () {}; diff --git a/rtengine/pixelshift.cc b/rtengine/pixelshift.cc index e7d6b86c7..605188867 100644 --- a/rtengine/pixelshift.cc +++ b/rtengine/pixelshift.cc @@ -561,83 +561,98 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA float blueBrightness[4] = {1.f, 1.f, 1.f, 1.f}; if(equalBrightness) { - LUT *histogreen[4]; - LUT *histored[4]; - LUT *histoblue[4]; - - for(int i = 0; i < 4; ++i) { - histogreen[i] = new LUT(65536); - histogreen[i]->clear(); - histored[i] = new LUT(65536); - histored[i]->clear(); - histoblue[i] = new LUT(65536); - histoblue[i]->clear(); - } - -#ifdef _OPENMP - #pragma omp parallel -#endif - { - LUT *histogreenThr[4]; - LUT *historedThr[4]; - LUT *histoblueThr[4]; + if(rawDirty) { + LUT *histogreen[4]; + LUT *histored[4]; + LUT *histoblue[4]; for(int i = 0; i < 4; ++i) { - histogreenThr[i] = new LUT(65536); - histogreenThr[i]->clear(); - historedThr[i] = new LUT(65536); - historedThr[i]->clear(); - histoblueThr[i] = new LUT(65536); - histoblueThr[i]->clear(); + histogreen[i] = new LUT(65536); + histogreen[i]->clear(); + histored[i] = new LUT(65536); + histored[i]->clear(); + histoblue[i] = new LUT(65536); + histoblue[i]->clear(); } #ifdef _OPENMP - #pragma omp for schedule(dynamic,16) nowait + #pragma omp parallel +#endif + { + LUT *histogreenThr[4]; + LUT *historedThr[4]; + LUT *histoblueThr[4]; + + for(int i = 0; i < 4; ++i) { + histogreenThr[i] = new LUT(65536); + histogreenThr[i]->clear(); + historedThr[i] = new LUT(65536); + historedThr[i]->clear(); + histoblueThr[i] = new LUT(65536); + histoblueThr[i]->clear(); + } + +#ifdef _OPENMP + #pragma omp for schedule(dynamic,16) nowait #endif - for(int i = winy + 1; i < winh - 1; ++i) { - int j = winx + 1; - int c = FC(i, j); + for(int i = winy + 1; i < winh - 1; ++i) { + int j = winx + 1; + int c = FC(i, j); - bool bluerow = (c + FC(i, j + 1)) == 3; + bool bluerow = (c + FC(i, j + 1)) == 3; - for(int j = winx + 1, offset = FC(i, j) & 1; j < winw - 1; ++j, offset ^= 1) { - (*histogreenThr[1 - offset])[(*rawDataFrames[1 - offset])[i - offset + 1][j]]++; - (*histogreenThr[3 - offset])[(*rawDataFrames[3 - offset])[i + offset][j + 1]]++; + for(int j = winx + 1, offset = FC(i, j) & 1; j < winw - 1; ++j, offset ^= 1) { + (*histogreenThr[1 - offset])[(*rawDataFrames[1 - offset])[i - offset + 1][j]]++; + (*histogreenThr[3 - offset])[(*rawDataFrames[3 - offset])[i + offset][j + 1]]++; - if(bluerow) { - (*historedThr[2 - offset])[(*rawDataFrames[2 - offset])[i + 1][j - offset + 1]]++; - (*histoblueThr[(offset << 1) + offset])[(*rawDataFrames[(offset << 1) + offset])[i][j + offset]]++; - } else { - (*historedThr[(offset << 1) + offset])[(*rawDataFrames[(offset << 1) + offset])[i][j + offset]]++; - (*histoblueThr[2 - offset])[(*rawDataFrames[2 - offset])[i + 1][j - offset + 1]]++; + if(bluerow) { + (*historedThr[2 - offset])[(*rawDataFrames[2 - offset])[i + 1][j - offset + 1]]++; + (*histoblueThr[(offset << 1) + offset])[(*rawDataFrames[(offset << 1) + offset])[i][j + offset]]++; + } else { + (*historedThr[(offset << 1) + offset])[(*rawDataFrames[(offset << 1) + offset])[i][j + offset]]++; + (*histoblueThr[2 - offset])[(*rawDataFrames[2 - offset])[i + 1][j - offset + 1]]++; + } + } + } + +#ifdef _OPENMP + #pragma omp critical +#endif + { + for(int i = 0; i < 4; ++i) { + (*histogreen[i]) += (*histogreenThr[i]); + delete histogreenThr[i]; + (*histored[i]) += (*historedThr[i]); + delete historedThr[i]; + (*histoblue[i]) += (*histoblueThr[i]); + delete histoblueThr[i]; } } } -#ifdef _OPENMP - #pragma omp critical -#endif - { - for(int i = 0; i < 4; ++i) { - (*histogreen[i]) += (*histogreenThr[i]); - delete histogreenThr[i]; - (*histored[i]) += (*historedThr[i]); - delete historedThr[i]; - (*histoblue[i]) += (*histoblueThr[i]); - delete histoblueThr[i]; - } + calcFrameBrightnessFactor(frame, (winh - 2) * (winw - 2) / 4, histored, redBrightness); + calcFrameBrightnessFactor(frame, (winh - 2) * (winw - 2) / 4, histoblue, blueBrightness); + calcFrameBrightnessFactor(frame, (winh - 2) * (winw - 2) / 2, histogreen, greenBrightness); + + for(int i = 0; i < 4; ++i) { + psRedBrightness[i] = redBrightness[i]; + psGreenBrightness[i] = greenBrightness[i]; + psBlueBrightness[i] = blueBrightness[i]; } - } + rawDirty = false; - calcFrameBrightnessFactor(frame, (winh - 2) * (winw - 2) / 4, histored, redBrightness); - calcFrameBrightnessFactor(frame, (winh - 2) * (winw - 2) / 4, histoblue, blueBrightness); - calcFrameBrightnessFactor(frame, (winh - 2) * (winw - 2) / 2, histogreen, greenBrightness); - - for(int i = 0; i < 4; ++i) { - delete histored[i]; - delete histoblue[i]; - delete histogreen[i]; + for(int i = 0; i < 4; ++i) { + delete histored[i]; + delete histoblue[i]; + delete histogreen[i]; + } + } else { + for(int i = 0; i < 4; ++i) { + redBrightness[i] = psRedBrightness[i]; + greenBrightness[i] = psGreenBrightness[i]; + blueBrightness[i] = psBlueBrightness[i]; + } } } diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 5bab3caa7..c639fafca 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -462,10 +462,14 @@ RawImageSource::RawImageSource () , green(0, 0) , red(0, 0) , blue(0, 0) + , rawDirty(true) { camProfile = nullptr; embProfile = nullptr; rgbSourceModified = false; + for(int i = 0; i < 4; ++i) { + psRedBrightness[i] = psGreenBrightness[i] = psBlueBrightness[i] = 1.f; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -2031,6 +2035,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le delete bitmapBads; } + rawDirty = true; return; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -2372,7 +2377,7 @@ void RawImageSource::retinexPrepareCurves(const RetinexParams &retinexParams, LU retinexParams.getCurves(retinextransmissionCurve, retinexgaintransmissionCurve); } -void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, 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) +void RawImageSource::retinex(ColorManagementParams cmp, const RetinexParams &deh, 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) { MyTime t4, t5; t4.set(); diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index b699a8a3f..bc2589408 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -90,6 +90,10 @@ protected: array2D red; // the interpolated blue plane: array2D blue; + bool rawDirty; + float psRedBrightness[4]; + float psGreenBrightness[4]; + float psBlueBrightness[4]; void hphd_vertical (float** hpmap, int col_from, int col_to); @@ -115,7 +119,7 @@ public: int load (const Glib::ustring &fname, int imageNum = 0, bool batch = false); void preprocess (const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse, bool prepareDenoise = true); void demosaic (const RAWParams &raw); - void retinex (ColorManagementParams cmp, RetinexParams deh, 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); + void retinex (ColorManagementParams cmp, const RetinexParams &deh, 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); void retinexPrepareCurves (const RetinexParams &retinexParams, LUTf &cdcurve, LUTf &mapcurve, RetinextransmissionCurve &retinextransmissionCurve, RetinexgaintransmissionCurve &retinexgaintransmissionCurve, bool &retinexcontlutili, bool &mapcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI); void retinexPrepareBuffers (ColorManagementParams cmp, const RetinexParams &retinexParams, multi_array2D &conversionBuffer, LUTu &lhist16RETI); void flushRawData (); diff --git a/rtexif/pentaxattribs.cc b/rtexif/pentaxattribs.cc index b57de067c..2c52a0c88 100644 --- a/rtexif/pentaxattribs.cc +++ b/rtexif/pentaxattribs.cc @@ -1290,10 +1290,10 @@ public: buffer[0] = 0; // return buffer; // TODO: how to get the string content!? - // normal path below (copy the content of the string), but has to be bug fixed - memcpy (buffer, t->getValue(), 30); - buffer[30] = 0; - return buffer; +// // normal path below (copy the content of the string), but has to be bug fixed +// memcpy (buffer, t->getValue(), 30); +// buffer[30] = 0; +// return buffer; } }; PALensModelQInterpreter paLensModelQInterpreter; @@ -1308,10 +1308,10 @@ public: buffer[0] = 0; return buffer; // TODO: how to get the string content!? - // normal path below (copy the content of the string), but has to be bug fixed - memcpy (buffer, t->getValue(), 20); - buffer[20] = 0; - return buffer; +// // normal path below (copy the content of the string), but has to be bug fixed +// memcpy (buffer, t->getValue(), 20); +// buffer[20] = 0; +// return buffer; } }; PALensInfoQInterpreter paLensInfoQInterpreter;