Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
subset_example.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(subset_example, 512, 512, false, 3) {
5void draw(SkCanvas* canvas) {
7 const int N = 8;
8 int shuffle[N * N];
9 for (int i = 0; i < (N * N); ++i) {
10 shuffle[i] = i;
11 }
12 srand(0);
13 for (int i = 0; i < (N * N); ++i) {
14 std::swap(shuffle[i], shuffle[rand() % (N * N - i) + i]);
15 }
16 int w = (source.width() - 1) / N + 1;
17 int h = (source.height() - 1) / N + 1;
18 for (int i = 0; i < N; ++i) {
19 for (int j = 0; j < N; ++j) {
20 int x = shuffle[(N * i) + j] % N;
21 int y = shuffle[(N * i) + j] / N;
22 SkBitmap subset;
23 source.extractSubset(&subset, SkIRect::MakeXYWH(w * x, h * y, w, h));
24 canvas->drawImage(subset.asImage(), w * i, h * j);
25 }
26 }
27}
28} // END FIDDLE
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
#define N
Definition beziers.cpp:19
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Definition SkBitmap.cpp:453
int width() const
Definition SkBitmap.h:149
int height() const
Definition SkBitmap.h:158
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
SkBitmap source
Definition examples.cpp:28
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
double y
double x
SkScalar w
SkScalar h
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104