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