Created
February 8, 2017 06:53
-
-
Save tamarous/3251b55d68ceb55e3ca720125df5672e to your computer and use it in GitHub Desktop.
使用快速指令集来将32位RGB转为24位RGB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void rbga32_to_rgb24_ssse3(uint8_t* dst, uint32_t* src, int width, int height) { | |
__m128i *d = (__m128i*)dst; | |
__m128i *s = (__m128i*)src; | |
__m128i mask = _mm_setr_epi8(0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1); | |
for (int i = 0; i < width*height; i += 16) { | |
__m128i sa = _mm_shuffle_epi8(_mm_load_si128(s), mask); | |
__m128i sb = _mm_shuffle_epi8(_mm_load_si128(s + 1), mask); | |
__m128i sc = _mm_shuffle_epi8(_mm_load_si128(s + 2), mask); | |
__m128i sd = _mm_shuffle_epi8(_mm_load_si128(s + 3), mask); | |
_mm_store_si128(d, _mm_or_si128(sa, _mm_slli_si128(sb, 12))); | |
_mm_store_si128(d + 1, _mm_or_si128(_mm_srli_si128(sb, 4), _mm_slli_si128(sc, 8))); | |
_mm_store_si128(d + 2, _mm_or_si128(_mm_srli_si128(sc, 8), _mm_slli_si128(sd, 4))); | |
s += 4; | |
d += 3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment