1 // 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.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Image_scalePixels, 256, 128, false, 3) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 std::vector<int32_t> srcPixels;
7 int quarterWidth = image->width() / 16;
8 int rowBytes = quarterWidth * 4;
9 int quarterHeight = image->height() / 16;
10 srcPixels.resize(quarterHeight * rowBytes);
11 SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight),
12 &srcPixels.front(), rowBytes);
13 canvas->scale(4, 4);
14
15 const SkSamplingOptions samplings[] = {
16 SkSamplingOptions(),
17 SkSamplingOptions(SkFilterMode::kLinear),
18 SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
19 SkSamplingOptions({1.0f/3, 1.0f/3}),
20 };
21 for (unsigned index = 0; index < std::size(samplings); ++index) {
22 image->scalePixels(pixmap, samplings[index]);
23 sk_sp<SkImage> filtered = SkImages::RasterFromPixmap(pixmap, nullptr, nullptr);
24 canvas->drawImage(filtered, 16 * index, 0);
25 }
26 }
27 } // END FIDDLE
28