gpt4 book ai didi

c++ - 如何使用 SSE 将 _m128i 转换为 unsigned int?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:05:05 30 4
gpt4 key购买 nike

我做了一个图像分色的功能。

// =(
#define ARGB_COLOR(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))

inline UINT PosterizeColor(const UINT &color, const float &nColors)
{
__m128 clr = _mm_cvtepi32_ps( _mm_cvtepu8_epi32((__m128i&)color) );

clr = _mm_mul_ps(clr, _mm_set_ps1(nColors / 255.0f) );
clr = _mm_round_ps(clr, _MM_FROUND_TO_NEAREST_INT);
clr = _mm_mul_ps(clr, _mm_set_ps1(255.0f / nColors) );

__m128i iClr = _mm_cvttps_epi32(clr);

return ARGB_COLOR(iClr.m128i_u8[12],
iClr.m128i_u8[8],
iClr.m128i_u8[4],
iClr.m128i_u8[0]);
}

在第一行中,我将颜色解包为 4 个 float ,但我找不到正确的方法来进行反向操作。

我搜索了 SSE 文档,找不到 _mm_cvtepu8_epi32 的逆向

有吗?

最佳答案

_mm_shuffle_epi8_mm_cvtsi128_si32 的组合是您所需要的:

static const __m128i shuffleMask = _mm_setr_epi8(0,  4,  8, 12, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1);
UINT color = _mm_cvtsi128_si32(_mm_shuffle_epi8(iClr, shuffleMask));

关于c++ - 如何使用 SSE 将 _m128i 转换为 unsigned int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8598942/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com