From de1a60534648ca8a6eb3ae32e06a7a9e9c0591f3 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 22 Mar 2017 10:57:00 -0400 Subject: Support premul/unpremul of F16 during read/writePixels Added PremulOutput and UnpremulOutput FP helpers. These are used (rather than GrConfigConversionEffect) when working with FP16 textures (and will also be used for other configs that can't be round-tripped via rounding). BUG=skia:5853 Change-Id: I101592c26c4f0b379d5e5a8678ef7b2f08e6ad56 Reviewed-on: https://skia-review.googlesource.com/9980 Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- include/gpu/GrColor.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/gpu/GrColor.h') diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h index 64368b9ef9..ad66523bcb 100644 --- a/include/gpu/GrColor.h +++ b/include/gpu/GrColor.h @@ -259,6 +259,15 @@ struct GrColor4f { float a = fRGBA[3]; return GrColor4f(fRGBA[0] * a, fRGBA[1] * a, fRGBA[2] * a, a); } + + GrColor4f unpremul() const { + float a = fRGBA[3]; + if (a <= 0.0f) { + return GrColor4f(0.0f, 0.0f, 0.0f, 0.0f); + } + float invAlpha = 1.0f / a; + return GrColor4f(fRGBA[0] * invAlpha, fRGBA[1] * invAlpha, fRGBA[2] * invAlpha, a); + } }; /** -- cgit v1.2.3