Bug 1493898 - P1. Add preliminary BT2020 colorspace support. r=mattwoodrow

Only active with webrender and AL.

Differential Revision: https://phabricator.services.mozilla.com/D25342

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2019-04-11 12:40:40 +00:00
Родитель 856169370c
Коммит c6e2001c75
5 изменённых файлов: 36 добавлений и 2 удалений

Просмотреть файл

@ -104,6 +104,7 @@ enum class StereoMode {
enum class YUVColorSpace {
BT601,
BT709,
BT2020,
// This represents the unknown format.
UNKNOWN,
};

Просмотреть файл

@ -1095,6 +1095,10 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
1.16438f, 0.00000f, 1.79274f, -0.97295f, 1.16438f, -0.21325f,
-0.53291f, 0.30148f, 1.16438f, 2.11240f, 0.00000f, -1.13340f,
0.00000f, 0.00000f, 0.00000f, 1.00000f};
const float kBT2020NarrowYCbCrToRGB_RowMajor[16] = {
1.16438f, 0.00000f, 1.67867f, -0.91569f, 1.16438f, -0.18733f,
-0.65042f, 0.34746f, 1.16438f, 2.14177f, 0.00000f, -1.14815f,
0.00000f, 0.00000f, 0.00000f, 1.00000f};
/* static */ const float* gfxUtils::YuvToRgbMatrix4x3RowMajor(
YUVColorSpace aYUVColorSpace) {
@ -1103,6 +1107,7 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
static const float rec601[12] = X(kBT601NarrowYCbCrToRGB_RowMajor);
static const float rec709[12] = X(kBT709NarrowYCbCrToRGB_RowMajor);
static const float rec2020[12] = X(kBT2020NarrowYCbCrToRGB_RowMajor);
#undef X
@ -1111,6 +1116,8 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
return rec601;
case YUVColorSpace::BT709:
return rec709;
case YUVColorSpace::BT2020:
return rec2020;
default: // YUVColorSpace::UNKNOWN
MOZ_ASSERT(false, "unknown aYUVColorSpace");
return rec601;
@ -1124,6 +1131,7 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
static const float rec601[9] = X(kBT601NarrowYCbCrToRGB_RowMajor);
static const float rec709[9] = X(kBT709NarrowYCbCrToRGB_RowMajor);
static const float rec2020[9] = X(kBT2020NarrowYCbCrToRGB_RowMajor);
#undef X
@ -1132,6 +1140,8 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
return rec601;
case YUVColorSpace::BT709:
return rec709;
case YUVColorSpace::BT2020:
return rec2020;
default: // YUVColorSpace::UNKNOWN
MOZ_ASSERT(false, "unknown aYUVColorSpace");
return rec601;
@ -1148,6 +1158,7 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
static const float rec601[16] = X(kBT601NarrowYCbCrToRGB_RowMajor);
static const float rec709[16] = X(kBT709NarrowYCbCrToRGB_RowMajor);
static const float rec2020[16] = X(kBT2020NarrowYCbCrToRGB_RowMajor);
#undef X
@ -1156,6 +1167,8 @@ const float kBT709NarrowYCbCrToRGB_RowMajor[16] = {
return rec601;
case YUVColorSpace::BT709:
return rec709;
case YUVColorSpace::BT2020:
return rec2020;
default: // YUVColorSpace::UNKNOWN
MOZ_ASSERT(false, "unknown aYUVColorSpace");
return rec601;

Просмотреть файл

@ -878,6 +878,8 @@ static inline wr::WrYuvColorSpace ToWrYuvColorSpace(
return wr::WrYuvColorSpace::Rec601;
case YUVColorSpace::BT709:
return wr::WrYuvColorSpace::Rec709;
case YUVColorSpace::BT2020:
return wr::WrYuvColorSpace::Rec2020;
default:
MOZ_ASSERT_UNREACHABLE("Tried to convert invalid YUVColorSpace.");
}

Просмотреть файл

@ -13,6 +13,7 @@
#define YUV_COLOR_SPACE_REC601 0
#define YUV_COLOR_SPACE_REC709 1
#define YUV_COLOR_SPACE_REC2020 2
#define YUV_FORMAT_NV12 0
#define YUV_FORMAT_PLANAR 1
@ -59,7 +60,7 @@ const mat3 YuvColorMatrixRec601 = mat3(
);
// From Rec709:
// [R] [1.1643835616438356, 4.2781193979771426e-17, 1.7927410714285714] [Y - 16]
// [R] [1.1643835616438356, 0.0, 1.7927410714285714] [Y - 16]
// [G] = [1.1643835616438358, -0.21324861427372963, -0.532909328559444 ] x [U - 128]
// [B] [1.1643835616438356, 2.1124017857142854, 0.0 ] [V - 128]
//
@ -72,6 +73,20 @@ const mat3 YuvColorMatrixRec709 = mat3(
1.79274, -0.53291, 0.0
);
// From Re2020:
// [R] [1.16438356164384, 0.0, 1.678674107142860 ] [Y - 16]
// [G] = [1.16438356164384, -0.187326104219343, -0.650424318505057 ] x [U - 128]
// [B] [1.16438356164384, 2.14177232142857, 0.0 ] [V - 128]
//
// For the range [0,1] instead of [0,255]:
//
// The matrix is stored in column-major.
const mat3 YuvColorMatrixRec2020 = mat3(
1.16438356164384 , 1.164383561643840, 1.16438356164384,
0.0 , -0.187326104219343, 2.14177232142857,
1.67867410714286 , -0.650424318505057, 0.0
);
void write_uv_rect(
int resource_id,
vec2 f,
@ -124,8 +139,10 @@ void brush_vs(
if (prim.color_space == YUV_COLOR_SPACE_REC601) {
vYuvColorMatrix = YuvColorMatrixRec601;
} else {
} else if (prim.color_space == YUV_COLOR_SPACE_REC709) {
vYuvColorMatrix = YuvColorMatrixRec709;
} else {
vYuvColorMatrix = YuvColorMatrixRec2020;
}
vFormat = prim.yuv_format;

Просмотреть файл

@ -805,6 +805,7 @@ pub struct YuvImageDisplayItem {
pub enum YuvColorSpace {
Rec601 = 0,
Rec709 = 1,
Rec2020 = 2,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]