aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkColorMatrixFilterRowMajor255.cpp21
-rw-r--r--src/core/SkColorMatrixFilterRowMajor255.h7
2 files changed, 22 insertions, 6 deletions
diff --git a/src/core/SkColorMatrixFilterRowMajor255.cpp b/src/core/SkColorMatrixFilterRowMajor255.cpp
index 6fdfa0b446..9106a279c0 100644
--- a/src/core/SkColorMatrixFilterRowMajor255.cpp
+++ b/src/core/SkColorMatrixFilterRowMajor255.cpp
@@ -32,10 +32,8 @@ static void transpose_to_pmorder(float dst[20], const float src[20]) {
}
}
-// src is [20] but some compilers won't accept __restrict__ on anything
-// but an raw pointer or reference
-void SkColorMatrixFilterRowMajor255::initState(const SkScalar* SK_RESTRICT src) {
- transpose_to_pmorder(fTranspose, src);
+void SkColorMatrixFilterRowMajor255::initState() {
+ transpose_to_pmorder(fTranspose, fMatrix);
const float* array = fMatrix;
@@ -55,7 +53,7 @@ void SkColorMatrixFilterRowMajor255::initState(const SkScalar* SK_RESTRICT src)
SkColorMatrixFilterRowMajor255::SkColorMatrixFilterRowMajor255(const SkScalar array[20]) {
memcpy(fMatrix, array, 20 * sizeof(SkScalar));
- this->initState(array);
+ this->initState();
}
uint32_t SkColorMatrixFilterRowMajor255::getFlags() const {
@@ -420,3 +418,16 @@ void SkColorMatrixFilterRowMajor255::toString(SkString* str) const {
SkColorFilter* SkColorFilter::CreateMatrixFilterRowMajor255(const SkScalar array[20]) {
return new SkColorMatrixFilterRowMajor255(array);
}
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkColorFilter* SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(const SkScalar row[5]) {
+ SkASSERT(row);
+ SkColorMatrixFilterRowMajor255* cf = new SkColorMatrixFilterRowMajor255();
+ static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't match");
+ for (int i = 0; i < 4; ++i) {
+ memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5);
+ }
+ cf->initState();
+ return cf;
+}
diff --git a/src/core/SkColorMatrixFilterRowMajor255.h b/src/core/SkColorMatrixFilterRowMajor255.h
index 453dd41bff..106d2bd882 100644
--- a/src/core/SkColorMatrixFilterRowMajor255.h
+++ b/src/core/SkColorMatrixFilterRowMajor255.h
@@ -14,6 +14,9 @@ class SK_API SkColorMatrixFilterRowMajor255 : public SkColorFilter {
public:
explicit SkColorMatrixFilterRowMajor255(const SkScalar array[20]);
+ /** Creates a color matrix filter that returns the same value in all four channels. */
+ static SkColorFilter* CreateSingleChannelOutput(const SkScalar row[5]);
+
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
void filterSpan4f(const SkPM4f src[], int count, SkPM4f[]) const override;
uint32_t getFlags() const override;
@@ -32,11 +35,13 @@ protected:
void flatten(SkWriteBuffer&) const override;
private:
+ SkColorMatrixFilterRowMajor255() {};
+
SkScalar fMatrix[20];
float fTranspose[20]; // for Sk4s
uint32_t fFlags;
- void initState(const SkScalar array[20]);
+ void initState();
typedef SkColorFilter INHERITED;
};