我制作了一个用于图像分离的功能。
// =(
#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 个浮点数,但我找不到执行相反操作的正确方法。
我搜索了 SSE 文档,但找不到相反的内容_mm_cvtepu8_epi32
有吗?
的组合_mm_shuffle_epi8
and _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));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)