Speedup for Shadows/Highlights HQ mode, Issue 1950
This commit is contained in:
56
rtengine/StopWatch.h
Normal file
56
rtengine/StopWatch.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of RawTherapee.
|
||||
*
|
||||
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: reine
|
||||
*/
|
||||
|
||||
#ifndef STOPWATCH_H
|
||||
#define STOPWATCH_H
|
||||
#include <iostream>
|
||||
#include <sys/time.h>
|
||||
|
||||
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" <<std::endl;
|
||||
stopped = true;
|
||||
}
|
||||
void stop(const char *msg)
|
||||
{
|
||||
message = msg;
|
||||
stop();
|
||||
};
|
||||
private:
|
||||
struct timeval startStruct;
|
||||
struct timeval stopStruct;
|
||||
const char *message;
|
||||
bool stopped;
|
||||
};
|
||||
|
||||
#endif /* STOPWATCH_H */
|
@@ -44,43 +44,29 @@ SHMap::~SHMap () {
|
||||
}
|
||||
|
||||
void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int skip) {
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel
|
||||
#endif
|
||||
{
|
||||
|
||||
// fill with luminance
|
||||
#pragma omp for
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for (int i=0; i<H; i++)
|
||||
for (int j=0; j<W; j++) {
|
||||
map[i][j] = lumi[0]*std::max(img->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<double>* pBuffer = new AlignedBufferMP<double> (max(W,H));
|
||||
gaussHorizontal<float> (map, map, *pBuffer, W, H, radius);
|
||||
gaussVertical<float> (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<nthreads-1)
|
||||
bilateral<float> (map, buffer, W, H, 8000, radius, tid*blk, (tid+1)*blk);
|
||||
else
|
||||
bilateral<float> (map, buffer, W, H, 8000, radius, tid*blk, H);
|
||||
}
|
||||
#else
|
||||
bilateral<float> (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<int>(exp(-(min(10.0f,(static_cast<float>(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<H-32; i++)
|
||||
for (int j=32; j<W-32; j++) {
|
||||
int val = map[i][j];
|
||||
if (val < min_f)
|
||||
min_f = val;
|
||||
if (val > 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
|
||||
|
Reference in New Issue
Block a user