2017-06-26 22:03:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 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/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.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"
|
2017-06-26 22:03:55 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <utility>
|
|
|
|
|
2017-06-26 22:03:55 +00:00
|
|
|
static sk_sp<SkImage> make_image(SkCanvas* canvas) {
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(250, 200);
|
2019-03-20 16:12:10 +00:00
|
|
|
auto surface = ToolUtils::makeSurface(canvas, info);
|
2017-06-26 22:03:55 +00:00
|
|
|
SkCanvas* c = surface->getCanvas();
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
c->drawRect(SkRect::MakeIWH(info.width(), info.height()), paint);
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
c->drawCircle(125, 100, 100, paint);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
c->drawRect(SkRect::MakeIWH(80, 80), paint);
|
|
|
|
|
|
|
|
return surface->makeImageSnapshot();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_image(SkCanvas* canvas, const sk_sp<SkImage> image, sk_sp<SkImageFilter> filter) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(std::move(filter));
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(30), 0);
|
2021-01-24 13:57:23 +00:00
|
|
|
canvas->clipIRect(image->bounds());
|
2021-01-23 17:23:23 +00:00
|
|
|
canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
|
2017-06-26 22:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// This GM draws one rectangle, one green inscribed circle, and one red square
|
|
|
|
// with different blur settings.
|
|
|
|
class ImageBlurClampModeGM : public GM {
|
|
|
|
public:
|
|
|
|
ImageBlurClampModeGM() {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFCCCCCC);
|
2017-06-26 22:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("imageblurclampmode");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(850, 920);
|
|
|
|
}
|
|
|
|
|
2017-06-30 17:44:45 +00:00
|
|
|
bool runAsBench() const override { return true; }
|
|
|
|
|
2017-06-26 22:03:55 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
sk_sp<SkImage> image(make_image(canvas));
|
2018-04-25 13:13:28 +00:00
|
|
|
sk_sp<SkImageFilter> filter;
|
2017-06-26 22:03:55 +00:00
|
|
|
|
|
|
|
canvas->translate(0, 30);
|
|
|
|
// Test different kernel size, including the one to launch 2d Gaussian
|
|
|
|
// blur.
|
|
|
|
for (auto sigma: { 0.6f, 3.0f, 8.0f, 20.0f }) {
|
|
|
|
canvas->save();
|
2018-04-25 13:13:28 +00:00
|
|
|
|
|
|
|
// x-only blur
|
2019-08-02 19:21:23 +00:00
|
|
|
filter = SkImageFilters::Blur(sigma, 0.0f, SkTileMode::kClamp, nullptr);
|
2017-06-26 22:03:55 +00:00
|
|
|
draw_image(canvas, image, std::move(filter));
|
|
|
|
canvas->translate(image->width() + 20, 0);
|
|
|
|
|
2018-04-25 13:13:28 +00:00
|
|
|
// y-only blur
|
2019-08-02 19:21:23 +00:00
|
|
|
filter = SkImageFilters::Blur(0.0f, sigma, SkTileMode::kClamp, nullptr);
|
2017-06-26 22:03:55 +00:00
|
|
|
draw_image(canvas, image, std::move(filter));
|
|
|
|
canvas->translate(image->width() + 20, 0);
|
|
|
|
|
2018-04-25 13:13:28 +00:00
|
|
|
// both directions
|
2019-08-02 19:21:23 +00:00
|
|
|
filter = SkImageFilters::Blur(sigma, sigma, SkTileMode::kClamp, nullptr);
|
2017-06-26 22:03:55 +00:00
|
|
|
draw_image(canvas, image, std::move(filter));
|
|
|
|
canvas->translate(image->width() + 20, 0);
|
|
|
|
|
|
|
|
canvas->restore();
|
2018-04-25 13:13:28 +00:00
|
|
|
|
2017-06-26 22:03:55 +00:00
|
|
|
canvas->translate(0, image->height() + 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2017-06-26 22:03:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ImageBlurClampModeGM;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|