diff options
author | 2018-07-12 10:37:08 -0400 | |
---|---|---|
committer | 2018-07-12 15:15:38 +0000 | |
commit | b774bbba2f5d8433a3b854f8f295f0375a1fc55d (patch) | |
tree | 8ded4854ce1826961207d26fe5ca8d41705a9080 /src/core/SkPM4fPriv.h | |
parent | d9c2e522ddab75f5702bb0c714c57711ade9c788 (diff) |
update mode color filter color management
Change-Id: I2f371e279f45086ae8885c7206fefff3fbc8c941
Reviewed-on: https://skia-review.googlesource.com/140985
Auto-Submit: Mike Klein <mtklein@chromium.org>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkPM4fPriv.h')
-rw-r--r-- | src/core/SkPM4fPriv.h | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h index df88d2a4c9..f9458f6df9 100644 --- a/src/core/SkPM4fPriv.h +++ b/src/core/SkPM4fPriv.h @@ -10,16 +10,54 @@ #include "SkColorData.h" #include "SkColorSpace.h" +#include "SkColorSpaceXformSteps.h" #include "SkArenaAlloc.h" #include "SkPM4f.h" #include "SkRasterPipeline.h" #include "SkSRGB.h" #include "../jumper/SkJumper.h" +// This file is mostly helper routines for doing color space management. +// It probably wants a new name, and they likely don't need to be inline. +// +// There are two generations of routines in here, the old ones that assumed linear blending, +// and the new ones assuming as-encoded blending. We're trying to move to the new as-encoded +// ones and will hopefully eventually remove all the linear routines. +// +// We'll start with the new as-encoded routines first, +// and shove all the old broken routines towards the bottom. + static inline Sk4f Sk4f_fromL32(uint32_t px) { return SkNx_cast<float>(Sk4b::Load(&px)) * (1/255.0f); } +static inline uint32_t Sk4f_toL32(const Sk4f& px) { + uint32_t l32; + SkNx_cast<uint8_t>(Sk4f_round(px * 255.0f)).store(&l32); + return l32; +} + +static inline SkPM4f premul_in_dst_colorspace(SkColor color, SkColorSpace* dstCS) { + float rgba[4]; + swizzle_rb(Sk4f_fromL32(color)).store(rgba); + + // SkColors are always sRGB. + auto srcCS = SkColorSpace::MakeSRGB().get(); + + // If dstCS is null, no color space transformation is needed (and apply() will just premul). + if (!dstCS) { dstCS = srcCS; } + + // TODO: Can we use a precomputed sRGB -> dstCS SkColorSpaceXformSteps for each device? + SkColorSpaceXformSteps(srcCS, kUnpremul_SkAlphaType, dstCS) + .apply(rgba); + + return {{rgba[0], rgba[1], rgba[2], rgba[3]}}; +} + +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// Functions below this line are probably totally broken as far as color space management goes. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + static inline Sk4f Sk4f_fromS32(uint32_t px) { return { sk_linear_from_srgb[(px >> 0) & 0xff], sk_linear_from_srgb[(px >> 8) & 0xff], @@ -27,12 +65,6 @@ static inline Sk4f Sk4f_fromS32(uint32_t px) { (1/255.0f) * (px >> 24) }; } -static inline uint32_t Sk4f_toL32(const Sk4f& px) { - uint32_t l32; - SkNx_cast<uint8_t>(Sk4f_round(px * 255.0f)).store(&l32); - return l32; -} - static inline uint32_t Sk4f_toS32(const Sk4f& px) { Sk4i rgb = sk_linear_to_srgb(px), srgb = { rgb[0], rgb[1], rgb[2], (int)(255.0f * px[3] + 0.5f) }; @@ -106,4 +138,5 @@ static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) { return SkColor4f_from_SkColor(color, dst).premul(); } + #endif |