1// [Blend2D]
2// 2D Vector Graphics Powered by a JIT Compiler.
3//
4// [License]
5// Zlib - See LICENSE.md file in the package.
6
7#ifndef BLEND2D_BLRGBA_P_H
8#define BLEND2D_BLRGBA_P_H
9
10#include "./blapi-internal_p.h"
11#include "./blrgba.h"
12
13#if defined(BL_BUILD_OPT_SSE2)
14 #include "./blsimd_p.h"
15#endif
16
17//! \cond INTERNAL
18//! \addtogroup blend2d_internal
19//! \{
20
21// ============================================================================
22// [BLRgba - Utilities]
23// ============================================================================
24
25namespace {
26
27static BL_INLINE bool blRgba32IsFullyOpaque(uint32_t rgba32) noexcept {
28 return rgba32 >= 0xFF000000u;
29}
30
31static BL_INLINE bool blRgba64IsFullyOpaque(uint64_t rgba64) noexcept {
32 return (rgba64 & 0xFFFF000000000000u) != 0;
33}
34
35static BL_INLINE uint32_t blRgba32Pack(uint32_t r, uint32_t g, uint32_t b, uint32_t a = 0xFFu) noexcept {
36 BL_ASSUME(r <= 0xFFu);
37 BL_ASSUME(g <= 0xFFu);
38 BL_ASSUME(b <= 0xFFu);
39 BL_ASSUME(a <= 0xFFu);
40
41 return (a << 24) | (r << 16) | (g << 8) | (b);
42}
43
44static BL_INLINE uint64_t blRgba64Pack(uint32_t r, uint32_t g, uint32_t b, uint32_t a = 0xFFFFu) noexcept {
45 BL_ASSUME(r <= 0xFFFFu);
46 BL_ASSUME(g <= 0xFFFFu);
47 BL_ASSUME(b <= 0xFFFFu);
48 BL_ASSUME(a <= 0xFFFFu);
49
50 uint32_t ar = (a << 16) | r;
51 uint32_t gb = (g << 16) | b;
52
53 return (uint64_t(ar) << 32) | gb;
54}
55
56static BL_INLINE uint64_t blRgba64FromRgba32(uint32_t src) noexcept {
57#if defined(BL_BUILD_OPT_SSE2)
58 using namespace SIMD;
59 I128 src128 = vcvtu32i128(src);
60 return vcvti128u64(vunpackli8(src128, src128));
61#else
62 return BLRgba64(BLRgba32(src)).value;
63#endif
64}
65
66static BL_INLINE uint32_t blRgba32FromRgba64(uint64_t src) noexcept {
67#if defined(BL_BUILD_OPT_SSE2)
68 using namespace SIMD;
69 return vcvti128u32(vpacki16u8(vsrli16<8>(vcvtu64i128(src))));
70#else
71 return BLRgba32(BLRgba64(src)).value;
72#endif
73}
74
75} // {anonymous}
76
77//! \}
78//! \endcond
79
80#endif // BLEND2D_BLRGBA_P_H
81