Skip to main content

Module images

Module images 

Source
Expand description

Raster image XObject emission for the PDF backend.

The layout engine hands us a [mos_layout::PageGraph::images] table: one entry per unique on-disk image, dedup’d by resolved path. For each entry we emit a single Image XObject (/Type /XObject /Subtype /Image) with /Width, /Height, /BitsPerComponent, /ColorSpace /DeviceRGB, and the raw RGB8 pixel buffer flate-compressed under /Filter /FlateDecode. Each page’s /Resources /XObject dict lists every image, so per-page resource dicts stay byte-stable across pages.

Per-page placements arrive as [ImagePlacement]s; the content stream wraps each in q w 0 0 h x y cm /Im<id> Do Q so the image occupies the requested width/height rectangle at the requested page-relative position (after the same top→bottom flip the text emit path applies).

Alpha/soft-mask support is deferred. The eval layer composites every input image onto opaque white before handing the bytes off, so the emit path can stay on a single /DeviceRGB /Filter /FlateDecode codepath.

Functions§

emit_image_xobject 🔒
Emit one Image XObject (/Subtype /Image) for handle at id. compressed is the zlib-compressed pixel stream produced by flate_compress; passed in pre-compressed so the caller can hold onto the bytes for byte-stability assertions in tests.
emit_placement 🔒
Emit the q w 0 0 h x y cm /Im<id> Do Q block for one placement, translated into PDF’s bottom-origin coordinate space using page_height_pt.
flate_compress 🔒
Compress a flat RGB8 byte buffer with zlib (the format PDF expects behind /FlateDecode). Uses default compression for a reasonable size/speed tradeoff; image XObject byte stability across runs is preserved because flate2’s default settings are deterministic.
resource_name 🔒
Stable PDF resource name for the image with handle.id. Mirrors the /F<n> convention used by the font emitter; every page’s resource dict declares /Im<n> so PDF readers can resolve the references in the content stream.