Rotating a bitmap 90 degrees

前端 未结 9 1854
粉色の甜心
粉色の甜心 2021-02-04 05:49

I have a one 64-bit integer, which I need to rotate 90 degrees in 8 x 8 area (preferably with straight bit-manipulation). I cannot figure out any handy algorith

9条回答
  •  萌比男神i
    2021-02-04 06:37

    This is quite easy using IA32 SIMD, there's a handy opcode to extract every eighth bit from a 64 bit value (this was written using DevStudio 2005):

    char
      source [8] = {0, 0, 0, 0, 0, 0, 0, 0xd0},
      dest [8];
    
    __asm
    {
      mov ch,3
      movq xmm0,qword ptr [source]
    Rotate2:
      lea edi,dest
      mov cl,8
    Rotate1:
      pmovmskb eax,xmm0
      psllq xmm0,1
      stosb
      dec cl
      jnz Rotate1
      movq xmm0,qword ptr [dest]
      dec ch
      jnz Rotate2
    }
    

    It rotates the data three times (-270 degrees) since +90 is a bit trickier (needs a bit more thought)

提交回复
热议问题