blob: e40a2d985637116b8587e26633e727e58f39b898 [file] [log] [blame]
Mike Klein7cfcc1e2020-01-08 10:07:57 -06001/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
Mike Klein7cfcc1e2020-01-08 10:07:57 -06009#include "include/core/SkCanvas.h"
Kevin Lubick08fc9882023-01-30 16:05:54 -050010#include "include/core/SkSamplingOptions.h"
11#include "include/core/SkShader.h"
Mike Reed3d30ca62020-07-22 16:55:02 -040012#include "include/core/SkSurface.h"
Kevin Lubick08fc9882023-01-30 16:05:54 -050013#include "include/core/SkTileMode.h"
Mike Klein7cfcc1e2020-01-08 10:07:57 -060014
Mike Reed3d30ca62020-07-22 16:55:02 -040015DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
Mike Klein7cfcc1e2020-01-08 10:07:57 -060016 canvas->clear(SK_ColorBLACK);
17
Mike Reedc82ab082021-07-16 22:19:26 -040018 const SkSamplingOptions gSamplings[] = {
19 SkSamplingOptions(SkFilterMode::kNearest),
20 SkSamplingOptions(SkFilterMode::kLinear),
21 SkSamplingOptions(SkCubicResampler::Mitchell()),
22 };
23
Mike Reed3d30ca62020-07-22 16:55:02 -040024 auto make_img = []() {
Kevin Lubick5c93acf2023-05-09 12:11:43 -040025 auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(7, 7));
Mike Reed3d30ca62020-07-22 16:55:02 -040026 surf->getCanvas()->drawColor(SK_ColorBLACK);
Mike Klein7cfcc1e2020-01-08 10:07:57 -060027
Mike Reed3d30ca62020-07-22 16:55:02 -040028 SkPaint paint;
29 paint.setColor(SK_ColorWHITE);
30 surf->getCanvas()->drawLine(3.5f, 0, 3.5f, 8, paint);
31 return surf->makeImageSnapshot();
32 };
33
34 auto img = make_img();
35
36 canvas->scale(40, 8);
Mike Reedc82ab082021-07-16 22:19:26 -040037 for (const auto& s : gSamplings) {
38 canvas->drawImage(img, 0, 0, s, nullptr);
Mike Reed3d30ca62020-07-22 16:55:02 -040039 canvas->translate(0, img->height() + 1.0f);
40 }
41
42 const SkRect r = SkRect::MakeIWH(img->width(), img->height());
Mike Klein7cfcc1e2020-01-08 10:07:57 -060043 SkPaint paint;
Mike Klein7cfcc1e2020-01-08 10:07:57 -060044
Kevin Lubick08fc9882023-01-30 16:05:54 -050045 SkCubicResampler cubics[] = {
Mike Reedf3ac2af2021-02-05 12:55:38 -050046 SkCubicResampler::CatmullRom(),
47 SkCubicResampler::Mitchell(),
Mike Reed3d30ca62020-07-22 16:55:02 -040048 };
49 for (auto c : cubics) {
Mike Reeda03f8bf2020-11-20 18:45:36 -050050 paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
51 SkSamplingOptions(c)));
Mike Reed3d30ca62020-07-22 16:55:02 -040052 canvas->drawRect(r, paint);
53 canvas->translate(0, img->height() + 1.0f);
Mike Klein7cfcc1e2020-01-08 10:07:57 -060054 }
55}