Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | 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. /**
  30.  * @file
  31.  * YUV and RGB subsampled formats conversion.
  32.  *
  33.  * @author Jose Fonseca <jfonseca@vmware.com>
  34.  */
  35.  
  36.  
  37. #include "util/u_debug.h"
  38. #include "util/u_format_yuv.h"
  39.  
  40.  
  41. void
  42. util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  43.                                          const uint8_t *src_row, unsigned src_stride,
  44.                                          unsigned width, unsigned height)
  45. {
  46.    unsigned x, y;
  47.  
  48.    for (y = 0; y < height; y += 1) {
  49.       float *dst = dst_row;
  50.       const uint32_t *src = (const uint32_t *)src_row;
  51.       uint32_t value;
  52.       float r, g0, g1, b;
  53.  
  54.       for (x = 0; x + 1 < width; x += 2) {
  55.          value = *src++;
  56.  
  57. #ifdef PIPE_ARCH_BIG_ENDIAN
  58.          value = util_bswap32(value);
  59. #endif
  60.  
  61.          r  = ubyte_to_float((value >>  0) & 0xff);
  62.          g0 = ubyte_to_float((value >>  8) & 0xff);
  63.          b  = ubyte_to_float((value >> 16) & 0xff);
  64.          g1 = ubyte_to_float((value >> 24) & 0xff);
  65.  
  66.          dst[0] = r;    /* r */
  67.          dst[1] = g0;   /* g */
  68.          dst[2] = b;    /* b */
  69.          dst[3] = 1.0f; /* a */
  70.          dst += 4;
  71.  
  72.          dst[0] = r;    /* r */
  73.          dst[1] = g1;   /* g */
  74.          dst[2] = b;    /* b */
  75.          dst[3] = 1.0f; /* a */
  76.          dst += 4;
  77.       }
  78.  
  79.       if (x < width) {
  80.          value = *src;
  81.  
  82. #ifdef PIPE_ARCH_BIG_ENDIAN
  83.          value = util_bswap32(value);
  84. #endif
  85.  
  86.          r  = ubyte_to_float((value >>  0) & 0xff);
  87.          g0 = ubyte_to_float((value >>  8) & 0xff);
  88.          b  = ubyte_to_float((value >> 16) & 0xff);
  89.          g1 = ubyte_to_float((value >> 24) & 0xff);
  90.  
  91.          dst[0] = r;    /* r */
  92.          dst[1] = g0;   /* g */
  93.          dst[2] = b;    /* b */
  94.          dst[3] = 1.0f; /* a */
  95.       }
  96.  
  97.       src_row += src_stride/sizeof(*src_row);
  98.       dst_row += dst_stride/sizeof(*dst_row);
  99.    }
  100. }
  101.  
  102.  
  103. void
  104. util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  105.                                           const uint8_t *src_row, unsigned src_stride,
  106.                                           unsigned width, unsigned height)
  107. {
  108.    unsigned x, y;
  109.  
  110.    for (y = 0; y < height; y += 1) {
  111.       uint8_t *dst = dst_row;
  112.       const uint32_t *src = (const uint32_t *)src_row;
  113.       uint32_t value;
  114.       uint8_t r, g0, g1, b;
  115.  
  116.       for (x = 0; x + 1 < width; x += 2) {
  117.          value = *src++;
  118.  
  119. #ifdef PIPE_ARCH_BIG_ENDIAN
  120.          value = util_bswap32(value);
  121. #endif
  122.  
  123.          r  = (value >>  0) & 0xff;
  124.          g0 = (value >>  8) & 0xff;
  125.          b  = (value >> 16) & 0xff;
  126.          g1 = (value >> 24) & 0xff;
  127.  
  128.          dst[0] = r;    /* r */
  129.          dst[1] = g0;   /* g */
  130.          dst[2] = b;    /* b */
  131.          dst[3] = 0xff; /* a */
  132.          dst += 4;
  133.  
  134.          dst[0] = r;    /* r */
  135.          dst[1] = g1;   /* g */
  136.          dst[2] = b;    /* b */
  137.          dst[3] = 0xff; /* a */
  138.          dst += 4;
  139.       }
  140.  
  141.       if (x < width) {
  142.          value = *src;
  143.  
  144. #ifdef PIPE_ARCH_BIG_ENDIAN
  145.          value = util_bswap32(value);
  146. #endif
  147.  
  148.          r  = (value >>  0) & 0xff;
  149.          g0 = (value >>  8) & 0xff;
  150.          b  = (value >> 16) & 0xff;
  151.          g1 = (value >> 24) & 0xff;
  152.  
  153.          dst[0] = r;    /* r */
  154.          dst[1] = g0;   /* g */
  155.          dst[2] = b;    /* b */
  156.          dst[3] = 0xff; /* a */
  157.       }
  158.  
  159.       src_row += src_stride/sizeof(*src_row);
  160.       dst_row += dst_stride/sizeof(*dst_row);
  161.    }
  162. }
  163.  
  164.  
  165. void
  166. util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  167.                                        const float *src_row, unsigned src_stride,
  168.                                        unsigned width, unsigned height)
  169. {
  170.    unsigned x, y;
  171.  
  172.    for (y = 0; y < height; y += 1) {
  173.       const float *src = src_row;
  174.       uint32_t *dst = (uint32_t *)dst_row;
  175.       float r, g0, g1, b;
  176.       uint32_t value;
  177.  
  178.       for (x = 0; x + 1 < width; x += 2) {
  179.          r  = 0.5f*(src[0] + src[4]);
  180.          g0 = src[1];
  181.          g1 = src[5];
  182.          b  = 0.5f*(src[2] + src[6]);
  183.  
  184.          value  = float_to_ubyte(r);
  185.          value |= float_to_ubyte(g0) <<  8;
  186.          value |= float_to_ubyte(b)  << 16;
  187.          value |= float_to_ubyte(g1) << 24;
  188.  
  189. #ifdef PIPE_ARCH_BIG_ENDIAN
  190.          value = util_bswap32(value);
  191. #endif
  192.  
  193.          *dst++ = value;
  194.  
  195.          src += 8;
  196.       }
  197.  
  198.       if (x < width) {
  199.          r  = src[0];
  200.          g0 = src[1];
  201.          g1 = 0;
  202.          b  = src[2];
  203.  
  204.          value  = float_to_ubyte(r);
  205.          value |= float_to_ubyte(g0) <<  8;
  206.          value |= float_to_ubyte(b)  << 16;
  207.          value |= float_to_ubyte(g1) << 24;
  208.  
  209. #ifdef PIPE_ARCH_BIG_ENDIAN
  210.          value = util_bswap32(value);
  211. #endif
  212.  
  213.          *dst = value;
  214.       }
  215.  
  216.       dst_row += dst_stride/sizeof(*dst_row);
  217.       src_row += src_stride/sizeof(*src_row);
  218.    }
  219. }
  220.  
  221.  
  222. void
  223. util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  224.                                         const uint8_t *src_row, unsigned src_stride,
  225.                                         unsigned width, unsigned height)
  226. {
  227.    unsigned x, y;
  228.  
  229.    for (y = 0; y < height; y += 1) {
  230.       const uint8_t *src = src_row;
  231.       uint32_t *dst = (uint32_t *)dst_row;
  232.       uint32_t r, g0, g1, b;
  233.       uint32_t value;
  234.  
  235.       for (x = 0; x + 1 < width; x += 2) {
  236.          r  = (src[0] + src[4] + 1) >> 1;
  237.          g0 = src[1];
  238.          g1 = src[5];
  239.          b  = (src[2] + src[6] + 1) >> 1;
  240.  
  241.          value  = r;
  242.          value |= g0 <<  8;
  243.          value |= b  << 16;
  244.          value |= g1 << 24;
  245.  
  246. #ifdef PIPE_ARCH_BIG_ENDIAN
  247.          value = util_bswap32(value);
  248. #endif
  249.  
  250.          *dst++ = value;
  251.  
  252.          src += 8;
  253.       }
  254.  
  255.       if (x < width) {
  256.          r  = src[0];
  257.          g0 = src[1];
  258.          g1 = 0;
  259.          b  = src[2];
  260.  
  261.          value  = r;
  262.          value |= g0 <<  8;
  263.          value |= b  << 16;
  264.          value |= g1 << 24;
  265.  
  266. #ifdef PIPE_ARCH_BIG_ENDIAN
  267.          value = util_bswap32(value);
  268. #endif
  269.  
  270.          *dst = value;
  271.       }
  272.  
  273.       dst_row += dst_stride/sizeof(*dst_row);
  274.       src_row += src_stride/sizeof(*src_row);
  275.    }
  276. }
  277.  
  278.  
  279. void
  280. util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
  281.                                         unsigned i, unsigned j)
  282. {
  283.    assert(i < 2);
  284.    assert(j < 1);
  285.  
  286.    dst[0] = ubyte_to_float(src[0]);             /* r */
  287.    dst[1] = ubyte_to_float(src[1 + 2*i]);       /* g */
  288.    dst[2] = ubyte_to_float(src[2]);             /* b */
  289.    dst[3] = 1.0f;                               /* a */
  290. }
  291.  
  292.  
  293. void
  294. util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  295.                                          const uint8_t *src_row, unsigned src_stride,
  296.                                          unsigned width, unsigned height)
  297. {
  298.    unsigned x, y;
  299.  
  300.    for (y = 0; y < height; y += 1) {
  301.       float *dst = dst_row;
  302.       const uint32_t *src = (const uint32_t *)src_row;
  303.       uint32_t value;
  304.       float r, g0, g1, b;
  305.  
  306.       for (x = 0; x + 1 < width; x += 2) {
  307.          value = *src++;
  308.  
  309. #ifdef PIPE_ARCH_BIG_ENDIAN
  310.          value = util_bswap32(value);
  311. #endif
  312.  
  313.          g0 = ubyte_to_float((value >>  0) & 0xff);
  314.          r  = ubyte_to_float((value >>  8) & 0xff);
  315.          g1 = ubyte_to_float((value >> 16) & 0xff);
  316.          b  = ubyte_to_float((value >> 24) & 0xff);
  317.  
  318.          dst[0] = r;    /* r */
  319.          dst[1] = g0;   /* g */
  320.          dst[2] = b;    /* b */
  321.          dst[3] = 1.0f; /* a */
  322.          dst += 4;
  323.  
  324.          dst[0] = r;    /* r */
  325.          dst[1] = g1;   /* g */
  326.          dst[2] = b;    /* b */
  327.          dst[3] = 1.0f; /* a */
  328.          dst += 4;
  329.       }
  330.  
  331.       if (x < width) {
  332.          value = *src;
  333.  
  334. #ifdef PIPE_ARCH_BIG_ENDIAN
  335.          value = util_bswap32(value);
  336. #endif
  337.  
  338.          g0 = ubyte_to_float((value >>  0) & 0xff);
  339.          r  = ubyte_to_float((value >>  8) & 0xff);
  340.          g1 = ubyte_to_float((value >> 16) & 0xff);
  341.          b  = ubyte_to_float((value >> 24) & 0xff);
  342.  
  343.          dst[0] = r;    /* r */
  344.          dst[1] = g0;   /* g */
  345.          dst[2] = b;    /* b */
  346.          dst[3] = 1.0f; /* a */
  347.       }
  348.  
  349.       src_row += src_stride/sizeof(*src_row);
  350.       dst_row += dst_stride/sizeof(*dst_row);
  351.    }
  352. }
  353.  
  354.  
  355. void
  356. util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *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.  
  362.    for (y = 0; y < height; y += 1) {
  363.       uint8_t *dst = dst_row;
  364.       const uint32_t *src = (const uint32_t *)src_row;
  365.       uint32_t value;
  366.       uint8_t r, g0, g1, b;
  367.  
  368.       for (x = 0; x + 1 < width; x += 2) {
  369.          value = *src++;
  370.  
  371. #ifdef PIPE_ARCH_BIG_ENDIAN
  372.          value = util_bswap32(value);
  373. #endif
  374.  
  375.          g0 = (value >>  0) & 0xff;
  376.          r  = (value >>  8) & 0xff;
  377.          g1 = (value >> 16) & 0xff;
  378.          b  = (value >> 24) & 0xff;
  379.  
  380.          dst[0] = r;    /* r */
  381.          dst[1] = g0;   /* g */
  382.          dst[2] = b;    /* b */
  383.          dst[3] = 0xff; /* a */
  384.          dst += 4;
  385.  
  386.          dst[0] = r;    /* r */
  387.          dst[1] = g1;   /* g */
  388.          dst[2] = b;    /* b */
  389.          dst[3] = 0xff; /* a */
  390.          dst += 4;
  391.       }
  392.  
  393.       if (x < width) {
  394.          value = *src;
  395.  
  396. #ifdef PIPE_ARCH_BIG_ENDIAN
  397.          value = util_bswap32(value);
  398. #endif
  399.  
  400.          g0 = (value >>  0) & 0xff;
  401.          r  = (value >>  8) & 0xff;
  402.          g1 = (value >> 16) & 0xff;
  403.          b  = (value >> 24) & 0xff;
  404.  
  405.          dst[0] = r;    /* r */
  406.          dst[1] = g0;   /* g */
  407.          dst[2] = b;    /* b */
  408.          dst[3] = 0xff; /* a */
  409.       }
  410.  
  411.       src_row += src_stride/sizeof(*src_row);
  412.       dst_row += dst_stride/sizeof(*dst_row);
  413.    }
  414. }
  415.  
  416.  
  417. void
  418. util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  419.                                        const float *src_row, unsigned src_stride,
  420.                                        unsigned width, unsigned height)
  421. {
  422.    unsigned x, y;
  423.  
  424.    for (y = 0; y < height; y += 1) {
  425.       const float *src = src_row;
  426.       uint32_t *dst = (uint32_t *)dst_row;
  427.       float r, g0, g1, b;
  428.       uint32_t value;
  429.  
  430.       for (x = 0; x + 1 < width; x += 2) {
  431.          r  = 0.5f*(src[0] + src[4]);
  432.          g0 = src[1];
  433.          g1 = src[5];
  434.          b  = 0.5f*(src[2] + src[6]);
  435.  
  436.          value  = float_to_ubyte(g0);
  437.          value |= float_to_ubyte(r)  <<  8;
  438.          value |= float_to_ubyte(g1) << 16;
  439.          value |= float_to_ubyte(b)  << 24;
  440.  
  441. #ifdef PIPE_ARCH_BIG_ENDIAN
  442.          value = util_bswap32(value);
  443. #endif
  444.  
  445.          *dst++ = value;
  446.  
  447.          src += 8;
  448.       }
  449.  
  450.       if (x < width) {
  451.          r  = src[0];
  452.          g0 = src[1];
  453.          g1 = 0;
  454.          b  = src[2];
  455.  
  456.          value  = float_to_ubyte(g0);
  457.          value |= float_to_ubyte(r)  <<  8;
  458.          value |= float_to_ubyte(g1) << 16;
  459.          value |= float_to_ubyte(b)  << 24;
  460.  
  461. #ifdef PIPE_ARCH_BIG_ENDIAN
  462.          value = util_bswap32(value);
  463. #endif
  464.  
  465.          *dst = value;
  466.       }
  467.  
  468.       dst_row += dst_stride/sizeof(*dst_row);
  469.       src_row += src_stride/sizeof(*src_row);
  470.    }
  471. }
  472.  
  473.  
  474. void
  475. util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  476.                                         const uint8_t *src_row, unsigned src_stride,
  477.                                         unsigned width, unsigned height)
  478. {
  479.    unsigned x, y;
  480.  
  481.    for (y = 0; y < height; y += 1) {
  482.       const uint8_t *src = src_row;
  483.       uint32_t *dst = (uint32_t *)dst_row;
  484.       uint32_t r, g0, g1, b;
  485.       uint32_t value;
  486.  
  487.       for (x = 0; x + 1 < width; x += 2) {
  488.          r  = (src[0] + src[4] + 1) >> 1;
  489.          g0 = src[1];
  490.          g1 = src[5];
  491.          b  = (src[2] + src[6] + 1) >> 1;
  492.  
  493.          value  = g0;
  494.          value |= r  <<  8;
  495.          value |= g1 << 16;
  496.          value |= b  << 24;
  497.  
  498. #ifdef PIPE_ARCH_BIG_ENDIAN
  499.          value = util_bswap32(value);
  500. #endif
  501.  
  502.          *dst++ = value;
  503.  
  504.          src += 8;
  505.       }
  506.  
  507.       if (x < width) {
  508.          r  = src[0];
  509.          g0 = src[1];
  510.          g1 = 0;
  511.          b  = src[2];
  512.  
  513.          value  = g0;
  514.          value |= r  <<  8;
  515.          value |= g1 << 16;
  516.          value |= b  << 24;
  517.  
  518. #ifdef PIPE_ARCH_BIG_ENDIAN
  519.          value = util_bswap32(value);
  520. #endif
  521.  
  522.          *dst = value;
  523.       }
  524.  
  525.       dst_row += dst_stride/sizeof(*dst_row);
  526.       src_row += src_stride/sizeof(*src_row);
  527.    }
  528. }
  529.  
  530.  
  531. void
  532. util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
  533.                                         unsigned i, unsigned j)
  534. {
  535.    assert(i < 2);
  536.    assert(j < 1);
  537.  
  538.    dst[0] = ubyte_to_float(src[1]);             /* r */
  539.    dst[1] = ubyte_to_float(src[0 + 2*i]);       /* g */
  540.    dst[2] = ubyte_to_float(src[3]);             /* b */
  541.    dst[3] = 1.0f;                               /* a */
  542. }
  543.  
  544.  
  545. void
  546. util_format_uyvy_unpack_rgba_float(float *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.  
  552.    for (y = 0; y < height; y += 1) {
  553.       float *dst = dst_row;
  554.       const uint32_t *src = (const uint32_t *)src_row;
  555.       uint32_t value;
  556.       uint8_t y0, y1, u, v;
  557.  
  558.       for (x = 0; x + 1 < width; x += 2) {
  559.          value = *src++;
  560.  
  561. #ifdef PIPE_ARCH_BIG_ENDIAN
  562.          value = util_bswap32(value);
  563. #endif
  564.  
  565.          u  = (value >>  0) & 0xff;
  566.          y0 = (value >>  8) & 0xff;
  567.          v  = (value >> 16) & 0xff;
  568.          y1 = (value >> 24) & 0xff;
  569.  
  570.          util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
  571.          dst[3] = 1.0f; /* a */
  572.          dst += 4;
  573.  
  574.          util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]);
  575.          dst[3] = 1.0f; /* a */
  576.          dst += 4;
  577.       }
  578.  
  579.       if (x < width) {
  580.          value = *src;
  581.  
  582. #ifdef PIPE_ARCH_BIG_ENDIAN
  583.          value = util_bswap32(value);
  584. #endif
  585.  
  586.          u  = (value >>  0) & 0xff;
  587.          y0 = (value >>  8) & 0xff;
  588.          v  = (value >> 16) & 0xff;
  589.          y1 = (value >> 24) & 0xff;
  590.  
  591.          util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
  592.          dst[3] = 1.0f; /* a */
  593.       }
  594.  
  595.       src_row += src_stride/sizeof(*src_row);
  596.       dst_row += dst_stride/sizeof(*dst_row);
  597.    }
  598. }
  599.  
  600.  
  601. void
  602. util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  603.                                const uint8_t *src_row, unsigned src_stride,
  604.                                unsigned width, unsigned height)
  605. {
  606.    unsigned x, y;
  607.  
  608.    for (y = 0; y < height; y += 1) {
  609.       uint8_t *dst = dst_row;
  610.       const uint32_t *src = (const uint32_t *)src_row;
  611.       uint32_t value;
  612.       uint8_t y0, y1, u, v;
  613.  
  614.       for (x = 0; x + 1 < width; x += 2) {
  615.          value = *src++;
  616.  
  617. #ifdef PIPE_ARCH_BIG_ENDIAN
  618.          value = util_bswap32(value);
  619. #endif
  620.  
  621.          u  = (value >>  0) & 0xff;
  622.          y0 = (value >>  8) & 0xff;
  623.          v  = (value >> 16) & 0xff;
  624.          y1 = (value >> 24) & 0xff;
  625.  
  626.          util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
  627.          dst[3] = 0xff; /* a */
  628.          dst += 4;
  629.  
  630.          util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]);
  631.          dst[3] = 0xff; /* a */
  632.          dst += 4;
  633.       }
  634.  
  635.       if (x < width) {
  636.          value = *src;
  637.  
  638. #ifdef PIPE_ARCH_BIG_ENDIAN
  639.          value = util_bswap32(value);
  640. #endif
  641.  
  642.          u  = (value >>  0) & 0xff;
  643.          y0 = (value >>  8) & 0xff;
  644.          v  = (value >> 16) & 0xff;
  645.          y1 = (value >> 24) & 0xff;
  646.  
  647.          util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
  648.          dst[3] = 0xff; /* a */
  649.       }
  650.  
  651.       src_row += src_stride/sizeof(*src_row);
  652.       dst_row += dst_stride/sizeof(*dst_row);
  653.    }
  654. }
  655.  
  656.  
  657. void
  658. util_format_uyvy_pack_rgba_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.  
  664.    for (y = 0; y < height; y += 1) {
  665.       const float *src = src_row;
  666.       uint32_t *dst = (uint32_t *)dst_row;
  667.       uint8_t y0, y1, u, v;
  668.       uint32_t value;
  669.  
  670.       for (x = 0; x + 1 < width; x += 2) {
  671.          uint8_t y0, y1, u0, u1, v0, v1, u, v;
  672.  
  673.          util_format_rgb_float_to_yuv(src[0], src[1], src[2],
  674.                                       &y0, &u0, &v0);
  675.          util_format_rgb_float_to_yuv(src[4], src[5], src[6],
  676.                                       &y1, &u1, &v1);
  677.  
  678.          u = (u0 + u1 + 1) >> 1;
  679.          v = (v0 + v1 + 1) >> 1;
  680.  
  681.          value  = u;
  682.          value |= y0 <<  8;
  683.          value |= v  << 16;
  684.          value |= y1 << 24;
  685.  
  686. #ifdef PIPE_ARCH_BIG_ENDIAN
  687.          value = util_bswap32(value);
  688. #endif
  689.  
  690.          *dst++ = value;
  691.  
  692.          src += 8;
  693.       }
  694.  
  695.       if (x < width) {
  696.          util_format_rgb_float_to_yuv(src[0], src[1], src[2],
  697.                                       &y0, &u, &v);
  698.          y1 = 0;
  699.  
  700.          value  = u;
  701.          value |= y0 <<  8;
  702.          value |= v  << 16;
  703.          value |= y1 << 24;
  704.  
  705. #ifdef PIPE_ARCH_BIG_ENDIAN
  706.          value = util_bswap32(value);
  707. #endif
  708.  
  709.          *dst = value;
  710.       }
  711.  
  712.       dst_row += dst_stride/sizeof(*dst_row);
  713.       src_row += src_stride/sizeof(*src_row);
  714.    }
  715. }
  716.  
  717.  
  718. void
  719. util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  720.                              const uint8_t *src_row, unsigned src_stride,
  721.                              unsigned width, unsigned height)
  722. {
  723.    unsigned x, y;
  724.  
  725.    for (y = 0; y < height; y += 1) {
  726.       const uint8_t *src = src_row;
  727.       uint32_t *dst = (uint32_t *)dst_row;
  728.       uint8_t y0, y1, u, v;
  729.       uint32_t value;
  730.  
  731.       for (x = 0; x + 1 < width; x += 2) {
  732.          uint8_t y0, y1, u0, u1, v0, v1, u, v;
  733.  
  734.          util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
  735.                                        &y0, &u0, &v0);
  736.          util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6],
  737.                                        &y1, &u1, &v1);
  738.  
  739.          u = (u0 + u1 + 1) >> 1;
  740.          v = (v0 + v1 + 1) >> 1;
  741.  
  742.          value  = u;
  743.          value |= y0 <<  8;
  744.          value |= v  << 16;
  745.          value |= y1 << 24;
  746.  
  747. #ifdef PIPE_ARCH_BIG_ENDIAN
  748.          value = util_bswap32(value);
  749. #endif
  750.  
  751.          *dst++ = value;
  752.  
  753.          src += 8;
  754.       }
  755.  
  756.       if (x < width) {
  757.          util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
  758.                                        &y0, &u, &v);
  759.          y1 = 0;
  760.  
  761.          value  = u;
  762.          value |= y0 <<  8;
  763.          value |= v  << 16;
  764.          value |= y1 << 24;
  765.  
  766. #ifdef PIPE_ARCH_BIG_ENDIAN
  767.          value = util_bswap32(value);
  768. #endif
  769.  
  770.          *dst = value;
  771.       }
  772.  
  773.       dst_row += dst_stride/sizeof(*dst_row);
  774.       src_row += src_stride/sizeof(*src_row);
  775.    }
  776. }
  777.  
  778.  
  779. void
  780. util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src,
  781.                              unsigned i, unsigned j)
  782. {
  783.    uint8_t y, u, v;
  784.  
  785.    assert(i < 2);
  786.    assert(j < 1);
  787.  
  788.    y = src[1 + i*2];
  789.    u = src[0];
  790.    v = src[2];
  791.  
  792.    util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]);
  793.  
  794.    dst[3] = 1.0f;
  795. }
  796.  
  797.  
  798. void
  799. util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  800.                               const uint8_t *src_row, unsigned src_stride,
  801.                               unsigned width, unsigned height)
  802. {
  803.    unsigned x, y;
  804.  
  805.    for (y = 0; y < height; y += 1) {
  806.       float *dst = dst_row;
  807.       const uint32_t *src = (const uint32_t *)src_row;
  808.       uint32_t value;
  809.       uint8_t y0, y1, u, v;
  810.  
  811.       for (x = 0; x + 1 < width; x += 2) {
  812.          value = *src++;
  813.  
  814. #ifdef PIPE_ARCH_BIG_ENDIAN
  815.          value = util_bswap32(value);
  816. #endif
  817.  
  818.          y0 = (value >>  0) & 0xff;
  819.          u  = (value >>  8) & 0xff;
  820.          y1 = (value >> 16) & 0xff;
  821.          v  = (value >> 24) & 0xff;
  822.  
  823.          util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
  824.          dst[3] = 1.0f; /* a */
  825.          dst += 4;
  826.  
  827.          util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]);
  828.          dst[3] = 1.0f; /* a */
  829.          dst += 4;
  830.       }
  831.  
  832.       if (x < width) {
  833.          value = *src;
  834.  
  835. #ifdef PIPE_ARCH_BIG_ENDIAN
  836.          value = util_bswap32(value);
  837. #endif
  838.  
  839.          y0 = (value >>  0) & 0xff;
  840.          u  = (value >>  8) & 0xff;
  841.          y1 = (value >> 16) & 0xff;
  842.          v  = (value >> 24) & 0xff;
  843.  
  844.          util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
  845.          dst[3] = 1.0f; /* a */
  846.       }
  847.  
  848.       src_row += src_stride/sizeof(*src_row);
  849.       dst_row += dst_stride/sizeof(*dst_row);
  850.    }
  851. }
  852.  
  853.  
  854. void
  855. util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  856.                                const uint8_t *src_row, unsigned src_stride,
  857.                                unsigned width, unsigned height)
  858. {
  859.    unsigned x, y;
  860.  
  861.    for (y = 0; y < height; y += 1) {
  862.       uint8_t *dst = dst_row;
  863.       const uint32_t *src = (const uint32_t *)src_row;
  864.       uint32_t value;
  865.       uint8_t y0, y1, u, v;
  866.  
  867.       for (x = 0; x + 1 < width; x += 2) {
  868.          value = *src++;
  869.  
  870. #ifdef PIPE_ARCH_BIG_ENDIAN
  871.          value = util_bswap32(value);
  872. #endif
  873.  
  874.          y0 = (value >>  0) & 0xff;
  875.          u  = (value >>  8) & 0xff;
  876.          y1 = (value >> 16) & 0xff;
  877.          v  = (value >> 24) & 0xff;
  878.  
  879.          util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
  880.          dst[3] = 0xff; /* a */
  881.          dst += 4;
  882.  
  883.          util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]);
  884.          dst[3] = 0xff; /* a */
  885.          dst += 4;
  886.       }
  887.  
  888.       if (x < width) {
  889.          value = *src;
  890.  
  891. #ifdef PIPE_ARCH_BIG_ENDIAN
  892.          value = util_bswap32(value);
  893. #endif
  894.  
  895.          y0 = (value >>  0) & 0xff;
  896.          u  = (value >>  8) & 0xff;
  897.          y1 = (value >> 16) & 0xff;
  898.          v  = (value >> 24) & 0xff;
  899.  
  900.          util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
  901.          dst[3] = 0xff; /* a */
  902.       }
  903.  
  904.       src_row += src_stride/sizeof(*src_row);
  905.       dst_row += dst_stride/sizeof(*dst_row);
  906.    }
  907. }
  908.  
  909.  
  910. void
  911. util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  912.                             const float *src_row, unsigned src_stride,
  913.                             unsigned width, unsigned height)
  914. {
  915.    unsigned x, y;
  916.  
  917.    for (y = 0; y < height; y += 1) {
  918.       const float *src = src_row;
  919.       uint32_t *dst = (uint32_t *)dst_row;
  920.       uint8_t y0, y1, u, v;
  921.       uint32_t value;
  922.  
  923.       for (x = 0; x + 1 < width; x += 2) {
  924.          uint8_t y0, y1, u0, u1, v0, v1, u, v;
  925.  
  926.          util_format_rgb_float_to_yuv(src[0], src[1], src[2],
  927.                                       &y0, &u0, &v0);
  928.          util_format_rgb_float_to_yuv(src[4], src[5], src[6],
  929.                                       &y1, &u1, &v1);
  930.  
  931.          u = (u0 + u1 + 1) >> 1;
  932.          v = (v0 + v1 + 1) >> 1;
  933.  
  934.          value  = y0;
  935.          value |= u  <<  8;
  936.          value |= y1 << 16;
  937.          value |= v  << 24;
  938.  
  939. #ifdef PIPE_ARCH_BIG_ENDIAN
  940.          value = util_bswap32(value);
  941. #endif
  942.  
  943.          *dst++ = value;
  944.  
  945.          src += 8;
  946.       }
  947.  
  948.       if (x < width) {
  949.          util_format_rgb_float_to_yuv(src[0], src[1], src[2],
  950.                                       &y0, &u, &v);
  951.          y1 = 0;
  952.  
  953.          value  = y0;
  954.          value |= u  <<  8;
  955.          value |= y1 << 16;
  956.          value |= v  << 24;
  957.  
  958. #ifdef PIPE_ARCH_BIG_ENDIAN
  959.          value = util_bswap32(value);
  960. #endif
  961.  
  962.          *dst = value;
  963.       }
  964.  
  965.       dst_row += dst_stride/sizeof(*dst_row);
  966.       src_row += src_stride/sizeof(*src_row);
  967.    }
  968. }
  969.  
  970.  
  971. void
  972. util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  973.                              const uint8_t *src_row, unsigned src_stride,
  974.                              unsigned width, unsigned height)
  975. {
  976.    unsigned x, y;
  977.  
  978.    for (y = 0; y < height; y += 1) {
  979.       const uint8_t *src = src_row;
  980.       uint32_t *dst = (uint32_t *)dst_row;
  981.       uint8_t y0, y1, u, v;
  982.       uint32_t value;
  983.  
  984.       for (x = 0; x + 1 < width; x += 2) {
  985.          uint8_t y0, y1, u0, u1, v0, v1, u, v;
  986.  
  987.          util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
  988.                                        &y0, &u0, &v0);
  989.          util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6],
  990.                                        &y1, &u1, &v1);
  991.  
  992.          u = (u0 + u1 + 1) >> 1;
  993.          v = (v0 + v1 + 1) >> 1;
  994.  
  995.          value  = y0;
  996.          value |= u  <<  8;
  997.          value |= y1 << 16;
  998.          value |= v  << 24;
  999.  
  1000. #ifdef PIPE_ARCH_BIG_ENDIAN
  1001.          value = util_bswap32(value);
  1002. #endif
  1003.  
  1004.          *dst++ = value;
  1005.  
  1006.          src += 8;
  1007.       }
  1008.  
  1009.       if (x < width) {
  1010.          util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
  1011.                                        &y0, &u, &v);
  1012.          y1 = 0;
  1013.  
  1014.          value  = y0;
  1015.          value |= u  <<  8;
  1016.          value |= y1 << 16;
  1017.          value |= v  << 24;
  1018.  
  1019. #ifdef PIPE_ARCH_BIG_ENDIAN
  1020.          value = util_bswap32(value);
  1021. #endif
  1022.  
  1023.          *dst = value;
  1024.       }
  1025.  
  1026.       dst_row += dst_stride/sizeof(*dst_row);
  1027.       src_row += src_stride/sizeof(*src_row);
  1028.    }
  1029. }
  1030.  
  1031.  
  1032. void
  1033. util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src,
  1034.                              unsigned i, unsigned j)
  1035. {
  1036.    uint8_t y, u, v;
  1037.  
  1038.    assert(i < 2);
  1039.    assert(j < 1);
  1040.  
  1041.    y = src[0 + i*2];
  1042.    u = src[1];
  1043.    v = src[3];
  1044.  
  1045.    util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]);
  1046.  
  1047.    dst[3] = 1.0f;
  1048. }
  1049.  
  1050. /* XXX: Stubbed for now */
  1051. void
  1052. util_format_yv12_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1053.                              const uint8_t *src_row, unsigned src_stride,
  1054.                              unsigned width, unsigned height) {}
  1055. void
  1056. util_format_yv12_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1057.                              const uint8_t *src_row, unsigned src_stride,
  1058.                              unsigned width, unsigned height) {}
  1059. void
  1060. util_format_yv12_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1061.                              const uint8_t *src_row, unsigned src_stride,
  1062.                              unsigned width, unsigned height) {}
  1063. void
  1064. util_format_yv12_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1065.                              const float *src_row, unsigned src_stride,
  1066.                              unsigned width, unsigned height) {}
  1067. void
  1068. util_format_yv12_fetch_rgba_float(float *dst, const uint8_t *src,
  1069.                              unsigned i, unsigned j) {}
  1070. void
  1071. util_format_yv16_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1072.                              const uint8_t *src_row, unsigned src_stride,
  1073.                              unsigned width, unsigned height) {}
  1074. void
  1075. util_format_yv16_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1076.                              const uint8_t *src_row, unsigned src_stride,
  1077.                              unsigned width, unsigned height) {}
  1078. void
  1079. util_format_yv16_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1080.                              const uint8_t *src_row, unsigned src_stride,
  1081.                              unsigned width, unsigned height) {}
  1082. void
  1083. util_format_yv16_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1084.                              const float *src_row, unsigned src_stride,
  1085.                              unsigned width, unsigned height) {}
  1086. void
  1087. util_format_yv16_fetch_rgba_float(float *dst, const uint8_t *src,
  1088.                              unsigned i, unsigned j) {}
  1089. void
  1090. util_format_iyuv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1091.                              const uint8_t *src_row, unsigned src_stride,
  1092.                              unsigned width, unsigned height) {}
  1093. void
  1094. util_format_iyuv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1095.                              const uint8_t *src_row, unsigned src_stride,
  1096.                              unsigned width, unsigned height) {}
  1097. void
  1098. util_format_iyuv_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1099.                              const uint8_t *src_row, unsigned src_stride,
  1100.                              unsigned width, unsigned height) {}
  1101. void
  1102. util_format_iyuv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1103.                              const float *src_row, unsigned src_stride,
  1104.                              unsigned width, unsigned height) {}
  1105. void
  1106. util_format_iyuv_fetch_rgba_float(float *dst, const uint8_t *src,
  1107.                              unsigned i, unsigned j) {}
  1108. void
  1109. util_format_nv12_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1110.                              const uint8_t *src_row, unsigned src_stride,
  1111.                              unsigned width, unsigned height) {}
  1112. void
  1113. util_format_nv12_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1114.                              const uint8_t *src_row, unsigned src_stride,
  1115.                              unsigned width, unsigned height) {}
  1116. void
  1117. util_format_nv12_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1118.                              const uint8_t *src_row, unsigned src_stride,
  1119.                              unsigned width, unsigned height) {}
  1120. void
  1121. util_format_nv12_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1122.                              const float *src_row, unsigned src_stride,
  1123.                              unsigned width, unsigned height) {}
  1124. void
  1125. util_format_nv12_fetch_rgba_float(float *dst, const uint8_t *src,
  1126.                              unsigned i, unsigned j) {}
  1127. void
  1128. util_format_nv21_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1129.                              const uint8_t *src_row, unsigned src_stride,
  1130.                              unsigned width, unsigned height) {}
  1131. void
  1132. util_format_nv21_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1133.                              const uint8_t *src_row, unsigned src_stride,
  1134.                              unsigned width, unsigned height) {}
  1135. void
  1136. util_format_nv21_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1137.                              const uint8_t *src_row, unsigned src_stride,
  1138.                              unsigned width, unsigned height) {}
  1139. void
  1140. util_format_nv21_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1141.                              const float *src_row, unsigned src_stride,
  1142.                              unsigned width, unsigned height) {}
  1143. void
  1144. util_format_nv21_fetch_rgba_float(float *dst, const uint8_t *src,
  1145.                              unsigned i, unsigned j) {}
  1146.  
  1147. void
  1148. util_format_r8g8_r8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1149.                                          const uint8_t *src_row, unsigned src_stride,
  1150.                                          unsigned width, unsigned height) {}
  1151.  
  1152. void
  1153. util_format_r8g8_r8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1154.                                           const uint8_t *src_row, unsigned src_stride,
  1155.                                           unsigned width, unsigned height) {}
  1156.  
  1157. void
  1158. util_format_r8g8_r8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1159.                                        const float *src_row, unsigned src_stride,
  1160.                                        unsigned width, unsigned height) {}
  1161.  
  1162. void
  1163. util_format_r8g8_r8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1164.                                         const uint8_t *src_row, unsigned src_stride,
  1165.                                         unsigned width, unsigned height) {}
  1166.  
  1167. void
  1168. util_format_r8g8_r8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
  1169.                                         unsigned i, unsigned j) {}
  1170.  
  1171. void
  1172. util_format_g8r8_b8r8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
  1173.                                          const uint8_t *src_row, unsigned src_stride,
  1174.                                          unsigned width, unsigned height) {}
  1175.  
  1176. void
  1177. util_format_g8r8_b8r8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1178.                                           const uint8_t *src_row, unsigned src_stride,
  1179.                                           unsigned width, unsigned height) {}
  1180.  
  1181. void
  1182. util_format_g8r8_b8r8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
  1183.                                        const float *src_row, unsigned src_stride,
  1184.                                        unsigned width, unsigned height) {}
  1185.  
  1186. void
  1187. util_format_g8r8_b8r8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
  1188.                                         const uint8_t *src_row, unsigned src_stride,
  1189.                                         unsigned width, unsigned height) {}
  1190.  
  1191. void
  1192. util_format_g8r8_b8r8_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
  1193.                                         unsigned i, unsigned j) {}
  1194.