From 0903edc014274cac2730c7124adf353ea4d99dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Devernay?= Date: Wed, 4 Mar 2015 15:09:32 +0100 Subject: [PATCH] ofxsFilterInterpolate2DSuper: antialias image borders when minimizing - closes https://github.com/MrKepzie/Natron/issues/258 - @mifth can you check? --- ofxsFilter.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ofxsFilter.h b/ofxsFilter.h index 9a9b55d..110b59c 100644 --- a/ofxsFilter.h +++ b/ofxsFilter.h @@ -779,6 +779,11 @@ ofxsFilterInterpolate2DSuperInternal(double fx, } // ofxsFilterInterpolate2DSuperInternal #undef _DBG_COUNT +inline bool ofxsFilterOutside(double x, double y, const OfxRectI &bounds) +{ + return x < bounds.x1 || bounds.x2 <= x || y < bounds.y1 || bounds.y2 <= y; +} + // Interpolation using the given filter and supersampling for minification // note that the center of pixel (0,0) has canonical coordinated (0.5,0.5) template @@ -797,8 +802,17 @@ ofxsFilterInterpolate2DSuper(double fx, bool inside = ofxsFilterInterpolate2D(fx, fy, srcImg, blackOutside, tmpPix); if (!inside) { + // Center of the pixel is outside. // no supersampling if we're outside (we don't want to supersample black and transparent areas) - return; + // ... but we still have to check wether the entire pixel is outside + const OfxRectI &bounds = srcImg->getBounds(); + // we check the four corners of the pixel + if (ofxsFilterOutside(fx - Jxx*0.5 - Jxy*0.5, fy - Jyx*0.5 - Jyy*0.5, bounds) && + ofxsFilterOutside(fx + Jxx*0.5 - Jxy*0.5, fy + Jyx*0.5 - Jyy*0.5, bounds) && + ofxsFilterOutside(fx - Jxx*0.5 + Jxy*0.5, fy - Jyx*0.5 + Jyy*0.5, bounds) && + ofxsFilterOutside(fx + Jxx*0.5 + Jxy*0.5, fy + Jyx*0.5 + Jyy*0.5, bounds)) { + return; + } } double dx = Jxx*Jxx+Jyx*Jyx; // squared norm of the derivative over x