使用SSE2优化RGB565到RGB888的转换 [英] Optimizing RGB565 to RGB888 conversions with SSE2

查看:149
本文介绍了使用SSE2优化RGB565到RGB888的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用具有以下基本公式的SSE2优化从565到888的像素深度转换:

I'm trying to optimize pixel depth conversion from 565 to 888 using SSE2 with the basic formula:

col8 = col5 << 3 | col5 >> 2
col8 = col6 << 2 | col6 >> 4

我采用两个2x565 128位向量,我正在输出3x888 128位向量.

I take two 2x565 128-bit vectors and I'm outputing 3x888 128-bit vectors.

经过一些掩蔽,移位和或运算后,我得出了两个矢量(以((blue<< <8)| red)* 8位颜色存储在16位字中的矢量和一个相似的矢量)的意义.零绿色值.现在,我需要将它们合并为888输出.

After some masking, shifting and OR'ing I came to the point when I have two vectors with ((blue << 8) | red)* 8-bit colors stored in 16-bit words and a similar vectors with zero-green values. Now I need to combine them into 888 output.

    BR: BR7-BR6-...-BR1-BR0
    0G: 0G7-0G7-...-0G1-0G0
                 |
                 v
  OUT1: R5-BGR4-...-BGR1-BGR0

在SSSE3中,有一个_mm_shuffle_epi8()可以解决我的需求,但由于我需要支持的硬件范围,因此希望将自己限制在SSE2中.

In SSSE3 there is a _mm_shuffle_epi8() which solves my needs but would like to restrict myself to SSE2 because of the hardware range I need to support.

  • 这是小尾数

推荐答案

您可以参考Google的libyuv项目,该项目具有SSE2转换:

You can refer to Google's libyuv project, which has SSE2 conversions:

https://chromium.googlesource.com/libyuv/libyuv/+/master/source/row_win.cc

 // pmul method to replicate bits.
// Math to replicate bits:
// (v << 8) | (v << 3)
// v * 256 + v * 8
// v * (256 + 8)
// G shift of 5 is incorporated, so shift is 5 + 8 and 5 + 3
// 20 instructions.
__declspec(naked)
void RGB565ToARGBRow_SSE2(const uint8* src_rgb565, uint8* dst_argb,
                          int width) {
  __asm {
    mov       eax, 0x01080108  // generate multiplier to repeat 5 bits
    movd      xmm5, eax
    pshufd    xmm5, xmm5, 0
    mov       eax, 0x20802080  // multiplier shift by 5 and then repeat 6 bits
    movd      xmm6, eax
    pshufd    xmm6, xmm6, 0
    pcmpeqb   xmm3, xmm3       // generate mask 0xf800f800 for Red
    psllw     xmm3, 11
    pcmpeqb   xmm4, xmm4       // generate mask 0x07e007e0 for Green
    psllw     xmm4, 10
    psrlw     xmm4, 5
    pcmpeqb   xmm7, xmm7       // generate mask 0xff00ff00 for Alpha
    psllw     xmm7, 8
    mov       eax, [esp + 4]   // src_rgb565
    mov       edx, [esp + 8]   // dst_argb
    mov       ecx, [esp + 12]  // width
    sub       edx, eax
    sub       edx, eax
 convertloop:
    movdqu    xmm0, [eax]   // fetch 8 pixels of bgr565
    movdqa    xmm1, xmm0
    movdqa    xmm2, xmm0
    pand      xmm1, xmm3    // R in upper 5 bits
    psllw     xmm2, 11      // B in upper 5 bits
    pmulhuw   xmm1, xmm5    // * (256 + 8)
    pmulhuw   xmm2, xmm5    // * (256 + 8)
    psllw     xmm1, 8
    por       xmm1, xmm2    // RB
    pand      xmm0, xmm4    // G in middle 6 bits
    pmulhuw   xmm0, xmm6    // << 5 * (256 + 4)
    por       xmm0, xmm7    // AG
    movdqa    xmm2, xmm1
    punpcklbw xmm1, xmm0
    punpckhbw xmm2, xmm0
    movdqu    [eax * 2 + edx], xmm1  // store 4 pixels of ARGB
    movdqu    [eax * 2 + edx + 16], xmm2  // store next 4 pixels of ARGB
    lea       eax, [eax + 16]
    sub       ecx, 8
    jg        convertloop
    ret
  }
}

这篇关于使用SSE2优化RGB565到RGB888的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