• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkAlphaType_DEFINED
9 #define SkAlphaType_DEFINED
10 
11 #include "include/private/base/SkAPI.h"
12 
13 /** \enum SkAlphaType
14     Describes how to interpret the alpha component of a pixel. A pixel may
15     be opaque, or alpha, describing multiple levels of transparency.
16 
17     In simple blending, alpha weights the draw color and the destination
18     color to create a new color. If alpha describes a weight from zero to one:
19 
20     new color = draw color * alpha + destination color * (1 - alpha)
21 
22     In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.
23 
24     RGB may have alpha included in each component value; the stored
25     value is the original RGB multiplied by alpha. Premultiplied color
26     components improve performance.
27 */
28 enum SK_API SkAlphaType : int {
29     kUnknown_SkAlphaType,                          //!< uninitialized
30     kOpaque_SkAlphaType,                           //!< pixel is opaque
31     kPremul_SkAlphaType,                           //!< pixel components are premultiplied by alpha
32     kUnpremul_SkAlphaType,                         //!< pixel components are independent of alpha
33     kLastEnum_SkAlphaType = kUnpremul_SkAlphaType, //!< last valid value
34 };
35 
36 /** Returns true if SkAlphaType equals kOpaque_SkAlphaType.
37 
38     kOpaque_SkAlphaType is a hint that the SkColorType is opaque, or that all
39     alpha values are set to their 1.0 equivalent. If SkAlphaType is
40     kOpaque_SkAlphaType, and SkColorType is not opaque, then the result of
41     drawing any pixel with a alpha value less than 1.0 is undefined.
42 */
SkAlphaTypeIsOpaque(SkAlphaType at)43 static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
44     return kOpaque_SkAlphaType == at;
45 }
46 
47 #endif
48