Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=5949c9a63610cae30019e5b1899ee38f |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Image_scalePixels, 256, 128, false, 3) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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); |
Mike Reed | b339d05 | 2021-01-28 11:20:41 -0500 | [diff] [blame] | 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]); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 24 | sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); |
| 25 | canvas->drawImage(filtered, 16 * index, 0); |
| 26 | } |
| 27 | } |
| 28 | } // END FIDDLE |