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

Side by Side Diff: gm/blurquickreject.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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 12 matching lines...) Expand all
23 protected: 23 protected:
24 virtual SkString onShortName() SK_OVERRIDE { 24 virtual SkString onShortName() SK_OVERRIDE {
25 return SkString("blurquickreject"); 25 return SkString("blurquickreject");
26 } 26 }
27 27
28 virtual SkISize onISize() SK_OVERRIDE { 28 virtual SkISize onISize() SK_OVERRIDE {
29 return SkISize::Make(kWidth, kHeight); 29 return SkISize::Make(kWidth, kHeight);
30 } 30 }
31 31
32 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 32 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
33 static const SkScalar kBlurRadius = SkIntToScalar(20); 33 static const SkScalar kSigma = SkFloatToScalar(12.047f);
34 static const SkScalar kBoxSize = SkIntToScalar(100); 34 static const SkScalar kBoxSize = SkIntToScalar(100);
35 35
36 SkRect clipRect = SkRect::MakeXYWH(0, 0, kBoxSize, kBoxSize); 36 SkRect clipRect = SkRect::MakeXYWH(0, 0, kBoxSize, kBoxSize);
37 SkRect blurRects[] = { 37 SkRect blurRects[] = {
38 { -kBoxSize - (kBlurRadius+1), 0, -(kBlurRadius+1), kBoxSize }, 38 { -kBoxSize - kSigma, 0, -kSigma, kBoxSize },
39 { 0, -kBoxSize - (kBlurRadius+1), kBoxSize, -(kBlurRadius+1) }, 39 { 0, -kBoxSize - kSigma, kBoxSize, -kSigma },
40 { kBoxSize+kBlurRadius+1, 0, 2*kBoxSize+kBlurRadius+1, kBoxSize }, 40 { kBoxSize+kSigma, 0, 2*kBoxSize+kSigma, kBoxSize },
41 { 0, kBoxSize+kBlurRadius+1, kBoxSize, 2*kBoxSize+kBlurRadius+1 } 41 { 0, kBoxSize+kSigma, kBoxSize, 2*kBoxSize+kSigma }
42 }; 42 };
43 SkColor colors[] = { 43 SkColor colors[] = {
44 SK_ColorRED, 44 SK_ColorRED,
45 SK_ColorGREEN, 45 SK_ColorGREEN,
46 SK_ColorBLUE, 46 SK_ColorBLUE,
47 SK_ColorYELLOW, 47 SK_ColorYELLOW,
48 }; 48 };
49 SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(blurRects)); 49 SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(blurRects));
50 50
51 SkPaint hairlinePaint; 51 SkPaint hairlinePaint;
52 hairlinePaint.setStyle(SkPaint::kStroke_Style); 52 hairlinePaint.setStyle(SkPaint::kStroke_Style);
53 hairlinePaint.setColor(SK_ColorWHITE); 53 hairlinePaint.setColor(SK_ColorWHITE);
54 hairlinePaint.setStrokeWidth(0); 54 hairlinePaint.setStrokeWidth(0);
55 55
56 SkPaint blurPaint; 56 SkPaint blurPaint;
57 blurPaint.setFilterBitmap(true); 57 blurPaint.setFilterBitmap(true);
58 SkMaskFilter* mf = SkBlurMaskFilter::Create(kBlurRadius, 58 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Bl urStyle,
59 SkBlurMaskFilter::kNormal_Bl urStyle); 59 kSigma);
60 blurPaint.setMaskFilter(mf)->unref(); 60 blurPaint.setMaskFilter(mf)->unref();
61 61
62 canvas->clear(SK_ColorBLACK); 62 canvas->clear(SK_ColorBLACK);
63 canvas->save(); 63 canvas->save();
64 canvas->translate(kBoxSize, kBoxSize); 64 canvas->translate(kBoxSize, kBoxSize);
65 canvas->drawRect(clipRect, hairlinePaint); 65 canvas->drawRect(clipRect, hairlinePaint);
66 canvas->clipRect(clipRect); 66 canvas->clipRect(clipRect);
67 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRects); ++i) { 67 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRects); ++i) {
68 blurPaint.setColor(colors[i]); 68 blurPaint.setColor(colors[i]);
69 canvas->drawRect(blurRects[i], blurPaint); 69 canvas->drawRect(blurRects[i], blurPaint);
70 canvas->drawRect(blurRects[i], hairlinePaint); 70 canvas->drawRect(blurRects[i], hairlinePaint);
71 } 71 }
72 canvas->restore(); 72 canvas->restore();
73 } 73 }
74 74
75 private: 75 private:
76 static const int kWidth = 300; 76 static const int kWidth = 300;
77 static const int kHeight = 300; 77 static const int kHeight = 300;
78 78
79 typedef GM INHERITED; 79 typedef GM INHERITED;
80 }; 80 };
81 81
82 DEF_GM( return new BlurQuickRejectGM(); ) 82 DEF_GM( return new BlurQuickRejectGM(); )
OLDNEW
« bench/BlurBench.cpp ('K') | « gm/bleed.cpp ('k') | gm/blurrect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698