blob: 3660c38c6075bdbde99df0625c8bdd197516c955 [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=92f81aa0459230459600a01e79ccff29
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Color_Type_RGB_101010, 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_101010x_SkColorType, kOpaque_SkAlphaType);
10 bitmap.allocPixels(imageInfo);
11 SkCanvas offscreen(bitmap);
12 offscreen.clear(SK_ColorGREEN);
Mike Reede1f72f92021-01-27 17:09:40 -050013 canvas->drawImage(bitmap.asImage(), 0, 0);
Hal Canary87515122019-03-15 14:22:51 -040014 auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t {
15 return (r << 0) | (g << 10) | (b << 20);
16 };
17 uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000),
18 pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) };
19 uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff),
20 pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) };
21 if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) {
Mike Reede1f72f92021-01-27 17:09:40 -050022 canvas->drawImage(bitmap.asImage(), 2, 2);
Hal Canary87515122019-03-15 14:22:51 -040023 }
24 SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
25 if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
Mike Reede1f72f92021-01-27 17:09:40 -050026 canvas->drawImage(bitmap.asImage(), 4, 4);
Hal Canary87515122019-03-15 14:22:51 -040027 }
28}
29} // END FIDDLE