stop calling legacy 255-biased colormatrix

... but keep the apis for now

Bug: skia:4872
Bug: skia:9012
Change-Id: I3a9b0c9194be6897c0e59b7edd972b7218168183
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/211343
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-04-30 12:18:54 -04:00 committed by Skia Commit-Bot
parent acde2d1d0d
commit e869a1ed96
22 changed files with 127 additions and 131 deletions

View File

@ -16,23 +16,22 @@
#define FILTER_HEIGHT_LARGE SkIntToScalar(256)
static sk_sp<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> input) {
SkScalar amount255 = amount * 255;
SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
0, 1, 0, 0, amount255,
0, 0, 1, 0, amount255,
0, 0, 0, 1, 0 };
sk_sp<SkColorFilter> filter(SkColorFilters::MatrixRowMajor255(matrix));
float matrix[20] = { 1, 0, 0, 0, amount,
0, 1, 0, 0, amount,
0, 0, 1, 0, amount,
0, 0, 0, 1, 0 };
sk_sp<SkColorFilter> filter(SkColorFilters::Matrix(matrix));
return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
}
static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
float matrix[20];
memset(matrix, 0, 20 * sizeof(float));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
sk_sp<SkColorFilter> filter(SkColorFilters::MatrixRowMajor255(matrix));
sk_sp<SkColorFilter> filter(SkColorFilters::Matrix(matrix));
return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
}

View File

