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 | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 15 | auto make_img = []() { |
| 16 | auto surf = SkSurface::MakeRasterN32Premul(7, 7); |
| 17 | surf->getCanvas()->drawColor(SK_ColorBLACK); |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 18 | |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 19 | SkPaint paint; |
| 20 | paint.setColor(SK_ColorWHITE); |
| 21 | surf->getCanvas()->drawLine(3.5f, 0, 3.5f, 8, paint); |
| 22 | return surf->makeImageSnapshot(); |
| 23 | }; |
| 24 | |
| 25 | auto img = make_img(); |
| 26 | |
| 27 | canvas->scale(40, 8); |
| 28 | for (auto q : {kNone_SkFilterQuality, kLow_SkFilterQuality, kHigh_SkFilterQuality}) { |
| 29 | SkPaint p; |
| 30 | p.setFilterQuality(q); |
| 31 | canvas->drawImage(img, 0, 0, &p); |
| 32 | canvas->translate(0, img->height() + 1.0f); |
| 33 | } |
| 34 | |
| 35 | const SkRect r = SkRect::MakeIWH(img->width(), img->height()); |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 36 | SkPaint paint; |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 37 | |
Mike Reed | 3d30ca6 | 2020-07-22 16:55:02 -0400 | [diff] [blame] | 38 | SkImage::CubicResampler cubics[] = { |
| 39 | { 0, 1.0f/2 }, |
| 40 | { 1.0f/3, 1.0f/3 }, |
| 41 | }; |
| 42 | for (auto c : cubics) { |
| 43 | paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, c)); |
| 44 | canvas->drawRect(r, paint); |
| 45 | canvas->translate(0, img->height() + 1.0f); |
Mike Klein | 7cfcc1e | 2020-01-08 10:07:57 -0600 | [diff] [blame] | 46 | } |
| 47 | } |