Skip to main content

Module image

Module image 

Source
Expand description

Raster images (docs/images.md): decoding encoded bytes into a native image, reading what it is, encoding it back, and releasing it again. Rendering a canvas drawing into a bitmap or a PDF (docs/canvas.md “Exporting”) lives here too: a rendered bitmap is the same Bitmap a decode returns, held in the same toolkit table.

The shape mirrors presentation (present.rs): a request id, a pending registry, and a completion that arrives as an day_spec::Event the backend raises. It is request-shaped rather than blocking because one backend can never answer synchronously (a browser decodes through createImageBitmap, which is a promise), and one async-shaped API everywhere beats a synchronous one that is a lie on the web (docs/async.md rule 3: a callback and a future, never a runtime).

Everything here is thread-local and !Send, like the rest of day-core: Day has one UI thread.

Structs§

Bitmap
A decoded image the toolkit holds, released when the last handle drops.
CanvasExports
What this toolkit can export a canvas drawing to (Cap::CanvasBitmap, Cap::CanvasPdf). Read it to enable or hide export commands, the way image_encode_formats decides which formats to offer.
DecodeFuture
A decode in flight. Resolves with the decoded Bitmap, or why it could not be.
EncodeFuture
An encode in flight. Resolves with the encoded bytes, or why they could not be produced.
RenderBitmap
A bitmap render in flight. Resolves with the rendered Bitmap, or why it could not be. Nothing is asked of the toolkit until the first poll.
RenderPdf
A PDF render in flight. Resolves with the document’s bytes, or why they could not be produced. Nothing is asked of the toolkit until the first poll.

Functions§

canvas_exports
What this toolkit can export a canvas drawing to.
decode
Decode encoded image bytes (PNG/JPEG/…) with the platform’s own decoder.
decode_async
decode’s callback half (docs/async.md rule 3), for a call site that is not already async.
image_decode_support
Whether this toolkit can decode image bytes at all (Cap::ImageDecode).
image_encode_formats
Which formats Bitmap::encode can write here: the Cap::ImageEncode counterpart of font_families(). Empty where encoding is unsupported.
image_encode_support
Whether this toolkit can encode a decoded image back to bytes (Cap::ImageEncode).
render_bitmap
Replay ops into an offscreen bitmap of size points at scale pixels per point, through the toolkit’s own canvas painter. Resolves with a Bitmap like a decode does, so image(&bitmap), Draw::image and Bitmap::encode all take it. Apps reach this through Drawing::to_bitmap.
render_bitmap_async
render_bitmap’s callback half (docs/async.md rule 3).
render_pdf
Replay each page into one PDF document through the platform’s own PDF writer. Resolves with the document’s bytes. Apps reach this through Drawing::to_pdf and PdfDocument::render.
render_pdf_async
render_pdf’s callback half (docs/async.md rule 3).
resolve_bitmap_render
Deliver a bitmap render’s answer (Event::BitmapRendered). The same contract as resolve_image_decode, including releasing a success nobody is waiting for.
resolve_image_decode
Deliver a decode answer. Called from pump_events; a request already answered, cancelled, or never issued finds nothing and does nothing, the same contract presentation has.
resolve_image_encode
Deliver an encode answer (see resolve_image_decode).
resolve_pdf_render
Deliver a PDF render’s answer (Event::PdfRendered).
Day API ↩ Guides· daybrite.dev