且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SSE中对图像通道进行去交织

更新时间:2022-06-16 23:30:55

由于8位值是无符号的,你可以通过移位和屏蔽来实现这一点,就像你一样用于标量代码,例如

Since the 8 bit values are unsigned you can just do this with shifting and masking, much like you would for scalar code, e.g.

__m128i vrgba;

__m128i vr = _mm_and_si128(vrgba, _mm_set1_epi32(0xff));
__m128i vg = _mm_and_si128(_mm_srli_epi32(vrgba, 8), _mm_set1_epi32(0xff));
__m128i vb = _mm_and_si128(_mm_srli_epi32(vrgba, 16), _mm_set1_epi32(0xff));
__m128i va = _mm_srli_epi32(vrgba, 24);

请注意,我假设你的RGBA元素在LS 8位和A中有R分量MS 8位中的组件,但如果它们是相反的字节序,您只需更改 vr的名称 / vg / vb / va vectors。

Note that I'm assuming your RGBA elements have the R component in the LS 8 bits and the A component in the MS 8 bits, but if they are the opposite endianness you can just change the names of the vr/vg/vb/va vectors.