• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef _SkTestImageFilters_h
3 #define _SkTestImageFilters_h
4 
5 #include "SkImageFilter.h"
6 #include "SkColorFilter.h"
7 
8 class SkOffsetImageFilter : public SkImageFilter {
9 public:
SkOffsetImageFilter(SkScalar dx,SkScalar dy)10     SkOffsetImageFilter(SkScalar dx, SkScalar dy) {
11         fOffset.set(dx, dy);
12     }
13 
CreateProc(SkFlattenableReadBuffer & buffer)14     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
15         return SkNEW_ARGS(SkOffsetImageFilter, (buffer));
16     }
17 
18 protected:
19     SkOffsetImageFilter(SkFlattenableReadBuffer& buffer);
20 
21     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
22                                SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
23     virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE;
24     // overrides from SkFlattenable
25     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
26     virtual Factory getFactory() SK_OVERRIDE;
27 
28 private:
29     SkVector fOffset;
30 
31     typedef SkImageFilter INHERITED;
32 };
33 
34 class SkComposeImageFilter : public SkImageFilter {
35 public:
SkComposeImageFilter(SkImageFilter * outer,SkImageFilter * inner)36     SkComposeImageFilter(SkImageFilter* outer, SkImageFilter* inner) {
37         fOuter = outer;
38         fInner = inner;
39         SkSafeRef(outer);
40         SkSafeRef(inner);
41     }
42     virtual ~SkComposeImageFilter();
43 
CreateProc(SkFlattenableReadBuffer & buffer)44     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
45         return SkNEW_ARGS(SkComposeImageFilter, (buffer));
46     }
47 
48 protected:
49     SkComposeImageFilter(SkFlattenableReadBuffer& buffer);
50 
51     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
52                                SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
53     virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE;
54     // overrides from SkFlattenable
55     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
56     virtual Factory getFactory() SK_OVERRIDE;
57 
58 private:
59     SkImageFilter*  fOuter;
60     SkImageFilter*  fInner;
61 
62     typedef SkImageFilter INHERITED;
63 };
64 
65 #include "SkXfermode.h"
66 
67 class SkMergeImageFilter : public SkImageFilter {
68 public:
69     SkMergeImageFilter(SkImageFilter* first, SkImageFilter* second,
70                        SkXfermode::Mode = SkXfermode::kSrcOver_Mode);
71     SkMergeImageFilter(SkImageFilter* const filters[], int count,
72                        const SkXfermode::Mode modes[] = NULL);
73     virtual ~SkMergeImageFilter();
74 
CreateProc(SkFlattenableReadBuffer & buffer)75     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
76         return SkNEW_ARGS(SkMergeImageFilter, (buffer));
77     }
78 
79 protected:
80     SkMergeImageFilter(SkFlattenableReadBuffer& buffer);
81 
82     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
83                                SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
84     virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE;
85     // overrides from SkFlattenable
86     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
87     virtual Factory getFactory() SK_OVERRIDE;
88 
89 private:
90     SkImageFilter**     fFilters;
91     uint8_t*            fModes; // SkXfermode::Mode
92     int                 fCount;
93 
94     // private storage, to avoid dynamically allocating storage for our copy
95     // of the filters and modes (unless fCount is so large we can't fit).
96     intptr_t    fStorage[16];
97 
98     void initAlloc(int count, bool hasModes);
99     void init(SkImageFilter* const [], int count, const SkXfermode::Mode []);
100 
101     typedef SkImageFilter INHERITED;
102 };
103 
104 class SkColorFilterImageFilter : public SkImageFilter {
105 public:
SkColorFilterImageFilter(SkColorFilter * cf)106     SkColorFilterImageFilter(SkColorFilter* cf) : fColorFilter(cf) {
107         SkSafeRef(cf);
108     }
109     virtual ~SkColorFilterImageFilter();
110 
CreateProc(SkFlattenableReadBuffer & buffer)111     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
112         return SkNEW_ARGS(SkColorFilterImageFilter, (buffer));
113     }
114 
115 protected:
116     SkColorFilterImageFilter(SkFlattenableReadBuffer& buffer);
117 
118     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
119                                SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
120     // overrides from SkFlattenable
121     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
122     virtual Factory getFactory() SK_OVERRIDE;
123 
124 private:
125     SkColorFilter*  fColorFilter;
126 
127     typedef SkImageFilter INHERITED;
128 };
129 
130 ///////////////////////////////////////////////////////////////////////////////
131 
132 // Fun mode that scales down (only) and then scales back up to look pixelated
133 class SkDownSampleImageFilter : public SkImageFilter {
134 public:
SkDownSampleImageFilter(SkScalar scale)135     SkDownSampleImageFilter(SkScalar scale) : fScale(scale) {}
136 
CreateProc(SkFlattenableReadBuffer & buffer)137     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
138         return SkNEW_ARGS(SkDownSampleImageFilter, (buffer));
139     }
140 
141 protected:
142     SkDownSampleImageFilter(SkFlattenableReadBuffer& buffer);
143 
144     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
145                                SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
146     // overrides from SkFlattenable
147     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
148     virtual Factory getFactory()  SK_OVERRIDE;
149 
150 private:
151     SkScalar fScale;
152 
153     typedef SkImageFilter INHERITED;
154 };
155 
156 #endif
157