• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkSurface.h"
11 
12 DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
13     canvas->clear(SK_ColorBLACK);
14 
15     const SkSamplingOptions gSamplings[] = {
16         SkSamplingOptions(SkFilterMode::kNearest),
17         SkSamplingOptions(SkFilterMode::kLinear),
18         SkSamplingOptions(SkCubicResampler::Mitchell()),
19     };
20 
__anondb2934000102() 21     auto make_img = []() {
22         auto surf = SkSurface::MakeRasterN32Premul(7, 7);
23         surf->getCanvas()->drawColor(SK_ColorBLACK);
24 
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);
34     for (const auto& s : gSamplings) {
35         canvas->drawImage(img, 0, 0, s, nullptr);
36         canvas->translate(0, img->height() + 1.0f);
37     }
38 
39     const SkRect r = SkRect::MakeIWH(img->width(), img->height());
40     SkPaint paint;
41 
42     SkImage::CubicResampler cubics[] = {
43         SkCubicResampler::CatmullRom(),
44         SkCubicResampler::Mitchell(),
45     };
46     for (auto c : cubics) {
47         paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
48                                         SkSamplingOptions(c)));
49         canvas->drawRect(r, paint);
50         canvas->translate(0, img->height() + 1.0f);
51     }
52 }
53