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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10 #ifndef SkBitmapFilter_DEFINED
11 #define SkBitmapFilter_DEFINED
12
13 #include "SkMath.h"
14
15 class SkBitmapFilter {
16 public:
17 SkBitmapFilter( float width )
18 : fWidth( width ), fInvWidth( 1.f/width ) {
19 }
20
21 float width() const { return fWidth; }
22 float invWidth() const { return fInvWidth; }
23 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.
24 protected:
25 float fWidth;
26 float fInvWidth;
27 };
28
29 class SkMitchellFilter: public SkBitmapFilter {
30 public:
31 SkMitchellFilter( float b, float c, float width=2.0 )
32 : SkBitmapFilter( width ), B( b ), C( c ) {
33 }
34
35 virtual float Evaluate( float x ) const {
reed1 2013/06/18 20:21:21 SK_OVERRIDE
humper 2013/06/19 20:49:26 Done.
36 x = fabsf(x);
37 float ret;
38 if (x > 2.f) {
39 return 0;
40 } else if (x > 1.f) {
41 return ((-B - 6*C) * x*x*x + (6*B + 30*C) * x*x +
42 (-12*B - 48*C) * x + (8*B + 24*C)) * (1.f/6.f);
43 } else {
44 return ((12 - 9*B - 6*C) * x*x*x +
45 (-18 + 12*B + 6*C) * x*x +
46 (6 - 2*B)) * (1.f/6.f);
47 }
48 }
49 protected:
50 float B, C;
51 };
52
53 class SkGaussianFilter: public SkBitmapFilter {
54 public:
55 SkGaussianFilter( float a, float width=2.0 )
56 : SkBitmapFilter( width ), alpha(a), expWidth( expf(-alpha * width * width )) {
57 }
58
59 virtual float Evaluate( float x ) const {
60 return SkTMax(0.f, float(expf(-alpha*x*x) - expWidth));
61 }
62 protected:
63 float alpha, expWidth;
64 };
65
66 class SkTriangleFilter: public SkBitmapFilter {
67 public:
68 SkTriangleFilter( float width=1 )
69 : SkBitmapFilter( width ) {
70 }
71
72 virtual float Evaluate( float x ) const {
73 return SkTMax( 0.f, fWidth - fabsf(x) );
74 }
75 protected:
76 };
77
78 class SkBoxFilter: public SkBitmapFilter {
79 public:
80 SkBoxFilter( float width=.5 )
reed1 2013/06/18 20:21:21 need .5f to avoid warning
humper 2013/06/19 20:49:26 Done.
81 : SkBitmapFilter( width ) {
82 }
83
84 virtual float Evaluate( float x ) const {
85 return 1;
86 }
87 protected:
88 };
89
90
91 class SkSincFilter: public SkBitmapFilter {
92 public:
93 SkSincFilter( float t, float width=3 )
94 : SkBitmapFilter( width ), tau(t) {
95 }
96
97 virtual float Evaluate( float x ) const {
98 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.
99 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.
100 if (x > 1.) return 0.f;
101 x *= M_PI;
102 float sinc = sinf(x) / x;
reed1 2013/06/18 20:21:21 sk_float_sin
humper 2013/06/19 20:49:26 Done.
103 float lanczos = sinf(x * tau) / (x * tau);
104 return sinc * lanczos;
105 }
106 protected:
107 float tau;
108 };
109
110
111 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698