Skip to content

Commit f1a1fb4

Browse files
committed
Bump rendering edges to fill axes when rendering affine non-NN interpolation
This fixes a visual issue where there can appear to be a slight gap between an image and the axes spines even when it is supposed to fill the axes. The code now expands the rendering edges to fill the axes without degrading the placement accuracy within the image.
1 parent 35ccd4c commit f1a1fb4

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

src/_image_resample.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,38 @@ void resample(
759759

760760
agg::path_storage path;
761761
if (params.is_affine && params.interpolation != NEAREST) {
762-
path.move_to(0, 0);
763-
path.line_to(in_width, 0);
764-
path.line_to(in_width, in_height);
765-
path.line_to(0, in_height);
766-
path.close_polygon();
767-
agg::conv_transform<agg::path_storage> rectangle(path, params.affine);
768-
rasterizer.add_path(rectangle);
762+
if (params.affine.shx != 0 || params.affine.shy != 0) {
763+
path.move_to(0, 0);
764+
path.line_to(in_width, 0);
765+
path.line_to(in_width, in_height);
766+
path.line_to(0, in_height);
767+
path.close_polygon();
768+
agg::conv_transform<agg::path_storage> rectangle(path, params.affine);
769+
rasterizer.add_path(rectangle);
770+
} else {
771+
// If there is no shear/rotation, bump out the rendering edges that are
772+
// within a half pixel of a full pixel so that axes are visually filled.
773+
// This bumping out is equivalent to treating any edge pixel that is at
774+
// least half-covered by the source as fully covered by the source.
775+
double left = 0;
776+
double right = in_width;
777+
double bottom = 0;
778+
double top = in_height;
779+
params.affine.transform(&left, &bottom);
780+
params.affine.transform(&right, &top);
781+
if (left > right) { std::swap(left, right); }
782+
if (bottom > top) { std::swap(top, bottom); }
783+
if (round(left) < left) { left = round(left); }
784+
if (round(right) > right) { right = round(right); }
785+
if (round(bottom) < bottom) { bottom = round(bottom); }
786+
if (round(top) > top) { top = round(top); }
787+
path.move_to(left, bottom);
788+
path.line_to(right, bottom);
789+
path.line_to(right, top);
790+
path.line_to(left, top);
791+
path.close_polygon();
792+
rasterizer.add_path(path);
793+
}
769794
} else {
770795
path.move_to(0, 0);
771796
path.line_to(out_width, 0);

0 commit comments

Comments
 (0)