Module zune_imageprocs::crop
source · Expand description
Crop an image
§Algorithm
We can take cropping as a view into a sub-image which means
width ──────────────────────────────►
│ ┌─────────────────────────────────────┐
│ │ │
│ │ │
│ │ (x,y) out width │
│ │ ┌────────────────────┐ │
│ │ o │ │ │
│ │ u │ │ │
│ │ t │ │ │
│ │ │ CROPPED IMAGE │ │
│ │ h │ │ │
│ │ e │ │ │
│ │ i │ │ │
│ │ g │ │ │
│ │ h └────────────────────┘ │
│ │ t │
│ │ │
▼ │ │
└─────────────────────────────────────┘
So a crop is essentially a weird memory copy starting from (x,y) like a small sub copy !!! That’s what we essentialy implement here
§Specific implementation
So because we need to skip from 0–y we can use iter.skip(y) to point at y.
Since every iterator is moving a single line per height, we only iterate per
out_height number of times, so we can achieve this with a take
iterators.
Rust iterators are fun!!
Structs§
- Crop out a part of an image
Functions§
- Crop an image channel