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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.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;
|
2019-08-02 19:21:23 +00:00
|
|
|
SkIRect cropRect = SkIRect::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) {
|
2019-08-02 19:21:23 +00:00
|
|
|
const SkIRect* cr = j & 0x02 ? &cropRect : nullptr;
|
2013-09-17 13:41:43 +00:00
|
|
|
if (j & 0x01) {
|
2019-08-02 19:21:23 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::Erode(
|
|
|
|
samples[i].fRadiusX, samples[i].fRadiusY, nullptr, cr));
|
2012-04-10 17:25:44 +00:00
|
|
|
} else {
|
2019-08-05 14:24:49 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::Dilate(
|
2019-08-02 19:21:23 +00:00
|
|
|
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
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|