Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: include/gpu/GrColor.h

Issue 773553002: Add function to return an unpremuled version of a GrColor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrColor.h
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h
index bd949cebe8473b297a4ce747dcbdc3ca6b6e2c15..f862ecc1d069c3bffaecc17528c5a207b15eebd8 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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698