• 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(Bitmap_getColor, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     const int w = 4;
7     const int h = 4;
8     SkColor colors[][w] = {
9         { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
10         { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
11         { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
12         { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
13     };
14     SkDebugf("Premultiplied:\n");
15     for (int y = 0; y < h; ++y) {
16         SkDebugf("(0, %d) ", y);
17         for (int x = 0; x < w; ++x) {
18             SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' ');
19         }
20     }
21     SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);
22     SkBitmap bitmap;
23     bitmap.installPixels(pixmap);
24     SkDebugf("Unpremultiplied:\n");
25     for (int y = 0; y < h; ++y) {
26         SkDebugf("(0, %d) ", y);
27         for (int x = 0; x < w; ++x) {
28             SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
29         }
30     }
31 }
32 }  // END FIDDLE
33