Skip to content

Commit 1ec94b0

Browse files
timtreisclaude
andcommitted
Remove blanket rasterization skip for images under 2000px
The guard `if x_dims < 2000 and y_dims < 2000: do_rasterization = False` silently ignored the user's DPI intent — a low-DPI figure should still trigger downsampling when the source image exceeds the target resolution. Also re-adds the visual test for #310: at dpi=15 the 512x512 blobs image is now correctly downsampled to ~96x72, producing visibly pixelated output that would fail baseline comparison if DPI were overridden to the default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8547f01 commit 1ec94b0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/spatialdata_plot/pl/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,10 +1960,10 @@ def _rasterize_if_necessary(
19601960
target_y_dims = dpi * height
19611961
target_x_dims = dpi * width
19621962

1963-
# Heuristics for when to rasterize
1963+
# Rasterize when the source image is substantially larger than what the
1964+
# current figure DPI × size requires. The +100 margin avoids rasterizing
1965+
# when the image is only slightly larger than the target.
19641966
do_rasterization = y_dims > target_y_dims + 100 or x_dims > target_x_dims + 100
1965-
if x_dims < 2000 and y_dims < 2000:
1966-
do_rasterization = False
19671967

19681968
if do_rasterization:
19691969
logger.info("Rasterizing image for faster rendering.")

tests/pl/test_show.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ def test_plot_no_decorations(self, sdata_blobs: SpatialData):
4242
"""Visual test: frameon=False + title='' produces just the plot content (regression for #204)."""
4343
sdata_blobs.pl.render_images(element="blobs_image").pl.show(frameon=False, title="", colorbar=False)
4444

45+
def test_plot_user_ax_dpi_preserved(self, sdata_blobs: SpatialData):
46+
"""Visual test: low DPI produces visibly pixelated rasterization (regression for #310).
47+
48+
Uses dpi=15 so the 512x512 blobs image is downsampled to ~96x72.
49+
If the bug regresses and DPI is overridden to the default (~100),
50+
no rasterization occurs and the sharper render fails comparison.
51+
"""
52+
fig, ax = plt.subplots(dpi=15)
53+
sdata_blobs.pl.render_images(element="blobs_image").pl.show(ax=ax)
54+
4555
def test_no_plt_show_when_ax_provided(self, sdata_blobs: SpatialData):
4656
"""plt.show() must not be called when the user supplies ax= (regression for #362)."""
4757
_, ax = plt.subplots()

0 commit comments

Comments
 (0)