辅助:BGRA -> BGR
(src: &[u8], dest: &mut [u8], width: usize, height: usize)
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // 辅助:NV12 (semi-planar YUV 4:2:0) -> BGR |
| 387 | fn nv12_to_bgr(src: &[u8], dest: &mut [u8], width: usize, height: usize) { |
| 388 | let y_size = width * height; |
| 389 | let uv_size = width * height.div_ceil(2); |
| 390 | if src.len() < y_size + uv_size || dest.len() < width * height * 3 { |
| 391 | return; |
| 392 | } |
| 393 | let uv_plane = &src[y_size..]; |
| 394 | for y in 0..height { |
| 395 | let uv_row = (y / 2) * width; |
| 396 | for x in 0..width { |
| 397 | let y_val = src[y * width + x] as i32; |
| 398 | let uv_idx = uv_row + (x / 2) * 2; |
| 399 | let u = uv_plane[uv_idx] as i32 - 128; |
| 400 | let v = uv_plane[uv_idx + 1] as i32 - 128; |
| 401 | let c = y_val - 16; |
| 402 | let r = (298 * c + 409 * v + 128) >> 8; |