Commit feeeabcd authored by Fredrik Hubinette's avatar Fredrik Hubinette Committed by Commit Bot

Handle RGB video correctly.

Turns out that when a video is tagged as RGB,
they really mean that the Y channel contains green,
Cr contains red, and Cb contains blue.
(According to ISO 23001-8:2016)

Bug: 901664
Change-Id: I468327252389dc2468020f23a912129fdc55574a
Reviewed-on: https://chromium-review.googlesource.com/c/1321582Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Fredrik Hubinette <hubbe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607442}
parent 19a66a42
...@@ -188,7 +188,9 @@ gfx::ColorSpace VideoColorSpace::ToGfxColorSpace() const { ...@@ -188,7 +188,9 @@ gfx::ColorSpace VideoColorSpace::ToGfxColorSpace() const {
switch (matrix) { switch (matrix) {
case MatrixID::RGB: case MatrixID::RGB:
matrix_id = gfx::ColorSpace::MatrixID::RGB; // RGB-encoded video actually puts the green in the Y channel,
// the blue in the Cb (U) channel and the red in the Cr (V) channel.
matrix_id = gfx::ColorSpace::MatrixID::GBR;
break; break;
case MatrixID::BT709: case MatrixID::BT709:
matrix_id = gfx::ColorSpace::MatrixID::BT709; matrix_id = gfx::ColorSpace::MatrixID::BT709;
......
...@@ -375,6 +375,7 @@ std::string ColorSpace::ToString() const { ...@@ -375,6 +375,7 @@ std::string ColorSpace::ToString() const {
PRINT_ENUM_CASE(MatrixID, BT2020_NCL) PRINT_ENUM_CASE(MatrixID, BT2020_NCL)
PRINT_ENUM_CASE(MatrixID, BT2020_CL) PRINT_ENUM_CASE(MatrixID, BT2020_CL)
PRINT_ENUM_CASE(MatrixID, YDZDX) PRINT_ENUM_CASE(MatrixID, YDZDX)
PRINT_ENUM_CASE(MatrixID, GBR)
} }
ss << ", range:"; ss << ", range:";
switch (range_) { switch (range_) {
...@@ -883,6 +884,14 @@ void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const { ...@@ -883,6 +884,14 @@ void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const {
matrix->setRowMajorf(data); matrix->setRowMajorf(data);
return; return;
} }
case ColorSpace::MatrixID::GBR: {
float data[16] = {0.0f, 1.0f, 0.0f, 0.0f, // G
0.0f, 0.0f, 1.0f, 0.0f, // B
1.0f, 0.0f, 0.0f, 0.0f, // R
0.0f, 0.0f, 0.0f, 1.0f};
matrix->setRowMajorf(data);
return;
}
} }
float Kg = 1.0f - Kr - Kb; float Kg = 1.0f - Kr - Kb;
float u_m = 0.5f / (1.0f - Kb); float u_m = 0.5f / (1.0f - Kb);
...@@ -909,6 +918,7 @@ void ColorSpace::GetRangeAdjustMatrix(SkMatrix44* matrix) const { ...@@ -909,6 +918,7 @@ void ColorSpace::GetRangeAdjustMatrix(SkMatrix44* matrix) const {
} }
switch (matrix_) { switch (matrix_) {
case MatrixID::RGB: case MatrixID::RGB:
case MatrixID::GBR:
case MatrixID::INVALID: case MatrixID::INVALID:
case MatrixID::YCOCG: case MatrixID::YCOCG:
matrix->setScale(255.0f/219.0f, 255.0f/219.0f, 255.0f/219.0f); matrix->setScale(255.0f/219.0f, 255.0f/219.0f, 255.0f/219.0f);
......
...@@ -105,7 +105,8 @@ class COLOR_SPACE_EXPORT ColorSpace { ...@@ -105,7 +105,8 @@ class COLOR_SPACE_EXPORT ColorSpace {
BT2020_NCL, BT2020_NCL,
BT2020_CL, BT2020_CL,
YDZDX, YDZDX,
LAST = YDZDX, GBR,
LAST = GBR,
}; };
enum class RangeID : uint8_t { enum class RangeID : uint8_t {
......
...@@ -44,6 +44,7 @@ DXVA2_ExtendedFormat ColorSpaceWin::GetExtendedFormat( ...@@ -44,6 +44,7 @@ DXVA2_ExtendedFormat ColorSpaceWin::GetExtendedFormat(
break; break;
case gfx::ColorSpace::MatrixID::RGB: case gfx::ColorSpace::MatrixID::RGB:
case gfx::ColorSpace::MatrixID::GBR:
case gfx::ColorSpace::MatrixID::FCC: case gfx::ColorSpace::MatrixID::FCC:
case gfx::ColorSpace::MatrixID::YCOCG: case gfx::ColorSpace::MatrixID::YCOCG:
case gfx::ColorSpace::MatrixID::BT2020_NCL: case gfx::ColorSpace::MatrixID::BT2020_NCL:
...@@ -226,6 +227,7 @@ D3D11_VIDEO_PROCESSOR_COLOR_SPACE ColorSpaceWin::GetD3D11ColorSpace( ...@@ -226,6 +227,7 @@ D3D11_VIDEO_PROCESSOR_COLOR_SPACE ColorSpaceWin::GetD3D11ColorSpace(
case gfx::ColorSpace::MatrixID::SMPTE240M: case gfx::ColorSpace::MatrixID::SMPTE240M:
case gfx::ColorSpace::MatrixID::RGB: case gfx::ColorSpace::MatrixID::RGB:
case gfx::ColorSpace::MatrixID::GBR:
case gfx::ColorSpace::MatrixID::FCC: case gfx::ColorSpace::MatrixID::FCC:
case gfx::ColorSpace::MatrixID::YCOCG: case gfx::ColorSpace::MatrixID::YCOCG:
case gfx::ColorSpace::MatrixID::BT2020_NCL: case gfx::ColorSpace::MatrixID::BT2020_NCL:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment