Skip to main content

Module image

Module image 

Source
Expand description

Raster image resolution and decode for #image(...) directives.

The lowerer hands us a relative path (typed as "path.png" in the source) plus the source file’s location. We resolve it to an absolute path, read the bytes, and decode them through the image crate’s PNG / JPEG decoders. The decoded pixels are flattened to RGB8 (alpha channels are composited onto white) so the PDF backend can emit them as a /DeviceRGB Image XObject without threading a soft-mask through the emit path.

Diagnostics:

  • MOS0037: #image(...) called without a path string.
  • MOS0012: cannot read the file on disk.
  • MOS0029: cannot decode the bytes as PNG/JPEG.

Structs§

DecodedImage 🔒
One decoded raster image, ready to be lowered onto a [mos_core::NodeKind::Image] node.

Functions§

composite 🔒
Composite a single 8-bit colour channel onto opaque white using its 8-bit alpha. ((c * a) + 255 * (255 - a)) / 255, rounded to nearest.
decode 🔒
load 🔒
Resolve src_path (as written in the source) relative to source_file (the .mos file currently being lowered), then read + decode it.