OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2011 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "gm.h" | |
9 #include "SkBlurImageFilter.h" | |
10 #include "SkRandom.h" | |
11 | |
12 // TODO deprecate imageblur | |
13 | |
14 #define WIDTH 500 | |
15 #define HEIGHT 500 | |
16 #include <stdio.h> | |
Stephen White
2014/07/25 20:43:17
Is this needed? If so, put it with the other #incl
| |
17 | |
18 // TODO this surely exists somewhere | |
Stephen White
2014/07/25 20:43:17
Try SK_ARRAY_COUNT.
| |
19 #define LENGTH(x) (sizeof((x)) / sizeof((x)[0])) | |
20 | |
21 static const float kBlurSigmas[] = { | |
22 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f }; | |
23 | |
24 const char* kTestStrings[] = { | |
25 "The quick`~", | |
26 "brown fox[]", | |
27 "jumped over", | |
28 "the lazy@#$", | |
29 "dog.{}!%^&", | |
30 "*()+=-\\'\"/", | |
31 }; | |
32 | |
33 namespace skiagm { | |
34 | |
35 class ImageBlur2GM : public GM { | |
Stephen White
2014/07/25 20:43:17
Let's call it BlurImageFilter (like the other imag
| |
36 public: | |
37 ImageBlur2GM() { | |
38 this->setBGColor(0xFFFFFFFF); | |
39 fName.printf("imageblur2"); | |
40 } | |
41 | |
42 protected: | |
43 virtual uint32_t onGetFlags() const SK_OVERRIDE { | |
44 return kSkipTiled_Flag; | |
45 } | |
46 | |
47 virtual SkString onShortName() { | |
48 return fName; | |
49 } | |
50 | |
51 virtual SkISize onISize() { | |
52 return SkISize::Make(WIDTH, HEIGHT); | |
53 } | |
54 | |
55 virtual void onDraw(SkCanvas* canvas) { | |
56 const int sigmaCount = LENGTH(kBlurSigmas); | |
57 const int testStringCount = LENGTH(kTestStrings); | |
58 SkScalar dx = WIDTH / sigmaCount; | |
59 SkScalar dy = HEIGHT / sigmaCount; | |
60 const int textSize = 12; | |
61 | |
62 for (int x = 0; x < sigmaCount; x++) { | |
63 SkScalar sigmaX = kBlurSigmas[x]; | |
64 for (int y = 0; y < sigmaCount; y++) { | |
65 SkScalar sigmaY = kBlurSigmas[y]; | |
66 | |
67 SkPaint paint; | |
68 paint.setImageFilter(SkBlurImageFilter::Create(sigmaX, sigmaY))- >unref(); | |
69 canvas->saveLayer(NULL, &paint); | |
70 | |
71 SkRandom rand; | |
72 SkPaint textPaint; | |
73 textPaint.setAntiAlias(true); | |
74 textPaint.setColor(rand.nextBits(24) | 0xFF000000); | |
75 textPaint.setTextSize(textSize); | |
76 | |
77 for (int i = 0; i < testStringCount; i++) { | |
78 canvas->drawText(kTestStrings[i], | |
79 strlen(kTestStrings[i]), | |
80 SkIntToScalar(x * dx), | |
81 SkIntToScalar(y * dy + textSize * i + textS ize), | |
82 textPaint); | |
83 } | |
84 canvas->restore(); | |
85 } | |
86 } | |
87 } | |
88 | |
89 private: | |
90 SkString fName; | |
91 | |
92 typedef GM INHERITED; | |
93 }; | |
94 | |
95 ////////////////////////////////////////////////////////////////////////////// | |
96 | |
97 static GM* MyFactory(void*) { return new ImageBlur2GM; } | |
98 static GMRegistry reg(MyFactory); | |
99 | |
100 } | |
OLD | NEW |