• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 REG_FIDDLE(Bitmap_setAlphaType, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
7                              "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
8                              "RGBA_F16"};
9     const char* alphas[] = {"Unknown ", "Opaque  ", "Premul  ", "Unpremul"};
10     SkBitmap bitmap;
11     SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
12     kUnpremul_SkAlphaType
13                                };
14     SkDebugf("%18s%15s%17s%18s%19s\n", "Canonical", "Unknown", "Opaque", "Premul", "Unpremul");
15     for (SkColorType colorType : {
16     kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
17     kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
18     kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
19     kGray_8_SkColorType, kRGBA_F16_SkColorType
20                                  } ) {
21         for (SkAlphaType canonicalAlphaType : alphaTypes) {
22             SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType );
23             SkDebugf("%12s %9s  ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]);
24             for (SkAlphaType alphaType : alphaTypes) {
25                 bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType));
26                 bool result = bitmap.setAlphaType(alphaType);
27                 SkDebugf("%s %s    ", result ? "true " : "false", alphas[(int) bitmap.alphaType()]);
28             }
29             SkDebugf("\n");
30         }
31     }
32 }
33 }  // END FIDDLE
34