Add smoothness option for threshold AA #27
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While using chainner's Threshold node to sharpen some upscaled text, I noticed that the AA is quite sharp. This is generally good, but I would have liked a bit more smoothness in this case.
This PR adds an
extra_smoothness
parameter tobinary_threshold
.extra_smoothness
can be used to control the strength of a sub-pixel blur applied to the AA. Well, that's what it does conceptually. Under the hood, this is actually implemented by simply extending the range of the bilinear kernels that are used to get the threshold area. Doing the blur like this has 2 advantages:Example:

While the new smoothness doesn't impact performance, it did highlight an old bug.
binary_threshold
only applies AA to pixels that need it. This is done via an edge detection, but this edge detection didn't flag edges correctly. This bug was barely noticeable before, but it is very obvious for high smoothing values.Unfortunately, the fix wasn't free. Depending on the image,
binary_threshold
is now between 5% and 20% slower with AA enabled. Not a problem IMO, but a performance regress nonetheless.