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/SkSamplingOptions.h" 11 #include "include/core/SkShader.h" 12 #include "include/core/SkSurface.h" 13 #include "include/core/SkTileMode.h" 14 15 DEF_SIMPLE_GM(bicubic, canvas, 300, 320) { 16 canvas->clear(SK_ColorBLACK); 17 18 const SkSamplingOptions gSamplings[] = { 19 SkSamplingOptions(SkFilterMode::kNearest), 20 SkSamplingOptions(SkFilterMode::kLinear), 21 SkSamplingOptions(SkCubicResampler::Mitchell()), 22 }; 23 __anoncda9aee30102() 24 auto make_img = []() { 25 auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(7, 7)); 26 surf->getCanvas()->drawColor(SK_ColorBLACK); 27 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); 37 for (const auto& s : gSamplings) { 38 canvas->drawImage(img, 0, 0, s, nullptr); 39 canvas->translate(0, img->height() + 1.0f); 40 } 41 42 const SkRect r = SkRect::MakeIWH(img->width(), img->height()); 43 SkPaint paint; 44 45 SkCubicResampler cubics[] = { 46 SkCubicResampler::CatmullRom(), 47 SkCubicResampler::Mitchell(), 48 }; 49 for (auto c : cubics) { 50 paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, 51 SkSamplingOptions(c))); 52 canvas->drawRect(r, paint); 53 canvas->translate(0, img->height() + 1.0f); 54 } 55 } 56