SkColorMatrix cleanup
Remove the RGB/YUV helpers (use SkYUVMath instead), along with the unused get20/set20. Change-Id: Id83467a1b7f33657869e0a933af75387a4e36a88 Bug: skia:9543 Change-Id: Id83467a1b7f33657869e0a933af75387a4e36a88 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/252188 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
parent
feac94f276
commit
e36d030016
@ -8,6 +8,9 @@ Milestone 80
|
||||
|
||||
<Insert new notes here- top is most recent.>
|
||||
|
||||
* Removed rotation and YUV support from SkColorMatrix
|
||||
https://review.skia.org/252188
|
||||
|
||||
* Added kBT2020_SkYUVColorSpace. This is BT.2020's YCbCr conversion (non-constant-luminance).
|
||||
https://review.skia.org/252160
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
|
||||
#define WIDTH 500
|
||||
#define HEIGHT 500
|
||||
#define HEIGHT 160
|
||||
|
||||
static void set_color_matrix(SkPaint* paint, const SkColorMatrix& matrix) {
|
||||
paint->setColorFilter(SkColorFilters::Matrix(matrix));
|
||||
@ -100,41 +100,25 @@ protected:
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 0, 0, &paint);
|
||||
|
||||
matrix.setRotate(SkColorMatrix::kR_Axis, 90);
|
||||
///////////////////////////////////////////////
|
||||
|
||||
matrix.setSaturation(0.0f);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 80, 0, &paint);
|
||||
|
||||
matrix.setRotate(SkColorMatrix::kG_Axis, 90);
|
||||
matrix.setSaturation(0.5f);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 160, 0, &paint);
|
||||
|
||||
matrix.setRotate(SkColorMatrix::kB_Axis, 90);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 240, 0, &paint);
|
||||
///////////////////////////////////////////////
|
||||
matrix.setSaturation(0.0f);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 0, 80, &paint);
|
||||
|
||||
matrix.setSaturation(0.5f);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 80, 80, &paint);
|
||||
|
||||
matrix.setSaturation(1.0f);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 160, 80, &paint);
|
||||
canvas->drawImage(bmps[i], 240, 0, &paint);
|
||||
|
||||
matrix.setSaturation(2.0f);
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 240, 80, &paint);
|
||||
///////////////////////////////////////////////
|
||||
matrix.setRGB2YUV();
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 0, 160, &paint);
|
||||
canvas->drawImage(bmps[i], 320, 0, &paint);
|
||||
|
||||
matrix.setYUV2RGB();
|
||||
set_color_matrix(&paint, matrix);
|
||||
canvas->drawImage(bmps[i], 80, 160, &paint);
|
||||
///////////////////////////////////////////////
|
||||
|
||||
// Move red into alpha, set color to white
|
||||
float data[20] = {
|
||||
@ -145,9 +129,9 @@ protected:
|
||||
};
|
||||
|
||||
set_array(&paint, data);
|
||||
canvas->drawImage(bmps[i], 160, 160, &paint);
|
||||
canvas->drawImage(bmps[i], 400, 0, &paint);
|
||||
///////////////////////////////////////////////
|
||||
canvas->translate(0, 240);
|
||||
canvas->translate(0, 80);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,30 +9,29 @@
|
||||
#define SkColorMatrix_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
#include <memory.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
class SK_API SkColorMatrix {
|
||||
public:
|
||||
constexpr SkColorMatrix() : SkColorMatrix(1, 0, 0, 0, 0,
|
||||
0, 1, 0, 0, 0,
|
||||
0, 0, 1, 0, 0,
|
||||
0, 0, 0, 1, 0) {}
|
||||
|
||||
constexpr SkColorMatrix(float m00, float m01, float m02, float m03, float m04,
|
||||
float m10, float m11, float m12, float m13, float m14,
|
||||
float m20, float m21, float m22, float m23, float m24,
|
||||
float m30, float m31, float m32, float m33, float m34)
|
||||
: fMat { m00, m01, m02, m03, m04,
|
||||
m10, m11, m12, m13, m14,
|
||||
m20, m21, m22, m23, m24,
|
||||
m30, m31, m32, m33, m34 } {}
|
||||
|
||||
void setIdentity();
|
||||
void setScale(float rScale, float gScale, float bScale, float aScale = 1.0f);
|
||||
|
||||
void setRowMajor(const float src[20]) {
|
||||
memcpy(fMat, src, sizeof(fMat));
|
||||
}
|
||||
|
||||
void getRowMajor(float dst[20]) const {
|
||||
memcpy(dst, fMat, sizeof(fMat));
|
||||
}
|
||||
|
||||
enum Axis {
|
||||
kR_Axis = 0,
|
||||
kG_Axis = 1,
|
||||
kB_Axis = 2
|
||||
};
|
||||
void setRotate(Axis, float degrees);
|
||||
void setSinCos(Axis, float sine, float cosine);
|
||||
void preRotate(Axis, float degrees);
|
||||
void postRotate(Axis, float degrees);
|
||||
void postTranslate(float dr, float dg, float db, float da);
|
||||
|
||||
void setConcat(const SkColorMatrix& a, const SkColorMatrix& b);
|
||||
@ -40,25 +39,12 @@ public:
|
||||
void postConcat(const SkColorMatrix& mat) { this->setConcat(mat, *this); }
|
||||
|
||||
void setSaturation(float sat);
|
||||
void setRGB2YUV();
|
||||
void setYUV2RGB();
|
||||
|
||||
bool operator==(const SkColorMatrix& other) const {
|
||||
return 0 == memcmp(fMat, other.fMat, sizeof(fMat));
|
||||
}
|
||||
|
||||
bool operator!=(const SkColorMatrix& other) const { return !((*this) == other); }
|
||||
|
||||
float* get20(float m[20]) const {
|
||||
memcpy(m, fMat, sizeof(fMat));
|
||||
return m;
|
||||
}
|
||||
void set20(const float m[20]) {
|
||||
memcpy(fMat, m, sizeof(fMat));
|
||||
}
|
||||
void setRowMajor(const float src[20]) { std::copy_n(src, 20, fMat.begin()); }
|
||||
void getRowMajor(float dst[20]) const { std::copy_n(fMat.begin(), 20, dst); }
|
||||
|
||||
private:
|
||||
float fMat[20];
|
||||
std::array<float, 20> fMat;
|
||||
|
||||
friend class SkColorFilters;
|
||||
};
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "modules/skottie/src/effects/Effects.h"
|
||||
|
||||
#include "include/effects/SkColorMatrix.h"
|
||||
#include "modules/skottie/src/SkottieAdapter.h"
|
||||
#include "modules/skottie/src/SkottieJson.h"
|
||||
#include "modules/skottie/src/SkottieValue.h"
|
||||
|
@ -82,10 +82,6 @@ public:
|
||||
gPaintProcs[i](&fPaint[i]);
|
||||
}
|
||||
|
||||
SkColorMatrix cm;
|
||||
cm.setRotate(SkColorMatrix::kG_Axis, 180);
|
||||
cm.setIdentity();
|
||||
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ sk_sp<SkColorFilter> SkColorFilters::Matrix(const float array[20]) {
|
||||
}
|
||||
|
||||
sk_sp<SkColorFilter> SkColorFilters::Matrix(const SkColorMatrix& cm) {
|
||||
return MakeMatrix(cm.fMat, SkColorFilter_Matrix::Domain::kRGBA);
|
||||
return MakeMatrix(cm.fMat.data(), SkColorFilter_Matrix::Domain::kRGBA);
|
||||
}
|
||||
|
||||
sk_sp<SkColorFilter> SkColorFilters::HSLAMatrix(const float array[20]) {
|
||||
|
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "include/effects/SkColorMatrix.h"
|
||||
#include "include/private/SkFloatingPoint.h"
|
||||
|
||||
enum {
|
||||
kR_Scale = 0,
|
||||
@ -46,17 +45,17 @@ static void set_concat(float result[20], const float outer[20], const float inne
|
||||
}
|
||||
|
||||
if (target != result) {
|
||||
memcpy(result, target, 20 * sizeof(float));
|
||||
std::copy_n(target, 20, result);
|
||||
}
|
||||
}
|
||||
|
||||
void SkColorMatrix::setIdentity() {
|
||||
memset(fMat, 0, sizeof(fMat));
|
||||
fMat.fill(0.0f);
|
||||
fMat[kR_Scale] = fMat[kG_Scale] = fMat[kB_Scale] = fMat[kA_Scale] = 1;
|
||||
}
|
||||
|
||||
void SkColorMatrix::setScale(float rScale, float gScale, float bScale, float aScale) {
|
||||
memset(fMat, 0, sizeof(fMat));
|
||||
fMat.fill(0.0f);
|
||||
fMat[kR_Scale] = rScale;
|
||||
fMat[kG_Scale] = gScale;
|
||||
fMat[kB_Scale] = bScale;
|
||||
@ -72,42 +71,8 @@ void SkColorMatrix::postTranslate(float dr, float dg, float db, float da) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkColorMatrix::setRotate(Axis axis, float degrees) {
|
||||
float r = sk_float_degrees_to_radians(degrees);
|
||||
this->setSinCos(axis, sk_float_sin(r), sk_float_cos(r));
|
||||
}
|
||||
|
||||
void SkColorMatrix::setSinCos(Axis axis, float sine, float cosine) {
|
||||
SkASSERT((unsigned)axis < 3);
|
||||
|
||||
static const uint8_t gRotateIndex[] = {
|
||||
6, 7, 11, 12,
|
||||
0, 10, 2, 12,
|
||||
0, 1, 5, 6,
|
||||
};
|
||||
const uint8_t* index = gRotateIndex + axis * 4;
|
||||
|
||||
this->setIdentity();
|
||||
fMat[index[0]] = cosine;
|
||||
fMat[index[1]] = sine;
|
||||
fMat[index[2]] = -sine;
|
||||
fMat[index[3]] = cosine;
|
||||
}
|
||||
|
||||
void SkColorMatrix::preRotate(Axis axis, float degrees) {
|
||||
SkColorMatrix tmp;
|
||||
tmp.setRotate(axis, degrees);
|
||||
this->preConcat(tmp);
|
||||
}
|
||||
|
||||
void SkColorMatrix::postRotate(Axis axis, float degrees) {
|
||||
SkColorMatrix tmp;
|
||||
tmp.setRotate(axis, degrees);
|
||||
this->postConcat(tmp);
|
||||
}
|
||||
|
||||
void SkColorMatrix::setConcat(const SkColorMatrix& matA, const SkColorMatrix& matB) {
|
||||
set_concat(fMat, matA.fMat, matB.fMat);
|
||||
set_concat(fMat.data(), matA.fMat.data(), matB.fMat.data());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -123,49 +88,14 @@ static const float kHueG = 0.715f;
|
||||
static const float kHueB = 0.072f;
|
||||
|
||||
void SkColorMatrix::setSaturation(float sat) {
|
||||
memset(fMat, 0, sizeof(fMat));
|
||||
fMat.fill(0.0f);
|
||||
|
||||
const float R = kHueR * (1 - sat);
|
||||
const float G = kHueG * (1 - sat);
|
||||
const float B = kHueB * (1 - sat);
|
||||
|
||||
setrow(fMat + 0, R + sat, G, B);
|
||||
setrow(fMat + 5, R, G + sat, B);
|
||||
setrow(fMat + 10, R, G, B + sat);
|
||||
fMat[kA_Scale] = 1;
|
||||
}
|
||||
|
||||
static const float kR2Y = 0.299f;
|
||||
static const float kG2Y = 0.587f;
|
||||
static const float kB2Y = 0.114f;
|
||||
|
||||
static const float kR2U = -0.16874f;
|
||||
static const float kG2U = -0.33126f;
|
||||
static const float kB2U = 0.5f;
|
||||
|
||||
static const float kR2V = 0.5f;
|
||||
static const float kG2V = -0.41869f;
|
||||
static const float kB2V = -0.08131f;
|
||||
|
||||
void SkColorMatrix::setRGB2YUV() {
|
||||
memset(fMat, 0, sizeof(fMat));
|
||||
|
||||
setrow(fMat + 0, kR2Y, kG2Y, kB2Y);
|
||||
setrow(fMat + 5, kR2U, kG2U, kB2U);
|
||||
setrow(fMat + 10, kR2V, kG2V, kB2V);
|
||||
fMat[kA_Scale] = 1;
|
||||
}
|
||||
|
||||
static const float kV2R = 1.402f;
|
||||
static const float kU2G = -0.34414f;
|
||||
static const float kV2G = -0.71414f;
|
||||
static const float kU2B = 1.772f;
|
||||
|
||||
void SkColorMatrix::setYUV2RGB() {
|
||||
memset(fMat, 0, sizeof(fMat));
|
||||
|
||||
setrow(fMat + 0, 1, 0, kV2R);
|
||||
setrow(fMat + 5, 1, kU2G, kV2G);
|
||||
setrow(fMat + 10, 1, kU2B, 0);
|
||||
setrow(fMat.data() + 0, R + sat, G, B);
|
||||
setrow(fMat.data() + 5, R, G + sat, B);
|
||||
setrow(fMat.data() + 10, R, G, B + sat);
|
||||
fMat[kA_Scale] = 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user