Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 1 | /* |
| 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 Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 10 | #include "include/core/SkSurface.h" |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 11 | |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 12 | DEF_SIMPLE_GM(bicubic, canvas, 300, 320) { |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 13 | canvas->clear(SK_ColorBLACK); |
| 14 | |
Mike Reed | c82ab08 | 2021-07-16 22:19:26 -0400 | [diff] [blame] | 15 | const SkSamplingOptions gSamplings[] = { |
| 16 | SkSamplingOptions(SkFilterMode::kNearest), |
| 17 | SkSamplingOptions(SkFilterMode::kLinear), |
| 18 | SkSamplingOptions(SkCubicResampler::Mitchell()), |
| 19 | }; |
| 20 | |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 21 | auto make_img = []() { |
| 22 | auto surf = SkSurface::MakeRasterN32Premul(7, 7); |
| 23 | surf->getCanvas()->drawColor(SK_ColorBLACK); |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 24 | |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 25 | 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 Reed | c82ab08 | 2021-07-16 22:19:26 -0400 | [diff] [blame] | 34 | for (const auto& s : gSamplings) { |
| 35 | canvas->drawImage(img, 0, 0, s, nullptr); |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 36 | canvas->translate(0, img->height() + 1.0f); |
| 37 | } |
| 38 | |
| 39 | const SkRect r = SkRect::MakeIWH(img->width(), img->height()); |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 40 | SkPaint paint; |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 41 | |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 42 | SkImage::CubicResampler cubics[] = { |
Mike Reed | f3ac2af | 2021-02-05 12:55:38 -0500 | [diff] [blame] | 43 | SkCubicResampler::CatmullRom(), |
| 44 | SkCubicResampler::Mitchell(), |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 45 | }; |
| 46 | for (auto c : cubics) { |
Mike Reed | a03f8bf | 2020-11-20 18:45:36 -0500 | [diff] [blame] | 47 | paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, |
| 48 | SkSamplingOptions(c))); |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 49 | canvas->drawRect(r, paint); |
| 50 | canvas->translate(0, img->height() + 1.0f); |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 51 | } |
| 52 | } |