simvx.graphics.assets.image_loader

Image file I/O for textures: loading and saving PNG/JPG.

Module Contents

Functions

premultiply_alpha_rgba

Return a new RGBA uint8 array with RGB channels premultiplied by alpha.

load_texture_from_file

Load PNG/JPG texture from disk → device-local VkImage.

save_png

Save RGBA uint8 pixels (H, W, 4) as a PNG file. Pure Python, no Pillow.

Data

log

API

simvx.graphics.assets.image_loader.log

‘getLogger(…)’

simvx.graphics.assets.image_loader.premultiply_alpha_rgba(pixels: numpy.ndarray) numpy.ndarray[source]

Return a new RGBA uint8 array with RGB channels premultiplied by alpha.

Fixes halo artefacts on alpha-blended PNGs where transparent pixels still carry stale RGB values (e.g. (255, 255, 255, 0) border pixels that bleed white into anti-aliased sprite edges). The transform is rgb' = rgb * a / 255; for fully transparent pixels the output RGB is zero, regardless of the source RGB. Engine code paths use straight-alpha blending today, so this is opt-in: pass premultiply_alpha=True to TextureManager.resolve / .load / .load_from_bytes to enable it per-texture.

Args: pixels: (H, W, 4) uint8 RGBA array.

Returns: A new (H, W, 4) uint8 array; the input is not mutated.

simvx.graphics.assets.image_loader.load_texture_from_file(device: Any, physical_device: Any, queue: Any, cmd_pool: Any, file_path: str, *, premultiply_alpha: bool = False) tuple[Any, Any, int, int][source]

Load PNG/JPG texture from disk → device-local VkImage.

Returns: (image, memory, width, height)

Args: premultiply_alpha: When True, multiply RGB by alpha before upload so anti-aliased edges don’t bleed garbage RGB through transparent pixels. Default False keeps existing snapshot tests stable.

simvx.graphics.assets.image_loader.save_png(path: str | pathlib.Path, pixels: numpy.ndarray) None[source]

Save RGBA uint8 pixels (H, W, 4) as a PNG file. Pure Python, no Pillow.