未验证 提交 4b670046 编写于 作者: J jesseryoung 提交者: GitHub

Clamp YUV values to be within byte ranges (#1726)

Co-authored-by: NJesse Young <jesseyoungcomputer@gmail.com>
上级 cbef127c
......@@ -159,11 +159,13 @@ namespace Iot.Device.Media
/// <returns>RGB color.</returns>
private static Color YuvToRgb(int y, int u, int v)
{
byte r = (byte)(y + 1.4075 * (v - 128));
byte g = (byte)(y - 0.3455 * (u - 128) - (0.7169 * (v - 128)));
byte b = (byte)(y + 1.7790 * (u - 128));
byte r = Clamp(y + 1.4075 * (v - 128));
byte g = Clamp(y - 0.3455 * (u - 128) - (0.7169 * (v - 128)));
byte b = Clamp(y + 1.7790 * (u - 128));
return Color.FromArgb(r, g, b);
}
private static byte Clamp(double val) => (byte)(val > 255 ? 255 : val < 0 ? 0 : val);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册