Color_Type_RGB_101010.cpp 1.4 KB

1234567891011121314151617181920212223242526272829
  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.
  3. #include "tools/fiddle/examples.h"
  4. // HASH=92f81aa0459230459600a01e79ccff29
  5. REG_FIDDLE(Color_Type_RGB_101010, 256, 96, false, 0) {
  6. void 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);
  13. canvas->drawBitmap(bitmap, 0, 0);
  14. 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())) {
  22. canvas->drawBitmap(bitmap, 2, 2);
  23. }
  24. SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes());
  25. if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) {
  26. canvas->drawBitmap(bitmap, 4, 4);
  27. }
  28. }
  29. } // END FIDDLE