API referencestd/image

std/image/ops

Public declarations, types, methods, and source contracts for std/image/ops.

On this page

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/ops"

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
carve std/image/shared/scratch quantize.dodo, resize.dodo
color std/image/color common.dodo, geometry.dodo, resize.dodo
convert std/image/convert adjust.dodo, common.dodo, compare.dodo, geometry.dodo, histogram.dodo, quantize.dodo, resize.dodo
math std/math compare.dodo
pixels std/image/pixels adjust.dodo, common.dodo, compare.dodo, geometry.dodo, histogram.dodo, quantize.dodo, resize.dodo
slice core/slice quantize.dodo, resize.dodo

fill

Function · Source

Set every pixel of target to a straight 16-bit RGBA color (8-bit values times 257); gray targets receive its BT.709 luma, layouts without alpha drop it.

pub fn fill(target: &mut pixels.ViewMut, r: u16, g: u16, b: u16, a: u16)

fill8

Function · Source

fill() with an 8-bit color.

pub fn fill8(target: &mut pixels.ViewMut, r: u8, g: u8, b: u8, a: u8)

composite_over

Function · Source

Blend source over target with source pixel (0, 0) at target (x, y), using its alpha (straight or premultiplied, any layout). Parts outside the target are skipped.

pub fn composite_over(source: &pixels.View, target: &mut pixels.ViewMut, x: i32, y: i32)

grayscale

Function · Source

Replace color by its BT.709 luma, keeping alpha; the target (same size) may be color or gray.

