Skip to main content

Python bindings for Blend2D focused on layout rasterization workflows.

Project description

raster-blend2d

Python bindings for Blend2D focused on layout rasterization.

Status

This project packages Blend2D as a Python extension. It expects Blend2D and AsmJit source trees under extern/ before native builds can succeed.

Development

Initialize vendored dependencies:

git submodule update --init --recursive

Build and test locally:

python -m pip install -U pip build pytest
python -m pip install -e .
pytest

Build a wheel:

python -m build

Polygon Rasterization API

from raster_blend2d import Blend2DPolygonRasterizer

rasterizer = Blend2DPolygonRasterizer(
    pixel_size_um=(0.01, 0.02),
    oversampling=4,
    # Optional: render in output-pixel tiles to cap peak A8 mask size.
    # tile_size_px=1024,
    # Optional: parallelize tiled flat-buffer rasterization.
    # parallel_workers=4,
)

polygons = [
    {
        "hull": [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],
        "holes": [],
    }
]

coverage = rasterizer.rasterize(
    polygons=polygons,
    window_size_um=(2.0, 2.0),
)

assert coverage.dtype == "float32"
assert coverage.shape == (200, 100)
assert coverage[0, 0] >= 0.0

coverage[x, y] uses a lower-left window origin. Internally, polygons are rendered to a Blend2D A8 mask at the requested oversampling rate and downsampled to float32 coverage. A Blend2DPolygonRasterizer instance caches its native A8 mask buffer between calls; use rasterizer.clear_cache() to release it. Set tile_size_px for very large windows to render smaller A8 mask tiles and reduce peak memory use. parallel_workers parallelizes tiled rasterize_flat() calls; the Python list/dict rasterize() path remains serial because it accesses Python objects.

For large layouts, use flat numpy buffers to reduce Python object parsing:

import numpy as np

points = np.array(
    [
        [0.0, 0.0],
        [1.0, 0.0],
        [1.0, 1.0],
        [0.0, 1.0],
    ],
    dtype=np.float64,
)
ring_offsets = np.array([0, 4], dtype=np.int64)
polygon_offsets = np.array([0, 1], dtype=np.int64)

coverage = rasterizer.rasterize_flat(
    points=points,
    ring_offsets=ring_offsets,
    polygon_offsets=polygon_offsets,
    window_size_um=(2.0, 2.0),
)

ring_offsets stores point ranges for each ring. polygon_offsets stores ring ranges for each polygon; the first ring is the hull and following rings are holes.

Benchmark

The table below compares the current implementation with the previous committed version, v0.1.4, on Windows CPython 3.12. The workload is 10,000 independent rectangles rasterized into a 700 x 700 coverage array with pixel_size_um=0.2. Times are median seconds over 9 runs.

API / configuration Oversampling Median time Speedup vs v0.1.4
v0.1.4 rasterize() 1 0.00547 s 1.00x
current rasterize() 1 0.00536 s 1.02x
current rasterize_flat() 1 0.00230 s 2.38x
current rasterize_flat(tile_size_px=256, parallel_workers=4) 1 0.00106 s 5.17x
v0.1.4 rasterize() 2 0.00745 s 1.00x
current rasterize() 2 0.00705 s 1.06x
current rasterize_flat() 2 0.00399 s 1.87x
current rasterize_flat(tile_size_px=256, parallel_workers=4) 2 0.00131 s 5.68x
v0.1.4 rasterize() 4 0.01339 s 1.00x
current rasterize() 4 0.01318 s 1.02x
current rasterize_flat() 4 0.00965 s 1.39x
current rasterize_flat(tile_size_px=256, parallel_workers=4) 4 0.00190 s 7.05x

The tiled parallel case benefits from flat numpy input, per-worker A8 mask reuse, tile-level polygon bounding-box culling, and parallel tile execution. Actual speedups depend on polygon size, spatial distribution, tile size, oversampling, and available CPU cores.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

raster_blend2d-0.1.6-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

raster_blend2d-0.1.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

raster_blend2d-0.1.6-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

raster_blend2d-0.1.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

raster_blend2d-0.1.6-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

raster_blend2d-0.1.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

