Repository navigation
Fix drawing on I;16B images #9982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff504f8
Move I;16 drawing tests to their own file
akx 5d3d3d7
Add more comprehensive tests for I;16 drawing
akx 7ed02f3
De-triplicate Bresenham walkers; use hline when possible
akx 83303d7
Implement correct draw functions for 16-bpp modes
akx 237d5ef
Merge branch 'main' into draw16
aclark4life 343cda4
Inline function
radarhere 0bccc1a
Correct inlined function
akx dd3e4bb
Move horizontal line check inside earlier block
radarhere 30657fb
Replace GEN_LINE with function
radarhere 178309f
Simplify little-endian path
radarhere 5e9bfa6
Moved release note
radarhere 0f1f3d0
Use relative imports
radarhere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from PIL import Image, ImageDraw | ||
|
|
||
| from .helper import assert_image_equal_tofile | ||
| from .test_imagedraw import BBOX, POINTS, X0, Y0, H, W | ||
|
|
||
| TYPE_CHECKING = False | ||
|
|
||
| if TYPE_CHECKING: | ||
| from PIL._typing import Coords | ||
|
|
||
| I16_MODES = ("I;16", "I;16L", "I;16B", "I;16N") | ||
| I16_INK = 0x1234 | ||
|
|
||
|
|
||
| def create_I16_image_draw(mode: str) -> tuple[Image.Image, ImageDraw.ImageDraw]: | ||
| img = Image.new(mode, (8, 8)) | ||
| return img, ImageDraw.Draw(img) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_point_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.point((4, 4), fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| @pytest.mark.parametrize( | ||
| "xy", | ||
| # horizontal, vertical, diagonal | ||
| ((0, 4, 7, 4), (4, 0, 4, 7), (0, 0, 7, 7)), | ||
| ) | ||
| def test_line_I16(mode: str, xy: tuple[int, int, int, int]) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.line(xy, fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_rectangle_fill_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.rectangle((0, 0, 7, 7), fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("bbox", BBOX) | ||
| def test_rectangle_I16(bbox: Coords) -> None: | ||
| # Arrange | ||
| im = Image.new("I;16", (W, H)) | ||
| draw = ImageDraw.Draw(im) | ||
|
|
||
| # Act | ||
| draw.rectangle(bbox, outline=0xCDEF) | ||
|
|
||
| # Assert | ||
| assert im.getpixel((X0, Y0)) == 0xCDEF | ||
| assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_I.tiff") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_polygon_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.polygon([(0, 0), (7, 0), (7, 7), (0, 7)], fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("points", POINTS) | ||
| def test_polygon_width_I16(points: Coords) -> None: | ||
| # Arrange | ||
| im = Image.new("I;16", (W, H)) | ||
| draw = ImageDraw.Draw(im) | ||
|
|
||
| # Act | ||
| draw.polygon(points, outline=0xFFFF, width=2) | ||
|
|
||
| # Assert | ||
| assert_image_equal_tofile(im, "Tests/images/imagedraw_polygon_width_I.tiff") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_masked_polygon_I16(mode: str) -> None: | ||
| # A polygon outline wider than one pixel is drawn through a mask. | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.polygon([(0, 0), (7, 0), (7, 7), (0, 7)], outline=I16_INK, width=8) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_ellipse_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.ellipse((0, 0, 7, 7), fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.