|
|
|
@ -4,6 +4,37 @@ |
|
|
|
|
|
|
|
|
|
#include "yuv_to_rgb.h" |
|
|
|
|
|
|
|
|
|
// https://chromium.googlesource.com/libyuv/libyuv
|
|
|
|
|
// https://mymusing.co/bt601-yuv-to-rgb-conversion-color/
|
|
|
|
|
// https://www.color.org/chardata/rgb/rgb_registry.xalter
|
|
|
|
|
|
|
|
|
|
// BT.601 YUV to RGB
|
|
|
|
|
// R = 1.164 * (Y - 16) + 1.596 * (V - 128)
|
|
|
|
|
// G = 1.164 * (Y - 16) - 0.392 * (U - 128) - 0.812 * (V - 128)
|
|
|
|
|
// B = 1.164 * (Y - 16) + 2.016 * (U - 128)
|
|
|
|
|
|
|
|
|
|
// Y = 0.257 * R + 0.504 * G + 0.098 * B + 16
|
|
|
|
|
// U = -0.148 * R - 0.291 * G + 0.439 * B + 128
|
|
|
|
|
// V = 0.439 * R - 0.368 * G - 0.072 * B + 128
|
|
|
|
|
|
|
|
|
|
// BT.709 YUV to RGB
|
|
|
|
|
// R = 1.1644 * (Y - 16) + 1.7928 * (V - 128)
|
|
|
|
|
// G = 1.1644 * (Y - 16) - 0.2133 * (U - 128) - 0.533 * (V - 128)
|
|
|
|
|
// B = 1.1644 * (Y - 16) + 2.1124 * (U - 128)
|
|
|
|
|
|
|
|
|
|
// Y = 0.1826 * R + 0.6142 * G + 0.0620 * B + 16
|
|
|
|
|
// U = -0.1006 * R - 0.3386 * G + 0.4392 * B + 128
|
|
|
|
|
// V = 0.4392 * B - 0.3989 * G - 0.0403 * B + 128
|
|
|
|
|
|
|
|
|
|
// BT.2020 YUV to RGB
|
|
|
|
|
// R = Y - 16 + 1.4746 * (V - 128)
|
|
|
|
|
// G = Y - 16 - 0.1645 * (U - 128) - 0.5713 * (V - 128)
|
|
|
|
|
// B = Y - 16 + 1.881 * (U - 128)
|
|
|
|
|
|
|
|
|
|
// Y = 0.2627 * R + 0.6780 * G + 0.0593 * B + 16
|
|
|
|
|
// U = -0.1396 * R - 0.3604 * G + 0.5 * B + 128
|
|
|
|
|
// V = 0.5 * R - 0.4598 * G - 0.0402 * B + 128
|
|
|
|
|
|
|
|
|
|
static int range(int val) { |
|
|
|
|
if (val < 0) { |
|
|
|
|
return 0; |
|
|
|
|