Implement correct draw functions for 16-bpp modes - #9982
Open
akx wants to merge 4 commits into
Open
Conversation
radarhere
reviewed
Sep 10, 2026
akx
marked this pull request as ready for review
September 10, 2026 13:38
Merging this PR will improve performance by ×2.4
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_draw_lines[1237x811-L] |
912.2 µs | 380.7 µs | ×2.4 |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing akx:draw16 (e3266fc) with main (05fcca1)
Footnotes
-
335 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
radarhere
reviewed
Sep 11, 2026
Comment on lines
+57
to
+75
| @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 |
Member
There was a problem hiding this comment.
Suggested change
| @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) | |
| @pytest.mark.parametrize( | |
| "xy", | |
| # horizontal, vertical, diagonal | |
| ((0, 4, 7, 4), (4, 0, 4, 7), (0, 0, 7, 7)), | |
| ) | |
| def test_horizontal_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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While reworking #9772, I noticed 16bpp drawing was piggybacking on
draw8... and then it kind of turned out that not all 16bpp modes were drawing things correctly.This PR:
draw16, the suite of point/hline/line functions for 16-bpp images, with some additional twists and turns of big-endian support (which was also incorrect in another special way).Along with correctness, this should also yield a bit of performance since
draw8functions don't need to do per-pixel checks for the image mode (and the Bresenham de-triplication commit also adds the option to usehline).