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

Side by Side Diff: gm/matrixconvolution.cpp

Issue 197013003: Clean up SkImageFilter. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « bench/MatrixConvolutionBench.cpp ('k') | src/effects/SkMatrixConvolutionImageFilter.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 * 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 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkMatrixConvolutionImageFilter.h" 10 #include "SkMatrixConvolutionImageFilter.h"
(...skipping 27 matching lines...) Expand all
38 paint.setShader(SkGradientShader::CreateLinear( 38 paint.setShader(SkGradientShader::CreateLinear(
39 pts, colors, pos, 2, SkShader::kClamp_TileMode))->unref(); 39 pts, colors, pos, 2, SkShader::kClamp_TileMode))->unref();
40 const char* str = "e"; 40 const char* str = "e";
41 canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint); 41 canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint);
42 } 42 }
43 43
44 virtual SkISize onISize() { 44 virtual SkISize onISize() {
45 return make_isize(500, 300); 45 return make_isize(500, 300);
46 } 46 }
47 47
48 void draw(SkCanvas* canvas, int x, int y, const SkIPoint& target, 48 void draw(SkCanvas* canvas, int x, int y, const SkIPoint& kernelOffset,
49 SkMatrixConvolutionImageFilter::TileMode tileMode, bool convolveAl pha, 49 SkMatrixConvolutionImageFilter::TileMode tileMode, bool convolveAl pha,
50 const SkImageFilter::CropRect* cropRect = NULL) { 50 const SkImageFilter::CropRect* cropRect = NULL) {
51 SkScalar kernel[9] = { 51 SkScalar kernel[9] = {
52 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 52 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
53 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 53 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
54 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 54 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
55 }; 55 };
56 SkISize kernelSize = SkISize::Make(3, 3); 56 SkISize kernelSize = SkISize::Make(3, 3);
57 SkScalar gain = 0.3f, bias = SkIntToScalar(100); 57 SkScalar gain = 0.3f, bias = SkIntToScalar(100);
58 SkPaint paint; 58 SkPaint paint;
59 SkAutoTUnref<SkImageFilter> filter( 59 SkAutoTUnref<SkImageFilter> filter(
60 SkMatrixConvolutionImageFilter::Create(kernelSize, 60 SkMatrixConvolutionImageFilter::Create(kernelSize,
61 kernel, 61 kernel,
62 gain, 62 gain,
63 bias, 63 bias,
64 target, 64 kernelOffset,
65 tileMode, 65 tileMode,
66 convolveAlpha, 66 convolveAlpha,
67 NULL, 67 NULL,
68 cropRect)); 68 cropRect));
69 paint.setImageFilter(filter); 69 paint.setImageFilter(filter);
70 canvas->save(); 70 canvas->save();
71 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 71 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
72 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), 72 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()),
73 SkIntToScalar(fBitmap.height()))); 73 SkIntToScalar(fBitmap.height())));
74 canvas->drawBitmap(fBitmap, 0, 0, &paint); 74 canvas->drawBitmap(fBitmap, 0, 0, &paint);
75 canvas->restore(); 75 canvas->restore();
76 } 76 }
77 77
78 typedef SkMatrixConvolutionImageFilter MCIF; 78 typedef SkMatrixConvolutionImageFilter MCIF;
79 79
80 virtual void onDraw(SkCanvas* canvas) { 80 virtual void onDraw(SkCanvas* canvas) {
81 if (!fInitialized) { 81 if (!fInitialized) {
82 make_bitmap(); 82 make_bitmap();
83 fInitialized = true; 83 fInitialized = true;
84 } 84 }
85 canvas->clear(0x00000000); 85 canvas->clear(0x00000000);
86 SkIPoint target = SkIPoint::Make(1, 0); 86 SkIPoint kernelOffset = SkIPoint::Make(1, 0);
87 for (int x = 10; x < 310; x += 100) { 87 for (int x = 10; x < 310; x += 100) {
88 this->draw(canvas, x, 10, target, MCIF::kClamp_TileMode, true); 88 this->draw(canvas, x, 10, kernelOffset, MCIF::kClamp_TileMode, true) ;
89 this->draw(canvas, x, 110, target, MCIF::kClampToBlack_TileMode, tru e); 89 this->draw(canvas, x, 110, kernelOffset, MCIF::kClampToBlack_TileMod e, true);
90 this->draw(canvas, x, 210, target, MCIF::kRepeat_TileMode, true); 90 this->draw(canvas, x, 210, kernelOffset, MCIF::kRepeat_TileMode, tru e);
91 target.fY++; 91 kernelOffset.fY++;
92 } 92 }
93 target.fY = 1; 93 kernelOffset.fY = 1;
94 SkImageFilter::CropRect rect(SkRect::MakeXYWH(10, 5, 60, 60)); 94 SkImageFilter::CropRect rect(SkRect::MakeXYWH(10, 5, 60, 60));
95 this->draw(canvas, 310, 10, target, MCIF::kClamp_TileMode, true, &rect); 95 this->draw(canvas, 310, 10, kernelOffset, MCIF::kClamp_TileMode, true, & rect);
96 this->draw(canvas, 310, 110, target, MCIF::kClampToBlack_TileMode, true, &rect); 96 this->draw(canvas, 310, 110, kernelOffset, MCIF::kClampToBlack_TileMode, true, &rect);
97 this->draw(canvas, 310, 210, target, MCIF::kRepeat_TileMode, true, &rect ); 97 this->draw(canvas, 310, 210, kernelOffset, MCIF::kRepeat_TileMode, true, &rect);
98 98
99 this->draw(canvas, 410, 10, target, MCIF::kClamp_TileMode, false); 99 this->draw(canvas, 410, 10, kernelOffset, MCIF::kClamp_TileMode, false);
100 this->draw(canvas, 410, 110, target, MCIF::kClampToBlack_TileMode, false ); 100 this->draw(canvas, 410, 110, kernelOffset, MCIF::kClampToBlack_TileMode, false);
101 this->draw(canvas, 410, 210, target, MCIF::kRepeat_TileMode, false); 101 this->draw(canvas, 410, 210, kernelOffset, MCIF::kRepeat_TileMode, false );
102 } 102 }
103 103
104 private: 104 private:
105 typedef GM INHERITED; 105 typedef GM INHERITED;
106 SkBitmap fBitmap; 106 SkBitmap fBitmap;
107 bool fInitialized; 107 bool fInitialized;
108 }; 108 };
109 109
110 ////////////////////////////////////////////////////////////////////////////// 110 //////////////////////////////////////////////////////////////////////////////
111 111
112 static GM* MyFactory(void*) { return new MatrixConvolutionGM; } 112 static GM* MyFactory(void*) { return new MatrixConvolutionGM; }
113 static GMRegistry reg(MyFactory); 113 static GMRegistry reg(MyFactory);
114 114
115 } 115 }
OLDNEW
« no previous file with comments | « bench/MatrixConvolutionBench.cpp ('k') | src/effects/SkMatrixConvolutionImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698