blob: 6a2f8af9255a705e904d2e3bd872772cc71ce342 [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"
Mike Reed3d30ca62020-07-22 16:55:02 -040010#include "include/core/SkSurface.h"
Mike Klein7cfcc1e2020-01-08 10:07:57 -060011
Mike Reed3d30ca62020-07-22 16:55:02 -040012DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
Mike Klein7cfcc1e2020-01-08 10:07:57 -060013 canvas->clear(SK_ColorBLACK);
14
Mike Reedc82ab082021-07-16 22:19:26 -040015 const SkSamplingOptions gSamplings[] = {
16 SkSamplingOptions(SkFilterMode::kNearest),
17 SkSamplingOptions(SkFilterMode::kLinear),
18 SkSamplingOptions(SkCubicResampler::Mitchell()),
19 };
20
Mike Reed3d30ca62020-07-22 16:55:02 -040021 auto make_img = []() {
22 auto surf = SkSurface::MakeRasterN32Premul(7, 7);
23 surf->getCanvas()->drawColor(SK_ColorBLACK);
Mike Klein7cfcc1e2020-01-08 10:07:57 -060024
Mike Reed3d30ca62020-07-22 16:55:02 -040025 SkPaint paint;
26 paint.setColor(SK_ColorWHITE);
27 surf->getCanvas()->drawLine(3.5f, 0, 3.5f, 8, paint);
28 return surf->makeImageSnapshot();
29 };
30
31 auto img = make_img();
32
33 canvas->scale(40, 8);
Mike Reedc82ab082021-07-16 22:19:26 -040034 for (const auto& s : gSamplings) {
35 canvas->drawImage(img, 0, 0, s, nullptr);
Mike Reed3d30ca62020-07-22 16:55:02 -040036 canvas->translate(0, img->height() + 1.0f);
37 }
38
39 const SkRect r = SkRect::MakeIWH(img->width(), img->height());
Mike Klein7cfcc1e2020-01-08 10:07:57 -060040 SkPaint paint;
Mike Klein7cfcc1e2020-01-08 10:07:57 -060041
Mike Reed3d30ca62020-07-22 16:55:02 -040042 SkImage::CubicResampler cubics[] = {
Mike Reedf3ac2af2021-02-05 12:55:38 -050043 SkCubicResampler::CatmullRom(),
44 SkCubicResampler::Mitchell(),
Mike Reed3d30ca62020-07-22 16:55:02 -040045 };
46 for (auto c : cubics) {
Mike Reeda03f8bf2020-11-20 18:45:36 -050047 paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
48 SkSamplingOptions(c)));
Mike Reed3d30ca62020-07-22 16:55:02 -040049 canvas->drawRect(r, paint);
50 canvas->translate(0, img->height() + 1.0f);
Mike Klein7cfcc1e2020-01-08 10:07:57 -060051 }
52}