diff --git a/examples/capture/.gitignore b/examples/capture/.gitignore index a46e442..ec8f8a0 100644 --- a/examples/capture/.gitignore +++ b/examples/capture/.gitignore @@ -84,3 +84,6 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +*.png +*.jpg +*.jpeg diff --git a/nokhwa-core/src/types.rs b/nokhwa-core/src/types.rs index 2457713..790d977 100644 --- a/nokhwa-core/src/types.rs +++ b/nokhwa-core/src/types.rs @@ -1782,6 +1782,8 @@ pub fn buf_nv12_to_rgb( }); } + let rgba_size = if rgba { 4 } else { 3 }; + let y_section = (resolution.width() * resolution.height()) as usize; for (idx, row) in data[0..y_section] @@ -1794,13 +1796,12 @@ pub fn buf_nv12_to_rgb( let y1 = block[1]; // determine the u and v let block_offset_idx = y_section + (true_idx * resolution.height() as usize) + cidx * 2; - let offset_idx = idx * resolution.height() as usize * (if rgba { 4 } else { 3 }) - + cidx * 2 * (if rgba { 4 } else { 3 }); + let offset_idx = idx * resolution.height() as usize * rgba_size + cidx * 2 * rgba_size; let u = data[block_offset_idx]; let v = data[block_offset_idx + 1]; if rgba { - let px0 = yuyv444_to_rgba(y0 as i32, u as i32, v as i32); - let px1 = yuyv444_to_rgba(y1 as i32, u as i32, v as i32); + let px0 = yuyv444_to_rgba(y0 as i32, v as i32, u as i32); + let px1 = yuyv444_to_rgba(y1 as i32, v as i32, u as i32); out[offset_idx] = px0[0]; out[offset_idx + 1] = px0[1]; out[offset_idx + 2] = px0[2];