d053ce9c54
Reason for revert:
guard has now landed in chrome
Original issue's description:
> Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #3 id:40001 of https://codereview.chromium.org/1825073002/ )
>
> Reason for revert:
> CreateModeFilter not compiling
>
> Original issue's description:
> > Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.org/1822623002/ )"
> >
> > Fixed legacy withColorFilter to call new(er) make method
> >
> > This reverts commit 1eb81db650
.
> >
> > BUG=skia:
> > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1825073002
> >
> > TBR=
> >
> > Committed: https://skia.googlesource.com/skia/+/4c9776b046dd5e9e46e2d1ce35154855c8fcb381
>
> TBR=
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/d6889293dd0942f27f9593f679722c956831f2c4
TBR=
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:
Review URL: https://codereview.chromium.org/1827433002
102 lines
3.5 KiB
C++
102 lines
3.5 KiB
C++
/*
|
|
* Copyright 2015 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
|
|
#include "SkBitmap.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkColor.h"
|
|
#include "SkColorMatrixFilter.h"
|
|
#include "SkPaint.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
static inline void assert_color(skiatest::Reporter* reporter,
|
|
SkColor expected, SkColor actual, int tolerance) {
|
|
REPORTER_ASSERT(reporter, abs((int)(SkColorGetA(expected) - SkColorGetA(actual))) <= tolerance);
|
|
REPORTER_ASSERT(reporter, abs((int)(SkColorGetR(expected) - SkColorGetR(actual))) <= tolerance);
|
|
REPORTER_ASSERT(reporter, abs((int)(SkColorGetG(expected) - SkColorGetG(actual))) <= tolerance);
|
|
REPORTER_ASSERT(reporter, abs((int)(SkColorGetB(expected) - SkColorGetB(actual))) <= tolerance);
|
|
}
|
|
|
|
static inline void assert_color(skiatest::Reporter* reporter, SkColor expected, SkColor actual) {
|
|
const int TOLERANCE = 1;
|
|
assert_color(reporter, expected, actual, TOLERANCE);
|
|
}
|
|
|
|
/**
|
|
* This test case is a mirror of the Android CTS tests for MatrixColorFilter
|
|
* found in the android.graphics.ColorMatrixColorFilterTest class.
|
|
*/
|
|
static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
|
|
|
|
SkBitmap bitmap;
|
|
bitmap.allocN32Pixels(1,1);
|
|
|
|
SkCanvas canvas(bitmap);
|
|
SkPaint paint;
|
|
|
|
SkScalar 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(SkColorFilter::MakeMatrixFilterRowMajor255(blueToCyan));
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SK_ColorGREEN, bitmap.getColor(0, 0));
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SK_ColorRED, bitmap.getColor(0, 0));
|
|
|
|
// color components are clipped, not scaled
|
|
paint.setColor(SK_ColorMAGENTA);
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SK_ColorWHITE, bitmap.getColor(0, 0));
|
|
|
|
SkScalar 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.5f, 0.0f, 0.0f, 1.0f, 0.0f
|
|
};
|
|
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
|
|
bitmap.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SkColorSetARGB(128, 255, 0, 64), bitmap.getColor(0, 0), 2);
|
|
|
|
paint.setColor(SK_ColorCYAN);
|
|
canvas.drawPoint(0, 0, paint);
|
|
// blue gets clipped
|
|
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
|
|
|
|
// change array to filter out green
|
|
REPORTER_ASSERT(reporter, 1.0f == transparentRedAddBlue[6]);
|
|
transparentRedAddBlue[6] = 0.0f;
|
|
|
|
// check that changing the array has no effect
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
|
|
|
|
// create a new filter with the changed matrix
|
|
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
|
|
canvas.drawPoint(0, 0, paint);
|
|
assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0));
|
|
}
|
|
|
|
DEF_TEST(ColorMatrix, reporter) {
|
|
test_colorMatrixCTS(reporter);
|
|
}
|