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.5-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 fe93296080f11b03ff2d473485e5e797c14d3d4dca3829b3e2a22f7472a52855
MD5 fb13cdab30d8ea6950c87ce5ec17b204
BLAKE2b-256 04e8d8455accf88c497215a68ca4a439584a01135ba28384566b38e92b5b0b3b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 44427b1875080ccb35928b01c1eb527832aac8c3a49cee6da1cbdafee25399b3
MD5 3b3b12aa1207187e73fd07a228e7ce9a
BLAKE2b-256 9553bbc8bca705d86ea68c9c6559bc481bffb31d79b63583cac83254a1aca1a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ea477631c25a46bc7f0f31f333989d76dd5e7106695ff238588b4e237f3b4762
MD5 ba1dad13a3191af961daba73364b2bba
BLAKE2b-256 7271002d0a60f1c317728d0b67c5a71b7dc4a178b7d0d51bcef72668ed89258e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 163968af00118139e3819cc3212f891b108c57341266d2a238dd8e421216eb1e
MD5 5616df8c012f7f32e4b7e568cff51636
BLAKE2b-256 458c070a502047ea9987e4f30b2c87f31f1014c1ba1100467892b81857cf2d47

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 42f494b23c902e8291c673a2983ffe846b47f6f785ee3ab76b78c733ad8a4467
MD5 7a0aff9e8868e0fe811fed7b3a2121a2
BLAKE2b-256 40d09643811ab5c19a88543c67adcad54fb73bf98e602475ea4ddf30b7640d3a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf1c1e305730228bc07e8c7f106ab514eca6c092a1f91a7d83ca15e249bc0f3c
MD5 54390d5bf8f881a35304e5e8c12aaa41
BLAKE2b-256 c43107b54aa521fa3e3bcc58f58f5ef39c45550c7a91af3808bed2bc0056f2a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5cc4ce10aed8d793ee4f971c3e1c23eb86785bfb2366fcf912d633d9aa9806c6
MD5 106f28c49740f8c0f1ece0334bec9398
BLAKE2b-256 bffbee422bb4124028d64377efc662d02b3d97d08898b558f6a637ae2fdb9a8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3f15286a6d354990b7df77460816a99f467f467dc6a4a4ab02e4db447b740135
MD5 bf7922ac34718fbe95f16fcf44322012
BLAKE2b-256 0416fd71a43b1f69fbcc61d1e16aa4c58938348c1d472c1bacf6a1585b7b5c40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a65eb2723bd15172f5bb1e711a574374c1fa00dbe7d2ba4dd0a587ae4470c500
MD5 71c979bde4e5ee090ac064b9ddb9895b
BLAKE2b-256 b195e841f34512089b98a983308b9c6b605856fb5d039af147948b33e01e293c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c92054dad7f335cd35cdc89fd51e5b22cfad631cec18432e6d060c57e8d520e0
MD5 25de6b9fd8d3e0501191499836571f08
BLAKE2b-256 1b441ac18194ba622d235f29b818bff0b5d4e1370d215208f215ca205302da86

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 417b507f2a97492d7abec3c2040ec1dd1ef0cd7533f1f452411df1673d04afc2
MD5 d6fe928aac47d72538543e684975e14a
BLAKE2b-256 bcb40b511ab014337dc49cce631c0e96d6c5a3798fc6550fff704b4588ac4499

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for raster_blend2d-0.1.5-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a3778d1349982b94fe048328436c7d89e31fb9ed7016964084d161a79243d031
MD5 86c20f4e36ccdb1610c1d71e768a7c69
BLAKE2b-256 aae290891cf9c715a75aa8438d14c5306ac6dac43c0276a80ee817acd3b682f8

See more details on using hashes here.

Provenance

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