Bug 1210357 - Handle VP9 colorspace BT.709 r=mattwoodrow,bas.schouten
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gfxUtils.h"
|
||||
#include "GLBlitHelper.h"
|
||||
#include "GLContext.h"
|
||||
#include "GLScreenBuffer.h"
|
||||
@@ -59,6 +60,7 @@ GLBlitHelper::GLBlitHelper(GLContext* gl)
|
||||
, mSrcTexEGL(0)
|
||||
, mYTexScaleLoc(-1)
|
||||
, mCbCrTexScaleLoc(-1)
|
||||
, mYuvColorMatrixLoc(-1)
|
||||
, mTexWidth(0)
|
||||
, mTexHeight(0)
|
||||
, mCurYScale(1.0f)
|
||||
@@ -171,14 +173,24 @@ GLBlitHelper::InitTexQuadProgram(BlitType target)
|
||||
";
|
||||
#endif
|
||||
/* From Rec601:
|
||||
[R] [1.1643835616438356, 0.0, 1.5960267857142858] [ Y - 16]
|
||||
[G] = [1.1643835616438358, -0.3917622900949137, -0.8129676472377708] x [Cb - 128]
|
||||
[B] [1.1643835616438356, 2.017232142857143, 8.862867620416422e-17] [Cr - 128]
|
||||
[R] [1.1643835616438356, 0.0, 1.5960267857142858] [ Y - 16]
|
||||
[G] = [1.1643835616438358, -0.3917622900949137, -0.8129676472377708] x [Cb - 128]
|
||||
[B] [1.1643835616438356, 2.017232142857143, 8.862867620416422e-17] [Cr - 128]
|
||||
|
||||
For [0,1] instead of [0,255], and to 5 places:
|
||||
[R] [1.16438, 0.00000, 1.59603] [ Y - 0.06275]
|
||||
[R] [1.16438, 0.00000, 1.59603] [ Y - 0.06275]
|
||||
[G] = [1.16438, -0.39176, -0.81297] x [Cb - 0.50196]
|
||||
[B] [1.16438, 2.01723, 0.00000] [Cr - 0.50196]
|
||||
[B] [1.16438, 2.01723, 0.00000] [Cr - 0.50196]
|
||||
|
||||
From Rec709:
|
||||
[R] [1.1643835616438356, 4.2781193979771426e-17, 1.7927410714285714] [ Y - 16]
|
||||
[G] = [1.1643835616438358, -0.21324861427372963, -0.532909328559444] x [Cb - 128]
|
||||
[B] [1.1643835616438356, 2.1124017857142854, 0.0] [Cr - 128]
|
||||
|
||||
For [0,1] instead of [0,255], and to 5 places:
|
||||
[R] [1.16438, 0.00000, 1.79274] [ Y - 0.06275]
|
||||
[G] = [1.16438, -0.21325, -0.53291] x [Cb - 0.50196]
|
||||
[B] [1.16438, 2.11240, 0.00000] [Cr - 0.50196]
|
||||
*/
|
||||
const char kTexYUVPlanarBlit_FragShaderSource[] = "\
|
||||
#version 100 \n\
|
||||
@@ -191,17 +203,17 @@ GLBlitHelper::InitTexQuadProgram(BlitType target)
|
||||
uniform sampler2D uCrTexture; \n\
|
||||
uniform vec2 uYTexScale; \n\
|
||||
uniform vec2 uCbCrTexScale; \n\
|
||||
uniform mat3 uYuvColorMatrix; \n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
float y = texture2D(uYTexture, vTexCoord * uYTexScale).r; \n\
|
||||
float cb = texture2D(uCbTexture, vTexCoord * uCbCrTexScale).r; \n\
|
||||
float cr = texture2D(uCrTexture, vTexCoord * uCbCrTexScale).r; \n\
|
||||
y = (y - 0.06275) * 1.16438; \n\
|
||||
y = y - 0.06275; \n\
|
||||
cb = cb - 0.50196; \n\
|
||||
cr = cr - 0.50196; \n\
|
||||
gl_FragColor.r = y + cr * 1.59603; \n\
|
||||
gl_FragColor.g = y - 0.81297 * cr - 0.39176 * cb; \n\
|
||||
gl_FragColor.b = y + cb * 2.01723; \n\
|
||||
vec3 yuv = vec3(y, cb, cr); \n\
|
||||
gl_FragColor.rgb = uYuvColorMatrix * yuv; \n\
|
||||
gl_FragColor.a = 1.0; \n\
|
||||
} \n\
|
||||
";
|
||||
@@ -409,13 +421,15 @@ GLBlitHelper::InitTexQuadProgram(BlitType target)
|
||||
GLint texCb = mGL->fGetUniformLocation(program, "uCbTexture");
|
||||
GLint texCr = mGL->fGetUniformLocation(program, "uCrTexture");
|
||||
mYTexScaleLoc = mGL->fGetUniformLocation(program, "uYTexScale");
|
||||
mCbCrTexScaleLoc= mGL->fGetUniformLocation(program, "uCbCrTexScale");
|
||||
mCbCrTexScaleLoc = mGL->fGetUniformLocation(program, "uCbCrTexScale");
|
||||
mYuvColorMatrixLoc = mGL->fGetUniformLocation(program, "uYuvColorMatrix");
|
||||
|
||||
DebugOnly<bool> hasUniformLocations = texY != -1 &&
|
||||
texCb != -1 &&
|
||||
texCr != -1 &&
|
||||
mYTexScaleLoc != -1 &&
|
||||
mCbCrTexScaleLoc != -1;
|
||||
mCbCrTexScaleLoc != -1 &&
|
||||
mYuvColorMatrixLoc != -1;
|
||||
MOZ_ASSERT(hasUniformLocations, "uniforms not found");
|
||||
|
||||
mGL->fUniform1i(texY, Channel_Y);
|
||||
@@ -790,6 +804,9 @@ GLBlitHelper::BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage)
|
||||
mGL->fUniform2f(mCbCrTexScaleLoc, (float)yuvData->mCbCrSize.width/yuvData->mCbCrStride, 1.0f);
|
||||
}
|
||||
|
||||
float* yuvToRgb = gfxUtils::Get3x3YuvColorMatrix(yuvData->mYUVColorSpace);
|
||||
mGL->fUniformMatrix3fv(mYuvColorMatrixLoc, 1, 0, yuvToRgb);
|
||||
|
||||
mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
mGL->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
||||
|
||||
Reference in New Issue
Block a user