Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86100aa

Browse files
committed
Avoid affine code path when scaling will make subpixels visible
1 parent acbedc6 commit 86100aa

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/matplotlib/tests/test_image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,8 @@ def test__resample_valid_output():
16691669
0.54, 0.62, 0.7, 0.78, 0.86, 0.9, 0.9, 0.9, 0.9, 0.9]])),
16701670
(np.array([[0.1, 0.1]]), mimage.BILINEAR, np.full((1, 10), 0.1)),
16711671
# Test at the subpixel level
1672+
(np.array([[0.1, 0.9]]), mimage.NEAREST,
1673+
np.concatenate([np.full(512, 0.1), np.full(512, 0.9)]).reshape(1, -1)),
16721674
(np.array([[0.1, 0.9]]), mimage.BILINEAR,
16731675
np.concatenate([np.full(256, 0.1),
16741676
np.linspace(0.5, 256, 512).astype(int) / 256 * 0.8 + 0.1,

src/_image_wrapper.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,17 @@ image_resample(py::array input_array,
167167

168168
if (is_affine) {
169169
convert_trans_affine(transform, params.affine);
170-
params.is_affine = true;
171-
} else {
170+
// If affine parameters will make subpixels visible, treat as nonaffine instead
171+
if (params.affine.sx >= agg::image_subpixel_scale / 2 || params.affine.sy >= agg::image_subpixel_scale / 2) {
172+
is_affine = false;
173+
params.affine = agg::trans_affine(); // reset to identity affine parameters
174+
}
175+
}
176+
if (!is_affine) {
172177
transform_mesh = _get_transform_mesh(transform, output_array.shape());
173178
params.transform_mesh = transform_mesh.data();
174-
params.is_affine = false;
175179
}
180+
params.is_affine = is_affine;
176181
}
177182

178183
if (auto resampler =

0 commit comments

Comments
 (0)