OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
13 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
14 #include "SkUtils.h" | 14 #include "SkUtils.h" |
15 #include "SkView.h" | 15 #include "SkView.h" |
16 | 16 |
17 static SkBitmap make_bitmap() { | 17 static SkBitmap make_bitmap() { |
18 SkPMColor c[256]; | 18 SkPMColor c[256]; |
19 for (int i = 0; i < 256; i++) { | 19 for (int i = 0; i < 256; i++) { |
20 c[i] = SkPackARGB32(255 - i, 0, 0, 0); | 20 c[i] = SkPackARGB32(255 - i, 0, 0, 0); |
21 } | 21 } |
22 | 22 |
23 SkBitmap bm; | 23 SkBitmap bm; |
24 SkColorTable* ctable = new SkColorTable(c, 256); | 24 SkColorTable* ctable = new SkColorTable(c, 256); |
25 | 25 |
26 bm.allocPixels(SkImageInfo::Make(256, 256, kIndex_8_SkColorType, | 26 bm.allocPixels(SkImageInfo::Make(256, 256, kIndex_8_SkColorType, |
27 kPremul_SkAlphaType), | 27 kPremul_SkAlphaType), |
28 NULL, ctable); | 28 nullptr, ctable); |
29 ctable->unref(); | 29 ctable->unref(); |
30 | 30 |
31 bm.lockPixels(); | 31 bm.lockPixels(); |
32 const float cx = bm.width() * 0.5f; | 32 const float cx = bm.width() * 0.5f; |
33 const float cy = bm.height() * 0.5f; | 33 const float cy = bm.height() * 0.5f; |
34 for (int y = 0; y < bm.height(); y++) { | 34 for (int y = 0; y < bm.height(); y++) { |
35 float dy = y - cy; | 35 float dy = y - cy; |
36 dy *= dy; | 36 dy *= dy; |
37 uint8_t* p = bm.getAddr8(0, y); | 37 uint8_t* p = bm.getAddr8(0, y); |
38 for (int x = 0; x < 256; x++) { | 38 for (int x = 0; x < 256; x++) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 for (int j = 0; j < 2; j++) { | 97 for (int j = 0; j < 2; j++) { |
98 canvas->save(); | 98 canvas->save(); |
99 paint.setColor(SK_ColorBLUE); | 99 paint.setColor(SK_ColorBLUE); |
100 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { | 100 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
101 if (gRecs[i].fStyle != NONE) { | 101 if (gRecs[i].fStyle != NONE) { |
102 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, | 102 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, |
103 SkBlurMask::ConvertRadiusToSigma(SkIntToSc
alar(20)), | 103 SkBlurMask::ConvertRadiusToSigma(SkIntToSc
alar(20)), |
104 flags); | 104 flags); |
105 paint.setMaskFilter(mf)->unref(); | 105 paint.setMaskFilter(mf)->unref(); |
106 } else { | 106 } else { |
107 paint.setMaskFilter(NULL); | 107 paint.setMaskFilter(nullptr); |
108 } | 108 } |
109 canvas->drawCircle(200 + gRecs[i].fCx*100.f, | 109 canvas->drawCircle(200 + gRecs[i].fCx*100.f, |
110 200 + gRecs[i].fCy*100.f, 50, paint); | 110 200 + gRecs[i].fCy*100.f, 50, paint); |
111 } | 111 } |
112 // draw text | 112 // draw text |
113 { | 113 { |
114 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 114 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
115 SkBlurMask::ConvertRadiusToSigma(SkIntToSc
alar(4)), | 115 SkBlurMask::ConvertRadiusToSigma(SkIntToSc
alar(4)), |
116 flags); | 116 flags); |
117 paint.setMaskFilter(mf)->unref(); | 117 paint.setMaskFilter(mf)->unref(); |
118 SkScalar x = SkIntToScalar(70); | 118 SkScalar x = SkIntToScalar(70); |
119 SkScalar y = SkIntToScalar(400); | 119 SkScalar y = SkIntToScalar(400); |
120 paint.setColor(SK_ColorBLACK); | 120 paint.setColor(SK_ColorBLACK); |
121 canvas->drawText("Hamburgefons Style", 18, x, y, paint); | 121 canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
122 canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar(
50), paint); | 122 canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar(
50), paint); |
123 paint.setMaskFilter(NULL); | 123 paint.setMaskFilter(nullptr); |
124 paint.setColor(SK_ColorWHITE); | 124 paint.setColor(SK_ColorWHITE); |
125 x -= SkIntToScalar(2); | 125 x -= SkIntToScalar(2); |
126 y -= SkIntToScalar(2); | 126 y -= SkIntToScalar(2); |
127 canvas->drawText("Hamburgefons Style", 18, x, y, paint); | 127 canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
128 } | 128 } |
129 canvas->restore(); | 129 canvas->restore(); |
130 flags = SkBlurMaskFilter::kHighQuality_BlurFlag; | 130 flags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
131 canvas->translate(350, 0); | 131 canvas->translate(350, 0); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 private: | 135 private: |
136 typedef SkView INHERITED; | 136 typedef SkView INHERITED; |
137 }; | 137 }; |
138 | 138 |
139 ////////////////////////////////////////////////////////////////////////////// | 139 ////////////////////////////////////////////////////////////////////////////// |
140 | 140 |
141 static SkView* MyFactory() { return new BlurView; } | 141 static SkView* MyFactory() { return new BlurView; } |
142 static SkViewRegister reg(MyFactory); | 142 static SkViewRegister reg(MyFactory); |
OLD | NEW |