• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 REG_FIDDLE(Pixmap_getColor, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     const int w = 4;
7     const int h = 4;
8     std::vector<SkPMColor> storage;
9     storage.resize(w * h);
10     SkDebugf("Premultiplied:\n");
11     for (int y = 0; y < h; ++y) {
12         SkDebugf("(0, %d) ", y);
13         for (int x = 0; x < w; ++x) {
14             const int a = 0xFF * (x + y) / (w - 1 + h - 1),
15                       r = 0xFF * x / (w - 1),
16                       g = 0xFF * y / (h - 1),
17                       b = 0xFF;
18             storage[x + y * w] = SkPreMultiplyColor(SkColorSetARGB(a, r, g, b));
19             SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' ');
20         }
21     }
22     SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);
23     SkDebugf("Unpremultiplied:\n");
24     for (int y = 0; y < h; ++y) {
25         SkDebugf("(0, %d) ", y);
26         for (int x = 0; x < w; ++x) {
27             SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
28         }
29     }
30 }
31 }  // END FIDDLE
32