pub fn grayscale(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

invert

Function · Source

Invert color (1 - value per channel), keeping alpha.

pub fn invert(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

Metrics

Struct · Source

Per-channel error statistics of two images; see measure().

pub struct Metrics {
    pub width: u32
    pub height: u32
    // 3, or 4 when either image has alpha.
    pub channels: usize
    // Pixels with any channel different.
    pub different_pixels: u64
    // Largest difference of any channel, in 16-bit units (257 per 8-bit
    // step).
    pub max_difference: u32
    // Largest difference per channel R, G, B, A.
    pub max_channel: [4]u32
    // Private implementation fields omitted.
}

Metrics.mse

Function · Source

Mean squared error of all compared channels on the 0..255 scale.

pub fn mse(&self) -> f64

Metrics.mse_channel

Function · Source

Mean squared error of channel 0 (red) to 3 (alpha).

pub fn mse_channel(&self, channel: usize) -> f64

Metrics.psnr

Function · Source

Peak signal-to-noise ratio in dB; infinity when identical.

pub fn psnr(&self) -> f64

Metrics.psnr_channel

Function · Source

pub fn psnr_channel(&self, channel: usize) -> f64

Metrics.identical

Function · Source

pub fn identical(&self) -> bool

measure

Function · Source

Compare two same-sized images in one pass.

pub fn measure(a: &pixels.View, b: &pixels.View) -> Metrics!pixels.Error

mse

Function · Source

Mean squared error on the 0..255 scale over R, G, B (and A when either image has alpha).

pub fn mse(a: &pixels.View, b: &pixels.View) -> f64!pixels.Error

psnr

Function · Source

PSNR in dB, infinity for identical images.

pub fn psnr(a: &pixels.View, b: &pixels.View) -> f64!pixels.Error

max_difference

Function · Source

The largest difference of any channel in 16-bit units.

pub fn max_difference(a: &pixels.View, b: &pixels.View) -> u32!pixels.Error

difference_count

Function · Source

How many pixels differ in any channel.

pub fn difference_count(a: &pixels.View, b: &pixels.View) -> u64!pixels.Error

equal

Function · Source

True when both images have the same size and every pixel matches as straight 16-bit RGBA.

pub fn equal(a: &pixels.View, b: &pixels.View) -> bool

ssim

Function · Source

Mean structural similarity of the two images’ luma, 1.0 when identical. Empty images give 1.0.

pub fn ssim(a: &pixels.View, b: &pixels.View) -> f64!pixels.Error

Size

Struct · Source

A width and height.

pub struct Size {
    pub width: u32
    pub height: u32
}

crop

Function · Source

The width x height rectangle of source at (x, y), sharing its pixels. Malformed when it does not fit.

pub fn crop(source: &pixels.View, x: u32, y: u32, width: u32, height: u32) -> pixels.View!pixels.Error from(source)

crop_mut

Function · Source

The writable width x height rectangle of target at (x, y).

pub fn crop_mut(target: &mut pixels.ViewMut, x: u32, y: u32, width: u32, height: u32) -> pixels.ViewMut!pixels.Error from(target)

copy

Function · Source

Copy source into a target of the same size, converting the layout.

pub fn copy(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

flip_horizontal

Function · Source

pub fn flip_horizontal(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

flip_vertical

Function · Source

pub fn flip_vertical(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

rotate180

Function · Source

pub fn rotate180(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

rotate90

Function · Source

Rotate 90 degrees clockwise; the target is source.height() wide.

pub fn rotate90(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

rotate270

Function · Source

Rotate 270 degrees clockwise (90 counter-clockwise).

pub fn rotate270(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

transpose

Function · Source

Mirror along the top-left to bottom-right diagonal.

pub fn transpose(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

transverse

Function · Source

Mirror along the top-right to bottom-left diagonal.

pub fn transverse(source: &pixels.View, target: &mut pixels.ViewMut) -> void!pixels.Error

orient

Function · Source

Apply an orientation (as stored in a file’s header) so that target holds the image as it is meant to be displayed. The target has oriented_size(source.width(), source.height(), orientation).

pub fn orient(source: &pixels.View, target: &mut pixels.ViewMut, orientation: &color.Orientation) -> void!pixels.Error

oriented_size

Function · Source

The size of a width x height image once orientation is applied.

pub fn oriented_size(width: u32, height: u32, orientation: &color.Orientation) -> Size

inverse_orientation

Function · Source

The orientation that undoes orientation: applying one after the other gives the original image. Only the quarter turns differ from themselves.

pub fn inverse_orientation(orientation: &color.Orientation) -> color.Orientation

flip_horizontal_in_place

Function · Source

Mirror left-right in place.

pub fn flip_horizontal_in_place(view: &mut pixels.ViewMut)

flip_vertical_in_place

Function · Source

Mirror top-bottom in place.

pub fn flip_vertical_in_place(view: &mut pixels.ViewMut)

rotate180_in_place

Function · Source

Rotate by 180 degrees in place.

pub fn rotate180_in_place(view: &mut pixels.ViewMut)

orient_in_place

Function · Source

Apply an orientation in place. Orientations that swap the axes need a square view; others are Malformed then.

pub fn orient_in_place(view: &mut pixels.ViewMut, orientation: &color.Orientation) -> void!pixels.Error

Channel

Enum · Source

pub enum Channel {
    Red,
    Green,
    Blue,
    Alpha,
    Luma
}

Range

Struct · Source

The smallest and largest value of a channel, in 16-bit units.

pub struct Range {
    pub min: u32
    pub max: u32
}

histogram

Function · Source

Count the values of one channel of source into bins (cleared first; bins.len is the bin count). Malformed when bins is empty.

pub fn histogram(source: &pixels.View, channel: Channel, bins: &mut[u32]) -> void!pixels.Error

luma_histogram

Function · Source

The histogram of BT.709 luma.

pub fn luma_histogram(source: &pixels.View, bins: &mut[u32]) -> void!pixels.Error

channel_range

Function · Source

The smallest and largest value of a channel. Malformed for an empty image.

pub fn channel_range(source: &pixels.View, channel: Channel) -> Range!pixels.Error

mean

Function · Source

The mean of a channel from 0.0 to 1.0. Malformed for an empty image.

pub fn mean(source: &pixels.View, channel: Channel) -> f64!pixels.Error

Dither

Enum · Source

pub enum Dither {
    None,
    FloydSteinberg,
    // 8x8 Bayer matrix.
    Ordered
}

MAX_PALETTE

Constant · Source

pub const MAX_PALETTE: usize = 256

palette_scratch_size

Function · Source

Scratch bytes palette() needs for a width x height image.

pub fn palette_scratch_size(width: u32, height: u32) -> usize!pixels.Error

palette

Function · Source

Build a palette of at most max_colors (1 to 256) RGBA quads in palette_out and return how many entries it has. Images with no more distinct colors than max_colors get exactly those colors, in ascending RGBA order. An empty image gives 0 entries.

pub fn palette(source: &pixels.View, max_colors: usize, palette_out: &mut[u8], work: &mut[u8]) -> usize!pixels.Error

nearest_color

Function · Source

The index of the palette entry (RGBA quads) nearest to a straight color. An empty palette gives 0.

pub fn nearest_color(palette: &[u8], r: u8, g: u8, b: u8, a: u8) -> usize

remap_scratch_size

Function · Source

Scratch bytes remap() needs for a source width pixels wide.

pub fn remap_scratch_size(width: u32) -> usize!pixels.Error

remap

Function · Source

Replace each pixel of source by the index of a palette entry (RGBA quads, 1 to 256 of them), row by row into indices[..width * height].

pub fn remap(source: &pixels.View, palette: &[u8], indices: &mut[u8], dither: Dither, work: &mut[u8]) -> void!pixels.Error

reduce_depth_scratch_size

Function · Source

Scratch bytes reduce_depth() needs for an image width pixels wide.

pub fn reduce_depth_scratch_size(width: u32) -> usize!pixels.Error

reduce_depth

Function · Source

Posterize source into target (same size, any layout) keeping red_bits, green_bits, blue_bits and alpha_bits (1 to 16 each) of every channel; levels are spread evenly over the full range, so 5 bits gives 0, 65535 / 31, … With 8-bit targets and 8 bits nothing changes.

pub fn reduce_depth(source: &pixels.View, target: &mut pixels.ViewMut, red_bits: u32, green_bits: u32, blue_bits: u32, alpha_bits: u32, dither: Dither, work: &mut[u8]) -> void!pixels.Error

Filter

Enum · Source

pub enum Filter {
    Nearest,
    Box,
    Bilinear,
    CatmullRom,
    Mitchell,
    Lanczos3
}

ResizeOptions

Struct · Source

pub struct ResizeOptions {
    pub filter: Filter
    // Filter in linear light instead of on sRGB-encoded values.
    pub linear: bool
}

ResizeOptions.new

Function · Source

pub fn new(filter: Filter) -> ResizeOptions

ResizeOptions.linear_light

Function · Source

pub fn linear_light(filter: Filter) -> ResizeOptions

resize_scratch_size

Function · Source

Scratch bytes resize() and ResizeSink need for these sizes and a target in target_layout.

pub fn resize_scratch_size(source_width: u32, source_height: u32, target_width: u32, target_height: u32, target_layout: &pixels.Layout, options: &ResizeOptions) -> usize!pixels.Error

resize

Function · Source

Resize source into target (any sizes and layouts). Identical sizes copy. Malformed when the source is empty but the target is not; BufferTooSmall when scratch is shorter than resize_scratch_size().

pub fn resize(source: &pixels.View, target: &mut pixels.ViewMut, options: &ResizeOptions, scratch: &mut[u8]) -> void!pixels.Error

ResizeSink

Struct · Source

A sink that resizes a decoder’s output into target while it streams, so a large image can be decoded straight to a thumbnail. The decoder must deliver full-width rects top to bottom with no gaps or repeats (PNG, BMP, QOI, PPM and other row-order decoders do); anything else, such as tiles or interlaced passes, fails with Unsupported, and the image should then be decoded to a full-size view and passed to resize(). Scratch is resize_scratch_size() for the header’s size and the target’s layout.

pub struct ResizeSink {
    // Private implementation fields omitted.
}

ResizeSink.new

Function · Source

pub fn new(target: &mut pixels.ViewMut, source_width: u32, source_height: u32, options: &ResizeOptions, scratch: &mut[u8]) -> ResizeSink!pixels.Error from(target, scratch)

ResizeSink.begin

Function · Source

pub fn begin(&mut self, header: &pixels.Header) -> void!pixels.Error

ResizeSink.rect

Function · Source

pub fn rect(&mut self, x: u32, y: u32, source: &pixels.View) -> void!pixels.Error

ResizeSink.complete

Function · Source

True once every target row has been written.

pub fn complete(&self) -> bool

Search every guide, reference page, and API declaration.