blob: 48a7eb3155dccea7fb6e675b914d796d391d6aa7 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=5949c9a63610cae30019e5b1899ee38f
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Image_scalePixels, 256, 128, false, 3) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 std::vector<int32_t> srcPixels;
8 int quarterWidth = image->width() / 16;
9 int rowBytes = quarterWidth * 4;
10 int quarterHeight = image->height() / 16;
11 srcPixels.resize(quarterHeight * rowBytes);
12 SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight),
13 &srcPixels.front(), rowBytes);
14 canvas->scale(4, 4);
Mike Reedb339d052021-01-28 11:20:41 -050015
16 const SkSamplingOptions samplings[] = {
17 SkSamplingOptions(),
18 SkSamplingOptions(SkFilterMode::kLinear),
19 SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
20 SkSamplingOptions({1.0f/3, 1.0f/3}),
21 };
22 for (unsigned index = 0; index < SK_ARRAY_COUNT(samplings); ++index) {
23 image->scalePixels(pixmap, samplings[index]);
Hal Canary87515122019-03-15 14:22:51 -040024 sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
25 canvas->drawImage(filtered, 16 * index, 0);
26 }
27}
28} // END FIDDLE