Add SkColorMatrix factories for SkYUVColorSpace

This lets clients access and use the same RGB to YUV matrices that we
use internally.

Inspired by https://crrev.com/c/3223983

Bug: skia:12545
Change-Id: I7f70f56e721819c3d33da447eff2e572b7774c51
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/461476
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Osman 2021-10-20 10:15:46 -04:00 committed by SkCQ
parent 0edd2c33d3
commit cb3c02005c
3 changed files with 19 additions and 8 deletions

View File

@ -8,7 +8,7 @@
#ifndef SkColorMatrix_DEFINED
#define SkColorMatrix_DEFINED
#include "include/core/SkTypes.h"
#include "include/core/SkImageInfo.h"
#include <algorithm>
#include <array>
@ -29,6 +29,9 @@ public:
m20, m21, m22, m23, m24,
m30, m31, m32, m33, m34 } {}
static SkColorMatrix RGBtoYUV(SkYUVColorSpace);
static SkColorMatrix YUVtoRGB(SkYUVColorSpace);
void setIdentity();
void setScale(float rScale, float gScale, float bScale, float aScale = 1.0f);

View File

@ -6,6 +6,19 @@
*/
#include "include/effects/SkColorMatrix.h"
#include "src/core/SkYUVMath.h"
SkColorMatrix SkColorMatrix::RGBtoYUV(SkYUVColorSpace cs) {
SkColorMatrix m;
SkColorMatrix_RGB2YUV(cs, m.fMat.data());
return m;
}
SkColorMatrix SkColorMatrix::YUVtoRGB(SkYUVColorSpace cs) {
SkColorMatrix m;
SkColorMatrix_YUV2RGB(cs, m.fMat.data());
return m;
}
enum {
kR_Scale = 0,

View File

@ -145,13 +145,8 @@ DEF_TEST(YUVMath, reporter) {
const float tolerance = 1.0f/(1 << 18);
for (auto cs : spaces) {
float r2y[20], y2r[20];
SkColorMatrix_RGB2YUV(cs, r2y);
SkColorMatrix_YUV2RGB(cs, y2r);
SkColorMatrix r2ym, y2rm;
r2ym.setRowMajor(r2y);
y2rm.setRowMajor(y2r);
SkColorMatrix r2ym = SkColorMatrix::RGBtoYUV(cs),
y2rm = SkColorMatrix::YUVtoRGB(cs);
r2ym.postConcat(y2rm);
float tmp[20];