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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 void onOnceBeforeDraw() override { | 113 void onOnceBeforeDraw() override { |
114 fImage = SkImage::MakeFromBitmap( | 114 fImage = SkImage::MakeFromBitmap( |
115 sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70,
96, "e")); | 115 sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70,
96, "e")); |
116 } | 116 } |
117 | 117 |
118 void onDraw(SkCanvas* canvas) override { | 118 void onDraw(SkCanvas* canvas) override { |
119 canvas->clear(SK_ColorBLACK); | 119 canvas->clear(SK_ColorBLACK); |
120 { | 120 { |
121 SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImag
e.get())); | 121 SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImag
e.get())); |
122 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, | 122 auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcI
n_Mode)); |
123 SkXfermode::kSrcIn_Mode
)); | |
124 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0
f, bitmapSource)); | 123 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0
f, bitmapSource)); |
125 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b
lur)); | 124 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b
lur)); |
126 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); | 125 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f.get(), erode)); |
127 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c
olor)); | 126 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c
olor)); |
128 | 127 |
129 SkPaint paint; | 128 SkPaint paint; |
130 paint.setImageFilter(merge); | 129 paint.setImageFilter(merge); |
131 canvas->drawPaint(paint); | 130 canvas->drawPaint(paint); |
132 canvas->translate(SkIntToScalar(100), 0); | 131 canvas->translate(SkIntToScalar(100), 0); |
133 } | 132 } |
134 { | 133 { |
135 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5))
; | 134 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5))
; |
136 | 135 |
137 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 136 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
138 0, SK_Scalar1, 0, 0, 0, | 137 0, SK_Scalar1, 0, 0, 0, |
139 0, 0, SK_Scalar1, 0, 0, | 138 0, 0, SK_Scalar1, 0, 0, |
140 0, 0, 0, 0.5f, 0 }; | 139 0, 0, 0, 0.5f, 0 }; |
141 | 140 |
142 SkAutoTUnref<SkColorFilter> matrixFilter(SkColorMatrixFilter::Create
(matrix)); | 141 auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)
); |
143 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre
ate(matrixFilter, morph)); | 142 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre
ate(matrixFilter.get(), morph)); |
144 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); | 143 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); |
145 SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create
(mode, colorMorph)); | 144 SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create
(mode, colorMorph)); |
146 | 145 |
147 SkPaint paint; | 146 SkPaint paint; |
148 paint.setImageFilter(blendColor); | 147 paint.setImageFilter(blendColor); |
149 DrawClippedImage(canvas, fImage.get(), paint); | 148 DrawClippedImage(canvas, fImage.get(), paint); |
150 canvas->translate(SkIntToScalar(100), 0); | 149 canvas->translate(SkIntToScalar(100), 0); |
151 } | 150 } |
152 { | 151 { |
153 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 152 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
154 0, SK_Scalar1, 0, 0, 0, | 153 0, SK_Scalar1, 0, 0, 0, |
155 0, 0, SK_Scalar1, 0, 0, | 154 0, 0, SK_Scalar1, 0, 0, |
156 0, 0, 0, 0.5f, 0 }; | 155 0, 0, 0, 0.5f, 0 }; |
157 SkAutoTUnref<SkColorFilter> matrixCF(SkColorMatrixFilter::Create(mat
rix)); | 156 auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); |
158 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C
reate(matrixCF)); | 157 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C
reate(matrixCF.get())); |
159 SkAutoTUnref<SkImageFilter> offsetFilter( | 158 SkAutoTUnref<SkImageFilter> offsetFilter( |
160 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter)); | 159 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter)); |
161 | 160 |
162 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar
1, SK_Scalar1, 0)); | 161 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar
1, SK_Scalar1, 0)); |
163 SkAutoTUnref<SkImageFilter> arithFilter( | 162 SkAutoTUnref<SkImageFilter> arithFilter( |
164 SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter)
); | 163 SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter)
); |
165 | 164 |
166 SkPaint paint; | 165 SkPaint paint; |
167 paint.setImageFilter(arithFilter); | 166 paint.setImageFilter(arithFilter); |
168 DrawClippedImage(canvas, fImage.get(), paint); | 167 DrawClippedImage(canvas, fImage.get(), paint); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 convolveAlpha, | 210 convolveAlpha, |
212 dilate)); | 211 dilate)); |
213 | 212 |
214 SkPaint paint; | 213 SkPaint paint; |
215 paint.setImageFilter(convolve); | 214 paint.setImageFilter(convolve); |
216 DrawClippedImage(canvas, fImage.get(), paint); | 215 DrawClippedImage(canvas, fImage.get(), paint); |
217 canvas->translate(SkIntToScalar(100), 0); | 216 canvas->translate(SkIntToScalar(100), 0); |
218 } | 217 } |
219 { | 218 { |
220 // Test that crop offsets are absolute, not relative to the parent's
crop rect. | 219 // Test that crop offsets are absolute, not relative to the parent's
crop rect. |
221 SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_C
olorBLUE, | 220 auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSr
cIn_Mode)); |
222 SkXf
ermode::kSrcIn_Mode)); | 221 auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kS
rcIn_Mode)); |
223 SkAutoTUnref<SkColorFilter> cf2(SkColorFilter::CreateModeFilter(SK_C
olorGREEN, | |
224 SkXf
ermode::kSrcIn_Mode)); | |
225 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10)
, SkIntToScalar(10), | 222 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10)
, SkIntToScalar(10), |
226 SkIntToScalar(80)
, SkIntToScalar(80))); | 223 SkIntToScalar(80)
, SkIntToScalar(80))); |
227 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20)
, SkIntToScalar(20), | 224 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20)
, SkIntToScalar(20), |
228 SkIntToScalar(60)
, SkIntToScalar(60))); | 225 SkIntToScalar(60)
, SkIntToScalar(60))); |
229 SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(
cf1, nullptr, &outerRect)); | 226 SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(
cf1.get(), nullptr, &outerRect)); |
230 SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(
cf2, color1, &innerRect)); | 227 SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(
cf2.get(), color1, &innerRect)); |
231 | 228 |
232 SkPaint paint; | 229 SkPaint paint; |
233 paint.setImageFilter(color2); | 230 paint.setImageFilter(color2); |
234 paint.setColor(SK_ColorRED); | 231 paint.setColor(SK_ColorRED); |
235 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); | 232 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); |
236 canvas->translate(SkIntToScalar(100), 0); | 233 canvas->translate(SkIntToScalar(100), 0); |
237 } | 234 } |
238 } | 235 } |
239 | 236 |
240 private: | 237 private: |
241 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S
kPaint& paint) { | 238 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S
kPaint& paint) { |
242 canvas->save(); | 239 canvas->save(); |
243 canvas->clipRect(SkRect::MakeIWH(image->width(), image->height())); | 240 canvas->clipRect(SkRect::MakeIWH(image->width(), image->height())); |
244 canvas->drawImage(image, 0, 0, &paint); | 241 canvas->drawImage(image, 0, 0, &paint); |
245 canvas->restore(); | 242 canvas->restore(); |
246 } | 243 } |
247 | 244 |
248 sk_sp<SkImage> fImage; | 245 sk_sp<SkImage> fImage; |
249 | 246 |
250 typedef GM INHERITED; | 247 typedef GM INHERITED; |
251 }; | 248 }; |
252 | 249 |
253 /////////////////////////////////////////////////////////////////////////////// | 250 /////////////////////////////////////////////////////////////////////////////// |
254 | 251 |
255 DEF_GM(return new ImageFiltersGraphGM;) | 252 DEF_GM(return new ImageFiltersGraphGM;) |
OLD | NEW |