Add function to return an unpremuled version of a GrColor

BUG=skia:

Review URL: https://codereview.chromium.org/773553002
This commit is contained in:
egdaniel 2014-12-01 12:30:50 -08:00 committed by Commit bot
parent 742cacdd20
commit 4bd4e8031d

View File

@ -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.