blob: 85ab3232a6b8c0e09e0fb1285aa7e06c6751caef [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=193d1f6d8a43b7a8e9f27ba21de38617
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Bitmap_getColor, 256, 256, true, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 const int w = 4;
8 const int h = 4;
9 SkColor colors[][w] = {
10 { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
11 { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
12 { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
13 { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
14 };
15 SkDebugf("Premultiplied:\n");
16 for (int y = 0; y < h; ++y) {
17 SkDebugf("(0, %d) ", y);
18 for (int x = 0; x < w; ++x) {
19 SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' ');
20 }
21 }
22 SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);
23 SkBitmap bitmap;
24 bitmap.installPixels(pixmap);
25 SkDebugf("Unpremultiplied:\n");
26 for (int y = 0; y < h; ++y) {
27 SkDebugf("(0, %d) ", y);
28 for (int x = 0; x < w; ++x) {
29 SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
30 }
31 }
32}
33} // END FIDDLE