/* * Copyright 2006 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SkMath_DEFINED #define SkMath_DEFINED #include "include/private/base/SkAssert.h" #include "include/private/base/SkCPUTypes.h" #include <cstdint> #include <climits> // Max Signed 16 bit value static constexpr int16_t SK_MaxS16 = …; static constexpr int16_t SK_MinS16 = …; static constexpr int32_t SK_MaxS32 = …; static constexpr int32_t SK_MinS32 = …; static constexpr int32_t SK_NaN32 = …; static constexpr int64_t SK_MaxS64 = …; static constexpr int64_t SK_MinS64 = …; // 64bit -> 32bit utilities // Handy util that can be passed two ints, and will automatically promote to // 64bits before the multiply, so the caller doesn't have to remember to cast // e.g. (int64_t)a * b; static inline int64_t sk_64_mul(int64_t a, int64_t b) { … } static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { … } static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { … } /////////////////////////////////////////////////////////////////////////////// /** * Returns true if value is a power of 2. Does not explicitly check for * value <= 0. */ template <typename T> constexpr inline bool SkIsPow2(T value) { … } /////////////////////////////////////////////////////////////////////////////// /** * Return a*b/((1 << shift) - 1), rounding any fractional bits. * Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8 */ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) { … } /** * Return a*b/255, rounding any fractional bits. * Only valid if a and b are unsigned and <= 32767. */ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { … } #endif