2020-01-08 16:07:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2020-07-22 20:55:02 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2020-01-08 16:07:57 +00:00
|
|
|
|
2020-07-22 20:55:02 +00:00
|
|
|
DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
|
2020-01-08 16:07:57 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
|
2021-07-17 02:19:26 +00:00
|
|
|
const SkSamplingOptions gSamplings[] = {
|
|
|
|
SkSamplingOptions(SkFilterMode::kNearest),
|
|
|
|
SkSamplingOptions(SkFilterMode::kLinear),
|
|
|
|
SkSamplingOptions(SkCubicResampler::Mitchell()),
|
|
|
|
};
|
|
|
|
|
2020-07-22 20:55:02 +00:00
|
|
|
auto make_img = []() {
|
|
|
|
auto surf = SkSurface::MakeRasterN32Premul(7, 7);
|
|
|
|
surf->getCanvas()->drawColor(SK_ColorBLACK);
|
2020-01-08 16:07:57 +00:00
|
|
|
|
2020-07-22 20:55:02 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
surf->getCanvas()->drawLine(3.5f, 0, 3.5f, 8, paint);
|
|
|
|
return surf->makeImageSnapshot();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto img = make_img();
|
|
|
|
|
|
|
|
canvas->scale(40, 8);
|
2021-07-17 02:19:26 +00:00
|
|
|
for (const auto& s : gSamplings) {
|
|
|
|
canvas->drawImage(img, 0, 0, s, nullptr);
|
2020-07-22 20:55:02 +00:00
|
|
|
canvas->translate(0, img->height() + 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkRect r = SkRect::MakeIWH(img->width(), img->height());
|
2020-01-08 16:07:57 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
2020-07-22 20:55:02 +00:00
|
|
|
SkImage::CubicResampler cubics[] = {
|
2021-02-05 17:55:38 +00:00
|
|
|
SkCubicResampler::CatmullRom(),
|
|
|
|
SkCubicResampler::Mitchell(),
|
2020-07-22 20:55:02 +00:00
|
|
|
};
|
|
|
|
for (auto c : cubics) {
|
2020-11-20 23:45:36 +00:00
|
|
|
paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
|
|
|
|
SkSamplingOptions(c)));
|
2020-07-22 20:55:02 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->translate(0, img->height() + 1.0f);
|
2020-01-08 16:07:57 +00:00
|
|
|
}
|
|
|
|
}
|