reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 8 | /* Generated by tools/bookmaker from include/core/SkColor.h and docs/SkColor_Reference.bmh |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 9 | on 2018-06-14 13:13:34. Additional documentation and examples can be found at: |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 10 | https://skia.org/user/api/SkColor_Reference |
| 11 | |
| 12 | You may edit either file directly. Structural changes to public interfaces require |
| 13 | editing both files. After editing docs/SkColor_Reference.bmh, run: |
| 14 | bookmaker -b docs -i include/core/SkColor.h -p |
| 15 | to create an updated version of this file. |
| 16 | */ |
| 17 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | #ifndef SkColor_DEFINED |
| 19 | #define SkColor_DEFINED |
| 20 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 21 | #include "SkImageInfo.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | #include "SkScalar.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 23 | #include "SkTypes.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | |
| 25 | /** \file SkColor.h |
| 26 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 27 | Types, consts, functions, and macros for colors. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | */ |
| 29 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 30 | /** 8-bit type for an alpha value. 255 is 100% opaque, zero is 100% transparent. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | */ |
| 32 | typedef uint8_t SkAlpha; |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 33 | |
| 34 | /** 32-bit ARGB color value, unpremultiplied. Color components are always in |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | a known order. This is different from SkPMColor, which has its bytes in a configuration |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 36 | dependent order, to match the format of kBGRA_8888_SkColorType bitmaps. SkColor |
| 37 | is the type used to specify colors in SkPaint and in gradients. |
| 38 | |
| 39 | Color that is premultiplied has the same component values as color |
| 40 | that is unpremultiplied if alpha is 255, fully opaque, although may have the |
| 41 | component values in a different order. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | */ |
| 43 | typedef uint32_t SkColor; |
| 44 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 45 | /** Returns color value from 8-bit component values. Asserts if SK_DEBUG is defined |
| 46 | if a, r, g, or b exceed 255. Since color is unpremultiplied, a may be smaller |
| 47 | than the largest of r, g, and b. |
| 48 | |
| 49 | @param a amount of alpha, from fully transparent (0) to fully opaque (255) |
| 50 | @param r amount of red, from no red (0) to full red (255) |
| 51 | @param g amount of green, from no green (0) to full green (255) |
| 52 | @param b amount of blue, from no blue (0) to full blue (255) |
| 53 | @return color and alpha, unpremultiplied |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | */ |
Mike Klein | 37bbfe3 | 2017-09-28 09:47:45 -0400 | [diff] [blame] | 55 | static constexpr inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 56 | return SkASSERT(a <= 255 && r <= 255 && g <= 255 && b <= 255), |
| 57 | (a << 24) | (r << 16) | (g << 8) | (b << 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | } |
agl@chromium.org | c9c9ebb | 2010-07-28 17:10:30 +0000 | [diff] [blame] | 59 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 60 | /** Returns color value from 8-bit component values, with alpha set |
| 61 | fully opaque to 255. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | */ |
| 63 | #define SkColorSetRGB(r, g, b) SkColorSetARGB(0xFF, r, g, b) |
| 64 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 65 | /** Returns alpha byte from color value. |
| 66 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | #define SkColorGetA(color) (((color) >> 24) & 0xFF) |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 68 | |
| 69 | /** Returns red component of color, from zero to 255. |
| 70 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | #define SkColorGetR(color) (((color) >> 16) & 0xFF) |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 72 | |
| 73 | /** Returns green component of color, from zero to 255. |
| 74 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | #define SkColorGetG(color) (((color) >> 8) & 0xFF) |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 76 | |
| 77 | /** Returns blue component of color, from zero to 255. |
| 78 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | #define SkColorGetB(color) (((color) >> 0) & 0xFF) |
| 80 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 81 | /** Returns unpremultiplied color with red, blue, and green set from c; and alpha set |
| 82 | from a. Alpha component of c is ignored and is replaced by a in result. |
| 83 | |
| 84 | @param c packed RGB, eight bits per component |
| 85 | @param a alpha: transparent at zero, fully opaque at 255 |
| 86 | @return color with transparency |
| 87 | */ |
Lei Zhang | 868d52b | 2017-04-07 12:28:21 -0700 | [diff] [blame] | 88 | static constexpr inline SkColor SkColorSetA(SkColor c, U8CPU a) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | return (c & 0x00FFFFFF) | (a << 24); |
| 90 | } |
| 91 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 92 | /** Represents fully transparent SkAlpha value. SkAlpha ranges from zero, |
| 93 | fully transparent; to 255, fully opaque. |
| 94 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 95 | constexpr SkAlpha SK_AlphaTRANSPARENT = 0x00; |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 96 | |
| 97 | /** Represents fully opaque SkAlpha value. SkAlpha ranges from zero, |
| 98 | fully transparent; to 255, fully opaque. |
| 99 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 100 | constexpr SkAlpha SK_AlphaOPAQUE = 0xFF; |
commit-bot@chromium.org | 9fdb705 | 2013-07-19 17:43:27 +0000 | [diff] [blame] | 101 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 102 | /** Represents fully transparent SkColor. May be used to initialize a destination |
| 103 | containing a mask or a non-rectangular image. |
| 104 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 105 | constexpr SkColor SK_ColorTRANSPARENT = SkColorSetARGB(0x00, 0x00, 0x00, 0x00); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 107 | /** Represents fully opaque black. |
| 108 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 109 | constexpr SkColor SK_ColorBLACK = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 110 | |
| 111 | /** Represents fully opaque dark gray. |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 112 | Note that SVG dark gray is equivalent to 0xFFA9A9A9. |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 113 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 114 | constexpr SkColor SK_ColorDKGRAY = SkColorSetARGB(0xFF, 0x44, 0x44, 0x44); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 115 | |
| 116 | /** Represents fully opaque gray. |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 117 | Note that HTML gray is equivalent to 0xFF808080. |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 118 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 119 | constexpr SkColor SK_ColorGRAY = SkColorSetARGB(0xFF, 0x88, 0x88, 0x88); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 120 | |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 121 | /** Represents fully opaque light gray. HTML silver is equivalent to 0xFFC0C0C0. |
| 122 | Note that SVG light gray is equivalent to 0xFFD3D3D3. |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 123 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 124 | constexpr SkColor SK_ColorLTGRAY = SkColorSetARGB(0xFF, 0xCC, 0xCC, 0xCC); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 125 | |
| 126 | /** Represents fully opaque white. |
| 127 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 128 | constexpr SkColor SK_ColorWHITE = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 129 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 130 | /** Represents fully opaque red. |
| 131 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 132 | constexpr SkColor SK_ColorRED = SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 133 | |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 134 | /** Represents fully opaque green. HTML lime is equivalent. |
| 135 | Note that HTML green is equivalent to 0xFF008000. |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 136 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 137 | constexpr SkColor SK_ColorGREEN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 138 | |
| 139 | /** Represents fully opaque blue. |
| 140 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 141 | constexpr SkColor SK_ColorBLUE = SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 142 | |
| 143 | /** Represents fully opaque yellow. |
| 144 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 145 | constexpr SkColor SK_ColorYELLOW = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0x00); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 146 | |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 147 | /** Represents fully opaque cyan. HTML aqua is equivalent. |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 148 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 149 | constexpr SkColor SK_ColorCYAN = SkColorSetARGB(0xFF, 0x00, 0xFF, 0xFF); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 150 | |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 151 | /** Represents fully opaque magenta. HTML fuchsia is equivalent. |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 152 | */ |
Hal Canary | 84c0792 | 2018-04-16 13:44:04 -0400 | [diff] [blame] | 153 | constexpr SkColor SK_ColorMAGENTA = SkColorSetARGB(0xFF, 0xFF, 0x00, 0xFF); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 154 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 155 | /** Converts RGB to its HSV components. |
| 156 | hsv[0] contains hsv hue, a value from zero to less than 360. |
| 157 | hsv[1] contains hsv saturation, a value from zero to one. |
| 158 | hsv[2] contains hsv value, a value from zero to one. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 159 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 160 | @param red red component value from zero to 255 |
| 161 | @param green green component value from zero to 255 |
| 162 | @param blue blue component value from zero to 255 |
| 163 | @param hsv three element array which holds the resulting HSV components |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 164 | */ |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 165 | SK_API void SkRGBToHSV(U8CPU red, U8CPU green, U8CPU blue, SkScalar hsv[3]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 167 | /** Converts ARGB to its HSV components. Alpha in ARGB is ignored. |
| 168 | hsv[0] contains hsv hue, and is assigned a value from zero to less than 360. |
| 169 | hsv[1] contains hsv saturation, a value from zero to one. |
| 170 | hsv[2] contains hsv value, a value from zero to one. |
| 171 | |
| 172 | @param color ARGB color to convert |
| 173 | @param hsv three element array which holds the resulting HSV components |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 174 | */ |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 175 | static inline void SkColorToHSV(SkColor color, SkScalar hsv[3]) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 176 | SkRGBToHSV(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color), hsv); |
| 177 | } |
| 178 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 179 | /** Converts HSV components to an ARGB color. Alpha is passed through unchanged. |
| 180 | hsv[0] represents hsv hue, an angle from zero to less than 360. |
| 181 | hsv[1] represents hsv saturation, and varies from zero to one. |
| 182 | hsv[2] represents hsv value, and varies from zero to one. |
| 183 | |
| 184 | Out of range hsv values are pinned. |
| 185 | |
| 186 | @param alpha alpha component of the returned ARGB color |
| 187 | @param hsv three element array which holds the input HSV components |
| 188 | @return ARGB equivalent to HSV |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 189 | */ |
reed@google.com | f316634 | 2011-04-26 20:06:08 +0000 | [diff] [blame] | 190 | SK_API SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 191 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 192 | /** Converts HSV components to an ARGB color. Alpha is set to 255. |
| 193 | hsv[0] represents hsv hue, an angle from zero to less than 360. |
| 194 | hsv[1] represents hsv saturation, and varies from zero to one. |
| 195 | hsv[2] represents hsv value, and varies from zero to one. |
| 196 | |
| 197 | Out of range hsv values are pinned. |
| 198 | |
| 199 | @param hsv three element array which holds the input HSV components |
| 200 | @return RGB equivalent to HSV |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 201 | */ |
reed | fbc1e29 | 2016-01-29 05:22:59 -0800 | [diff] [blame] | 202 | static inline SkColor SkHSVToColor(const SkScalar hsv[3]) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 203 | return SkHSVToColor(0xFF, hsv); |
| 204 | } |
| 205 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 206 | /** 32-bit ARGB color value, premultiplied. The byte order for this value is |
| 207 | configuration dependent, matching the format of kBGRA_8888_SkColorType bitmaps. |
| 208 | This is different from SkColor, which is unpremultiplied, and is always in the |
| 209 | same byte order. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 210 | */ |
| 211 | typedef uint32_t SkPMColor; |
| 212 | |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 213 | /** Returns a SkPMColor value from unpremultiplied 8-bit component values. |
| 214 | |
| 215 | @param a amount of alpha, from fully transparent (0) to fully opaque (255) |
| 216 | @param r amount of red, from no red (0) to full red (255) |
| 217 | @param g amount of green, from no green (0) to full green (255) |
| 218 | @param b amount of blue, from no blue (0) to full blue (255) |
| 219 | @return premultiplied color |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 221 | SK_API SkPMColor SkPreMultiplyARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 222 | |
| 223 | /** Returns pmcolor closest to color c. Multiplies c RGB components by the c alpha, |
| 224 | and arranges the bytes to match the format of kN32_SkColorType. |
| 225 | |
| 226 | @param c unpremultiplied ARGB color |
| 227 | @return premultiplied color |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 228 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 229 | SK_API SkPMColor SkPreMultiplyColor(SkColor c); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 230 | |
reed | dd9ffea | 2016-02-18 12:39:14 -0800 | [diff] [blame] | 231 | struct SkPM4f; |
reed | 3125565 | 2016-02-08 12:56:56 -0800 | [diff] [blame] | 232 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 233 | template <SkAlphaType kAT> |
Mike Klein | f6a4bd8 | 2018-09-21 16:38:57 -0400 | [diff] [blame^] | 234 | struct SkRGBA4f { |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 235 | float fR; |
| 236 | float fG; |
| 237 | float fB; |
| 238 | float fA; |
reed | 6d3cef9 | 2016-01-22 01:04:29 -0800 | [diff] [blame] | 239 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 240 | bool operator==(const SkRGBA4f& other) const { |
reed | 6d3cef9 | 2016-01-22 01:04:29 -0800 | [diff] [blame] | 241 | return fA == other.fA && fR == other.fR && fG == other.fG && fB == other.fB; |
| 242 | } |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 243 | bool operator!=(const SkRGBA4f& other) const { |
reed | 6d3cef9 | 2016-01-22 01:04:29 -0800 | [diff] [blame] | 244 | return !(*this == other); |
| 245 | } |
| 246 | |
brianosman | e074d1f | 2016-06-24 06:31:47 -0700 | [diff] [blame] | 247 | const float* vec() const { return &fR; } |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 248 | float* vec() { return &fR; } |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 249 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 250 | static SkRGBA4f Pin(float r, float g, float b, float a); // impl. depends on kAT |
| 251 | SkRGBA4f pin() const { return Pin(fR, fG, fB, fA); } |
Cary Clark | 9149954 | 2018-06-08 11:49:19 -0400 | [diff] [blame] | 252 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 253 | static SkRGBA4f FromColor(SkColor); // impl. depends on kAT |
| 254 | SkColor toSkColor() const; // impl. depends on kAT |
reed | 6d3cef9 | 2016-01-22 01:04:29 -0800 | [diff] [blame] | 255 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 256 | SkRGBA4f<kPremul_SkAlphaType> premul() const { |
| 257 | static_assert(kAT == kUnpremul_SkAlphaType, ""); |
Brian Osman | 81cbd03 | 2018-09-21 11:09:15 -0400 | [diff] [blame] | 258 | return { fR * fA, fG * fA, fB * fA, fA }; |
| 259 | } |
| 260 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 261 | SkRGBA4f<kUnpremul_SkAlphaType> unpremul() const { |
| 262 | static_assert(kAT == kPremul_SkAlphaType, ""); |
| 263 | |
Brian Osman | 81cbd03 | 2018-09-21 11:09:15 -0400 | [diff] [blame] | 264 | if (fA == 0.0f) { |
| 265 | return { 0, 0, 0, 0 }; |
| 266 | } else { |
| 267 | float invAlpha = 1 / fA; |
| 268 | return { fR * invAlpha, fG * invAlpha, fB * invAlpha, fA }; |
| 269 | } |
| 270 | } |
| 271 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 272 | // TODO: remove? |
| 273 | SkPM4f toPM4f() const; // impl. depends on kAT |
reed | 6d3cef9 | 2016-01-22 01:04:29 -0800 | [diff] [blame] | 274 | }; |
| 275 | |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 276 | using SkColor4f = SkRGBA4f<kUnpremul_SkAlphaType>; |
Mike Klein | f6a4bd8 | 2018-09-21 16:38:57 -0400 | [diff] [blame^] | 277 | template <> SK_API SkColor4f SkColor4f::FromColor(SkColor); |
| 278 | template <> SK_API SkColor SkColor4f::toSkColor() const; |
Brian Osman | d25b7c1 | 2018-09-21 16:01:59 -0400 | [diff] [blame] | 279 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 280 | #endif |