2 * Copyright 2020 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkSurface.h"
12 DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
13 canvas->clear(SK_ColorBLACK);
15 const SkSamplingOptions gSamplings[] = {
16 SkSamplingOptions(SkFilterMode::kNearest),
17 SkSamplingOptions(SkFilterMode::kLinear),
18 SkSamplingOptions(SkCubicResampler::Mitchell()),
21 auto make_img = []() {
22 auto surf = SkSurface::MakeRasterN32Premul(7, 7);
23 surf->getCanvas()->drawColor(SK_ColorBLACK);
26 paint.setColor(SK_ColorWHITE);
27 surf->getCanvas()->drawLine(3.5f, 0, 3.5f, 8, paint);
28 return surf->makeImageSnapshot();
31 auto img = make_img();
34 for (const auto& s : gSamplings) {
35 canvas->drawImage(img, 0, 0, s, nullptr);
36 canvas->translate(0, img->height() + 1.0f);
39 const SkRect r = SkRect::MakeIWH(img->width(), img->height());
42 SkImage::CubicResampler cubics[] = {
43 SkCubicResampler::CatmullRom(),
44 SkCubicResampler::Mitchell(),
46 for (auto c : cubics) {
47 paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
48 SkSamplingOptions(c)));
49 canvas->drawRect(r, paint);
50 canvas->translate(0, img->height() + 1.0f);