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,
    # Optional: use "prgb32" instead of the default "a8" mask.
    # mask_format="prgb32",
    # Optional: disable near-integer pixel-grid snapping.
    # snap_to_pixel_grid=False,
)

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 mask at the requested oversampling rate and downsampled to float32 coverage. The default mask_format="a8" uses a single-channel mask. mask_format="prgb32" uses Blend2D's 4-channel PRGB32 path, which can be useful for comparing Blend2D rasterization behavior, but it uses about 4x the mask memory and read bandwidth. snap_to_pixel_grid=True snaps transformed near-integer mask coordinates to avoid floating-point unit-conversion artifacts on grid-aligned edges. A Blend2DPolygonRasterizer instance caches its native mask buffer between calls; use rasterizer.clear_cache() to release it. Set tile_size_px for very large windows to render smaller 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.7-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

raster_blend2d-0.1.7-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.7-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

raster_blend2d-0.1.7-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.7-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

raster_blend2d-0.1.7-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.7-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

raster_blend2d-0.1.7-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.7-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

raster_blend2d-0.1.7-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.7-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9Windows x86-64

raster_blend2d-0.1.7-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.7-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3c06eafc143f08b9088f23894c9531593278a624a587a708de1ba34aa7110543
MD5 0f3cee371b6287b68fd012511bb1f2eb
BLAKE2b-256 90db75f0687a58e45d2248e1b5d468135003d3ae582b0929e87f29fcb2d2d81c

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3128b4daa0abd3b88e346aa110a79be539f5d737cffab835c1e35f29e7cf8eb0
MD5 de39b8bb36770be9f3dab286e9d9c12e
BLAKE2b-256 e2cd6d4b5185fc0c74470e5fbc82d58ca05f15c70a37fbf23b8d8ada217a004a

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 514b7d566482ac84ff347934310d2fb334a7b28549d106d2bb59a904ab0763c6
MD5 004eab3b85a8081a4787f667fefbd084
BLAKE2b-256 478a5ef7df5b4ecf97b8fe5a1d09001b207bc4e9cf0c6ead5dcd5f157a737cf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1197e239d26dc3bb34c29afef4a1dd508252fec6d60033fc761110cb4e2f10f7
MD5 5e61514496a7f74c6314791b02421ff3
BLAKE2b-256 eb91ea4d4ebe67d1338d360e13052745ca7dbfd38659ab87c2620d88457edd97

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 720f9c5adaa3df8c8a117cd5b65f90f2b215bdbd09aa63b00626c869ff9f0897
MD5 4cdc8bd0d49dd6f366bb8113656c0379
BLAKE2b-256 7363d373d0384558136a17447535bfd5456d241699fe41fc5fba4b03edce2413

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 00ba3b33f25abfba3dc0dc1b0f4ee9a761f7b63a093c63884763b63ba32bd301
MD5 583329c20472b1c7000dabc8ecb2cffd
BLAKE2b-256 6bb00cfd0c82d93466772be86a402fc096dab2205f3bd59a03aeb382f86d5f3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d49eefcedb8c1e6319c1b0716cba96c82c893e536817c32401b19b75c88df1e2
MD5 a27191320a825a38fa8923f09125b9f5
BLAKE2b-256 14cd727e29d06fe8797b34fea4a380f997ee464bbaba258898399e2d39b304fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd9de97b7db67130737ef70e14f3f16dfa720413c83a319ef9dc015fa602e61f
MD5 e8d0391566d47f44a85bd8e36ff817d6
BLAKE2b-256 502e2a217bf2612647383ec5a43c35530cf951920beb03ec11befedea82cf4dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4f7b6748f3a6b1496311a55fde16eed7f15d54031bae5a915b4dc47b9a2a5246
MD5 4531eb1f9f5c88bf391210f18a60defd
BLAKE2b-256 8e4607dcea7fdd975e2a1f81c97439e72047f3c5d1460637459fb7dcf98ab538

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 95742130e8e5108652178ca85d8854a5456f4ccdf34217416dba006418917837
MD5 11cfddc0b00d7d4d3b64bd31874160a6
BLAKE2b-256 65cd7017106aa0cb5ab7ce0cc1e5e7bfca451d7113ea54d7b89b256ad503ee36

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 754fd54009877fa46cbb4b6a001fbf6b61f35faaf235c44a64adda4a6049c303
MD5 8592d768fda5047ff722cd1d30df9be1
BLAKE2b-256 d9493cd23de9f775f2f27f99fb52da15ecd138740abd57b774a1e105d866192a

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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.7-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for raster_blend2d-0.1.7-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 01679ee5ead529a69fc019a65ca1fc722579c6f304fc3fc407529bbfdbcbdeae
MD5 c0121eb135444a9ba08ec7cdc45b48ac
BLAKE2b-256 8aafd6dbe93650355bfb0a0c71a749ebf8c6a15cc57e100ed83616014532c5f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for raster_blend2d-0.1.7-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