Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: src/core/SkBitmapFilter.h

Issue 17381008: More general version of image filtering; reworked to be robust and easier to SSE (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkBitmapFilter.h
diff --git a/src/core/SkBitmapFilter.h b/src/core/SkBitmapFilter.h
new file mode 100644
index 0000000000000000000000000000000000000000..7ea60b81080b9e20e7a04ecce9338bd3d4d90264
--- /dev/null
+++ b/src/core/SkBitmapFilter.h
@@ -0,0 +1,111 @@
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkBitmapFilter_DEFINED
+#define SkBitmapFilter_DEFINED
+
+#include "SkMath.h"
+
+class SkBitmapFilter {
+ public:
+ SkBitmapFilter( float width )
+ : fWidth( width ), fInvWidth( 1.f/width ) {
+ }
+
+ float width() const { return fWidth; }
+ float invWidth() const { return fInvWidth; }
+ virtual float Evaluate( float x ) const = 0;
reed1 2013/06/18 20:21:21 non-static methods are lowerCamelCase
humper 2013/06/19 20:49:26 Done.
+ protected:
+ float fWidth;
+ float fInvWidth;
+};
+
+class SkMitchellFilter: public SkBitmapFilter {
+ public:
+ SkMitchellFilter( float b, float c, float width=2.0 )
+ : SkBitmapFilter( width ), B( b ), C( c ) {
+ }
+
+ virtual float Evaluate( float x ) const {
reed1 2013/06/18 20:21:21 SK_OVERRIDE
humper 2013/06/19 20:49:26 Done.
+ x = fabsf(x);
+ float ret;
+ if (x > 2.f) {
+ return 0;
+ } else if (x > 1.f) {
+ return ((-B - 6*C) * x*x*x + (6*B + 30*C) * x*x +
+ (-12*B - 48*C) * x + (8*B + 24*C)) * (1.f/6.f);
+ } else {
+ return ((12 - 9*B - 6*C) * x*x*x +
+ (-18 + 12*B + 6*C) * x*x +
+ (6 - 2*B)) * (1.f/6.f);
+ }
+ }
+ protected:
+ float B, C;
+};
+
+class SkGaussianFilter: public SkBitmapFilter {
+ public:
+ SkGaussianFilter( float a, float width=2.0 )
+ : SkBitmapFilter( width ), alpha(a), expWidth( expf(-alpha * width * width )) {
+ }
+
+ virtual float Evaluate( float x ) const {
+ return SkTMax(0.f, float(expf(-alpha*x*x) - expWidth));
+ }
+ protected:
+ float alpha, expWidth;
+};
+
+class SkTriangleFilter: public SkBitmapFilter {
+ public:
+ SkTriangleFilter( float width=1 )
+ : SkBitmapFilter( width ) {
+ }
+
+ virtual float Evaluate( float x ) const {
+ return SkTMax( 0.f, fWidth - fabsf(x) );
+ }
+ protected:
+};
+
+class SkBoxFilter: public SkBitmapFilter {
+ public:
+ SkBoxFilter( float width=.5 )
reed1 2013/06/18 20:21:21 need .5f to avoid warning
humper 2013/06/19 20:49:26 Done.
+ : SkBitmapFilter( width ) {
+ }
+
+ virtual float Evaluate( float x ) const {
+ return 1;
+ }
+ protected:
+};
+
+
+class SkSincFilter: public SkBitmapFilter {
+ public:
+ SkSincFilter( float t, float width=3 )
+ : SkBitmapFilter( width ), tau(t) {
+ }
+
+ virtual float Evaluate( float x ) const {
+ x = fabsf(x/fWidth);
reed1 2013/06/18 20:21:21 sk_float_abs
reed1 2013/06/18 20:21:21 x * fInvWidth
humper 2013/06/19 20:49:26 Done.
humper 2013/06/19 20:49:26 Done.
humper 2013/06/19 20:49:26 Done.
+ if (x < 1e-5) return 1.f;
reed1 2013/06/18 20:21:21 1e-5f for warning I think
humper 2013/06/19 20:49:26 Done.
+ if (x > 1.) return 0.f;
+ x *= M_PI;
+ float sinc = sinf(x) / x;
reed1 2013/06/18 20:21:21 sk_float_sin
humper 2013/06/19 20:49:26 Done.
+ float lanczos = sinf(x * tau) / (x * tau);
+ return sinc * lanczos;
+ }
+ protected:
+ float tau;
+};
+
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698