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 // HASH=5949c9a63610cae30019e5b1899ee38f
5 REG_FIDDLE(Image_scalePixels, 256, 128, false, 3) {
draw(SkCanvas * canvas)6 void 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);
15 
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]);
24         sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
25         canvas->drawImage(filtered, 16 * index, 0);
26     }
27 }
28 }  // END FIDDLE
29