Skip to content

Replace Python raster scan loops with Rust-accelerated raygeo functions#277

Merged
knipknap merged 6 commits into
mainfrom
feat/rust-rasterizer
Jun 6, 2026
Merged

Replace Python raster scan loops with Rust-accelerated raygeo functions#277
knipknap merged 6 commits into
mainfrom
feat/rust-rasterizer

Conversation

@knipknap

@knipknap knipknap commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replaces the pure-Python raster scan loops in Rasterizer with single calls to the Rust-accelerated raygeo.ops.raster functions (rasterize_power_modulation, rasterize_mask_scan, rasterize_multi_pass)
  • Replaces compute_auto_levels and normalize_grayscale imports with their raygeo.image Rust equivalents
  • Removes the _rasterize_mask helper method (no longer needed)
  • Reduces raster_producer.py from 735 to 500 lines (-32%)

Details

All four raster modes now delegate to Rust:

Mode Before After
POWER_MODULATION 90-line scan loop with segment/power/downsample logic rasterize_power_modulation()
CONSTANT_POWER 60-line scan loop with segment detection rasterize_mask_scan()
DITHER Same loop as constant_power rasterize_mask_scan()
MULTI_PASS 30-line depth-mask loop + _rasterize_mask rasterize_multi_pass()

Cairo surface→mask conversion (binary/dithered) still happens in Python since it requires Cairo interaction. The Y-axis inversion is now handled entirely within the Rust functions.

Depends on raygeo v0.5.0 (tagged).

Testing

All 39 existing rasterizer producer tests and 51 raster_util tests pass unchanged.

knipknap added 2 commits June 5, 2026 15:59
Delegate rasterization to raygeo.ops.raster high-level functions
(rasterize_power_modulation, rasterize_mask_scan, rasterize_multi_pass)
and raygeo.image (compute_auto_levels, normalize_grayscale) instead of
the pure-Python raster_util implementations. Reduces raster_producer.py
from 735 to 500 lines while keeping identical behavior through all 39
existing tests.
knipknap added 3 commits June 5, 2026 17:07
The Windows CI was installing raygeo from PyPI (v0.4.1) which doesn't
include the new image and raster modules. Install from the local git
checkout instead so the build always uses the current raygeo source.
@knipknap
knipknap merged commit 52b1b0e into main Jun 6, 2026
29 checks passed
@knipknap
knipknap deleted the feat/rust-rasterizer branch June 12, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant