2015-10-14 11:53:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.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"
|
2015-10-14 11:53:31 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> make_image(SkCanvas* rootCanvas) {
|
2015-10-14 11:53:31 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
|
2019-03-20 16:12:10 +00:00
|
|
|
auto surface(ToolUtils::makeSurface(rootCanvas, info));
|
2015-10-14 11:53:31 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
surface->getCanvas()->drawCircle(50, 50, 50, paint);
|
2016-03-17 17:51:11 +00:00
|
|
|
return surface->makeImageSnapshot();
|
2015-10-14 11:53:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 22:15:50 +00:00
|
|
|
static void show_image(SkCanvas* canvas, SkImage* image, sk_sp<SkImageFilter> filter) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
SkRect r = SkRect::MakeIWH(image->width(), image->height()).makeOutset(SK_ScalarHalf,
|
|
|
|
SK_ScalarHalf);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setImageFilter(filter);
|
|
|
|
canvas->drawImage(image, 0, 0, &paint);
|
|
|
|
}
|
|
|
|
|
2016-04-05 16:09:36 +00:00
|
|
|
typedef sk_sp<SkImageFilter> (*ImageFilterFactory)();
|
2015-10-14 11:53:31 +00:00
|
|
|
|
|
|
|
// Show the effect of localmatriximagefilter with various matrices, on various filters
|
2017-01-12 22:15:50 +00:00
|
|
|
DEF_SIMPLE_GM(localmatriximagefilter, canvas, 640, 640) {
|
|
|
|
sk_sp<SkImage> image0(make_image(canvas));
|
|
|
|
|
|
|
|
const ImageFilterFactory factories[] = {
|
2019-08-02 19:21:23 +00:00
|
|
|
[]{ return SkImageFilters::Blur(8, 8, nullptr); },
|
|
|
|
[]{ return SkImageFilters::Dilate(8, 8, nullptr); },
|
|
|
|
[]{ return SkImageFilters::Erode(8, 8, nullptr); },
|
|
|
|
[]{ return SkImageFilters::Offset(8, 8, nullptr); },
|
2017-01-12 22:15:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkMatrix matrices[] = {
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix::Scale(SK_ScalarHalf, SK_ScalarHalf),
|
|
|
|
SkMatrix::Scale(2, 2),
|
|
|
|
SkMatrix::Translate(10, 10)
|
2017-01-12 22:15:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkScalar spacer = image0->width() * 3.0f / 2;
|
|
|
|
|
|
|
|
canvas->translate(40, 40);
|
|
|
|
for (auto&& factory : factories) {
|
|
|
|
sk_sp<SkImageFilter> filter(factory());
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
show_image(canvas, image0.get(), filter);
|
|
|
|
for (const auto& matrix : matrices) {
|
|
|
|
sk_sp<SkImageFilter> localFilter(filter->makeWithLocalMatrix(matrix));
|
|
|
|
canvas->translate(spacer, 0);
|
|
|
|
show_image(canvas, image0.get(), std::move(localFilter));
|
2015-10-14 11:53:31 +00:00
|
|
|
}
|
2017-01-12 22:15:50 +00:00
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, spacer);
|
2015-10-14 11:53:31 +00:00
|
|
|
}
|
2017-01-12 22:15:50 +00:00
|
|
|
}
|