Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=7e7c46bb4572e21e13529ff364eb0a9c |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Color_Type_RGB_565, 256, 96, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | canvas->scale(16, 16); |
| 8 | SkBitmap bitmap; |
| 9 | SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType); |
| 10 | bitmap.allocPixels(imageInfo); |
| 11 | SkCanvas offscreen(bitmap); |
| 12 | offscreen.clear(SK_ColorGREEN); |
Mike Reed | e1f72f9 | 2021-01-27 17:09:40 -0500 | [diff] [blame] | 13 | canvas->drawImage(bitmap.asImage(), 0, 0); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 14 | auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t { |
| 15 | return (b << 0) | (g << 5) | (r << 11); |
| 16 | }; |
| 17 | uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00), |
| 18 | pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) }; |
| 19 | uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17), |
| 20 | pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) }; |
| 21 | SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes()); |
| 22 | if (bitmap.writePixels(redPixmap, 0, 0)) { |
Mike Reed | e1f72f9 | 2021-01-27 17:09:40 -0500 | [diff] [blame] | 23 | canvas->drawImage(bitmap.asImage(), 2, 2); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 24 | } |
| 25 | SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes()); |
| 26 | if (bitmap.writePixels(bluePixmap, 0, 0)) { |
Mike Reed | e1f72f9 | 2021-01-27 17:09:40 -0500 | [diff] [blame] | 27 | canvas->drawImage(bitmap.asImage(), 4, 4); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 28 | } |
| 29 | } |
| 30 | } // END FIDDLE |