Skip to content

Commit 87ffb29

Browse files
committed
Use Limited Range YUV
1 parent 7eb55a5 commit 87ffb29

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

openh264/src/formats/yuv2rgb.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ pub fn write_rgb8_scalar_par(
9797

9898
let rgb_pixel = &mut target[base_tgt..base_tgt + 3];
9999

100-
let y = f32::from(y_plane[base_y]);
101-
let u = f32::from(u_plane[base_u]);
102-
let v = f32::from(v_plane[base_v]);
103-
104-
rgb_pixel[0] = 1.402f32.mul_add(v - 128.0, y) as u8;
105-
rgb_pixel[1] = 0.714f32.mul_add(-(v - 128.0), 0.344f32.mul_add(-(u - 128.0), y)) as u8;
106-
rgb_pixel[2] = 1.772f32.mul_add(u - 128.0, y) as u8;
100+
// Convert limited range YUV to RGB
101+
// https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion
102+
let y_mul = Y_MUL * (f32::from(y_plane[base_y]) - 16.0);
103+
let u = f32::from(u_plane[base_u]) - 128.0;
104+
let v = f32::from(v_plane[base_v]) - 128.0;
105+
106+
rgb_pixel[0] = RV_MUL.mul_add(v, y_mul) as u8;
107+
rgb_pixel[1] = GV_MUL.mul_add(v, GU_MUL.mul_add(u, y_mul)) as u8;
108+
rgb_pixel[2] = BU_MUL.mul_add(u, y_mul) as u8;
107109
}
108110
}
109111
});
@@ -161,6 +163,7 @@ pub fn write_rgb8_f32x8(
161163

162164
/// Write RGB8 data from YUV420 using f32x8 SIMD.
163165
#[allow(clippy::identity_op)]
166+
#[allow(dead_code)] // usabe TBD
164167
pub fn write_rgb8_f32x8_par(
165168
y_plane: &[u8],
166169
u_plane: &[u8],

0 commit comments

Comments
 (0)