improved performance of Fattal in dcrop

Now only Fattal works on the full image, the rest of the pipeline (including denoising) always operates only on the visible crop
This commit is contained in:
Alberto Griggio 2017-11-17 15:27:56 +01:00
parent 619b3e9c63
commit b25bac8c53

View File

@ -691,45 +691,79 @@ void Crop::update (int todo)
createBuffer (cropw, croph);
std::unique_ptr<Imagefloat> fattalCrop;
bool need_cropping = false;
bool has_fattal = false;
if ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.fattal.enabled) {
has_fattal = true;
Imagefloat *f = baseCrop;
int fw = skips(parent->fw, skip);
int fh = skips(parent->fh, skip);
bool need_cropping = false;
if (cropx || cropy || trafw != fw || trafh != fh) {
need_cropping = true;
// fattal needs to work on the full image. So here we get the full
// image from imgsrc, and replace the denoised crop in case
f = new Imagefloat(fw, fh);
PreviewProps pp (0, 0, parent->fw, parent->fh, skip);
int tr = getCoarseBitMask(params.coarse);
parent->imgsrc->getImage(parent->currWB, tr, f, pp, params.toneCurve, params.icm, params.raw);
parent->imgsrc->convertColorSpace(f, params.icm, parent->currWB);
if (params.dirpyrDenoise.enabled) {
// copy the denoised crop
int oy = cropy / skip;
int ox = cropx / skip;
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int y = 0; y < baseCrop->getHeight(); ++y) {
int dy = oy + y;
for (int x = 0; x < baseCrop->getWidth(); ++x) {
int dx = ox + x;
f->r(dy, dx) = baseCrop->r(y, x);
f->g(dy, dx) = baseCrop->g(y, x);
f->b(dy, dx) = baseCrop->b(y, x);
}
}
}
}
if (f == origCrop) {
fattalCrop.reset(baseCrop->copy());
f = fattalCrop.get();
}
parent->ipf.ToneMapFattal02(f);
need_cropping = (cropx || cropy || trafw != cropw || trafh != croph);
baseCrop = f;
// crop back to the size expected by the rest of the pipeline
if (need_cropping) {
Imagefloat *c = new Imagefloat(cropw, croph);
int oy = cropy / skip;
int ox = cropx / skip;
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int y = 0; y < croph; ++y) {
int cy = y + oy;
for (int x = 0; x < cropw; ++x) {
int cx = x + ox;
c->r(y, x) = f->r(cy, cx);
c->g(y, x) = f->g(cy, cx);
c->b(y, x) = f->b(cy, cx);
}
}
fattalCrop.reset(c);
baseCrop = c;
} else {
baseCrop = f;
}
}
// transform
if (needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled)) {
int tx = cropx;
int ty = cropy;
int tw = cropw;
int th = croph;
if (has_fattal) {
tx = 0;
ty = 0;
tw = trafw;
th = trafh;
if (transCrop) {
delete transCrop;
transCrop = nullptr;
}
}
if (!transCrop) {
transCrop = new Imagefloat (tw, th);
transCrop = new Imagefloat (cropw, croph);
}
if (needstransform)
parent->ipf.transform (baseCrop, transCrop, tx / skip, ty / skip, trafx / skip, trafy / skip, skips (parent->fw, skip), skips (parent->fh, skip), parent->getFullWidth(), parent->getFullHeight(),
parent->ipf.transform (baseCrop, transCrop, cropx / skip, cropy / skip, trafx / skip, trafy / skip, skips (parent->fw, skip), skips (parent->fh, skip), parent->getFullWidth(), parent->getFullHeight(),
parent->imgsrc->getMetaData(),
parent->imgsrc->getRotateDegree(), false);
else {
@ -747,28 +781,6 @@ void Crop::update (int todo)
transCrop = nullptr;
}
if (need_cropping) {
Imagefloat *c = new Imagefloat(cropw, croph);
int oy = cropy / skip;
int ox = cropx / skip;
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int y = 0; y < croph; ++y) {
int cy = y + oy;
for (int x = 0; x < cropw; ++x) {
int cx = x + ox;
c->r(y, x) = baseCrop->r(cy, cx);
c->g(y, x) = baseCrop->g(cy, cx);
c->b(y, x) = baseCrop->b(cy, cx);
}
}
fattalCrop.reset(c);
baseCrop = c;
}
if ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled) {
const int W = baseCrop->getWidth();
@ -1131,11 +1143,6 @@ void Crop::freeAll ()
namespace
{
bool check_need_full_image(const ProcParams &params)
{
return params.fattal.enabled; // agriggio - maybe we can do this for wavelets too?
}
bool check_need_larger_crop_for_lcp_distortion (int fw, int fh, int x, int y, int w, int h, const ProcParams &params)
{
if (x == 0 && y == 0 && w == fw && h == fh) {
@ -1241,13 +1248,6 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte
leftBorder = skips (rqx1 - bx1, skip);
upperBorder = skips (rqy1 - by1, skip);
if (check_need_full_image(parent->params)) {
orx = 0;
ory = 0;
orw = parent->fullw;
orh = parent->fullh;
}
PreviewProps cp (orx, ory, orw, orh, skip);
int orW, orH;
parent->imgsrc->getSize (cp, orW, orH);