Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Image_scalePixels.cpp
Go to the documentation of this file.
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.
4// HASH=5949c9a63610cae30019e5b1899ee38f
5REG_FIDDLE(Image_scalePixels, 256, 128, false, 3) {
6void 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[] = {
20 SkSamplingOptions({1.0f/3, 1.0f/3}),
21 };
22 for (unsigned index = 0; index < std::size(samplings); ++index) {
23 image->scalePixels(pixmap, samplings[index]);
24 sk_sp<SkImage> filtered = SkImages::RasterFromPixmap(pixmap, nullptr, nullptr);
25 canvas->drawImage(filtered, 16 * index, 0);
26 }
27}
28} // END FIDDLE
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
void scale(SkScalar sx, SkScalar sy)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
bool scalePixels(const SkPixmap &dst, const SkSamplingOptions &, CachingHint cachingHint=kAllow_CachingHint) const
Definition SkImage.cpp:127
sk_sp< SkImage > image
Definition examples.cpp:29
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
static SkImageInfo MakeN32Premul(int width, int height)