blob: 52df753f7860fccaff1bde43c59fca1fb91fbfe5 [file] [log] [blame]
Hal Canary6c8422c2020-01-10 15:22:09 -05001// 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"
4REG_FIDDLE(unexpected_setAlphaType, 256, 256, true, 0) {
5static const char* alphatype_name(SkAlphaType at) {
6 switch (at) {
7 case kUnknown_SkAlphaType: return "Unknown";
8 case kOpaque_SkAlphaType: return "Opaque";
9 case kPremul_SkAlphaType: return "Premul";
10 case kUnpremul_SkAlphaType: return "Unpremul";
11 }
12 SkASSERT(false);
13 return "unexpected alphatype";
14}
15static const char* colortype_name(SkColorType ct) {
16 switch (ct) {
17 case kUnknown_SkColorType: return "Unknown";
18 case kAlpha_8_SkColorType: return "Alpha_8";
19 case kA16_unorm_SkColorType: return "Alpha_16";
20 case kA16_float_SkColorType: return "A16_float";
21 case kRGB_565_SkColorType: return "RGB_565";
22 case kARGB_4444_SkColorType: return "ARGB_4444";
23 case kRGBA_8888_SkColorType: return "RGBA_8888";
24 case kRGB_888x_SkColorType: return "RGB_888x";
25 case kBGRA_8888_SkColorType: return "BGRA_8888";
26 case kRGBA_1010102_SkColorType: return "RGBA_1010102";
27 case kRGB_101010x_SkColorType: return "RGB_101010x";
28 case kGray_8_SkColorType: return "Gray_8";
29 case kRGBA_F16Norm_SkColorType: return "RGBA_F16Norm";
30 case kRGBA_F16_SkColorType: return "RGBA_F16";
31 case kRGBA_F32_SkColorType: return "RGBA_F32";
32 case kR8G8_unorm_SkColorType: return "R8G8_unorm";
33 case kR16G16_unorm_SkColorType: return "R16G16_unorm";
34 case kR16G16_float_SkColorType: return "R16G16_float";
35 case kR16G16B16A16_unorm_SkColorType: return "R16G16B16A16_unorm";
36 }
37 SkASSERT(false);
38 return "unexpected colortype";
39}
40void draw(SkCanvas* canvas) {
41 static const SkAlphaType kAlphaTypes[] =
42 {kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType};
43 static const SkColorType kColorTypes[] =
44 {kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
45 kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
46 kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
47 kGray_8_SkColorType, kRGBA_F16_SkColorType};
48 SkBitmap bitmap;
49 SkDebugf("%16s Canonical Unknown Opaque Premul "
50 "Unpremul\n", " ");
51 for (SkColorType colorType : kColorTypes) {
52 for (SkAlphaType canonicalAlphaType : kAlphaTypes) {
53 SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType);
54 SkDebugf("%15s %10s ", colortype_name(colorType), alphatype_name(canonicalAlphaType));
55 for (SkAlphaType alphaType : kAlphaTypes) {
56 bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType));
57 bool result = bitmap.setAlphaType(alphaType);
58 SkDebugf("%s %s ", result ? "true " : "false",
59 alphatype_name(bitmap.alphaType()));
60 }
61 SkDebugf("\n");
62 }
63 }
64}
65} // END FIDDLE