| 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 "tools/fiddle/examples.h" |
| 4 |
|
| 5 |
#include <climits> |
| 6 |
#include <random> |
| 7 |
|
| 8 |
REG_FIDDLE(Bitmap_installPixels_2, 256, 256, false, 0) { |
| 9 |
void draw(SkCanvas* canvas) { |
| 10 |
std::default_random_engine rng; |
| 11 |
const auto randUint = [&rng](uint32_t min, uint32_t max) -> uint32_t { |
| 12 |
return std::uniform_int_distribution<uint32_t>(min, max)(rng); |
| 13 |
}; |
| 14 |
SkBitmap bitmap; |
| 15 |
const int width = 8; |
| 16 |
const int height = 8; |
| 17 |
uint32_t pixels[width * height]; |
| 18 |
for (unsigned x = 0; x < width * height; ++x) { |
| 19 |
pixels[x] = randUint(0, UINT_MAX); |
| 20 |
} |
| 21 |
SkImageInfo info = SkImageInfo::MakeN32(width, height, kUnpremul_SkAlphaType); |
| 22 |
if (bitmap.installPixels(info, pixels, info.minRowBytes())) { |
| 23 |
canvas->scale(32, 32); |
| 24 |
canvas->drawImage(bitmap.asImage(), 0, 0); |
| 25 |
} |
| 26 |
} |
| 27 |
} // END FIDDLE |