From aa4d7550e9ff622afad38af368f9a8a5c37df6a1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 16 Oct 2023 13:09:49 +0900 Subject: [PATCH] yuyv444_to_rgb: avoid highlight overflows --- nokhwa-core/src/types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nokhwa-core/src/types.rs b/nokhwa-core/src/types.rs index 3596f4c..9e465b6 100644 --- a/nokhwa-core/src/types.rs +++ b/nokhwa-core/src/types.rs @@ -1617,9 +1617,9 @@ pub fn yuyv444_to_rgb(y: i32, u: i32, v: i32) -> [u8; 3] { let c298 = (y - 16) * 298; let d = u - 128; let e = v - 128; - let r = ((c298 + 409 * e + 128) >> 8) as u8; - let g = ((c298 - 100 * d - 208 * e + 128) >> 8) as u8; - let b = ((c298 + 516 * d + 128) >> 8) as u8; + let r = ((c298 + 409 * e + 128) >> 8).clamp(0, 255) as u8; + let g = ((c298 - 100 * d - 208 * e + 128) >> 8).clamp(0, 255) as u8; + let b = ((c298 + 516 * d + 128) >> 8).clamp(0, 255) as u8; [r, g, b] }