Aller au contenu principal

raygeo.image

Image processing functions for CNC engraving applications.

Provides sRGB/linear color space conversions, RGBA-to-grayscale/binary conversions with alpha unpremultiplication, grayscale normalization with auto-levels, dithering algorithms (Floyd-Steinberg, Bayer, minimum run length) for converting grayscale images to binary output, and scanline rasterization for converting Ops scanlines into pixel buffers.

Functions

rasterize_scanlines()

rasterize_scanlines(
ops: ops.Ops,
width_px: int,
height_px: int,
px_per_mm: tuple[float, float],
origin_mm: tuple[float, float] = (0, 0),
radius_px: int = 0,
) -> compressed_array.CompressedArray

Rasterize ScanLine commands from ops into a 2D power-map buffer.

Iterates all scanline commands in ops, converts their mm coordinates to pixel space using px_per_mm, and returns a uint8 array where each pixel holds the maximum power value written to it.

When radius_px is greater than zero, each rasterized sample is expanded to a square brush of side 2*radius_px + 1 (max-merged), equivalent to a square morphological dilation of the thin raster. Coverage is bounds-clamped at the texture edges (no wraparound).

ParameterTypeDescription
opsops.OpsCommand sequence to rasterize.
width_pxintWidth of the output texture in pixels.
height_pxintHeight of the output texture in pixels.
px_per_mmtuple[float, float](x, y) resolution in pixels per millimeter.
origin_mmtuple[float, float] = (0, 0)(x, y) origin offset in mm (default (0.0, 0.0)).
radius_pxint = 0Half-size of the dilation brush in pixels (default 0 -- no dilation).
Returnscompressed_array.CompressedArrayCompressedArray of shape (height_px, width_px), uint8.
ComplexityO(scanline_pixels * (2*radius_px + 1))

Scanline ops rasterized into a 2D power-map buffer

Scanline ops rasterized into a 2D power-map buffer