Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Tests/test_image_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ def test_consistency_5x5(mode: str) -> None:
assert_image_equal(source.filter(kernel), reference)


@pytest.mark.parametrize("mode", ("I;16", "I;16L", "I;16B", "I;16N"))
def test_consistency_i16_high_byte(mode: str) -> None:
# Exercise filters with a 16bpc image that has content in the high byte, too.
im = Image.new(mode, (8, 8), 1000)
pixel = im.filter(ImageFilter.SMOOTH).getpixel((4, 4))
assert isinstance(pixel, (int, float))
# Allow for kernel rounding errors.
assert abs(pixel - 1000) <= 1


@pytest.mark.parametrize(
"radius",
(
Expand Down
2 changes: 1 addition & 1 deletion src/libImaging/Filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ kernel_i16(int size, UINT8 *in0, int x, const float *kernel, int bigendian) {
for (i = 0; i < size; i++) {
int x1 = x + i - half_size;
result += (float)(in0[x1 * 2 + (bigendian ? 1 : 0)] +
(in0[x1 * 2 + (bigendian ? 0 : 1)] >> 8)) *
(in0[x1 * 2 + (bigendian ? 0 : 1)] << 8)) *
kernel[i];
}
return result;
Expand Down
Loading