Home | History | Annotate | Download | only in util
      1 /**************************************************************************
      2  *
      3  * Copyright 2010 VMware, Inc.
      4  * All Rights Reserved.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the
      8  * "Software"), to deal in the Software without restriction, including
      9  * without limitation the rights to use, copy, modify, merge, publish,
     10  * distribute, sub license, and/or sell copies of the Software, and to
     11  * permit persons to whom the Software is furnished to do so, subject to
     12  * the following conditions:
     13  *
     14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     17  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     19  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     20  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     21  *
     22  * The above copyright notice and this permission notice (including the
     23  * next paragraph) shall be included in all copies or substantial portions
     24  * of the Software.
     25  *
     26  **************************************************************************/
     27 
     28 
     29 #include "u_debug.h"
     30 #include "u_math.h"
     31 #include "u_format_zs.h"
     32 
     33 
     34 /*
     35  * z32_unorm conversion functions
     36  */
     37 
     38 static INLINE uint16_t
     39 z32_unorm_to_z16_unorm(uint32_t z)
     40 {
     41    /* z * 0xffff / 0xffffffff */
     42    return z >> 16;
     43 }
     44 
     45 static INLINE uint32_t
     46 z16_unorm_to_z32_unorm(uint16_t z)
     47 {
     48    /* z * 0xffffffff / 0xffff */
     49    return (z << 16) | z;
     50 }
     51 
     52 static INLINE uint32_t
     53 z32_unorm_to_z24_unorm(uint32_t z)
     54 {
     55    /* z * 0xffffff / 0xffffffff */
     56    return z >> 8;
     57 }
     58 
     59 static INLINE uint32_t
     60 z24_unorm_to_z32_unorm(uint32_t z)
     61 {
     62    /* z * 0xffffffff / 0xffffff */
     63    return (z << 8) | (z >> 16);
     64 }
     65 
     66 
     67 /*
     68  * z32_float conversion functions
     69  */
     70 
     71 static INLINE uint16_t
     72 z32_float_to_z16_unorm(float z)
     73 {
     74    const float scale = 0xffff;
     75    return (uint16_t)(z * scale);
     76 }
     77 
     78 static INLINE float
     79 z16_unorm_to_z32_float(uint16_t z)
     80 {
     81    const float scale = 1.0 / 0xffff;
     82    return (float)(z * scale);
     83 }
     84 
     85 static INLINE uint32_t
     86 z32_float_to_z24_unorm(float z)
     87 {
     88    const double scale = 0xffffff;
     89    return (uint32_t)(z * scale) & 0xffffff;
     90 }
     91 
     92 static INLINE float
     93 z24_unorm_to_z32_float(uint32_t z)
     94 {
     95    const double scale = 1.0 / 0xffffff;
     96    return (float)(z * scale);
     97 }
     98 
     99 static INLINE uint32_t
    100 z32_float_to_z32_unorm(float z)
    101 {
    102    const double scale = 0xffffffff;
    103    return (uint32_t)(z * scale);
    104 }
    105 
    106 static INLINE float
    107 z32_unorm_to_z32_float(uint32_t z)
    108 {
    109    const double scale = 1.0 / 0xffffffff;
    110    return (float)(z * scale);
    111 }
    112 
    113 
    114 void
    115 util_format_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    116                                          const uint8_t *src_row, unsigned src_stride,
    117                                          unsigned width, unsigned height)
    118 {
    119    unsigned y;
    120    for(y = 0; y < height; ++y) {
    121       memcpy(dst_row, src_row, width);
    122       src_row += src_stride/sizeof(*src_row);
    123       dst_row += dst_stride/sizeof(*dst_row);
    124    }
    125 }
    126 
    127 void
    128 util_format_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    129                                        const uint8_t *src_row, unsigned src_stride,
    130                                        unsigned width, unsigned height)
    131 {
    132    unsigned y;
    133    for(y = 0; y < height; ++y) {
    134       memcpy(dst_row, src_row, width);
    135       src_row += src_stride/sizeof(*src_row);
    136       dst_row += dst_stride/sizeof(*dst_row);
    137    }
    138 }
    139 
    140 void
    141 util_format_z16_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
    142                                      const uint8_t *src_row, unsigned src_stride,
    143                                      unsigned width, unsigned height)
    144 {
    145    unsigned x, y;
    146    for(y = 0; y < height; ++y) {
    147       float *dst = dst_row;
    148       const uint16_t *src = (const uint16_t *)src_row;
    149       for(x = 0; x < width; ++x) {
    150          uint16_t value = *src++;
    151 #ifdef PIPE_ARCH_BIG_ENDIAN
    152          value = util_bswap16(value);
    153 #endif
    154          *dst++ = z16_unorm_to_z32_float(value);
    155       }
    156       src_row += src_stride/sizeof(*src_row);
    157       dst_row += dst_stride/sizeof(*dst_row);
    158    }
    159 }
    160 
    161 void
    162 util_format_z16_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    163                                    const float *src_row, unsigned src_stride,
    164                                    unsigned width, unsigned height)
    165 {
    166    unsigned x, y;
    167    for(y = 0; y < height; ++y) {
    168       const float *src = src_row;
    169       uint16_t *dst = (uint16_t *)dst_row;
    170       for(x = 0; x < width; ++x) {
    171          uint16_t value;
    172          value = z32_float_to_z16_unorm(*src++);
    173 #ifdef PIPE_ARCH_BIG_ENDIAN
    174          value = util_bswap16(value);
    175 #endif
    176          *dst++ = value;
    177       }
    178       dst_row += dst_stride/sizeof(*dst_row);
    179       src_row += src_stride/sizeof(*src_row);
    180    }
    181 }
    182 
    183 void
    184 util_format_z16_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    185                                        const uint8_t *src_row, unsigned src_stride,
    186                                        unsigned width, unsigned height)
    187 {
    188    unsigned x, y;
    189    for(y = 0; y < height; ++y) {
    190       uint32_t *dst = dst_row;
    191       const uint16_t *src = (const uint16_t *)src_row;
    192       for(x = 0; x < width; ++x) {
    193          uint16_t value = *src++;
    194 #ifdef PIPE_ARCH_BIG_ENDIAN
    195          value = util_bswap16(value);
    196 #endif
    197          *dst++ = z16_unorm_to_z32_unorm(value);
    198       }
    199       src_row += src_stride/sizeof(*src_row);
    200       dst_row += dst_stride/sizeof(*dst_row);
    201    }
    202 }
    203 
    204 void
    205 util_format_z16_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    206                                      const uint32_t *src_row, unsigned src_stride,
    207                                      unsigned width, unsigned height)
    208 {
    209    unsigned x, y;
    210    for(y = 0; y < height; ++y) {
    211       const uint32_t *src = src_row;
    212       uint16_t *dst = (uint16_t *)dst_row;
    213       for(x = 0; x < width; ++x) {
    214          uint16_t value;
    215          value = z32_unorm_to_z16_unorm(*src++);
    216 #ifdef PIPE_ARCH_BIG_ENDIAN
    217          value = util_bswap16(value);
    218 #endif
    219          *dst++ = value;
    220       }
    221       dst_row += dst_stride/sizeof(*dst_row);
    222       src_row += src_stride/sizeof(*src_row);
    223    }
    224 }
    225 
    226 void
    227 util_format_z32_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
    228                                      const uint8_t *src_row, unsigned src_stride,
    229                                      unsigned width, unsigned height)
    230 {
    231    unsigned x, y;
    232    for(y = 0; y < height; ++y) {
    233       float *dst = dst_row;
    234       const uint32_t *src = (const uint32_t *)src_row;
    235       for(x = 0; x < width; ++x) {
    236          uint32_t value = *src++;
    237 #ifdef PIPE_ARCH_BIG_ENDIAN
    238          value = util_bswap32(value);
    239 #endif
    240          *dst++ = z32_unorm_to_z32_float(value);
    241       }
    242       src_row += src_stride/sizeof(*src_row);
    243       dst_row += dst_stride/sizeof(*dst_row);
    244    }
    245 }
    246 
    247 void
    248 util_format_z32_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    249                                    const float *src_row, unsigned src_stride,
    250                                    unsigned width, unsigned height)
    251 {
    252    unsigned x, y;
    253    for(y = 0; y < height; ++y) {
    254       const float *src = src_row;
    255       uint32_t *dst = (uint32_t *)dst_row;
    256       for(x = 0; x < width; ++x) {
    257          uint32_t value;
    258          value = z32_float_to_z32_unorm(*src++);
    259 #ifdef PIPE_ARCH_BIG_ENDIAN
    260          value = util_bswap32(value);
    261 #endif
    262          *dst++ = value;
    263       }
    264       dst_row += dst_stride/sizeof(*dst_row);
    265       src_row += src_stride/sizeof(*src_row);
    266    }
    267 }
    268 
    269 void
    270 util_format_z32_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    271                                        const uint8_t *src_row, unsigned src_stride,
    272                                        unsigned width, unsigned height)
    273 {
    274    unsigned y;
    275    for(y = 0; y < height; ++y) {
    276       memcpy(dst_row, src_row, width * 4);
    277       src_row += src_stride/sizeof(*src_row);
    278       dst_row += dst_stride/sizeof(*dst_row);
    279    }
    280 }
    281 
    282 void
    283 util_format_z32_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    284                                      const uint32_t *src_row, unsigned src_stride,
    285                                      unsigned width, unsigned height)
    286 {
    287    unsigned y;
    288    for(y = 0; y < height; ++y) {
    289       memcpy(dst_row, src_row, width * 4);
    290       src_row += src_stride/sizeof(*src_row);
    291       dst_row += dst_stride/sizeof(*dst_row);
    292    }
    293 }
    294 
    295 void
    296 util_format_z32_float_unpack_z_float(float *dst_row, unsigned dst_stride,
    297                                      const uint8_t *src_row, unsigned src_stride,
    298                                      unsigned width, unsigned height)
    299 {
    300    unsigned y;
    301    for(y = 0; y < height; ++y) {
    302       memcpy(dst_row, src_row, width * 4);
    303       src_row += src_stride/sizeof(*src_row);
    304       dst_row += dst_stride/sizeof(*dst_row);
    305    }
    306 }
    307 
    308 void
    309 util_format_z32_float_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    310                                    const float *src_row, unsigned src_stride,
    311                                    unsigned width, unsigned height)
    312 {
    313    unsigned y;
    314    for(y = 0; y < height; ++y) {
    315       memcpy(dst_row, src_row, width * 4);
    316       src_row += src_stride/sizeof(*src_row);
    317       dst_row += dst_stride/sizeof(*dst_row);
    318    }
    319 }
    320 
    321 void
    322 util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    323                                        const uint8_t *src_row, unsigned src_stride,
    324                                        unsigned width, unsigned height)
    325 {
    326    unsigned x, y;
    327    for(y = 0; y < height; ++y) {
    328       uint32_t *dst = dst_row;
    329       const float *src = (const float *)src_row;
    330       for(x = 0; x < width; ++x) {
    331          *dst++ = z32_float_to_z32_unorm(*src++);
    332       }
    333       src_row += src_stride/sizeof(*src_row);
    334       dst_row += dst_stride/sizeof(*dst_row);
    335    }
    336 }
    337 
    338 void
    339 util_format_z32_float_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    340                                      const uint32_t *src_row, unsigned src_stride,
    341                                      unsigned width, unsigned height)
    342 {
    343    unsigned x, y;
    344    for(y = 0; y < height; ++y) {
    345       const uint32_t *src = src_row;
    346       float *dst = (float *)dst_row;
    347       for(x = 0; x < width; ++x) {
    348          *dst++ = z32_unorm_to_z32_float(*src++);
    349       }
    350       dst_row += dst_stride/sizeof(*dst_row);
    351       src_row += src_stride/sizeof(*src_row);
    352    }
    353 }
    354 
    355 void
    356 util_format_z24_unorm_s8_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
    357                                                 const uint8_t *src_row, unsigned src_stride,
    358                                                 unsigned width, unsigned height)
    359 {
    360    unsigned x, y;
    361    for(y = 0; y < height; ++y) {
    362       float *dst = dst_row;
    363       const uint32_t *src = (const uint32_t *)src_row;
    364       for(x = 0; x < width; ++x) {
    365          uint32_t value = *src++;
    366 #ifdef PIPE_ARCH_BIG_ENDIAN
    367          value = util_bswap32(value);
    368 #endif
    369          *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
    370       }
    371       src_row += src_stride/sizeof(*src_row);
    372       dst_row += dst_stride/sizeof(*dst_row);
    373    }
    374 }
    375 
    376 void
    377 util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    378                                               const float *src_row, unsigned src_stride,
    379                                               unsigned width, unsigned height)
    380 {
    381    unsigned x, y;
    382    for(y = 0; y < height; ++y) {
    383       const float *src = src_row;
    384       uint32_t *dst = (uint32_t *)dst_row;
    385       for(x = 0; x < width; ++x) {
    386          uint32_t value = *dst;
    387 #ifdef PIPE_ARCH_BIG_ENDIAN
    388          value = util_bswap32(value);
    389 #endif
    390          value &= 0xff000000;
    391          value |= z32_float_to_z24_unorm(*src++);
    392 #ifdef PIPE_ARCH_BIG_ENDIAN
    393          value = util_bswap32(value);
    394 #endif
    395          *dst++ = value;
    396       }
    397       dst_row += dst_stride/sizeof(*dst_row);
    398       src_row += src_stride/sizeof(*src_row);
    399    }
    400 }
    401 
    402 void
    403 util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    404                                                   const uint8_t *src_row, unsigned src_stride,
    405                                                   unsigned width, unsigned height)
    406 {
    407    unsigned x, y;
    408    for(y = 0; y < height; ++y) {
    409       uint32_t *dst = dst_row;
    410       const uint32_t *src = (const uint32_t *)src_row;
    411       for(x = 0; x < width; ++x) {
    412          uint32_t value = *src++;
    413 #ifdef PIPE_ARCH_BIG_ENDIAN
    414          value = util_bswap32(value);
    415 #endif
    416          *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
    417       }
    418       src_row += src_stride/sizeof(*src_row);
    419       dst_row += dst_stride/sizeof(*dst_row);
    420    }
    421 }
    422 
    423 void
    424 util_format_z24_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    425                                                 const uint32_t *src_row, unsigned src_stride,
    426                                                 unsigned width, unsigned height)
    427 {
    428    unsigned x, y;
    429    for(y = 0; y < height; ++y) {
    430       const uint32_t *src = src_row;
    431       uint32_t *dst = (uint32_t *)dst_row;
    432       for(x = 0; x < width; ++x) {
    433          uint32_t value= *dst;
    434 #ifdef PIPE_ARCH_BIG_ENDIAN
    435          value = util_bswap32(value);
    436 #endif
    437          value &= 0xff000000;
    438          value |= z32_unorm_to_z24_unorm(*src++);
    439 #ifdef PIPE_ARCH_BIG_ENDIAN
    440          value = util_bswap32(value);
    441 #endif
    442          *dst++ = value;
    443       }
    444       dst_row += dst_stride/sizeof(*dst_row);
    445       src_row += src_stride/sizeof(*src_row);
    446    }
    447 }
    448 
    449 void
    450 util_format_z24_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    451                                                    const uint8_t *src_row, unsigned src_stride,
    452                                                    unsigned width, unsigned height)
    453 {
    454    unsigned x, y;
    455    for(y = 0; y < height; ++y) {
    456       uint8_t *dst = dst_row;
    457       const uint32_t *src = (const uint32_t *)src_row;
    458       for(x = 0; x < width; ++x) {
    459          uint32_t value = *src++;
    460 #ifdef PIPE_ARCH_BIG_ENDIAN
    461          value = util_bswap32(value);
    462 #endif
    463          *dst++ = value >> 24;
    464       }
    465       src_row += src_stride/sizeof(*src_row);
    466       dst_row += dst_stride/sizeof(*dst_row);
    467    }
    468 }
    469 
    470 void
    471 util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    472                                                  const uint8_t *src_row, unsigned src_stride,
    473                                                  unsigned width, unsigned height)
    474 {
    475    unsigned x, y;
    476    for(y = 0; y < height; ++y) {
    477       const uint8_t *src = src_row;
    478       uint32_t *dst = (uint32_t *)dst_row;
    479       for(x = 0; x < width; ++x) {
    480          uint32_t value = *dst;
    481 #ifdef PIPE_ARCH_BIG_ENDIAN
    482          value = util_bswap32(value);
    483 #endif
    484          value &= 0x00ffffff;
    485          value |= *src++ << 24;
    486 #ifdef PIPE_ARCH_BIG_ENDIAN
    487          value = util_bswap32(value);
    488 #endif
    489          *dst++ = value;
    490       }
    491       dst_row += dst_stride/sizeof(*dst_row);
    492       src_row += src_stride/sizeof(*src_row);
    493    }
    494 }
    495 
    496 void
    497 util_format_s8_uint_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
    498                                                 const uint8_t *src_row, unsigned src_stride,
    499                                                 unsigned width, unsigned height)
    500 {
    501    unsigned x, y;
    502    for(y = 0; y < height; ++y) {
    503       float *dst = dst_row;
    504       const uint32_t *src = (const uint32_t *)src_row;
    505       for(x = 0; x < width; ++x) {
    506          uint32_t value = *src++;
    507 #ifdef PIPE_ARCH_BIG_ENDIAN
    508          value = util_bswap32(value);
    509 #endif
    510          *dst++ = z24_unorm_to_z32_float(value >> 8);
    511       }
    512       src_row += src_stride/sizeof(*src_row);
    513       dst_row += dst_stride/sizeof(*dst_row);
    514    }
    515 }
    516 
    517 void
    518 util_format_s8_uint_z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    519                                               const float *src_row, unsigned src_stride,
    520                                               unsigned width, unsigned height)
    521 {
    522    unsigned x, y;
    523    for(y = 0; y < height; ++y) {
    524       const float *src = src_row;
    525       uint32_t *dst = (uint32_t *)dst_row;
    526       for(x = 0; x < width; ++x) {
    527          uint32_t value = *dst;
    528 #ifdef PIPE_ARCH_BIG_ENDIAN
    529          value = util_bswap32(value);
    530 #endif
    531          value &= 0x000000ff;
    532          value |= z32_float_to_z24_unorm(*src++) << 8;
    533 #ifdef PIPE_ARCH_BIG_ENDIAN
    534          value = util_bswap32(value);
    535 #endif
    536          *dst++ = value;
    537       }
    538       dst_row += dst_stride/sizeof(*dst_row);
    539       src_row += src_stride/sizeof(*src_row);
    540    }
    541 }
    542 
    543 void
    544 util_format_s8_uint_z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    545                                                   const uint8_t *src_row, unsigned src_stride,
    546                                                   unsigned width, unsigned height)
    547 {
    548    unsigned x, y;
    549    for(y = 0; y < height; ++y) {
    550       uint32_t *dst = dst_row;
    551       const uint32_t *src = (const uint32_t *)src_row;
    552       for(x = 0; x < width; ++x) {
    553          uint32_t value = *src++;
    554 #ifdef PIPE_ARCH_BIG_ENDIAN
    555          value = util_bswap32(value);
    556 #endif
    557          *dst++ = z24_unorm_to_z32_unorm(value >> 8);
    558       }
    559       src_row += src_stride/sizeof(*src_row);
    560       dst_row += dst_stride/sizeof(*dst_row);
    561    }
    562 }
    563 
    564 void
    565 util_format_s8_uint_z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    566                                                 const uint32_t *src_row, unsigned src_stride,
    567                                                 unsigned width, unsigned height)
    568 {
    569    unsigned x, y;
    570    for(y = 0; y < height; ++y) {
    571       const uint32_t *src = src_row;
    572       uint32_t *dst = (uint32_t *)dst_row;
    573       for(x = 0; x < width; ++x) {
    574          uint32_t value = *dst;
    575 #ifdef PIPE_ARCH_BIG_ENDIAN
    576          value = util_bswap32(value);
    577 #endif
    578          value &= 0x000000ff;
    579          value |= *src++ & 0xffffff00;
    580 #ifdef PIPE_ARCH_BIG_ENDIAN
    581          value = util_bswap32(value);
    582 #endif
    583          *dst++ = value;
    584       }
    585       dst_row += dst_stride/sizeof(*dst_row);
    586       src_row += src_stride/sizeof(*src_row);
    587    }
    588 }
    589 
    590 void
    591 util_format_s8_uint_z24_unorm_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    592                                                    const uint8_t *src_row, unsigned src_stride,
    593                                                    unsigned width, unsigned height)
    594 {
    595    unsigned x, y;
    596    for(y = 0; y < height; ++y) {
    597       uint8_t *dst = dst_row;
    598       const uint32_t *src = (const uint32_t *)src_row;
    599       for(x = 0; x < width; ++x) {
    600          uint32_t value = *src++;
    601 #ifdef PIPE_ARCH_BIG_ENDIAN
    602          value = util_bswap32(value);
    603 #endif
    604          *dst++ = value & 0xff;
    605       }
    606       src_row += src_stride/sizeof(*src_row);
    607       dst_row += dst_stride/sizeof(*dst_row);
    608    }
    609 }
    610 
    611 void
    612 util_format_s8_uint_z24_unorm_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    613                                                  const uint8_t *src_row, unsigned src_stride,
    614                                                  unsigned width, unsigned height)
    615 {
    616    unsigned x, y;
    617    for(y = 0; y < height; ++y) {
    618       const uint8_t *src = src_row;
    619       uint32_t *dst = (uint32_t *)dst_row;
    620       for(x = 0; x < width; ++x) {
    621          uint32_t value = *dst;
    622 #ifdef PIPE_ARCH_BIG_ENDIAN
    623          value = util_bswap32(value);
    624 #endif
    625          value &= 0xffffff00;
    626          value |= *src++;
    627 #ifdef PIPE_ARCH_BIG_ENDIAN
    628          value = util_bswap32(value);
    629 #endif
    630          *dst++ = value;
    631       }
    632       dst_row += dst_stride/sizeof(*dst_row);
    633       src_row += src_stride/sizeof(*src_row);
    634    }
    635 }
    636 
    637 void
    638 util_format_z24x8_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
    639                                        const uint8_t *src_row, unsigned src_stride,
    640                                        unsigned width, unsigned height)
    641 {
    642    unsigned x, y;
    643    for(y = 0; y < height; ++y) {
    644       float *dst = dst_row;
    645       const uint32_t *src = (const uint32_t *)src_row;
    646       for(x = 0; x < width; ++x) {
    647          uint32_t value = *src++;
    648 #ifdef PIPE_ARCH_BIG_ENDIAN
    649          value = util_bswap32(value);
    650 #endif
    651          *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
    652       }
    653       src_row += src_stride/sizeof(*src_row);
    654       dst_row += dst_stride/sizeof(*dst_row);
    655    }
    656 }
    657 
    658 void
    659 util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    660                                      const float *src_row, unsigned src_stride,
    661                                      unsigned width, unsigned height)
    662 {
    663    unsigned x, y;
    664    for(y = 0; y < height; ++y) {
    665       const float *src = src_row;
    666       uint32_t *dst = (uint32_t *)dst_row;
    667       for(x = 0; x < width; ++x) {
    668          uint32_t value;
    669          value = z32_float_to_z24_unorm(*src++);
    670 #ifdef PIPE_ARCH_BIG_ENDIAN
    671          value = util_bswap32(value);
    672 #endif
    673          *dst++ = value;
    674       }
    675       dst_row += dst_stride/sizeof(*dst_row);
    676       src_row += src_stride/sizeof(*src_row);
    677    }
    678 }
    679 
    680 void
    681 util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    682                                          const uint8_t *src_row, unsigned src_stride,
    683                                          unsigned width, unsigned height)
    684 {
    685    unsigned x, y;
    686    for(y = 0; y < height; ++y) {
    687       uint32_t *dst = dst_row;
    688       const uint32_t *src = (const uint32_t *)src_row;
    689       for(x = 0; x < width; ++x) {
    690          uint32_t value = *src++;
    691 #ifdef PIPE_ARCH_BIG_ENDIAN
    692          value = util_bswap32(value);
    693 #endif
    694          *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
    695       }
    696       src_row += src_stride/sizeof(*src_row);
    697       dst_row += dst_stride/sizeof(*dst_row);
    698    }
    699 }
    700 
    701 void
    702 util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    703                                        const uint32_t *src_row, unsigned src_stride,
    704                                        unsigned width, unsigned height)
    705 {
    706    unsigned x, y;
    707    for(y = 0; y < height; ++y) {
    708       const uint32_t *src = src_row;
    709       uint32_t *dst = (uint32_t *)dst_row;
    710       for(x = 0; x < width; ++x) {
    711          uint32_t value;
    712          value = z32_unorm_to_z24_unorm(*src++);
    713 #ifdef PIPE_ARCH_BIG_ENDIAN
    714          value = util_bswap32(value);
    715 #endif
    716          *dst++ = value;
    717       }
    718       dst_row += dst_stride/sizeof(*dst_row);
    719       src_row += src_stride/sizeof(*src_row);
    720    }
    721 }
    722 
    723 void
    724 util_format_x8z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
    725                                        const uint8_t *src_row, unsigned src_stride,
    726                                        unsigned width, unsigned height)
    727 {
    728    unsigned x, y;
    729    for(y = 0; y < height; ++y) {
    730       float *dst = dst_row;
    731       const uint32_t *src = (uint32_t *)src_row;
    732       for(x = 0; x < width; ++x) {
    733          uint32_t value = *src++;
    734 #ifdef PIPE_ARCH_BIG_ENDIAN
    735          value = util_bswap32(value);
    736 #endif
    737          *dst++ = z24_unorm_to_z32_float(value >> 8);
    738       }
    739       src_row += src_stride/sizeof(*src_row);
    740       dst_row += dst_stride/sizeof(*dst_row);
    741    }
    742 }
    743 
    744 void
    745 util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    746                                      const float *src_row, unsigned src_stride,
    747                                      unsigned width, unsigned height)
    748 {
    749    unsigned x, y;
    750    for(y = 0; y < height; ++y) {
    751       const float *src = src_row;
    752       uint32_t *dst = (uint32_t *)dst_row;
    753       for(x = 0; x < width; ++x) {
    754          uint32_t value;
    755          value = z32_float_to_z24_unorm(*src++) << 8;
    756 #ifdef PIPE_ARCH_BIG_ENDIAN
    757          value = util_bswap32(value);
    758 #endif
    759          *dst++ = value;
    760       }
    761       dst_row += dst_stride/sizeof(*dst_row);
    762       src_row += src_stride/sizeof(*src_row);
    763    }
    764 }
    765 
    766 void
    767 util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    768                                          const uint8_t *src_row, unsigned src_stride,
    769                                          unsigned width, unsigned height)
    770 {
    771    unsigned x, y;
    772    for(y = 0; y < height; ++y) {
    773       uint32_t *dst = dst_row;
    774       const uint32_t *src = (const uint32_t *)src_row;
    775       for(x = 0; x < width; ++x) {
    776          uint32_t value = *src++;
    777 #ifdef PIPE_ARCH_BIG_ENDIAN
    778          value = util_bswap32(value);
    779 #endif
    780          *dst++ = z24_unorm_to_z32_unorm(value >> 8);
    781       }
    782       src_row += src_stride/sizeof(*src_row);
    783       dst_row += dst_stride/sizeof(*dst_row);
    784    }
    785 }
    786 
    787 void
    788 util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    789                                        const uint32_t *src_row, unsigned src_stride,
    790                                        unsigned width, unsigned height)
    791 {
    792    unsigned x, y;
    793    for(y = 0; y < height; ++y) {
    794       const uint32_t *src = src_row;
    795       uint32_t *dst = (uint32_t *)dst_row;
    796       for(x = 0; x < width; ++x) {
    797          uint32_t value;
    798          value = z32_unorm_to_z24_unorm(*src++) << 8;
    799 #ifdef PIPE_ARCH_BIG_ENDIAN
    800          value = util_bswap32(value);
    801 #endif
    802          *dst++ = value;
    803       }
    804       dst_row += dst_stride/sizeof(*dst_row);
    805       src_row += src_stride/sizeof(*src_row);
    806    }
    807 }
    808 
    809 void
    810 util_format_z32_float_s8x24_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
    811                                                    const uint8_t *src_row, unsigned src_stride,
    812                                                    unsigned width, unsigned height)
    813 {
    814    unsigned x, y;
    815    for(y = 0; y < height; ++y) {
    816       float *dst = dst_row;
    817       const float *src = (const float *)src_row;
    818       for(x = 0; x < width; ++x) {
    819          *dst = *src;
    820          src += 2;
    821          dst += 1;
    822       }
    823       src_row += src_stride/sizeof(*src_row);
    824       dst_row += dst_stride/sizeof(*dst_row);
    825    }
    826 }
    827 
    828 void
    829 util_format_z32_float_s8x24_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
    830                                                  const float *src_row, unsigned src_stride,
    831                                                  unsigned width, unsigned height)
    832 {
    833    unsigned x, y;
    834    for(y = 0; y < height; ++y) {
    835       const float *src = src_row;
    836       float *dst = (float *)dst_row;
    837       for(x = 0; x < width; ++x) {
    838          *dst = *src;
    839          src += 1;
    840          dst += 2;
    841       }
    842       dst_row += dst_stride/sizeof(*dst_row);
    843       src_row += src_stride/sizeof(*src_row);
    844    }
    845 }
    846 
    847 void
    848 util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
    849                                                      const uint8_t *src_row, unsigned src_stride,
    850                                                      unsigned width, unsigned height)
    851 {
    852    unsigned x, y;
    853    for(y = 0; y < height; ++y) {
    854       uint32_t *dst = dst_row;
    855       const float *src = (const float *)src_row;
    856       for(x = 0; x < width; ++x) {
    857          *dst = z32_float_to_z32_unorm(*src);
    858          src += 2;
    859          dst += 1;
    860       }
    861       src_row += src_stride/sizeof(*src_row);
    862       dst_row += dst_stride/sizeof(*dst_row);
    863    }
    864 }
    865 
    866 void
    867 util_format_z32_float_s8x24_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
    868                                                    const uint32_t *src_row, unsigned src_stride,
    869                                                    unsigned width, unsigned height)
    870 {
    871    unsigned x, y;
    872    for(y = 0; y < height; ++y) {
    873       const uint32_t *src = src_row;
    874       float *dst = (float *)dst_row;
    875       for(x = 0; x < width; ++x) {
    876          *dst++ = z32_unorm_to_z32_float(*src++);
    877       }
    878       dst_row += dst_stride/sizeof(*dst_row);
    879       src_row += src_stride/sizeof(*src_row);
    880    }
    881 }
    882 
    883 void
    884 util_format_z32_float_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    885                                                       const uint8_t *src_row, unsigned src_stride,
    886                                                       unsigned width, unsigned height)
    887 {
    888    unsigned x, y;
    889    for(y = 0; y < height; ++y) {
    890       uint8_t *dst = dst_row;
    891       const uint8_t *src = src_row + 4;
    892       for(x = 0; x < width; ++x) {
    893          *dst = *src;
    894          src += 8;
    895          dst += 1;
    896       }
    897       src_row += src_stride/sizeof(*src_row);
    898       dst_row += dst_stride/sizeof(*dst_row);
    899    }
    900 }
    901 
    902 void
    903 util_format_z32_float_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    904                                                     const uint8_t *src_row, unsigned src_stride,
    905                                                     unsigned width, unsigned height)
    906 {
    907    unsigned x, y;
    908    for(y = 0; y < height; ++y) {
    909       const uint8_t *src = src_row;
    910       uint8_t *dst = dst_row + 4;
    911       for(x = 0; x < width; ++x) {
    912          *dst = *src;
    913          src += 1;
    914          dst += 8;
    915       }
    916       dst_row += dst_stride/sizeof(*dst_row);
    917       src_row += src_stride/sizeof(*src_row);
    918    }
    919 }
    920 
    921 
    922 void
    923 util_format_x24s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
    924 {
    925    util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row, dst_stride,
    926 						      src_row, src_stride,
    927 						      width, height);
    928 }
    929 
    930 void
    931 util_format_x24s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
    932 {
    933    util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row, dst_stride,
    934 						    src_row, src_stride,
    935 						    width, height);
    936 }
    937 
    938 void
    939 util_format_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
    940 {
    941    util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row, dst_stride,
    942 						      src_row, src_stride,
    943 						      width, height);
    944 }
    945 
    946 void
    947 util_format_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
    948 {
    949    util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row, dst_stride,
    950 						      src_row, src_stride,
    951 						      width, height);
    952 }
    953 
    954 void
    955 util_format_x32_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    956 						const uint8_t *src_row, unsigned src_stride,
    957 						unsigned width, unsigned height)
    958 {
    959    util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row, dst_stride,
    960 							 src_row, src_stride,
    961 							 width, height);
    962 
    963 }
    964 
    965 void
    966 util_format_x32_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
    967 					      const uint8_t *src_row, unsigned src_stride,
    968 					      unsigned width, unsigned height)
    969 {
    970    util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row, dst_stride,
    971                                                        src_row, src_stride,
    972 						       width, height);
    973 }
    974