2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "sk_tool_utils.h"
10 #include "SkMorphologyImageFilter.h"
17 class MorphologyGM : public GM {
20 this->setBGColor(0xFF000000);
24 SkString onShortName() override {
25 return SkString("morphology");
28 void onOnceBeforeDraw() override {
29 fBitmap.allocN32Pixels(135, 135);
30 SkCanvas canvas(fBitmap);
33 paint.setAntiAlias(true);
34 sk_tool_utils::set_portable_typeface(&paint);
35 const char* str1 = "ABC";
36 const char* str2 = "XYZ";
37 paint.setColor(0xFFFFFFFF);
38 paint.setTextSize(64);
39 canvas.drawString(str1, 10, 55, paint);
40 canvas.drawString(str2, 10, 110, paint);
43 SkISize onISize() override {
44 return SkISize::Make(WIDTH, HEIGHT);
47 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
49 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
50 canvas->clipRect(SkRect::MakeWH(
51 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
52 canvas->drawBitmap(fBitmap, 0, 0, &paint);
56 void onDraw(SkCanvas* canvas) override {
59 int fRadiusX, fRadiusY;
68 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80));
70 for (unsigned j = 0; j < 4; ++j) {
71 for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) {
72 const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : nullptr;
74 paint.setImageFilter(SkErodeImageFilter::Make(samples[i].fRadiusX,
79 paint.setImageFilter(SkDilateImageFilter::Make(samples[i].fRadiusX,
84 this->drawClippedBitmap(canvas, paint, i * 140, j * 140);
95 //////////////////////////////////////////////////////////////////////////////
97 DEF_GM(return new MorphologyGM;)