From 58e560b88e9b0cfdf1e1a8ac1606a31c1d0ba2a6 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Thu, 30 Jun 2016 19:48:44 +0200 Subject: [PATCH] Added further speedups and astyles the changed files --- rtengine/imagesource.h | 2 +- rtengine/rawimagesource.cc | 79 +++++++++++++++++++++++++------------- rtengine/rawimagesource.h | 4 +- rtengine/simpleprocess.cc | 7 ++-- 4 files changed, 59 insertions(+), 33 deletions(-) diff --git a/rtengine/imagesource.h b/rtengine/imagesource.h index f252dc1bb..305c67da5 100644 --- a/rtengine/imagesource.h +++ b/rtengine/imagesource.h @@ -67,7 +67,7 @@ public: virtual ~ImageSource () {} virtual int load (const Glib::ustring &fname, bool batch = false) = 0; - virtual void preprocess (const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse) {}; + 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 retinexPrepareCurves (RetinexParams retinexParams, LUTf &cdcurve, LUTf &mapcurve, RetinextransmissionCurve &retinextransmissionCurve, RetinexgaintransmissionCurve &retinexgaintransmissionCurve, bool &retinexcontlutili, bool &mapcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI) {}; diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 8c33bc497..5b3232af5 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -714,7 +714,7 @@ void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* ima rm /= area; gm /= area; bm /= area; - + bool doHr = (hrp.hrenabled && hrp.method != "Color"); #ifdef _OPENMP #pragma omp parallel if(!d1x) // omp disabled for D1x to avoid race conditions (see Issue 1088 http://code.google.com/p/rawtherapee/issues/detail?id=1088) { @@ -801,8 +801,8 @@ void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* ima } //process all highlight recovery other than "Color" - if (hrp.hrenabled && hrp.method != "Color") { - hlRecovery (hrp.method, line_red, line_grn, line_blue, i, sx1, imwidth, skip, raw, hlmax); + if (doHr) { + hlRecovery (hrp.method, line_red, line_grn, line_blue, imwidth, hlmax); } if(d1x) { @@ -1662,7 +1662,7 @@ int RawImageSource::load (const Glib::ustring &fname, bool batch) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse) +void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse, bool prepareDenoise) { BENCHFUN MyTime t1, t2; @@ -1683,18 +1683,20 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le printf( "Subtracting Darkframe:%s\n", rid->get_filename().c_str()); } - PixelsMap bitmapBads(W, H); + PixelsMap *bitmapBads = nullptr; + 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) + bitmapBads = new PixelsMap(W, H); #ifdef _OPENMP - #pragma omp parallel for reduction(+:totBP) + #pragma omp parallel for reduction(+:totBP) schedule(dynamic,16) #endif for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) { if(ri->data[i][j] == 0.f) { - bitmapBads.set(j, i); + bitmapBads->set(j, i); totBP++; } } @@ -1705,7 +1707,6 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } //FLATFIELD start - Glib::ustring newFF = raw.ff_file; RawImage *rif = NULL; if (!raw.ff_AutoSelect) { @@ -1731,7 +1732,11 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le std::vector *bp = dfm.getBadPixels( ri->get_maker(), ri->get_model(), idata->getSerialNumber() ); if( bp ) { - totBP += bitmapBads.set( *bp ); + if(!bitmapBads) { + bitmapBads = new PixelsMap(W, H); + } + + totBP += bitmapBads->set( *bp ); if( settings->verbose ) { std::cout << "Correcting " << bp->size() << " pixels from .badpixels" << std::endl; @@ -1748,7 +1753,11 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } if(bp) { - totBP += bitmapBads.set( *bp ); + if(!bitmapBads) { + bitmapBads = new PixelsMap(W, H); + } + + totBP += bitmapBads->set( *bp ); if( settings->verbose && !bp->empty()) { std::cout << "Correcting " << bp->size() << " hotpixels from darkframe" << std::endl; @@ -1787,7 +1796,11 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le plistener->setProgress (0.0); } - int nFound = findHotDeadPixels( bitmapBads, raw.hotdeadpix_thresh, raw.hotPixelFilter, raw.deadPixelFilter ); + if(!bitmapBads) { + bitmapBads = new PixelsMap(W, H); + } + + int nFound = findHotDeadPixels( *bitmapBads, raw.hotdeadpix_thresh, raw.hotPixelFilter, raw.deadPixelFilter ); totBP += nFound; if( settings->verbose && nFound > 0) { @@ -1845,11 +1858,11 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le if( totBP ) if ( ri->getSensorType() == ST_BAYER ) { - interpolateBadPixelsBayer( bitmapBads ); + interpolateBadPixelsBayer( *bitmapBads ); } else if ( ri->getSensorType() == ST_FUJI_XTRANS ) { - interpolateBadPixelsXtrans( bitmapBads ); + interpolateBadPixelsXtrans( *bitmapBads ); } else { - interpolateBadPixelsNColours( bitmapBads, ri->get_colors() ); + interpolateBadPixelsNColours( *bitmapBads, ri->get_colors() ); } if ( ri->getSensorType() == ST_BAYER && raw.bayersensor.linenoise > 0 ) { @@ -1874,7 +1887,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le processRawWhitepoint(raw.expos, raw.preser); } - if(dirpyrdenoiseExpComp == INFINITY) { + if(prepareDenoise && dirpyrdenoiseExpComp == INFINITY) { LUTu aehist; int aehistcompr; double clip = 0; @@ -1889,6 +1902,10 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le printf("Preprocessing: %d usec\n", t2.etime(t1)); } + if(bitmapBads) { + delete bitmapBads; + } + return; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -2978,13 +2995,17 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw for (int col = 0; col < W; col++) { int c = FC(row, col); int c4 = ( c == 1 && !(row & 1) ) ? 3 : c; - rawData[row][col] = max(src->data[row][col] + black[c4] - riDark->data[row][col], 0.0f); + rawData[row][col] = max(src->data[row][col] + black[c4] - riDark->data[row][col], 0.0f); } } } else { +#ifdef _OPENMP + #pragma omp parallel for +#endif + for (int row = 0; row < H; row++) { for (int col = 0; col < W; col++) { - rawData[row][col] = src->data[row][col]; + rawData[row][col] = src->data[row][col]; } } } @@ -4403,7 +4424,7 @@ void RawImageSource::HLRecovery_CIELab (float* rin, float* gin, float* bin, floa //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void RawImageSource::hlRecovery (std::string method, float* red, float* green, float* blue, int i, int sx1, int width, int skip, const RAWParams &raw, float* hlmax ) +void RawImageSource::hlRecovery (std::string method, float* red, float* green, float* blue, int width, float* hlmax ) { if (method == "Luminance") { @@ -4449,10 +4470,12 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr) 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) { + + for (j = start; j < end - 1; j += 2) { tmphistogram[(int)(refwb0 * rawData[i][j])] += 4; - tmphistogram[(int)(refwb1 * rawData[i][j+1])] += 4; + tmphistogram[(int)(refwb1 * rawData[i][j + 1])] += 4; } + if(j < end) { tmphistogram[(int)(refwb0 * rawData[i][j])] += 4; } @@ -4465,14 +4488,16 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr) 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) { + + for (j = start; j < end - 5; j += 6) { tmphistogram[(int)(refwb0 * rawData[i][j])] += 4; - tmphistogram[(int)(refwb1 * rawData[i][j+1])] += 4; - tmphistogram[(int)(refwb2 * rawData[i][j+2])] += 4; - tmphistogram[(int)(refwb3 * rawData[i][j+3])] += 4; - tmphistogram[(int)(refwb4 * rawData[i][j+4])] += 4; - tmphistogram[(int)(refwb5 * rawData[i][j+5])] += 4; + tmphistogram[(int)(refwb1 * rawData[i][j + 1])] += 4; + tmphistogram[(int)(refwb2 * rawData[i][j + 2])] += 4; + tmphistogram[(int)(refwb3 * rawData[i][j + 3])] += 4; + tmphistogram[(int)(refwb4 * rawData[i][j + 4])] += 4; + tmphistogram[(int)(refwb5 * rawData[i][j + 5])] += 4; } + for (; j < end; j++) { tmphistogram[(int)(refwb[ri->XTRANSFC(i, j)] * rawData[i][j])] += 4; } @@ -4532,7 +4557,7 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU #ifdef _OPENMP int numThreads; - // reduce the number of threads under certain conditions to avoid overhaed of too many critical regions + // 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::min(std::max(numThreads, 1), omp_get_max_threads()); diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index c9e593e23..e682f0e79 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -97,7 +97,7 @@ protected: void hphd_horizontal (float** hpmap, int row_from, int row_to); void hphd_green (float** hpmap); void processFalseColorCorrectionThread (Imagefloat* im, array2D &rbconv_Y, array2D &rbconv_I, array2D &rbconv_Q, array2D &rbout_I, array2D &rbout_Q, const int row_from, const int row_to); - void hlRecovery (std::string method, float* red, float* green, float* blue, int i, int sx1, int width, int skip, const RAWParams &raw, float* hlmax); + void hlRecovery (std::string method, float* red, float* green, float* blue, int width, float* hlmax); void transformRect (PreviewProps pp, int tran, int &sx1, int &sy1, int &width, int &height, int &fw); void transformPosition (int x, int y, int tran, int& tx, int& ty); @@ -116,7 +116,7 @@ public: ~RawImageSource (); int load (const Glib::ustring &fname, bool batch = false); - void preprocess (const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse); + 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 retinexPrepareCurves (RetinexParams retinexParams, LUTf &cdcurve, LUTf &mapcurve, RetinextransmissionCurve &retinextransmissionCurve, RetinexgaintransmissionCurve &retinexgaintransmissionCurve, bool &retinexcontlutili, bool &mapcontlutili, bool &useHsl, LUTu & lhist16RETI, LUTu & histLRETI); diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index c11ac6452..25bf45742 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -102,7 +102,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p ImProcFunctions ipf (¶ms, true); PreviewProps pp (0, 0, fw, fh, 1); - imgsrc->preprocess( params.raw, params.lensProf, params.coarse); + imgsrc->preprocess( params.raw, params.lensProf, params.coarse, params.dirpyrDenoise.enabled); if (params.toneCurve.autoexp) {// this enabled HLRecovery LUTu histRedRaw(256), histGreenRaw(256), histBlueRaw(256); @@ -823,11 +823,13 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p cl2Toningcurve (65536, 0); CurveFactory::curveToning(params.colorToning.cl2curve, cl2Toningcurve, 1); } + LabImage* labView = new LabImage (fw, fh); if(params.blackwhite.enabled) { CurveFactory::curveBW (params.blackwhite.beforeCurve, params.blackwhite.afterCurve, hist16, dummy, customToneCurvebw1, customToneCurvebw2, 1); } + double rrm, ggm, bbm; float autor, autog, autob; float satLimit = float(params.colorToning.satProtectionThreshold) / 100.f * 0.7f + 0.3f; @@ -910,8 +912,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p #endif for (int i = 0; i < fh; i++) - for (int j = 0; j < fw; j++) - { + for (int j = 0; j < fw; j++) { hist16thr[(int)((labView->L[i][j]))]++; }