Skip to main content

Crate otf_pixels_ops

Crate otf_pixels_ops 

Source
Expand description

Operation kernels for otf-pixels.

Each op implements Op and is chained onto an Image to build graph structure. Ops do no work when chained — they declare their output shape and their demand, and run only when a terminal pulls pixels through them.

§Scope

The full v1 op set from SPEC §Core ops is here: Resize, Crop, Rotate, Flip, Flop, Modulate, Convolve, Composite, ExtractChannel and Flatten.

§Two kinds of op

Layout ops — crop, flip, flop, rotate — move whole pixels without inspecting them. They copy opaque byte runs, so one implementation is correct for every pixel format including ones added later, and they do not use dispatch_sample!: there is no arithmetic to specialize.

Arithmetic ops — resize, modulate, convolve, composite, flatten — read sample values, so they dispatch once per tile on the sample type and run a monomorphized inner loop (ADR-0002). Per ADR-0011 those loops are written to autovectorize rather than to call intrinsics, and 8-bit paths use i32 fixed point so that vectorization cannot change the result.

§Tiling is not observable

Every op here produces the same pixels whether it runs in one tile or in many. That is not automatic — a resize whose weight tables were built per tile would resample at the tile’s scale — so each op with a non-trivial demand mapping asserts it directly.

§Writing an op

An op declares four things (ARCHITECTURE §Layer 3):

  • output_descriptor — its output shape, computed at graph-build time.
  • input_regions — the inverse mapping demand propagation walks backwards.
  • access_pattern — Sequential or Spatial, driving tile negotiation (ADR-0003).
  • compute — the kernel itself.

The first three are what make an op work correctly under M2’s scheduler rather than only under M1’s whole-image evaluator, so they must be right even while the evaluator only ever asks for whole images.

Structs§

Composite
Draw overlay over base at an offset.
ConvertFormat
Convert to a different PixelFormat.
Convolve
Apply a convolution kernel.
Crop
Extract a rectangular window of an image.
ExtractChannel
Extract one channel as a greyscale image (SPEC §Core ops).
Flatten
Composite an image onto an opaque background, discarding alpha.
Flip
Mirror an image vertically: the top row becomes the bottom row.
Flop
Mirror an image horizontally: the left column becomes the right column.
Kernel
A convolution kernel: odd-sized, square or rectangular, small.
Modulate
Brightness, saturation and hue adjustment (SPEC §Core ops).
Resize
Resample an image to a new size.
ResizeOptions
Options for Resize.
Rotate
Rotate an image by a multiple of 90 degrees.
Run
The input samples and weights contributing to one output position.
ToSrgb
Converts pixels in an ICC profile’s colour space to sRGB.
Weights
Precomputed weights for one resize pass along one axis.

Enums§

Blend
How the source is combined with the backdrop.
Conversion
What ToSrgb::from_profile makes of a profile.
Filter
A resampling filter kernel (SPEC §Core ops).
Fit
How a resize reconciles the requested box with the source aspect ratio, with sharp’s meanings.
Quarter
A quarter-turn rotation, clockwise.
Unconvertible
Why a profile is not converted.