Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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 + 0.5f);
  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 = util_cpu_to_le16(*src++);
  151.          *dst++ = z16_unorm_to_z32_float(value);
  152.       }
  153.       src_row += src_stride/sizeof(*src_row);
  154.       dst_row += dst_stride/sizeof(*dst_row);
  155.    }
  156. }
  157.  
  158. void
  159. util_format_z16_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  160.                                    const float *src_row, unsigned src_stride,
  161.                                    unsigned width, unsigned height)
  162. {
  163.    unsigned x, y;
  164.    for(y = 0; y < height; ++y) {
  165.       const float *src = src_row;
  166.       uint16_t *dst = (uint16_t *)dst_row;
  167.       for(x = 0; x < width; ++x) {
  168.          uint16_t value;
  169.          value = z32_float_to_z16_unorm(*src++);
  170.          *dst++ = util_le16_to_cpu(value);
  171.       }
  172.       dst_row += dst_stride/sizeof(*dst_row);
  173.       src_row += src_stride/sizeof(*src_row);
  174.    }
  175. }
  176.  
  177. void
  178. util_format_z16_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  179.                                        const uint8_t *src_row, unsigned src_stride,
  180.                                        unsigned width, unsigned height)
  181. {
  182.    unsigned x, y;
  183.    for(y = 0; y < height; ++y) {
  184.       uint32_t *dst = dst_row;
  185.       const uint16_t *src = (const uint16_t *)src_row;
  186.       for(x = 0; x < width; ++x) {
  187.          uint16_t value = util_cpu_to_le16(*src++);
  188.          *dst++ = z16_unorm_to_z32_unorm(value);
  189.       }
  190.       src_row += src_stride/sizeof(*src_row);
  191.       dst_row += dst_stride/sizeof(*dst_row);
  192.    }
  193. }
  194.  
  195. void
  196. util_format_z16_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  197.                                      const uint32_t *src_row, unsigned src_stride,
  198.                                      unsigned width, unsigned height)
  199. {
  200.    unsigned x, y;
  201.    for(y = 0; y < height; ++y) {
  202.       const uint32_t *src = src_row;
  203.       uint16_t *dst = (uint16_t *)dst_row;
  204.       for(x = 0; x < width; ++x) {
  205.          uint16_t value;
  206.          value = z32_unorm_to_z16_unorm(*src++);
  207.          *dst++ = util_le16_to_cpu(value);
  208.       }
  209.       dst_row += dst_stride/sizeof(*dst_row);
  210.       src_row += src_stride/sizeof(*src_row);
  211.    }
  212. }
  213.  
  214. void
  215. util_format_z32_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
  216.                                      const uint8_t *src_row, unsigned src_stride,
  217.                                      unsigned width, unsigned height)
  218. {
  219.    unsigned x, y;
  220.    for(y = 0; y < height; ++y) {
  221.       float *dst = dst_row;
  222.       const uint32_t *src = (const uint32_t *)src_row;
  223.       for(x = 0; x < width; ++x) {
  224.          uint32_t value = util_cpu_to_le32(*src++);
  225.          *dst++ = z32_unorm_to_z32_float(value);
  226.       }
  227.       src_row += src_stride/sizeof(*src_row);
  228.       dst_row += dst_stride/sizeof(*dst_row);
  229.    }
  230. }
  231.  
  232. void
  233. util_format_z32_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  234.                                    const float *src_row, unsigned src_stride,
  235.                                    unsigned width, unsigned height)
  236. {
  237.    unsigned x, y;
  238.    for(y = 0; y < height; ++y) {
  239.       const float *src = src_row;
  240.       uint32_t *dst = (uint32_t *)dst_row;
  241.       for(x = 0; x < width; ++x) {
  242.          uint32_t value;
  243.          value = z32_float_to_z32_unorm(*src++);
  244.          *dst++ = util_le32_to_cpu(value);
  245.       }
  246.       dst_row += dst_stride/sizeof(*dst_row);
  247.       src_row += src_stride/sizeof(*src_row);
  248.    }
  249. }
  250.  
  251. void
  252. util_format_z32_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  253.                                        const uint8_t *src_row, unsigned src_stride,
  254.                                        unsigned width, unsigned height)
  255. {
  256.    unsigned y;
  257.    for(y = 0; y < height; ++y) {
  258.       memcpy(dst_row, src_row, width * 4);
  259.       src_row += src_stride/sizeof(*src_row);
  260.       dst_row += dst_stride/sizeof(*dst_row);
  261.    }
  262. }
  263.  
  264. void
  265. util_format_z32_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  266.                                      const uint32_t *src_row, unsigned src_stride,
  267.                                      unsigned width, unsigned height)
  268. {
  269.    unsigned y;
  270.    for(y = 0; y < height; ++y) {
  271.       memcpy(dst_row, src_row, width * 4);
  272.       src_row += src_stride/sizeof(*src_row);
  273.       dst_row += dst_stride/sizeof(*dst_row);
  274.    }
  275. }
  276.  
  277. void
  278. util_format_z32_float_unpack_z_float(float *dst_row, unsigned dst_stride,
  279.                                      const uint8_t *src_row, unsigned src_stride,
  280.                                      unsigned width, unsigned height)
  281. {
  282.    unsigned y;
  283.    for(y = 0; y < height; ++y) {
  284.       memcpy(dst_row, src_row, width * 4);
  285.       src_row += src_stride/sizeof(*src_row);
  286.       dst_row += dst_stride/sizeof(*dst_row);
  287.    }
  288. }
  289.  
  290. void
  291. util_format_z32_float_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  292.                                    const float *src_row, unsigned src_stride,
  293.                                    unsigned width, unsigned height)
  294. {
  295.    unsigned y;
  296.    for(y = 0; y < height; ++y) {
  297.       memcpy(dst_row, src_row, width * 4);
  298.       src_row += src_stride/sizeof(*src_row);
  299.       dst_row += dst_stride/sizeof(*dst_row);
  300.    }
  301. }
  302.  
  303. void
  304. util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  305.                                        const uint8_t *src_row, unsigned src_stride,
  306.                                        unsigned width, unsigned height)
  307. {
  308.    unsigned x, y;
  309.    for(y = 0; y < height; ++y) {
  310.       uint32_t *dst = dst_row;
  311.       const float *src = (const float *)src_row;
  312.       for(x = 0; x < width; ++x) {
  313.          *dst++ = z32_float_to_z32_unorm(*src++);
  314.       }
  315.       src_row += src_stride/sizeof(*src_row);
  316.       dst_row += dst_stride/sizeof(*dst_row);
  317.    }
  318. }
  319.  
  320. void
  321. util_format_z32_float_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  322.                                      const uint32_t *src_row, unsigned src_stride,
  323.                                      unsigned width, unsigned height)
  324. {
  325.    unsigned x, y;
  326.    for(y = 0; y < height; ++y) {
  327.       const uint32_t *src = src_row;
  328.       float *dst = (float *)dst_row;
  329.       for(x = 0; x < width; ++x) {
  330.          *dst++ = z32_unorm_to_z32_float(*src++);
  331.       }
  332.       dst_row += dst_stride/sizeof(*dst_row);
  333.       src_row += src_stride/sizeof(*src_row);
  334.    }
  335. }
  336.  
  337. void
  338. util_format_z24_unorm_s8_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
  339.                                                 const uint8_t *src_row, unsigned src_stride,
  340.                                                 unsigned width, unsigned height)
  341. {
  342.    unsigned x, y;
  343.    for(y = 0; y < height; ++y) {
  344.       float *dst = dst_row;
  345.       const uint32_t *src = (const uint32_t *)src_row;
  346.       for(x = 0; x < width; ++x) {
  347.          uint32_t value =  util_cpu_to_le32(*src++);
  348.          *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
  349.       }
  350.       src_row += src_stride/sizeof(*src_row);
  351.       dst_row += dst_stride/sizeof(*dst_row);
  352.    }
  353. }
  354.  
  355. void
  356. util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  357.                                               const float *src_row, unsigned src_stride,
  358.                                               unsigned width, unsigned height)
  359. {
  360.    unsigned x, y;
  361.    for(y = 0; y < height; ++y) {
  362.       const float *src = src_row;
  363.       uint32_t *dst = (uint32_t *)dst_row;
  364.       for(x = 0; x < width; ++x) {
  365.          uint32_t value = util_le32_to_cpu(*dst);
  366.          value &= 0xff000000;
  367.          value |= z32_float_to_z24_unorm(*src++);
  368.          *dst++ = util_cpu_to_le32(value);
  369.       }
  370.       dst_row += dst_stride/sizeof(*dst_row);
  371.       src_row += src_stride/sizeof(*src_row);
  372.    }
  373. }
  374.  
  375. void
  376. util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  377.                                                   const uint8_t *src_row, unsigned src_stride,
  378.                                                   unsigned width, unsigned height)
  379. {
  380.    unsigned x, y;
  381.    for(y = 0; y < height; ++y) {
  382.       uint32_t *dst = dst_row;
  383.       const uint32_t *src = (const uint32_t *)src_row;
  384.       for(x = 0; x < width; ++x) {
  385.          uint32_t value = util_cpu_to_le32(*src++);
  386.          *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
  387.       }
  388.       src_row += src_stride/sizeof(*src_row);
  389.       dst_row += dst_stride/sizeof(*dst_row);
  390.    }
  391. }
  392.  
  393. void
  394. util_format_z24_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  395.                                                 const uint32_t *src_row, unsigned src_stride,
  396.                                                 unsigned width, unsigned height)
  397. {
  398.    unsigned x, y;
  399.    for(y = 0; y < height; ++y) {
  400.       const uint32_t *src = src_row;
  401.       uint32_t *dst = (uint32_t *)dst_row;
  402.       for(x = 0; x < width; ++x) {
  403.          uint32_t value = util_le32_to_cpu(*dst);
  404.          value &= 0xff000000;
  405.          value |= z32_unorm_to_z24_unorm(*src++);
  406.          *dst++ = util_cpu_to_le32(value);
  407.       }
  408.       dst_row += dst_stride/sizeof(*dst_row);
  409.       src_row += src_stride/sizeof(*src_row);
  410.    }
  411. }
  412.  
  413. void
  414. util_format_z24_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  415.                                                    const uint8_t *src_row, unsigned src_stride,
  416.                                                    unsigned width, unsigned height)
  417. {
  418.    unsigned x, y;
  419.    for(y = 0; y < height; ++y) {
  420.       uint8_t *dst = dst_row;
  421.       const uint32_t *src = (const uint32_t *)src_row;
  422.       for(x = 0; x < width; ++x) {
  423.          uint32_t value = util_cpu_to_le32(*src++);
  424.          *dst++ = value >> 24;
  425.       }
  426.       src_row += src_stride/sizeof(*src_row);
  427.       dst_row += dst_stride/sizeof(*dst_row);
  428.    }
  429. }
  430.  
  431. void
  432. util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  433.                                                  const uint8_t *src_row, unsigned src_stride,
  434.                                                  unsigned width, unsigned height)
  435. {
  436.    unsigned x, y;
  437.    for(y = 0; y < height; ++y) {
  438.       const uint8_t *src = src_row;
  439.       uint32_t *dst = (uint32_t *)dst_row;
  440.       for(x = 0; x < width; ++x) {
  441.          uint32_t value = util_le32_to_cpu(*dst);
  442.          value &= 0x00ffffff;
  443.          value |= *src++ << 24;
  444.          *dst++ = util_cpu_to_le32(value);
  445.       }
  446.       dst_row += dst_stride/sizeof(*dst_row);
  447.       src_row += src_stride/sizeof(*src_row);
  448.    }
  449. }
  450.  
  451. void
  452. util_format_s8_uint_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
  453.                                                 const uint8_t *src_row, unsigned src_stride,
  454.                                                 unsigned width, unsigned height)
  455. {
  456.    unsigned x, y;
  457.    for(y = 0; y < height; ++y) {
  458.       float *dst = dst_row;
  459.       const uint32_t *src = (const uint32_t *)src_row;
  460.       for(x = 0; x < width; ++x) {
  461.          uint32_t value = util_cpu_to_le32(*src++);
  462.          *dst++ = z24_unorm_to_z32_float(value >> 8);
  463.       }
  464.       src_row += src_stride/sizeof(*src_row);
  465.       dst_row += dst_stride/sizeof(*dst_row);
  466.    }
  467. }
  468.  
  469. void
  470. util_format_s8_uint_z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  471.                                               const float *src_row, unsigned src_stride,
  472.                                               unsigned width, unsigned height)
  473. {
  474.    unsigned x, y;
  475.    for(y = 0; y < height; ++y) {
  476.       const float *src = src_row;
  477.       uint32_t *dst = (uint32_t *)dst_row;
  478.       for(x = 0; x < width; ++x) {
  479.          uint32_t value = util_le32_to_cpu(*dst);
  480.          value &= 0x000000ff;
  481.          value |= z32_float_to_z24_unorm(*src++) << 8;
  482.          *dst++ = util_cpu_to_le32(value);
  483.       }
  484.       dst_row += dst_stride/sizeof(*dst_row);
  485.       src_row += src_stride/sizeof(*src_row);
  486.    }
  487. }
  488.  
  489. void
  490. util_format_s8_uint_z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  491.                                                   const uint8_t *src_row, unsigned src_stride,
  492.                                                   unsigned width, unsigned height)
  493. {
  494.    unsigned x, y;
  495.    for(y = 0; y < height; ++y) {
  496.       uint32_t *dst = dst_row;
  497.       const uint32_t *src = (const uint32_t *)src_row;
  498.       for(x = 0; x < width; ++x) {
  499.          uint32_t value = util_cpu_to_le32(*src++);
  500.          *dst++ = z24_unorm_to_z32_unorm(value >> 8);
  501.       }
  502.       src_row += src_stride/sizeof(*src_row);
  503.       dst_row += dst_stride/sizeof(*dst_row);
  504.    }
  505. }
  506.  
  507. void
  508. util_format_s8_uint_z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  509.                                                 const uint32_t *src_row, unsigned src_stride,
  510.                                                 unsigned width, unsigned height)
  511. {
  512.    unsigned x, y;
  513.    for(y = 0; y < height; ++y) {
  514.       const uint32_t *src = src_row;
  515.       uint32_t *dst = (uint32_t *)dst_row;
  516.       for(x = 0; x < width; ++x) {
  517.          uint32_t value = util_le32_to_cpu(*dst);
  518.          value &= 0x000000ff;
  519.          value |= *src++ & 0xffffff00;
  520.          *dst++ = util_cpu_to_le32(value);
  521.       }
  522.       dst_row += dst_stride/sizeof(*dst_row);
  523.       src_row += src_stride/sizeof(*src_row);
  524.    }
  525. }
  526.  
  527. void
  528. util_format_s8_uint_z24_unorm_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  529.                                                    const uint8_t *src_row, unsigned src_stride,
  530.                                                    unsigned width, unsigned height)
  531. {
  532.    unsigned x, y;
  533.    for(y = 0; y < height; ++y) {
  534.       uint8_t *dst = dst_row;
  535.       const uint32_t *src = (const uint32_t *)src_row;
  536.       for(x = 0; x < width; ++x) {
  537.          uint32_t value = util_cpu_to_le32(*src++);
  538.          *dst++ = value & 0xff;
  539.       }
  540.       src_row += src_stride/sizeof(*src_row);
  541.       dst_row += dst_stride/sizeof(*dst_row);
  542.    }
  543. }
  544.  
  545. void
  546. util_format_s8_uint_z24_unorm_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  547.                                                  const uint8_t *src_row, unsigned src_stride,
  548.                                                  unsigned width, unsigned height)
  549. {
  550.    unsigned x, y;
  551.    for(y = 0; y < height; ++y) {
  552.       const uint8_t *src = src_row;
  553.       uint32_t *dst = (uint32_t *)dst_row;
  554.       for(x = 0; x < width; ++x) {
  555.          uint32_t value = util_le32_to_cpu(*dst);
  556.          value &= 0xffffff00;
  557.          value |= *src++;
  558.          *dst++ = util_cpu_to_le32(value);
  559.       }
  560.       dst_row += dst_stride/sizeof(*dst_row);
  561.       src_row += src_stride/sizeof(*src_row);
  562.    }
  563. }
  564.  
  565. void
  566. util_format_z24x8_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
  567.                                        const uint8_t *src_row, unsigned src_stride,
  568.                                        unsigned width, unsigned height)
  569. {
  570.    unsigned x, y;
  571.    for(y = 0; y < height; ++y) {
  572.       float *dst = dst_row;
  573.       const uint32_t *src = (const uint32_t *)src_row;
  574.       for(x = 0; x < width; ++x) {
  575.          uint32_t value = util_cpu_to_le32(*src++);
  576.          *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
  577.       }
  578.       src_row += src_stride/sizeof(*src_row);
  579.       dst_row += dst_stride/sizeof(*dst_row);
  580.    }
  581. }
  582.  
  583. void
  584. util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  585.                                      const float *src_row, unsigned src_stride,
  586.                                      unsigned width, unsigned height)
  587. {
  588.    unsigned x, y;
  589.    for(y = 0; y < height; ++y) {
  590.       const float *src = src_row;
  591.       uint32_t *dst = (uint32_t *)dst_row;
  592.       for(x = 0; x < width; ++x) {
  593.          uint32_t value;
  594.          value = z32_float_to_z24_unorm(*src++);
  595.          *dst++ = util_le32_to_cpu(value);
  596.       }
  597.       dst_row += dst_stride/sizeof(*dst_row);
  598.       src_row += src_stride/sizeof(*src_row);
  599.    }
  600. }
  601.  
  602. void
  603. util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  604.                                          const uint8_t *src_row, unsigned src_stride,
  605.                                          unsigned width, unsigned height)
  606. {
  607.    unsigned x, y;
  608.    for(y = 0; y < height; ++y) {
  609.       uint32_t *dst = dst_row;
  610.       const uint32_t *src = (const uint32_t *)src_row;
  611.       for(x = 0; x < width; ++x) {
  612.          uint32_t value = util_cpu_to_le32(*src++);
  613.          *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
  614.       }
  615.       src_row += src_stride/sizeof(*src_row);
  616.       dst_row += dst_stride/sizeof(*dst_row);
  617.    }
  618. }
  619.  
  620. void
  621. util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  622.                                        const uint32_t *src_row, unsigned src_stride,
  623.                                        unsigned width, unsigned height)
  624. {
  625.    unsigned x, y;
  626.    for(y = 0; y < height; ++y) {
  627.       const uint32_t *src = src_row;
  628.       uint32_t *dst = (uint32_t *)dst_row;
  629.       for(x = 0; x < width; ++x) {
  630.          uint32_t value;
  631.          value = z32_unorm_to_z24_unorm(*src++);
  632.          *dst++ = util_cpu_to_le32(value);
  633.       }
  634.       dst_row += dst_stride/sizeof(*dst_row);
  635.       src_row += src_stride/sizeof(*src_row);
  636.    }
  637. }
  638.  
  639. void
  640. util_format_x8z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
  641.                                        const uint8_t *src_row, unsigned src_stride,
  642.                                        unsigned width, unsigned height)
  643. {
  644.    unsigned x, y;
  645.    for(y = 0; y < height; ++y) {
  646.       float *dst = dst_row;
  647.       const uint32_t *src = (uint32_t *)src_row;
  648.       for(x = 0; x < width; ++x) {
  649.          uint32_t value = util_cpu_to_le32(*src++);
  650.          *dst++ = z24_unorm_to_z32_float(value >> 8);
  651.       }
  652.       src_row += src_stride/sizeof(*src_row);
  653.       dst_row += dst_stride/sizeof(*dst_row);
  654.    }
  655. }
  656.  
  657. void
  658. util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  659.                                      const float *src_row, unsigned src_stride,
  660.                                      unsigned width, unsigned height)
  661. {
  662.    unsigned x, y;
  663.    for(y = 0; y < height; ++y) {
  664.       const float *src = src_row;
  665.       uint32_t *dst = (uint32_t *)dst_row;
  666.       for(x = 0; x < width; ++x) {
  667.          uint32_t value;
  668.          value = z32_float_to_z24_unorm(*src++) << 8;
  669.          *dst++ = util_cpu_to_le32(value);
  670.       }
  671.       dst_row += dst_stride/sizeof(*dst_row);
  672.       src_row += src_stride/sizeof(*src_row);
  673.    }
  674. }
  675.  
  676. void
  677. util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  678.                                          const uint8_t *src_row, unsigned src_stride,
  679.                                          unsigned width, unsigned height)
  680. {
  681.    unsigned x, y;
  682.    for(y = 0; y < height; ++y) {
  683.       uint32_t *dst = dst_row;
  684.       const uint32_t *src = (const uint32_t *)src_row;
  685.       for(x = 0; x < width; ++x) {
  686.          uint32_t value = util_cpu_to_le32(*src++);
  687.          *dst++ = z24_unorm_to_z32_unorm(value >> 8);
  688.       }
  689.       src_row += src_stride/sizeof(*src_row);
  690.       dst_row += dst_stride/sizeof(*dst_row);
  691.    }
  692. }
  693.  
  694. void
  695. util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  696.                                        const uint32_t *src_row, unsigned src_stride,
  697.                                        unsigned width, unsigned height)
  698. {
  699.    unsigned x, y;
  700.    for(y = 0; y < height; ++y) {
  701.       const uint32_t *src = src_row;
  702.       uint32_t *dst = (uint32_t *)dst_row;
  703.       for(x = 0; x < width; ++x) {
  704.          uint32_t value;
  705.          value = z32_unorm_to_z24_unorm(*src++) << 8;
  706.          *dst++ = util_cpu_to_le32(value);
  707.       }
  708.       dst_row += dst_stride/sizeof(*dst_row);
  709.       src_row += src_stride/sizeof(*src_row);
  710.    }
  711. }
  712.  
  713. void
  714. util_format_z32_float_s8x24_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
  715.                                                    const uint8_t *src_row, unsigned src_stride,
  716.                                                    unsigned width, unsigned height)
  717. {
  718.    unsigned x, y;
  719.    for(y = 0; y < height; ++y) {
  720.       float *dst = dst_row;
  721.       const float *src = (const float *)src_row;
  722.       for(x = 0; x < width; ++x) {
  723.          *dst = *src;
  724.          src += 2;
  725.          dst += 1;
  726.       }
  727.       src_row += src_stride/sizeof(*src_row);
  728.       dst_row += dst_stride/sizeof(*dst_row);
  729.    }
  730. }
  731.  
  732. void
  733. util_format_z32_float_s8x24_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
  734.                                                  const float *src_row, unsigned src_stride,
  735.                                                  unsigned width, unsigned height)
  736. {
  737.    unsigned x, y;
  738.    for(y = 0; y < height; ++y) {
  739.       const float *src = src_row;
  740.       float *dst = (float *)dst_row;
  741.       for(x = 0; x < width; ++x) {
  742.          *dst = *src;
  743.          src += 1;
  744.          dst += 2;
  745.       }
  746.       dst_row += dst_stride/sizeof(*dst_row);
  747.       src_row += src_stride/sizeof(*src_row);
  748.    }
  749. }
  750.  
  751. void
  752. util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
  753.                                                      const uint8_t *src_row, unsigned src_stride,
  754.                                                      unsigned width, unsigned height)
  755. {
  756.    unsigned x, y;
  757.    for(y = 0; y < height; ++y) {
  758.       uint32_t *dst = dst_row;
  759.       const float *src = (const float *)src_row;
  760.       for(x = 0; x < width; ++x) {
  761.          *dst = z32_float_to_z32_unorm(*src);
  762.          src += 2;
  763.          dst += 1;
  764.       }
  765.       src_row += src_stride/sizeof(*src_row);
  766.       dst_row += dst_stride/sizeof(*dst_row);
  767.    }
  768. }
  769.  
  770. void
  771. util_format_z32_float_s8x24_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
  772.                                                    const uint32_t *src_row, unsigned src_stride,
  773.                                                    unsigned width, unsigned height)
  774. {
  775.    unsigned x, y;
  776.    for(y = 0; y < height; ++y) {
  777.       const uint32_t *src = src_row;
  778.       float *dst = (float *)dst_row;
  779.       for(x = 0; x < width; ++x) {
  780.          *dst++ = z32_unorm_to_z32_float(*src++);
  781.       }
  782.       dst_row += dst_stride/sizeof(*dst_row);
  783.       src_row += src_stride/sizeof(*src_row);
  784.    }
  785. }
  786.  
  787. void
  788. util_format_z32_float_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  789.                                                       const uint8_t *src_row, unsigned src_stride,
  790.                                                       unsigned width, unsigned height)
  791. {
  792.    unsigned x, y;
  793.    for(y = 0; y < height; ++y) {
  794.       uint8_t *dst = dst_row;
  795.       const uint8_t *src = src_row + 4;
  796.       for(x = 0; x < width; ++x) {
  797.          *dst = *src;
  798.          src += 8;
  799.          dst += 1;
  800.       }
  801.       src_row += src_stride/sizeof(*src_row);
  802.       dst_row += dst_stride/sizeof(*dst_row);
  803.    }
  804. }
  805.  
  806. void
  807. util_format_z32_float_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  808.                                                     const uint8_t *src_row, unsigned src_stride,
  809.                                                     unsigned width, unsigned height)
  810. {
  811.    unsigned x, y;
  812.    for(y = 0; y < height; ++y) {
  813.       const uint8_t *src = src_row;
  814.       uint8_t *dst = dst_row + 4;
  815.       for(x = 0; x < width; ++x) {
  816.          *dst = *src;
  817.          src += 1;
  818.          dst += 8;
  819.       }
  820.       dst_row += dst_stride/sizeof(*dst_row);
  821.       src_row += src_stride/sizeof(*src_row);
  822.    }
  823. }
  824.  
  825.  
  826. void
  827. 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)
  828. {
  829.    util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row, dst_stride,
  830.                                                       src_row, src_stride,
  831.                                                       width, height);
  832. }
  833.  
  834. void
  835. 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)
  836. {
  837.    util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row, dst_stride,
  838.                                                     src_row, src_stride,
  839.                                                     width, height);
  840. }
  841.  
  842. void
  843. 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)
  844. {
  845.    util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row, dst_stride,
  846.                                                       src_row, src_stride,
  847.                                                       width, height);
  848. }
  849.  
  850. void
  851. 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)
  852. {
  853.    util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row, dst_stride,
  854.                                                       src_row, src_stride,
  855.                                                       width, height);
  856. }
  857.  
  858. void
  859. util_format_x32_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  860.                                                 const uint8_t *src_row, unsigned src_stride,
  861.                                                 unsigned width, unsigned height)
  862. {
  863.    util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row, dst_stride,
  864.                                                          src_row, src_stride,
  865.                                                          width, height);
  866.  
  867. }
  868.  
  869. void
  870. util_format_x32_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
  871.                                               const uint8_t *src_row, unsigned src_stride,
  872.                                               unsigned width, unsigned height)
  873. {
  874.    util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row, dst_stride,
  875.                                                        src_row, src_stride,
  876.                                                        width, height);
  877. }
  878.