mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-24 16:17:29 +09:00
Issue #2118 - Part 1: Update gfxUtils YuvColorMatrix functions to match upstream mozilla code more closely.
https://hg.mozilla.org/mozilla-central/file/4fba5295dc19f9d2f5d065ba502a44d8f2dc9e85/gfx/thebes/gfxUtils.cpp#l1246
This commit is contained in:
parent
55100bb28e
commit
beef437602
6 changed files with 48 additions and 54 deletions
|
|
@ -667,7 +667,7 @@ GLBlitHelper::BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage)
|
||||||
mGL->fUniform2f(mCbCrTexScaleLoc, (float)yuvData->mCbCrSize.width/yuvData->mCbCrStride, 1.0f);
|
mGL->fUniform2f(mCbCrTexScaleLoc, (float)yuvData->mCbCrSize.width/yuvData->mCbCrStride, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float* yuvToRgb = gfxUtils::Get3x3YuvColorMatrix(yuvData->mYUVColorSpace);
|
const float* yuvToRgb = gfxUtils::Get3x3YuvColorMatrix(yuvData->mYUVColorSpace);
|
||||||
mGL->fUniformMatrix3fv(mYuvColorMatrixLoc, 1, 0, yuvToRgb);
|
mGL->fUniformMatrix3fv(mYuvColorMatrixLoc, 1, 0, yuvToRgb);
|
||||||
|
|
||||||
mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
|
||||||
|
|
@ -886,7 +886,7 @@ CompositorD3D11::DrawQuad(const gfx::Rect& aRect,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float* yuvToRgb = gfxUtils::Get4x3YuvColorMatrix(ycbcrEffect->mYUVColorSpace);
|
const float* yuvToRgb = gfxUtils::Get4x3YuvColorMatrix(ycbcrEffect->mYUVColorSpace);
|
||||||
memcpy(&mPSConstants.yuvColorMatrix, yuvToRgb, sizeof(mPSConstants.yuvColorMatrix));
|
memcpy(&mPSConstants.yuvColorMatrix, yuvToRgb, sizeof(mPSConstants.yuvColorMatrix));
|
||||||
|
|
||||||
TextureSourceD3D11* sourceY = source->GetSubSource(Y)->AsSourceD3D11();
|
TextureSourceD3D11* sourceY = source->GetSubSource(Y)->AsSourceD3D11();
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ CompositorD3D9::DrawQuad(const gfx::Rect &aRect,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float* yuvToRgb = gfxUtils::Get4x3YuvColorMatrix(ycbcrEffect->mYUVColorSpace);
|
const float* yuvToRgb = gfxUtils::Get4x3YuvColorMatrix(ycbcrEffect->mYUVColorSpace);
|
||||||
d3d9Device->SetPixelShaderConstantF(CBmYuvColorMatrix, yuvToRgb, 3);
|
d3d9Device->SetPixelShaderConstantF(CBmYuvColorMatrix, yuvToRgb, 3);
|
||||||
|
|
||||||
TextureSourceD3D9* sourceY = source->GetSubSource(Y)->AsSourceD3D9();
|
TextureSourceD3D9* sourceY = source->GetSubSource(Y)->AsSourceD3D9();
|
||||||
|
|
|
||||||
|
|
@ -966,7 +966,7 @@ ShaderProgramOGL::SetBlurRadius(float aRX, float aRY)
|
||||||
void
|
void
|
||||||
ShaderProgramOGL::SetYUVColorSpace(YUVColorSpace aYUVColorSpace)
|
ShaderProgramOGL::SetYUVColorSpace(YUVColorSpace aYUVColorSpace)
|
||||||
{
|
{
|
||||||
float* yuvToRgb = gfxUtils::Get3x3YuvColorMatrix(aYUVColorSpace);
|
const float* yuvToRgb = gfxUtils::Get3x3YuvColorMatrix(aYUVColorSpace);
|
||||||
SetMatrix3fvUniform(KnownUniform::YuvColorMatrix, yuvToRgb);
|
SetMatrix3fvUniform(KnownUniform::YuvColorMatrix, yuvToRgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1082,61 +1082,55 @@ gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||||
aBinaryOrData, aFile, nullptr);
|
aBinaryOrData, aFile, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* From Rec601:
|
// https://jdashg.github.io/misc/colors/from-coeffs.html
|
||||||
[R] [1.1643835616438356, 0.0, 1.5960267857142858] [ Y - 16]
|
const float kBT601NarrowYCbCrToRGB_RowMajor[16] = {
|
||||||
[G] = [1.1643835616438358, -0.3917622900949137, -0.8129676472377708] x [Cb - 128]
|
1.16438f, 0.00000f, 1.59603f, -0.87420f, 1.16438f, -0.39176f,
|
||||||
[B] [1.1643835616438356, 2.017232142857143, 8.862867620416422e-17] [Cr - 128]
|
-0.81297f, 0.53167f, 1.16438f, 2.01723f, 0.00000f, -1.08563f,
|
||||||
|
0.00000f, 0.00000f, 0.00000f, 1.00000f};
|
||||||
|
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};
|
||||||
|
|
||||||
For [0,1] instead of [0,255], and to 5 places:
|
/* static */ const float*
|
||||||
[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]
|
|
||||||
|
|
||||||
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]
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* static */ float*
|
|
||||||
gfxUtils::Get4x3YuvColorMatrix(YUVColorSpace aYUVColorSpace)
|
gfxUtils::Get4x3YuvColorMatrix(YUVColorSpace aYUVColorSpace)
|
||||||
{
|
{
|
||||||
static const float yuv_to_rgb_rec601[12] = { 1.16438f, 0.0f, 1.59603f, 0.0f,
|
#define X(x) \
|
||||||
1.16438f, -0.39176f, -0.81297f, 0.0f,
|
{ x[0], x[1], x[2], 0.0f, x[4], x[5], x[6], 0.0f, x[8], x[9], x[10], 0.0f }
|
||||||
1.16438f, 2.01723f, 0.0f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const float yuv_to_rgb_rec709[12] = { 1.16438f, 0.0f, 1.79274f, 0.0f,
|
static const float rec601[12] = X(kBT601NarrowYCbCrToRGB_RowMajor);
|
||||||
1.16438f, -0.21325f, -0.53291f, 0.0f,
|
static const float rec709[12] = X(kBT709NarrowYCbCrToRGB_RowMajor);
|
||||||
1.16438f, 2.11240f, 0.0f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (aYUVColorSpace == YUVColorSpace::BT709) {
|
#undef X
|
||||||
return const_cast<float*>(yuv_to_rgb_rec709);
|
|
||||||
} else {
|
switch (aYUVColorSpace) {
|
||||||
return const_cast<float*>(yuv_to_rgb_rec601);
|
case YUVColorSpace::BT601:
|
||||||
|
return rec601;
|
||||||
|
case YUVColorSpace::BT709:
|
||||||
|
return rec709;
|
||||||
|
default:
|
||||||
|
MOZ_CRASH("Bad YUVColorSpace");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ float*
|
/* static */ const float*
|
||||||
gfxUtils::Get3x3YuvColorMatrix(YUVColorSpace aYUVColorSpace)
|
gfxUtils::Get3x3YuvColorMatrix(YUVColorSpace aYUVColorSpace)
|
||||||
{
|
{
|
||||||
static const float yuv_to_rgb_rec601[9] = {
|
#define X(x) \
|
||||||
1.16438f, 1.16438f, 1.16438f, 0.0f, -0.39176f, 2.01723f, 1.59603f, -0.81297f, 0.0f,
|
{ x[0], x[4], x[8], x[1], x[5], x[9], x[2], x[6], x[10] }
|
||||||
};
|
|
||||||
static const float yuv_to_rgb_rec709[9] = {
|
|
||||||
1.16438f, 1.16438f, 1.16438f, 0.0f, -0.21325f, 2.11240f, 1.79274f, -0.53291f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (aYUVColorSpace == YUVColorSpace::BT709) {
|
static const float rec601[9] = X(kBT601NarrowYCbCrToRGB_RowMajor);
|
||||||
return const_cast<float*>(yuv_to_rgb_rec709);
|
static const float rec709[9] = X(kBT709NarrowYCbCrToRGB_RowMajor);
|
||||||
} else {
|
|
||||||
return const_cast<float*>(yuv_to_rgb_rec601);
|
#undef X
|
||||||
|
|
||||||
|
switch (aYUVColorSpace) {
|
||||||
|
case YUVColorSpace::BT601:
|
||||||
|
return rec601;
|
||||||
|
case YUVColorSpace::BT709:
|
||||||
|
return rec709;
|
||||||
|
default:
|
||||||
|
MOZ_CRASH("Bad YUVColorSpace");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get array of yuv to rgb conversion matrix.
|
* Get array of yuv to rgb conversion matrix.
|
||||||
*/
|
*/
|
||||||
static float* Get4x3YuvColorMatrix(YUVColorSpace aYUVColorSpace);
|
static const float* Get4x3YuvColorMatrix(YUVColorSpace aYUVColorSpace);
|
||||||
|
|
||||||
static float* Get3x3YuvColorMatrix(YUVColorSpace aYUVColorSpace);
|
static const float* Get3x3YuvColorMatrix(YUVColorSpace aYUVColorSpace);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a copy of aSurface, but having the SurfaceFormat aFormat.
|
* Creates a copy of aSurface, but having the SurfaceFormat aFormat.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue