-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Implement correct draw functions for 16-bpp modes #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
Open
akx
wants to merge
4
commits into
python-pillow:main
Choose a base branch
from
akx:draw16
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+262
−280
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,104 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from PIL import Image, ImageDraw | ||
| from Tests.helper import assert_image_equal_tofile | ||
| from Tests.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("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("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_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) | ||
| def test_horizontal_line_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.line((0, 4, 7, 4), fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_vertical_line_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.line((4, 0, 4, 7), fill=I16_INK) | ||
| assert img.getpixel((4, 4)) == I16_INK | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", I16_MODES) | ||
| def test_diagonal_line_I16(mode: str) -> None: | ||
| img, draw = create_I16_image_draw(mode) | ||
| draw.line((0, 0, 7, 7), 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("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("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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be called
test_line_I16?