engine/dlib/src/dlib/webp.cpp
// Compose 32-bit colora RGBA, colorb RGBA and 32-bit modulation buffers into PVRTC1 64-bit blocks.
// Data is transformed from linear bitmap space to morton order (PVRTC1), ref: http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
Compose 32-bit colora RGBA, colorb RGBA and 32-bit modulation buffers into PVRTC1 64-bit blocks.
Compose 32 - bit colora RGBA colorb RGBA and 32 - bit modulation buffers into PVRTC1 64 - bit blocks .
static void PVRTComposeBlocks(uint64_t* data, const uint32_t width, const uint32_t height, const uint32_t* color_a, const uint32_t* color_b, const uint32_t* modulation)
    {
        for(uint32_t y = 0; y < height; ++y)
        {
            uint32_t my = (y | (y << 8)) & 0x00FF00FF;
            my = (my | (my << 4)) & 0x0F0F0F0F;
            my = (my | (my << 2)) & 0x33333333;
            my = (my | (my << 1)) & 0x55555555;
            const uint32_t yi = y*width;
            for(uint32_t x = 0; x < width; ++x)
            {
                const uint32_t li = yi+x;
                uint64_t color;
                uint32_t c = color_a[li];
                if((c & 0xf0000000) == 0xf0000000)
                {
                    color = ((c & 0xff) << 7) | ((c & 0xff00) >> 6) | ((c & 0xff0000) >> 19) | 0x8000;
                }
                else
                {
                    color = ((c & 0xff) << 4) | ((c & 0xff00) >> 8) | ((c & 0xff0000) >> 20) | ((c & 0xff000000) >> 17);
                }
                c = color_b[li];
                if((c & 0xf0000000) == 0xf0000000)
                {
                    color |= ((c & 0xff) << 23) | ((c & 0xff00) << 10) | ((c & 0xff0000) >> 3) | 0x80000000;
                }
                else
                {
                    color |= ((c & 0xff) << 20) | ((c & 0xff00) << 8) | ((c & 0xff0000) >> 4) | ((c & 0xff000000) >> 1);
                }
                uint32_t mx = (x | (x << 8)) & 0x00FF00FF;
                mx = (mx | (mx << 4)) & 0x0F0F0F0F;
                mx = (mx | (mx << 2)) & 0x33333333;
                mx = (mx | (mx << 1)) & 0x55555555;
                const uint32_t mi = my | (mx << 1);
                data[mi] = modulation[li] | (color << 32);
            }
        }
    }
static void PVRTComposeBlocks ( uint64_t * data , const uint32_t width , const uint32_t height , const uint32_t * color_a , const uint32_t * color_b , const uint32_t * modulation ) { for ( uint32_t y = 0 ; y < height ; ++ y ) { uint32_t my = ( y | ( y << 8 ) ) & 0x00FF00FF ; my = ( my | ( my << 4 ) ) & 0x0F0F0F0F ; my = ( my | ( my << 2 ) ) & 0x33333333 ; my = ( my | ( my << 1 ) ) & 0x55555555 ; const uint32_t yi = y * width ; for ( uint32_t x = 0 ; x < width ; ++ x ) { const uint32_t li = yi + x ; uint64_t color ; uint32_t c = color_a [ li ] ; if ( ( c & 0xf0000000 ) == 0xf0000000 ) { color = ( ( c & 0xff ) << 7 ) | ( ( c & 0xff00 ) >> 6 ) | ( ( c & 0xff0000 ) >> 19 ) | 0x8000 ; } else { color = ( ( c & 0xff ) << 4 ) | ( ( c & 0xff00 ) >> 8 ) | ( ( c & 0xff0000 ) >> 20 ) | ( ( c & 0xff000000 ) >> 17 ) ; } c = color_b [ li ] ; if ( ( c & 0xf0000000 ) == 0xf0000000 ) { color |= ( ( c & 0xff ) << 23 ) | ( ( c & 0xff00 ) << 10 ) | ( ( c & 0xff0000 ) >> 3 ) | 0x80000000 ; } else { color |= ( ( c & 0xff ) << 20 ) | ( ( c & 0xff00 ) << 8 ) | ( ( c & 0xff0000 ) >> 4 ) | ( ( c & 0xff000000 ) >> 1 ) ; } uint32_t mx = ( x | ( x << 8 ) ) & 0x00FF00FF ; mx = ( mx | ( mx << 4 ) ) & 0x0F0F0F0F ; mx = ( mx | ( mx << 2 ) ) & 0x33333333 ; mx = ( mx | ( mx << 1 ) ) & 0x55555555 ; const uint32_t mi = my | ( mx << 1 ) ; data [ mi ] = modulation [ li ] | ( color << 32 ) ; } } }
Compose 32-bit colora RGBA, colorb RGBA and 32-bit modulation buffers into PVRTC1 64-bit blocks.
Compose 32 - bit colora RGBA colorb RGBA and 32 - bit modulation buffers into PVRTC1 64 - bit blocks .
// morton order y (max 0xffff). // RGB 888 -> RGB 555. MSB is color mode // ARGB 4444. MSB is color mode // RGB 554 (Blue is 3 + 1 Modulation mode). MSB is color mode // ARGB 4443 (Blue is 3 + 1 Modulation mode). MSB is color mode // morton order x (max 0xffff)