Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
subset_example.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (subset_example, 512, 512, false, 3)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( subset_example  ,
512  ,
512  ,
false  ,
 
)

Definition at line 4 of file subset_example.cpp.

4 {
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
double y
double x
SI Vec< sizeof...(Ix), T > shuffle(const Vec< N, T > &)
Definition SkVx.h:667
SkScalar w
SkScalar h
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104