aom_decode/
chroma.rs

1use yuv::YUV;
2
3/// Iterator that combines equal-sized planes of Y, U, V into YUV pixels
4pub fn yuv_444<'a, T: Copy + 'a, YRowsIter, URowsIter, VRowsIter>(y: YRowsIter, u: URowsIter, v: VRowsIter) -> impl Iterator<Item = YUV<T>> + 'a
5where
6    YRowsIter: Iterator<Item = &'a [T]> + 'a,
7    URowsIter: Iterator<Item = &'a [T]> + 'a,
8    VRowsIter: Iterator<Item = &'a [T]> + 'a,
9{
10    y.zip(u.zip(v))
11        .flat_map(|(y,(u,v))| {
12            y.iter().copied().zip(u.iter().copied().zip(v.iter().copied()))
13            .map(|(y,(u,v))| YUV{y,u,v})
14        })
15}
16
17/// Iterator that combines planes of Y, U, V into YUV pixels, where U and V have half width
18///
19/// Uses nearest-neighbor scaling.
20pub fn yuv_422<'a, T: Copy + 'a, YRowsIter, URowsIter, VRowsIter>(y: YRowsIter, u: URowsIter, v: VRowsIter) -> impl Iterator<Item = YUV<T>> + 'a
21where
22    YRowsIter: Iterator<Item = &'a [T]> + 'a,
23    URowsIter: Iterator<Item = &'a [T]> + 'a,
24    VRowsIter: Iterator<Item = &'a [T]> + 'a,
25{
26    y.zip(u.zip(v))
27        .flat_map(|(y,(u,v))| {
28            let u = u.iter().copied().flat_map(|u_px| std::iter::repeat(u_px).take(2));
29            let v = v.iter().copied().flat_map(|v_px| std::iter::repeat(v_px).take(2));
30            y.iter().copied().zip(u.zip(v))
31            .map(|(y,(u,v))| YUV{y,u,v})
32        })
33}
34
35/// Iterator that combines planes of Y, U, V into YUV pixels, where U and V have half width and half height
36///
37/// Uses nearest-neighbor scaling.
38pub fn yuv_420<'a, T: Copy + 'a, YRowsIter, URowsIter, VRowsIter>(y: YRowsIter, u: URowsIter, v: VRowsIter) -> impl Iterator<Item = YUV<T>> + 'a
39where
40    YRowsIter: Iterator<Item = &'a [T]> + 'a,
41    URowsIter: Iterator<Item = &'a [T]> + 'a,
42    VRowsIter: Iterator<Item = &'a [T]> + 'a,
43{
44    let u = u.flat_map(|u_row| std::iter::repeat(u_row).take(2));
45    let v = v.flat_map(|v_row| std::iter::repeat(v_row).take(2));
46    y.zip(u.zip(v))
47    .flat_map(|(y,(u,v))| {
48        let u = u.iter().copied().flat_map(|u_px| std::iter::repeat(u_px).take(2));
49        let v = v.iter().copied().flat_map(|v_px| std::iter::repeat(v_px).take(2));
50        y.iter().copied().zip(u.zip(v))
51        .map(|(y,(u,v))| YUV{y,u,v})
52    })
53}