blob: 52cc43ccec622ddee15c5ff4417c81a9a929179c [file] [log] [blame]
Hal Canary6c8422c2020-01-10 15:22:09 -05001// 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.
3#include "tools/fiddle/examples.h"
4REG_FIDDLE(subset_example, 512, 512, false, 3) {
5void draw(SkCanvas* canvas) {
6 canvas->drawColor(SK_ColorWHITE);
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->drawBitmap(subset, w * i, h * j);
25 }
26 }
27}
28} // END FIDDLE