blob: 2571920d06c80a0d29d594e3dca96ed97307705e [file] [log] [blame]
Mike Klein7cfcc1e2020-01-08 10:07:57 -06001/*
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 Klein7cfcc1e2020-01-08 10:07:57 -06009#include "include/core/SkCanvas.h"
Mike Reed3d30ca62020-07-22 16:55:02 -040010#include "include/core/SkSurface.h"
Mike Klein7cfcc1e2020-01-08 10:07:57 -060011
Mike Reed3d30ca62020-07-22 16:55:02 -040012DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
Mike Klein7cfcc1e2020-01-08 10:07:57 -060013 canvas->clear(SK_ColorBLACK);
14
Mike Reed3d30ca62020-07-22 16:55:02 -040015 auto make_img = []() {
16 auto surf = SkSurface::MakeRasterN32Premul(7, 7);
17 surf->getCanvas()->drawColor(SK_ColorBLACK);
Mike Klein7cfcc1e2020-01-08 10:07:57 -060018
Mike Reed3d30ca62020-07-22 16:55:02 -040019 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 Klein7cfcc1e2020-01-08 10:07:57 -060036 SkPaint paint;
Mike Klein7cfcc1e2020-01-08 10:07:57 -060037
Mike Reed3d30ca62020-07-22 16:55:02 -040038 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 Klein7cfcc1e2020-01-08 10:07:57 -060046 }
47}