Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/image/sink"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
convert |
std/image/convert |
sink.dodo |
graphics |
std/graphics |
sink.dodo |
pixels |
std/image/pixels |
sink.dodo |
Sink
Interface · Source
Where decoders put pixels. A decoder calls begin() once with the header, then rect() with pieces of the image in the header’s native layout, in whatever order the format produces them: rows for PNG and BMP, groups or tiles for JPEG XL, single pixels for interlaced passes. A row is a rect of height 1. Every pixel of the image arrives at least once; for progressive formats a later rect replaces an earlier one.
ViewSink converts into caller storage in any layout, CanvasSink draws onto a graphics.Canvas, and NullSink discards (for validation). Implement Sink for anything else, such as a streaming encoder or resizer.
pub interface Sink {
fn begin(&mut self, header: &pixels.Header) -> void!pixels.Error
fn rect(&mut self, x: u32, y: u32, source: &pixels.View) -> void!pixels.Error
}
ViewSink
Struct · Source
Converts rects into a ViewMut at least as large as the image. The image’s top-left pixel lands at the view’s top-left pixel.
pub struct ViewSink {
// Private implementation fields omitted.
}
ViewSink.new
Function · Source
pub fn new(target: &mut pixels.ViewMut) -> ViewSink from(target)
ViewSink.begin
Function · Source
pub fn begin(&mut self, header: &pixels.Header) -> void!pixels.Error
ViewSink.rect
Function · Source
pub fn rect(&mut self, x: u32, y: u32, source: &pixels.View) -> void!pixels.Error
CanvasSink
Struct · Source
Draws rects onto a canvas with the image’s top-left corner at (x, y). Pixels outside the canvas or its clip are skipped; colors are stored, not blended, after conversion to straight 8-bit RGBA.
pub struct CanvasSink {
// Private implementation fields omitted.
}
CanvasSink.new
Function · Source
pub fn new(canvas: &mut graphics.Canvas, x: i32, y: i32) -> CanvasSink from(canvas)
CanvasSink.begin
Function · Source
pub fn begin(&mut self, header: &pixels.Header) -> void!pixels.Error
CanvasSink.rect
Function · Source
pub fn rect(&mut self, x: u32, y: u32, source: &pixels.View) -> void!pixels.Error
NullSink
Struct · Source
Accepts and discards everything: decoding into it validates a file.
pub struct NullSink {
pub width: u32
pub height: u32
pub rects: u64
}
NullSink.new
Function · Source
pub fn new() -> NullSink
NullSink.begin
Function · Source
pub fn begin(&mut self, header: &pixels.Header) -> void!pixels.Error
NullSink.rect
Function · Source
pub fn rect(&mut self, x: u32, y: u32, source: &pixels.View) -> void!pixels.Error
Source
Interface · Source
Where encoders read pixels. An encoder asks for the source’s layout to pick its output format (channel count, 8 or 16-bit), then loads runs of pixels as straight RGBA. ViewSource reads a pixels.View in any layout and CanvasSource a graphics.Canvas in any pixel format; both are integer-only.
pub interface Source {
fn width(&self) -> u32
fn height(&self) -> u32
// The layout that holds the source's samples without loss.
fn layout(&self) -> pixels.Layout
// `count` pixels of row y from column x as straight 8-bit RGBA in
// out[..4 * count]. The caller keeps x + count <= width and y < height.
fn load_rgba8(&self, x: u32, y: u32, count: usize, out: &mut[u8])
// The same as straight 16-bit RGBA.
fn load_rgba16(&self, x: u32, y: u32, count: usize, out: &mut[u16])
}
ViewSource
Struct · Source
Reads a View, converting with convert.load_rgba8 and load_rgba16.
pub struct ViewSource {
// Private implementation fields omitted.
}
ViewSource.new
Function · Source
pub fn new(view: &pixels.View) -> ViewSource from(view)
ViewSource.width
Function · Source
pub fn width(&self) -> u32
ViewSource.height
Function · Source
pub fn height(&self) -> u32
ViewSource.layout
Function · Source
pub fn layout(&self) -> pixels.Layout
ViewSource.load_rgba8
Function · Source
pub fn load_rgba8(&self, x: u32, y: u32, count: usize, out: &mut[u8])
ViewSource.load_rgba16
Function · Source
pub fn load_rgba16(&self, x: u32, y: u32, count: usize, out: &mut[u16])
CanvasSource
Struct · Source
Reads a canvas from its top-left pixel, wherever its origin is, as 8-bit RGBA (formats without alpha read as opaque).
pub struct CanvasSource {
// Private implementation fields omitted.
}
CanvasSource.new
Function · Source
pub fn new(canvas: &graphics.Canvas) -> CanvasSource from(canvas)
CanvasSource.width
Function · Source
pub fn width(&self) -> u32
CanvasSource.height
Function · Source
pub fn height(&self) -> u32
CanvasSource.layout
Function · Source
pub fn layout(&self) -> pixels.Layout
CanvasSource.load_rgba8
Function · Source
pub fn load_rgba8(&self, x: u32, y: u32, count: usize, out: &mut[u8])
CanvasSource.load_rgba16
Function · Source
pub fn load_rgba16(&self, x: u32, y: u32, count: usize, out: &mut[u16])