Skip to main content

Module mip

Module mip 

Source
Expand description

An image drawn smaller is drawn from a level the core halves (docs/adr/0044-an-image-drawn-smaller-is-drawn-from-a-level.md, backlog V6).

Level 0 is the image; level n + 1 is level n with each 2×2 block averaged into one texel, ⌈w/2⌉ × ⌈h/2⌉, the last row and column of an odd size repeated. The average is taken in linear light with the alpha premultiplied, so a level is neither darker than its source nor fringed where a transparent edge meets colour. Which level a quad draws is level_for: the deepest still at least as many texels as pixels on both axes.

Functions§

depth
How many levels below level 0 a w × h image has: halving stops at 1×1.
halve
Level n + 1 from level n’s straight RGBA, w × h × 4 bytes: each 2×2 block averaged in linear light with the alpha premultiplied, the colour taken back to straight alpha. Returns the new size and pixels.
halved
The size of the level below a w × h one.
level_for
The level a quad draws: the deepest whose texels still cover the pixels on both axes. texels is the texel rect fit picked at level 0, pixels the drawn size in physical px (any scale the quad is drawn through multiplied in), deepest the chain’s last level. ⌊log₂ r⌋ for r the smaller of the two ratios, so a bilinear sample inside the level minifies by less than two and a level never magnifies.