raster_blend2d-0.1.6-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

raster_blend2d-0.1.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

raster_blend2d-0.1.6-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

raster_blend2d-0.1.6-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

raster_blend2d-0.1.6-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9Windows x86-64

raster_blend2d-0.1.6-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file raster_blend2d-0.1.6-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 20d17ad4b7b1dd6c9ac2657b2be3210024c7a7e8d63031069275562a74c9a986
MD5 9c9eddda639b3a317cfcdb31b9590881
BLAKE2b-256 9bf32de5e1f312b9278a146606f64fc1351c67de4650d4ae22cfe2f35352d408

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp314-cp314-win_amd64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8da42f76e44cecea942f9853956de0a537848e602f4316b150e9f8d5899169b2
MD5 6dcaba8d98207e77fe8c006d4e66563d
BLAKE2b-256 3225a91f44ce6d43a08f6668abb035051186bbb5305d39b16da8b6857274f0a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b20b1960bce11abc6db1a9b82d3f547856f33402918e4a7ca983849e9322a6e0
MD5 372a771ca3b4a0a09d0ca443beda5162
BLAKE2b-256 511560008d3cd088eb9da2061d4a934a0e41fe483c121ac8d5711f84ba94617b

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a167bf14b8a3a334db19e6366e6c876717bf0e1d30ffe153b17965abc6f16030
MD5 9df488f518fd9a51bc266494b5b62111
BLAKE2b-256 b048214bb20549570d45c2126640dde7cb4724d499ab47a9f516b0b62d5ac75b

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c889ed27b77e847f9a26302172992ea7957ed0a78d2622cf1513692576d8c847
MD5 28489444f70808f8ad025e550bd5d9a6
BLAKE2b-256 ba1f215eb4fd466786813c311d622f98e370e952f4df2ab7fd3684502d0175c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a9dfe29ede003585bb10ceb759df3852588f351659f4f5ede94c9a34c6f6b1f
MD5 da6f2c4a55f6971f5656fe5170f032a7
BLAKE2b-256 e4b2d8d5dc2bfe63e0c2fc92b64042603377eb4c68b62c9b876ac30573ee10d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 350a4277cf9aca044bf9e4c06208ce01811f0ba66845a4b966c115631ccbe735
MD5 bd3332111214181917a2a3dca7cc31d7
BLAKE2b-256 d5cea5dc7417fd3422e6137ba595dbce573e0466beb9cf96d86480b6a8a1a528

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b1a068d31d8658997551a2f62db51df9303995d5c8d1cc9d4f409d765f0f358
MD5 6c4111cc0e8fcc4398b9b487644d6ccc
BLAKE2b-256 75b673b83d6ce173663d13f529000ffd12ff69026182806c6addc044e0f19a2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c913c020979df5b33b6c3a7e28a1825b0c71fea2c8cd2d84ea2015d981670de9
MD5 ee1064093ab7ea4e1a1a550f3424f283
BLAKE2b-256 1fce38394fb7957edf95343bbb0cf3c46c9b66cafa63b82e0e8115a38bfd6428

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 68105a9b64f91a8eb246d9afcd48eb24c1ffeb477c9aa1dc8fc2ce2a8842f0f3
MD5 36db05528fd6d244d445b27af053f7bb
BLAKE2b-256 129eb2d1d4e8045192edd7bde50fd19c1118ec6e77f08e489b19585e58a1c675

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8e59e0fa218ed64a2316f2201239d69bf77c7006528e72a7b5c635048a8cdbc2
MD5 29e676fb5a85dd5a987f9ec7a2490174
BLAKE2b-256 3cb8ee68b56820463eb105e4300eed26bda028a502296bd02ecd7e66b4924c7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp39-cp39-win_amd64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file raster_blend2d-0.1.6-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.6-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aac5dc0513e57498543c7359b4a9255c6bb236238080dae967f7ec5acc1b50d0
MD5 de5c33b3c8e37a7ef6bfa240a8a13274
BLAKE2b-256 e5c0ee0c795bc636eb1e20818dcd67863f5e33b3241a5c165fcd51735e911770

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.6-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on diffractlight/raster_blend2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page