crates/format/image/src/tile.rs 972 B 32 lines Raw
1 //! Splitting a frame into a strip of tiles.2 //!3 //! The engine sends an image to a plugin in parts. A short tile at the edge is4 //! kept short: a pad would invent pixels and the plugin would return them.5 6 use crate::pixel::{Frame, Tile};7 8 /// Splits a frame into tiles of at most `w × h`. The last row and column are9 /// short, never padded: a pad would invent pixels.10 pub fn split(frame: &Frame, w: u32, h: u32) -> Vec<Tile> {11     if w == 0 || h == 0 || frame.width == 0 || frame.height == 0 {12         return Vec::new();13     }14     let mut tiles = Vec::new();15     let mut y = 0;16     while y < frame.height {17         let tile_h = h.min(frame.height - y);18         let mut x = 0;19         while x < frame.width {20             let tile_w = w.min(frame.width - x);21             tiles.push(Tile {22                 x,23                 y,24                 w: tile_w,25                 h: tile_h,26             });27             x += tile_w;28         }29         y += tile_h;30     }31     tiles32 }