| 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 "include/core/SkColorType.h" |
| 4 |
#include "tools/fiddle/examples.h" |
| 5 |
REG_FIDDLE(unexpected_setAlphaType, 256, 256, true, 0) { |
| 6 |
static const char* alphatype_name(SkAlphaType at) { |
| 7 |
switch (at) { |
| 8 |
case kUnknown_SkAlphaType: return "Unknown"; |
| 9 |
case kOpaque_SkAlphaType: return "Opaque"; |
| 10 |
case kPremul_SkAlphaType: return "Premul"; |
| 11 |
case kUnpremul_SkAlphaType: return "Unpremul"; |
| 12 |
} |
| 13 |
SkASSERT(false); |
| 14 |
return "unexpected alphatype"; |
| 15 |
} |
| 16 |
static const char* colortype_name(SkColorType ct) { |
| 17 |
switch (ct) { |
| 18 |
case kUnknown_SkColorType: return "Unknown"; |
| 19 |
case kAlpha_8_SkColorType: return "Alpha_8"; |
| 20 |
case kA16_unorm_SkColorType: return "Alpha_16"; |
| 21 |
case kA16_float_SkColorType: return "A16_float"; |
| 22 |
case kRGB_565_SkColorType: return "RGB_565"; |
| 23 |
case kARGB_4444_SkColorType: return "ARGB_4444"; |
| 24 |
case kRGBA_8888_SkColorType: return "RGBA_8888"; |
| 25 |
case kSRGBA_8888_SkColorType: return "SRGBA_8888"; |
| 26 |
case kRGB_888x_SkColorType: return "RGB_888x"; |
| 27 |
case kBGRA_8888_SkColorType: return "BGRA_8888"; |
| 28 |
case kRGBA_1010102_SkColorType: return "RGBA_1010102"; |
| 29 |
case kRGB_101010x_SkColorType: return "RGB_101010x"; |
| 30 |
case kBGRA_1010102_SkColorType: return "BGRA_1010102"; |
| 31 |
case kBGR_101010x_SkColorType: return "BGR_101010x"; |
| 32 |
case kBGR_101010x_XR_SkColorType: return "BGR_101010x_xr"; |
| 33 |
case kBGRA_10101010_XR_SkColorType: return "BGRA_10101010_xr"; |
| 34 |
case kRGBA_10x6_SkColorType: return "RGBA_10x6"; |
| 35 |
case kGray_8_SkColorType: return "Gray_8"; |
| 36 |
case kRGBA_F16Norm_SkColorType: return "RGBA_F16Norm"; |
| 37 |
case kRGBA_F16_SkColorType: return "RGBA_F16"; |
| 38 |
case kRGB_F16F16F16x_SkColorType: return "RGB_F16F16F16x"; |
| 39 |
case kRGBA_F32_SkColorType: return "RGBA_F32"; |
| 40 |
case kR8G8_unorm_SkColorType: return "R8G8_unorm"; |
| 41 |
case kR16_unorm_SkColorType: return "R16_unorm"; |
| 42 |
case kR16G16_unorm_SkColorType: return "R16G16_unorm"; |
| 43 |
case kR16G16_float_SkColorType: return "R16G16_float"; |
| 44 |
case kR16G16B16A16_unorm_SkColorType: return "R16G16B16A16_unorm"; |
| 45 |
case kR8_unorm_SkColorType: return "R8_unorm"; |
| 46 |
} |
| 47 |
SkASSERT(false); |
| 48 |
return "unexpected colortype"; |
| 49 |
} |
| 50 |
void draw(SkCanvas* canvas) { |
| 51 |
static const SkAlphaType kAlphaTypes[] = |
| 52 |
{kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType}; |
| 53 |
static const SkColorType kColorTypes[] = |
| 54 |
{kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, |
| 55 |
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, |
| 56 |
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, |
| 57 |
kGray_8_SkColorType, kRGBA_F16_SkColorType}; |
| 58 |
SkBitmap bitmap; |
| 59 |
SkDebugf("%16s Canonical Unknown Opaque Premul " |
| 60 |
"Unpremul\n", " "); |
| 61 |
for (SkColorType colorType : kColorTypes) { |
| 62 |
for (SkAlphaType canonicalAlphaType : kAlphaTypes) { |
| 63 |
SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType); |
| 64 |
SkDebugf("%15s %10s ", colortype_name(colorType), alphatype_name(canonicalAlphaType)); |
| 65 |
for (SkAlphaType alphaType : kAlphaTypes) { |
| 66 |
bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType)); |
| 67 |
bool result = bitmap.setAlphaType(alphaType); |
| 68 |
SkDebugf("%s %s ", result ? "true " : "false", |
| 69 |
alphatype_name(bitmap.alphaType())); |
| 70 |
} |
| 71 |
SkDebugf("\n"); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} // END FIDDLE |