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

Side by Side Diff: gm/morphology.cpp

Issue 23892011: Implement crop rect for the dilate and erode (morphology) filters. This provoked some cleanup on th… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Embiggen GM to accommodate new test cases. 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 | « no previous file | include/effects/SkMorphologyImageFilter.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 "SkMorphologyImageFilter.h" 9 #include "SkMorphologyImageFilter.h"
10 10
11 #define WIDTH 640 11 #define WIDTH 700
12 #define HEIGHT 480 12 #define HEIGHT 560
13 13
14 namespace skiagm { 14 namespace skiagm {
15 15
16 class MorphologyGM : public GM { 16 class MorphologyGM : public GM {
17 public: 17 public:
18 MorphologyGM() { 18 MorphologyGM() {
19 this->setBGColor(0xFF000000); 19 this->setBGColor(0xFF000000);
20 fOnce = false; 20 fOnce = false;
21 } 21 }
22 22
(...skipping 14 matching lines...) Expand all
37 const char* str2 = "XYZ"; 37 const char* str2 = "XYZ";
38 paint.setColor(0xFFFFFFFF); 38 paint.setColor(0xFFFFFFFF);
39 paint.setTextSize(64); 39 paint.setTextSize(64);
40 canvas.drawText(str1, strlen(str1), 10, 55, paint); 40 canvas.drawText(str1, strlen(str1), 10, 55, paint);
41 canvas.drawText(str2, strlen(str2), 10, 110, paint); 41 canvas.drawText(str2, strlen(str2), 10, 110, paint);
42 } 42 }
43 43
44 virtual SkISize onISize() { 44 virtual SkISize onISize() {
45 return make_isize(WIDTH, HEIGHT); 45 return make_isize(WIDTH, HEIGHT);
46 } 46 }
47
48 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
49 canvas->save();
50 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
51 canvas->clipRect(SkRect::MakeWH(
52 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
53 canvas->drawBitmap(fBitmap, 0, 0, &paint);
54 canvas->restore();
55 }
56
47 virtual void onDraw(SkCanvas* canvas) { 57 virtual void onDraw(SkCanvas* canvas) {
48 if (!fOnce) { 58 if (!fOnce) {
49 make_bitmap(); 59 make_bitmap();
50 fOnce = true; 60 fOnce = true;
51 } 61 }
52 struct { 62 struct {
53 int fWidth, fHeight; 63 int fWidth, fHeight;
54 int fRadiusX, fRadiusY; 64 int fRadiusX, fRadiusY;
55 } samples[] = { 65 } samples[] = {
56 { 140, 140, 0, 0 }, 66 { 140, 140, 0, 0 },
57 { 140, 140, 0, 2 }, 67 { 140, 140, 0, 2 },
58 { 140, 140, 2, 0 }, 68 { 140, 140, 2, 0 },
59 { 140, 140, 2, 2 }, 69 { 140, 140, 2, 2 },
60 { 24, 24, 25, 25 }, 70 { 24, 24, 25, 25 },
61 }; 71 };
62 SkPaint paint; 72 SkPaint paint;
63 for (unsigned j = 0; j < 2; ++j) { 73 SkIRect cropRect = SkIRect::MakeXYWH(25, 20, 100, 80);
74
75 for (unsigned j = 0; j < 4; ++j) {
64 for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { 76 for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) {
65 SkScalar x = SkIntToScalar(i * 140), y = SkIntToScalar(j * 140); 77 const SkIRect* cr = j & 0x02 ? &cropRect : NULL;
66 if (j) { 78 if (j & 0x01) {
67 paint.setImageFilter(new SkErodeImageFilter( 79 paint.setImageFilter(new SkErodeImageFilter(
68 samples[i].fRadiusX, 80 samples[i].fRadiusX,
69 samples[i].fRadiusY))->unref(); 81 samples[i].fRadiusY,
82 NULL,
83 cr))->unref();
70 } else { 84 } else {
71 paint.setImageFilter(new SkDilateImageFilter( 85 paint.setImageFilter(new SkDilateImageFilter(
72 samples[i].fRadiusX, 86 samples[i].fRadiusX,
73 samples[i].fRadiusY))->unref(); 87 samples[i].fRadiusY,
88 NULL,
89 cr))->unref();
74 } 90 }
75 SkRect bounds = SkRect::MakeXYWH( 91 drawClippedBitmap(canvas, paint, i * 140, j * 140);
76 x,
77 y,
78 SkIntToScalar(samples[i].fWidth),
79 SkIntToScalar(samples[i].fHeight));
80 canvas->saveLayer(&bounds, &paint);
81 canvas->drawBitmap(fBitmap, x, y);
82 canvas->restore();
83 } 92 }
84 } 93 }
85 } 94 }
86 95
87 private: 96 private:
88 typedef GM INHERITED; 97 typedef GM INHERITED;
89 SkBitmap fBitmap; 98 SkBitmap fBitmap;
90 bool fOnce; 99 bool fOnce;
91 }; 100 };
92 101
93 ////////////////////////////////////////////////////////////////////////////// 102 //////////////////////////////////////////////////////////////////////////////
94 103
95 static GM* MyFactory(void*) { return new MorphologyGM; } 104 static GM* MyFactory(void*) { return new MorphologyGM; }
96 static GMRegistry reg(MyFactory); 105 static GMRegistry reg(MyFactory);
97 106
98 } 107 }
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkMorphologyImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698