2017-07-10 17:49:05 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBlurImageFilter.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
2017-07-10 17:49:05 +00:00
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(blurimagevmask, canvas, 700, 1200) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 25);
|
2017-07-10 17:49:05 +00:00
|
|
|
|
|
|
|
const double sigmas[] = {3.0, 8.0, 16.0, 24.0, 32.0};
|
|
|
|
|
2019-01-05 21:35:13 +00:00
|
|
|
canvas->drawString("mask blur", 285, 50, font, paint);
|
|
|
|
canvas->drawString("image blur", 285 + 250, 50, font, paint);
|
2017-07-10 17:49:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
SkRect r = {35, 100, 135, 200};
|
|
|
|
for (auto sigma:sigmas) {
|
|
|
|
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
char out[100];
|
|
|
|
sprintf(out, "Sigma: %g", sigma);
|
2019-01-05 21:35:13 +00:00
|
|
|
canvas->drawString(out, r.left(), r.bottom() + 35, font, paint);
|
2017-07-10 17:49:05 +00:00
|
|
|
|
|
|
|
r.offset(250, 0);
|
|
|
|
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
|
2017-07-10 17:49:05 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
paint.setMaskFilter(nullptr);
|
|
|
|
|
|
|
|
SkPaint imageBlurPaint;
|
|
|
|
r.offset(250, 0);
|
|
|
|
imageBlurPaint.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
|
|
|
|
canvas->saveLayer(nullptr, &imageBlurPaint);
|
|
|
|
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->restore();
|
|
|
|
r.offset(-500, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-01-18 04:04:04 +00:00
|
|
|
|
|
|
|
#include "Resources.h"
|
2019-02-07 23:20:09 +00:00
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(blur_image, canvas, errorMsg, 500, 500) {
|
2018-01-18 04:04:04 +00:00
|
|
|
auto image = GetResourceAsImage("images/mandrill_128.png");
|
2018-11-26 20:34:12 +00:00
|
|
|
if (!image) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Could not load mandrill_128.png. Did you forget to set the resourcePath?";
|
|
|
|
return skiagm::DrawResult::kFail;
|
2018-11-26 20:34:12 +00:00
|
|
|
}
|
2018-01-18 04:04:04 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 4));
|
2018-01-18 04:04:04 +00:00
|
|
|
|
|
|
|
// both of these should draw with the blur, but (formerally) we had a bug where the unscaled
|
|
|
|
// version (taking the spriteblitter code path) ignore the maskfilter.
|
|
|
|
|
|
|
|
canvas->drawImage(image, 10, 10, &paint);
|
|
|
|
canvas->scale(1.01f, 1.01f);
|
|
|
|
canvas->drawImage(image, 10 + image->width() + 10.f, 10, &paint);
|
2019-02-07 23:20:09 +00:00
|
|
|
return skiagm::DrawResult::kOk;
|
2018-01-18 04:04:04 +00:00
|
|
|
}
|