diff options
author | egdaniel <egdaniel@google.com> | 2014-12-01 12:30:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-01 12:30:51 -0800 |
commit | 4bd4e8031df0b38a71fc7344fede5a352484ccbb (patch) | |
tree | 1f7ea2b35bfb0ff2c258cbb7932d086d1046ec84 /include/gpu | |
parent | 742cacdd20034c70f826b60eb416f7cc0a81d587 (diff) |
Add function to return an unpremuled version of a GrColor
BUG=skia:
Review URL: https://codereview.chromium.org/773553002
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrColor.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h index bd949cebe8..f862ecc1d0 100644 --- a/include/gpu/GrColor.h +++ b/include/gpu/GrColor.h @@ -12,6 +12,9 @@ #define GrColor_DEFINED #include "GrTypes.h" +#include "SkColor.h" +#include "SkColorPriv.h" +#include "SkUnPreMultiply.h" /** * GrColor is 4 bytes for R, G, B, A, in a specific order defined below. The components are stored @@ -99,6 +102,23 @@ static inline bool GrColorIsOpaque(GrColor color) { return (color & (0xFFU << GrColor_SHIFT_A)) == (0xFFU << GrColor_SHIFT_A); } +/** Returns an unpremuled version of the GrColor. */ +static inline GrColor GrUnPreMulColor(GrColor color) { + unsigned r = GrColorUnpackR(color); + unsigned g = GrColorUnpackG(color); + unsigned b = GrColorUnpackB(color); + unsigned a = GrColorUnpackA(color); + SkPMColor colorPM = SkPackARGB32(a, r, g, b); + SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM); + + r = SkGetPackedR32(colorUPM); + g = SkGetPackedG32(colorUPM); + b = SkGetPackedB32(colorUPM); + a = SkGetPackedA32(colorUPM); + + return GrColorPackRGBA(r, g, b, a); +} + /** * Flags used for bitfields of color components. They are defined so that the bit order reflects the * GrColor shift order. |