simvx.graphics.assets.image_loader¶
Image file I/O for textures: loading and saving PNG/JPG.
Module Contents¶
Functions¶
Return a new RGBA uint8 array with RGB channels premultiplied by alpha. |
|
Load PNG/JPG texture from disk → device-local VkImage. |
|
Save RGBA uint8 pixels (H, W, 4) as a PNG file. Pure Python, no Pillow. |
Data¶
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 isrgb' = 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: passpremultiply_alpha=TruetoTextureManager.resolve/.load/.load_from_bytesto 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.