c82ab0839f
Change-Id: I67d1a464618f1a54f4e3bd4e1409b1d91a90e66a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/429336 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
/*
|
|
* 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"
|
|
#include "include/core/SkSurface.h"
|
|
|
|
DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
const SkSamplingOptions gSamplings[] = {
|
|
SkSamplingOptions(SkFilterMode::kNearest),
|
|
SkSamplingOptions(SkFilterMode::kLinear),
|
|
SkSamplingOptions(SkCubicResampler::Mitchell()),
|
|
};
|
|
|
|
auto make_img = []() {
|
|
auto surf = SkSurface::MakeRasterN32Premul(7, 7);
|
|
surf->getCanvas()->drawColor(SK_ColorBLACK);
|
|
|
|
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);
|
|
for (const auto& s : gSamplings) {
|
|
canvas->drawImage(img, 0, 0, s, nullptr);
|
|
canvas->translate(0, img->height() + 1.0f);
|
|
}
|
|
|
|
const SkRect r = SkRect::MakeIWH(img->width(), img->height());
|
|
SkPaint paint;
|
|
|
|
SkImage::CubicResampler cubics[] = {
|
|
SkCubicResampler::CatmullRom(),
|
|
SkCubicResampler::Mitchell(),
|
|
};
|
|
for (auto c : cubics) {
|
|
paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
|
|
SkSamplingOptions(c)));
|
|
canvas->drawRect(r, paint);
|
|
canvas->translate(0, img->height() + 1.0f);
|
|
}
|
|
}
|