OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 SkCanvas canvas(&device); | 102 SkCanvas canvas(&device); |
103 canvas.clear(0x00000000); | 103 canvas.clear(0x00000000); |
104 SkPaint paint; | 104 SkPaint paint; |
105 paint.setAntiAlias(true); | 105 paint.setAntiAlias(true); |
106 paint.setColor(0xFFFFFFFF); | 106 paint.setColor(0xFFFFFFFF); |
107 paint.setTextSize(SkIntToScalar(96)); | 107 paint.setTextSize(SkIntToScalar(96)); |
108 const char* str = "e"; | 108 const char* str = "e"; |
109 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 109 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
110 } | 110 } |
111 | 111 |
| 112 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint) { |
| 113 canvas->save(); |
| 114 canvas->clipRect(SkRect::MakeXYWH(0, 0, |
| 115 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
| 116 canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 117 canvas->restore(); |
| 118 } |
| 119 |
112 virtual SkISize onISize() { return SkISize::Make(500, 150); } | 120 virtual SkISize onISize() { return SkISize::Make(500, 150); } |
113 | 121 |
114 virtual void onDraw(SkCanvas* canvas) { | 122 virtual void onDraw(SkCanvas* canvas) { |
115 if (!fInitialized) { | 123 if (!fInitialized) { |
116 this->make_bitmap(); | 124 this->make_bitmap(); |
117 fInitialized = true; | 125 fInitialized = true; |
118 } | 126 } |
119 canvas->clear(0x00000000); | 127 canvas->clear(0x00000000); |
120 { | 128 { |
121 SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap)
); | 129 SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap)
); |
122 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, | 130 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, |
123 SkXfermode::kSrcIn_Mode
)); | 131 SkXfermode::kSrcIn_Mode
)); |
124 SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, b
itmapSource)); | 132 SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, b
itmapSource)); |
125 SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur)
); | 133 SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur)
); |
126 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); | 134 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); |
127 SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color
)); | 135 SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color
)); |
128 | 136 |
129 SkPaint paint; | 137 SkPaint paint; |
130 paint.setImageFilter(merge); | 138 paint.setImageFilter(merge); |
131 canvas->drawPaint(paint); | 139 canvas->drawPaint(paint); |
| 140 canvas->translate(SkIntToScalar(100), 0); |
132 } | 141 } |
133 { | 142 { |
134 SkAutoTUnref<SkImageFilter> morph(new SkDilateImageFilter(5, 5)); | 143 SkAutoTUnref<SkImageFilter> morph(new SkDilateImageFilter(5, 5)); |
135 | 144 |
136 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 145 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
137 0, SK_Scalar1, 0, 0, 0, | 146 0, SK_Scalar1, 0, 0, 0, |
138 0, 0, SK_Scalar1, 0, 0, | 147 0, 0, SK_Scalar1, 0, 0, |
139 0, 0, 0, SkFloatToScalar(0.5f), 0 }; | 148 0, 0, 0, SkFloatToScalar(0.5f), 0 }; |
140 | 149 |
141 SkAutoTUnref<SkColorFilter> matrixFilter(new SkColorMatrixFilter(mat
rix)); | 150 SkAutoTUnref<SkColorFilter> matrixFilter(new SkColorMatrixFilter(mat
rix)); |
142 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre
ate(matrixFilter, morph)); | 151 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre
ate(matrixFilter, morph)); |
143 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); | 152 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); |
144 SkAutoTUnref<SkImageFilter> blendColor(new SkXfermodeImageFilter(mod
e, colorMorph)); | 153 SkAutoTUnref<SkImageFilter> blendColor(new SkXfermodeImageFilter(mod
e, colorMorph)); |
145 | 154 |
146 SkPaint paint; | 155 SkPaint paint; |
147 paint.setImageFilter(blendColor); | 156 paint.setImageFilter(blendColor); |
148 canvas->drawBitmap(fBitmap, 100, 0, &paint); | 157 drawClippedBitmap(canvas, fBitmap, paint); |
| 158 canvas->translate(SkIntToScalar(100), 0); |
149 } | 159 } |
150 { | 160 { |
151 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 161 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
152 0, SK_Scalar1, 0, 0, 0, | 162 0, SK_Scalar1, 0, 0, 0, |
153 0, 0, SK_Scalar1, 0, 0, | 163 0, 0, SK_Scalar1, 0, 0, |
154 0, 0, 0, SkFloatToScalar(0.5f), 0 }; | 164 0, 0, 0, SkFloatToScalar(0.5f), 0 }; |
155 SkColorMatrixFilter matrixCF(matrix); | 165 SkColorMatrixFilter matrixCF(matrix); |
156 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C
reate(&matrixCF)); | 166 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C
reate(&matrixCF)); |
157 SimpleOffsetFilter offsetFilter(SkIntToScalar(10), SkIntToScalar(10)
, matrixFilter); | 167 SimpleOffsetFilter offsetFilter(SkIntToScalar(10), SkIntToScalar(10)
, matrixFilter); |
158 | 168 |
159 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar
1, SK_Scalar1, 0)); | 169 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar
1, SK_Scalar1, 0)); |
160 SkXfermodeImageFilter arithFilter(arith, matrixFilter, &offsetFilter
); | 170 SkXfermodeImageFilter arithFilter(arith, matrixFilter, &offsetFilter
); |
161 | 171 |
162 SkPaint paint; | 172 SkPaint paint; |
163 paint.setImageFilter(&arithFilter); | 173 paint.setImageFilter(&arithFilter); |
164 canvas->drawSprite(fBitmap, 200, 0, &paint); | 174 drawClippedBitmap(canvas, fBitmap, paint); |
| 175 canvas->translate(SkIntToScalar(100), 0); |
| 176 } |
| 177 { |
| 178 SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter( |
| 179 SkIntToScalar(10), SkIntToScalar(10))); |
| 180 |
| 181 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_
Mode)); |
| 182 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S
kIntToScalar(100))); |
| 183 SkAutoTUnref<SkImageFilter> blend(new SkXfermodeImageFilter(mode, bl
ur, NULL, &cropRect)); |
| 184 |
| 185 SkPaint paint; |
| 186 paint.setImageFilter(blend); |
| 187 drawClippedBitmap(canvas, fBitmap, paint); |
| 188 canvas->translate(SkIntToScalar(100), 0); |
165 } | 189 } |
166 } | 190 } |
167 | 191 |
168 private: | 192 private: |
169 typedef GM INHERITED; | 193 typedef GM INHERITED; |
170 SkBitmap fBitmap; | 194 SkBitmap fBitmap; |
171 bool fInitialized; | 195 bool fInitialized; |
172 }; | 196 }; |
173 | 197 |
174 /////////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////////// |
175 | 199 |
176 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } | 200 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } |
177 static skiagm::GMRegistry reg(MyFactory); | 201 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |