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(Pixmap_scalePixels, 256, 256, false, 3) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height());
7 std::vector<int32_t> srcPixels;
8 int rowBytes = image->width() * 4;
9 srcPixels.resize(image->height() * rowBytes);
10 SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes);
11 image->readPixels(nullptr, pixmap, 0, 0);
12 for (int offset : { 32, 64, 96 } ) {
13 info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height());
14 rowBytes = info.width() * 4;
15 std::vector<int32_t> dstPixels;
16 dstPixels.resize(image->height() * rowBytes);
17 SkPixmap dstmap(info, &dstPixels.front(), rowBytes);
18 pixmap.scalePixels(dstmap, SkSamplingOptions(SkFilterMode::kLinear,
19 SkMipmapMode::kNearest));
20 SkBitmap bitmap;
21 bitmap.installPixels(dstmap);
22 canvas->translate(32, 32);
23 canvas->drawImage(bitmap.asImage(), 0, 0);
24 }
25 }
26 } // END FIDDLE
27