blob: c589262a0332d4b764ffead98e7d47396d6cb511 [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=4260d6cc15db2c60c07f6fdc8d9ae425
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Color_Type_RGB_888, 256, 96, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 canvas->scale(16, 16);
8 SkBitmap bitmap;
9 SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType);
10 bitmap.allocPixels(imageInfo);
11 SkCanvas offscreen(bitmap);
12 offscreen.clear(SK_ColorGREEN);
13 canvas->drawBitmap(bitmap, 0, 0);
14 auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
15 return (r << 0) | (g << 8) | (b << 16);
16 };
17 uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00),
18 pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) };
19 uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb),
20 pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) };
21 if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) {
22 canvas->drawBitmap(bitmap, 2, 2);
23 }
24 if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) {
25 canvas->drawBitmap(bitmap, 4, 4);
26 }
27}
28} // END FIDDLE