@ -98,22 +98,21 @@ private:
};
static sk_sp<SkColorFilter> make_brightness(float amount) {
SkScalar amount255 = amount * 255;
SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
0, 1, 0, 0, amount255,
0, 0, 1, 0, amount255,
SkScalar matrix[20] = { 1, 0, 0, 0, amount,
0, 1, 0, 0, amount,
0, 0, 1, 0, amount,
0, 0, 0, 1, 0 };
return SkColorFilters::MatrixRowMajor255(matrix);
return SkColorFilters::Matrix(matrix);
}
static sk_sp<SkColorFilter> make_grayscale() {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
float matrix[20];
memset(matrix, 0, 20 * sizeof(float));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
return SkColorFilters::MatrixRowMajor255(matrix);
return SkColorFilters::Matrix(matrix);
}
class MatrixCollapseBench: public BaseImageFilterCollapseBench {

View File

@ -127,9 +127,9 @@ static sk_sp<SkColorFilter> make_fuzz_colorfilter(Fuzz* fuzz, int depth) {
return outer->makeComposed(std::move(inner));
}
case 3: {
SkScalar array[20];
float array[20];
fuzz->nextN(array, SK_ARRAY_COUNT(array));
return SkColorFilters::MatrixRowMajor255(array);
return SkColorFilters::Matrix(array);
}
case 4: {
SkColor mul, add;

View File

@ -26,12 +26,12 @@ static SkBitmap make_alpha_image(int w, int h) {
}
static sk_sp<SkColorFilter> make_color_filter() {
SkScalar colorMatrix[20] = {
float colorMatrix[20] = {
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 0.5, 0.5, 0,
0, 0, 0.5, 0.5, 0}; // mix G and A.
return SkColorFilters::MatrixRowMajor255(colorMatrix);
return SkColorFilters::Matrix(colorMatrix);
}
DEF_SIMPLE_GM(alpha_image, canvas, 256, 256) {

View File

@ -31,13 +31,13 @@ static sk_sp<SkShader> MakeLinear() {
}
static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
float matrix[20];
memset(matrix, 0, 20 * sizeof(float));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
sk_sp<SkColorFilter> filter(SkColorFilters::MatrixRowMajor255(matrix));
sk_sp<SkColorFilter> filter(SkColorFilters::Matrix(matrix));
return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
}

View File

@ -35,9 +35,9 @@ protected:
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 255.0f
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
paint.setColorFilter(SkColorFilters::MatrixRowMajor255(opaqueGrayMatrix));
paint.setColorFilter(SkColorFilters::Matrix(opaqueGrayMatrix));
canvas->drawBitmap(bitmap, 100.0f, 100.0f, &paint);
}

View File

@ -20,23 +20,22 @@
#define MARGIN SkIntToScalar(10)
static sk_sp<SkColorFilter> cf_make_brightness(float brightness) {
SkScalar amount255 = brightness * 255;
SkScalar matrix[20] = {
1, 0, 0, 0, amount255,
0, 1, 0, 0, amount255,
0, 0, 1, 0, amount255,
float matrix[20] = {
1, 0, 0, 0, brightness,
0, 1, 0, 0, brightness,
0, 0, 1, 0, brightness,
0, 0, 0, 1, 0 };
return SkColorFilters::MatrixRowMajor255(matrix);
return SkColorFilters::Matrix(matrix);
}
static sk_sp<SkColorFilter> cf_make_grayscale() {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
float matrix[20];
memset(matrix, 0, 20 * sizeof(float));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
return SkColorFilters::MatrixRowMajor255(matrix);
return SkColorFilters::Matrix(matrix);
}
static sk_sp<SkColorFilter> cf_make_colorize(SkColor color) {

View File

@ -17,8 +17,8 @@ static void set_color_matrix(SkPaint* paint, const SkColorMatrix& matrix) {
paint->setColorFilter(SkColorFilters::Matrix(matrix));
}
static void set_array(SkPaint* paint, const SkScalar array[]) {
paint->setColorFilter(SkColorFilters::MatrixRowMajor255(array));
static void set_array(SkPaint* paint, const float array[]) {
paint->setColorFilter(SkColorFilters::Matrix(array));
}
class ColorMatrixGM : public skiagm::GM {
@ -121,14 +121,12 @@ protected:
set_color_matrix(&paint, matrix);
canvas->drawImage(bmps[i], 80, 160, &paint);
SkScalar s1 = SK_Scalar1;
SkScalar s255 = SkIntToScalar(255);
// Move red into alpha, set color to white
SkScalar data[20] = {
0, 0, 0, 0, s255,
0, 0, 0, 0, s255,
0, 0, 0, 0, s255,
s1, 0, 0, 0, 0,
float data[20] = {
0, 0, 0, 0, 1,
0, 0, 0, 0, 1,
0, 0, 0, 0, 1,
1, 0, 0, 0, 0,
};
set_array(&paint, data);

View File

@ -11,11 +11,11 @@
// This GM renders correctly in 8888, but fails in PDF
DEF_SIMPLE_GM(fadefilter, canvas, 256, 256) {
SkScalar matrix[20] = { 1, 0, 0, 0, 128.0f,
0, 1, 0, 0, 128.0f,
0, 0, 1, 0, 128.0f,
0, 0, 0, 1, 0 };
sk_sp<SkColorFilter> colorFilter(SkColorFilters::MatrixRowMajor255(matrix));
float matrix[20] = { 1, 0, 0, 0, 0.5f,
0, 1, 0, 0, 0.5f,
0, 0, 1, 0, 0.5f,
0, 0, 0, 1, 0 };
sk_sp<SkColorFilter> colorFilter(SkColorFilters::Matrix(matrix));
SkPaint layerPaint;
layerPaint.setImageFilter(SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr));
canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint);

View File

@ -50,11 +50,11 @@ DEF_SIMPLE_GM(imagefilterscropexpand, canvas, 730, 650) {
// This color matrix saturates the green component but only partly increases the opacity.
// For the opaque checkerboard, the opacity boost doesn't matter but it does impact the
// area outside the checkerboard.
SkScalar matrix[20] = { 1, 0, 0, 0, 0,
0, 1, 0, 0, 255,
0, 0, 1, 0, 0,
0, 0, 0, 1, 32 };
sk_sp<SkColorFilter> cfAlphaTrans(SkColorFilters::MatrixRowMajor255(matrix));
float matrix[20] = { 1, 0, 0, 0, 0,
0, 1, 0, 0, 1,
0, 0, 1, 0, 0,
0, 0, 0, 1, 32.0f/255 };
sk_sp<SkColorFilter> cfAlphaTrans(SkColorFilters::Matrix(matrix));
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
SkScalar MARGIN = SkIntToScalar(12);

View File

@ -62,12 +62,12 @@ protected:
{
sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr));
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
0, SK_Scalar1, 0, 0, 0,
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, 0.5f, 0 };
float matrix[20] = { 1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 0.5f, 0 };
sk_sp<SkColorFilter> matrixFilter(SkColorFilters::MatrixRowMajor255(matrix));
sk_sp<SkColorFilter> matrixFilter(SkColorFilters::Matrix(matrix));
sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter),
std::move(morph)));
SkPaint paint;
@ -78,11 +78,11 @@ protected:
canvas->translate(SkIntToScalar(100), 0);
}
{
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
0, SK_Scalar1, 0, 0, 0,
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, 0.5f, 0 };
sk_sp<SkColorFilter> matrixCF(SkColorFilters::MatrixRowMajor255(matrix));
float matrix[20] = { 1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 0.5f, 0 };
sk_sp<SkColorFilter> matrixCF(SkColorFilters::Matrix(matrix));
sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF),
nullptr));
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f,

