Skip to content

Commit

Permalink
ofxsFilterInterpolate2DSuper: antialias image borders when minimizing
Browse files Browse the repository at this point in the history
- closes MrKepzie/Natron#258
- @mifth can you check?
  • Loading branch information
devernay committed Mar 4, 2015
1 parent 89af241 commit 0903edc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ofxsFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class PIX, int nComponents, FilterEnum filter, bool clamp>
Expand All @@ -797,8 +802,17 @@ ofxsFilterInterpolate2DSuper(double fx,
bool inside = ofxsFilterInterpolate2D<PIX,nComponents,filter,clamp>(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
Expand Down

2 comments on commit 0903edc

@mifth
Copy link

@mifth mifth commented on 0903edc Mar 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devernay sure i can. I need to get linux snapshot with your changes.
i'll try to download the latest snapshot tomorrow and give you to know if everything is ok. :)
Thank you!!!!!

@mifth
Copy link

@mifth mifth commented on 0903edc Mar 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested. I answered here MrKepzie/Natron#258

Please sign in to comment.