img_core/mip.rs#
Source: lib/img_core/mip.rs
mip -- display mip levels: 2 x 2 box filter in premultiplied space [src/img/mip.s]
mip_down(src, dst, x0, y0, x1, y1) -> 0 / ERR_*
update the part of dst (the next level of src) covered by the source rectangle
x0, y0 .. x1, y1 (exclusive; clamped to src) [mip_down]
mip_down_rows(src, band, x0, x1, dy0, dy1) -> 0 / ERR_*
the same for dst rows dy0 .. dy1-1 (of a Band of dst; workers split the dst rows) and
the source columns x0 .. x1-1 [mip_down_rows]
MipChain::alloc(w, h, levels) -> Option<MipChain>
levels 1 .. n below a w x h base (levels 0 = until 1 x 1; at most MIP_MAX)
[mip_chain_alloc]
chain.update(src, rect) -> 0 / ERR_* propagate the dirty rectangle rect ([x0, y0, x1,
y1]; None = everything) of the base image src through every level [mip_chain_update]
chain.level(k) -> Option<&Surface> level k (1 .. n) [mip_chain_level]
src: FMT_ARGB (straight) or FMT_PARGB; dst: FMT_PARGB of (w + 1) / 2 x (h + 1) / 2
(ERR_UNSUPPORTED / ERR_DIMS otherwise). dst(i, j) averages src columns 2i, min(2i + 1,
w - 1) and rows 2j, min(2j + 1, h - 1) (odd edges repeat the last pixel):
FMT_PARGB v = (p00 + p01 + p10 + p11 + 2) >> 2 per channel
FMT_ARGB a = (sum a + 2) >> 2; t = (sum c * a + 2) >> 2, c = min(a, ((t + 128) * 257) >> 16)
Thread safe (no global state); mip_down_rows calls on disjoint bands may run in parallel.
The level surfaces are ordinary FMT_PARGB surfaces owned by the chain (drop = mip_chain_free).
MIP_MAX: u32 = 16 // levels below the base (65535 -> 1 needs 16)
fn mip_down_rows(src: &Surface, dst: &mut Band, x0: i32, x1: i32, dy0: i32, dy1: i32) -> i32dst rows dy0 .. dy1-1 (clamped to the dst and to the band) from the source columns x0 .. x1-1: ERR_UNSUPPORTED (formats), ERR_DIMS (dst not the half size) [mip_down_rows]fn mip_down(src: &Surface, dst: &mut Surface, x0: i32, y0: i32, x1: i32, y1: i32) -> i32the part of dst covered by the source rectangle x0, y0 .. x1, y1 [mip_down]struct MipChaina mip chain: levels 1 .. n (FMT_PARGB) below a w x h base [MC_*]n: u32w: i32h: i32
impl MipChain
fn alloc(w: i32, h: i32, levels: i32) -> Option<MipChain>levels 1 .. MIP_MAX as given, else (0, negative, too many) as many as reach 1 x 1; None when w or h is outside 1 .. 65535 [mip_chain_alloc]fn level(&self, k: u32) -> Option<&Surface>level k (1 .. n) [mip_chain_level]fn update(&mut self, src: &Surface, rect: Option<[i32; 4]>) -> i32propagate the dirty rectangle of the base image src (None = all of it) through every level: the next level's rectangle is (x0 >> 1, y0 >> 1, (x1 + 1) >> 1, (y1 + 1) >> 1) [mip_chain_update]