Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: samplecode/SampleBlur.cpp

Issue 23701006: Push sigma-based blur interface into our GMs/benches/tests/samplecode (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: cleaned up Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleBigBlur.cpp ('k') | samplecode/SampleEffects.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
11 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
11 #include "SkGradientShader.h" 13 #include "SkGradientShader.h"
14 #include "SkUtils.h"
12 #include "SkView.h" 15 #include "SkView.h"
13 #include "SkCanvas.h"
14 #include "SkUtils.h"
15 16
16 static SkBitmap make_bitmap() { 17 static SkBitmap make_bitmap() {
17 SkBitmap bm; 18 SkBitmap bm;
18 SkColorTable* ctable = new SkColorTable(256); 19 SkColorTable* ctable = new SkColorTable(256);
19 20
20 SkPMColor* c = ctable->lockColors(); 21 SkPMColor* c = ctable->lockColors();
21 for (int i = 0; i < 256; i++) { 22 for (int i = 0; i < 256; i++) {
22 c[i] = SkPackARGB32(255 - i, 0, 0, 0); 23 c[i] = SkPackARGB32(255 - i, 0, 0, 0);
23 } 24 }
24 ctable->unlockColors(true); 25 ctable->unlockColors(true);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 paint.setAntiAlias(true); 91 paint.setAntiAlias(true);
91 paint.setTextSize(25); 92 paint.setTextSize(25);
92 canvas->translate(-40, 0); 93 canvas->translate(-40, 0);
93 94
94 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; 95 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
95 for (int j = 0; j < 2; j++) { 96 for (int j = 0; j < 2; j++) {
96 canvas->save(); 97 canvas->save();
97 paint.setColor(SK_ColorBLUE); 98 paint.setColor(SK_ColorBLUE);
98 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { 99 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
99 if (gRecs[i].fStyle != NONE) { 100 if (gRecs[i].fStyle != NONE) {
100 SkMaskFilter* mf = SkBlurMaskFilter::Create(20, 101 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
101 gRecs[i].fStyle, 102 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(20)),
102 flags); 103 flags);
103 paint.setMaskFilter(mf)->unref(); 104 paint.setMaskFilter(mf)->unref();
104 } else { 105 } else {
105 paint.setMaskFilter(NULL); 106 paint.setMaskFilter(NULL);
106 } 107 }
107 canvas->drawCircle(200 + gRecs[i].fCx*100.f, 108 canvas->drawCircle(200 + gRecs[i].fCx*100.f,
108 200 + gRecs[i].fCy*100.f, 50, paint); 109 200 + gRecs[i].fCy*100.f, 50, paint);
109 } 110 }
110 // draw text 111 // draw text
111 { 112 {
112 SkMaskFilter* mf = SkBlurMaskFilter::Create(4, 113 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kN ormal_BlurStyle,
113 SkBlurMaskFilter::kN ormal_BlurStyle, 114 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(4)),
114 flags); 115 flags);
115 paint.setMaskFilter(mf)->unref(); 116 paint.setMaskFilter(mf)->unref();
116 SkScalar x = SkIntToScalar(70); 117 SkScalar x = SkIntToScalar(70);
117 SkScalar y = SkIntToScalar(400); 118 SkScalar y = SkIntToScalar(400);
118 paint.setColor(SK_ColorBLACK); 119 paint.setColor(SK_ColorBLACK);
119 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 120 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
120 canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar( 50), paint); 121 canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar( 50), paint);
121 paint.setMaskFilter(NULL); 122 paint.setMaskFilter(NULL);
122 paint.setColor(SK_ColorWHITE); 123 paint.setColor(SK_ColorWHITE);
123 x -= SkIntToScalar(2); 124 x -= SkIntToScalar(2);
124 y -= SkIntToScalar(2); 125 y -= SkIntToScalar(2);
125 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 126 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
126 } 127 }
127 canvas->restore(); 128 canvas->restore();
128 flags = SkBlurMaskFilter::kHighQuality_BlurFlag; 129 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
129 canvas->translate(350, 0); 130 canvas->translate(350, 0);
130 } 131 }
131 } 132 }
132 133
133 private: 134 private:
134 typedef SkView INHERITED; 135 typedef SkView INHERITED;
135 }; 136 };
136 137
137 ////////////////////////////////////////////////////////////////////////////// 138 //////////////////////////////////////////////////////////////////////////////
138 139
139 static SkView* MyFactory() { return new BlurView; } 140 static SkView* MyFactory() { return new BlurView; }
140 static SkViewRegister reg(MyFactory); 141 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleBigBlur.cpp ('k') | samplecode/SampleEffects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698