diff --git a/rtengine/StopWatch.h b/rtengine/StopWatch.h new file mode 100644 index 000000000..e43b90247 --- /dev/null +++ b/rtengine/StopWatch.h @@ -0,0 +1,56 @@ +/* + * This file is part of RawTherapee. + * + * Copyright (c) 2004-2010 Gabor Horvath + * + * RawTherapee is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RawTherapee is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RawTherapee. If not, see . + * + * Author: reine + */ + +#ifndef STOPWATCH_H +#define STOPWATCH_H +#include +#include + +class StopWatch { +public: + StopWatch( ) { stopped = false; } + StopWatch( const char* msg) { message = msg; start(); stopped = false; } + ~StopWatch() { if(!stopped) stop(); } + void start() + { + gettimeofday(&startStruct,NULL); + }; + void stop() + { + gettimeofday(&stopStruct,NULL); + long elapsedTime = (stopStruct.tv_sec - startStruct.tv_sec) * 1000.0; // sec to ms + elapsedTime += (stopStruct.tv_usec - startStruct.tv_usec)/1000; + std::cout << message << " took " << elapsedTime << "ms" <r(i,j),0.f) + lumi[1]*std::max(img->g(i,j),0.f) + lumi[2]*std::max(img->b(i,j),0.f); } if (!hq) { +#ifdef _OPENMP +#pragma omp parallel +#endif +{ AlignedBufferMP* pBuffer = new AlignedBufferMP (max(W,H)); gaussHorizontal (map, map, *pBuffer, W, H, radius); gaussVertical (map, map, *pBuffer, W, H, radius); delete pBuffer; +} } - else { -/* -#if 0 -// the new OpenMP method does not need thread number specific code. -// #ifdef _OPENMP - #pragma omp parallel if (multiThread) - { - int tid = omp_get_thread_num(); - int nthreads = omp_get_num_threads(); - int blk = H/nthreads; - if (tid (map, buffer, W, H, 8000, radius, tid*blk, (tid+1)*blk); - else - bilateral (map, buffer, W, H, 8000, radius, tid*blk, H); - } -#else - bilateral (map, buffer, W, H, 8000, radius, 0, H); -#endif -*/ + else { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //experimental dirpyr shmap @@ -91,7 +77,6 @@ void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int int intfactor = 1024;//16384; //set up range functions - for (int i=0; i<0x10000; i++) { //rangefn[i] = (int)(((thresh)/((double)(i) + (thresh)))*intfactor); rangefn[i] = static_cast(exp(-(min(10.0f,(static_cast(i)*i) / (thresh*thresh))))*intfactor); @@ -137,23 +122,43 @@ void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int */ } - } // end parallel enclosure // update average, minimum, maximum - double _avg = 0; - int n = 1; + + float _avg = 0.0f; min_f = 65535; max_f = 0; +#ifdef _OPENMP +#pragma omp parallel +#endif +{ + float _min_f = 65535.0f; + float _max_f = 0.0f; + float _val; +#ifdef _OPENMP +#pragma omp for reduction(+:_avg) nowait +#endif for (int i=32; i max_f) - max_f = val; - _avg = 1.0/n * val + (1.0 - 1.0/n) * _avg; - n++; + _val = map[i][j]; + if (_val < _min_f) + _min_f = _val; + if (_val > _max_f) + _max_f = _val; + _avg += _val; } - avg = (int) _avg; +#ifdef _OPENMP +#pragma omp critical +#endif +{ + if(_min_f < min_f ) + min_f = _min_f; + if(_max_f > max_f ) + max_f = _max_f; +} +} + _avg /= ((H-64)*(W-64)); + avg = _avg; + } void SHMap::forceStat (float max_, float min_, float avg_) { @@ -180,7 +185,6 @@ void SHMap::dirpyr_shmap(float ** data_fine, float ** data_coarse, int width, in domker[1][1]=domker[1][2]=domker[2][1]=domker[2][2]=1; } - int scalewin = halfwin*scale; #ifdef _OPENMP @@ -216,5 +220,4 @@ void SHMap::dirpyr_shmap(float ** data_fine, float ** data_coarse, int width, in } - }//end of SHMap