• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_SRGB(gpu4444diff, 260, 260, false, 3, 0, false) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     canvas->scale(16, 16);
7     SkBitmap bitmap;
8     SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType);
9     bitmap.allocPixels(imageInfo);
10     SkCanvas offscreen(bitmap);
11     offscreen.clear(SK_ColorGREEN);
12     canvas->drawBitmap(bitmap, 0, 0);
13     offscreen.clear(SK_ColorGRAY);
14     canvas->drawBitmap(bitmap, 2, 2);
15     auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
16         return (a << 0) | (b << 4) | (g << 8) | (r << 12);
17     };
18     uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0),
19                            pack4444(0xF, 0x9, 0x0, 0x0), pack4444(0xF, 0x5, 0x0, 0x0) };
20     uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0x0F), pack4444(0xF, 0x0, 0x0, 0x0b),
21                             pack4444(0xF, 0x0, 0x0, 0x09), pack4444(0xF, 0x0, 0x0, 0x05) };
22     SkImageInfo pixInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType);
23     SkPixmap redPixmap(imageInfo, &red4444, 4);
24     if (bitmap.writePixels(redPixmap, 0, 0)) {
25         canvas->drawBitmap(bitmap, 4, 4);
26     }
27     SkPixmap bluePixmap(imageInfo, &blue4444, 4);
28     if (bitmap.writePixels(bluePixmap, 0, 0)) {
29         canvas->drawBitmap(bitmap, 6, 6);
30     }
31 }
32 }  // END FIDDLE
33