Color_Type_Gray_8.cpp 806 B

1234567891011121314151617181920
  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=93da0eb0b6722a4f33dc7dae094abf0b
  5. REG_FIDDLE(Color_Type_Gray_8, 256, 64, false, 0) {
  6. void draw(SkCanvas* canvas) {
  7. canvas->scale(16, 16);
  8. SkBitmap bitmap;
  9. SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType);
  10. bitmap.allocPixels(imageInfo);
  11. SkCanvas offscreen(bitmap);
  12. offscreen.clear(SK_ColorGREEN);
  13. canvas->drawBitmap(bitmap, 0, 0);
  14. uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 };
  15. SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes());
  16. if (bitmap.writePixels(grayPixmap, 0, 0)) {
  17. canvas->drawBitmap(bitmap, 2, 2);
  18. }
  19. }
  20. } // END FIDDLE