View File

@ -20,13 +20,13 @@
static sk_sp<SkColorFilter> yuv_to_rgb_colorfilter() {
static const float kJPEGConversionMatrix[20] = {
1.0f, 0.0f, 1.402f, 0.0f, -180.0f,
1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f,
1.0f, 1.772f, 0.0f, 0.0f, -227.6f,
1.0f, 0.0f, 1.402f, 0.0f, -180.0f/255,
1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f/255,
1.0f, 1.772f, 0.0f, 0.0f, -227.6f/255,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
};
return SkColorFilters::MatrixRowMajor255(kJPEGConversionMatrix);
return SkColorFilters::Matrix(kJPEGConversionMatrix);
}
namespace skiagm {

View File

@ -39,14 +39,14 @@ static sk_sp<SkColorFilter> MakeTintColorFilter(SkColor lo, SkColor hi) {
//
// The input luminance is stored in the alpha channel
// (and RGB are cleared -- see SkLumaColorFilter). Thus:
const SkScalar tint_matrix[] = {
0, 0, 0, (r_hi - r_lo) / 255.0f, SkIntToScalar(r_lo),
0, 0, 0, (g_hi - g_lo) / 255.0f, SkIntToScalar(g_lo),
0, 0, 0, (b_hi - b_lo) / 255.0f, SkIntToScalar(b_lo),
0, 0, 0, (a_hi - a_lo) / 255.0f, SkIntToScalar(a_lo),
const float tint_matrix[] = {
0, 0, 0, (r_hi - r_lo) / 255.0f, SkIntToScalar(r_lo) / 255.0f,
0, 0, 0, (g_hi - g_lo) / 255.0f, SkIntToScalar(g_lo) / 255.0f,
0, 0, 0, (b_hi - b_lo) / 255.0f, SkIntToScalar(b_lo) / 255.0f,
0, 0, 0, (a_hi - a_lo) / 255.0f, SkIntToScalar(a_lo) / 255.0f,
};
return SkColorFilters::MatrixRowMajor255(tint_matrix)
return SkColorFilters::Matrix(tint_matrix)
->makeComposed(SkLumaColorFilter::Make());
}

View File

@ -21,7 +21,7 @@ DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) {
0, 0, 1, 0, 0,
-1, 0, 0, 1, 0,
};
auto cf0 = SkColorFilters::MatrixRowMajor255(array);
auto cf0 = SkColorFilters::Matrix(array);
auto cf1 = SkColorFilters::LinearToSRGBGamma();
auto cf2 = SkColorFilters::SRGBToLinearGamma();

View File

@ -85,17 +85,17 @@ protected:
}
{
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
0, SK_Scalar1, 0, 0, 0,
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, SK_Scalar1, 0 };
float matrix[20] = { 1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0 };
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()),
SkIntToScalar(fBitmap->height()));
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
SkIntToScalar(fBitmap->height() * 2));
sk_sp<SkImageFilter> tile(SkTileImageFilter::Make(srcRect, dstRect, nullptr));
sk_sp<SkColorFilter> cf(SkColorFilters::MatrixRowMajor255(matrix));
sk_sp<SkColorFilter> cf(SkColorFilters::Matrix(matrix));
SkPaint paint;
paint.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), std::move(tile)));

