aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-06-19 02:50:05 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-19 02:50:18 +0000
commitab51d1b297e6ce19347c6f6cb86808e0495a86ff (patch)
treebebdf52754b1c60e7993758f4718e458d5fe4639
parent6b9cd051b4fc2ae83f69d8c0482b646e5a2d02f6 (diff)
Revert "remove unused TableMaskFilter"
This reverts commit d72b55b32cf6b3bf7b8d7b4c08045597652285cf. Reason for revert: used by android Original change's description: > remove unused TableMaskFilter > > will revert if its needed in android > > Bug: skia: > Change-Id: I2ef777d31de4bbed6556d013054083ff6ff2cb8c > Reviewed-on: https://skia-review.googlesource.com/20206 > Reviewed-by: Mike Reed <reed@google.com> > Commit-Queue: Mike Reed <reed@google.com> TBR=djsollen@google.com,reed@google.com,stani@google.com Change-Id: I8ea36a912496e12c9fbfb73587d11e002252e8b8 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/20212 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
-rw-r--r--gn/effects.gni2
-rw-r--r--include/effects/SkTableMaskFilter.h66
-rw-r--r--src/effects/SkTableMaskFilter.cpp145
3 files changed, 213 insertions, 0 deletions
diff --git a/gn/effects.gni b/gn/effects.gni
index 3c8ef914ca..9418e12dd0 100644
--- a/gn/effects.gni
+++ b/gn/effects.gni
@@ -55,6 +55,7 @@ skia_effects_sources = [
"$_src/effects/SkPictureImageFilter.cpp",
"$_src/effects/SkRRectsGaussianEdgeMaskFilter.cpp",
"$_src/effects/SkTableColorFilter.cpp",
+ "$_src/effects/SkTableMaskFilter.cpp",
"$_src/effects/SkTileImageFilter.cpp",
"$_src/effects/SkXfermodeImageFilter.cpp",
@@ -110,6 +111,7 @@ skia_effects_sources = [
"$_include/effects/SkPerlinNoiseShader.h",
"$_include/effects/SkRRectsGaussianEdgeMaskFilter.h",
"$_include/effects/SkTableColorFilter.h",
+ "$_include/effects/SkTableMaskFilter.h",
"$_include/effects/SkTileImageFilter.h",
"$_include/effects/SkXfermodeImageFilter.h",
]
diff --git a/include/effects/SkTableMaskFilter.h b/include/effects/SkTableMaskFilter.h
new file mode 100644
index 0000000000..f226dd1760
--- /dev/null
+++ b/include/effects/SkTableMaskFilter.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTableMaskFilter_DEFINED
+#define SkTableMaskFilter_DEFINED
+
+#include "SkMaskFilter.h"
+#include "SkScalar.h"
+
+/** \class SkTableMaskFilter
+
+ Applies a table lookup on each of the alpha values in the mask.
+ Helper methods create some common tables (e.g. gamma, clipping)
+ */
+class SK_API SkTableMaskFilter : public SkMaskFilter {
+public:
+ /** Utility that sets the gamma table
+ */
+ static void MakeGammaTable(uint8_t table[256], SkScalar gamma);
+
+ /** Utility that creates a clipping table: clamps values below min to 0
+ and above max to 255, and rescales the remaining into 0..255
+ */
+ static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max);
+
+ static SkMaskFilter* Create(const uint8_t table[256]) {
+ return new SkTableMaskFilter(table);
+ }
+
+ static SkMaskFilter* CreateGamma(SkScalar gamma) {
+ uint8_t table[256];
+ MakeGammaTable(table, gamma);
+ return new SkTableMaskFilter(table);
+ }
+
+ static SkMaskFilter* CreateClip(uint8_t min, uint8_t max) {
+ uint8_t table[256];
+ MakeClipTable(table, min, max);
+ return new SkTableMaskFilter(table);
+ }
+
+ SkMask::Format getFormat() const override;
+ bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*) const override;
+
+ SK_TO_STRING_OVERRIDE()
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTableMaskFilter)
+
+protected:
+ ~SkTableMaskFilter() override;
+
+ void flatten(SkWriteBuffer&) const override;
+
+private:
+ SkTableMaskFilter();
+ explicit SkTableMaskFilter(const uint8_t table[256]);
+
+ uint8_t fTable[256];
+
+ typedef SkMaskFilter INHERITED;
+};
+
+#endif
diff --git a/src/effects/SkTableMaskFilter.cpp b/src/effects/SkTableMaskFilter.cpp
new file mode 100644
index 0000000000..a3b4038a2f
--- /dev/null
+++ b/src/effects/SkTableMaskFilter.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "SkFixed.h"
+#include "SkReadBuffer.h"
+#include "SkString.h"
+#include "SkTableMaskFilter.h"
+#include "SkWriteBuffer.h"
+
+SkTableMaskFilter::SkTableMaskFilter() {
+ for (int i = 0; i < 256; i++) {
+ fTable[i] = i;
+ }
+}
+
+SkTableMaskFilter::SkTableMaskFilter(const uint8_t table[256]) {
+ memcpy(fTable, table, sizeof(fTable));
+}
+
+SkTableMaskFilter::~SkTableMaskFilter() {}
+
+bool SkTableMaskFilter::filterMask(SkMask* dst, const SkMask& src,
+ const SkMatrix&, SkIPoint* margin) const {
+ if (src.fFormat != SkMask::kA8_Format) {
+ return false;
+ }
+
+ dst->fBounds = src.fBounds;
+ dst->fRowBytes = SkAlign4(dst->fBounds.width());
+ dst->fFormat = SkMask::kA8_Format;
+ dst->fImage = nullptr;
+
+ if (src.fImage) {
+ dst->fImage = SkMask::AllocImage(dst->computeImageSize());
+
+ const uint8_t* srcP = src.fImage;
+ uint8_t* dstP = dst->fImage;
+ const uint8_t* table = fTable;
+ int dstWidth = dst->fBounds.width();
+ int extraZeros = dst->fRowBytes - dstWidth;
+
+ for (int y = dst->fBounds.height() - 1; y >= 0; --y) {
+ for (int x = dstWidth - 1; x >= 0; --x) {
+ dstP[x] = table[srcP[x]];
+ }
+ srcP += src.fRowBytes;
+ // we can't just inc dstP by rowbytes, because if it has any
+ // padding between its width and its rowbytes, we need to zero those
+ // so that the bitters can read those safely if that is faster for
+ // them
+ dstP += dstWidth;
+ for (int i = extraZeros - 1; i >= 0; --i) {
+ *dstP++ = 0;
+ }
+ }
+ }
+
+ if (margin) {
+ margin->set(0, 0);
+ }
+ return true;
+}
+
+SkMask::Format SkTableMaskFilter::getFormat() const {
+ return SkMask::kA8_Format;
+}
+
+void SkTableMaskFilter::flatten(SkWriteBuffer& wb) const {
+ wb.writeByteArray(fTable, 256);
+}
+
+sk_sp<SkFlattenable> SkTableMaskFilter::CreateProc(SkReadBuffer& buffer) {
+ uint8_t table[256];
+ if (!buffer.readByteArray(table, 256)) {
+ return nullptr;
+ }
+ return sk_sp<SkFlattenable>(Create(table));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+void SkTableMaskFilter::MakeGammaTable(uint8_t table[256], SkScalar gamma) {
+ const float dx = 1 / 255.0f;
+ const float g = SkScalarToFloat(gamma);
+
+ float x = 0;
+ for (int i = 0; i < 256; i++) {
+ // float ee = powf(x, g) * 255;
+ table[i] = SkTPin(sk_float_round2int(powf(x, g) * 255), 0, 255);
+ x += dx;
+ }
+}
+
+void SkTableMaskFilter::MakeClipTable(uint8_t table[256], uint8_t min,
+ uint8_t max) {
+ if (0 == max) {
+ max = 1;
+ }
+ if (min >= max) {
+ min = max - 1;
+ }
+ SkASSERT(min < max);
+
+ SkFixed scale = (1 << 16) * 255 / (max - min);
+ memset(table, 0, min + 1);
+ for (int i = min + 1; i < max; i++) {
+ int value = SkFixedRoundToInt(scale * (i - min));
+ SkASSERT(value <= 255);
+ table[i] = value;
+ }
+ memset(table + max, 255, 256 - max);
+
+#if 0
+ int j;
+ for (j = 0; j < 256; j++) {
+ if (table[j]) {
+ break;
+ }
+ }
+ SkDebugf("%d %d start [%d]", min, max, j);
+ for (; j < 256; j++) {
+ SkDebugf(" %d", table[j]);
+ }
+ SkDebugf("\n\n");
+#endif
+}
+
+#ifndef SK_IGNORE_TO_STRING
+void SkTableMaskFilter::toString(SkString* str) const {
+ str->append("SkTableMaskFilter: (");
+
+ str->append("table: ");
+ for (int i = 0; i < 255; ++i) {
+ str->appendf("%d, ", fTable[i]);
+ }
+ str->appendf("%d", fTable[255]);
+
+ str->append(")");
+}
+#endif