Hal Canary | 83c2f70 | 2019-03-07 14:53:03 -0500 | [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. |
| 3 | #include "fiddle/examples.h" |
| 4 | // HASH=5949c9a63610cae30019e5b1899ee38f |
| 5 | REG_FIDDLE(Image_031, 256, 128, false, 3) { |
| 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 | SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 16 | kMedium_SkFilterQuality, kHigh_SkFilterQuality }; |
| 17 | for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) { |
| 18 | image->scalePixels(pixmap, qualities[index]); |
| 19 | sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); |
| 20 | canvas->drawImage(filtered, 16 * index, 0); |
| 21 | } |
| 22 | } |
| 23 | } // END FIDDLE |