fix: correct fx resize behavior

This commit is contained in:
2026-03-14 01:07:24 +08:00
parent f9a312b80a
commit 67502cb932
3 changed files with 56 additions and 15 deletions

View File

@ -35,3 +35,39 @@ def test_apply_jpeg_damage_clamps_quality_range():
assert high.size == image.size
assert low.mode == "RGBA"
assert high.mode == "RGBA"
def test_apply_resize_clamps_small_result_to_at_least_one_pixel():
image = Image.new("RGBA", (10, 10), (255, 0, 0, 255))
result = ImageFilterImplement.apply_resize(image, 0.01)
assert result.size == (1, 1)
def test_apply_resize_negative_x_with_positive_y_only_mirrors_horizontally():
image = Image.new("RGBA", (2, 1))
image.putpixel((0, 0), (255, 0, 0, 255))
image.putpixel((1, 0), (0, 0, 255, 255))
result = ImageFilterImplement.apply_resize(image, -1, 1)
assert result.size == (2, 1)
assert result.getpixel((0, 0)) == (0, 0, 255, 255)
assert result.getpixel((1, 0)) == (255, 0, 0, 255)
def test_apply_resize_negative_scale_without_y_flips_both_axes():
image = Image.new("RGBA", (2, 2))
image.putpixel((0, 0), (255, 0, 0, 255))
image.putpixel((1, 0), (0, 255, 0, 255))
image.putpixel((0, 1), (0, 0, 255, 255))
image.putpixel((1, 1), (255, 255, 0, 255))
result = ImageFilterImplement.apply_resize(image, -1)
assert result.size == (2, 2)
assert result.getpixel((0, 0)) == (255, 255, 0, 255)
assert result.getpixel((1, 0)) == (0, 0, 255, 255)
assert result.getpixel((0, 1)) == (0, 255, 0, 255)
assert result.getpixel((1, 1)) == (255, 0, 0, 255)