Speedup for Flat-Field correction, fixes #3253, also introduces changed formatting to switch statements caused by new astyle profile

This commit is contained in:
heckflosse
2016-06-11 22:18:59 +02:00
parent 49a6af275e
commit 65306973b1
3 changed files with 687 additions and 606 deletions

View File

@@ -18,12 +18,17 @@
*/
#include "ffmanager.h"
#include "../rtgui/options.h"
#include <giomm.h>
#include "rawimage.h"
#include <sstream>
#include <cstdio>
#include "imagedata.h"
#define PIX_SORT(a,b) { if ((a)>(b)) {temp=(a);(a)=(b);(b)=temp;} }
#define med5(a0,a1,a2,a3,a4,median) { \
p[0]=a0; p[1]=a1; p[2]=a2; p[3]=a3; p[4]=a4; \
PIX_SORT(p[0],p[1]) ; PIX_SORT(p[3],p[4]) ; PIX_SORT(p[0],p[3]) ; \
PIX_SORT(p[1],p[4]) ; PIX_SORT(p[1],p[2]) ; PIX_SORT(p[2],p[3]) ; \
PIX_SORT(p[1],p[2]) ; median=p[2] ;}
namespace rtengine
{
@@ -200,8 +205,37 @@ void ffInfo::updateRawImage()
ri->compress_image();
}
}
}
if(ri) {
// apply median to avoid this step being executed each time a flat field gets applied
int H = ri->get_height();
int W = ri->get_width();
float *cfatmp = (float (*)) malloc (H * W * sizeof * cfatmp);
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic,16)
#endif
for (int i = 0; i < H; i++) {
int p[5], temp;
int iprev = i < 2 ? i + 2 : i - 2;
int inext = i > H - 3 ? i - 2 : i + 2;
for (int j = 0; j < W; j++) {
int jprev = j < 2 ? j + 2 : j - 2;
int jnext = j > W - 3 ? j - 2 : j + 2;
med5(ri->data[iprev][j], ri->data[i][jprev], ri->data[i][j],
ri->data[i][jnext], ri->data[inext][j], cfatmp[i * W + j]);
}
}
memcpy(ri->data[0], cfatmp, W * H * sizeof(float));
free (cfatmp);
}
}
// ************************* class FFManager *********************************
@@ -210,6 +244,7 @@ void FFManager::init( Glib::ustring pathname )
std::vector<Glib::ustring> names;
auto dir = Gio::File::create_for_path (pathname);
if (!dir || !dir->query_exists()) {
return;
}
@@ -287,6 +322,7 @@ ffInfo* FFManager::addFileInfo (const Glib::ustring& filename, bool pool)
Glib::ustring ext;
auto lastdot = info->get_name ().find_last_of ('.');
if (lastdot != Glib::ustring::npos) {
ext = info->get_name ().substr (lastdot + 1);
}