Rotating a bitmap 90 degrees

前端 未结 9 1747
粉色の甜心
粉色の甜心 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条回答
  • 2021-02-04 06:46

    If an if-powered loop is acceptable, the formula for bits is simple enough:

    8>>Column - Row - 1
    

    Column and Row are 0-indexed.

    This gives you this mapping:

     7 15 23 31 39 47 55 63
     6 14 22 ...
     5 ...
     4 ...
     3 ...
     2 ...
     1 ...
     0  8 16 24 32 40 48 54 
    
    0 讨论(0)
  • 2021-02-04 06:51

    probably something like that

    for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < 8; j++)
        {
            new_image[j*8+8-i] = image[i*8+j];
        }
    }
    
    0 讨论(0)
  • 2021-02-04 06:52
    v = (v & 0x000000000f0f0f0fUL) << 004 | (v & 0x00000000f0f0f0f0UL) << 040 |
        (v & 0xf0f0f0f000000000UL) >> 004 | (v & 0x0f0f0f0f00000000UL) >> 040;
    v = (v & 0x0000333300003333UL) << 002 | (v & 0x0000cccc0000ccccUL) << 020 | 
        (v & 0xcccc0000cccc0000UL) >> 002 | (v & 0x3333000033330000UL) >> 020;
    v = (v & 0x0055005500550055UL) << 001 | (v & 0x00aa00aa00aa00aaUL) << 010 | 
        (v & 0xaa00aa00aa00aa00UL) >> 001 | (v & 0x5500550055005500UL) >> 010;
    
    0 讨论(0)
提交回复
热议问题