View File

@ -784,13 +784,13 @@ static GrBackendTexture create_yuva_texture(GrGpu* gpu, const SkBitmap& bm,
static sk_sp<SkColorFilter> yuv_to_rgb_colorfilter() {
static const float kJPEGConversionMatrix[20] = {
1.0f, 0.0f, 1.402f, 0.0f, -180.0f,
1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f,
1.0f, 1.772f, 0.0f, 0.0f, -227.6f,
1.0f, 0.0f, 1.402f, 0.0f, -180.0f/255,
1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f/255,
1.0f, 1.772f, 0.0f, 0.0f, -227.6f/255,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
};
return SkColorFilters::MatrixRowMajor255(kJPEGConversionMatrix);
return SkColorFilters::Matrix(kJPEGConversionMatrix);
}
namespace skiagm {

View File

@ -140,14 +140,14 @@ sk_sp<SkColorFilter> Make2ColorGradient(const sk_sp<Color>& color0, const sk_sp<
//
// Composing these two, we get the total tint matrix:
const SkScalar tint_matrix[] = {
dR*SK_LUM_COEFF_R, dR*SK_LUM_COEFF_G, dR*SK_LUM_COEFF_B, 0, c0.fR * 255,
dG*SK_LUM_COEFF_R, dG*SK_LUM_COEFF_G, dG*SK_LUM_COEFF_B, 0, c0.fG * 255,
dB*SK_LUM_COEFF_R, dB*SK_LUM_COEFF_G, dB*SK_LUM_COEFF_B, 0, c0.fB * 255,
0, 0, 0, 1, 0,
const float tint_matrix[] = {
dR*SK_LUM_COEFF_R, dR*SK_LUM_COEFF_G, dR*SK_LUM_COEFF_B, 0, c0.fR,
dG*SK_LUM_COEFF_R, dG*SK_LUM_COEFF_G, dG*SK_LUM_COEFF_B, 0, c0.fG,
dB*SK_LUM_COEFF_R, dB*SK_LUM_COEFF_G, dB*SK_LUM_COEFF_B, 0, c0.fB,
0, 0, 0, 1, 0,
};
return SkColorFilters::MatrixRowMajor255(tint_matrix);
return SkColorFilters::Matrix(tint_matrix);
}
sk_sp<SkColorFilter> MakeNColorGradient(const std::vector<sk_sp<Color>>& colors) {
@ -191,7 +191,7 @@ sk_sp<SkColorFilter> MakeNColorGradient(const std::vector<sk_sp<Color>>& colors)
}
SkASSERT(span_start == 256);
const SkScalar luminance_matrix[] = {
const float luminance_matrix[] = {
SK_LUM_COEFF_R, SK_LUM_COEFF_G, SK_LUM_COEFF_B, 0, 0, // r' = L
SK_LUM_COEFF_R, SK_LUM_COEFF_G, SK_LUM_COEFF_B, 0, 0, // g' = L
SK_LUM_COEFF_R, SK_LUM_COEFF_G, SK_LUM_COEFF_B, 0, 0, // b' = L
@ -199,7 +199,7 @@ sk_sp<SkColorFilter> MakeNColorGradient(const std::vector<sk_sp<Color>>& colors)
};
return SkTableColorFilter::MakeARGB(nullptr, rTable, gTable, bTable)
->makeComposed(SkColorFilters::MatrixRowMajor255(luminance_matrix));
->makeComposed(SkColorFilters::Matrix(luminance_matrix));
}
} // namespace

View File

@ -16,7 +16,7 @@
#include "src/core/SkUtils.h"
#include "tools/Resources.h"
const SkScalar gMat[] = {
const float gMat[] = {
.3f, .6f, .1f, 0, 0,
.3f, .6f, .1f, 0, 0,
.3f, .6f, .1f, 0, 0,
@ -58,7 +58,7 @@ protected:
void onDrawContent(SkCanvas* canvas) override {
if (!fImg) {
fImg = GetResourceAsImage("images/mandrill_256.png");
fCF0 = SkColorFilters::MatrixRowMajor255(gMat);
fCF0 = SkColorFilters::Matrix(gMat);
fCF1 = SkColorFilters::Blend(0xFF44CC88, SkBlendMode::kScreen);
}

View File

@ -214,14 +214,14 @@ public:
blit.setFilterQuality(scale > 1.f ? kNone_SkFilterQuality : kMedium_SkFilterQuality);
if (debugMode) {
// Makes anything that's > 1/255 alpha fully opaque and sets color to medium green.
static constexpr SkScalar kFilter[] = {
0.f, 0.f, 0.f, 0.f, 16.f,
0.f, 0.f, 0.f, 0.f, 200.f,
0.f, 0.f, 0.f, 0.f, 16.f,
static constexpr float kFilter[] = {
0.f, 0.f, 0.f, 0.f, 16.f/255,
0.f, 0.f, 0.f, 0.f, 200.f/255,
0.f, 0.f, 0.f, 0.f, 16.f/255,
0.f, 0.f, 0.f, 255.f, 0.f
};
blit.setColorFilter(SkColorFilters::MatrixRowMajor255(kFilter));
blit.setColorFilter(SkColorFilters::Matrix(kFilter));
}
canvas->scale(scale, scale);

View File

@ -34,12 +34,12 @@ SkOverdrawCanvas::SkOverdrawCanvas(SkCanvas* canvas)
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f/255,
};
fPaint.setAntiAlias(false);
fPaint.setBlendMode(SkBlendMode::kPlus);
fPaint.setColorFilter(SkColorFilters::MatrixRowMajor255(kIncrementAlpha));
fPaint.setColorFilter(SkColorFilters::Matrix(kIncrementAlpha));
}
namespace {

View File

@ -42,12 +42,12 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
SkCanvas canvas(bitmap);
SkPaint paint;
SkScalar blueToCyan[20] = {
float blueToCyan[20] = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f };
paint.setColorFilter(SkColorFilters::MatrixRowMajor255(blueToCyan));
paint.setColorFilter(SkColorFilters::Matrix(blueToCyan));
paint.setColor(SK_ColorBLUE);
canvas.drawPoint(0, 0, paint);
@ -66,13 +66,13 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorWHITE, bitmap.getColor(0, 0));
SkScalar transparentRedAddBlue[20] = {
float transparentRedAddBlue[20] = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 64.0f,
0.0f, 0.0f, 1.0f, 0.0f, 64.0f/255,
-0.5f, 0.0f, 0.0f, 1.0f, 0.0f
};
paint.setColorFilter(SkColorFilters::MatrixRowMajor255(transparentRedAddBlue));
paint.setColorFilter(SkColorFilters::Matrix(transparentRedAddBlue));
bitmap.eraseColor(SK_ColorTRANSPARENT);
paint.setColor(SK_ColorRED);
@ -93,7 +93,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
// create a new filter with the changed matrix
paint.setColorFilter(SkColorFilters::MatrixRowMajor255(transparentRedAddBlue));
paint.setColorFilter(SkColorFilters::Matrix(transparentRedAddBlue));
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0));
}
@ -107,13 +107,13 @@ DEF_TEST(ColorMatrix_clamp_while_unpremul, r) {
// This matrix does green += 255/255 and alpha += 32/255. We want to test
// that if we pass it opaque alpha and small red and blue values, red and
// blue stay unchanged, not pumped up by that ~1.12 intermediate alpha.
SkScalar m[] = {
float m[] = {
1, 0, 0, 0, 0,
0, 1, 0, 0, 255,
0, 1, 0, 0, 1,
0, 0, 1, 0, 0,
0, 0, 0, 1, 32,
0, 0, 0, 1, 32.0f/255,
};
auto filter = SkColorFilters::MatrixRowMajor255(m);
auto filter = SkColorFilters::Matrix(m);
SkColor filtered = filter->filterColor(0xff0a0b0c);
REPORTER_ASSERT(r, SkColorGetA(filtered) == 0xff);

View File

@ -339,24 +339,24 @@ static sk_sp<SkImage> make_small_image() {
}
static sk_sp<SkImageFilter> make_scale(float amount, sk_sp<SkImageFilter> input) {
SkScalar s = amount;
SkScalar matrix[20] = { s, 0, 0, 0, 0,
0, s, 0, 0, 0,
0, 0, s, 0, 0,
0, 0, 0, s, 0 };
sk_sp<SkColorFilter> filter(SkColorFilters::MatrixRowMajor255(matrix));
float s = amount;
float matrix[20] = { s, 0, 0, 0, 0,
0, s, 0, 0, 0,
0, 0, s, 0, 0,
0, 0, 0, s, 0 };
sk_sp<SkColorFilter> filter(SkColorFilters::Matrix(matrix));
return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
}
static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input,
const SkImageFilter::CropRect* cropRect) {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
float matrix[20];
memset(matrix, 0, 20 * sizeof(float));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
sk_sp<SkColorFilter> filter(SkColorFilters::MatrixRowMajor255(matrix));
sk_sp<SkColorFilter> filter(SkColorFilters::Matrix(matrix));
return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
}
@ -454,14 +454,14 @@ DEF_TEST(ImageFilter, reporter) {
{
// Check that two non-commutative matrices are concatenated in
// the correct order.
SkScalar blueToRedMatrix[20] = { 0 };
blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
SkScalar redToGreenMatrix[20] = { 0 };
redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
sk_sp<SkColorFilter> blueToRed(SkColorFilters::MatrixRowMajor255(blueToRedMatrix));
float blueToRedMatrix[20] = { 0 };
blueToRedMatrix[2] = blueToRedMatrix[18] = 1;
float redToGreenMatrix[20] = { 0 };
redToGreenMatrix[5] = redToGreenMatrix[18] = 1;
sk_sp<SkColorFilter> blueToRed(SkColorFilters::Matrix(blueToRedMatrix));
sk_sp<SkImageFilter> filter1(SkColorFilterImageFilter::Make(std::move(blueToRed),
nullptr));
sk_sp<SkColorFilter> redToGreen(SkColorFilters::MatrixRowMajor255(redToGreenMatrix));
sk_sp<SkColorFilter> redToGreen(SkColorFilters::Matrix(redToGreenMatrix));
sk_sp<SkImageFilter> filter2(SkColorFilterImageFilter::Make(std::move(redToGreen),
std::move(filter1)));
@ -1557,11 +1557,12 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
}
{
SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0,
0, 0, 0, 0, 1,
0, 0, 0, 0, 0,
0, 0, 0, 0, 1 };
sk_sp<SkColorFilter> greenCF(SkColorFilters::MatrixRowMajor255(greenMatrix));
float greenMatrix[20] = { 0, 0, 0, 0, 0,
0, 0, 0, 0, 1.0f/255,
0, 0, 0, 0, 0,
0, 0, 0, 0, 1.0f/255
};
sk_sp<SkColorFilter> greenCF(SkColorFilters::Matrix(greenMatrix));
sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(greenCF, nullptr));
REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());