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

Side by Side Diff: gm/matrixconvolution.cpp

Issue 27471002: Implement crop rect support for SkMatrixConvolutionImageFilter. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix style issue Created 7 years, 2 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 | « expectations/gm/ignored-tests.txt ('k') | include/core/SkImageFilter.h » ('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 26 matching lines...) Expand all
37 SkPoint::Make(0, SkIntToScalar(80)) }; 37 SkPoint::Make(0, SkIntToScalar(80)) };
38 SkColor colors[2] = { 0xFFFFFFFF, 0x40404040 }; 38 SkColor colors[2] = { 0xFFFFFFFF, 0x40404040 };
39 SkScalar pos[2] = { 0, SkIntToScalar(80) }; 39 SkScalar pos[2] = { 0, SkIntToScalar(80) };
40 paint.setShader(SkGradientShader::CreateLinear( 40 paint.setShader(SkGradientShader::CreateLinear(
41 pts, colors, pos, 2, SkShader::kClamp_TileMode))->unref(); 41 pts, colors, pos, 2, SkShader::kClamp_TileMode))->unref();
42 const char* str = "e"; 42 const char* str = "e";
43 canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint); 43 canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint);
44 } 44 }
45 45
46 virtual SkISize onISize() { 46 virtual SkISize onISize() {
47 return make_isize(400, 300); 47 return make_isize(500, 300);
48 } 48 }
49 49
50 void draw(SkCanvas* canvas, int x, int y, const SkIPoint& target, SkMatrixCo nvolutionImageFilter::TileMode tileMode, bool convolveAlpha) { 50 void draw(SkCanvas* canvas, int x, int y, const SkIPoint& target,
51 SkMatrixConvolutionImageFilter::TileMode tileMode, bool convolveAl pha,
52 const SkImageFilter::CropRect* cropRect = NULL) {
51 SkScalar kernel[9] = { 53 SkScalar kernel[9] = {
52 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 54 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
53 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 55 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
54 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 56 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
55 }; 57 };
56 SkISize kernelSize = SkISize::Make(3, 3); 58 SkISize kernelSize = SkISize::Make(3, 3);
57 SkScalar gain = SkFloatToScalar(0.3f), bias = SkIntToScalar(100); 59 SkScalar gain = SkFloatToScalar(0.3f), bias = SkIntToScalar(100);
58 SkPaint paint; 60 SkPaint paint;
59 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkMatrixConvolutionImageFi lter, (kernelSize, kernel, gain, bias, target, tileMode, convolveAlpha))); 61 SkAutoTUnref<SkImageFilter> filter(
62 SkNEW_ARGS(SkMatrixConvolutionImageFilter, (kernelSize,
63 kernel,
64 gain,
65 bias,
66 target,
67 tileMode,
68 convolveAlpha,
69 NULL,
70 cropRect)));
60 paint.setImageFilter(filter); 71 paint.setImageFilter(filter);
61 canvas->save(); 72 canvas->save();
62 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 73 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
63 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); 74 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()),
64 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); 75 SkIntToScalar(fBitmap.height())));
76 canvas->drawBitmap(fBitmap, 0, 0, &paint);
65 canvas->restore(); 77 canvas->restore();
66 } 78 }
67 79
80 typedef SkMatrixConvolutionImageFilter MCIF;
81
68 virtual void onDraw(SkCanvas* canvas) { 82 virtual void onDraw(SkCanvas* canvas) {
69 if (!fInitialized) { 83 if (!fInitialized) {
70 make_bitmap(); 84 make_bitmap();
71 fInitialized = true; 85 fInitialized = true;
72 } 86 }
73 canvas->clear(0x00000000); 87 canvas->clear(0x00000000);
74 SkIPoint target = SkIPoint::Make(1, 0); 88 SkIPoint target = SkIPoint::Make(1, 0);
75 for (int x = 10; x < 310; x += 100) { 89 for (int x = 10; x < 310; x += 100) {
76 draw(canvas, x, 10, target, SkMatrixConvolutionImageFilter::kClamp_T ileMode, true); 90 this->draw(canvas, x, 10, target, MCIF::kClamp_TileMode, true);
77 draw(canvas, x, 110, target, SkMatrixConvolutionImageFilter::kClampT oBlack_TileMode, true); 91 this->draw(canvas, x, 110, target, MCIF::kClampToBlack_TileMode, tru e);
78 draw(canvas, x, 210, target, SkMatrixConvolutionImageFilter::kRepeat _TileMode, true); 92 this->draw(canvas, x, 210, target, MCIF::kRepeat_TileMode, true);
79 target.fY++; 93 target.fY++;
80 } 94 }
81 target.fY = 1; 95 target.fY = 1;
82 draw(canvas, 310, 10, target, SkMatrixConvolutionImageFilter::kClamp_Til eMode, false); 96 SkImageFilter::CropRect rect(SkRect::MakeXYWH(10, 10, 60, 60));
83 draw(canvas, 310, 110, target, SkMatrixConvolutionImageFilter::kClampToB lack_TileMode, false); 97 this->draw(canvas, 310, 10, target, MCIF::kClamp_TileMode, true, &rect);
84 draw(canvas, 310, 210, target, SkMatrixConvolutionImageFilter::kRepeat_T ileMode, false); 98 this->draw(canvas, 310, 110, target, MCIF::kClampToBlack_TileMode, true, &rect);
99 this->draw(canvas, 310, 210, target, MCIF::kRepeat_TileMode, true, &rect );
100
101 this->draw(canvas, 410, 10, target, MCIF::kClamp_TileMode, false);
102 this->draw(canvas, 410, 110, target, MCIF::kClampToBlack_TileMode, false );
103 this->draw(canvas, 410, 210, target, MCIF::kRepeat_TileMode, false);
85 } 104 }
86 105
87 private: 106 private:
88 typedef GM INHERITED; 107 typedef GM INHERITED;
89 SkBitmap fBitmap; 108 SkBitmap fBitmap;
90 bool fInitialized; 109 bool fInitialized;
91 }; 110 };
92 111
93 ////////////////////////////////////////////////////////////////////////////// 112 //////////////////////////////////////////////////////////////////////////////
94 113
95 static GM* MyFactory(void*) { return new MatrixConvolutionGM; } 114 static GM* MyFactory(void*) { return new MatrixConvolutionGM; }
96 static GMRegistry reg(MyFactory); 115 static GMRegistry reg(MyFactory);
97 116
98 } 117 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | include/core/SkImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698