marcellBan / rgb2yuv420-rs

Simple RGB to YUV420 converter
0 stars 2 forks source link

yuv file down half color is wrong #1

Open nintha opened 3 years ago

nintha commented 3 years ago

I try to use this lib to convert png image, but the output yuv file down half color is wrong.

I use ffplay to display yuv file.

Luckily, i find some way to fix it. Comments is origin code.

pub fn convert_rgb_to_yuv420p(img: &[u8], width: u32, height: u32, bytes_per_pixel: usize) -> Vec<u8> {
    convert_rgb_to_yuv420(img, width, height, bytes_per_pixel, |yuv, uv_index, chroma_size, u, v| {
        yuv[*uv_index] = u;
        yuv[*uv_index + chroma_size] = v; // yuv[*uv_index + (f32::ceil(chroma_size as f32 / 2.0) as usize)] = v;
        *uv_index += 1;
    })
}
CryZe commented 3 years ago

I just ran into the same issue.