/* * Copyright 2012 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SkMaskGamma_DEFINED #define SkMaskGamma_DEFINED #include "include/core/SkColor.h" #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" #include "include/private/SkColorData.h" #include "include/private/base/SkCPUTypes.h" #include "include/private/base/SkNoncopyable.h" #include "include/private/base/SkTo.h" #include <algorithm> #include <cstddef> #include <cstdint> #include <memory> /** * SkColorSpaceLuminance is used to convert luminances to and from linear and * perceptual color spaces. * * Luma is used to specify a linear luminance value [0.0, 1.0]. * Luminance is used to specify a luminance value in an arbitrary color space [0.0, 1.0]. */ class SkColorSpaceLuminance : SkNoncopyable { … }; ///@{ /** * Scales base <= 2^N-1 to 2^8-1 * @param N [1, 8] the number of bits used by base. * @param base the number to be scaled to [0, 255]. */ template<U8CPU N> static inline U8CPU sk_t_scale255(U8CPU base) { … } template<> /*static*/ inline U8CPU sk_t_scale255<1>(U8CPU base) { … } template<> /*static*/ inline U8CPU sk_t_scale255<2>(U8CPU base) { … } template<> /*static*/ inline U8CPU sk_t_scale255<4>(U8CPU base) { … } template<> /*static*/ inline U8CPU sk_t_scale255<8>(U8CPU base) { … } ///@} template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> class SkTMaskPreBlend; void SkTMaskGamma_build_correcting_lut(uint8_t* table, U8CPU srcI, SkScalar contrast, const SkColorSpaceLuminance& dstConvert, SkScalar dstGamma); /** * A regular mask contains linear alpha values. A gamma correcting mask * contains non-linear alpha values in an attempt to create gamma correct blits * in the presence of a gamma incorrect (linear) blend in the blitter. * * SkMaskGamma creates and maintains tables which convert linear alpha values * to gamma correcting alpha values. * @param R The number of luminance bits to use [1, 8] from the red channel. * @param G The number of luminance bits to use [1, 8] from the green channel. * @param B The number of luminance bits to use [1, 8] from the blue channel. */ template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> class SkTMaskGamma : public SkRefCnt { … }; /** * SkTMaskPreBlend is a tear-off of SkTMaskGamma. It provides the tables to * convert a linear alpha value for a given channel to a gamma correcting alpha * value for that channel. This class is immutable. * * If fR, fG, or fB is nullptr, all of them will be. This indicates that no mask * pre blend should be applied. SkTMaskPreBlend::isApplicable() is provided as * a convenience function to test for the absence of this case. */ template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> class SkTMaskPreBlend { … }; template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS> SkTMaskGamma<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>::preBlend(SkColor color) const { … } ///@{ /** * If APPLY_LUT is false, returns component unchanged. * If APPLY_LUT is true, returns lut[component]. * @param APPLY_LUT whether or not the look-up table should be applied to component. * @component the initial component. * @lut a look-up table which transforms the component. */ template<bool APPLY_LUT> static inline U8CPU sk_apply_lut_if(U8CPU component, const uint8_t*) { … } template<> /*static*/ inline U8CPU sk_apply_lut_if<true>(U8CPU component, const uint8_t* lut) { … } ///@} #endif