2012-03-02 21:05:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkMorphologyImageFilter.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
|
|
|
#include "gm.h"
|
2012-03-02 21:05:45 +00:00
|
|
|
|
2013-09-17 13:41:43 +00:00
|
|
|
#define WIDTH 700
|
|
|
|
#define HEIGHT 560
|
2012-03-02 21:05:45 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class MorphologyGM : public GM {
|
|
|
|
public:
|
|
|
|
MorphologyGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-02 21:05:45 +00:00
|
|
|
protected:
|
2016-03-25 11:49:22 +00:00
|
|
|
SkString onShortName() override {
|
2012-03-02 21:05:45 +00:00
|
|
|
return SkString("morphology");
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:49:22 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-01-25 16:46:20 +00:00
|
|
|
fBitmap.allocN32Pixels(135, 135);
|
2014-02-13 17:14:46 +00:00
|
|
|
SkCanvas canvas(fBitmap);
|
2012-03-02 21:05:45 +00:00
|
|
|
canvas.clear(0x0);
|
2019-01-08 14:38:02 +00:00
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 64.0f);
|
2012-03-02 21:05:45 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFFFFFFFF);
|
2019-01-08 14:38:02 +00:00
|
|
|
canvas.drawString("ABC", 10, 55, font, paint);
|
|
|
|
canvas.drawString("XYZ", 10, 110, font, paint);
|
2012-03-02 21:05:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-25 11:49:22 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
2012-03-02 21:05:45 +00:00
|
|
|
}
|
2013-09-17 13:41:43 +00:00
|
|
|
|
|
|
|
void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
canvas->clipRect(SkRect::MakeWH(
|
|
|
|
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
|
|
|
|
canvas->drawBitmap(fBitmap, 0, 0, &paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:49:22 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-03-02 21:05:45 +00:00
|
|
|
struct {
|
2012-04-10 17:25:44 +00:00
|
|
|
int fWidth, fHeight;
|
2012-03-02 21:05:45 +00:00
|
|
|
int fRadiusX, fRadiusY;
|
|
|
|
} samples[] = {
|
2012-04-10 17:25:44 +00:00
|
|
|
{ 140, 140, 0, 0 },
|
|
|
|
{ 140, 140, 0, 2 },
|
|
|
|
{ 140, 140, 2, 0 },
|
|
|
|
{ 140, 140, 2, 2 },
|
|
|
|
{ 24, 24, 25, 25 },
|
2012-03-02 21:05:45 +00:00
|
|
|
};
|
|
|
|
SkPaint paint;
|
2013-10-10 13:51:19 +00:00
|
|
|
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80));
|
2013-09-17 13:41:43 +00:00
|
|
|
|
|
|
|
for (unsigned j = 0; j < 4; ++j) {
|
2012-04-10 17:25:44 +00:00
|
|
|
for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) {
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : nullptr;
|
2013-09-17 13:41:43 +00:00
|
|
|
if (j & 0x01) {
|
2016-04-05 16:09:36 +00:00
|
|
|
paint.setImageFilter(SkErodeImageFilter::Make(samples[i].fRadiusX,
|
|
|
|
samples[i].fRadiusY,
|
|
|
|
nullptr,
|
|
|
|
cr));
|
2012-04-10 17:25:44 +00:00
|
|
|
} else {
|
2016-04-05 16:09:36 +00:00
|
|
|
paint.setImageFilter(SkDilateImageFilter::Make(samples[i].fRadiusX,
|
|
|
|
samples[i].fRadiusY,
|
|
|
|
nullptr,
|
|
|
|
cr));
|
2012-04-10 17:25:44 +00:00
|
|
|
}
|
2016-03-25 11:49:22 +00:00
|
|
|
this->drawClippedBitmap(canvas, paint, i * 140, j * 140);
|
2012-03-02 21:05:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-02 21:05:45 +00:00
|
|
|
private:
|
|
|
|
SkBitmap fBitmap;
|
2016-03-25 11:49:22 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
2012-03-02 21:05:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-03-25 11:49:22 +00:00
|
|
|
DEF_GM(return new MorphologyGM;)
|
2012-03-02 21:05:45 +00:00
|
|
|
|
|
|
|
}
|