/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */

/**************************************************************************
 *
 * Copyright 2010 VMware, Inc.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

#include "util/format/u_format.h"
#include "u_format_bptc.h"
#include "u_format_fxt1.h"
#include "u_format_s3tc.h"
#include "u_format_rgtc.h"
#include "u_format_latc.h"
#include "u_format_etc.h"


#include "pipe/p_compiler.h"
#include "util/u_math.h"
#include "util/half_float.h"
#include "u_format.h"
#include "u_format_other.h"
#include "util/format_srgb.h"
#include "format_utils.h"
#include "u_format_yuv.h"
#include "u_format_zs.h"
#include "u_format_pack.h"

void
util_format_none_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_none_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)CLAMP(src[0], 0.0f, 255.0f);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_none_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_none_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_none_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[2])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[2])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_b8g8r8a8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[2]) << 24;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)((src[0]) & 0xff) << 8;
         value |= (src[3]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[2]) & 0xff;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (uint32_t)((src[0]) & 0xff) << 16;
         value |= (uint32_t)(src[3]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[2])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[2])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8x8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[2]) << 24;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)((src[0]) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[2]) & 0xff;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (uint32_t)((src[0]) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8x8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[2], 8, 8)) << 24) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[2], 255)) << 24;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)MIN2(src[0], 255)) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)MIN2(src[2], 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)MIN2(src[0], 255)) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8x8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[2], 0, 255)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0, 255)) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[2], 0, 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0, 255)) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[2], -128, 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8x8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[2], 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (float_to_ubyte(src[2])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[3])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[2])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_a8r8g8b8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[3]) << 24;
         value |= (uint32_t)((src[0]) & 0xff) << 16;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (src[2]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[3]) & 0xff;
         value |= (uint32_t)((src[0]) & 0xff) << 8;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)(src[2]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
}

void
util_format_a8r8g8b8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) << 24) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[3], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[2], 8, 8)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128, 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128, 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[2], -128, 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_a8r8g8b8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[3], 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)MIN2(src[3], 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[2], 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (float_to_ubyte(src[2])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((float_to_ubyte(src[0])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[2])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8r8g8b8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((src[0]) & 0xff) << 16;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (src[2]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((src[0]) & 0xff) << 8;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)(src[2]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8r8g8b8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[2], 8, 8)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[2], -128, 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8r8g8b8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[2], 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (float_to_ubyte(src[0])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[3])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_a8b8g8r8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[3]) << 24;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (src[0]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[3]) & 0xff;
         value |= (uint32_t)((src[2]) & 0xff) << 8;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)(src[0]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (float_to_ubyte(src[0])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8b8g8r8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (src[0]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((src[2]) & 0xff) << 8;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)(src[0]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[0])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8x8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[0]) << 24;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)((src[2]) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[0]) & 0xff;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g5b5a1_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g5b5a1_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) << 15;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g5b5a1_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
}

void
util_format_r5g5b5a1_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g5b5a1_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 1)) << 15;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 10;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g5b5x1_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g5b5x1_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g5b5x1_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r5g5b5x1_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g5b5x1_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 10;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g5r5x1_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g5r5x1_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g5r5x1_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b5g5r5x1_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g5r5x1_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 10;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g5r5a1_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g5r5a1_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) << 15;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 10;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g5r5a1_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
}

void
util_format_b5g5r5a1_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g5r5a1_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 1)) << 15;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 5;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 10;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x1b5g5r5_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_x1b5g5r5_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) << 11;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x1b5g5r5_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x1b5g5r5_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_x1b5g5r5_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 5)) << 11;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 1;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 5)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1r5g5b5_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a1r5g5b5_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) << 11;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) & 0x1;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1r5g5b5_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
}

void
util_format_a1r5g5b5_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a1r5g5b5_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 5)) << 11;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 1;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 1)) & 0x1;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 1;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 5)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x1r5g5b5_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_x1r5g5b5_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) << 11;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x1r5g5b5_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x1r5g5b5_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_x1r5g5b5_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 5)) << 11;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f) << 1;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 5)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1b5g5r5_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a1b5g5r5_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) << 11;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x1)) & 0x1;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x1f)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1b5g5r5_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x1f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
}

void
util_format_a1b5g5r5_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 1, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a1b5g5r5_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 5)) << 11;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 1;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 1)) & 0x1;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f) << 1;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 5)) & 0x1f) << 6;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 5)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4g4b4a4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r4g4b4a4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 12;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4g4b4a4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_r4g4b4a4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r4g4b4a4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 12;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4g4b4x4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r4g4b4x4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4g4b4x4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r4g4b4x4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r4g4b4x4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b4g4r4a4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b4g4r4a4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 12;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b4g4r4a4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_b4g4r4a4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b4g4r4a4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 12;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b4g4r4x4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b4g4r4x4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b4g4r4x4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b4g4r4x4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b4g4r4x4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 4;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4r4g4b4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a4r4g4b4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) << 12;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4r4g4b4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_a4r4g4b4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = value >> 12;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a4r4g4b4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 4)) << 12;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf) << 4;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 4)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 4)) & 0xf;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf) << 4;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 4)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4b4g4r4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a4b4g4r4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) << 12;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xf)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xf)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4b4g4r4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = value >> 12;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_a4b4g4r4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = value >> 12;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a4b4g4r4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 4)) << 12;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf) << 4;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 4)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 4)) & 0xf;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 4)) & 0xf) << 4;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 4)) & 0xf) << 8;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 4)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g6b5_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g6b5_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) << 11;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3f)) & 0x3f) << 5;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3f)) & 0x3f) << 5;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g6b5_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r5g6b5_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 6, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 6, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g6b5_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 5)) << 11;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 6)) & 0x3f) << 5;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 5)) & 0x1f;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 6)) & 0x3f) << 5;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 5)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g6r5_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g6r5_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) << 11;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3f)) & 0x3f) << 5;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x1f)) & 0x1f;
         value |= (uint32_t)(((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3f)) & 0x3f) << 5;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x1f)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g6r5_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = (float)(r * (1.0f/0x1f)); /* r */
         dst[1] = (float)(g * (1.0f/0x3f)); /* g */
         dst[2] = (float)(b * (1.0f/0x1f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b5g6r5_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 6, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = _mesa_unorm_to_unorm(r, 5, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 6, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 5, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g6r5_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 5)) << 11;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 6)) & 0x3f) << 5;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 5)) & 0x1f;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 6)) & 0x3f) << 5;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 5)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) << 30;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= ((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
}

void
util_format_r10g10b10a2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 2)) << 30;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff) << 20;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff) << 20;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 2)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10x2_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10x2_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= ((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10x2_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r10g10b10x2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10x2_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff) << 20;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff) << 20;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) << 30;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= ((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
}

void
util_format_b10g10r10a2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 2)) << 30;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff) << 20;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff) << 20;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 2)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2r10g10b10_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = value >> 22;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a2r10g10b10_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) << 22;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 12;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 2;
         value |= ((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) & 0x3;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 2;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 12;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2r10g10b10_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = value >> 22;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
}

void
util_format_a2r10g10b10_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = value >> 22;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a2r10g10b10_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 10)) << 22;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 12;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff) << 2;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 2)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 2)) & 0x3;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff) << 2;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 12;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 10)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2b10g10r10_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = value >> 22;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a2b10g10r10_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) << 22;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 12;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 2;
         value |= ((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) & 0x3;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 2;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 12;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2b10g10r10_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = value >> 22;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
}

void
util_format_a2b10g10r10_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = value >> 22;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a2b10g10r10_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 10)) << 22;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 12;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff) << 2;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 2)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 2)) & 0x3;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff) << 2;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 12;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 10)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r3g3b2_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = value >> 6;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t r = (value) & 0x7;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0x7;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t b = value >> 6;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_r3g3b2_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3)) << 6;
         value |= (uint32_t)(((uint8_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x7)) & 0x7) << 3;
         value |= ((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x7)) & 0x7;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x7)) & 0x7;
         value |= (uint32_t)(((uint8_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x7)) & 0x7) << 3;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3)) << 6;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r3g3b2_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = value >> 6;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t r = (value) & 0x7;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0x7;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t b = value >> 6;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r3g3b2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = value >> 6;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t r = (value) & 0x7;
         dst[0] = _mesa_unorm_to_unorm(r, 3, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 3, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 2, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0x7;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t b = value >> 6;
         dst[0] = _mesa_unorm_to_unorm(r, 3, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 3, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 2, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_r3g3b2_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 2)) << 6;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 3)) & 0x7) << 3;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 3)) & 0x7;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 3)) & 0x7;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 3)) & 0x7) << 3;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 2)) << 6;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b2g3r3_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 5;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t b = (value) & 0x3;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = (value) & 0x3;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t r = value >> 5;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_b2g3r3_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x7)) << 5;
         value |= (uint32_t)(((uint8_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x7)) & 0x7) << 2;
         value |= ((uint8_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3)) & 0x3;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3)) & 0x3;
         value |= (uint32_t)(((uint8_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x7)) & 0x7) << 2;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x7)) << 5;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b2g3r3_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 5;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t b = (value) & 0x3;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = (value) & 0x3;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t r = value >> 5;
         dst[0] = (float)(r * (1.0f/0x7)); /* r */
         dst[1] = (float)(g * (1.0f/0x7)); /* g */
         dst[2] = (float)(b * (1.0f/0x3)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b2g3r3_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 5;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t b = (value) & 0x3;
         dst[0] = _mesa_unorm_to_unorm(r, 3, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 3, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 2, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = (value) & 0x3;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t r = value >> 5;
         dst[0] = _mesa_unorm_to_unorm(r, 3, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 3, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 2, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_b2g3r3_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 3)) << 5;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 3)) & 0x7) << 2;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 2)) & 0x3;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 2)) & 0x3;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 3)) & 0x7) << 2;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 3)) << 5;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = ubyte_to_float(rgb); /* r */
         dst[1] = ubyte_to_float(rgb); /* g */
         dst[2] = ubyte_to_float(rgb); /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= float_to_ubyte(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = ubyte_to_float(rgb); /* r */
         dst[1] = ubyte_to_float(rgb); /* g */
         dst[2] = ubyte_to_float(rgb); /* b */
         dst[3] = 1; /* a */
}

void
util_format_l8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= src[0];
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_a8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= float_to_ubyte(src[3]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
}

void
util_format_a8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_a8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= src[3];
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgba = value;
         dst[0] = ubyte_to_float(rgba); /* r */
         dst[1] = ubyte_to_float(rgba); /* g */
         dst[2] = ubyte_to_float(rgba); /* b */
         dst[3] = ubyte_to_float(rgba); /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_i8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= float_to_ubyte(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgba = value;
         dst[0] = ubyte_to_float(rgba); /* r */
         dst[1] = ubyte_to_float(rgba); /* g */
         dst[2] = ubyte_to_float(rgba); /* b */
         dst[3] = ubyte_to_float(rgba); /* a */
}

void
util_format_i8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgba = value;
         dst[0] = rgba; /* r */
         dst[1] = rgba; /* g */
         dst[2] = rgba; /* b */
         dst[3] = rgba; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_i8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= src[0];
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l4a4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value >> 4;
         uint8_t rgb = (value) & 0xf;
         dst[0] = (float)(rgb * (1.0f/0xf)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xf)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = (value) & 0xf;
         uint8_t a = value >> 4;
         dst[0] = (float)(rgb * (1.0f/0xf)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xf)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_l4a4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 4;
         value |= ((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 4;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l4a4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value >> 4;
         uint8_t rgb = (value) & 0xf;
         dst[0] = (float)(rgb * (1.0f/0xf)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xf)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = (value) & 0xf;
         uint8_t a = value >> 4;
         dst[0] = (float)(rgb * (1.0f/0xf)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xf)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xf)); /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_l4a4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value >> 4;
         uint8_t rgb = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(rgb, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(rgb, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(rgb, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = (value) & 0xf;
         uint8_t a = value >> 4;
         dst[0] = _mesa_unorm_to_unorm(rgb, 4, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(rgb, 4, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(rgb, 4, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_l4a4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 4;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 4;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(rgb); /* r */
         dst[1] = ubyte_to_float(rgb); /* g */
         dst[2] = ubyte_to_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = ubyte_to_float(rgb); /* r */
         dst[1] = ubyte_to_float(rgb); /* g */
         dst[2] = ubyte_to_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (float_to_ubyte(src[0])) & 0xff;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(rgb); /* r */
         dst[1] = ubyte_to_float(rgb); /* g */
         dst[2] = ubyte_to_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = ubyte_to_float(rgb); /* r */
         dst[1] = ubyte_to_float(rgb); /* g */
         dst[2] = ubyte_to_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_l8a8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(src[0]) << 8;
         value |= (src[3]) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (src[0]) & 0xff;
         value |= (uint32_t)(src[3]) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value;
         dst[0] = (float)(rgb * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value;
         dst[0] = (float)(rgb * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
}

void
util_format_l16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value;
         dst[0] = _mesa_unorm_to_unorm(rgb, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(rgb, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(rgb, 16, 8); /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= _mesa_unorm_to_unorm(src[0], 8, 16);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
}

void
util_format_a16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 16, 8); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= _mesa_unorm_to_unorm(src[3], 8, 16);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgba = value;
         dst[0] = (float)(rgba * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgba * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgba * (1.0f/0xffff)); /* b */
         dst[3] = (float)(rgba * (1.0f/0xffff)); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgba = value;
         dst[0] = (float)(rgba * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgba * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgba * (1.0f/0xffff)); /* b */
         dst[3] = (float)(rgba * (1.0f/0xffff)); /* a */
}

void
util_format_i16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgba = value;
         dst[0] = _mesa_unorm_to_unorm(rgba, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(rgba, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(rgba, 16, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(rgba, 16, 8); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= _mesa_unorm_to_unorm(src[0], 8, 16);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (float)(rgb * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xffff)); /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (float)(rgb * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xffff)); /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) << 16;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (float)(rgb * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xffff)); /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (float)(rgb * (1.0f/0xffff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0xffff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0xffff)); /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#endif
}

void
util_format_l16a16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = _mesa_unorm_to_unorm(rgb, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(rgb, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(rgb, 16, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 16, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = _mesa_unorm_to_unorm(rgb, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(rgb, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(rgb, 16, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 16, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 16)) << 16;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 16)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 16)) & 0xffff;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 16)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t a = (int8_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_a8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t a = (int8_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
}

void
util_format_a8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t a = (int8_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_a8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t rgb = (int8_t)(value) ;
         dst[0] = (float)(rgb * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t rgb = (int8_t)(value) ;
         dst[0] = (float)(rgb * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
}

void
util_format_l8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t rgb = (int8_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(rgb * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(rgb * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 8) ;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(rgb * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(rgb * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
}

void
util_format_l8a8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 8) ;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[3], 8, 8)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t rgba = (int8_t)(value) ;
         dst[0] = (float)(rgba * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgba * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgba * (1.0f/0x7f)); /* b */
         dst[3] = (float)(rgba * (1.0f/0x7f)); /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_i8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t rgba = (int8_t)(value) ;
         dst[0] = (float)(rgba * (1.0f/0x7f)); /* r */
         dst[1] = (float)(rgba * (1.0f/0x7f)); /* g */
         dst[2] = (float)(rgba * (1.0f/0x7f)); /* b */
         dst[3] = (float)(rgba * (1.0f/0x7f)); /* a */
}

void
util_format_i8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t rgba = (int8_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 8, 8); /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_i8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t a = (int16_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t a = (int16_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
}

void
util_format_a16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t a = (int16_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 16, 8); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)(_mesa_unorm_to_snorm(src[3], 8, 16)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = (int16_t)(value) ;
         dst[0] = (float)(rgb * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = (int16_t)(value) ;
         dst[0] = (float)(rgb * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
}

void
util_format_l16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = (int16_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(rgb * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(rgb * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(rgb * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(rgb * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgb * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgb * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#endif
}

void
util_format_l16a16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 16, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgb, 0), 16, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 16, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) << 16) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[3], 8, 16)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 16)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 16)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t rgba = (int16_t)(value) ;
         dst[0] = (float)(rgba * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgba * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgba * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(rgba * (1.0f/0x7fff)); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t rgba = (int16_t)(value) ;
         dst[0] = (float)(rgba * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(rgba * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(rgba * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(rgba * (1.0f/0x7fff)); /* a */
}

void
util_format_i16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t rgba = (int16_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 16, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(rgba, 0), 16, 8); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_a16_float {
   uint16_t a;
};

void
util_format_a16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_a16_float pixel = {0};
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
}

void
util_format_a16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_a16_float pixel = {0};
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_l16_float {
   uint16_t rgb;
};

void
util_format_l16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_l16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgb); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgb); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgb); /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_l16_float pixel = {0};
         pixel.rgb = _mesa_float_to_float16_rtz(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_l16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgb); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgb); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgb); /* b */
         dst[3] = 1; /* a */
}

void
util_format_l16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_l16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_l16_float pixel = {0};
         pixel.rgb = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_l16a16_float {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t rgb;
   uint16_t a;
#else
   uint16_t rgb;
   uint16_t a;
#endif
};

void
util_format_l16a16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgb); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgb); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgb); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#else
         struct util_format_l16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgb); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgb); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgb); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l16a16_float pixel = {0};
         pixel.rgb = _mesa_float_to_float16_rtz(src[0]);
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l16a16_float pixel = {0};
         pixel.rgb = _mesa_float_to_float16_rtz(src[0]);
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgb); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgb); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgb); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#else
         struct util_format_l16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgb); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgb); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgb); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#endif
}

void
util_format_l16a16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
#else
         struct util_format_l16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.rgb)); /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l16a16_float pixel = {0};
         pixel.rgb = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l16a16_float pixel = {0};
         pixel.rgb = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_i16_float {
   uint16_t rgba;
};

void
util_format_i16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_i16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgba); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgba); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgba); /* b */
         dst[3] = _mesa_half_to_float(pixel.rgba); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_i16_float pixel = {0};
         pixel.rgba = _mesa_float_to_float16_rtz(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_i16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.rgba); /* r */
         dst[1] = _mesa_half_to_float(pixel.rgba); /* g */
         dst[2] = _mesa_half_to_float(pixel.rgba); /* b */
         dst[3] = _mesa_half_to_float(pixel.rgba); /* a */
}

void
util_format_i16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_i16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.rgba)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.rgba)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.rgba)); /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.rgba)); /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_i16_float pixel = {0};
         pixel.rgba = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_a32_float {
   float a;
};

void
util_format_a32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_a32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_a32_float pixel = {0};
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
}

void
util_format_a32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_a32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_a32_float pixel = {0};
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_l32_float {
   float rgb;
};

void
util_format_l32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_l32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_l32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_l32_float pixel = {0};
         pixel.rgb = src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_l32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_l32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.rgb); /* r */
         dst[1] = float_to_ubyte(pixel.rgb); /* g */
         dst[2] = float_to_ubyte(pixel.rgb); /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_l32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_l32_float pixel = {0};
         pixel.rgb = ubyte_to_float(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_l32a32_float {
#if UTIL_ARCH_BIG_ENDIAN
   float rgb;
   float a;
#else
   float rgb;
   float a;
#endif
};

void
util_format_l32a32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_l32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_l32a32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_float pixel = {0};
         pixel.rgb = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l32a32_float pixel = {0};
         pixel.rgb = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32a32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_l32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_l32a32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.rgb); /* r */
         dst[1] = float_to_ubyte(pixel.rgb); /* g */
         dst[2] = float_to_ubyte(pixel.rgb); /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
#else
         struct util_format_l32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.rgb); /* r */
         dst[1] = float_to_ubyte(pixel.rgb); /* g */
         dst[2] = float_to_ubyte(pixel.rgb); /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_l32a32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_float pixel = {0};
         pixel.rgb = ubyte_to_float(src[0]);
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l32a32_float pixel = {0};
         pixel.rgb = ubyte_to_float(src[0]);
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_i32_float {
   float rgba;
};

void
util_format_i32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_i32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgba; /* r */
         dst[1] = pixel.rgba; /* g */
         dst[2] = pixel.rgba; /* b */
         dst[3] = pixel.rgba; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_i32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_i32_float pixel = {0};
         pixel.rgba = src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_i32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgba; /* r */
         dst[1] = pixel.rgba; /* g */
         dst[2] = pixel.rgba; /* b */
         dst[3] = pixel.rgba; /* a */
}

void
util_format_i32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_i32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.rgba); /* r */
         dst[1] = float_to_ubyte(pixel.rgba); /* g */
         dst[2] = float_to_ubyte(pixel.rgba); /* b */
         dst[3] = float_to_ubyte(pixel.rgba); /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_i32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_i32_float pixel = {0};
         pixel.rgba = ubyte_to_float(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = util_format_srgb_8unorm_to_linear_float(rgb); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(rgb); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(rgb); /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= util_format_linear_float_to_srgb_8unorm(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = util_format_srgb_8unorm_to_linear_float(rgb); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(rgb); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(rgb); /* b */
         dst[3] = 1; /* a */
}

void
util_format_l8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = util_format_srgb_to_linear_8unorm(rgb); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(rgb); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(rgb); /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= util_format_linear_to_srgb_8unorm(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= util_format_linear_float_to_srgb_8unorm(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= util_format_linear_to_srgb_8unorm(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(rgb); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(rgb); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = util_format_srgb_8unorm_to_linear_float(rgb); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(rgb); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0])) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(rgb); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(rgb); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = util_format_srgb_8unorm_to_linear_float(rgb); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(rgb); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(rgb); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_l8a8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(rgb); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(rgb); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(rgb); /* b */
         dst[3] = a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = util_format_srgb_to_linear_8unorm(rgb); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(rgb); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(rgb); /* b */
         dst[3] = a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0])) << 8;
         value |= (src[3]) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)(src[3]) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0])) << 8;
         value |= (util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[1])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0])) << 8;
         value |= (util_format_linear_to_srgb_8unorm(src[1])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[1])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_srgb {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t r;
   uint8_t g;
   uint8_t b;
#else
   uint8_t r;
   uint8_t g;
   uint8_t b;
#endif
};

void
util_format_r8g8b8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_srgb pixel = {0};
         pixel.r = util_format_linear_float_to_srgb_8unorm(src[0]);
         pixel.g = util_format_linear_float_to_srgb_8unorm(src[1]);
         pixel.b = util_format_linear_float_to_srgb_8unorm(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_srgb pixel = {0};
         pixel.r = util_format_linear_float_to_srgb_8unorm(src[0]);
         pixel.g = util_format_linear_float_to_srgb_8unorm(src[1]);
         pixel.b = util_format_linear_float_to_srgb_8unorm(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_to_linear_8unorm(pixel.r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(pixel.g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(pixel.b); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r8g8b8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_to_linear_8unorm(pixel.r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(pixel.g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(pixel.b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_srgb pixel = {0};
         pixel.r = util_format_linear_to_srgb_8unorm(src[0]);
         pixel.g = util_format_linear_to_srgb_8unorm(src[1]);
         pixel.b = util_format_linear_to_srgb_8unorm(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_srgb pixel = {0};
         pixel.r = util_format_linear_to_srgb_8unorm(src[0]);
         pixel.g = util_format_linear_to_srgb_8unorm(src[1]);
         pixel.b = util_format_linear_to_srgb_8unorm(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_srgb {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t b;
   uint8_t g;
   uint8_t r;
#else
   uint8_t b;
   uint8_t g;
   uint8_t r;
#endif
};

void
util_format_b8g8r8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_srgb pixel = {0};
         pixel.b = util_format_linear_float_to_srgb_8unorm(src[2]);
         pixel.g = util_format_linear_float_to_srgb_8unorm(src[1]);
         pixel.r = util_format_linear_float_to_srgb_8unorm(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_srgb pixel = {0};
         pixel.b = util_format_linear_float_to_srgb_8unorm(src[2]);
         pixel.g = util_format_linear_float_to_srgb_8unorm(src[1]);
         pixel.r = util_format_linear_float_to_srgb_8unorm(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_8unorm_to_linear_float(pixel.r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(pixel.g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_to_linear_8unorm(pixel.r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(pixel.g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(pixel.b); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_b8g8r8_srgb pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = util_format_srgb_to_linear_8unorm(pixel.r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(pixel.g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(pixel.b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_srgb pixel = {0};
         pixel.b = util_format_linear_to_srgb_8unorm(src[2]);
         pixel.g = util_format_linear_to_srgb_8unorm(src[1]);
         pixel.r = util_format_linear_to_srgb_8unorm(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_srgb pixel = {0};
         pixel.b = util_format_linear_to_srgb_8unorm(src[2]);
         pixel.g = util_format_linear_to_srgb_8unorm(src[1]);
         pixel.r = util_format_linear_to_srgb_8unorm(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0])) << 24;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_r8g8b8a8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0])) << 24;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 8;
         value |= (src[3]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 16;
         value |= (uint32_t)(src[3]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[3])) & 0xff;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_a8b8g8r8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[3]) << 24;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_to_srgb_8unorm(src[0])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[3]) & 0xff;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8b8g8r8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_to_srgb_8unorm(src[0])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[2])) << 24;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_b8g8r8a8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[2])) << 24;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 8;
         value |= (src[3]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[2])) & 0xff;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 16;
         value |= (uint32_t)(src[3]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[2])) << 24;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8x8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8x8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8x8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[2])) << 24;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[2])) & 0xff;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[3])) & 0xff;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[2])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_a8r8g8b8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[3]) << 24;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_to_srgb_8unorm(src[2])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[3]) & 0xff;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[2])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[2])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8r8g8b8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8r8g8b8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8r8g8b8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (util_format_linear_to_srgb_8unorm(src[2])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[0])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[2])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8sg8sb8ux8u_norm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8sg8sb8ux8u_norm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8sg8sb8ux8u_norm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8sg8sb8ux8u_norm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 16) & 0xff;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8sg8sb8ux8u_norm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10sg10sb10sa2u_norm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         uint32_t a = value >> 30;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10sg10sb10sa2u_norm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) << 30;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0x3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10sg10sb10sa2u_norm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         uint32_t a = value >> 30;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x3)); /* a */
#endif
}

void
util_format_r10sg10sb10sa2u_norm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         uint32_t a = value >> 30;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10sg10sb10sa2u_norm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 2)) << 30;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 2)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5sg5sb6u_norm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 10;
         int16_t g = ((int16_t)(value << 6) ) >> 11;
         int16_t r = ((int16_t)(value << 11) ) >> 11;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0x3f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 11) ) >> 11;
         int16_t g = ((int16_t)(value << 6) ) >> 11;
         uint16_t b = value >> 10;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0x3f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5sg5sb6u_norm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3f)) << 10;
         value |= (uint16_t)((uint32_t)(((uint16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0xf)) & 0x1f) << 5) ;
         value |= (uint16_t)(((uint16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0xf)) & 0x1f) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((uint16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0xf)) & 0x1f) ;
         value |= (uint16_t)((uint32_t)(((uint16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0xf)) & 0x1f) << 5) ;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3f)) << 10;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5sg5sb6u_norm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 10;
         int16_t g = ((int16_t)(value << 6) ) >> 11;
         int16_t r = ((int16_t)(value << 11) ) >> 11;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0x3f)); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 11) ) >> 11;
         int16_t g = ((int16_t)(value << 6) ) >> 11;
         uint16_t b = value >> 10;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = (float)(g * (1.0f/0xf)); /* g */
         dst[2] = (float)(b * (1.0f/0x3f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r5sg5sb6u_norm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 10;
         int16_t g = ((int16_t)(value << 6) ) >> 11;
         int16_t r = ((int16_t)(value << 11) ) >> 11;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 5, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 6, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 11) ) >> 11;
         int16_t g = ((int16_t)(value << 6) ) >> 11;
         uint16_t b = value >> 10;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 5, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 5, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 6, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5sg5sb6u_norm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 6)) << 10;
         value |= (uint16_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 5)) & 0x1f) << 5) ;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[0], 8, 5)) & 0x1f) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[0], 8, 5)) & 0x1f) ;
         value |= (uint16_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 5)) & 0x1f) << 5) ;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[2], 8, 6)) << 10;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_z24_unorm_s8_uint_as_r8g8b8a8_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_z24_unorm_s8_uint_as_r8g8b8a8_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[0])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_z24_unorm_s8_uint_as_r8g8b8a8_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_z24_unorm_s8_uint_as_r8g8b8a8_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_z24_unorm_s8_uint_as_r8g8b8a8_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[0]) << 24;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)((src[2]) & 0xff) << 8;
         value |= (src[3]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[0]) & 0xff;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         value |= (uint32_t)(src[3]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64_float {
   double r;
};

void
util_format_r64_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 8;
      dst += 4;
   }
}

void
util_format_r64_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r64_float pixel = {0};
         pixel.r = (double)src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_r64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r64_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 8;
      dst += 4;
   }
}

void
util_format_r64_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64g64_float {
#if UTIL_ARCH_BIG_ENDIAN
   double r;
   double g;
#else
   double r;
   double g;
#endif
};

void
util_format_r64g64_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r64g64_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_float pixel = {0};
         pixel.r = (double)src[0];
         pixel.g = (double)src[1];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64_float pixel = {0};
         pixel.r = (double)src[0];
         pixel.g = (double)src[1];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64g64_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r64g64_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround(CLAMP(pixel.g, 0.0, 1.0) * 0xff); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r64g64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround(CLAMP(pixel.g, 0.0, 1.0) * 0xff); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r64g64_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         pixel.g = (double)(src[1] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         pixel.g = (double)(src[1] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64g64b64_float {
#if UTIL_ARCH_BIG_ENDIAN
   double r;
   double g;
   double b;
#else
   double r;
   double g;
   double b;
#endif
};

void
util_format_r64g64b64_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64b64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 24;
      dst += 4;
   }
}

void
util_format_r64g64b64_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_float pixel = {0};
         pixel.r = (double)src[0];
         pixel.g = (double)src[1];
         pixel.b = (double)src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64_float pixel = {0};
         pixel.r = (double)src[0];
         pixel.g = (double)src[1];
         pixel.b = (double)src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 24;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64g64b64_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64b64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r64g64b64_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround(CLAMP(pixel.g, 0.0, 1.0) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround(CLAMP(pixel.b, 0.0, 1.0) * 0xff); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r64g64b64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround(CLAMP(pixel.g, 0.0, 1.0) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround(CLAMP(pixel.b, 0.0, 1.0) * 0xff); /* b */
         dst[3] = 255; /* a */
#endif
      src += 24;
      dst += 4;
   }
}

void
util_format_r64g64b64_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         pixel.g = (double)(src[1] * (1.0f/0xff));
         pixel.b = (double)(src[2] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         pixel.g = (double)(src[1] * (1.0f/0xff));
         pixel.b = (double)(src[2] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 24;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64g64b64a64_float {
#if UTIL_ARCH_BIG_ENDIAN
   double r;
   double g;
   double b;
   double a;
#else
   double r;
   double g;
   double b;
   double a;
#endif
};

void
util_format_r64g64b64a64_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r64g64b64a64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
      src += 32;
      dst += 4;
   }
}

void
util_format_r64g64b64a64_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_float pixel = {0};
         pixel.r = (double)src[0];
         pixel.g = (double)src[1];
         pixel.b = (double)src[2];
         pixel.a = (double)src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64a64_float pixel = {0};
         pixel.r = (double)src[0];
         pixel.g = (double)src[1];
         pixel.b = (double)src[2];
         pixel.a = (double)src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 32;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64g64b64a64_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r64g64b64a64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
}

void
util_format_r64g64b64a64_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround(CLAMP(pixel.g, 0.0, 1.0) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround(CLAMP(pixel.b, 0.0, 1.0) * 0xff); /* b */
         dst[3] = (uint8_t)util_iround(CLAMP(pixel.a, 0.0, 1.0) * 0xff); /* a */
#else
         struct util_format_r64g64b64a64_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround(CLAMP(pixel.r, 0.0, 1.0) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround(CLAMP(pixel.g, 0.0, 1.0) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround(CLAMP(pixel.b, 0.0, 1.0) * 0xff); /* b */
         dst[3] = (uint8_t)util_iround(CLAMP(pixel.a, 0.0, 1.0) * 0xff); /* a */
#endif
      src += 32;
      dst += 4;
   }
}

void
util_format_r64g64b64a64_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         pixel.g = (double)(src[1] * (1.0f/0xff));
         pixel.b = (double)(src[2] * (1.0f/0xff));
         pixel.a = (double)(src[3] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64a64_float pixel = {0};
         pixel.r = (double)(src[0] * (1.0f/0xff));
         pixel.g = (double)(src[1] * (1.0f/0xff));
         pixel.b = (double)(src[2] * (1.0f/0xff));
         pixel.a = (double)(src[3] * (1.0f/0xff));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 32;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32_float {
   float r;
};

void
util_format_r32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r32_float pixel = {0};
         pixel.r = src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_r32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_float {
#if UTIL_ARCH_BIG_ENDIAN
   float r;
   float g;
#else
   float r;
   float g;
#endif
};

void
util_format_r32g32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_float {
#if UTIL_ARCH_BIG_ENDIAN
   float r;
   float g;
   float b;
#else
   float r;
   float g;
   float b;
#endif
};

void
util_format_r32g32b32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = float_to_ubyte(pixel.b); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = float_to_ubyte(pixel.b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         pixel.b = ubyte_to_float(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         pixel.b = ubyte_to_float(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_float {
#if UTIL_ARCH_BIG_ENDIAN
   float r;
   float g;
   float b;
   float a;
#else
   float r;
   float g;
   float b;
   float a;
#endif
};

void
util_format_r32g32b32a32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_r32g32b32a32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = float_to_ubyte(pixel.b); /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
#else
         struct util_format_r32g32b32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = float_to_ubyte(pixel.b); /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         pixel.b = ubyte_to_float(src[2]);
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         pixel.b = ubyte_to_float(src[2]);
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = (float)(r * (1.0/0xffffffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = (float)(r * (1.0/0xffffffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = _mesa_unorm_to_unorm(r, 32, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= _mesa_unorm_to_unorm(src[0], 8, 32);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
#else
   uint32_t r;
   uint32_t g;
#endif
};

void
util_format_r32g32_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_unorm pixel = {0};
         pixel.r = (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.g = (uint32_t)(CLAMP(src[1], 0.0f, 1.0f) * (double)0xffffffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_unorm pixel = {0};
         pixel.r = (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.g = (uint32_t)(CLAMP(src[1], 0.0f, 1.0f) * (double)0xffffffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 32, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 32, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 32, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 32, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
#endif
};

void
util_format_r32g32b32_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_unorm pixel = {0};
         pixel.r = (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.g = (uint32_t)(CLAMP(src[1], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.b = (uint32_t)(CLAMP(src[2], 0.0f, 1.0f) * (double)0xffffffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_unorm pixel = {0};
         pixel.r = (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.g = (uint32_t)(CLAMP(src[1], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.b = (uint32_t)(CLAMP(src[2], 0.0f, 1.0f) * (double)0xffffffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 32, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 32, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 32, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 32, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 32, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 32, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t a;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t a;
#endif
};

void
util_format_r32g32b32a32_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0xffffffff)); /* a */
#else
         struct util_format_r32g32b32a32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0xffffffff)); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_unorm pixel = {0};
         pixel.r = (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.g = (uint32_t)(CLAMP(src[1], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.b = (uint32_t)(CLAMP(src[2], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.a = (uint32_t)(CLAMP(src[3], 0.0f, 1.0f) * (double)0xffffffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_unorm pixel = {0};
         pixel.r = (uint32_t)(CLAMP(src[0], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.g = (uint32_t)(CLAMP(src[1], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.b = (uint32_t)(CLAMP(src[2], 0.0f, 1.0f) * (double)0xffffffff);
         pixel.a = (uint32_t)(CLAMP(src[3], 0.0f, 1.0f) * (double)0xffffffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0xffffffff)); /* a */
#else
         struct util_format_r32g32b32a32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0xffffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0xffffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0xffffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0xffffffff)); /* a */
#endif
}

void
util_format_r32g32b32a32_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 32, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 32, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 32, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(pixel.a, 32, 8); /* a */
#else
         struct util_format_r32g32b32a32_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 32, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 32, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 32, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(pixel.a, 32, 8); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 32);
         pixel.a = _mesa_unorm_to_unorm(src[3], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 32);
         pixel.a = _mesa_unorm_to_unorm(src[3], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = (uint8_t)(((uint64_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
#else
   uint32_t r;
   uint32_t g;
#endif
};

void
util_format_r32g32_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uscaled pixel = {0};
         pixel.r = (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         pixel.g = (uint32_t)CLAMP(src[1], 0.0f, 4294967040.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_uscaled pixel = {0};
         pixel.r = (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         pixel.g = (uint32_t)CLAMP(src[1], 0.0f, 4294967040.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uscaled pixel = {0};
         pixel.r = (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_uscaled pixel = {0};
         pixel.r = (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
#endif
};

void
util_format_r32g32b32_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uscaled pixel = {0};
         pixel.r = (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         pixel.g = (uint32_t)CLAMP(src[1], 0.0f, 4294967040.0f);
         pixel.b = (uint32_t)CLAMP(src[2], 0.0f, 4294967040.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_uscaled pixel = {0};
         pixel.r = (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         pixel.g = (uint32_t)CLAMP(src[1], 0.0f, 4294967040.0f);
         pixel.b = (uint32_t)CLAMP(src[2], 0.0f, 4294967040.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uscaled pixel = {0};
         pixel.r = (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_uscaled pixel = {0};
         pixel.r = (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t a;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t a;
#endif
};

void
util_format_r32g32b32a32_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uscaled pixel = {0};
         pixel.r = (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         pixel.g = (uint32_t)CLAMP(src[1], 0.0f, 4294967040.0f);
         pixel.b = (uint32_t)CLAMP(src[2], 0.0f, 4294967040.0f);
         pixel.a = (uint32_t)CLAMP(src[3], 0.0f, 4294967040.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_uscaled pixel = {0};
         pixel.r = (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);
         pixel.g = (uint32_t)CLAMP(src[1], 0.0f, 4294967040.0f);
         pixel.b = (uint32_t)CLAMP(src[2], 0.0f, 4294967040.0f);
         pixel.a = (uint32_t)CLAMP(src[3], 0.0f, 4294967040.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
}

void
util_format_r32g32b32a32_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint64_t)MIN2(pixel.a, 1)) * 0xff / 0x1); /* a */
#else
         struct util_format_r32g32b32a32_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint64_t)MIN2(pixel.a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uscaled pixel = {0};
         pixel.r = (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         pixel.a = (uint32_t)(((uint64_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_uscaled pixel = {0};
         pixel.r = (uint32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         pixel.a = (uint32_t)(((uint64_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = (float)(r * (1.0/0x7fffffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = (float)(r * (1.0/0x7fffffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 32, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 32)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
#else
   int32_t r;
   int32_t g;
#endif
};

void
util_format_r32g32_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_snorm pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.g = (int32_t)(CLAMP(src[1], -1.0f, 1.0f) * (double)0x7fffffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_snorm pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.g = (int32_t)(CLAMP(src[1], -1.0f, 1.0f) * (double)0x7fffffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 32, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 32, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 32, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 32, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
#else
   int32_t r;
   int32_t g;
   int32_t b;
#endif
};

void
util_format_r32g32b32_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_snorm pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.g = (int32_t)(CLAMP(src[1], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.b = (int32_t)(CLAMP(src[2], -1.0f, 1.0f) * (double)0x7fffffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_snorm pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.g = (int32_t)(CLAMP(src[1], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.b = (int32_t)(CLAMP(src[2], -1.0f, 1.0f) * (double)0x7fffffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 32, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 32, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 32, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 32, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 32, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 32, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#else
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#endif
};

void
util_format_r32g32b32a32_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x7fffffff)); /* a */
#else
         struct util_format_r32g32b32a32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x7fffffff)); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_snorm pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.g = (int32_t)(CLAMP(src[1], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.b = (int32_t)(CLAMP(src[2], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.a = (int32_t)(CLAMP(src[3], -1.0f, 1.0f) * (double)0x7fffffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_snorm pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.g = (int32_t)(CLAMP(src[1], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.b = (int32_t)(CLAMP(src[2], -1.0f, 1.0f) * (double)0x7fffffff);
         pixel.a = (int32_t)(CLAMP(src[3], -1.0f, 1.0f) * (double)0x7fffffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x7fffffff)); /* a */
#else
         struct util_format_r32g32b32a32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x7fffffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x7fffffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x7fffffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x7fffffff)); /* a */
#endif
}

void
util_format_r32g32b32a32_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 32, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 32, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 32, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(pixel.a, 0), 32, 8); /* a */
#else
         struct util_format_r32g32b32a32_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 32, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 32, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 32, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(pixel.a, 0), 32, 8); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 32);
         pixel.a = _mesa_unorm_to_snorm(src[3], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 32);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 32);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 32);
         pixel.a = _mesa_unorm_to_snorm(src[3], 8, 32);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = (uint8_t)(((uint64_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)(((uint64_t)src[0]) * 0x1 / 0xff)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
#else
   int32_t r;
   int32_t g;
#endif
};

void
util_format_r32g32_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sscaled pixel = {0};
         pixel.r = (int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f);
         pixel.g = (int32_t)CLAMP(src[1], -2147483648.0f, 2147483520.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_sscaled pixel = {0};
         pixel.r = (int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f);
         pixel.g = (int32_t)CLAMP(src[1], -2147483648.0f, 2147483520.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sscaled pixel = {0};
         pixel.r = (int32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_sscaled pixel = {0};
         pixel.r = (int32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
#else
   int32_t r;
   int32_t g;
   int32_t b;
#endif
};

void
util_format_r32g32b32_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sscaled pixel = {0};
         pixel.r = (int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f);
         pixel.g = (int32_t)CLAMP(src[1], -2147483648.0f, 2147483520.0f);
         pixel.b = (int32_t)CLAMP(src[2], -2147483648.0f, 2147483520.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_sscaled pixel = {0};
         pixel.r = (int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f);
         pixel.g = (int32_t)CLAMP(src[1], -2147483648.0f, 2147483520.0f);
         pixel.b = (int32_t)CLAMP(src[2], -2147483648.0f, 2147483520.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sscaled pixel = {0};
         pixel.r = (int32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_sscaled pixel = {0};
         pixel.r = (int32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#else
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#endif
};

void
util_format_r32g32b32a32_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sscaled pixel = {0};
         pixel.r = (int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f);
         pixel.g = (int32_t)CLAMP(src[1], -2147483648.0f, 2147483520.0f);
         pixel.b = (int32_t)CLAMP(src[2], -2147483648.0f, 2147483520.0f);
         pixel.a = (int32_t)CLAMP(src[3], -2147483648.0f, 2147483520.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_sscaled pixel = {0};
         pixel.r = (int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f);
         pixel.g = (int32_t)CLAMP(src[1], -2147483648.0f, 2147483520.0f);
         pixel.b = (int32_t)CLAMP(src[2], -2147483648.0f, 2147483520.0f);
         pixel.a = (int32_t)CLAMP(src[3], -2147483648.0f, 2147483520.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
}

void
util_format_r32g32b32a32_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint64_t)CLAMP(pixel.a, 0, 1)) * 0xff / 0x1); /* a */
#else
         struct util_format_r32g32b32a32_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint64_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint64_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint64_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint64_t)CLAMP(pixel.a, 0, 1)) * 0xff / 0x1); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sscaled pixel = {0};
         pixel.r = (int32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         pixel.a = (int32_t)(((uint64_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_sscaled pixel = {0};
         pixel.r = (int32_t)(((uint64_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int32_t)(((uint64_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int32_t)(((uint64_t)src[2]) * 0x1 / 0xff);
         pixel.a = (int32_t)(((uint64_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16_float {
   uint16_t r;
};

void
util_format_r16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_r16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16_float {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
#else
   uint16_t r;
   uint16_t g;
#endif
};

void
util_format_r16g16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_float {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
#endif
};

void
util_format_r16g16b16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         pixel.b = _mesa_float_to_float16_rtz(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         pixel.b = _mesa_float_to_float16_rtz(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.b)); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.b)); /* b */
         dst[3] = 255; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         pixel.b = _mesa_float_to_float16_rtz((float)(src[2] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         pixel.b = _mesa_float_to_float16_rtz((float)(src[2] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_float {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#endif
};

void
util_format_r16g16b16a16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#else
         struct util_format_r16g16b16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         pixel.b = _mesa_float_to_float16_rtz(src[2]);
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         pixel.b = _mesa_float_to_float16_rtz(src[2]);
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#else
         struct util_format_r16g16b16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#endif
}

void
util_format_r16g16b16a16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.b)); /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
#else
         struct util_format_r16g16b16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.b)); /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         pixel.b = _mesa_float_to_float16_rtz((float)(src[2] * (1.0f/0xff)));
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         pixel.b = _mesa_float_to_float16_rtz((float)(src[2] * (1.0f/0xff)));
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= _mesa_unorm_to_unorm(src[0], 8, 16);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) << 16;
         value |= ((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 16)) << 16;
         value |= (_mesa_unorm_to_unorm(src[1], 8, 16)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 16)) & 0xffff;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[1], 8, 16)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
#endif
};

void
util_format_r16g16b16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_unorm pixel = {0};
         pixel.r = (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         pixel.g = (uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff);
         pixel.b = (uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_unorm pixel = {0};
         pixel.r = (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         pixel.g = (uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff);
         pixel.b = (uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 16, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 16, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#endif
};

void
util_format_r16g16b16a16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0xffff)); /* a */
#else
         struct util_format_r16g16b16a16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0xffff)); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_unorm pixel = {0};
         pixel.r = (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         pixel.g = (uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff);
         pixel.b = (uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xffff);
         pixel.a = (uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_unorm pixel = {0};
         pixel.r = (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         pixel.g = (uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff);
         pixel.b = (uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xffff);
         pixel.a = (uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0xffff)); /* a */
#else
         struct util_format_r16g16b16a16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0xffff)); /* a */
#endif
}

void
util_format_r16g16b16a16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 16, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(pixel.a, 16, 8); /* a */
#else
         struct util_format_r16g16b16a16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 16, 8); /* b */
         dst[3] = _mesa_unorm_to_unorm(pixel.a, 16, 8); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 16);
         pixel.a = _mesa_unorm_to_unorm(src[3], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 16);
         pixel.a = _mesa_unorm_to_unorm(src[3], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)CLAMP(src[0], 0.0f, 65535.0f);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0.0f, 65535.0f)) << 16;
         value |= ((uint16_t)CLAMP(src[1], 0.0f, 65535.0f)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0.0f, 65535.0f)) & 0xffff;
         value |= (uint32_t)((uint16_t)CLAMP(src[1], 0.0f, 65535.0f)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 16;
         value |= ((uint16_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xffff;
         value |= (uint32_t)((uint16_t)(((uint32_t)src[1]) * 0x1 / 0xff)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
#endif
};

void
util_format_r16g16b16_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uscaled pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0.0f, 65535.0f);
         pixel.g = (uint16_t)CLAMP(src[1], 0.0f, 65535.0f);
         pixel.b = (uint16_t)CLAMP(src[2], 0.0f, 65535.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_uscaled pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0.0f, 65535.0f);
         pixel.g = (uint16_t)CLAMP(src[1], 0.0f, 65535.0f);
         pixel.b = (uint16_t)CLAMP(src[2], 0.0f, 65535.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uscaled pixel = {0};
         pixel.r = (uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_uscaled pixel = {0};
         pixel.r = (uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#endif
};

void
util_format_r16g16b16a16_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uscaled pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0.0f, 65535.0f);
         pixel.g = (uint16_t)CLAMP(src[1], 0.0f, 65535.0f);
         pixel.b = (uint16_t)CLAMP(src[2], 0.0f, 65535.0f);
         pixel.a = (uint16_t)CLAMP(src[3], 0.0f, 65535.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_uscaled pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0.0f, 65535.0f);
         pixel.g = (uint16_t)CLAMP(src[1], 0.0f, 65535.0f);
         pixel.b = (uint16_t)CLAMP(src[2], 0.0f, 65535.0f);
         pixel.a = (uint16_t)CLAMP(src[3], 0.0f, 65535.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
}

void
util_format_r16g16b16a16_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(pixel.a, 1)) * 0xff / 0x1); /* a */
#else
         struct util_format_r16g16b16a16_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(pixel.a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uscaled pixel = {0};
         pixel.r = (uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.a = (uint16_t)(((uint32_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_uscaled pixel = {0};
         pixel.r = (uint16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.a = (uint16_t)(((uint32_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) << 16) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 16)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 16)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[1], 8, 16)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
#else
   int16_t r;
   int16_t g;
   int16_t b;
#endif
};

void
util_format_r16g16b16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_snorm pixel = {0};
         pixel.r = (int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff);
         pixel.g = (int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff);
         pixel.b = (int16_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7fff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_snorm pixel = {0};
         pixel.r = (int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff);
         pixel.g = (int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff);
         pixel.b = (int16_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7fff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 16, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 16, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
   int16_t a;
#else
   int16_t r;
   int16_t g;
   int16_t b;
   int16_t a;
#endif
};

void
util_format_r16g16b16a16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0x7fff)); /* a */
#else
         struct util_format_r16g16b16a16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0x7fff)); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_snorm pixel = {0};
         pixel.r = (int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff);
         pixel.g = (int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff);
         pixel.b = (int16_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7fff);
         pixel.a = (int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_snorm pixel = {0};
         pixel.r = (int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff);
         pixel.g = (int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff);
         pixel.b = (int16_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7fff);
         pixel.a = (int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0x7fff)); /* a */
#else
         struct util_format_r16g16b16a16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = (float)(pixel.a * (1.0f/0x7fff)); /* a */
#endif
}

void
util_format_r16g16b16a16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 16, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(pixel.a, 0), 16, 8); /* a */
#else
         struct util_format_r16g16b16a16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 16, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(pixel.a, 0), 16, 8); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 16);
         pixel.a = _mesa_unorm_to_snorm(src[3], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 16);
         pixel.a = _mesa_unorm_to_snorm(src[3], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)CLAMP(src[0], -32768.0f, 32767.0f)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)(((uint32_t)src[0]) * 0x1 / 0xff)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[0], -32768.0f, 32767.0f)) << 16) ;
         value |= (uint32_t)(((int16_t)CLAMP(src[1], -32768.0f, 32767.0f)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)CLAMP(src[0], -32768.0f, 32767.0f)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[1], -32768.0f, 32767.0f)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 16) ;
         value |= (uint32_t)(((int16_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)(((uint32_t)src[1]) * 0x1 / 0xff)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
#else
   int16_t r;
   int16_t g;
   int16_t b;
#endif
};

void
util_format_r16g16b16_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sscaled pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768.0f, 32767.0f);
         pixel.g = (int16_t)CLAMP(src[1], -32768.0f, 32767.0f);
         pixel.b = (int16_t)CLAMP(src[2], -32768.0f, 32767.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_sscaled pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768.0f, 32767.0f);
         pixel.g = (int16_t)CLAMP(src[1], -32768.0f, 32767.0f);
         pixel.b = (int16_t)CLAMP(src[2], -32768.0f, 32767.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sscaled pixel = {0};
         pixel.r = (int16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_sscaled pixel = {0};
         pixel.r = (int16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
   int16_t a;
#else
   int16_t r;
   int16_t g;
   int16_t b;
   int16_t a;
#endif
};

void
util_format_r16g16b16a16_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sscaled pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768.0f, 32767.0f);
         pixel.g = (int16_t)CLAMP(src[1], -32768.0f, 32767.0f);
         pixel.b = (int16_t)CLAMP(src[2], -32768.0f, 32767.0f);
         pixel.a = (int16_t)CLAMP(src[3], -32768.0f, 32767.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_sscaled pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768.0f, 32767.0f);
         pixel.g = (int16_t)CLAMP(src[1], -32768.0f, 32767.0f);
         pixel.b = (int16_t)CLAMP(src[2], -32768.0f, 32767.0f);
         pixel.a = (int16_t)CLAMP(src[3], -32768.0f, 32767.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = (float)pixel.a; /* a */
#endif
}

void
util_format_r16g16b16a16_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(pixel.a, 0, 1)) * 0xff / 0x1); /* a */
#else
         struct util_format_r16g16b16a16_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(pixel.a, 0, 1)) * 0xff / 0x1); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sscaled pixel = {0};
         pixel.r = (int16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.a = (int16_t)(((uint32_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_sscaled pixel = {0};
         pixel.r = (int16_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int16_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int16_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.a = (int16_t)(((uint32_t)src[3]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= float_to_ubyte(src[0]);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= src[0];
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 8;
         value |= (float_to_ubyte(src[1])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (float_to_ubyte(src[0])) & 0xff;
         value |= (uint32_t)(float_to_ubyte(src[1])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(src[0]) << 8;
         value |= (src[1]) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (src[0]) & 0xff;
         value |= (uint32_t)(src[1]) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t r;
   uint8_t g;
   uint8_t b;
#else
   uint8_t r;
   uint8_t g;
   uint8_t b;
#endif
};

void
util_format_r8g8b8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_unorm pixel = {0};
         pixel.r = float_to_ubyte(src[0]);
         pixel.g = float_to_ubyte(src[1]);
         pixel.b = float_to_ubyte(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_unorm pixel = {0};
         pixel.r = float_to_ubyte(src[0]);
         pixel.g = float_to_ubyte(src[1]);
         pixel.b = float_to_ubyte(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r8g8b8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_unorm pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_unorm pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t b;
   uint8_t g;
   uint8_t r;
#else
   uint8_t b;
   uint8_t g;
   uint8_t r;
#endif
};

void
util_format_b8g8r8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_unorm pixel = {0};
         pixel.b = float_to_ubyte(src[2]);
         pixel.g = float_to_ubyte(src[1]);
         pixel.r = float_to_ubyte(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_unorm pixel = {0};
         pixel.b = float_to_ubyte(src[2]);
         pixel.g = float_to_ubyte(src[1]);
         pixel.r = float_to_ubyte(src[0]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = ubyte_to_float(pixel.r); /* r */
         dst[1] = ubyte_to_float(pixel.g); /* g */
         dst[2] = ubyte_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_b8g8r8_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_unorm pixel = {0};
         pixel.b = src[2];
         pixel.g = src[1];
         pixel.r = src[0];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_unorm pixel = {0};
         pixel.b = src[2];
         pixel.g = src[1];
         pixel.r = src[0];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 24;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 16;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (float_to_ubyte(src[0])) & 0xff;
         value |= (uint32_t)((float_to_ubyte(src[1])) & 0xff) << 8;
         value |= (uint32_t)((float_to_ubyte(src[2])) & 0xff) << 16;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = ubyte_to_float(b); /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_r8g8b8a8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = b; /* b */
         dst[3] = a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(src[0]) << 24;
         value |= (uint32_t)((src[1]) & 0xff) << 16;
         value |= (uint32_t)((src[2]) & 0xff) << 8;
         value |= (src[3]) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (src[0]) & 0xff;
         value |= (uint32_t)((src[1]) & 0xff) << 8;
         value |= (uint32_t)((src[2]) & 0xff) << 16;
         value |= (uint32_t)(src[3]) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)CLAMP(src[0], 0.0f, 255.0f);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) << 8;
         value |= ((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) & 0xff;
         value |= (uint32_t)((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 8;
         value |= ((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t r;
   uint8_t g;
   uint8_t b;
#else
   uint8_t r;
   uint8_t g;
   uint8_t b;
#endif
};

void
util_format_r8g8b8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uscaled pixel = {0};
         pixel.r = (uint8_t)CLAMP(src[0], 0.0f, 255.0f);
         pixel.g = (uint8_t)CLAMP(src[1], 0.0f, 255.0f);
         pixel.b = (uint8_t)CLAMP(src[2], 0.0f, 255.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_uscaled pixel = {0};
         pixel.r = (uint8_t)CLAMP(src[0], 0.0f, 255.0f);
         pixel.g = (uint8_t)CLAMP(src[1], 0.0f, 255.0f);
         pixel.b = (uint8_t)CLAMP(src[2], 0.0f, 255.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r8g8b8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uscaled pixel = {0};
         pixel.r = (uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_uscaled pixel = {0};
         pixel.r = (uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_uscaled {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t b;
   uint8_t g;
   uint8_t r;
#else
   uint8_t b;
   uint8_t g;
   uint8_t r;
#endif
};

void
util_format_b8g8r8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uscaled pixel = {0};
         pixel.b = (uint8_t)CLAMP(src[2], 0.0f, 255.0f);
         pixel.g = (uint8_t)CLAMP(src[1], 0.0f, 255.0f);
         pixel.r = (uint8_t)CLAMP(src[0], 0.0f, 255.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_uscaled pixel = {0};
         pixel.b = (uint8_t)CLAMP(src[2], 0.0f, 255.0f);
         pixel.g = (uint8_t)CLAMP(src[1], 0.0f, 255.0f);
         pixel.r = (uint8_t)CLAMP(src[0], 0.0f, 255.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_b8g8r8_uscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)MIN2(pixel.r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(pixel.g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(pixel.b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uscaled pixel = {0};
         pixel.b = (uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.g = (uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.r = (uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_uscaled pixel = {0};
         pixel.b = (uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.g = (uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.r = (uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0.0f, 255.0f)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[3], 0.0f, 255.0f)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0.0f, 255.0f)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0.0f, 255.0f)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_r8g8b8a8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 24;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 8;
         value |= ((uint8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[2], 0.0f, 255.0f)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[3], 0.0f, 255.0f)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[2], 0.0f, 255.0f)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0.0f, 255.0f)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_b8g8r8a8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) << 24;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) << 8;
         value |= ((uint8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0.0f, 255.0f)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0.0f, 255.0f)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[3], 0.0f, 255.0f)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0.0f, 255.0f)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0.0f, 255.0f)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0.0f, 255.0f)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_a8b8g8r8_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 24;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 8;
         value |= ((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) & 0xff;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 8) ;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 8) ;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[1], 8, 8)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int8_t r;
   int8_t g;
   int8_t b;
#else
   int8_t r;
   int8_t g;
   int8_t b;
#endif
};

void
util_format_r8g8b8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_snorm pixel = {0};
         pixel.r = (int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f);
         pixel.g = (int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f);
         pixel.b = (int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_snorm pixel = {0};
         pixel.r = (int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f);
         pixel.g = (int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f);
         pixel.b = (int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r8g8b8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 8);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 8);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 8);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 8);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 8);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 8);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int8_t b;
   int8_t g;
   int8_t r;
#else
   int8_t b;
   int8_t g;
   int8_t r;
#endif
};

void
util_format_b8g8r8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_snorm pixel = {0};
         pixel.b = (int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f);
         pixel.g = (int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f);
         pixel.r = (int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_snorm pixel = {0};
         pixel.b = (int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f);
         pixel.g = (int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f);
         pixel.r = (int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_b8g8r8_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_snorm pixel = {0};
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 8);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 8);
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 8);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_snorm pixel = {0};
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 8);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 8);
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 8);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
}

void
util_format_r8g8b8a8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 24) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[3], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
}

void
util_format_b8g8r8a8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[2], 8, 8)) << 24) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[3], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)CLAMP(src[0], -128.0f, 127.0f)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (float)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[0], -128.0f, 127.0f)) << 8) ;
         value |= (uint16_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)CLAMP(src[0], -128.0f, 127.0f)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[1], -128.0f, 127.0f)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 8) ;
         value |= (uint16_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int8_t r;
   int8_t g;
   int8_t b;
#else
   int8_t r;
   int8_t g;
   int8_t b;
#endif
};

void
util_format_r8g8b8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sscaled pixel = {0};
         pixel.r = (int8_t)CLAMP(src[0], -128.0f, 127.0f);
         pixel.g = (int8_t)CLAMP(src[1], -128.0f, 127.0f);
         pixel.b = (int8_t)CLAMP(src[2], -128.0f, 127.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_sscaled pixel = {0};
         pixel.r = (int8_t)CLAMP(src[0], -128.0f, 127.0f);
         pixel.g = (int8_t)CLAMP(src[1], -128.0f, 127.0f);
         pixel.b = (int8_t)CLAMP(src[2], -128.0f, 127.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r8g8b8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sscaled pixel = {0};
         pixel.r = (int8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_sscaled pixel = {0};
         pixel.r = (int8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         pixel.g = (int8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.b = (int8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_sscaled {
#if UTIL_ARCH_BIG_ENDIAN
   int8_t b;
   int8_t g;
   int8_t r;
#else
   int8_t b;
   int8_t g;
   int8_t r;
#endif
};

void
util_format_b8g8r8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sscaled pixel = {0};
         pixel.b = (int8_t)CLAMP(src[2], -128.0f, 127.0f);
         pixel.g = (int8_t)CLAMP(src[1], -128.0f, 127.0f);
         pixel.r = (int8_t)CLAMP(src[0], -128.0f, 127.0f);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_sscaled pixel = {0};
         pixel.b = (int8_t)CLAMP(src[2], -128.0f, 127.0f);
         pixel.g = (int8_t)CLAMP(src[1], -128.0f, 127.0f);
         pixel.r = (int8_t)CLAMP(src[0], -128.0f, 127.0f);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)pixel.r; /* r */
         dst[1] = (float)pixel.g; /* g */
         dst[2] = (float)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_b8g8r8_sscaled pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)(((uint32_t)CLAMP(pixel.r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(pixel.g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(pixel.b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sscaled pixel = {0};
         pixel.b = (int8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.g = (int8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.r = (int8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_sscaled pixel = {0};
         pixel.b = (int8_t)(((uint32_t)src[2]) * 0x1 / 0xff);
         pixel.g = (int8_t)(((uint32_t)src[1]) * 0x1 / 0xff);
         pixel.r = (int8_t)(((uint32_t)src[0]) * 0x1 / 0xff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[0], -128.0f, 127.0f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128.0f, 127.0f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128.0f, 127.0f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[0], -128.0f, 127.0f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128.0f, 127.0f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128.0f, 127.0f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_r8g8b8a8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(a, 0, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(a, 0, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[2], -128.0f, 127.0f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128.0f, 127.0f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128.0f, 127.0f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[2], -128.0f, 127.0f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128.0f, 127.0f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128.0f, 127.0f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_b8g8r8a8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(a, 0, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(a, 0, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128.0f, 127.0f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128.0f, 127.0f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[0], -128.0f, 127.0f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128.0f, 127.0f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128.0f, 127.0f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128.0f, 127.0f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[0], -128.0f, 127.0f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_a8b8g8r8_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(a, 0, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)CLAMP(a, 0, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)(((uint32_t)src[3]) * 0x1 / 0xff)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)(((uint32_t)src[0]) * 0x1 / 0xff)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32_fixed {
   int32_t r;
};

void
util_format_r32_fixed_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_fixed_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_fixed_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
         struct util_format_r32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_fixed_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_fixed_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_fixed {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
#else
   int32_t r;
   int32_t g;
#endif
};

void
util_format_r32g32_fixed_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_fixed_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.g = (int32_t)(CLAMP(src[1], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.g = (int32_t)(CLAMP(src[1], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_fixed_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_fixed_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround((CLAMP(pixel.g, 0, 65536) * (1.0/0x10000)) * 0xff); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround((CLAMP(pixel.g, 0, 65536) * (1.0/0x10000)) * 0xff); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_fixed_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         pixel.g = (int32_t)((float)(src[1] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         pixel.g = (int32_t)((float)(src[1] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_fixed {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
#else
   int32_t r;
   int32_t g;
   int32_t b;
#endif
};

void
util_format_r32g32b32_fixed_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_fixed_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.g = (int32_t)(CLAMP(src[1], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.b = (int32_t)(CLAMP(src[2], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.g = (int32_t)(CLAMP(src[1], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.b = (int32_t)(CLAMP(src[2], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_fixed_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_fixed_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround((CLAMP(pixel.g, 0, 65536) * (1.0/0x10000)) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround((CLAMP(pixel.b, 0, 65536) * (1.0/0x10000)) * 0xff); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround((CLAMP(pixel.g, 0, 65536) * (1.0/0x10000)) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround((CLAMP(pixel.b, 0, 65536) * (1.0/0x10000)) * 0xff); /* b */
         dst[3] = 255; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_fixed_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         pixel.g = (int32_t)((float)(src[1] * (1.0f/0xff)) * (double)0x10000);
         pixel.b = (int32_t)((float)(src[2] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         pixel.g = (int32_t)((float)(src[1] * (1.0f/0xff)) * (double)0x10000);
         pixel.b = (int32_t)((float)(src[2] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_fixed {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#else
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#endif
};

void
util_format_r32g32b32a32_fixed_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x10000)); /* a */
#else
         struct util_format_r32g32b32a32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x10000)); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_fixed_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.g = (int32_t)(CLAMP(src[1], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.b = (int32_t)(CLAMP(src[2], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.a = (int32_t)(CLAMP(src[3], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_fixed pixel = {0};
         pixel.r = (int32_t)(CLAMP(src[0], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.g = (int32_t)(CLAMP(src[1], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.b = (int32_t)(CLAMP(src[2], -65536.0f, 65535.0f) * (double)0x10000);
         pixel.a = (int32_t)(CLAMP(src[3], -65536.0f, 65535.0f) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_fixed_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x10000)); /* a */
#else
         struct util_format_r32g32b32a32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0/0x10000)); /* r */
         dst[1] = (float)(pixel.g * (1.0/0x10000)); /* g */
         dst[2] = (float)(pixel.b * (1.0/0x10000)); /* b */
         dst[3] = (float)(pixel.a * (1.0/0x10000)); /* a */
#endif
}

void
util_format_r32g32b32a32_fixed_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround((CLAMP(pixel.g, 0, 65536) * (1.0/0x10000)) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround((CLAMP(pixel.b, 0, 65536) * (1.0/0x10000)) * 0xff); /* b */
         dst[3] = (uint8_t)util_iround((CLAMP(pixel.a, 0, 65536) * (1.0/0x10000)) * 0xff); /* a */
#else
         struct util_format_r32g32b32a32_fixed pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (uint8_t)util_iround((CLAMP(pixel.r, 0, 65536) * (1.0/0x10000)) * 0xff); /* r */
         dst[1] = (uint8_t)util_iround((CLAMP(pixel.g, 0, 65536) * (1.0/0x10000)) * 0xff); /* g */
         dst[2] = (uint8_t)util_iround((CLAMP(pixel.b, 0, 65536) * (1.0/0x10000)) * 0xff); /* b */
         dst[3] = (uint8_t)util_iround((CLAMP(pixel.a, 0, 65536) * (1.0/0x10000)) * 0xff); /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_fixed_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         pixel.g = (int32_t)((float)(src[1] * (1.0f/0xff)) * (double)0x10000);
         pixel.b = (int32_t)((float)(src[2] * (1.0f/0xff)) * (double)0x10000);
         pixel.a = (int32_t)((float)(src[3] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_fixed pixel = {0};
         pixel.r = (int32_t)((float)(src[0] * (1.0f/0xff)) * (double)0x10000);
         pixel.g = (int32_t)((float)(src[1] * (1.0f/0xff)) * (double)0x10000);
         pixel.b = (int32_t)((float)(src[2] * (1.0f/0xff)) * (double)0x10000);
         pixel.a = (int32_t)((float)(src[3] * (1.0f/0xff)) * (double)0x10000);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10x2_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10x2_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0.0f, 1023.0f)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0.0f, 1023.0f)) & 0x3ff) << 10;
         value |= ((uint32_t)CLAMP(src[0], 0.0f, 1023.0f)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[0], 0.0f, 1023.0f)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0.0f, 1023.0f)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0.0f, 1023.0f)) & 0x3ff) << 20;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10x2_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r10g10b10x2_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10x2_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10;
         value |= ((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) << 20;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10x2_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10x2_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10x2_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r10g10b10x2_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10x2_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) << 20) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4r4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 4;
         uint8_t a = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = (value) & 0xf;
         uint8_t r = value >> 4;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_a4r4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) << 4;
         value |= ((uint8_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) << 4;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4r4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 4;
         uint8_t a = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = (value) & 0xf;
         uint8_t r = value >> 4;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_a4r4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 4;
         uint8_t a = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = (value) & 0xf;
         uint8_t r = value >> 4;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_a4r4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 4)) << 4;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 4)) & 0xf;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 4)) & 0xf;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 4)) << 4;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4a4_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value >> 4;
         uint8_t r = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0xf;
         uint8_t a = value >> 4;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_r4a4_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 4;
         value |= ((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xf)) & 0xf;
         value |= (uint32_t)((uint8_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xf)) << 4;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4a4_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value >> 4;
         uint8_t r = (value) & 0xf;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0xf;
         uint8_t a = value >> 4;
         dst[0] = (float)(r * (1.0f/0xf)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xf)); /* a */
#endif
}

void
util_format_r4a4_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value >> 4;
         uint8_t r = (value) & 0xf;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0xf;
         uint8_t a = value >> 4;
         dst[0] = _mesa_unorm_to_unorm(r, 4, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 4, 8); /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_r4a4_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 4;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 4)) & 0xf;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 4)) << 4;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8a8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 8;
         value |= (float_to_ubyte(src[3])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (float_to_ubyte(src[0])) & 0xff;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_r8a8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8a8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(src[0]) << 8;
         value |= (src[3]) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (src[0]) & 0xff;
         value |= (uint32_t)(src[3]) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 8;
         uint16_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xff;
         uint16_t r = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a8r8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[3])) << 8;
         value |= (float_to_ubyte(src[0])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (float_to_ubyte(src[3])) & 0xff;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 8;
         uint16_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xff;
         uint16_t r = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = ubyte_to_float(a); /* a */
#endif
}

void
util_format_a8r8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 8;
         uint16_t r = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xff;
         uint16_t r = value >> 8;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a8r8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(src[3]) << 8;
         value |= (src[0]) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (src[3]) & 0xff;
         value |= (uint32_t)(src[0]) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0.0f, 3.0f)) << 30;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0.0f, 1023.0f)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0.0f, 1023.0f)) & 0x3ff) << 10;
         value |= ((uint32_t)CLAMP(src[0], 0.0f, 1023.0f)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[0], 0.0f, 1023.0f)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0.0f, 1023.0f)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0.0f, 1023.0f)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0.0f, 3.0f)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_r10g10b10a2_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10;
         value |= ((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2.0f, 1.0f)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[2], -512.0f, 511.0f)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512.0f, 511.0f)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], -512.0f, 511.0f)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], -512.0f, 511.0f)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512.0f, 511.0f)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[2], -512.0f, 511.0f)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2.0f, 1.0f)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_r10g10b10a2_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MAX2(a, 0)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MAX2(a, 0)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x1)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x1)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
}

void
util_format_r10g10b10a2_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 2)) << 30) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 2)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_uscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_uscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0.0f, 3.0f)) << 30;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], 0.0f, 1023.0f)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0.0f, 1023.0f)) & 0x3ff) << 10;
         value |= ((uint32_t)CLAMP(src[2], 0.0f, 1023.0f)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[2], 0.0f, 1023.0f)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0.0f, 1023.0f)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], 0.0f, 1023.0f)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0.0f, 3.0f)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_uscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_b10g10r10a2_uscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (uint8_t)(((uint32_t)MIN2(r, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)MIN2(g, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)MIN2(b, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MIN2(a, 1)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_uscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10;
         value |= ((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_sscaled_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_sscaled_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2.0f, 1.0f)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[0], -512.0f, 511.0f)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512.0f, 511.0f)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], -512.0f, 511.0f)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], -512.0f, 511.0f)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512.0f, 511.0f)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[0], -512.0f, 511.0f)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2.0f, 1.0f)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_sscaled_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)r; /* r */
         dst[1] = (float)g; /* g */
         dst[2] = (float)b; /* b */
         dst[3] = (float)a; /* a */
#endif
}

void
util_format_b10g10r10a2_sscaled_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MAX2(a, 0)) * 0xff / 0x1); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (uint8_t)(((uint32_t)CLAMP(r, 0, 1)) * 0xff / 0x1); /* r */
         dst[1] = (uint8_t)(((uint32_t)CLAMP(g, 0, 1)) * 0xff / 0x1); /* g */
         dst[2] = (uint8_t)(((uint32_t)CLAMP(b, 0, 1)) * 0xff / 0x1); /* b */
         dst[3] = (uint8_t)(((uint32_t)MAX2(a, 0)) * 0xff / 0x1); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_sscaled_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)(((uint32_t)src[2]) * 0x1 / 0xff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[1]) * 0x1 / 0xff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)(((uint32_t)src[0]) * 0x1 / 0xff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)(((uint32_t)src[3]) * 0x1 / 0xff)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x1)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x1)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = (float)(a * (1.0f/0x1)); /* a */
#endif
}

void
util_format_b10g10r10a2_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 2, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 2, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 2)) << 30) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 2)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)MIN2(src[0], 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)CLAMP(src[0], 0, 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 255)) << 8;
         value |= ((uint8_t)MIN2(src[1], 255)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)MIN2(src[0], 255)) & 0xff;
         value |= (uint32_t)((uint8_t)MIN2(src[1], 255)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t g = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t g = value >> 8;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 255)) << 8;
         value |= ((uint8_t)CLAMP(src[1], 0, 255)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0, 255)) & 0xff;
         value |= (uint32_t)((uint8_t)CLAMP(src[1], 0, 255)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t r;
   uint8_t g;
   uint8_t b;
#else
   uint8_t r;
   uint8_t g;
   uint8_t b;
#endif
};

void
util_format_r8g8b8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uint pixel = {0};
         pixel.r = (uint8_t)MIN2(src[0], 255);
         pixel.g = (uint8_t)MIN2(src[1], 255);
         pixel.b = (uint8_t)MIN2(src[2], 255);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_uint pixel = {0};
         pixel.r = (uint8_t)MIN2(src[0], 255);
         pixel.g = (uint8_t)MIN2(src[1], 255);
         pixel.b = (uint8_t)MIN2(src[2], 255);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_uint pixel = {0};
         pixel.r = (uint8_t)CLAMP(src[0], 0, 255);
         pixel.g = (uint8_t)CLAMP(src[1], 0, 255);
         pixel.b = (uint8_t)CLAMP(src[2], 0, 255);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_uint pixel = {0};
         pixel.r = (uint8_t)CLAMP(src[0], 0, 255);
         pixel.g = (uint8_t)CLAMP(src[1], 0, 255);
         pixel.b = (uint8_t)CLAMP(src[2], 0, 255);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 255)) << 24;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)MIN2(src[2], 255)) & 0xff) << 8;
         value |= ((uint8_t)MIN2(src[3], 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)MIN2(src[0], 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)MIN2(src[2], 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)MIN2(src[3], 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_r8g8b8a8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 255)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0, 255)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[3], 0, 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0, 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0, 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_r8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)CLAMP(src[0], -128, 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t r = (int8_t)(value) ;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)MIN2(src[0], 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8g8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 8) ;
         value |= (uint16_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[1], -128, 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t g = ((int16_t)(value) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 8) ;
         value |= (uint16_t)(((int8_t)MIN2(src[1], 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[1], 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r8g8b8_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int8_t r;
   int8_t g;
   int8_t b;
#else
   int8_t r;
   int8_t g;
   int8_t b;
#endif
};

void
util_format_r8g8b8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_r8g8b8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sint pixel = {0};
         pixel.r = (int8_t)CLAMP(src[0], -128, 127);
         pixel.g = (int8_t)CLAMP(src[1], -128, 127);
         pixel.b = (int8_t)CLAMP(src[2], -128, 127);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_sint pixel = {0};
         pixel.r = (int8_t)CLAMP(src[0], -128, 127);
         pixel.g = (int8_t)CLAMP(src[1], -128, 127);
         pixel.b = (int8_t)CLAMP(src[2], -128, 127);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r8g8b8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r8g8b8_sint pixel = {0};
         pixel.r = (int8_t)MIN2(src[0], 127);
         pixel.g = (int8_t)MIN2(src[1], 127);
         pixel.b = (int8_t)MIN2(src[2], 127);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r8g8b8_sint pixel = {0};
         pixel.r = (int8_t)MIN2(src[0], 127);
         pixel.g = (int8_t)MIN2(src[1], 127);
         pixel.b = (int8_t)MIN2(src[2], 127);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8a8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128, 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128, 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8a8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_r8g8b8a8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)MIN2(src[3], 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[3], 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)MIN2(src[0], 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)CLAMP(src[0], 0, 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 65535)) << 16;
         value |= ((uint16_t)MIN2(src[1], 65535)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)MIN2(src[0], 65535)) & 0xffff;
         value |= (uint32_t)((uint16_t)MIN2(src[1], 65535)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t g = (value) & 0xffff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t g = value >> 16;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 65535)) << 16;
         value |= ((uint16_t)CLAMP(src[1], 0, 65535)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0, 65535)) & 0xffff;
         value |= (uint32_t)((uint16_t)CLAMP(src[1], 0, 65535)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
#endif
};

void
util_format_r16g16b16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uint pixel = {0};
         pixel.r = (uint16_t)MIN2(src[0], 65535);
         pixel.g = (uint16_t)MIN2(src[1], 65535);
         pixel.b = (uint16_t)MIN2(src[2], 65535);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_uint pixel = {0};
         pixel.r = (uint16_t)MIN2(src[0], 65535);
         pixel.g = (uint16_t)MIN2(src[1], 65535);
         pixel.b = (uint16_t)MIN2(src[2], 65535);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_uint pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0, 65535);
         pixel.g = (uint16_t)CLAMP(src[1], 0, 65535);
         pixel.b = (uint16_t)CLAMP(src[2], 0, 65535);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_uint pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0, 65535);
         pixel.g = (uint16_t)CLAMP(src[1], 0, 65535);
         pixel.b = (uint16_t)CLAMP(src[2], 0, 65535);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t a;
#endif
};

void
util_format_r16g16b16a16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = (unsigned)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = (unsigned)pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uint pixel = {0};
         pixel.r = (uint16_t)MIN2(src[0], 65535);
         pixel.g = (uint16_t)MIN2(src[1], 65535);
         pixel.b = (uint16_t)MIN2(src[2], 65535);
         pixel.a = (uint16_t)MIN2(src[3], 65535);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_uint pixel = {0};
         pixel.r = (uint16_t)MIN2(src[0], 65535);
         pixel.g = (uint16_t)MIN2(src[1], 65535);
         pixel.b = (uint16_t)MIN2(src[2], 65535);
         pixel.a = (uint16_t)MIN2(src[3], 65535);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = (unsigned)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = (unsigned)pixel.a; /* a */
#endif
}

void
util_format_r16g16b16a16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_uint pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0, 65535);
         pixel.g = (uint16_t)CLAMP(src[1], 0, 65535);
         pixel.b = (uint16_t)CLAMP(src[2], 0, 65535);
         pixel.a = (uint16_t)CLAMP(src[3], 0, 65535);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_uint pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0, 65535);
         pixel.g = (uint16_t)CLAMP(src[1], 0, 65535);
         pixel.b = (uint16_t)CLAMP(src[2], 0, 65535);
         pixel.a = (uint16_t)CLAMP(src[3], 0, 65535);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_r16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)CLAMP(src[0], -32768, 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t r = (int16_t)(value) ;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)MIN2(src[0], 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16g16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[0], -32768, 32767)) << 16) ;
         value |= (uint32_t)(((int16_t)CLAMP(src[1], -32768, 32767)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)CLAMP(src[0], -32768, 32767)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[1], -32768, 32767)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t g = ((int32_t)(value) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)MIN2(src[0], 32767)) << 16) ;
         value |= (uint32_t)(((int16_t)MIN2(src[1], 32767)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)MIN2(src[0], 32767)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)MIN2(src[1], 32767)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
#else
   int16_t r;
   int16_t g;
   int16_t b;
#endif
};

void
util_format_r16g16b16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 6;
      dst += 4;
   }
}

void
util_format_r16g16b16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sint pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768, 32767);
         pixel.g = (int16_t)CLAMP(src[1], -32768, 32767);
         pixel.b = (int16_t)CLAMP(src[2], -32768, 32767);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_sint pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768, 32767);
         pixel.g = (int16_t)CLAMP(src[1], -32768, 32767);
         pixel.b = (int16_t)CLAMP(src[2], -32768, 32767);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16_sint pixel = {0};
         pixel.r = (int16_t)MIN2(src[0], 32767);
         pixel.g = (int16_t)MIN2(src[1], 32767);
         pixel.b = (int16_t)MIN2(src[2], 32767);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16_sint pixel = {0};
         pixel.r = (int16_t)MIN2(src[0], 32767);
         pixel.g = (int16_t)MIN2(src[1], 32767);
         pixel.b = (int16_t)MIN2(src[2], 32767);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 6;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16a16_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
   int16_t a;
#else
   int16_t r;
   int16_t g;
   int16_t b;
   int16_t a;
#endif
};

void
util_format_r16g16b16a16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = (int)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = (int)pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16a16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sint pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768, 32767);
         pixel.g = (int16_t)CLAMP(src[1], -32768, 32767);
         pixel.b = (int16_t)CLAMP(src[2], -32768, 32767);
         pixel.a = (int16_t)CLAMP(src[3], -32768, 32767);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_sint pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768, 32767);
         pixel.g = (int16_t)CLAMP(src[1], -32768, 32767);
         pixel.b = (int16_t)CLAMP(src[2], -32768, 32767);
         pixel.a = (int16_t)CLAMP(src[3], -32768, 32767);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16a16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = (int)pixel.a; /* a */
#else
         struct util_format_r16g16b16a16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = (int)pixel.a; /* a */
#endif
}

void
util_format_r16g16b16a16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16a16_sint pixel = {0};
         pixel.r = (int16_t)MIN2(src[0], 32767);
         pixel.g = (int16_t)MIN2(src[1], 32767);
         pixel.b = (int16_t)MIN2(src[2], 32767);
         pixel.a = (int16_t)MIN2(src[3], 32767);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16a16_sint pixel = {0};
         pixel.r = (int16_t)MIN2(src[0], 32767);
         pixel.g = (int16_t)MIN2(src[1], 32767);
         pixel.b = (int16_t)MIN2(src[2], 32767);
         pixel.a = (int16_t)MIN2(src[3], 32767);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= src[0];
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)MAX2(src[0], 0);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
#else
   uint32_t r;
   uint32_t g;
#endif
};

void
util_format_r32g32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
#endif
};

void
util_format_r32g32b32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         pixel.b = (uint32_t)MAX2(src[2], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         pixel.b = (uint32_t)MAX2(src[2], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t a;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t a;
#endif
};

void
util_format_r32g32b32a32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_r32g32b32a32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         pixel.b = (uint32_t)MAX2(src[2], 0);
         pixel.a = (uint32_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         pixel.b = (uint32_t)MAX2(src[2], 0);
         pixel.a = (uint32_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_r32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(src[0]) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         int32_t r = (int32_t)(value) ;
         dst[0] = r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)MIN2(src[0], 2147483647)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
#else
   int32_t r;
   int32_t g;
#endif
};

void
util_format_r32g32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32g32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
#else
   int32_t r;
   int32_t g;
   int32_t b;
#endif
};

void
util_format_r32g32b32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 12;
      dst += 4;
   }
}

void
util_format_r32g32b32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         pixel.b = (int32_t)MIN2(src[2], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         pixel.b = (int32_t)MIN2(src[2], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 12;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32a32_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#else
   int32_t r;
   int32_t g;
   int32_t b;
   int32_t a;
#endif
};

void
util_format_r32g32b32a32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32a32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32a32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32g32b32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_r32g32b32a32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32a32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         pixel.b = (int32_t)MIN2(src[2], 2147483647);
         pixel.a = (int32_t)MIN2(src[3], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32a32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         pixel.b = (int32_t)MIN2(src[2], 2147483647);
         pixel.a = (int32_t)MIN2(src[3], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64_uint {
   uint64_t r;
};

void
util_format_r64_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 8;
      dst += 4;
   }
}

void
util_format_r64_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         struct util_format_r64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r64_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64g64_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint64_t r;
   uint64_t g;
#else
   uint64_t r;
   uint64_t g;
#endif
};

void
util_format_r64g64_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r64g64_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         pixel.g = (uint64_t)src[1];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         pixel.g = (uint64_t)src[1];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64g64_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r64g64_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         pixel.g = (uint64_t)MAX2(src[1], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         pixel.g = (uint64_t)MAX2(src[1], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64g64b64_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint64_t r;
   uint64_t g;
   uint64_t b;
#else
   uint64_t r;
   uint64_t g;
   uint64_t b;
#endif
};

void
util_format_r64g64b64_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64b64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = 1; /* a */
#endif
      src += 24;
      dst += 4;
   }
}

void
util_format_r64g64b64_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         pixel.g = (uint64_t)src[1];
         pixel.b = (uint64_t)src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         pixel.g = (uint64_t)src[1];
         pixel.b = (uint64_t)src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 24;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64g64b64_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r64g64b64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r64g64b64_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         pixel.g = (uint64_t)MAX2(src[1], 0);
         pixel.b = (uint64_t)MAX2(src[2], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         pixel.g = (uint64_t)MAX2(src[1], 0);
         pixel.b = (uint64_t)MAX2(src[2], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 24;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64g64b64a64_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint64_t r;
   uint64_t g;
   uint64_t b;
   uint64_t a;
#else
   uint64_t r;
   uint64_t g;
   uint64_t b;
   uint64_t a;
#endif
};

void
util_format_r64g64b64a64_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = (unsigned)MIN2(pixel.a, 4294967295); /* a */
#else
         struct util_format_r64g64b64a64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = (unsigned)MIN2(pixel.a, 4294967295); /* a */
#endif
      src += 32;
      dst += 4;
   }
}

void
util_format_r64g64b64a64_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         pixel.g = (uint64_t)src[1];
         pixel.b = (uint64_t)src[2];
         pixel.a = (uint64_t)src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64a64_uint pixel = {0};
         pixel.r = (uint64_t)src[0];
         pixel.g = (uint64_t)src[1];
         pixel.b = (uint64_t)src[2];
         pixel.a = (uint64_t)src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 32;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64g64b64a64_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = (unsigned)MIN2(pixel.a, 4294967295); /* a */
#else
         struct util_format_r64g64b64a64_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)MIN2(pixel.r, 4294967295); /* r */
         dst[1] = (unsigned)MIN2(pixel.g, 4294967295); /* g */
         dst[2] = (unsigned)MIN2(pixel.b, 4294967295); /* b */
         dst[3] = (unsigned)MIN2(pixel.a, 4294967295); /* a */
#endif
}

void
util_format_r64g64b64a64_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r64g64b64a64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         pixel.g = (uint64_t)MAX2(src[1], 0);
         pixel.b = (uint64_t)MAX2(src[2], 0);
         pixel.a = (uint64_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r64g64b64a64_uint pixel = {0};
         pixel.r = (uint64_t)MAX2(src[0], 0);
         pixel.g = (uint64_t)MAX2(src[1], 0);
         pixel.b = (uint64_t)MAX2(src[2], 0);
         pixel.a = (uint64_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 32;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r64_sint {
   int64_t r;
};

void
util_format_r64_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         struct util_format_r64_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)CLAMP(pixel.r, -2147483648, 2147483647); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
      src += 8;
      dst += 4;
   }
}

void
util_format_r64_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r64_sint pixel = {0};
         pixel.r = (int64_t)src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r64_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         struct util_format_r64_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)CLAMP(pixel.r, -2147483648, 2147483647); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
}

void
util_format_r64_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         struct util_format_r64_sint pixel = {0};
         pixel.r = (int64_t)src[0];
         memcpy(dst, &pixel, sizeof pixel);
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_a8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)MIN2(src[3], 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
}

void
util_format_a8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)CLAMP(src[3], 0, 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgba = value;
         dst[0] = (unsigned)rgba; /* r */
         dst[1] = (unsigned)rgba; /* g */
         dst[2] = (unsigned)rgba; /* b */
         dst[3] = (unsigned)rgba; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_i8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)MIN2(src[0], 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgba = value;
         dst[0] = (unsigned)rgba; /* r */
         dst[1] = (unsigned)rgba; /* g */
         dst[2] = (unsigned)rgba; /* b */
         dst[3] = (unsigned)rgba; /* a */
}

void
util_format_i8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)CLAMP(src[0], 0, 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)MIN2(src[0], 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         uint8_t rgb = value;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)CLAMP(src[0], 0, 255);
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 255)) << 8;
         value |= ((uint8_t)MIN2(src[3], 255)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)MIN2(src[0], 255)) & 0xff;
         value |= (uint32_t)((uint8_t)MIN2(src[3], 255)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_l8a8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 255)) << 8;
         value |= ((uint8_t)CLAMP(src[3], 0, 255)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0, 255)) & 0xff;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0, 255)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t a = (int8_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_a8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)CLAMP(src[3], -128, 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t a = (int8_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
}

void
util_format_a8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)MIN2(src[3], 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t rgba = (int8_t)(value) ;
         dst[0] = (int)rgba; /* r */
         dst[1] = (int)rgba; /* g */
         dst[2] = (int)rgba; /* b */
         dst[3] = (int)rgba; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_i8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)CLAMP(src[0], -128, 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t rgba = (int8_t)(value) ;
         dst[0] = (int)rgba; /* r */
         dst[1] = (int)rgba; /* g */
         dst[2] = (int)rgba; /* b */
         dst[3] = (int)rgba; /* a */
}

void
util_format_i8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)MIN2(src[0], 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint8_t value = *(const uint8_t *)src;
         int8_t rgb = (int8_t)(value) ;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = 1; /* a */
      src += 1;
      dst += 4;
   }
}

void
util_format_l8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)CLAMP(src[0], -128, 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint8_t value = *(const uint8_t *)src;
         int8_t rgb = (int8_t)(value) ;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint8_t value = 0;
         value |= (uint8_t)((int8_t)MIN2(src[0], 127)) ;
         *(uint8_t *)dst = value;
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_l8a8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 8) ;
         value |= (uint16_t)(((int8_t)CLAMP(src[3], -128, 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[3], -128, 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l8a8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_l8a8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 8) ;
         value |= (uint16_t)(((int8_t)MIN2(src[3], 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[3], 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)MIN2(src[3], 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
}

void
util_format_a16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)CLAMP(src[3], 0, 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgba = value;
         dst[0] = (unsigned)rgba; /* r */
         dst[1] = (unsigned)rgba; /* g */
         dst[2] = (unsigned)rgba; /* b */
         dst[3] = (unsigned)rgba; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)MIN2(src[0], 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgba = value;
         dst[0] = (unsigned)rgba; /* r */
         dst[1] = (unsigned)rgba; /* g */
         dst[2] = (unsigned)rgba; /* b */
         dst[3] = (unsigned)rgba; /* a */
}

void
util_format_i16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)CLAMP(src[0], 0, 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)MIN2(src[0], 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         uint16_t rgb = value;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)CLAMP(src[0], 0, 65535);
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 65535)) << 16;
         value |= ((uint16_t)MIN2(src[3], 65535)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)MIN2(src[0], 65535)) & 0xffff;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 65535)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (unsigned)rgb; /* r */
         dst[1] = (unsigned)rgb; /* g */
         dst[2] = (unsigned)rgb; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_l16a16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 65535)) << 16;
         value |= ((uint16_t)CLAMP(src[3], 0, 65535)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0, 65535)) & 0xffff;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 65535)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t a = (int16_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_a16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)CLAMP(src[3], -32768, 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t a = (int16_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
}

void
util_format_a16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)MIN2(src[3], 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t rgba = (int16_t)(value) ;
         dst[0] = (int)rgba; /* r */
         dst[1] = (int)rgba; /* g */
         dst[2] = (int)rgba; /* b */
         dst[3] = (int)rgba; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_i16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)CLAMP(src[0], -32768, 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t rgba = (int16_t)(value) ;
         dst[0] = (int)rgba; /* r */
         dst[1] = (int)rgba; /* g */
         dst[2] = (int)rgba; /* b */
         dst[3] = (int)rgba; /* a */
}

void
util_format_i16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)MIN2(src[0], 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = (int16_t)(value) ;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = 1; /* a */
      src += 2;
      dst += 4;
   }
}

void
util_format_l16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)CLAMP(src[0], -32768, 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint16_t value = *(const uint16_t *)src;
         int16_t rgb = (int16_t)(value) ;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint16_t value = 0;
         value |= (uint16_t)((int16_t)MIN2(src[0], 32767)) ;
         *(uint16_t *)dst = value;
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_l16a16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[0], -32768, 32767)) << 16) ;
         value |= (uint32_t)(((int16_t)CLAMP(src[3], -32768, 32767)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)CLAMP(src[0], -32768, 32767)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[3], -32768, 32767)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l16a16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (int)rgb; /* r */
         dst[1] = (int)rgb; /* g */
         dst[2] = (int)rgb; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_l16a16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)MIN2(src[0], 32767)) << 16) ;
         value |= (uint32_t)(((int16_t)MIN2(src[3], 32767)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)MIN2(src[0], 32767)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)MIN2(src[3], 32767)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_a32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= src[3];
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
}

void
util_format_a32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)MAX2(src[3], 0);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgba = value;
         dst[0] = rgba; /* r */
         dst[1] = rgba; /* g */
         dst[2] = rgba; /* b */
         dst[3] = rgba; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_i32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= src[0];
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgba = value;
         dst[0] = rgba; /* r */
         dst[1] = rgba; /* g */
         dst[2] = rgba; /* b */
         dst[3] = rgba; /* a */
}

void
util_format_i32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)MAX2(src[0], 0);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_l32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= src[0];
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         uint32_t rgb = value;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)MAX2(src[0], 0);
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_l32a32_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t rgb;
   uint32_t a;
#else
   uint32_t rgb;
   uint32_t a;
#endif
};

void
util_format_l32a32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_l32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_l32a32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_uint pixel = {0};
         pixel.rgb = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l32a32_uint pixel = {0};
         pixel.rgb = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32a32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_l32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_l32a32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_uint pixel = {0};
         pixel.rgb = (uint32_t)MAX2(src[0], 0);
         pixel.a = (uint32_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l32a32_uint pixel = {0};
         pixel.rgb = (uint32_t)MAX2(src[0], 0);
         pixel.a = (uint32_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t a = (int32_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_a32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(src[3]) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         int32_t a = (int32_t)(value) ;
         dst[0] = 0; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = a; /* a */
}

void
util_format_a32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)MIN2(src[3], 2147483647)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t rgba = (int32_t)(value) ;
         dst[0] = rgba; /* r */
         dst[1] = rgba; /* g */
         dst[2] = rgba; /* b */
         dst[3] = rgba; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_i32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(src[0]) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_i32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         int32_t rgba = (int32_t)(value) ;
         dst[0] = rgba; /* r */
         dst[1] = rgba; /* g */
         dst[2] = rgba; /* b */
         dst[3] = rgba; /* a */
}

void
util_format_i32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)MIN2(src[0], 2147483647)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = (int32_t)(value) ;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = 1; /* a */
      src += 4;
      dst += 4;
   }
}

void
util_format_l32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)(src[0]) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
         uint32_t value = *(const uint32_t *)src;
         int32_t rgb = (int32_t)(value) ;
         dst[0] = rgb; /* r */
         dst[1] = rgb; /* g */
         dst[2] = rgb; /* b */
         dst[3] = 1; /* a */
}

void
util_format_l32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
         uint32_t value = 0;
         value |= (uint32_t)((int32_t)MIN2(src[0], 2147483647)) ;
         *(uint32_t *)dst = value;
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_l32a32_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t rgb;
   int32_t a;
#else
   int32_t rgb;
   int32_t a;
#endif
};

void
util_format_l32a32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_l32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_l32a32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_sint pixel = {0};
         pixel.rgb = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l32a32_sint pixel = {0};
         pixel.rgb = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_l32a32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_l32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.rgb; /* r */
         dst[1] = pixel.rgb; /* g */
         dst[2] = pixel.rgb; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_l32a32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_l32a32_sint pixel = {0};
         pixel.rgb = (int32_t)MIN2(src[0], 2147483647);
         pixel.a = (int32_t)MIN2(src[3], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_l32a32_sint pixel = {0};
         pixel.rgb = (int32_t)MIN2(src[0], 2147483647);
         pixel.a = (int32_t)MIN2(src[3], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint8_t b;
   uint8_t g;
   uint8_t r;
#else
   uint8_t b;
   uint8_t g;
   uint8_t r;
#endif
};

void
util_format_b8g8r8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uint pixel = {0};
         pixel.b = (uint8_t)MIN2(src[2], 255);
         pixel.g = (uint8_t)MIN2(src[1], 255);
         pixel.r = (uint8_t)MIN2(src[0], 255);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_uint pixel = {0};
         pixel.b = (uint8_t)MIN2(src[2], 255);
         pixel.g = (uint8_t)MIN2(src[1], 255);
         pixel.r = (uint8_t)MIN2(src[0], 255);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_uint pixel = {0};
         pixel.b = (uint8_t)CLAMP(src[2], 0, 255);
         pixel.g = (uint8_t)CLAMP(src[1], 0, 255);
         pixel.r = (uint8_t)CLAMP(src[0], 0, 255);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_uint pixel = {0};
         pixel.b = (uint8_t)CLAMP(src[2], 0, 255);
         pixel.g = (uint8_t)CLAMP(src[1], 0, 255);
         pixel.r = (uint8_t)CLAMP(src[0], 0, 255);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[2], 255)) << 24;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)MIN2(src[0], 255)) & 0xff) << 8;
         value |= ((uint8_t)MIN2(src[3], 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)MIN2(src[2], 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)MIN2(src[0], 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)MIN2(src[3], 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t a = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t a = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_b8g8r8a8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[2], 0, 255)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0, 255)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[3], 0, 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[2], 0, 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0, 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_b8g8r8_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int8_t b;
   int8_t g;
   int8_t r;
#else
   int8_t b;
   int8_t g;
   int8_t r;
#endif
};

void
util_format_b8g8r8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 3;
      dst += 4;
   }
}

void
util_format_b8g8r8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sint pixel = {0};
         pixel.b = (int8_t)CLAMP(src[2], -128, 127);
         pixel.g = (int8_t)CLAMP(src[1], -128, 127);
         pixel.r = (int8_t)CLAMP(src[0], -128, 127);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_sint pixel = {0};
         pixel.b = (int8_t)CLAMP(src[2], -128, 127);
         pixel.g = (int8_t)CLAMP(src[1], -128, 127);
         pixel.r = (int8_t)CLAMP(src[0], -128, 127);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_b8g8r8_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b8g8r8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_b8g8r8_sint pixel = {0};
         pixel.b = (int8_t)MIN2(src[2], 127);
         pixel.g = (int8_t)MIN2(src[1], 127);
         pixel.r = (int8_t)MIN2(src[0], 127);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_b8g8r8_sint pixel = {0};
         pixel.b = (int8_t)MIN2(src[2], 127);
         pixel.g = (int8_t)MIN2(src[1], 127);
         pixel.r = (int8_t)MIN2(src[0], 127);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 3;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b8g8r8a8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[2], -128, 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128, 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128, 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b8g8r8a8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value << 16) ) >> 24;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 8) ) >> 24;
         int32_t a = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_b8g8r8a8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[2], 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)MIN2(src[3], 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[3], 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8r8g8b8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[3], 255)) << 24;
         value |= (uint32_t)(((uint8_t)MIN2(src[0], 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 8;
         value |= ((uint8_t)MIN2(src[2], 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)MIN2(src[3], 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)MIN2(src[0], 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)MIN2(src[2], 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8r8g8b8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t r = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t r = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a8r8g8b8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0, 255)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[2], 0, 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[3], 0, 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[0], 0, 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[2], 0, 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[3], 255)) << 24;
         value |= (uint32_t)(((uint8_t)MIN2(src[2], 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 8;
         value |= ((uint8_t)MIN2(src[0], 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)MIN2(src[3], 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)MIN2(src[2], 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 24;
         uint32_t b = (value >> 16) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t r = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t r = value >> 24;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a8b8g8r8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0, 255)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 8;
         value |= ((uint8_t)CLAMP(src[0], 0, 255)) & 0xff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[3], 0, 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0, 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 255)) << 24;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2r10g10b10_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = value >> 22;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a2r10g10b10_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)MIN2(src[2], 1023)) << 22;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 12;
         value |= (uint32_t)(((uint32_t)MIN2(src[0], 1023)) & 0x3ff) << 2;
         value |= ((uint32_t)MIN2(src[3], 3)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)MIN2(src[3], 3)) & 0x3;
         value |= (uint32_t)(((uint32_t)MIN2(src[0], 1023)) & 0x3ff) << 2;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 12;
         value |= (uint32_t)((uint32_t)MIN2(src[2], 1023)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2r10g10b10_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t r = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = value >> 22;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a2r10g10b10_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)CLAMP(src[2], 0, 1023)) << 22;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 12;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff) << 2;
         value |= ((uint32_t)CLAMP(src[3], 0, 3)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[3], 0, 3)) & 0x3;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff) << 2;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 12;
         value |= (uint32_t)((uint32_t)CLAMP(src[2], 0, 1023)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2b10g10r10_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = value >> 22;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a2b10g10r10_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)MIN2(src[0], 1023)) << 22;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 12;
         value |= (uint32_t)(((uint32_t)MIN2(src[2], 1023)) & 0x3ff) << 2;
         value |= ((uint32_t)MIN2(src[3], 3)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)MIN2(src[3], 3)) & 0x3;
         value |= (uint32_t)(((uint32_t)MIN2(src[2], 1023)) & 0x3ff) << 2;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 12;
         value |= (uint32_t)((uint32_t)MIN2(src[0], 1023)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a2b10g10r10_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 22;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t a = (value) & 0x3;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = (value) & 0x3;
         uint32_t b = (value >> 2) & 0x3ff;
         uint32_t g = (value >> 12) & 0x3ff;
         uint32_t r = value >> 22;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a2b10g10r10_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)CLAMP(src[0], 0, 1023)) << 22;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 12;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff) << 2;
         value |= ((uint32_t)CLAMP(src[3], 0, 3)) & 0x3;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[3], 0, 3)) & 0x3;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff) << 2;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 12;
         value |= (uint32_t)((uint32_t)CLAMP(src[0], 0, 1023)) << 22;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)MIN2(src[3], 3)) << 30;
         value |= (uint32_t)(((uint32_t)MIN2(src[0], 1023)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 10;
         value |= ((uint32_t)MIN2(src[2], 1023)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)MIN2(src[2], 1023)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)MIN2(src[0], 1023)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)MIN2(src[3], 3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_b10g10r10a2_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0, 3)) << 30;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
         value |= ((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0, 3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10a2_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10a2_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_b10g10r10a2_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)MIN2(src[3], 1)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[0], 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[1], 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)MIN2(src[2], 511)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)MIN2(src[2], 511)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[1], 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[0], 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)MIN2(src[3], 1)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g6b5_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g6b5_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[2], 31)) << 11;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 63)) & 0x3f) << 5;
         value |= ((uint16_t)MIN2(src[0], 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[0], 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 63)) & 0x3f) << 5;
         value |= (uint32_t)((uint16_t)MIN2(src[2], 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g6b5_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r5g6b5_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[2], 0, 31)) << 11;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 63)) & 0x3f) << 5;
         value |= ((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 63)) & 0x3f) << 5;
         value |= (uint32_t)((uint16_t)CLAMP(src[2], 0, 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g6r5_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g6r5_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 31)) << 11;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 63)) & 0x3f) << 5;
         value |= ((uint16_t)MIN2(src[2], 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[2], 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 63)) & 0x3f) << 5;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g6r5_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b5g6r5_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 31)) << 11;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 63)) & 0x3f) << 5;
         value |= ((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 63)) & 0x3f) << 5;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r3g3b2_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = value >> 6;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t r = (value) & 0x7;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0x7;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t b = value >> 6;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_r3g3b2_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[2], 3)) << 6;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 7)) & 0x7) << 3;
         value |= ((uint8_t)MIN2(src[0], 7)) & 0x7;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)MIN2(src[0], 7)) & 0x7;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 7)) & 0x7) << 3;
         value |= (uint32_t)((uint8_t)MIN2(src[2], 3)) << 6;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r3g3b2_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = value >> 6;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t r = (value) & 0x7;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = (value) & 0x7;
         uint8_t g = (value >> 3) & 0x7;
         uint8_t b = value >> 6;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r3g3b2_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[2], 0, 3)) << 6;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 7)) & 0x7) << 3;
         value |= ((uint8_t)CLAMP(src[0], 0, 7)) & 0x7;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0, 7)) & 0x7;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 7)) & 0x7) << 3;
         value |= (uint32_t)((uint8_t)CLAMP(src[2], 0, 3)) << 6;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b2g3r3_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 5;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t b = (value) & 0x3;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = (value) & 0x3;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t r = value >> 5;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 1;
      dst += 4;
   }
}

void
util_format_b2g3r3_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 7)) << 5;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 7)) & 0x7) << 2;
         value |= ((uint8_t)MIN2(src[2], 3)) & 0x3;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)MIN2(src[2], 3)) & 0x3;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 7)) & 0x7) << 2;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 7)) << 5;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b2g3r3_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = *(const uint8_t *)src;
         uint8_t r = value >> 5;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t b = (value) & 0x3;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint8_t value = *(const uint8_t *)src;
         uint8_t b = (value) & 0x3;
         uint8_t g = (value >> 2) & 0x7;
         uint8_t r = value >> 5;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b2g3r3_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint8_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 7)) << 5;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 7)) & 0x7) << 2;
         value |= ((uint8_t)CLAMP(src[2], 0, 3)) & 0x3;
         *(uint8_t *)dst = value;
#else
         uint8_t value = 0;
         value |= ((uint8_t)CLAMP(src[2], 0, 3)) & 0x3;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 7)) & 0x7) << 2;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 7)) << 5;
         *(uint8_t *)dst = value;
#endif
         src += 4;
         dst += 1;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4g4b4a4_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r4g4b4a4_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 15)) << 12;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 4;
         value |= ((uint16_t)MIN2(src[0], 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[0], 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r4g4b4a4_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_r4g4b4a4_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 15)) << 12;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 4;
         value |= ((uint16_t)CLAMP(src[0], 0, 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0, 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b4g4r4a4_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b4g4r4a4_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 15)) << 12;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 4;
         value |= ((uint16_t)MIN2(src[2], 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[2], 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b4g4r4a4_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 12;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t b = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0xf;
         uint16_t g = (value >> 4) & 0xf;
         uint16_t r = (value >> 8) & 0xf;
         uint16_t a = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_b4g4r4a4_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 15)) << 12;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 4;
         value |= ((uint16_t)CLAMP(src[2], 0, 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[2], 0, 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4r4g4b4_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a4r4g4b4_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[2], 15)) << 12;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 15)) & 0xf) << 4;
         value |= ((uint16_t)MIN2(src[3], 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[3], 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)MIN2(src[2], 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4r4g4b4_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t r = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a4r4g4b4_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[2], 0, 15)) << 12;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 15)) & 0xf) << 4;
         value |= ((uint16_t)CLAMP(src[3], 0, 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[3], 0, 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)CLAMP(src[2], 0, 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4b4g4r4_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a4b4g4r4_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 15)) << 12;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 15)) & 0xf) << 4;
         value |= ((uint16_t)MIN2(src[3], 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[3], 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a4b4g4r4_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 12;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t a = (value) & 0xf;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0xf;
         uint16_t b = (value >> 4) & 0xf;
         uint16_t g = (value >> 8) & 0xf;
         uint16_t r = value >> 12;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a4b4g4r4_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 15)) << 12;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 15)) & 0xf) << 4;
         value |= ((uint16_t)CLAMP(src[3], 0, 15)) & 0xf;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[3], 0, 15)) & 0xf;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 15)) & 0xf) << 4;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 15)) & 0xf) << 8;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 15)) << 12;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1r5g5b5_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a1r5g5b5_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[2], 31)) << 11;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 31)) & 0x1f) << 1;
         value |= ((uint16_t)MIN2(src[3], 1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[3], 1)) & 0x1;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 31)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)MIN2(src[2], 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1r5g5b5_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t r = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a1r5g5b5_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[2], 0, 31)) << 11;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f) << 1;
         value |= ((uint16_t)CLAMP(src[3], 0, 1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[3], 0, 1)) & 0x1;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)CLAMP(src[2], 0, 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1b5g5r5_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_a1b5g5r5_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 31)) << 11;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 31)) & 0x1f) << 1;
         value |= ((uint16_t)MIN2(src[3], 1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[3], 1)) & 0x1;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 31)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a1b5g5r5_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t a = (value) & 0x1;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = (value) & 0x1;
         uint16_t b = (value >> 1) & 0x1f;
         uint16_t g = (value >> 6) & 0x1f;
         uint16_t r = value >> 11;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_a1b5g5r5_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 31)) << 11;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 6;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f) << 1;
         value |= ((uint16_t)CLAMP(src[3], 0, 1)) & 0x1;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[3], 0, 1)) & 0x1;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f) << 1;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 6;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 31)) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g5b5a1_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g5b5a1_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 1)) << 15;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 31)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 5;
         value |= ((uint16_t)MIN2(src[0], 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[0], 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)MIN2(src[2], 31)) & 0x1f) << 10;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g5b5a1_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_r5g5b5a1_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 1)) << 15;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 5;
         value |= ((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f) << 10;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g5r5a1_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g5r5a1_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 1)) << 15;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 31)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 5;
         value |= ((uint16_t)MIN2(src[2], 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)MIN2(src[2], 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)MIN2(src[1], 31)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)MIN2(src[0], 31)) & 0x1f) << 10;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g5r5a1_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t a = value >> 15;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t b = (value) & 0x1f;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x1f;
         uint16_t r = (value >> 10) & 0x1f;
         uint16_t a = value >> 15;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_b5g5r5a1_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 1)) << 15;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f) << 10;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 5;
         value |= ((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint16_t)CLAMP(src[2], 0, 31)) & 0x1f;
         value |= (uint32_t)(((uint16_t)CLAMP(src[1], 0, 31)) & 0x1f) << 5;
         value |= (uint32_t)(((uint16_t)CLAMP(src[0], 0, 31)) & 0x1f) << 10;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 1)) << 15;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8x8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 24) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0])) << 24;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[2])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8x8_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = util_format_srgb_to_linear_8unorm(r); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0])) << 24;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 16;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[0])) & 0xff;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1])) & 0xff) << 8;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[2])) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 255)) << 24;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)MIN2(src[2], 255)) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)MIN2(src[0], 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)MIN2(src[1], 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)MIN2(src[2], 255)) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 24;
         uint32_t g = (value >> 16) & 0xff;
         uint32_t b = (value >> 8) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xff;
         uint32_t g = (value >> 8) & 0xff;
         uint32_t b = (value >> 16) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8x8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 255)) << 24;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 16;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0, 255)) & 0xff) << 8;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0, 255)) & 0xff;
         value |= (uint32_t)(((uint8_t)CLAMP(src[1], 0, 255)) & 0xff) << 8;
         value |= (uint32_t)(((uint8_t)CLAMP(src[2], 0, 255)) & 0xff) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r8g8b8x8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8g8b8x8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r8g8b8x8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 8) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10x2_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10x2_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= ((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10x2_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         dst[0] = (float)(r * (1.0f/0x3ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x3ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x3ff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b10g10r10x2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value) & 0x3ff;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t b = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value >> 20) & 0x3ff;
         dst[0] = _mesa_unorm_to_unorm(r, 10, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 10, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(b, 10, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10x2_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff) << 20;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[2], 8, 10)) & 0x3ff;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[1], 8, 10)) & 0x3ff) << 10;
         value |= (uint32_t)((_mesa_unorm_to_unorm(src[0], 8, 10)) & 0x3ff) << 20;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10x2_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10x2_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x1ff)) & 0x3ff) << 20) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b10g10r10x2_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         dst[0] = (float)(r * (1.0f/0x1ff)); /* r */
         dst[1] = (float)(g * (1.0f/0x1ff)); /* g */
         dst[2] = (float)(b * (1.0f/0x1ff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b10g10r10x2_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 2) ) >> 22;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 10, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 10, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 10, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_b10g10r10x2_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 10)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 10)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 10)) & 0x3ff) << 20) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16x16_unorm {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t x;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t x;
#endif
};

void
util_format_r16g16b16x16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_unorm pixel = {0};
         pixel.r = (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         pixel.g = (uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff);
         pixel.b = (uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xffff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_unorm pixel = {0};
         pixel.r = (uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff);
         pixel.g = (uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff);
         pixel.b = (uint16_t)util_iround(CLAMP(src[2], 0.0f, 1.0f) * 0xffff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16x16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0xffff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0xffff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16x16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 16, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16x16_unorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_unorm_to_unorm(pixel.r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(pixel.g, 16, 8); /* g */
         dst[2] = _mesa_unorm_to_unorm(pixel.b, 16, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_unorm pixel = {0};
         pixel.r = _mesa_unorm_to_unorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_unorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_unorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16x16_snorm {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
   uint16_t x;
#else
   int16_t r;
   int16_t g;
   int16_t b;
   uint16_t x;
#endif
};

void
util_format_r16g16b16x16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_snorm pixel = {0};
         pixel.r = (int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff);
         pixel.g = (int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff);
         pixel.b = (int16_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7fff);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_snorm pixel = {0};
         pixel.r = (int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff);
         pixel.g = (int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff);
         pixel.b = (int16_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7fff);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16x16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (float)(pixel.r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(pixel.g * (1.0f/0x7fff)); /* g */
         dst[2] = (float)(pixel.b * (1.0f/0x7fff)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16x16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 16, 8); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16x16_snorm pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_snorm_to_unorm(MAX2(pixel.r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(pixel.g, 0), 16, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(pixel.b, 0), 16, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_snorm pixel = {0};
         pixel.r = _mesa_unorm_to_snorm(src[0], 8, 16);
         pixel.g = _mesa_unorm_to_snorm(src[1], 8, 16);
         pixel.b = _mesa_unorm_to_snorm(src[2], 8, 16);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16x16_float {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t x;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t x;
#endif
};

void
util_format_r16g16b16x16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         pixel.b = _mesa_float_to_float16_rtz(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.g = _mesa_float_to_float16_rtz(src[1]);
         pixel.b = _mesa_float_to_float16_rtz(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16x16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = _mesa_half_to_float(pixel.g); /* g */
         dst[2] = _mesa_half_to_float(pixel.b); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16x16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.b)); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r16g16b16x16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = float_to_ubyte(_mesa_half_to_float(pixel.g)); /* g */
         dst[2] = float_to_ubyte(_mesa_half_to_float(pixel.b)); /* b */
         dst[3] = 255; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         pixel.b = _mesa_float_to_float16_rtz((float)(src[2] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.g = _mesa_float_to_float16_rtz((float)(src[1] * (1.0f/0xff)));
         pixel.b = _mesa_float_to_float16_rtz((float)(src[2] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16x16_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t x;
#else
   uint16_t r;
   uint16_t g;
   uint16_t b;
   uint16_t x;
#endif
};

void
util_format_r16g16b16x16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_uint pixel = {0};
         pixel.r = (uint16_t)MIN2(src[0], 65535);
         pixel.g = (uint16_t)MIN2(src[1], 65535);
         pixel.b = (uint16_t)MIN2(src[2], 65535);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_uint pixel = {0};
         pixel.r = (uint16_t)MIN2(src[0], 65535);
         pixel.g = (uint16_t)MIN2(src[1], 65535);
         pixel.b = (uint16_t)MIN2(src[2], 65535);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16x16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (unsigned)pixel.r; /* r */
         dst[1] = (unsigned)pixel.g; /* g */
         dst[2] = (unsigned)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16x16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_uint pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0, 65535);
         pixel.g = (uint16_t)CLAMP(src[1], 0, 65535);
         pixel.b = (uint16_t)CLAMP(src[2], 0, 65535);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_uint pixel = {0};
         pixel.r = (uint16_t)CLAMP(src[0], 0, 65535);
         pixel.g = (uint16_t)CLAMP(src[1], 0, 65535);
         pixel.b = (uint16_t)CLAMP(src[2], 0, 65535);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16g16b16x16_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int16_t r;
   int16_t g;
   int16_t b;
   uint16_t x;
#else
   int16_t r;
   int16_t g;
   int16_t b;
   uint16_t x;
#endif
};

void
util_format_r16g16b16x16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r16g16b16x16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_sint pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768, 32767);
         pixel.g = (int16_t)CLAMP(src[1], -32768, 32767);
         pixel.b = (int16_t)CLAMP(src[2], -32768, 32767);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_sint pixel = {0};
         pixel.r = (int16_t)CLAMP(src[0], -32768, 32767);
         pixel.g = (int16_t)CLAMP(src[1], -32768, 32767);
         pixel.b = (int16_t)CLAMP(src[2], -32768, 32767);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16g16b16x16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r16g16b16x16_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = (int)pixel.r; /* r */
         dst[1] = (int)pixel.g; /* g */
         dst[2] = (int)pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r16g16b16x16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16g16b16x16_sint pixel = {0};
         pixel.r = (int16_t)MIN2(src[0], 32767);
         pixel.g = (int16_t)MIN2(src[1], 32767);
         pixel.b = (int16_t)MIN2(src[2], 32767);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16g16b16x16_sint pixel = {0};
         pixel.r = (int16_t)MIN2(src[0], 32767);
         pixel.g = (int16_t)MIN2(src[1], 32767);
         pixel.b = (int16_t)MIN2(src[2], 32767);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32x32_float {
#if UTIL_ARCH_BIG_ENDIAN
   float r;
   float g;
   float b;
   uint32_t x;
#else
   float r;
   float g;
   float b;
   uint32_t x;
#endif
};

void
util_format_r32g32b32x32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32x32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32x32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32x32_float pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32x32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32x32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32x32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = float_to_ubyte(pixel.b); /* b */
         dst[3] = 255; /* a */
#else
         struct util_format_r32g32b32x32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = float_to_ubyte(pixel.g); /* g */
         dst[2] = float_to_ubyte(pixel.b); /* b */
         dst[3] = 255; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32x32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         pixel.b = ubyte_to_float(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32x32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.g = ubyte_to_float(src[1]);
         pixel.b = ubyte_to_float(src[2]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32x32_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t x;
#else
   uint32_t r;
   uint32_t g;
   uint32_t b;
   uint32_t x;
#endif
};

void
util_format_r32g32b32x32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32x32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32x32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32x32_uint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32x32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32x32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32x32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         pixel.b = (uint32_t)MAX2(src[2], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32x32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.g = (uint32_t)MAX2(src[1], 0);
         pixel.b = (uint32_t)MAX2(src[2], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32g32b32x32_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t g;
   int32_t b;
   uint32_t x;
#else
   int32_t r;
   int32_t g;
   int32_t b;
   uint32_t x;
#endif
};

void
util_format_r32g32b32x32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32x32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 16;
      dst += 4;
   }
}

void
util_format_r32g32b32x32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32x32_sint pixel = {0};
         pixel.r = src[0];
         pixel.g = src[1];
         pixel.b = src[2];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32g32b32x32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#else
         struct util_format_r32g32b32x32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = pixel.g; /* g */
         dst[2] = pixel.b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r32g32b32x32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32g32b32x32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         pixel.b = (int32_t)MIN2(src[2], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32g32b32x32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.g = (int32_t)MIN2(src[1], 2147483647);
         pixel.b = (int32_t)MIN2(src[2], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 16;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8a8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 8) ;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
}

void
util_format_r8a8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8a8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 8) ;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[3], 8, 8)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) << 16;
         value |= ((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[3], 0.0f, 1.0f) * 0xffff)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0xffff)); /* a */
#endif
}

void
util_format_r16a16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 16, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_unorm_to_unorm(a, 16, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 16)) << 16;
         value |= (_mesa_unorm_to_unorm(src[3], 8, 16)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 16)) & 0xffff;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[3], 8, 16)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (float)(a * (1.0f/0x7fff)); /* a */
#endif
}

void
util_format_r16a16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 16, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 16, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) << 16) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[3], 8, 16)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 16)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 16)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r16a16_float {
#if UTIL_ARCH_BIG_ENDIAN
   uint16_t r;
   uint16_t a;
#else
   uint16_t r;
   uint16_t a;
#endif
};

void
util_format_r16a16_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#else
         struct util_format_r16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz(src[0]);
         pixel.a = _mesa_float_to_float16_rtz(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#else
         struct util_format_r16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = _mesa_half_to_float(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = _mesa_half_to_float(pixel.a); /* a */
#endif
}

void
util_format_r16a16_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
#else
         struct util_format_r16a16_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(_mesa_half_to_float(pixel.r)); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = float_to_ubyte(_mesa_half_to_float(pixel.a)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r16a16_float pixel = {0};
         pixel.r = _mesa_float_to_float16_rtz((float)(src[0] * (1.0f/0xff)));
         pixel.a = _mesa_float_to_float16_rtz((float)(src[3] * (1.0f/0xff)));
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32a32_float {
#if UTIL_ARCH_BIG_ENDIAN
   float r;
   float a;
#else
   float r;
   float a;
#endif
};

void
util_format_r32a32_float_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32a32_float_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_float pixel = {0};
         pixel.r = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32a32_float pixel = {0};
         pixel.r = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32a32_float_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_r32a32_float_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
#else
         struct util_format_r32a32_float pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = float_to_ubyte(pixel.r); /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = float_to_ubyte(pixel.a); /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32a32_float_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32a32_float pixel = {0};
         pixel.r = ubyte_to_float(src[0]);
         pixel.a = ubyte_to_float(src[3]);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8a8_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)MIN2(src[0], 255)) << 8;
         value |= ((uint8_t)MIN2(src[3], 255)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)MIN2(src[0], 255)) & 0xff;
         value |= (uint32_t)((uint8_t)MIN2(src[3], 255)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 8;
         uint16_t a = (value) & 0xff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0xff;
         uint16_t a = value >> 8;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_r8a8_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)((uint8_t)CLAMP(src[0], 0, 255)) << 8;
         value |= ((uint8_t)CLAMP(src[3], 0, 255)) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= ((uint8_t)CLAMP(src[0], 0, 255)) & 0xff;
         value |= (uint32_t)((uint8_t)CLAMP(src[3], 0, 255)) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r8a8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 8) ;
         value |= (uint16_t)(((int8_t)CLAMP(src[3], -128, 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[3], -128, 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r8a8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value) ) >> 8;
         int16_t a = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         int16_t a = ((int16_t)(value) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_r8a8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 8) ;
         value |= (uint16_t)(((int8_t)MIN2(src[3], 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[3], 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)MIN2(src[0], 65535)) << 16;
         value |= ((uint16_t)MIN2(src[3], 65535)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)MIN2(src[0], 65535)) & 0xffff;
         value |= (uint32_t)((uint16_t)MIN2(src[3], 65535)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = value >> 16;
         uint32_t a = (value) & 0xffff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0xffff;
         uint32_t a = value >> 16;
         dst[0] = (unsigned)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_r16a16_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)CLAMP(src[0], 0, 65535)) << 16;
         value |= ((uint16_t)CLAMP(src[3], 0, 65535)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)CLAMP(src[0], 0, 65535)) & 0xffff;
         value |= (uint32_t)((uint16_t)CLAMP(src[3], 0, 65535)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r16a16_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[0], -32768, 32767)) << 16) ;
         value |= (uint32_t)(((int16_t)CLAMP(src[3], -32768, 32767)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)CLAMP(src[0], -32768, 32767)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)CLAMP(src[3], -32768, 32767)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r16a16_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value) ) >> 16;
         int32_t a = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         int32_t a = ((int32_t)(value) ) >> 16;
         dst[0] = (int)r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_r16a16_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)MIN2(src[0], 32767)) << 16) ;
         value |= (uint32_t)(((int16_t)MIN2(src[3], 32767)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)MIN2(src[0], 32767)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)MIN2(src[3], 32767)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32a32_uint {
#if UTIL_ARCH_BIG_ENDIAN
   uint32_t r;
   uint32_t a;
#else
   uint32_t r;
   uint32_t a;
#endif
};

void
util_format_r32a32_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32a32_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_uint pixel = {0};
         pixel.r = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32a32_uint pixel = {0};
         pixel.r = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32a32_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32a32_uint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_r32a32_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.a = (uint32_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32a32_uint pixel = {0};
         pixel.r = (uint32_t)MAX2(src[0], 0);
         pixel.a = (uint32_t)MAX2(src[3], 0);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

struct util_format_r32a32_sint {
#if UTIL_ARCH_BIG_ENDIAN
   int32_t r;
   int32_t a;
#else
   int32_t r;
   int32_t a;
#endif
};

void
util_format_r32a32_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#endif
      src += 8;
      dst += 4;
   }
}

void
util_format_r32a32_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_sint pixel = {0};
         pixel.r = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32a32_sint pixel = {0};
         pixel.r = src[0];
         pixel.a = src[3];
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r32a32_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#else
         struct util_format_r32a32_sint pixel;
         memcpy(&pixel, src, sizeof pixel);
         dst[0] = pixel.r; /* r */
         dst[1] = 0; /* g */
         dst[2] = 0; /* b */
         dst[3] = pixel.a; /* a */
#endif
}

void
util_format_r32a32_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         struct util_format_r32a32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.a = (int32_t)MIN2(src[3], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#else
         struct util_format_r32a32_sint pixel = {0};
         pixel.r = (int32_t)MIN2(src[0], 2147483647);
         pixel.a = (int32_t)MIN2(src[3], 2147483647);
         memcpy(dst, &pixel, sizeof pixel);
#endif
         src += 4;
         dst += 8;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_uint_unpack_unsigned(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   unsigned *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_uint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)MIN2(src[3], 3)) << 30;
         value |= (uint32_t)(((uint32_t)MIN2(src[2], 1023)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 10;
         value |= ((uint32_t)MIN2(src[0], 1023)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)MIN2(src[0], 1023)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)MIN2(src[1], 1023)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)MIN2(src[2], 1023)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)MIN2(src[3], 3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_uint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   unsigned *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t a = value >> 30;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t r = (value) & 0x3ff;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t r = (value) & 0x3ff;
         uint32_t g = (value >> 10) & 0x3ff;
         uint32_t b = (value >> 20) & 0x3ff;
         uint32_t a = value >> 30;
         dst[0] = (unsigned)r; /* r */
         dst[1] = (unsigned)g; /* g */
         dst[2] = (unsigned)b; /* b */
         dst[3] = (unsigned)a; /* a */
#endif
}

void
util_format_r10g10b10a2_uint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0, 3)) << 30;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff) << 20;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
         value |= ((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff;
         value |= (uint32_t)(((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
         value |= (uint32_t)(((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff) << 20;
         value |= (uint32_t)((uint32_t)CLAMP(src[3], 0, 3)) << 30;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_r10g10b10a2_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r10g10b10a2_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 30;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t r = ((int32_t)(value << 22) ) >> 22;
         int32_t g = ((int32_t)(value << 12) ) >> 22;
         int32_t b = ((int32_t)(value << 2) ) >> 22;
         int32_t a = ((int32_t)(value) ) >> 30;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_r10g10b10a2_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((uint32_t)MIN2(src[3], 1)) << 30) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[2], 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[1], 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)(((uint32_t)MIN2(src[0], 511)) & 0x3ff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((uint32_t)MIN2(src[0], 511)) & 0x3ff) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[1], 511)) & 0x3ff) << 10) ;
         value |= (uint32_t)((uint32_t)(((uint32_t)MIN2(src[2], 511)) & 0x3ff) << 20) ;
         value |= (uint32_t)((uint32_t)((uint32_t)MIN2(src[3], 1)) << 30) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g6r5_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g6r5_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0]) >> 3) << 11;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (util_format_linear_float_to_srgb_8unorm(src[2]) >> 3) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[2]) >> 3) & 0x1f;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[0]) >> 3) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_b5g6r5_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_b5g6r5_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = (value) & 0x1f;
         dst[0] = util_format_srgb_to_linear_8unorm(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b << 3 | b >> 2); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = value >> 11;
         dst[0] = util_format_srgb_to_linear_8unorm(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b << 3 | b >> 2); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_b5g6r5_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0]) >> 3) << 11;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (util_format_linear_to_srgb_8unorm(src[2]) >> 3) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[2]) >> 3) & 0x1f;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[0]) >> 3) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g6b5_srgb_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g6b5_srgb_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[2]) >> 3) << 11;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0]) >> 3) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_float_to_srgb_8unorm(src[0]) >> 3) & 0x1f;
         value |= (uint32_t)((util_format_linear_float_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (uint32_t)(util_format_linear_float_to_srgb_8unorm(src[2]) >> 3) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_r5g6b5_srgb_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = util_format_srgb_8unorm_to_linear_float(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_8unorm_to_linear_float(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_8unorm_to_linear_float(b << 3 | b >> 2); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_r5g6b5_srgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t b = value >> 11;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t r = (value) & 0x1f;
         dst[0] = util_format_srgb_to_linear_8unorm(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b << 3 | b >> 2); /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t r = (value) & 0x1f;
         uint16_t g = (value >> 5) & 0x3f;
         uint16_t b = value >> 11;
         dst[0] = util_format_srgb_to_linear_8unorm(r << 3 | r >> 2); /* r */
         dst[1] = util_format_srgb_to_linear_8unorm(g << 2 | g >> 4); /* g */
         dst[2] = util_format_srgb_to_linear_8unorm(b << 3 | b >> 2); /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_r5g6b5_srgb_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[2]) >> 3) << 11;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (util_format_linear_to_srgb_8unorm(src[0]) >> 3) & 0x1f;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (util_format_linear_to_srgb_8unorm(src[0]) >> 3) & 0x1f;
         value |= (uint32_t)((util_format_linear_to_srgb_8unorm(src[1]) >> 2) & 0x3f) << 5;
         value |= (uint32_t)(util_format_linear_to_srgb_8unorm(src[2]) >> 3) << 11;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g8r8_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t g = value >> 8;
         uint16_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t g = (value) & 0xff;
         uint16_t r = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_g8r8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(float_to_ubyte(src[1])) << 8;
         value |= (float_to_ubyte(src[0])) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (float_to_ubyte(src[1])) & 0xff;
         value |= (uint32_t)(float_to_ubyte(src[0])) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g8r8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t g = value >> 8;
         uint16_t r = (value) & 0xff;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t g = (value) & 0xff;
         uint16_t r = value >> 8;
         dst[0] = ubyte_to_float(r); /* r */
         dst[1] = ubyte_to_float(g); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_g8r8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         uint16_t g = value >> 8;
         uint16_t r = (value) & 0xff;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         uint16_t g = (value) & 0xff;
         uint16_t r = value >> 8;
         dst[0] = r; /* r */
         dst[1] = g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_g8r8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint32_t)(src[1]) << 8;
         value |= (src[0]) & 0xff;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (src[1]) & 0xff;
         value |= (uint32_t)(src[0]) << 8;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g8r8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value) ) >> 8;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         int16_t r = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_g8r8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) << 8) ;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g8r8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value) ) >> 8;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         int16_t r = ((int16_t)(value) ) >> 8;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_g8r8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value) ) >> 8;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         int16_t r = ((int16_t)(value) ) >> 8;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_g8r8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[1], 8, 8)) << 8) ;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) ;
         value |= (uint16_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g8r8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value) ) >> 8;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         int16_t r = ((int16_t)(value) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 2;
      dst += 4;
   }
}

void
util_format_g8r8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[1], -128, 127)) << 8) ;
         value |= (uint16_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g8r8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value) ) >> 8;
         int16_t r = ((int16_t)(value << 8) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint16_t value = *(const uint16_t *)src;
         int16_t g = ((int16_t)(value << 8) ) >> 8;
         int16_t r = ((int16_t)(value) ) >> 8;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_g8r8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint16_t value = 0;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[1], 127)) << 8) ;
         value |= (uint16_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         *(uint16_t *)dst = value;
#else
         uint16_t value = 0;
         value |= (uint16_t)(((int8_t)MIN2(src[1], 127)) & 0xff) ;
         value |= (uint16_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 8) ;
         *(uint16_t *)dst = value;
#endif
         src += 4;
         dst += 2;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g16r16_unorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t g = value >> 16;
         uint32_t r = (value) & 0xffff;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t g = (value) & 0xffff;
         uint32_t r = value >> 16;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_g16r16_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff)) << 16;
         value |= ((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= ((uint16_t)util_iround(CLAMP(src[1], 0.0f, 1.0f) * 0xffff)) & 0xffff;
         value |= (uint32_t)((uint16_t)util_iround(CLAMP(src[0], 0.0f, 1.0f) * 0xffff)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g16r16_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t g = value >> 16;
         uint32_t r = (value) & 0xffff;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t g = (value) & 0xffff;
         uint32_t r = value >> 16;
         dst[0] = (float)(r * (1.0f/0xffff)); /* r */
         dst[1] = (float)(g * (1.0f/0xffff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_g16r16_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         uint32_t g = value >> 16;
         uint32_t r = (value) & 0xffff;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         uint32_t g = (value) & 0xffff;
         uint32_t r = value >> 16;
         dst[0] = _mesa_unorm_to_unorm(r, 16, 8); /* r */
         dst[1] = _mesa_unorm_to_unorm(g, 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_g16r16_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[1], 8, 16)) << 16;
         value |= (_mesa_unorm_to_unorm(src[0], 8, 16)) & 0xffff;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (_mesa_unorm_to_unorm(src[1], 8, 16)) & 0xffff;
         value |= (uint32_t)(_mesa_unorm_to_unorm(src[0], 8, 16)) << 16;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g16r16_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t g = ((int32_t)(value) ) >> 16;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         int32_t r = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_g16r16_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int16_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7fff)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)((int16_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7fff)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_g16r16_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t g = ((int32_t)(value) ) >> 16;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         int32_t r = ((int32_t)(value) ) >> 16;
         dst[0] = (float)(r * (1.0f/0x7fff)); /* r */
         dst[1] = (float)(g * (1.0f/0x7fff)); /* g */
         dst[2] = 0; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_g16r16_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t g = ((int32_t)(value) ) >> 16;
         int32_t r = ((int32_t)(value << 16) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t g = ((int32_t)(value << 16) ) >> 16;
         int32_t r = ((int32_t)(value) ) >> 16;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 16, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 16, 8); /* g */
         dst[2] = 0; /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_g16r16_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[1], 8, 16)) << 16) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 16)) & 0xffff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 16)) & 0xffff) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 16)) << 16) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[3], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = (float)(a * (1.0f/0x7f)); /* a */
#endif
}

void
util_format_a8b8g8r8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = _mesa_snorm_to_unorm(MAX2(a, 0), 8, 8); /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[3], 8, 8)) << 24) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[3], 8, 8)) & 0xff) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_a8b8g8r8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[3], -128, 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)CLAMP(src[3], -128, 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_a8b8g8r8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value) ) >> 24;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t a = ((int32_t)(value << 24) ) >> 24;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = (int)a; /* a */
#endif
}

void
util_format_a8b8g8r8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[3], 127)) << 24) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)(((int8_t)MIN2(src[3], 127)) & 0xff) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_snorm_unpack_rgba_float(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   float *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_snorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const float *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[2], -1.0f, 1.0f) * 0x7f)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)util_iround(CLAMP(src[1], -1.0f, 1.0f) * 0x7f)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)util_iround(CLAMP(src[0], -1.0f, 1.0f) * 0x7f)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_snorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   float *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (float)(r * (1.0f/0x7f)); /* r */
         dst[1] = (float)(g * (1.0f/0x7f)); /* g */
         dst[2] = (float)(b * (1.0f/0x7f)); /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8b8g8r8_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   uint8_t *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = _mesa_snorm_to_unorm(MAX2(r, 0), 8, 8); /* r */
         dst[1] = _mesa_snorm_to_unorm(MAX2(g, 0), 8, 8); /* g */
         dst[2] = _mesa_snorm_to_unorm(MAX2(b, 0), 8, 8); /* b */
         dst[3] = 255; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const uint8_t *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((_mesa_unorm_to_snorm(src[0], 8, 8)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[2], 8, 8)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)((_mesa_unorm_to_snorm(src[1], 8, 8)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(_mesa_unorm_to_snorm(src[0], 8, 8)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_sint_unpack_signed(void *restrict dst_row, const uint8_t *restrict src, unsigned width)
{
   int *dst = dst_row;
   for (unsigned x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
      src += 4;
      dst += 4;
   }
}

void
util_format_x8b8g8r8_sint_pack_signed(uint8_t *restrict dst_row, unsigned dst_stride, const int *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const int *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)CLAMP(src[0], -128, 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[2], -128, 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)CLAMP(src[1], -128, 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)CLAMP(src[0], -128, 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

void
util_format_x8b8g8r8_sint_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src, UNUSED unsigned i, UNUSED unsigned j)
{
   int *dst = in_dst;
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 8) ) >> 24;
         int32_t g = ((int32_t)(value << 16) ) >> 24;
         int32_t r = ((int32_t)(value << 24) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#else
         uint32_t value = *(const uint32_t *)src;
         int32_t b = ((int32_t)(value << 16) ) >> 24;
         int32_t g = ((int32_t)(value << 8) ) >> 24;
         int32_t r = ((int32_t)(value) ) >> 24;
         dst[0] = (int)r; /* r */
         dst[1] = (int)g; /* g */
         dst[2] = (int)b; /* b */
         dst[3] = 1; /* a */
#endif
}

void
util_format_x8b8g8r8_sint_pack_unsigned(uint8_t *restrict dst_row, unsigned dst_stride, const unsigned *restrict src_row, unsigned src_stride, unsigned width, unsigned height)
{
   unsigned x, y;
   for(y = 0; y < height; y += 1) {
      const unsigned *src = src_row;
      uint8_t *dst = dst_row;
      for(x = 0; x < width; x += 1) {
#if UTIL_ARCH_BIG_ENDIAN
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 8) ;
         value |= (uint32_t)(((int8_t)MIN2(src[0], 127)) & 0xff) ;
         *(uint32_t *)dst = value;
#else
         uint32_t value = 0;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[2], 127)) & 0xff) << 8) ;
         value |= (uint32_t)((uint32_t)(((int8_t)MIN2(src[1], 127)) & 0xff) << 16) ;
         value |= (uint32_t)((uint32_t)((int8_t)MIN2(src[0], 127)) << 24) ;
         *(uint32_t *)dst = value;
#endif
         src += 4;
         dst += 4;
      }
      dst_row += dst_stride;
      src_row += src_stride/sizeof(*src_row);
   }
}

static const struct util_format_description
util_format_descriptions[] = {
   [PIPE_FORMAT_NONE] = {
      PIPE_FORMAT_NONE,
      "PIPE_FORMAT_NONE",
      "none",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8A8_UNORM] = {
      PIPE_FORMAT_B8G8R8A8_UNORM,
      "PIPE_FORMAT_B8G8R8A8_UNORM",
      "b8g8r8a8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8X8_UNORM] = {
      PIPE_FORMAT_B8G8R8X8_UNORM,
      "PIPE_FORMAT_B8G8R8X8_UNORM",
      "b8g8r8x8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8X8_SNORM] = {
      PIPE_FORMAT_B8G8R8X8_SNORM,
      "PIPE_FORMAT_B8G8R8X8_SNORM",
      "b8g8r8x8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8X8_UINT] = {
      PIPE_FORMAT_B8G8R8X8_UINT,
      "PIPE_FORMAT_B8G8R8X8_UINT",
      "b8g8r8x8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8X8_SINT] = {
      PIPE_FORMAT_B8G8R8X8_SINT,
      "PIPE_FORMAT_B8G8R8X8_SINT",
      "b8g8r8x8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8R8G8B8_UNORM] = {
      PIPE_FORMAT_A8R8G8B8_UNORM,
      "PIPE_FORMAT_A8R8G8B8_UNORM",
      "a8r8g8b8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8R8G8B8_SNORM] = {
      PIPE_FORMAT_A8R8G8B8_SNORM,
      "PIPE_FORMAT_A8R8G8B8_SNORM",
      "a8r8g8b8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8R8G8B8_SINT] = {
      PIPE_FORMAT_A8R8G8B8_SINT,
      "PIPE_FORMAT_A8R8G8B8_SINT",
      "a8r8g8b8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X8R8G8B8_UNORM] = {
      PIPE_FORMAT_X8R8G8B8_UNORM,
      "PIPE_FORMAT_X8R8G8B8_UNORM",
      "x8r8g8b8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X8R8G8B8_SNORM] = {
      PIPE_FORMAT_X8R8G8B8_SNORM,
      "PIPE_FORMAT_X8R8G8B8_SNORM",
      "x8r8g8b8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X8R8G8B8_SINT] = {
      PIPE_FORMAT_X8R8G8B8_SINT,
      "PIPE_FORMAT_X8R8G8B8_SINT",
      "x8r8g8b8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8B8G8R8_UNORM] = {
      PIPE_FORMAT_A8B8G8R8_UNORM,
      "PIPE_FORMAT_A8B8G8R8_UNORM",
      "a8b8g8r8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X8B8G8R8_UNORM] = {
      PIPE_FORMAT_X8B8G8R8_UNORM,
      "PIPE_FORMAT_X8B8G8R8_UNORM",
      "x8b8g8r8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8X8_UNORM] = {
      PIPE_FORMAT_R8G8B8X8_UNORM,
      "PIPE_FORMAT_R8G8B8X8_UNORM",
      "r8g8b8x8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R5G5B5A1_UNORM] = {
      PIPE_FORMAT_R5G5B5A1_UNORM,
      "PIPE_FORMAT_R5G5B5A1_UNORM",
      "r5g5b5a1_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 15},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 15}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R5G5B5X1_UNORM] = {
      PIPE_FORMAT_R5G5B5X1_UNORM,
      "PIPE_FORMAT_R5G5B5X1_UNORM",
      "r5g5b5x1_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 15},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 15}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B5G5R5X1_UNORM] = {
      PIPE_FORMAT_B5G5R5X1_UNORM,
      "PIPE_FORMAT_B5G5R5X1_UNORM",
      "b5g5r5x1_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 15},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 15}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B5G5R5A1_UNORM] = {
      PIPE_FORMAT_B5G5R5A1_UNORM,
      "PIPE_FORMAT_B5G5R5A1_UNORM",
      "b5g5r5a1_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 15},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 10},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 15}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X1B5G5R5_UNORM] = {
      PIPE_FORMAT_X1B5G5R5_UNORM,
      "PIPE_FORMAT_X1B5G5R5_UNORM",
      "x1b5g5r5_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A1R5G5B5_UNORM] = {
      PIPE_FORMAT_A1R5G5B5_UNORM,
      "PIPE_FORMAT_A1R5G5B5_UNORM",
      "a1r5g5b5_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X1R5G5B5_UNORM] = {
      PIPE_FORMAT_X1R5G5B5_UNORM,
      "PIPE_FORMAT_X1R5G5B5_UNORM",
      "x1r5g5b5_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 1, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A1B5G5R5_UNORM] = {
      PIPE_FORMAT_A1B5G5R5_UNORM,
      "PIPE_FORMAT_A1B5G5R5_UNORM",
      "a1b5g5r5_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 1, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 1},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 6},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R4G4B4A4_UNORM] = {
      PIPE_FORMAT_R4G4B4A4_UNORM,
      "PIPE_FORMAT_R4G4B4A4_UNORM",
      "r4g4b4a4_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R4G4B4X4_UNORM] = {
      PIPE_FORMAT_R4G4B4X4_UNORM,
      "PIPE_FORMAT_R4G4B4X4_UNORM",
      "r4g4b4x4_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 4, 12},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 4, 12}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B4G4R4A4_UNORM] = {
      PIPE_FORMAT_B4G4R4A4_UNORM,
      "PIPE_FORMAT_B4G4R4A4_UNORM",
      "b4g4r4a4_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B4G4R4X4_UNORM] = {
      PIPE_FORMAT_B4G4R4X4_UNORM,
      "PIPE_FORMAT_B4G4R4X4_UNORM",
      "b4g4r4x4_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 4, 12},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 4, 12}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A4R4G4B4_UNORM] = {
      PIPE_FORMAT_A4R4G4B4_UNORM,
      "PIPE_FORMAT_A4R4G4B4_UNORM",
      "a4r4g4b4_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A4B4G4R4_UNORM] = {
      PIPE_FORMAT_A4B4G4R4_UNORM,
      "PIPE_FORMAT_A4B4G4R4_UNORM",
      "a4b4g4r4_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 12}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R5G6B5_UNORM] = {
      PIPE_FORMAT_R5G6B5_UNORM,
      "PIPE_FORMAT_R5G6B5_UNORM",
      "r5g6b5_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B5G6R5_UNORM] = {
      PIPE_FORMAT_B5G6R5_UNORM,
      "PIPE_FORMAT_B5G6R5_UNORM",
      "b5g6r5_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10A2_UNORM] = {
      PIPE_FORMAT_R10G10B10A2_UNORM,
      "PIPE_FORMAT_R10G10B10A2_UNORM",
      "r10g10b10a2_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10X2_UNORM] = {
      PIPE_FORMAT_R10G10B10X2_UNORM,
      "PIPE_FORMAT_R10G10B10X2_UNORM",
      "r10g10b10x2_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10A2_UNORM] = {
      PIPE_FORMAT_B10G10R10A2_UNORM,
      "PIPE_FORMAT_B10G10R10A2_UNORM",
      "b10g10r10a2_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A2R10G10B10_UNORM] = {
      PIPE_FORMAT_A2R10G10B10_UNORM,
      "PIPE_FORMAT_A2R10G10B10_UNORM",
      "a2r10g10b10_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 22},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 12},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 2},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 2},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 12},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 22}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A2B10G10R10_UNORM] = {
      PIPE_FORMAT_A2B10G10R10_UNORM,
      "PIPE_FORMAT_A2B10G10R10_UNORM",
      "a2b10g10r10_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 22},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 12},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 2},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 2},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 12},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 22}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R3G3B2_UNORM] = {
      PIPE_FORMAT_R3G3B2_UNORM,
      "PIPE_FORMAT_R3G3B2_UNORM",
      "r3g3b2_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 6},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 3},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 3},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 6},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B2G3R3_UNORM] = {
      PIPE_FORMAT_B2G3R3_UNORM,
      "PIPE_FORMAT_B2G3R3_UNORM",
      "b2g3r3_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 5},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 2},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 2},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 3, 5},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8_UNORM] = {
      PIPE_FORMAT_L8_UNORM,
      "PIPE_FORMAT_L8_UNORM",
      "l8_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8_UNORM] = {
      PIPE_FORMAT_A8_UNORM,
      "PIPE_FORMAT_A8_UNORM",
      "a8_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I8_UNORM] = {
      PIPE_FORMAT_I8_UNORM,
      "PIPE_FORMAT_I8_UNORM",
      "i8_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L4A4_UNORM] = {
      PIPE_FORMAT_L4A4_UNORM,
      "PIPE_FORMAT_L4A4_UNORM",
      "l4a4_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* y = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8A8_UNORM] = {
      PIPE_FORMAT_L8A8_UNORM,
      "PIPE_FORMAT_L8A8_UNORM",
      "l8a8_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16_UNORM] = {
      PIPE_FORMAT_L16_UNORM,
      "PIPE_FORMAT_L16_UNORM",
      "l16_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A16_UNORM] = {
      PIPE_FORMAT_A16_UNORM,
      "PIPE_FORMAT_A16_UNORM",
      "a16_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I16_UNORM] = {
      PIPE_FORMAT_I16_UNORM,
      "PIPE_FORMAT_I16_UNORM",
      "i16_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16A16_UNORM] = {
      PIPE_FORMAT_L16A16_UNORM,
      "PIPE_FORMAT_L16A16_UNORM",
      "l16a16_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8_SNORM] = {
      PIPE_FORMAT_A8_SNORM,
      "PIPE_FORMAT_A8_SNORM",
      "a8_snorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8_SNORM] = {
      PIPE_FORMAT_L8_SNORM,
      "PIPE_FORMAT_L8_SNORM",
      "l8_snorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8A8_SNORM] = {
      PIPE_FORMAT_L8A8_SNORM,
      "PIPE_FORMAT_L8A8_SNORM",
      "l8a8_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I8_SNORM] = {
      PIPE_FORMAT_I8_SNORM,
      "PIPE_FORMAT_I8_SNORM",
      "i8_snorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A16_SNORM] = {
      PIPE_FORMAT_A16_SNORM,
      "PIPE_FORMAT_A16_SNORM",
      "a16_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16_SNORM] = {
      PIPE_FORMAT_L16_SNORM,
      "PIPE_FORMAT_L16_SNORM",
      "l16_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16A16_SNORM] = {
      PIPE_FORMAT_L16A16_SNORM,
      "PIPE_FORMAT_L16A16_SNORM",
      "l16a16_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I16_SNORM] = {
      PIPE_FORMAT_I16_SNORM,
      "PIPE_FORMAT_I16_SNORM",
      "i16_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A16_FLOAT] = {
      PIPE_FORMAT_A16_FLOAT,
      "PIPE_FORMAT_A16_FLOAT",
      "a16_float",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16_FLOAT] = {
      PIPE_FORMAT_L16_FLOAT,
      "PIPE_FORMAT_L16_FLOAT",
      "l16_float",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16A16_FLOAT] = {
      PIPE_FORMAT_L16A16_FLOAT,
      "PIPE_FORMAT_L16A16_FLOAT",
      "l16a16_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* x = rgb */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I16_FLOAT] = {
      PIPE_FORMAT_I16_FLOAT,
      "PIPE_FORMAT_I16_FLOAT",
      "i16_float",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A32_FLOAT] = {
      PIPE_FORMAT_A32_FLOAT,
      "PIPE_FORMAT_A32_FLOAT",
      "a32_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L32_FLOAT] = {
      PIPE_FORMAT_L32_FLOAT,
      "PIPE_FORMAT_L32_FLOAT",
      "l32_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L32A32_FLOAT] = {
      PIPE_FORMAT_L32A32_FLOAT,
      "PIPE_FORMAT_L32A32_FLOAT",
      "l32a32_float",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* x = rgb */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I32_FLOAT] = {
      PIPE_FORMAT_I32_FLOAT,
      "PIPE_FORMAT_I32_FLOAT",
      "i32_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8_SRGB] = {
      PIPE_FORMAT_L8_SRGB,
      "PIPE_FORMAT_L8_SRGB",
      "l8_srgb",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_X,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R8_SRGB] = {
      PIPE_FORMAT_R8_SRGB,
      "PIPE_FORMAT_R8_SRGB",
      "r8_srgb",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_0,	/* sg */
      PIPE_SWIZZLE_0,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_L8A8_SRGB] = {
      PIPE_FORMAT_L8A8_SRGB,
      "PIPE_FORMAT_L8A8_SRGB",
      "l8a8_srgb",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_X,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_X,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R8G8_SRGB] = {
      PIPE_FORMAT_R8G8_SRGB,
      "PIPE_FORMAT_R8G8_SRGB",
      "r8g8_srgb",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_0,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_0,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R8G8B8_SRGB] = {
      PIPE_FORMAT_R8G8B8_SRGB,
      "PIPE_FORMAT_R8G8B8_SRGB",
      "r8g8b8_srgb",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_B8G8R8_SRGB] = {
      PIPE_FORMAT_B8G8R8_SRGB,
      "PIPE_FORMAT_B8G8R8_SRGB",
      "b8g8r8_srgb",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R8G8B8A8_SRGB] = {
      PIPE_FORMAT_R8G8B8A8_SRGB,
      "PIPE_FORMAT_R8G8B8A8_SRGB",
      "r8g8b8a8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_A8B8G8R8_SRGB] = {
      PIPE_FORMAT_A8B8G8R8_SRGB,
      "PIPE_FORMAT_A8B8G8R8_SRGB",
      "a8b8g8r8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_Y,	/* sb */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_Y,	/* sb */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_X8B8G8R8_SRGB] = {
      PIPE_FORMAT_X8B8G8R8_SRGB,
      "PIPE_FORMAT_X8B8G8R8_SRGB",
      "x8b8g8r8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_Y,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_Y,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_B8G8R8A8_SRGB] = {
      PIPE_FORMAT_B8G8R8A8_SRGB,
      "PIPE_FORMAT_B8G8R8A8_SRGB",
      "b8g8r8a8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_B8G8R8X8_SRGB] = {
      PIPE_FORMAT_B8G8R8X8_SRGB,
      "PIPE_FORMAT_B8G8R8X8_SRGB",
      "b8g8r8x8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_A8R8G8B8_SRGB] = {
      PIPE_FORMAT_A8R8G8B8_SRGB,
      "PIPE_FORMAT_A8R8G8B8_SRGB",
      "a8r8g8b8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_W,	/* sb */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_W,	/* sb */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_X8R8G8B8_SRGB] = {
      PIPE_FORMAT_X8R8G8B8_SRGB,
      "PIPE_FORMAT_X8R8G8B8_SRGB",
      "x8r8g8b8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_W,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* sr */
      PIPE_SWIZZLE_Z,	/* sg */
      PIPE_SWIZZLE_W,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R8SG8SB8UX8U_NORM] = {
      PIPE_FORMAT_R8SG8SB8UX8U_NORM,
      "PIPE_FORMAT_R8SG8SB8UX8U_NORM",
      "r8sg8sb8ux8u_norm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10SG10SB10SA2U_NORM] = {
      PIPE_FORMAT_R10SG10SB10SA2U_NORM,
      "PIPE_FORMAT_R10SG10SB10SA2U_NORM",
      "r10sg10sb10sa2u_norm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R5SG5SB6U_NORM] = {
      PIPE_FORMAT_R5SG5SB6U_NORM,
      "PIPE_FORMAT_R5SG5SB6U_NORM",
      "r5sg5sb6u_norm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 10},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 5, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 10},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_S8_UINT] = {
      PIPE_FORMAT_S8_UINT,
      "PIPE_FORMAT_S8_UINT",
      "s8_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_X,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z16_UNORM] = {
      PIPE_FORMAT_Z16_UNORM,
      "PIPE_FORMAT_Z16_UNORM",
      "z16_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z16_UNORM_S8_UINT] = {
      PIPE_FORMAT_Z16_UNORM_S8_UINT,
      "PIPE_FORMAT_Z16_UNORM_S8_UINT",
      "z16_unorm_s8_uint",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 8},	/* x = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* y = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z32_UNORM] = {
      PIPE_FORMAT_Z32_UNORM,
      "PIPE_FORMAT_Z32_UNORM",
      "z32_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* x = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z32_FLOAT] = {
      PIPE_FORMAT_Z32_FLOAT,
      "PIPE_FORMAT_Z32_FLOAT",
      "z32_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z24_UNORM_S8_UINT] = {
      PIPE_FORMAT_Z24_UNORM_S8_UINT,
      "PIPE_FORMAT_Z24_UNORM_S8_UINT",
      "z24_unorm_s8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = s */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 0},	/* y = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 0},	/* x = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* y = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* z */
      PIPE_SWIZZLE_X,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_S8_UINT_Z24_UNORM] = {
      PIPE_FORMAT_S8_UINT_Z24_UNORM,
      "PIPE_FORMAT_S8_UINT_Z24_UNORM",
      "s8_uint_z24_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 8},	/* x = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* y = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = s */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 8},	/* y = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* z */
      PIPE_SWIZZLE_X,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_X24S8_UINT] = {
      PIPE_FORMAT_X24S8_UINT,
      "PIPE_FORMAT_X24S8_UINT",
      "x24s8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = s */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 0},	/* y = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* y = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_X,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_S8X24_UINT] = {
      PIPE_FORMAT_S8X24_UINT,
      "PIPE_FORMAT_S8X24_UINT",
      "s8x24_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 8},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* y = s */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = s */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 8},	/* y = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_X,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z24X8_UNORM] = {
      PIPE_FORMAT_Z24X8_UNORM,
      "PIPE_FORMAT_Z24X8_UNORM",
      "z24x8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 0},	/* y = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 0},	/* x = z */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* y = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_X8Z24_UNORM] = {
      PIPE_FORMAT_X8Z24_UNORM,
      "PIPE_FORMAT_X8Z24_UNORM",
      "x8z24_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 8},	/* x = z */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* y = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 24, 8},	/* y = z */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* z */
      PIPE_SWIZZLE_NONE,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = {
      PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
      "PIPE_FORMAT_Z32_FLOAT_S8X24_UINT",
      "z32_float_s8x24_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      TRUE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* x = z */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 8},	/* y = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* z = s */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 32},	/* y = s */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 40},	/* z = x */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_Z,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_X32_S8X24_UINT] = {
      PIPE_FORMAT_X32_S8X24_UINT,
      "PIPE_FORMAT_X32_S8X24_UINT",
      "x32_s8x24_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 32},	/* x = x */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 8},	/* y = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* z = s */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 32},	/* y = s */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 24, 40},	/* z = x */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_Z,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_NONE,	/* z */
      PIPE_SWIZZLE_Y,	/* s */
      PIPE_SWIZZLE_NONE,	/* ignored */
      PIPE_SWIZZLE_NONE	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_ZS,
   },

   [PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8] = {
      PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8,
      "PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8",
      "z24_unorm_s8_uint_as_r8g8b8a8",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_UYVY] = {
      PIPE_FORMAT_UYVY,
      "PIPE_FORMAT_UYVY",
      "uyvy",
      {2, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_1	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_YUYV] = {
      PIPE_FORMAT_YUYV,
      "PIPE_FORMAT_YUYV",
      "yuyv",
      {2, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_1	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_AYUV] = {
      PIPE_FORMAT_AYUV,
      "PIPE_FORMAT_AYUV",
      "ayuv",
      {4, 4, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_XYUV] = {
      PIPE_FORMAT_XYUV,
      "PIPE_FORMAT_XYUV",
      "xyuv",
      {4, 4, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_1	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_R8G8_B8G8_UNORM] = {
      PIPE_FORMAT_R8G8_B8G8_UNORM,
      "PIPE_FORMAT_R8G8_B8G8_UNORM",
      "r8g8_b8g8_unorm",
      {2, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_G8R8_G8B8_UNORM] = {
      PIPE_FORMAT_G8R8_G8B8_UNORM,
      "PIPE_FORMAT_G8R8_G8B8_UNORM",
      "g8r8_g8b8_unorm",
      {2, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_G8R8_B8R8_UNORM] = {
      PIPE_FORMAT_G8R8_B8R8_UNORM,
      "PIPE_FORMAT_G8R8_B8R8_UNORM",
      "g8r8_b8r8_unorm",
      {2, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_R8B8_UNORM] = {
      PIPE_FORMAT_R8G8_R8B8_UNORM,
      "PIPE_FORMAT_R8G8_R8B8_UNORM",
      "r8g8_r8b8_unorm",
      {2, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R11G11B10_FLOAT] = {
      PIPE_FORMAT_R11G11B10_FLOAT,
      "PIPE_FORMAT_R11G11B10_FLOAT",
      "r11g11b10_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 11, 21},	/* x = x */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 11, 10},	/* y = y */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 10, 0},	/* z = z */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 11, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 11, 11},	/* y = y */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 10, 22},	/* z = z */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R9G9B9E5_FLOAT] = {
      PIPE_FORMAT_R9G9B9E5_FLOAT,
      "PIPE_FORMAT_R9G9B9E5_FLOAT",
      "r9g9b9e5_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 9, 23},	/* x = x */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 9, 14},	/* y = y */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 9, 5},	/* z = z */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 5, 0}	/* w = w */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 9, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 9, 9},	/* y = y */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 9, 18},	/* z = z */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 5, 27}	/* w = w */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R1_UNORM] = {
      PIPE_FORMAT_R1_UNORM,
      "PIPE_FORMAT_R1_UNORM",
      "r1_unorm",
      {8, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8Bx_SNORM] = {
      PIPE_FORMAT_R8G8Bx_SNORM,
      "PIPE_FORMAT_R8G8Bx_SNORM",
      "r8g8bx_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* y = y */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = y */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_DXT1_RGB] = {
      PIPE_FORMAT_DXT1_RGB,
      "PIPE_FORMAT_DXT1_RGB",
      "dxt1_rgb",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_DXT1_RGBA] = {
      PIPE_FORMAT_DXT1_RGBA,
      "PIPE_FORMAT_DXT1_RGBA",
      "dxt1_rgba",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_DXT3_RGBA] = {
      PIPE_FORMAT_DXT3_RGBA,
      "PIPE_FORMAT_DXT3_RGBA",
      "dxt3_rgba",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_DXT5_RGBA] = {
      PIPE_FORMAT_DXT5_RGBA,
      "PIPE_FORMAT_DXT5_RGBA",
      "dxt5_rgba",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_DXT1_SRGB] = {
      PIPE_FORMAT_DXT1_SRGB,
      "PIPE_FORMAT_DXT1_SRGB",
      "dxt1_srgb",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_DXT1_SRGBA] = {
      PIPE_FORMAT_DXT1_SRGBA,
      "PIPE_FORMAT_DXT1_SRGBA",
      "dxt1_srgba",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_DXT3_SRGBA] = {
      PIPE_FORMAT_DXT3_SRGBA,
      "PIPE_FORMAT_DXT3_SRGBA",
      "dxt3_srgba",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_DXT5_SRGBA] = {
      PIPE_FORMAT_DXT5_SRGBA,
      "PIPE_FORMAT_DXT5_SRGBA",
      "dxt5_srgba",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_S3TC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_FXT1_RGB] = {
      PIPE_FORMAT_FXT1_RGB,
      "PIPE_FORMAT_FXT1_RGB",
      "fxt1_rgb",
      {8, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_FXT1,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_FXT1_RGBA] = {
      PIPE_FORMAT_FXT1_RGBA,
      "PIPE_FORMAT_FXT1_RGBA",
      "fxt1_rgba",
      {8, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_FXT1,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_RGTC1_UNORM] = {
      PIPE_FORMAT_RGTC1_UNORM,
      "PIPE_FORMAT_RGTC1_UNORM",
      "rgtc1_unorm",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_RGTC1_SNORM] = {
      PIPE_FORMAT_RGTC1_SNORM,
      "PIPE_FORMAT_RGTC1_SNORM",
      "rgtc1_snorm",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_RGTC2_UNORM] = {
      PIPE_FORMAT_RGTC2_UNORM,
      "PIPE_FORMAT_RGTC2_UNORM",
      "rgtc2_unorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_RGTC2_SNORM] = {
      PIPE_FORMAT_RGTC2_SNORM,
      "PIPE_FORMAT_RGTC2_SNORM",
      "rgtc2_snorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_LATC1_UNORM] = {
      PIPE_FORMAT_LATC1_UNORM,
      "PIPE_FORMAT_LATC1_UNORM",
      "latc1_unorm",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_LATC1_SNORM] = {
      PIPE_FORMAT_LATC1_SNORM,
      "PIPE_FORMAT_LATC1_SNORM",
      "latc1_snorm",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_LATC2_UNORM] = {
      PIPE_FORMAT_LATC2_UNORM,
      "PIPE_FORMAT_LATC2_UNORM",
      "latc2_unorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_LATC2_SNORM] = {
      PIPE_FORMAT_LATC2_SNORM,
      "PIPE_FORMAT_LATC2_SNORM",
      "latc2_snorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_RGTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC1_RGB8] = {
      PIPE_FORMAT_ETC1_RGB8,
      "PIPE_FORMAT_ETC1_RGB8",
      "etc1_rgb8",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_RGB8] = {
      PIPE_FORMAT_ETC2_RGB8,
      "PIPE_FORMAT_ETC2_RGB8",
      "etc2_rgb8",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_SRGB8] = {
      PIPE_FORMAT_ETC2_SRGB8,
      "PIPE_FORMAT_ETC2_SRGB8",
      "etc2_srgb8",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ETC2_RGB8A1] = {
      PIPE_FORMAT_ETC2_RGB8A1,
      "PIPE_FORMAT_ETC2_RGB8A1",
      "etc2_rgb8a1",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_SRGB8A1] = {
      PIPE_FORMAT_ETC2_SRGB8A1,
      "PIPE_FORMAT_ETC2_SRGB8A1",
      "etc2_srgb8a1",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ETC2_RGBA8] = {
      PIPE_FORMAT_ETC2_RGBA8,
      "PIPE_FORMAT_ETC2_RGBA8",
      "etc2_rgba8",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_SRGBA8] = {
      PIPE_FORMAT_ETC2_SRGBA8,
      "PIPE_FORMAT_ETC2_SRGBA8",
      "etc2_srgba8",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ETC2_R11_UNORM] = {
      PIPE_FORMAT_ETC2_R11_UNORM,
      "PIPE_FORMAT_ETC2_R11_UNORM",
      "etc2_r11_unorm",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_R11_SNORM] = {
      PIPE_FORMAT_ETC2_R11_SNORM,
      "PIPE_FORMAT_ETC2_R11_SNORM",
      "etc2_r11_snorm",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_RG11_UNORM] = {
      PIPE_FORMAT_ETC2_RG11_UNORM,
      "PIPE_FORMAT_ETC2_RG11_UNORM",
      "etc2_rg11_unorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ETC2_RG11_SNORM] = {
      PIPE_FORMAT_ETC2_RG11_SNORM,
      "PIPE_FORMAT_ETC2_RG11_SNORM",
      "etc2_rg11_snorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ETC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_BPTC_RGBA_UNORM] = {
      PIPE_FORMAT_BPTC_RGBA_UNORM,
      "PIPE_FORMAT_BPTC_RGBA_UNORM",
      "bptc_rgba_unorm",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_BPTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_BPTC_SRGBA] = {
      PIPE_FORMAT_BPTC_SRGBA,
      "PIPE_FORMAT_BPTC_SRGBA",
      "bptc_srgba",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_BPTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_BPTC_RGB_FLOAT] = {
      PIPE_FORMAT_BPTC_RGB_FLOAT,
      "PIPE_FORMAT_BPTC_RGB_FLOAT",
      "bptc_rgb_float",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_BPTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_BPTC_RGB_UFLOAT] = {
      PIPE_FORMAT_BPTC_RGB_UFLOAT,
      "PIPE_FORMAT_BPTC_RGB_UFLOAT",
      "bptc_rgb_ufloat",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_BPTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_4x4] = {
      PIPE_FORMAT_ASTC_4x4,
      "PIPE_FORMAT_ASTC_4x4",
      "astc_4x4",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_5x4] = {
      PIPE_FORMAT_ASTC_5x4,
      "PIPE_FORMAT_ASTC_5x4",
      "astc_5x4",
      {5, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_5x5] = {
      PIPE_FORMAT_ASTC_5x5,
      "PIPE_FORMAT_ASTC_5x5",
      "astc_5x5",
      {5, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_6x5] = {
      PIPE_FORMAT_ASTC_6x5,
      "PIPE_FORMAT_ASTC_6x5",
      "astc_6x5",
      {6, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_6x6] = {
      PIPE_FORMAT_ASTC_6x6,
      "PIPE_FORMAT_ASTC_6x6",
      "astc_6x6",
      {6, 6, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_8x5] = {
      PIPE_FORMAT_ASTC_8x5,
      "PIPE_FORMAT_ASTC_8x5",
      "astc_8x5",
      {8, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_8x6] = {
      PIPE_FORMAT_ASTC_8x6,
      "PIPE_FORMAT_ASTC_8x6",
      "astc_8x6",
      {8, 6, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_8x8] = {
      PIPE_FORMAT_ASTC_8x8,
      "PIPE_FORMAT_ASTC_8x8",
      "astc_8x8",
      {8, 8, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_10x5] = {
      PIPE_FORMAT_ASTC_10x5,
      "PIPE_FORMAT_ASTC_10x5",
      "astc_10x5",
      {10, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_10x6] = {
      PIPE_FORMAT_ASTC_10x6,
      "PIPE_FORMAT_ASTC_10x6",
      "astc_10x6",
      {10, 6, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_10x8] = {
      PIPE_FORMAT_ASTC_10x8,
      "PIPE_FORMAT_ASTC_10x8",
      "astc_10x8",
      {10, 8, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_10x10] = {
      PIPE_FORMAT_ASTC_10x10,
      "PIPE_FORMAT_ASTC_10x10",
      "astc_10x10",
      {10, 10, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_12x10] = {
      PIPE_FORMAT_ASTC_12x10,
      "PIPE_FORMAT_ASTC_12x10",
      "astc_12x10",
      {12, 10, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_12x12] = {
      PIPE_FORMAT_ASTC_12x12,
      "PIPE_FORMAT_ASTC_12x12",
      "astc_12x12",
      {12, 12, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_4x4_SRGB] = {
      PIPE_FORMAT_ASTC_4x4_SRGB,
      "PIPE_FORMAT_ASTC_4x4_SRGB",
      "astc_4x4_srgb",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_5x4_SRGB] = {
      PIPE_FORMAT_ASTC_5x4_SRGB,
      "PIPE_FORMAT_ASTC_5x4_SRGB",
      "astc_5x4_srgb",
      {5, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_5x5_SRGB] = {
      PIPE_FORMAT_ASTC_5x5_SRGB,
      "PIPE_FORMAT_ASTC_5x5_SRGB",
      "astc_5x5_srgb",
      {5, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_6x5_SRGB] = {
      PIPE_FORMAT_ASTC_6x5_SRGB,
      "PIPE_FORMAT_ASTC_6x5_SRGB",
      "astc_6x5_srgb",
      {6, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_6x6_SRGB] = {
      PIPE_FORMAT_ASTC_6x6_SRGB,
      "PIPE_FORMAT_ASTC_6x6_SRGB",
      "astc_6x6_srgb",
      {6, 6, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_8x5_SRGB] = {
      PIPE_FORMAT_ASTC_8x5_SRGB,
      "PIPE_FORMAT_ASTC_8x5_SRGB",
      "astc_8x5_srgb",
      {8, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_8x6_SRGB] = {
      PIPE_FORMAT_ASTC_8x6_SRGB,
      "PIPE_FORMAT_ASTC_8x6_SRGB",
      "astc_8x6_srgb",
      {8, 6, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_8x8_SRGB] = {
      PIPE_FORMAT_ASTC_8x8_SRGB,
      "PIPE_FORMAT_ASTC_8x8_SRGB",
      "astc_8x8_srgb",
      {8, 8, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_10x5_SRGB] = {
      PIPE_FORMAT_ASTC_10x5_SRGB,
      "PIPE_FORMAT_ASTC_10x5_SRGB",
      "astc_10x5_srgb",
      {10, 5, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_10x6_SRGB] = {
      PIPE_FORMAT_ASTC_10x6_SRGB,
      "PIPE_FORMAT_ASTC_10x6_SRGB",
      "astc_10x6_srgb",
      {10, 6, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_10x8_SRGB] = {
      PIPE_FORMAT_ASTC_10x8_SRGB,
      "PIPE_FORMAT_ASTC_10x8_SRGB",
      "astc_10x8_srgb",
      {10, 8, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_10x10_SRGB] = {
      PIPE_FORMAT_ASTC_10x10_SRGB,
      "PIPE_FORMAT_ASTC_10x10_SRGB",
      "astc_10x10_srgb",
      {10, 10, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_12x10_SRGB] = {
      PIPE_FORMAT_ASTC_12x10_SRGB,
      "PIPE_FORMAT_ASTC_12x10_SRGB",
      "astc_12x10_srgb",
      {12, 10, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_12x12_SRGB] = {
      PIPE_FORMAT_ASTC_12x12_SRGB,
      "PIPE_FORMAT_ASTC_12x12_SRGB",
      "astc_12x12_srgb",
      {12, 12, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_3x3x3] = {
      PIPE_FORMAT_ASTC_3x3x3,
      "PIPE_FORMAT_ASTC_3x3x3",
      "astc_3x3x3",
      {3, 3, 3, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_4x3x3] = {
      PIPE_FORMAT_ASTC_4x3x3,
      "PIPE_FORMAT_ASTC_4x3x3",
      "astc_4x3x3",
      {4, 3, 3, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_4x4x3] = {
      PIPE_FORMAT_ASTC_4x4x3,
      "PIPE_FORMAT_ASTC_4x4x3",
      "astc_4x4x3",
      {4, 4, 3, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_4x4x4] = {
      PIPE_FORMAT_ASTC_4x4x4,
      "PIPE_FORMAT_ASTC_4x4x4",
      "astc_4x4x4",
      {4, 4, 4, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_5x4x4] = {
      PIPE_FORMAT_ASTC_5x4x4,
      "PIPE_FORMAT_ASTC_5x4x4",
      "astc_5x4x4",
      {5, 4, 4, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_5x5x4] = {
      PIPE_FORMAT_ASTC_5x5x4,
      "PIPE_FORMAT_ASTC_5x5x4",
      "astc_5x5x4",
      {5, 5, 4, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_5x5x5] = {
      PIPE_FORMAT_ASTC_5x5x5,
      "PIPE_FORMAT_ASTC_5x5x5",
      "astc_5x5x5",
      {5, 5, 5, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_6x5x5] = {
      PIPE_FORMAT_ASTC_6x5x5,
      "PIPE_FORMAT_ASTC_6x5x5",
      "astc_6x5x5",
      {6, 5, 5, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_6x6x5] = {
      PIPE_FORMAT_ASTC_6x6x5,
      "PIPE_FORMAT_ASTC_6x6x5",
      "astc_6x6x5",
      {6, 6, 5, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_6x6x6] = {
      PIPE_FORMAT_ASTC_6x6x6,
      "PIPE_FORMAT_ASTC_6x6x6",
      "astc_6x6x6",
      {6, 6, 6, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ASTC_3x3x3_SRGB] = {
      PIPE_FORMAT_ASTC_3x3x3_SRGB,
      "PIPE_FORMAT_ASTC_3x3x3_SRGB",
      "astc_3x3x3_srgb",
      {3, 3, 3, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_4x3x3_SRGB] = {
      PIPE_FORMAT_ASTC_4x3x3_SRGB,
      "PIPE_FORMAT_ASTC_4x3x3_SRGB",
      "astc_4x3x3_srgb",
      {4, 3, 3, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_4x4x3_SRGB] = {
      PIPE_FORMAT_ASTC_4x4x3_SRGB,
      "PIPE_FORMAT_ASTC_4x4x3_SRGB",
      "astc_4x4x3_srgb",
      {4, 4, 3, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_4x4x4_SRGB] = {
      PIPE_FORMAT_ASTC_4x4x4_SRGB,
      "PIPE_FORMAT_ASTC_4x4x4_SRGB",
      "astc_4x4x4_srgb",
      {4, 4, 4, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_5x4x4_SRGB] = {
      PIPE_FORMAT_ASTC_5x4x4_SRGB,
      "PIPE_FORMAT_ASTC_5x4x4_SRGB",
      "astc_5x4x4_srgb",
      {5, 4, 4, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_5x5x4_SRGB] = {
      PIPE_FORMAT_ASTC_5x5x4_SRGB,
      "PIPE_FORMAT_ASTC_5x5x4_SRGB",
      "astc_5x5x4_srgb",
      {5, 5, 4, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_5x5x5_SRGB] = {
      PIPE_FORMAT_ASTC_5x5x5_SRGB,
      "PIPE_FORMAT_ASTC_5x5x5_SRGB",
      "astc_5x5x5_srgb",
      {5, 5, 5, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_6x5x5_SRGB] = {
      PIPE_FORMAT_ASTC_6x5x5_SRGB,
      "PIPE_FORMAT_ASTC_6x5x5_SRGB",
      "astc_6x5x5_srgb",
      {6, 5, 5, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_6x6x5_SRGB] = {
      PIPE_FORMAT_ASTC_6x6x5_SRGB,
      "PIPE_FORMAT_ASTC_6x6x5_SRGB",
      "astc_6x6x5_srgb",
      {6, 6, 5, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ASTC_6x6x6_SRGB] = {
      PIPE_FORMAT_ASTC_6x6x6_SRGB,
      "PIPE_FORMAT_ASTC_6x6x6_SRGB",
      "astc_6x6x6_srgb",
      {6, 6, 6, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ASTC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_ATC_RGB] = {
      PIPE_FORMAT_ATC_RGB,
      "PIPE_FORMAT_ATC_RGB",
      "atc_rgb",
      {4, 4, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_ATC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ATC_RGBA_EXPLICIT] = {
      PIPE_FORMAT_ATC_RGBA_EXPLICIT,
      "PIPE_FORMAT_ATC_RGBA_EXPLICIT",
      "atc_rgba_explicit",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ATC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_ATC_RGBA_INTERPOLATED] = {
      PIPE_FORMAT_ATC_RGBA_INTERPOLATED,
      "PIPE_FORMAT_ATC_RGBA_INTERPOLATED",
      "atc_rgba_interpolated",
      {4, 4, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_ATC,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 128, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64_FLOAT] = {
      PIPE_FORMAT_R64_FLOAT,
      "PIPE_FORMAT_R64_FLOAT",
      "r64_float",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64G64_FLOAT] = {
      PIPE_FORMAT_R64G64_FLOAT,
      "PIPE_FORMAT_R64G64_FLOAT",
      "r64g64_float",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 64},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64G64B64_FLOAT] = {
      PIPE_FORMAT_R64G64B64_FLOAT,
      "PIPE_FORMAT_R64G64B64_FLOAT",
      "r64g64b64_float",
      {1, 1, 1, 192},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 128},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 128},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64G64B64A64_FLOAT] = {
      PIPE_FORMAT_R64G64B64A64_FLOAT,
      "PIPE_FORMAT_R64G64B64A64_FLOAT",
      "r64g64b64a64_float",
      {1, 1, 1, 256},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 192},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 128},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 128},	/* z = b */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 64, 192}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_FLOAT] = {
      PIPE_FORMAT_R32_FLOAT,
      "PIPE_FORMAT_R32_FLOAT",
      "r32_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_FLOAT] = {
      PIPE_FORMAT_R32G32_FLOAT,
      "PIPE_FORMAT_R32G32_FLOAT",
      "r32g32_float",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_FLOAT] = {
      PIPE_FORMAT_R32G32B32_FLOAT,
      "PIPE_FORMAT_R32G32B32_FLOAT",
      "r32g32b32_float",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_FLOAT] = {
      PIPE_FORMAT_R32G32B32A32_FLOAT,
      "PIPE_FORMAT_R32G32B32A32_FLOAT",
      "r32g32b32a32_float",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_UNORM] = {
      PIPE_FORMAT_R32_UNORM,
      "PIPE_FORMAT_R32_UNORM",
      "r32_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_UNORM] = {
      PIPE_FORMAT_R32G32_UNORM,
      "PIPE_FORMAT_R32G32_UNORM",
      "r32g32_unorm",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_UNORM] = {
      PIPE_FORMAT_R32G32B32_UNORM,
      "PIPE_FORMAT_R32G32B32_UNORM",
      "r32g32b32_unorm",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_UNORM] = {
      PIPE_FORMAT_R32G32B32A32_UNORM,
      "PIPE_FORMAT_R32G32B32A32_UNORM",
      "r32g32b32a32_unorm",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_USCALED] = {
      PIPE_FORMAT_R32_USCALED,
      "PIPE_FORMAT_R32_USCALED",
      "r32_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_USCALED] = {
      PIPE_FORMAT_R32G32_USCALED,
      "PIPE_FORMAT_R32G32_USCALED",
      "r32g32_uscaled",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_USCALED] = {
      PIPE_FORMAT_R32G32B32_USCALED,
      "PIPE_FORMAT_R32G32B32_USCALED",
      "r32g32b32_uscaled",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_USCALED] = {
      PIPE_FORMAT_R32G32B32A32_USCALED,
      "PIPE_FORMAT_R32G32B32A32_USCALED",
      "r32g32b32a32_uscaled",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_SNORM] = {
      PIPE_FORMAT_R32_SNORM,
      "PIPE_FORMAT_R32_SNORM",
      "r32_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_SNORM] = {
      PIPE_FORMAT_R32G32_SNORM,
      "PIPE_FORMAT_R32G32_SNORM",
      "r32g32_snorm",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_SNORM] = {
      PIPE_FORMAT_R32G32B32_SNORM,
      "PIPE_FORMAT_R32G32B32_SNORM",
      "r32g32b32_snorm",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_SNORM] = {
      PIPE_FORMAT_R32G32B32A32_SNORM,
      "PIPE_FORMAT_R32G32B32A32_SNORM",
      "r32g32b32a32_snorm",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_SSCALED] = {
      PIPE_FORMAT_R32_SSCALED,
      "PIPE_FORMAT_R32_SSCALED",
      "r32_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_SSCALED] = {
      PIPE_FORMAT_R32G32_SSCALED,
      "PIPE_FORMAT_R32G32_SSCALED",
      "r32g32_sscaled",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_SSCALED] = {
      PIPE_FORMAT_R32G32B32_SSCALED,
      "PIPE_FORMAT_R32G32B32_SSCALED",
      "r32g32b32_sscaled",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_SSCALED] = {
      PIPE_FORMAT_R32G32B32A32_SSCALED,
      "PIPE_FORMAT_R32G32B32A32_SSCALED",
      "r32g32b32a32_sscaled",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_FLOAT] = {
      PIPE_FORMAT_R16_FLOAT,
      "PIPE_FORMAT_R16_FLOAT",
      "r16_float",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_FLOAT] = {
      PIPE_FORMAT_R16G16_FLOAT,
      "PIPE_FORMAT_R16G16_FLOAT",
      "r16g16_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_FLOAT] = {
      PIPE_FORMAT_R16G16B16_FLOAT,
      "PIPE_FORMAT_R16G16B16_FLOAT",
      "r16g16b16_float",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_FLOAT] = {
      PIPE_FORMAT_R16G16B16A16_FLOAT,
      "PIPE_FORMAT_R16G16B16A16_FLOAT",
      "r16g16b16a16_float",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_UNORM] = {
      PIPE_FORMAT_R16_UNORM,
      "PIPE_FORMAT_R16_UNORM",
      "r16_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_UNORM] = {
      PIPE_FORMAT_R16G16_UNORM,
      "PIPE_FORMAT_R16G16_UNORM",
      "r16g16_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_UNORM] = {
      PIPE_FORMAT_R16G16B16_UNORM,
      "PIPE_FORMAT_R16G16B16_UNORM",
      "r16g16b16_unorm",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_UNORM] = {
      PIPE_FORMAT_R16G16B16A16_UNORM,
      "PIPE_FORMAT_R16G16B16A16_UNORM",
      "r16g16b16a16_unorm",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_USCALED] = {
      PIPE_FORMAT_R16_USCALED,
      "PIPE_FORMAT_R16_USCALED",
      "r16_uscaled",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_USCALED] = {
      PIPE_FORMAT_R16G16_USCALED,
      "PIPE_FORMAT_R16G16_USCALED",
      "r16g16_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_USCALED] = {
      PIPE_FORMAT_R16G16B16_USCALED,
      "PIPE_FORMAT_R16G16B16_USCALED",
      "r16g16b16_uscaled",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_USCALED] = {
      PIPE_FORMAT_R16G16B16A16_USCALED,
      "PIPE_FORMAT_R16G16B16A16_USCALED",
      "r16g16b16a16_uscaled",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_SNORM] = {
      PIPE_FORMAT_R16_SNORM,
      "PIPE_FORMAT_R16_SNORM",
      "r16_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_SNORM] = {
      PIPE_FORMAT_R16G16_SNORM,
      "PIPE_FORMAT_R16G16_SNORM",
      "r16g16_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_SNORM] = {
      PIPE_FORMAT_R16G16B16_SNORM,
      "PIPE_FORMAT_R16G16B16_SNORM",
      "r16g16b16_snorm",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_SNORM] = {
      PIPE_FORMAT_R16G16B16A16_SNORM,
      "PIPE_FORMAT_R16G16B16A16_SNORM",
      "r16g16b16a16_snorm",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_SSCALED] = {
      PIPE_FORMAT_R16_SSCALED,
      "PIPE_FORMAT_R16_SSCALED",
      "r16_sscaled",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_SSCALED] = {
      PIPE_FORMAT_R16G16_SSCALED,
      "PIPE_FORMAT_R16G16_SSCALED",
      "r16g16_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_SSCALED] = {
      PIPE_FORMAT_R16G16B16_SSCALED,
      "PIPE_FORMAT_R16G16B16_SSCALED",
      "r16g16b16_sscaled",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_SSCALED] = {
      PIPE_FORMAT_R16G16B16A16_SSCALED,
      "PIPE_FORMAT_R16G16B16A16_SSCALED",
      "r16g16b16a16_sscaled",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_UNORM] = {
      PIPE_FORMAT_R8_UNORM,
      "PIPE_FORMAT_R8_UNORM",
      "r8_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_UNORM] = {
      PIPE_FORMAT_R8G8_UNORM,
      "PIPE_FORMAT_R8G8_UNORM",
      "r8g8_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8_UNORM] = {
      PIPE_FORMAT_R8G8B8_UNORM,
      "PIPE_FORMAT_R8G8B8_UNORM",
      "r8g8b8_unorm",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8_UNORM] = {
      PIPE_FORMAT_B8G8R8_UNORM,
      "PIPE_FORMAT_B8G8R8_UNORM",
      "b8g8r8_unorm",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8A8_UNORM] = {
      PIPE_FORMAT_R8G8B8A8_UNORM,
      "PIPE_FORMAT_R8G8B8A8_UNORM",
      "r8g8b8a8_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_USCALED] = {
      PIPE_FORMAT_R8_USCALED,
      "PIPE_FORMAT_R8_USCALED",
      "r8_uscaled",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_USCALED] = {
      PIPE_FORMAT_R8G8_USCALED,
      "PIPE_FORMAT_R8G8_USCALED",
      "r8g8_uscaled",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8_USCALED] = {
      PIPE_FORMAT_R8G8B8_USCALED,
      "PIPE_FORMAT_R8G8B8_USCALED",
      "r8g8b8_uscaled",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8_USCALED] = {
      PIPE_FORMAT_B8G8R8_USCALED,
      "PIPE_FORMAT_B8G8R8_USCALED",
      "b8g8r8_uscaled",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8A8_USCALED] = {
      PIPE_FORMAT_R8G8B8A8_USCALED,
      "PIPE_FORMAT_R8G8B8A8_USCALED",
      "r8g8b8a8_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8A8_USCALED] = {
      PIPE_FORMAT_B8G8R8A8_USCALED,
      "PIPE_FORMAT_B8G8R8A8_USCALED",
      "b8g8r8a8_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8B8G8R8_USCALED] = {
      PIPE_FORMAT_A8B8G8R8_USCALED,
      "PIPE_FORMAT_A8B8G8R8_USCALED",
      "a8b8g8r8_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_SNORM] = {
      PIPE_FORMAT_R8_SNORM,
      "PIPE_FORMAT_R8_SNORM",
      "r8_snorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_SNORM] = {
      PIPE_FORMAT_R8G8_SNORM,
      "PIPE_FORMAT_R8G8_SNORM",
      "r8g8_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8_SNORM] = {
      PIPE_FORMAT_R8G8B8_SNORM,
      "PIPE_FORMAT_R8G8B8_SNORM",
      "r8g8b8_snorm",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8_SNORM] = {
      PIPE_FORMAT_B8G8R8_SNORM,
      "PIPE_FORMAT_B8G8R8_SNORM",
      "b8g8r8_snorm",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8A8_SNORM] = {
      PIPE_FORMAT_R8G8B8A8_SNORM,
      "PIPE_FORMAT_R8G8B8A8_SNORM",
      "r8g8b8a8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8A8_SNORM] = {
      PIPE_FORMAT_B8G8R8A8_SNORM,
      "PIPE_FORMAT_B8G8R8A8_SNORM",
      "b8g8r8a8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_SSCALED] = {
      PIPE_FORMAT_R8_SSCALED,
      "PIPE_FORMAT_R8_SSCALED",
      "r8_sscaled",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_SSCALED] = {
      PIPE_FORMAT_R8G8_SSCALED,
      "PIPE_FORMAT_R8G8_SSCALED",
      "r8g8_sscaled",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8_SSCALED] = {
      PIPE_FORMAT_R8G8B8_SSCALED,
      "PIPE_FORMAT_R8G8B8_SSCALED",
      "r8g8b8_sscaled",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8_SSCALED] = {
      PIPE_FORMAT_B8G8R8_SSCALED,
      "PIPE_FORMAT_B8G8R8_SSCALED",
      "b8g8r8_sscaled",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8A8_SSCALED] = {
      PIPE_FORMAT_R8G8B8A8_SSCALED,
      "PIPE_FORMAT_R8G8B8A8_SSCALED",
      "r8g8b8a8_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8A8_SSCALED] = {
      PIPE_FORMAT_B8G8R8A8_SSCALED,
      "PIPE_FORMAT_B8G8R8A8_SSCALED",
      "b8g8r8a8_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8B8G8R8_SSCALED] = {
      PIPE_FORMAT_A8B8G8R8_SSCALED,
      "PIPE_FORMAT_A8B8G8R8_SSCALED",
      "a8b8g8r8_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_FIXED] = {
      PIPE_FORMAT_R32_FIXED,
      "PIPE_FORMAT_R32_FIXED",
      "r32_fixed",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_FIXED] = {
      PIPE_FORMAT_R32G32_FIXED,
      "PIPE_FORMAT_R32G32_FIXED",
      "r32g32_fixed",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_FIXED] = {
      PIPE_FORMAT_R32G32B32_FIXED,
      "PIPE_FORMAT_R32G32B32_FIXED",
      "r32g32b32_fixed",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_FIXED] = {
      PIPE_FORMAT_R32G32B32A32_FIXED,
      "PIPE_FORMAT_R32G32B32A32_FIXED",
      "r32g32b32a32_fixed",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_FIXED, FALSE, FALSE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10X2_USCALED] = {
      PIPE_FORMAT_R10G10B10X2_USCALED,
      "PIPE_FORMAT_R10G10B10X2_USCALED",
      "r10g10b10x2_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10X2_SNORM] = {
      PIPE_FORMAT_R10G10B10X2_SNORM,
      "PIPE_FORMAT_R10G10B10X2_SNORM",
      "r10g10b10x2_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_YV12] = {
      PIPE_FORMAT_YV12,
      "PIPE_FORMAT_YV12",
      "yv12",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_YV16] = {
      PIPE_FORMAT_YV16,
      "PIPE_FORMAT_YV16",
      "yv16",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_IYUV] = {
      PIPE_FORMAT_IYUV,
      "PIPE_FORMAT_IYUV",
      "iyuv",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_NV12] = {
      PIPE_FORMAT_NV12,
      "PIPE_FORMAT_NV12",
      "nv12",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_NV21] = {
      PIPE_FORMAT_NV21,
      "PIPE_FORMAT_NV21",
      "nv21",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_R8_G8B8_420_UNORM] = {
      PIPE_FORMAT_R8_G8B8_420_UNORM,
      "PIPE_FORMAT_R8_G8B8_420_UNORM",
      "r8_g8b8_420_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_G8_B8_420_UNORM] = {
      PIPE_FORMAT_R8_G8_B8_420_UNORM,
      "PIPE_FORMAT_R8_G8_B8_420_UNORM",
      "r8_g8_b8_420_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_Y8_U8_V8_422_UNORM] = {
      PIPE_FORMAT_Y8_U8_V8_422_UNORM,
      "PIPE_FORMAT_Y8_U8_V8_422_UNORM",
      "y8_u8_v8_422_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y8_U8V8_422_UNORM] = {
      PIPE_FORMAT_Y8_U8V8_422_UNORM,
      "PIPE_FORMAT_Y8_U8V8_422_UNORM",
      "y8_u8v8_422_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y8_U8_V8_444_UNORM] = {
      PIPE_FORMAT_Y8_U8_V8_444_UNORM,
      "PIPE_FORMAT_Y8_U8_V8_444_UNORM",
      "y8_u8_v8_444_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y16_U16_V16_420_UNORM] = {
      PIPE_FORMAT_Y16_U16_V16_420_UNORM,
      "PIPE_FORMAT_Y16_U16_V16_420_UNORM",
      "y16_u16_v16_420_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y16_U16_V16_422_UNORM] = {
      PIPE_FORMAT_Y16_U16_V16_422_UNORM,
      "PIPE_FORMAT_Y16_U16_V16_422_UNORM",
      "y16_u16_v16_422_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y16_U16V16_422_UNORM] = {
      PIPE_FORMAT_Y16_U16V16_422_UNORM,
      "PIPE_FORMAT_Y16_U16V16_422_UNORM",
      "y16_u16v16_422_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y16_U16_V16_444_UNORM] = {
      PIPE_FORMAT_Y16_U16_V16_444_UNORM,
      "PIPE_FORMAT_Y16_U16_V16_444_UNORM",
      "y16_u16_v16_444_unorm",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR3,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_P010] = {
      PIPE_FORMAT_P010,
      "PIPE_FORMAT_P010",
      "p010",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_P012] = {
      PIPE_FORMAT_P012,
      "PIPE_FORMAT_P012",
      "p012",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_P016] = {
      PIPE_FORMAT_P016,
      "PIPE_FORMAT_P016",
      "p016",
      {1, 1, 1, 0},	/* block */
      UTIL_FORMAT_LAYOUT_PLANAR2,
      0,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y210] = {
      PIPE_FORMAT_Y210,
      "PIPE_FORMAT_Y210",
      "y210",
      {2, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_1	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y212] = {
      PIPE_FORMAT_Y212,
      "PIPE_FORMAT_Y212",
      "y212",
      {2, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_1	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y216] = {
      PIPE_FORMAT_Y216,
      "PIPE_FORMAT_Y216",
      "y216",
      {2, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_SUBSAMPLED,
      1,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 64, 0},	/* x = x */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* y */
      PIPE_SWIZZLE_Y,	/* u */
      PIPE_SWIZZLE_Z,	/* v */
      PIPE_SWIZZLE_1	/* ignored */
   },
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y410] = {
      PIPE_FORMAT_Y410,
      "PIPE_FORMAT_Y410",
      "y410",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 22},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 12},	/* y = y */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 2},	/* z = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 0}	/* w = w */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* y = y */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* z = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 2, 30}	/* w = w */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* y */
      PIPE_SWIZZLE_Z,	/* u */
      PIPE_SWIZZLE_X,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* y */
      PIPE_SWIZZLE_Z,	/* u */
      PIPE_SWIZZLE_X,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y412] = {
      PIPE_FORMAT_Y412,
      "PIPE_FORMAT_Y412",
      "y412",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* y = y */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* z = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0}	/* w = w */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = y */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* z = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48}	/* w = w */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* y */
      PIPE_SWIZZLE_Z,	/* u */
      PIPE_SWIZZLE_X,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* y */
      PIPE_SWIZZLE_Z,	/* u */
      PIPE_SWIZZLE_X,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_Y416] = {
      PIPE_FORMAT_Y416,
      "PIPE_FORMAT_Y416",
      "y416",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_OTHER,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* y = y */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* z = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0}	/* w = w */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = y */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* z = z */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48}	/* w = w */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* y */
      PIPE_SWIZZLE_Z,	/* u */
      PIPE_SWIZZLE_X,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* y */
      PIPE_SWIZZLE_Z,	/* u */
      PIPE_SWIZZLE_X,	/* v */
      PIPE_SWIZZLE_W	/* ignored */
   },
#endif
      UTIL_FORMAT_COLORSPACE_YUV,
   },

   [PIPE_FORMAT_A4R4_UNORM] = {
      PIPE_FORMAT_A4R4_UNORM,
      "PIPE_FORMAT_A4R4_UNORM",
      "a4r4_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R4A4_UNORM] = {
      PIPE_FORMAT_R4A4_UNORM,
      "PIPE_FORMAT_R4A4_UNORM",
      "r4a4_unorm",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 4, 4},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8A8_UNORM] = {
      PIPE_FORMAT_R8A8_UNORM,
      "PIPE_FORMAT_R8A8_UNORM",
      "r8a8_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8R8_UNORM] = {
      PIPE_FORMAT_A8R8_UNORM,
      "PIPE_FORMAT_A8R8_UNORM",
      "a8r8_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10A2_USCALED] = {
      PIPE_FORMAT_R10G10B10A2_USCALED,
      "PIPE_FORMAT_R10G10B10A2_USCALED",
      "r10g10b10a2_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10A2_SSCALED] = {
      PIPE_FORMAT_R10G10B10A2_SSCALED,
      "PIPE_FORMAT_R10G10B10A2_SSCALED",
      "r10g10b10a2_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10A2_SNORM] = {
      PIPE_FORMAT_R10G10B10A2_SNORM,
      "PIPE_FORMAT_R10G10B10A2_SNORM",
      "r10g10b10a2_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10A2_USCALED] = {
      PIPE_FORMAT_B10G10R10A2_USCALED,
      "PIPE_FORMAT_B10G10R10A2_USCALED",
      "b10g10r10a2_uscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10A2_SSCALED] = {
      PIPE_FORMAT_B10G10R10A2_SSCALED,
      "PIPE_FORMAT_B10G10R10A2_SSCALED",
      "b10g10r10a2_sscaled",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10A2_SNORM] = {
      PIPE_FORMAT_B10G10R10A2_SNORM,
      "PIPE_FORMAT_B10G10R10A2_SNORM",
      "b10g10r10a2_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_UINT] = {
      PIPE_FORMAT_R8_UINT,
      "PIPE_FORMAT_R8_UINT",
      "r8_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_UINT] = {
      PIPE_FORMAT_R8G8_UINT,
      "PIPE_FORMAT_R8G8_UINT",
      "r8g8_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8_UINT] = {
      PIPE_FORMAT_R8G8B8_UINT,
      "PIPE_FORMAT_R8G8B8_UINT",
      "r8g8b8_uint",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8A8_UINT] = {
      PIPE_FORMAT_R8G8B8A8_UINT,
      "PIPE_FORMAT_R8G8B8A8_UINT",
      "r8g8b8a8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8_SINT] = {
      PIPE_FORMAT_R8_SINT,
      "PIPE_FORMAT_R8_SINT",
      "r8_sint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8_SINT] = {
      PIPE_FORMAT_R8G8_SINT,
      "PIPE_FORMAT_R8G8_SINT",
      "r8g8_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8_SINT] = {
      PIPE_FORMAT_R8G8B8_SINT,
      "PIPE_FORMAT_R8G8B8_SINT",
      "r8g8b8_sint",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8A8_SINT] = {
      PIPE_FORMAT_R8G8B8A8_SINT,
      "PIPE_FORMAT_R8G8B8A8_SINT",
      "r8g8b8a8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_UINT] = {
      PIPE_FORMAT_R16_UINT,
      "PIPE_FORMAT_R16_UINT",
      "r16_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_UINT] = {
      PIPE_FORMAT_R16G16_UINT,
      "PIPE_FORMAT_R16G16_UINT",
      "r16g16_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_UINT] = {
      PIPE_FORMAT_R16G16B16_UINT,
      "PIPE_FORMAT_R16G16B16_UINT",
      "r16g16b16_uint",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_UINT] = {
      PIPE_FORMAT_R16G16B16A16_UINT,
      "PIPE_FORMAT_R16G16B16A16_UINT",
      "r16g16b16a16_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16_SINT] = {
      PIPE_FORMAT_R16_SINT,
      "PIPE_FORMAT_R16_SINT",
      "r16_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16_SINT] = {
      PIPE_FORMAT_R16G16_SINT,
      "PIPE_FORMAT_R16G16_SINT",
      "r16g16_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16_SINT] = {
      PIPE_FORMAT_R16G16B16_SINT,
      "PIPE_FORMAT_R16G16B16_SINT",
      "r16g16b16_sint",
      {1, 1, 1, 48},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 32},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16A16_SINT] = {
      PIPE_FORMAT_R16G16B16A16_SINT,
      "PIPE_FORMAT_R16G16B16A16_SINT",
      "r16g16b16a16_sint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 48}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_UINT] = {
      PIPE_FORMAT_R32_UINT,
      "PIPE_FORMAT_R32_UINT",
      "r32_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_UINT] = {
      PIPE_FORMAT_R32G32_UINT,
      "PIPE_FORMAT_R32G32_UINT",
      "r32g32_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_UINT] = {
      PIPE_FORMAT_R32G32B32_UINT,
      "PIPE_FORMAT_R32G32B32_UINT",
      "r32g32b32_uint",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_UINT] = {
      PIPE_FORMAT_R32G32B32A32_UINT,
      "PIPE_FORMAT_R32G32B32A32_UINT",
      "r32g32b32a32_uint",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32_SINT] = {
      PIPE_FORMAT_R32_SINT,
      "PIPE_FORMAT_R32_SINT",
      "r32_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32_SINT] = {
      PIPE_FORMAT_R32G32_SINT,
      "PIPE_FORMAT_R32G32_SINT",
      "r32g32_sint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32_SINT] = {
      PIPE_FORMAT_R32G32B32_SINT,
      "PIPE_FORMAT_R32G32B32_SINT",
      "r32g32b32_sint",
      {1, 1, 1, 96},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 64},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32A32_SINT] = {
      PIPE_FORMAT_R32G32B32A32_SINT,
      "PIPE_FORMAT_R32G32B32A32_SINT",
      "r32g32b32a32_sint",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 96}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64_UINT] = {
      PIPE_FORMAT_R64_UINT,
      "PIPE_FORMAT_R64_UINT",
      "r64_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64G64_UINT] = {
      PIPE_FORMAT_R64G64_UINT,
      "PIPE_FORMAT_R64G64_UINT",
      "r64g64_uint",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 64},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 64},	/* y = g */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64G64B64_UINT] = {
      PIPE_FORMAT_R64G64B64_UINT,
      "PIPE_FORMAT_R64G64B64_UINT",
      "r64g64b64_uint",
      {1, 1, 1, 192},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 128},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 128},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64G64B64A64_UINT] = {
      PIPE_FORMAT_R64G64B64A64_UINT,
      "PIPE_FORMAT_R64G64B64A64_UINT",
      "r64g64b64a64_uint",
      {1, 1, 1, 256},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 192},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 128},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 128},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 64, 192}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R64_SINT] = {
      PIPE_FORMAT_R64_SINT,
      "PIPE_FORMAT_R64_SINT",
      "r64_sint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 64, 0},	/* x = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8_UINT] = {
      PIPE_FORMAT_A8_UINT,
      "PIPE_FORMAT_A8_UINT",
      "a8_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I8_UINT] = {
      PIPE_FORMAT_I8_UINT,
      "PIPE_FORMAT_I8_UINT",
      "i8_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8_UINT] = {
      PIPE_FORMAT_L8_UINT,
      "PIPE_FORMAT_L8_UINT",
      "l8_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8A8_UINT] = {
      PIPE_FORMAT_L8A8_UINT,
      "PIPE_FORMAT_L8A8_UINT",
      "l8a8_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8_SINT] = {
      PIPE_FORMAT_A8_SINT,
      "PIPE_FORMAT_A8_SINT",
      "a8_sint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I8_SINT] = {
      PIPE_FORMAT_I8_SINT,
      "PIPE_FORMAT_I8_SINT",
      "i8_sint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8_SINT] = {
      PIPE_FORMAT_L8_SINT,
      "PIPE_FORMAT_L8_SINT",
      "l8_sint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L8A8_SINT] = {
      PIPE_FORMAT_L8A8_SINT,
      "PIPE_FORMAT_L8A8_SINT",
      "l8a8_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A16_UINT] = {
      PIPE_FORMAT_A16_UINT,
      "PIPE_FORMAT_A16_UINT",
      "a16_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I16_UINT] = {
      PIPE_FORMAT_I16_UINT,
      "PIPE_FORMAT_I16_UINT",
      "i16_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16_UINT] = {
      PIPE_FORMAT_L16_UINT,
      "PIPE_FORMAT_L16_UINT",
      "l16_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16A16_UINT] = {
      PIPE_FORMAT_L16A16_UINT,
      "PIPE_FORMAT_L16A16_UINT",
      "l16a16_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A16_SINT] = {
      PIPE_FORMAT_A16_SINT,
      "PIPE_FORMAT_A16_SINT",
      "a16_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I16_SINT] = {
      PIPE_FORMAT_I16_SINT,
      "PIPE_FORMAT_I16_SINT",
      "i16_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16_SINT] = {
      PIPE_FORMAT_L16_SINT,
      "PIPE_FORMAT_L16_SINT",
      "l16_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L16A16_SINT] = {
      PIPE_FORMAT_L16A16_SINT,
      "PIPE_FORMAT_L16A16_SINT",
      "l16a16_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A32_UINT] = {
      PIPE_FORMAT_A32_UINT,
      "PIPE_FORMAT_A32_UINT",
      "a32_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I32_UINT] = {
      PIPE_FORMAT_I32_UINT,
      "PIPE_FORMAT_I32_UINT",
      "i32_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L32_UINT] = {
      PIPE_FORMAT_L32_UINT,
      "PIPE_FORMAT_L32_UINT",
      "l32_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L32A32_UINT] = {
      PIPE_FORMAT_L32A32_UINT,
      "PIPE_FORMAT_L32A32_UINT",
      "l32a32_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A32_SINT] = {
      PIPE_FORMAT_A32_SINT,
      "PIPE_FORMAT_A32_SINT",
      "a32_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_0,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_I32_SINT] = {
      PIPE_FORMAT_I32_SINT,
      "PIPE_FORMAT_I32_SINT",
      "i32_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = rgba */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L32_SINT] = {
      PIPE_FORMAT_L32_SINT,
      "PIPE_FORMAT_L32_SINT",
      "l32_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      1,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = rgb */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_L32A32_SINT] = {
      PIPE_FORMAT_L32A32_SINT,
      "PIPE_FORMAT_L32A32_SINT",
      "l32a32_sint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = rgb */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8_UINT] = {
      PIPE_FORMAT_B8G8R8_UINT,
      "PIPE_FORMAT_B8G8R8_UINT",
      "b8g8r8_uint",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8A8_UINT] = {
      PIPE_FORMAT_B8G8R8A8_UINT,
      "PIPE_FORMAT_B8G8R8A8_UINT",
      "b8g8r8a8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8_SINT] = {
      PIPE_FORMAT_B8G8R8_SINT,
      "PIPE_FORMAT_B8G8R8_SINT",
      "b8g8r8_sint",
      {1, 1, 1, 24},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B8G8R8A8_SINT] = {
      PIPE_FORMAT_B8G8R8A8_SINT,
      "PIPE_FORMAT_B8G8R8A8_SINT",
      "b8g8r8a8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8R8G8B8_UINT] = {
      PIPE_FORMAT_A8R8G8B8_UINT,
      "PIPE_FORMAT_A8R8G8B8_UINT",
      "a8r8g8b8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8B8G8R8_UINT] = {
      PIPE_FORMAT_A8B8G8R8_UINT,
      "PIPE_FORMAT_A8B8G8R8_UINT",
      "a8b8g8r8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A2R10G10B10_UINT] = {
      PIPE_FORMAT_A2R10G10B10_UINT,
      "PIPE_FORMAT_A2R10G10B10_UINT",
      "a2r10g10b10_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 22},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 12},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 2},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 2},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 12},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 22}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A2B10G10R10_UINT] = {
      PIPE_FORMAT_A2B10G10R10_UINT,
      "PIPE_FORMAT_A2B10G10R10_UINT",
      "a2b10g10r10_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 22},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 12},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 2},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 2},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 12},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 22}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10A2_UINT] = {
      PIPE_FORMAT_B10G10R10A2_UINT,
      "PIPE_FORMAT_B10G10R10A2_UINT",
      "b10g10r10a2_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10A2_SINT] = {
      PIPE_FORMAT_B10G10R10A2_SINT,
      "PIPE_FORMAT_B10G10R10A2_SINT",
      "b10g10r10a2_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R5G6B5_UINT] = {
      PIPE_FORMAT_R5G6B5_UINT,
      "PIPE_FORMAT_R5G6B5_UINT",
      "r5g6b5_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B5G6R5_UINT] = {
      PIPE_FORMAT_B5G6R5_UINT,
      "PIPE_FORMAT_B5G6R5_UINT",
      "b5g6r5_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R3G3B2_UINT] = {
      PIPE_FORMAT_R3G3B2_UINT,
      "PIPE_FORMAT_R3G3B2_UINT",
      "r3g3b2_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 6},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 3},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 3},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 6},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B2G3R3_UINT] = {
      PIPE_FORMAT_B2G3R3_UINT,
      "PIPE_FORMAT_B2G3R3_UINT",
      "b2g3r3_uint",
      {1, 1, 1, 8},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 5},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 2},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 2},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 3, 5},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R4G4B4A4_UINT] = {
      PIPE_FORMAT_R4G4B4A4_UINT,
      "PIPE_FORMAT_R4G4B4A4_UINT",
      "r4g4b4a4_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B4G4R4A4_UINT] = {
      PIPE_FORMAT_B4G4R4A4_UINT,
      "PIPE_FORMAT_B4G4R4A4_UINT",
      "b4g4r4a4_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A4R4G4B4_UINT] = {
      PIPE_FORMAT_A4R4G4B4_UINT,
      "PIPE_FORMAT_A4R4G4B4_UINT",
      "a4r4g4b4_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A4B4G4R4_UINT] = {
      PIPE_FORMAT_A4B4G4R4_UINT,
      "PIPE_FORMAT_A4B4G4R4_UINT",
      "a4b4g4r4_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 4},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 4, 12}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A1R5G5B5_UINT] = {
      PIPE_FORMAT_A1R5G5B5_UINT,
      "PIPE_FORMAT_A1R5G5B5_UINT",
      "a1r5g5b5_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 6},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 1},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 1},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 6},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11}	/* w = b */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A1B5G5R5_UINT] = {
      PIPE_FORMAT_A1B5G5R5_UINT,
      "PIPE_FORMAT_A1B5G5R5_UINT",
      "a1b5g5r5_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 6},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 1},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 0}	/* w = a */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 1},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 6},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 11}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R5G5B5A1_UINT] = {
      PIPE_FORMAT_R5G5B5A1_UINT,
      "PIPE_FORMAT_R5G5B5A1_UINT",
      "r5g5b5a1_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 15},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 10},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 5},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 10},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 15}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B5G5R5A1_UINT] = {
      PIPE_FORMAT_B5G5R5A1_UINT,
      "PIPE_FORMAT_B5G5R5A1_UINT",
      "b5g5r5a1_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 15},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 10},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 5},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 5, 10},	/* z = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 1, 15}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8X8_SNORM] = {
      PIPE_FORMAT_R8G8B8X8_SNORM,
      "PIPE_FORMAT_R8G8B8X8_SNORM",
      "r8g8b8x8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8X8_SRGB] = {
      PIPE_FORMAT_R8G8B8X8_SRGB,
      "PIPE_FORMAT_R8G8B8X8_SRGB",
      "r8g8b8x8_srgb",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R8G8B8X8_UINT] = {
      PIPE_FORMAT_R8G8B8X8_UINT,
      "PIPE_FORMAT_R8G8B8X8_UINT",
      "r8g8b8x8_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8G8B8X8_SINT] = {
      PIPE_FORMAT_R8G8B8X8_SINT,
      "PIPE_FORMAT_R8G8B8X8_SINT",
      "r8g8b8x8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10X2_UNORM] = {
      PIPE_FORMAT_B10G10R10X2_UNORM,
      "PIPE_FORMAT_B10G10R10X2_UNORM",
      "b10g10r10x2_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30},	/* x = x */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B10G10R10X2_SNORM] = {
      PIPE_FORMAT_B10G10R10X2_SNORM,
      "PIPE_FORMAT_B10G10R10X2_SNORM",
      "b10g10r10x2_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* y = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0}	/* w = b */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 10, 20},	/* z = r */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 2, 30}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_W,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_X,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16X16_UNORM] = {
      PIPE_FORMAT_R16G16B16X16_UNORM,
      "PIPE_FORMAT_R16G16B16X16_UNORM",
      "r16g16b16x16_unorm",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 48}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16X16_SNORM] = {
      PIPE_FORMAT_R16G16B16X16_SNORM,
      "PIPE_FORMAT_R16G16B16X16_SNORM",
      "r16g16b16x16_snorm",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 48}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16X16_FLOAT] = {
      PIPE_FORMAT_R16G16B16X16_FLOAT,
      "PIPE_FORMAT_R16G16B16X16_FLOAT",
      "r16g16b16x16_float",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 48}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16X16_UINT] = {
      PIPE_FORMAT_R16G16B16X16_UINT,
      "PIPE_FORMAT_R16G16B16X16_UINT",
      "r16g16b16x16_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 48}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16G16B16X16_SINT] = {
      PIPE_FORMAT_R16G16B16X16_SINT,
      "PIPE_FORMAT_R16G16B16X16_SINT",
      "r16g16b16x16_sint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 48},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 16, 48}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32X32_FLOAT] = {
      PIPE_FORMAT_R32G32B32X32_FLOAT,
      "PIPE_FORMAT_R32G32B32X32_FLOAT",
      "r32g32b32x32_float",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 96}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32X32_UINT] = {
      PIPE_FORMAT_R32G32B32X32_UINT,
      "PIPE_FORMAT_R32G32B32X32_UINT",
      "r32g32b32x32_uint",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 96}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32G32B32X32_SINT] = {
      PIPE_FORMAT_R32G32B32X32_SINT,
      "PIPE_FORMAT_R32G32B32X32_SINT",
      "r32g32b32x32_sint",
      {1, 1, 1, 128},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 96},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 64},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 0}	/* w = x */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 64},	/* z = b */
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 32, 96}	/* w = x */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8A8_SNORM] = {
      PIPE_FORMAT_R8A8_SNORM,
      "PIPE_FORMAT_R8A8_SNORM",
      "r8a8_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16A16_UNORM] = {
      PIPE_FORMAT_R16A16_UNORM,
      "PIPE_FORMAT_R16A16_UNORM",
      "r16a16_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16A16_SNORM] = {
      PIPE_FORMAT_R16A16_SNORM,
      "PIPE_FORMAT_R16A16_SNORM",
      "r16a16_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16A16_FLOAT] = {
      PIPE_FORMAT_R16A16_FLOAT,
      "PIPE_FORMAT_R16A16_FLOAT",
      "r16a16_float",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32A32_FLOAT] = {
      PIPE_FORMAT_R32A32_FLOAT,
      "PIPE_FORMAT_R32A32_FLOAT",
      "r32a32_float",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_FLOAT, FALSE, FALSE, 32, 32},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8A8_UINT] = {
      PIPE_FORMAT_R8A8_UINT,
      "PIPE_FORMAT_R8A8_UINT",
      "r8a8_uint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R8A8_SINT] = {
      PIPE_FORMAT_R8A8_SINT,
      "PIPE_FORMAT_R8A8_SINT",
      "r8a8_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16A16_UINT] = {
      PIPE_FORMAT_R16A16_UINT,
      "PIPE_FORMAT_R16A16_UINT",
      "r16a16_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R16A16_SINT] = {
      PIPE_FORMAT_R16A16_SINT,
      "PIPE_FORMAT_R16A16_SINT",
      "r16a16_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 16, 16},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32A32_UINT] = {
      PIPE_FORMAT_R32A32_UINT,
      "PIPE_FORMAT_R32A32_UINT",
      "r32a32_uint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 32, 32},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R32A32_SINT] = {
      PIPE_FORMAT_R32A32_SINT,
      "PIPE_FORMAT_R32A32_SINT",
      "r32a32_sint",
      {1, 1, 1, 64},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      FALSE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 32, 32},	/* y = a */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_0,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_Y	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10A2_UINT] = {
      PIPE_FORMAT_R10G10B10A2_UINT,
      "PIPE_FORMAT_R10G10B10A2_UINT",
      "r10g10b10a2_uint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, FALSE, TRUE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_R10G10B10A2_SINT] = {
      PIPE_FORMAT_R10G10B10A2_SINT,
      "PIPE_FORMAT_R10G10B10A2_SINT",
      "r10g10b10a2_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 2, 30},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 20},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 10},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 10},	/* y = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 10, 20},	/* z = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 2, 30}	/* w = a */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* r */
      PIPE_SWIZZLE_Y,	/* g */
      PIPE_SWIZZLE_Z,	/* b */
      PIPE_SWIZZLE_W	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_B5G6R5_SRGB] = {
      PIPE_FORMAT_B5G6R5_SRGB,
      "PIPE_FORMAT_B5G6R5_SRGB",
      "b5g6r5_srgb",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_R5G6B5_SRGB] = {
      PIPE_FORMAT_R5G6B5_SRGB,
      "PIPE_FORMAT_R5G6B5_SRGB",
      "r5g6b5_srgb",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      3,	/* nr_channels */
      FALSE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* x = b */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* z = r */
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 0},	/* x = r */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 6, 5},	/* y = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 5, 11},	/* z = b */
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Z,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_X,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_X,	/* sr */
      PIPE_SWIZZLE_Y,	/* sg */
      PIPE_SWIZZLE_Z,	/* sb */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_SRGB,
   },

   [PIPE_FORMAT_G8R8_UNORM] = {
      PIPE_FORMAT_G8R8_UNORM,
      "PIPE_FORMAT_G8R8_UNORM",
      "g8r8_unorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* x = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 0},	/* x = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_G8R8_SNORM] = {
      PIPE_FORMAT_G8R8_SNORM,
      "PIPE_FORMAT_G8R8_SNORM",
      "g8r8_snorm",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* x = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_G8R8_SINT] = {
      PIPE_FORMAT_G8R8_SINT,
      "PIPE_FORMAT_G8R8_SINT",
      "g8r8_sint",
      {1, 1, 1, 16},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* x = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_G16R16_UNORM] = {
      PIPE_FORMAT_G16R16_UNORM,
      "PIPE_FORMAT_G16R16_UNORM",
      "g16r16_unorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      TRUE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* x = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 0},	/* x = g */
      {UTIL_FORMAT_TYPE_UNSIGNED, TRUE, FALSE, 16, 16},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_G16R16_SNORM] = {
      PIPE_FORMAT_G16R16_SNORM,
      "PIPE_FORMAT_G16R16_SNORM",
      "g16r16_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      2,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* x = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 0},	/* x = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 16, 16},	/* y = r */
      {0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0}
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_Y,	/* r */
      PIPE_SWIZZLE_X,	/* g */
      PIPE_SWIZZLE_0,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8B8G8R8_SNORM] = {
      PIPE_FORMAT_A8B8G8R8_SNORM,
      "PIPE_FORMAT_A8B8G8R8_SNORM",
      "a8b8g8r8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_A8B8G8R8_SINT] = {
      PIPE_FORMAT_A8B8G8R8_SINT,
      "PIPE_FORMAT_A8B8G8R8_SINT",
      "a8b8g8r8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0},	/* x = a */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_X	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X8B8G8R8_SNORM] = {
      PIPE_FORMAT_X8B8G8R8_SNORM,
      "PIPE_FORMAT_X8B8G8R8_SNORM",
      "x8b8g8r8_snorm",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      TRUE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, TRUE, FALSE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

   [PIPE_FORMAT_X8B8G8R8_SINT] = {
      PIPE_FORMAT_X8B8G8R8_SINT,
      "PIPE_FORMAT_X8B8G8R8_SINT",
      "x8b8g8r8_sint",
      {1, 1, 1, 32},	/* block */
      UTIL_FORMAT_LAYOUT_PLAIN,
      4,	/* nr_channels */
      TRUE,	/* is_array */
      TRUE,	/* is_bitmask */
      FALSE,	/* is_mixed */
      FALSE,	/* is_unorm */
      FALSE,	/* is_snorm */
#if UTIL_ARCH_BIG_ENDIAN
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 24},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 0}	/* w = r */
   },
#else
   {
      {UTIL_FORMAT_TYPE_VOID, FALSE, FALSE, 8, 0},	/* x = x */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 8},	/* y = b */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 16},	/* z = g */
      {UTIL_FORMAT_TYPE_SIGNED, FALSE, TRUE, 8, 24}	/* w = r */
   },
#endif
#if UTIL_ARCH_BIG_ENDIAN
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#else
   {
      PIPE_SWIZZLE_W,	/* r */
      PIPE_SWIZZLE_Z,	/* g */
      PIPE_SWIZZLE_Y,	/* b */
      PIPE_SWIZZLE_1	/* a */
   },
#endif
      UTIL_FORMAT_COLORSPACE_RGB,
   },

};

const struct util_format_description *
util_format_description(enum pipe_format format)
{
   if (format >= ARRAY_SIZE(util_format_descriptions))
      return NULL;

   return &util_format_descriptions[format];
}

static const struct util_format_pack_description
util_format_pack_descriptions[] = {
   [PIPE_FORMAT_NONE] = {
      .pack_rgba_8unorm = &util_format_none_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_none_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8A8_UNORM] = {
      .pack_rgba_8unorm = &util_format_b8g8r8a8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8a8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8X8_UNORM] = {
      .pack_rgba_8unorm = &util_format_b8g8r8x8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8x8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8X8_SNORM] = {
      .pack_rgba_8unorm = &util_format_b8g8r8x8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8x8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8X8_UINT] = {
      .pack_rgba_uint = &util_format_b8g8r8x8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b8g8r8x8_uint_pack_signed,
   },

   [PIPE_FORMAT_B8G8R8X8_SINT] = {
      .pack_rgba_uint = &util_format_b8g8r8x8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_b8g8r8x8_sint_pack_signed,
   },

   [PIPE_FORMAT_A8R8G8B8_UNORM] = {
      .pack_rgba_8unorm = &util_format_a8r8g8b8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8r8g8b8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8R8G8B8_SNORM] = {
      .pack_rgba_8unorm = &util_format_a8r8g8b8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8r8g8b8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8R8G8B8_SINT] = {
      .pack_rgba_uint = &util_format_a8r8g8b8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_a8r8g8b8_sint_pack_signed,
   },

   [PIPE_FORMAT_X8R8G8B8_UNORM] = {
      .pack_rgba_8unorm = &util_format_x8r8g8b8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x8r8g8b8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_X8R8G8B8_SNORM] = {
      .pack_rgba_8unorm = &util_format_x8r8g8b8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x8r8g8b8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_X8R8G8B8_SINT] = {
      .pack_rgba_uint = &util_format_x8r8g8b8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_x8r8g8b8_sint_pack_signed,
   },

   [PIPE_FORMAT_A8B8G8R8_UNORM] = {
      .pack_rgba_8unorm = &util_format_a8b8g8r8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8b8g8r8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_X8B8G8R8_UNORM] = {
      .pack_rgba_8unorm = &util_format_x8b8g8r8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x8b8g8r8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8X8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8b8x8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8x8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R5G5B5A1_UNORM] = {
      .pack_rgba_8unorm = &util_format_r5g5b5a1_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r5g5b5a1_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R5G5B5X1_UNORM] = {
      .pack_rgba_8unorm = &util_format_r5g5b5x1_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r5g5b5x1_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B5G5R5X1_UNORM] = {
      .pack_rgba_8unorm = &util_format_b5g5r5x1_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b5g5r5x1_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B5G5R5A1_UNORM] = {
      .pack_rgba_8unorm = &util_format_b5g5r5a1_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b5g5r5a1_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_X1B5G5R5_UNORM] = {
      .pack_rgba_8unorm = &util_format_x1b5g5r5_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x1b5g5r5_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A1R5G5B5_UNORM] = {
      .pack_rgba_8unorm = &util_format_a1r5g5b5_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a1r5g5b5_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_X1R5G5B5_UNORM] = {
      .pack_rgba_8unorm = &util_format_x1r5g5b5_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x1r5g5b5_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A1B5G5R5_UNORM] = {
      .pack_rgba_8unorm = &util_format_a1b5g5r5_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a1b5g5r5_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R4G4B4A4_UNORM] = {
      .pack_rgba_8unorm = &util_format_r4g4b4a4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r4g4b4a4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R4G4B4X4_UNORM] = {
      .pack_rgba_8unorm = &util_format_r4g4b4x4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r4g4b4x4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B4G4R4A4_UNORM] = {
      .pack_rgba_8unorm = &util_format_b4g4r4a4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b4g4r4a4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B4G4R4X4_UNORM] = {
      .pack_rgba_8unorm = &util_format_b4g4r4x4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b4g4r4x4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A4R4G4B4_UNORM] = {
      .pack_rgba_8unorm = &util_format_a4r4g4b4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a4r4g4b4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A4B4G4R4_UNORM] = {
      .pack_rgba_8unorm = &util_format_a4b4g4r4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a4b4g4r4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R5G6B5_UNORM] = {
      .pack_rgba_8unorm = &util_format_r5g6b5_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r5g6b5_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B5G6R5_UNORM] = {
      .pack_rgba_8unorm = &util_format_b5g6r5_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b5g6r5_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10A2_UNORM] = {
      .pack_rgba_8unorm = &util_format_r10g10b10a2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10a2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10X2_UNORM] = {
      .pack_rgba_8unorm = &util_format_r10g10b10x2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10x2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B10G10R10A2_UNORM] = {
      .pack_rgba_8unorm = &util_format_b10g10r10a2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b10g10r10a2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A2R10G10B10_UNORM] = {
      .pack_rgba_8unorm = &util_format_a2r10g10b10_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a2r10g10b10_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A2B10G10R10_UNORM] = {
      .pack_rgba_8unorm = &util_format_a2b10g10r10_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a2b10g10r10_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R3G3B2_UNORM] = {
      .pack_rgba_8unorm = &util_format_r3g3b2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r3g3b2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B2G3R3_UNORM] = {
      .pack_rgba_8unorm = &util_format_b2g3r3_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b2g3r3_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L8_UNORM] = {
      .pack_rgba_8unorm = &util_format_l8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8_UNORM] = {
      .pack_rgba_8unorm = &util_format_a8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_I8_UNORM] = {
      .pack_rgba_8unorm = &util_format_i8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_i8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L4A4_UNORM] = {
      .pack_rgba_8unorm = &util_format_l4a4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l4a4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L8A8_UNORM] = {
      .pack_rgba_8unorm = &util_format_l8a8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l8a8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L16_UNORM] = {
      .pack_rgba_8unorm = &util_format_l16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A16_UNORM] = {
      .pack_rgba_8unorm = &util_format_a16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_I16_UNORM] = {
      .pack_rgba_8unorm = &util_format_i16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_i16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L16A16_UNORM] = {
      .pack_rgba_8unorm = &util_format_l16a16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l16a16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8_SNORM] = {
      .pack_rgba_8unorm = &util_format_a8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L8_SNORM] = {
      .pack_rgba_8unorm = &util_format_l8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L8A8_SNORM] = {
      .pack_rgba_8unorm = &util_format_l8a8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l8a8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_I8_SNORM] = {
      .pack_rgba_8unorm = &util_format_i8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_i8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A16_SNORM] = {
      .pack_rgba_8unorm = &util_format_a16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L16_SNORM] = {
      .pack_rgba_8unorm = &util_format_l16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_L16A16_SNORM] = {
      .pack_rgba_8unorm = &util_format_l16a16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l16a16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_I16_SNORM] = {
      .pack_rgba_8unorm = &util_format_i16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_i16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_a16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_L16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_l16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_L16A16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_l16a16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l16a16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_I16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_i16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_i16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_A32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_a32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_L32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_l32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_L32A32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_l32a32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l32a32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_I32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_i32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_i32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_L8_SRGB] = {
      .pack_rgba_8unorm = &util_format_l8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R8_SRGB] = {
      .pack_rgba_8unorm = &util_format_r8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_L8A8_SRGB] = {
      .pack_rgba_8unorm = &util_format_l8a8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_l8a8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8_SRGB] = {
      .pack_rgba_8unorm = &util_format_r8g8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8_SRGB] = {
      .pack_rgba_8unorm = &util_format_r8g8b8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8_SRGB] = {
      .pack_rgba_8unorm = &util_format_b8g8r8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8A8_SRGB] = {
      .pack_rgba_8unorm = &util_format_r8g8b8a8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8a8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_A8B8G8R8_SRGB] = {
      .pack_rgba_8unorm = &util_format_a8b8g8r8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8b8g8r8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_X8B8G8R8_SRGB] = {
      .pack_rgba_8unorm = &util_format_x8b8g8r8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x8b8g8r8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8A8_SRGB] = {
      .pack_rgba_8unorm = &util_format_b8g8r8a8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8a8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8X8_SRGB] = {
      .pack_rgba_8unorm = &util_format_b8g8r8x8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8x8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_A8R8G8B8_SRGB] = {
      .pack_rgba_8unorm = &util_format_a8r8g8b8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8r8g8b8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_X8R8G8B8_SRGB] = {
      .pack_rgba_8unorm = &util_format_x8r8g8b8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x8r8g8b8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R8SG8SB8UX8U_NORM] = {
      .pack_rgba_8unorm = &util_format_r8sg8sb8ux8u_norm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8sg8sb8ux8u_norm_pack_rgba_float,
   },

   [PIPE_FORMAT_R10SG10SB10SA2U_NORM] = {
      .pack_rgba_8unorm = &util_format_r10sg10sb10sa2u_norm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10sg10sb10sa2u_norm_pack_rgba_float,
   },

   [PIPE_FORMAT_R5SG5SB6U_NORM] = {
      .pack_rgba_8unorm = &util_format_r5sg5sb6u_norm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r5sg5sb6u_norm_pack_rgba_float,
   },

   [PIPE_FORMAT_S8_UINT] = {
      .pack_s_8uint = &util_format_s8_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_Z16_UNORM] = {
      .pack_z_32unorm = &util_format_z16_unorm_pack_z_32unorm,
      .pack_z_float = &util_format_z16_unorm_pack_z_float,
   },

   [PIPE_FORMAT_Z16_UNORM_S8_UINT] = {
      .pack_z_32unorm = &util_format_z16_unorm_s8_uint_pack_z_32unorm,
      .pack_z_float = &util_format_z16_unorm_s8_uint_pack_z_float,
      .pack_s_8uint = &util_format_z16_unorm_s8_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_Z32_UNORM] = {
      .pack_z_32unorm = &util_format_z32_unorm_pack_z_32unorm,
      .pack_z_float = &util_format_z32_unorm_pack_z_float,
   },

   [PIPE_FORMAT_Z32_FLOAT] = {
      .pack_z_32unorm = &util_format_z32_float_pack_z_32unorm,
      .pack_z_float = &util_format_z32_float_pack_z_float,
   },

   [PIPE_FORMAT_Z24_UNORM_S8_UINT] = {
      .pack_z_32unorm = &util_format_z24_unorm_s8_uint_pack_z_32unorm,
      .pack_z_float = &util_format_z24_unorm_s8_uint_pack_z_float,
      .pack_s_8uint = &util_format_z24_unorm_s8_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_S8_UINT_Z24_UNORM] = {
      .pack_z_32unorm = &util_format_s8_uint_z24_unorm_pack_z_32unorm,
      .pack_z_float = &util_format_s8_uint_z24_unorm_pack_z_float,
      .pack_s_8uint = &util_format_s8_uint_z24_unorm_pack_s_8uint,
   },

   [PIPE_FORMAT_X24S8_UINT] = {
      .pack_s_8uint = &util_format_x24s8_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_S8X24_UINT] = {
      .pack_s_8uint = &util_format_s8x24_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_Z24X8_UNORM] = {
      .pack_z_32unorm = &util_format_z24x8_unorm_pack_z_32unorm,
      .pack_z_float = &util_format_z24x8_unorm_pack_z_float,
   },

   [PIPE_FORMAT_X8Z24_UNORM] = {
      .pack_z_32unorm = &util_format_x8z24_unorm_pack_z_32unorm,
      .pack_z_float = &util_format_x8z24_unorm_pack_z_float,
   },

   [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = {
      .pack_z_32unorm = &util_format_z32_float_s8x24_uint_pack_z_32unorm,
      .pack_z_float = &util_format_z32_float_s8x24_uint_pack_z_float,
      .pack_s_8uint = &util_format_z32_float_s8x24_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_X32_S8X24_UINT] = {
      .pack_s_8uint = &util_format_x32_s8x24_uint_pack_s_8uint,
   },

   [PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8] = {
      .pack_rgba_8unorm = &util_format_z24_unorm_s8_uint_as_r8g8b8a8_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_z24_unorm_s8_uint_as_r8g8b8a8_pack_rgba_float,
   },

   [PIPE_FORMAT_UYVY] = {
      .pack_rgba_8unorm = &util_format_uyvy_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_uyvy_pack_rgba_float,
   },

   [PIPE_FORMAT_YUYV] = {
      .pack_rgba_8unorm = &util_format_yuyv_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_yuyv_pack_rgba_float,
   },

   [PIPE_FORMAT_AYUV] = { 0 },
   [PIPE_FORMAT_XYUV] = { 0 },
   [PIPE_FORMAT_R8G8_B8G8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8_b8g8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8_b8g8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_G8R8_G8B8_UNORM] = { 0 },
   [PIPE_FORMAT_G8R8_B8R8_UNORM] = { 0 },
   [PIPE_FORMAT_R8G8_R8B8_UNORM] = { 0 },
   [PIPE_FORMAT_R11G11B10_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r11g11b10_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r11g11b10_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R9G9B9E5_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r9g9b9e5_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r9g9b9e5_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R1_UNORM] = { 0 },
   [PIPE_FORMAT_R8G8Bx_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8bx_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8bx_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT1_RGB] = {
      .pack_rgba_8unorm = &util_format_dxt1_rgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt1_rgb_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT1_RGBA] = {
      .pack_rgba_8unorm = &util_format_dxt1_rgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt1_rgba_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT3_RGBA] = {
      .pack_rgba_8unorm = &util_format_dxt3_rgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt3_rgba_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT5_RGBA] = {
      .pack_rgba_8unorm = &util_format_dxt5_rgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt5_rgba_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT1_SRGB] = {
      .pack_rgba_8unorm = &util_format_dxt1_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt1_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT1_SRGBA] = {
      .pack_rgba_8unorm = &util_format_dxt1_srgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt1_srgba_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT3_SRGBA] = {
      .pack_rgba_8unorm = &util_format_dxt3_srgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt3_srgba_pack_rgba_float,
   },

   [PIPE_FORMAT_DXT5_SRGBA] = {
      .pack_rgba_8unorm = &util_format_dxt5_srgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_dxt5_srgba_pack_rgba_float,
   },

   [PIPE_FORMAT_FXT1_RGB] = {
      .pack_rgba_8unorm = &util_format_fxt1_rgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_fxt1_rgb_pack_rgba_float,
   },

   [PIPE_FORMAT_FXT1_RGBA] = {
      .pack_rgba_8unorm = &util_format_fxt1_rgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_fxt1_rgba_pack_rgba_float,
   },

   [PIPE_FORMAT_RGTC1_UNORM] = {
      .pack_rgba_8unorm = &util_format_rgtc1_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_rgtc1_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_RGTC1_SNORM] = {
      .pack_rgba_8unorm = &util_format_rgtc1_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_rgtc1_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_RGTC2_UNORM] = {
      .pack_rgba_8unorm = &util_format_rgtc2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_rgtc2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_RGTC2_SNORM] = {
      .pack_rgba_8unorm = &util_format_rgtc2_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_rgtc2_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_LATC1_UNORM] = {
      .pack_rgba_8unorm = &util_format_latc1_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_latc1_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_LATC1_SNORM] = {
      .pack_rgba_8unorm = &util_format_latc1_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_latc1_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_LATC2_UNORM] = {
      .pack_rgba_8unorm = &util_format_latc2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_latc2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_LATC2_SNORM] = {
      .pack_rgba_8unorm = &util_format_latc2_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_latc2_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_ETC1_RGB8] = {
      .pack_rgba_8unorm = &util_format_etc1_rgb8_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_etc1_rgb8_pack_rgba_float,
   },

   [PIPE_FORMAT_ETC2_RGB8] = { 0 },
   [PIPE_FORMAT_ETC2_SRGB8] = { 0 },
   [PIPE_FORMAT_ETC2_RGB8A1] = { 0 },
   [PIPE_FORMAT_ETC2_SRGB8A1] = { 0 },
   [PIPE_FORMAT_ETC2_RGBA8] = { 0 },
   [PIPE_FORMAT_ETC2_SRGBA8] = { 0 },
   [PIPE_FORMAT_ETC2_R11_UNORM] = { 0 },
   [PIPE_FORMAT_ETC2_R11_SNORM] = { 0 },
   [PIPE_FORMAT_ETC2_RG11_UNORM] = { 0 },
   [PIPE_FORMAT_ETC2_RG11_SNORM] = { 0 },
   [PIPE_FORMAT_BPTC_RGBA_UNORM] = {
      .pack_rgba_8unorm = &util_format_bptc_rgba_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_bptc_rgba_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_BPTC_SRGBA] = {
      .pack_rgba_8unorm = &util_format_bptc_srgba_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_bptc_srgba_pack_rgba_float,
   },

   [PIPE_FORMAT_BPTC_RGB_FLOAT] = {
      .pack_rgba_8unorm = &util_format_bptc_rgb_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_bptc_rgb_float_pack_rgba_float,
   },

   [PIPE_FORMAT_BPTC_RGB_UFLOAT] = {
      .pack_rgba_8unorm = &util_format_bptc_rgb_ufloat_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_bptc_rgb_ufloat_pack_rgba_float,
   },

   [PIPE_FORMAT_ASTC_4x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x6] = { 0 },
   [PIPE_FORMAT_ASTC_8x5] = { 0 },
   [PIPE_FORMAT_ASTC_8x6] = { 0 },
   [PIPE_FORMAT_ASTC_8x8] = { 0 },
   [PIPE_FORMAT_ASTC_10x5] = { 0 },
   [PIPE_FORMAT_ASTC_10x6] = { 0 },
   [PIPE_FORMAT_ASTC_10x8] = { 0 },
   [PIPE_FORMAT_ASTC_10x10] = { 0 },
   [PIPE_FORMAT_ASTC_12x10] = { 0 },
   [PIPE_FORMAT_ASTC_12x12] = { 0 },
   [PIPE_FORMAT_ASTC_4x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x6_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_8x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_8x6_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_8x8_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x6_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x8_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x10_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_12x10_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_12x12_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_3x3x3] = { 0 },
   [PIPE_FORMAT_ASTC_4x3x3] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x3] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x4x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x5x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x6] = { 0 },
   [PIPE_FORMAT_ASTC_3x3x3_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_4x3x3_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x3_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x4x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x5x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x6_SRGB] = { 0 },
   [PIPE_FORMAT_ATC_RGB] = { 0 },
   [PIPE_FORMAT_ATC_RGBA_EXPLICIT] = { 0 },
   [PIPE_FORMAT_ATC_RGBA_INTERPOLATED] = { 0 },
   [PIPE_FORMAT_R64_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r64_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r64_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R64G64_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r64g64_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r64g64_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R64G64B64_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r64g64b64_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r64g64b64_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R64G64B64A64_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r64g64b64a64_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r64g64b64a64_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r32g32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r32g32b32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32A32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r32g32b32a32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32a32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32_UNORM] = {
      .pack_rgba_8unorm = &util_format_r32_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32_UNORM] = {
      .pack_rgba_8unorm = &util_format_r32g32_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32_UNORM] = {
      .pack_rgba_8unorm = &util_format_r32g32b32_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32A32_UNORM] = {
      .pack_rgba_8unorm = &util_format_r32g32b32a32_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32a32_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32_USCALED] = {
      .pack_rgba_8unorm = &util_format_r32_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32_USCALED] = {
      .pack_rgba_8unorm = &util_format_r32g32_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32_USCALED] = {
      .pack_rgba_8unorm = &util_format_r32g32b32_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32A32_USCALED] = {
      .pack_rgba_8unorm = &util_format_r32g32b32a32_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32a32_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32_SNORM] = {
      .pack_rgba_8unorm = &util_format_r32_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32_SNORM] = {
      .pack_rgba_8unorm = &util_format_r32g32_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32_SNORM] = {
      .pack_rgba_8unorm = &util_format_r32g32b32_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32A32_SNORM] = {
      .pack_rgba_8unorm = &util_format_r32g32b32a32_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32a32_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R32_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r32_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r32g32_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r32g32b32_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32A32_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r32g32b32a32_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32a32_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r16g16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r16g16b16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16A16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r16g16b16a16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16a16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R16_UNORM] = {
      .pack_rgba_8unorm = &util_format_r16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16_UNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16_UNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16b16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16A16_UNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16b16a16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16a16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16_USCALED] = {
      .pack_rgba_8unorm = &util_format_r16_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16_USCALED] = {
      .pack_rgba_8unorm = &util_format_r16g16_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16_USCALED] = {
      .pack_rgba_8unorm = &util_format_r16g16b16_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16A16_USCALED] = {
      .pack_rgba_8unorm = &util_format_r16g16b16a16_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16a16_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16_SNORM] = {
      .pack_rgba_8unorm = &util_format_r16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16_SNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16_SNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16b16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16A16_SNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16b16a16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16a16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r16_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r16g16_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r16g16b16_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16A16_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r16g16b16a16_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16a16_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8b8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8_UNORM] = {
      .pack_rgba_8unorm = &util_format_b8g8r8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8A8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8b8a8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8a8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8_USCALED] = {
      .pack_rgba_8unorm = &util_format_r8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8_USCALED] = {
      .pack_rgba_8unorm = &util_format_r8g8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8_USCALED] = {
      .pack_rgba_8unorm = &util_format_r8g8b8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8_USCALED] = {
      .pack_rgba_8unorm = &util_format_b8g8r8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8A8_USCALED] = {
      .pack_rgba_8unorm = &util_format_r8g8b8a8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8a8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8A8_USCALED] = {
      .pack_rgba_8unorm = &util_format_b8g8r8a8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8a8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_A8B8G8R8_USCALED] = {
      .pack_rgba_8unorm = &util_format_a8b8g8r8_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8b8g8r8_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8b8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8_SNORM] = {
      .pack_rgba_8unorm = &util_format_b8g8r8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8A8_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8b8a8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8a8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8A8_SNORM] = {
      .pack_rgba_8unorm = &util_format_b8g8r8a8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8a8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r8g8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r8g8b8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_b8g8r8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8A8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r8g8b8a8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8a8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_B8G8R8A8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_b8g8r8a8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b8g8r8a8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_A8B8G8R8_SSCALED] = {
      .pack_rgba_8unorm = &util_format_a8b8g8r8_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8b8g8r8_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R32_FIXED] = {
      .pack_rgba_8unorm = &util_format_r32_fixed_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32_fixed_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32_FIXED] = {
      .pack_rgba_8unorm = &util_format_r32g32_fixed_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32_fixed_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32_FIXED] = {
      .pack_rgba_8unorm = &util_format_r32g32b32_fixed_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32_fixed_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32A32_FIXED] = {
      .pack_rgba_8unorm = &util_format_r32g32b32a32_fixed_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32a32_fixed_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10X2_USCALED] = {
      .pack_rgba_8unorm = &util_format_r10g10b10x2_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10x2_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10X2_SNORM] = {
      .pack_rgba_8unorm = &util_format_r10g10b10x2_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10x2_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_YV12] = { 0 },
   [PIPE_FORMAT_YV16] = { 0 },
   [PIPE_FORMAT_IYUV] = { 0 },
   [PIPE_FORMAT_NV12] = { 0 },
   [PIPE_FORMAT_NV21] = { 0 },
   [PIPE_FORMAT_R8_G8B8_420_UNORM] = { 0 },
   [PIPE_FORMAT_R8_G8_B8_420_UNORM] = { 0 },
   [PIPE_FORMAT_Y8_U8_V8_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y8_U8V8_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y8_U8_V8_444_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16_V16_420_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16_V16_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16V16_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16_V16_444_UNORM] = { 0 },
   [PIPE_FORMAT_P010] = { 0 },
   [PIPE_FORMAT_P012] = { 0 },
   [PIPE_FORMAT_P016] = { 0 },
   [PIPE_FORMAT_Y210] = { 0 },
   [PIPE_FORMAT_Y212] = { 0 },
   [PIPE_FORMAT_Y216] = { 0 },
   [PIPE_FORMAT_Y410] = { 0 },
   [PIPE_FORMAT_Y412] = { 0 },
   [PIPE_FORMAT_Y416] = { 0 },
   [PIPE_FORMAT_A4R4_UNORM] = {
      .pack_rgba_8unorm = &util_format_a4r4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a4r4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R4A4_UNORM] = {
      .pack_rgba_8unorm = &util_format_r4a4_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r4a4_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8A8_UNORM] = {
      .pack_rgba_8unorm = &util_format_r8a8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8a8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8R8_UNORM] = {
      .pack_rgba_8unorm = &util_format_a8r8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8r8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10A2_USCALED] = {
      .pack_rgba_8unorm = &util_format_r10g10b10a2_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10a2_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10A2_SSCALED] = {
      .pack_rgba_8unorm = &util_format_r10g10b10a2_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10a2_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_R10G10B10A2_SNORM] = {
      .pack_rgba_8unorm = &util_format_r10g10b10a2_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r10g10b10a2_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B10G10R10A2_USCALED] = {
      .pack_rgba_8unorm = &util_format_b10g10r10a2_uscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b10g10r10a2_uscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_B10G10R10A2_SSCALED] = {
      .pack_rgba_8unorm = &util_format_b10g10r10a2_sscaled_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b10g10r10a2_sscaled_pack_rgba_float,
   },

   [PIPE_FORMAT_B10G10R10A2_SNORM] = {
      .pack_rgba_8unorm = &util_format_b10g10r10a2_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b10g10r10a2_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8_UINT] = {
      .pack_rgba_uint = &util_format_r8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8_uint_pack_signed,
   },

   [PIPE_FORMAT_R8G8_UINT] = {
      .pack_rgba_uint = &util_format_r8g8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8_uint_pack_signed,
   },

   [PIPE_FORMAT_R8G8B8_UINT] = {
      .pack_rgba_uint = &util_format_r8g8b8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8b8_uint_pack_signed,
   },

   [PIPE_FORMAT_R8G8B8A8_UINT] = {
      .pack_rgba_uint = &util_format_r8g8b8a8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8b8a8_uint_pack_signed,
   },

   [PIPE_FORMAT_R8_SINT] = {
      .pack_rgba_uint = &util_format_r8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8_sint_pack_signed,
   },

   [PIPE_FORMAT_R8G8_SINT] = {
      .pack_rgba_uint = &util_format_r8g8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8_sint_pack_signed,
   },

   [PIPE_FORMAT_R8G8B8_SINT] = {
      .pack_rgba_uint = &util_format_r8g8b8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8b8_sint_pack_signed,
   },

   [PIPE_FORMAT_R8G8B8A8_SINT] = {
      .pack_rgba_uint = &util_format_r8g8b8a8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8b8a8_sint_pack_signed,
   },

   [PIPE_FORMAT_R16_UINT] = {
      .pack_rgba_uint = &util_format_r16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16_uint_pack_signed,
   },

   [PIPE_FORMAT_R16G16_UINT] = {
      .pack_rgba_uint = &util_format_r16g16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16_uint_pack_signed,
   },

   [PIPE_FORMAT_R16G16B16_UINT] = {
      .pack_rgba_uint = &util_format_r16g16b16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16b16_uint_pack_signed,
   },

   [PIPE_FORMAT_R16G16B16A16_UINT] = {
      .pack_rgba_uint = &util_format_r16g16b16a16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16b16a16_uint_pack_signed,
   },

   [PIPE_FORMAT_R16_SINT] = {
      .pack_rgba_uint = &util_format_r16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16_sint_pack_signed,
   },

   [PIPE_FORMAT_R16G16_SINT] = {
      .pack_rgba_uint = &util_format_r16g16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16_sint_pack_signed,
   },

   [PIPE_FORMAT_R16G16B16_SINT] = {
      .pack_rgba_uint = &util_format_r16g16b16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16b16_sint_pack_signed,
   },

   [PIPE_FORMAT_R16G16B16A16_SINT] = {
      .pack_rgba_uint = &util_format_r16g16b16a16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16b16a16_sint_pack_signed,
   },

   [PIPE_FORMAT_R32_UINT] = {
      .pack_rgba_uint = &util_format_r32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32_uint_pack_signed,
   },

   [PIPE_FORMAT_R32G32_UINT] = {
      .pack_rgba_uint = &util_format_r32g32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32_uint_pack_signed,
   },

   [PIPE_FORMAT_R32G32B32_UINT] = {
      .pack_rgba_uint = &util_format_r32g32b32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32b32_uint_pack_signed,
   },

   [PIPE_FORMAT_R32G32B32A32_UINT] = {
      .pack_rgba_uint = &util_format_r32g32b32a32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32b32a32_uint_pack_signed,
   },

   [PIPE_FORMAT_R32_SINT] = {
      .pack_rgba_uint = &util_format_r32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32_sint_pack_signed,
   },

   [PIPE_FORMAT_R32G32_SINT] = {
      .pack_rgba_uint = &util_format_r32g32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32_sint_pack_signed,
   },

   [PIPE_FORMAT_R32G32B32_SINT] = {
      .pack_rgba_uint = &util_format_r32g32b32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32b32_sint_pack_signed,
   },

   [PIPE_FORMAT_R32G32B32A32_SINT] = {
      .pack_rgba_uint = &util_format_r32g32b32a32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32b32a32_sint_pack_signed,
   },

   [PIPE_FORMAT_R64_UINT] = {
      .pack_rgba_uint = &util_format_r64_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r64_uint_pack_signed,
   },

   [PIPE_FORMAT_R64G64_UINT] = {
      .pack_rgba_uint = &util_format_r64g64_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r64g64_uint_pack_signed,
   },

   [PIPE_FORMAT_R64G64B64_UINT] = {
      .pack_rgba_uint = &util_format_r64g64b64_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r64g64b64_uint_pack_signed,
   },

   [PIPE_FORMAT_R64G64B64A64_UINT] = {
      .pack_rgba_uint = &util_format_r64g64b64a64_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r64g64b64a64_uint_pack_signed,
   },

   [PIPE_FORMAT_R64_SINT] = {
      .pack_rgba_uint = &util_format_r64_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r64_sint_pack_signed,
   },

   [PIPE_FORMAT_A8_UINT] = {
      .pack_rgba_uint = &util_format_a8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a8_uint_pack_signed,
   },

   [PIPE_FORMAT_I8_UINT] = {
      .pack_rgba_uint = &util_format_i8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_i8_uint_pack_signed,
   },

   [PIPE_FORMAT_L8_UINT] = {
      .pack_rgba_uint = &util_format_l8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_l8_uint_pack_signed,
   },

   [PIPE_FORMAT_L8A8_UINT] = {
      .pack_rgba_uint = &util_format_l8a8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_l8a8_uint_pack_signed,
   },

   [PIPE_FORMAT_A8_SINT] = {
      .pack_rgba_uint = &util_format_a8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_a8_sint_pack_signed,
   },

   [PIPE_FORMAT_I8_SINT] = {
      .pack_rgba_uint = &util_format_i8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_i8_sint_pack_signed,
   },

   [PIPE_FORMAT_L8_SINT] = {
      .pack_rgba_uint = &util_format_l8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_l8_sint_pack_signed,
   },

   [PIPE_FORMAT_L8A8_SINT] = {
      .pack_rgba_uint = &util_format_l8a8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_l8a8_sint_pack_signed,
   },

   [PIPE_FORMAT_A16_UINT] = {
      .pack_rgba_uint = &util_format_a16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a16_uint_pack_signed,
   },

   [PIPE_FORMAT_I16_UINT] = {
      .pack_rgba_uint = &util_format_i16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_i16_uint_pack_signed,
   },

   [PIPE_FORMAT_L16_UINT] = {
      .pack_rgba_uint = &util_format_l16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_l16_uint_pack_signed,
   },

   [PIPE_FORMAT_L16A16_UINT] = {
      .pack_rgba_uint = &util_format_l16a16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_l16a16_uint_pack_signed,
   },

   [PIPE_FORMAT_A16_SINT] = {
      .pack_rgba_uint = &util_format_a16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_a16_sint_pack_signed,
   },

   [PIPE_FORMAT_I16_SINT] = {
      .pack_rgba_uint = &util_format_i16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_i16_sint_pack_signed,
   },

   [PIPE_FORMAT_L16_SINT] = {
      .pack_rgba_uint = &util_format_l16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_l16_sint_pack_signed,
   },

   [PIPE_FORMAT_L16A16_SINT] = {
      .pack_rgba_uint = &util_format_l16a16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_l16a16_sint_pack_signed,
   },

   [PIPE_FORMAT_A32_UINT] = {
      .pack_rgba_uint = &util_format_a32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a32_uint_pack_signed,
   },

   [PIPE_FORMAT_I32_UINT] = {
      .pack_rgba_uint = &util_format_i32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_i32_uint_pack_signed,
   },

   [PIPE_FORMAT_L32_UINT] = {
      .pack_rgba_uint = &util_format_l32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_l32_uint_pack_signed,
   },

   [PIPE_FORMAT_L32A32_UINT] = {
      .pack_rgba_uint = &util_format_l32a32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_l32a32_uint_pack_signed,
   },

   [PIPE_FORMAT_A32_SINT] = {
      .pack_rgba_uint = &util_format_a32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_a32_sint_pack_signed,
   },

   [PIPE_FORMAT_I32_SINT] = {
      .pack_rgba_uint = &util_format_i32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_i32_sint_pack_signed,
   },

   [PIPE_FORMAT_L32_SINT] = {
      .pack_rgba_uint = &util_format_l32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_l32_sint_pack_signed,
   },

   [PIPE_FORMAT_L32A32_SINT] = {
      .pack_rgba_uint = &util_format_l32a32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_l32a32_sint_pack_signed,
   },

   [PIPE_FORMAT_B8G8R8_UINT] = {
      .pack_rgba_uint = &util_format_b8g8r8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b8g8r8_uint_pack_signed,
   },

   [PIPE_FORMAT_B8G8R8A8_UINT] = {
      .pack_rgba_uint = &util_format_b8g8r8a8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b8g8r8a8_uint_pack_signed,
   },

   [PIPE_FORMAT_B8G8R8_SINT] = {
      .pack_rgba_uint = &util_format_b8g8r8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_b8g8r8_sint_pack_signed,
   },

   [PIPE_FORMAT_B8G8R8A8_SINT] = {
      .pack_rgba_uint = &util_format_b8g8r8a8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_b8g8r8a8_sint_pack_signed,
   },

   [PIPE_FORMAT_A8R8G8B8_UINT] = {
      .pack_rgba_uint = &util_format_a8r8g8b8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a8r8g8b8_uint_pack_signed,
   },

   [PIPE_FORMAT_A8B8G8R8_UINT] = {
      .pack_rgba_uint = &util_format_a8b8g8r8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a8b8g8r8_uint_pack_signed,
   },

   [PIPE_FORMAT_A2R10G10B10_UINT] = {
      .pack_rgba_uint = &util_format_a2r10g10b10_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a2r10g10b10_uint_pack_signed,
   },

   [PIPE_FORMAT_A2B10G10R10_UINT] = {
      .pack_rgba_uint = &util_format_a2b10g10r10_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a2b10g10r10_uint_pack_signed,
   },

   [PIPE_FORMAT_B10G10R10A2_UINT] = {
      .pack_rgba_uint = &util_format_b10g10r10a2_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b10g10r10a2_uint_pack_signed,
   },

   [PIPE_FORMAT_B10G10R10A2_SINT] = {
      .pack_rgba_uint = &util_format_b10g10r10a2_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_b10g10r10a2_sint_pack_signed,
   },

   [PIPE_FORMAT_R5G6B5_UINT] = {
      .pack_rgba_uint = &util_format_r5g6b5_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r5g6b5_uint_pack_signed,
   },

   [PIPE_FORMAT_B5G6R5_UINT] = {
      .pack_rgba_uint = &util_format_b5g6r5_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b5g6r5_uint_pack_signed,
   },

   [PIPE_FORMAT_R3G3B2_UINT] = {
      .pack_rgba_uint = &util_format_r3g3b2_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r3g3b2_uint_pack_signed,
   },

   [PIPE_FORMAT_B2G3R3_UINT] = {
      .pack_rgba_uint = &util_format_b2g3r3_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b2g3r3_uint_pack_signed,
   },

   [PIPE_FORMAT_R4G4B4A4_UINT] = {
      .pack_rgba_uint = &util_format_r4g4b4a4_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r4g4b4a4_uint_pack_signed,
   },

   [PIPE_FORMAT_B4G4R4A4_UINT] = {
      .pack_rgba_uint = &util_format_b4g4r4a4_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b4g4r4a4_uint_pack_signed,
   },

   [PIPE_FORMAT_A4R4G4B4_UINT] = {
      .pack_rgba_uint = &util_format_a4r4g4b4_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a4r4g4b4_uint_pack_signed,
   },

   [PIPE_FORMAT_A4B4G4R4_UINT] = {
      .pack_rgba_uint = &util_format_a4b4g4r4_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a4b4g4r4_uint_pack_signed,
   },

   [PIPE_FORMAT_A1R5G5B5_UINT] = {
      .pack_rgba_uint = &util_format_a1r5g5b5_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a1r5g5b5_uint_pack_signed,
   },

   [PIPE_FORMAT_A1B5G5R5_UINT] = {
      .pack_rgba_uint = &util_format_a1b5g5r5_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_a1b5g5r5_uint_pack_signed,
   },

   [PIPE_FORMAT_R5G5B5A1_UINT] = {
      .pack_rgba_uint = &util_format_r5g5b5a1_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r5g5b5a1_uint_pack_signed,
   },

   [PIPE_FORMAT_B5G5R5A1_UINT] = {
      .pack_rgba_uint = &util_format_b5g5r5a1_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_b5g5r5a1_uint_pack_signed,
   },

   [PIPE_FORMAT_R8G8B8X8_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8g8b8x8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8x8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8X8_SRGB] = {
      .pack_rgba_8unorm = &util_format_r8g8b8x8_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8g8b8x8_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R8G8B8X8_UINT] = {
      .pack_rgba_uint = &util_format_r8g8b8x8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8b8x8_uint_pack_signed,
   },

   [PIPE_FORMAT_R8G8B8X8_SINT] = {
      .pack_rgba_uint = &util_format_r8g8b8x8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8g8b8x8_sint_pack_signed,
   },

   [PIPE_FORMAT_B10G10R10X2_UNORM] = {
      .pack_rgba_8unorm = &util_format_b10g10r10x2_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b10g10r10x2_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_B10G10R10X2_SNORM] = {
      .pack_rgba_8unorm = &util_format_b10g10r10x2_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b10g10r10x2_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16X16_UNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16b16x16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16x16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16X16_SNORM] = {
      .pack_rgba_8unorm = &util_format_r16g16b16x16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16x16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16X16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r16g16b16x16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16g16b16x16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R16G16B16X16_UINT] = {
      .pack_rgba_uint = &util_format_r16g16b16x16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16b16x16_uint_pack_signed,
   },

   [PIPE_FORMAT_R16G16B16X16_SINT] = {
      .pack_rgba_uint = &util_format_r16g16b16x16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16g16b16x16_sint_pack_signed,
   },

   [PIPE_FORMAT_R32G32B32X32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r32g32b32x32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32g32b32x32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32G32B32X32_UINT] = {
      .pack_rgba_uint = &util_format_r32g32b32x32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32b32x32_uint_pack_signed,
   },

   [PIPE_FORMAT_R32G32B32X32_SINT] = {
      .pack_rgba_uint = &util_format_r32g32b32x32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32g32b32x32_sint_pack_signed,
   },

   [PIPE_FORMAT_R8A8_SNORM] = {
      .pack_rgba_8unorm = &util_format_r8a8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r8a8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16A16_UNORM] = {
      .pack_rgba_8unorm = &util_format_r16a16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16a16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16A16_SNORM] = {
      .pack_rgba_8unorm = &util_format_r16a16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16a16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_R16A16_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r16a16_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r16a16_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R32A32_FLOAT] = {
      .pack_rgba_8unorm = &util_format_r32a32_float_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r32a32_float_pack_rgba_float,
   },

   [PIPE_FORMAT_R8A8_UINT] = {
      .pack_rgba_uint = &util_format_r8a8_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8a8_uint_pack_signed,
   },

   [PIPE_FORMAT_R8A8_SINT] = {
      .pack_rgba_uint = &util_format_r8a8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r8a8_sint_pack_signed,
   },

   [PIPE_FORMAT_R16A16_UINT] = {
      .pack_rgba_uint = &util_format_r16a16_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16a16_uint_pack_signed,
   },

   [PIPE_FORMAT_R16A16_SINT] = {
      .pack_rgba_uint = &util_format_r16a16_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r16a16_sint_pack_signed,
   },

   [PIPE_FORMAT_R32A32_UINT] = {
      .pack_rgba_uint = &util_format_r32a32_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32a32_uint_pack_signed,
   },

   [PIPE_FORMAT_R32A32_SINT] = {
      .pack_rgba_uint = &util_format_r32a32_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r32a32_sint_pack_signed,
   },

   [PIPE_FORMAT_R10G10B10A2_UINT] = {
      .pack_rgba_uint = &util_format_r10g10b10a2_uint_pack_unsigned,
      .pack_rgba_sint = &util_format_r10g10b10a2_uint_pack_signed,
   },

   [PIPE_FORMAT_R10G10B10A2_SINT] = {
      .pack_rgba_uint = &util_format_r10g10b10a2_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_r10g10b10a2_sint_pack_signed,
   },

   [PIPE_FORMAT_B5G6R5_SRGB] = {
      .pack_rgba_8unorm = &util_format_b5g6r5_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_b5g6r5_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_R5G6B5_SRGB] = {
      .pack_rgba_8unorm = &util_format_r5g6b5_srgb_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_r5g6b5_srgb_pack_rgba_float,
   },

   [PIPE_FORMAT_G8R8_UNORM] = {
      .pack_rgba_8unorm = &util_format_g8r8_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_g8r8_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_G8R8_SNORM] = {
      .pack_rgba_8unorm = &util_format_g8r8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_g8r8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_G8R8_SINT] = {
      .pack_rgba_uint = &util_format_g8r8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_g8r8_sint_pack_signed,
   },

   [PIPE_FORMAT_G16R16_UNORM] = {
      .pack_rgba_8unorm = &util_format_g16r16_unorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_g16r16_unorm_pack_rgba_float,
   },

   [PIPE_FORMAT_G16R16_SNORM] = {
      .pack_rgba_8unorm = &util_format_g16r16_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_g16r16_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8B8G8R8_SNORM] = {
      .pack_rgba_8unorm = &util_format_a8b8g8r8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_a8b8g8r8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_A8B8G8R8_SINT] = {
      .pack_rgba_uint = &util_format_a8b8g8r8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_a8b8g8r8_sint_pack_signed,
   },

   [PIPE_FORMAT_X8B8G8R8_SNORM] = {
      .pack_rgba_8unorm = &util_format_x8b8g8r8_snorm_pack_rgba_8unorm,
      .pack_rgba_float = &util_format_x8b8g8r8_snorm_pack_rgba_float,
   },

   [PIPE_FORMAT_X8B8G8R8_SINT] = {
      .pack_rgba_uint = &util_format_x8b8g8r8_sint_pack_unsigned,
      .pack_rgba_sint = &util_format_x8b8g8r8_sint_pack_signed,
   },

};

const struct util_format_pack_description *
util_format_pack_description(enum pipe_format format)
{
   if (format >= ARRAY_SIZE(util_format_pack_descriptions))
      return NULL;

   return &util_format_pack_descriptions[format];
}

static const struct util_format_unpack_description
util_format_unpack_descriptions[] = {
   [PIPE_FORMAT_NONE] = {
      .unpack_rgba_8unorm = &util_format_none_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_none_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8A8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8a8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8a8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8X8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8x8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8x8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8X8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8x8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8x8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8X8_UINT] = {
      .unpack_rgba = &util_format_b8g8r8x8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B8G8R8X8_SINT] = {
      .unpack_rgba = &util_format_b8g8r8x8_sint_unpack_signed,
   },
   [PIPE_FORMAT_A8R8G8B8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a8r8g8b8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8r8g8b8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8R8G8B8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_a8r8g8b8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8r8g8b8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8R8G8B8_SINT] = {
      .unpack_rgba = &util_format_a8r8g8b8_sint_unpack_signed,
   },
   [PIPE_FORMAT_X8R8G8B8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_x8r8g8b8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x8r8g8b8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_X8R8G8B8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_x8r8g8b8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x8r8g8b8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_X8R8G8B8_SINT] = {
      .unpack_rgba = &util_format_x8r8g8b8_sint_unpack_signed,
   },
   [PIPE_FORMAT_A8B8G8R8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a8b8g8r8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8b8g8r8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_X8B8G8R8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_x8b8g8r8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x8b8g8r8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8X8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8x8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8x8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R5G5B5A1_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r5g5b5a1_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r5g5b5a1_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R5G5B5X1_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r5g5b5x1_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r5g5b5x1_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B5G5R5X1_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b5g5r5x1_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b5g5r5x1_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B5G5R5A1_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b5g5r5a1_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b5g5r5a1_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_X1B5G5R5_UNORM] = {
      .unpack_rgba_8unorm = &util_format_x1b5g5r5_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x1b5g5r5_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A1R5G5B5_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a1r5g5b5_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a1r5g5b5_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_X1R5G5B5_UNORM] = {
      .unpack_rgba_8unorm = &util_format_x1r5g5b5_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x1r5g5b5_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A1B5G5R5_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a1b5g5r5_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a1b5g5r5_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R4G4B4A4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r4g4b4a4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r4g4b4a4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R4G4B4X4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r4g4b4x4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r4g4b4x4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B4G4R4A4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b4g4r4a4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b4g4r4a4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B4G4R4X4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b4g4r4x4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b4g4r4x4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A4R4G4B4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a4r4g4b4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a4r4g4b4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A4B4G4R4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a4b4g4r4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a4b4g4r4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R5G6B5_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r5g6b5_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r5g6b5_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B5G6R5_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b5g6r5_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b5g6r5_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10A2_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10a2_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10a2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10X2_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10x2_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10x2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B10G10R10A2_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b10g10r10a2_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b10g10r10a2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A2R10G10B10_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a2r10g10b10_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a2r10g10b10_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A2B10G10R10_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a2b10g10r10_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a2b10g10r10_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R3G3B2_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r3g3b2_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r3g3b2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B2G3R3_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b2g3r3_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b2g3r3_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_l8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_I8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_i8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_i8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L4A4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_l4a4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l4a4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L8A8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_l8a8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l8a8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_l16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_I16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_i16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_i16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L16A16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_l16a16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l16a16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_a8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_l8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L8A8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_l8a8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l8a8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_I8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_i8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_i8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_a16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_l16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_L16A16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_l16a16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l16a16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_I16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_i16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_i16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_a16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_L16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_l16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_L16A16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_l16a16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l16a16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_I16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_i16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_i16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_A32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_a32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_L32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_l32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_L32A32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_l32a32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l32a32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_I32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_i32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_i32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_L8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_l8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_r8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_L8A8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_l8a8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_l8a8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_r8g8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8A8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8a8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8a8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8B8G8R8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_a8b8g8r8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8b8g8r8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_X8B8G8R8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_x8b8g8r8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x8b8g8r8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8A8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8a8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8a8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8X8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8x8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8x8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8R8G8B8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_a8r8g8b8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8r8g8b8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_X8R8G8B8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_x8r8g8b8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x8r8g8b8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8SG8SB8UX8U_NORM] = {
      .unpack_rgba_8unorm = &util_format_r8sg8sb8ux8u_norm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8sg8sb8ux8u_norm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10SG10SB10SA2U_NORM] = {
      .unpack_rgba_8unorm = &util_format_r10sg10sb10sa2u_norm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10sg10sb10sa2u_norm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R5SG5SB6U_NORM] = {
      .unpack_rgba_8unorm = &util_format_r5sg5sb6u_norm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r5sg5sb6u_norm_unpack_rgba_float,
   },
   [PIPE_FORMAT_S8_UINT] = {
      .unpack_s_8uint = &util_format_s8_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_Z16_UNORM] = {
      .unpack_z_32unorm = &util_format_z16_unorm_unpack_z_32unorm,
      .unpack_z_float = &util_format_z16_unorm_unpack_z_float,
   },
   [PIPE_FORMAT_Z16_UNORM_S8_UINT] = {
      .unpack_z_32unorm = &util_format_z16_unorm_s8_uint_unpack_z_32unorm,
      .unpack_z_float = &util_format_z16_unorm_s8_uint_unpack_z_float,
      .unpack_s_8uint = &util_format_z16_unorm_s8_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_Z32_UNORM] = {
      .unpack_z_32unorm = &util_format_z32_unorm_unpack_z_32unorm,
      .unpack_z_float = &util_format_z32_unorm_unpack_z_float,
   },
   [PIPE_FORMAT_Z32_FLOAT] = {
      .unpack_z_32unorm = &util_format_z32_float_unpack_z_32unorm,
      .unpack_z_float = &util_format_z32_float_unpack_z_float,
   },
   [PIPE_FORMAT_Z24_UNORM_S8_UINT] = {
      .unpack_z_32unorm = &util_format_z24_unorm_s8_uint_unpack_z_32unorm,
      .unpack_z_float = &util_format_z24_unorm_s8_uint_unpack_z_float,
      .unpack_s_8uint = &util_format_z24_unorm_s8_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_S8_UINT_Z24_UNORM] = {
      .unpack_z_32unorm = &util_format_s8_uint_z24_unorm_unpack_z_32unorm,
      .unpack_z_float = &util_format_s8_uint_z24_unorm_unpack_z_float,
      .unpack_s_8uint = &util_format_s8_uint_z24_unorm_unpack_s_8uint,
   },
   [PIPE_FORMAT_X24S8_UINT] = {
      .unpack_s_8uint = &util_format_x24s8_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_S8X24_UINT] = {
      .unpack_s_8uint = &util_format_s8x24_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_Z24X8_UNORM] = {
      .unpack_z_32unorm = &util_format_z24x8_unorm_unpack_z_32unorm,
      .unpack_z_float = &util_format_z24x8_unorm_unpack_z_float,
   },
   [PIPE_FORMAT_X8Z24_UNORM] = {
      .unpack_z_32unorm = &util_format_x8z24_unorm_unpack_z_32unorm,
      .unpack_z_float = &util_format_x8z24_unorm_unpack_z_float,
   },
   [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = {
      .unpack_z_32unorm = &util_format_z32_float_s8x24_uint_unpack_z_32unorm,
      .unpack_z_float = &util_format_z32_float_s8x24_uint_unpack_z_float,
      .unpack_s_8uint = &util_format_z32_float_s8x24_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_X32_S8X24_UINT] = {
      .unpack_s_8uint = &util_format_x32_s8x24_uint_unpack_s_8uint,
   },
   [PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8] = {
      .unpack_rgba_8unorm = &util_format_z24_unorm_s8_uint_as_r8g8b8a8_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_z24_unorm_s8_uint_as_r8g8b8a8_unpack_rgba_float,
   },
   [PIPE_FORMAT_UYVY] = {
      .unpack_rgba_8unorm_rect = &util_format_uyvy_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_uyvy_unpack_rgba_float,
   },
   [PIPE_FORMAT_YUYV] = {
      .unpack_rgba_8unorm_rect = &util_format_yuyv_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_yuyv_unpack_rgba_float,
   },
   [PIPE_FORMAT_AYUV] = { 0 },
   [PIPE_FORMAT_XYUV] = { 0 },
   [PIPE_FORMAT_R8G8_B8G8_UNORM] = {
      .unpack_rgba_8unorm_rect = &util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_r8g8_b8g8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_G8R8_G8B8_UNORM] = { 0 },
   [PIPE_FORMAT_G8R8_B8R8_UNORM] = { 0 },
   [PIPE_FORMAT_R8G8_R8B8_UNORM] = { 0 },
   [PIPE_FORMAT_R11G11B10_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r11g11b10_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r11g11b10_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R9G9B9E5_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r9g9b9e5_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r9g9b9e5_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R1_UNORM] = { 0 },
   [PIPE_FORMAT_R8G8Bx_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8bx_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8bx_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT1_RGB] = {
      .fetch_rgba_8unorm = &util_format_dxt1_rgb_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt1_rgb_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt1_rgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT1_RGBA] = {
      .fetch_rgba_8unorm = &util_format_dxt1_rgba_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt1_rgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt1_rgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT3_RGBA] = {
      .fetch_rgba_8unorm = &util_format_dxt3_rgba_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt3_rgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt3_rgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT5_RGBA] = {
      .fetch_rgba_8unorm = &util_format_dxt5_rgba_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt5_rgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt5_rgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT1_SRGB] = {
      .fetch_rgba_8unorm = &util_format_dxt1_srgb_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt1_srgb_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt1_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT1_SRGBA] = {
      .fetch_rgba_8unorm = &util_format_dxt1_srgba_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt1_srgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt1_srgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT3_SRGBA] = {
      .fetch_rgba_8unorm = &util_format_dxt3_srgba_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt3_srgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt3_srgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_DXT5_SRGBA] = {
      .fetch_rgba_8unorm = &util_format_dxt5_srgba_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_dxt5_srgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_dxt5_srgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_FXT1_RGB] = {
      .unpack_rgba_8unorm_rect = &util_format_fxt1_rgb_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_fxt1_rgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_FXT1_RGBA] = {
      .unpack_rgba_8unorm_rect = &util_format_fxt1_rgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_fxt1_rgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_RGTC1_UNORM] = {
      .fetch_rgba_8unorm = &util_format_rgtc1_unorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_rgtc1_unorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_rgtc1_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_RGTC1_SNORM] = {
      .fetch_rgba_8unorm = &util_format_rgtc1_snorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_rgtc1_snorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_rgtc1_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_RGTC2_UNORM] = {
      .fetch_rgba_8unorm = &util_format_rgtc2_unorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_rgtc2_unorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_rgtc2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_RGTC2_SNORM] = {
      .fetch_rgba_8unorm = &util_format_rgtc2_snorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_rgtc2_snorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_rgtc2_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_LATC1_UNORM] = {
      .fetch_rgba_8unorm = &util_format_latc1_unorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_latc1_unorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_latc1_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_LATC1_SNORM] = {
      .fetch_rgba_8unorm = &util_format_latc1_snorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_latc1_snorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_latc1_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_LATC2_UNORM] = {
      .fetch_rgba_8unorm = &util_format_latc2_unorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_latc2_unorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_latc2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_LATC2_SNORM] = {
      .fetch_rgba_8unorm = &util_format_latc2_snorm_fetch_rgba_8unorm,
      .unpack_rgba_8unorm_rect = &util_format_latc2_snorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_latc2_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_ETC1_RGB8] = {
      .unpack_rgba_8unorm_rect = &util_format_etc1_rgb8_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_etc1_rgb8_unpack_rgba_float,
   },
   [PIPE_FORMAT_ETC2_RGB8] = { 0 },
   [PIPE_FORMAT_ETC2_SRGB8] = { 0 },
   [PIPE_FORMAT_ETC2_RGB8A1] = { 0 },
   [PIPE_FORMAT_ETC2_SRGB8A1] = { 0 },
   [PIPE_FORMAT_ETC2_RGBA8] = { 0 },
   [PIPE_FORMAT_ETC2_SRGBA8] = { 0 },
   [PIPE_FORMAT_ETC2_R11_UNORM] = { 0 },
   [PIPE_FORMAT_ETC2_R11_SNORM] = { 0 },
   [PIPE_FORMAT_ETC2_RG11_UNORM] = { 0 },
   [PIPE_FORMAT_ETC2_RG11_SNORM] = { 0 },
   [PIPE_FORMAT_BPTC_RGBA_UNORM] = {
      .unpack_rgba_8unorm_rect = &util_format_bptc_rgba_unorm_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_bptc_rgba_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_BPTC_SRGBA] = {
      .unpack_rgba_8unorm_rect = &util_format_bptc_srgba_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_bptc_srgba_unpack_rgba_float,
   },
   [PIPE_FORMAT_BPTC_RGB_FLOAT] = {
      .unpack_rgba_8unorm_rect = &util_format_bptc_rgb_float_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_bptc_rgb_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_BPTC_RGB_UFLOAT] = {
      .unpack_rgba_8unorm_rect = &util_format_bptc_rgb_ufloat_unpack_rgba_8unorm,
      .unpack_rgba_rect = &util_format_bptc_rgb_ufloat_unpack_rgba_float,
   },
   [PIPE_FORMAT_ASTC_4x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x6] = { 0 },
   [PIPE_FORMAT_ASTC_8x5] = { 0 },
   [PIPE_FORMAT_ASTC_8x6] = { 0 },
   [PIPE_FORMAT_ASTC_8x8] = { 0 },
   [PIPE_FORMAT_ASTC_10x5] = { 0 },
   [PIPE_FORMAT_ASTC_10x6] = { 0 },
   [PIPE_FORMAT_ASTC_10x8] = { 0 },
   [PIPE_FORMAT_ASTC_10x10] = { 0 },
   [PIPE_FORMAT_ASTC_12x10] = { 0 },
   [PIPE_FORMAT_ASTC_12x12] = { 0 },
   [PIPE_FORMAT_ASTC_4x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x6_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_8x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_8x6_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_8x8_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x6_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x8_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_10x10_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_12x10_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_12x12_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_3x3x3] = { 0 },
   [PIPE_FORMAT_ASTC_4x3x3] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x3] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x4x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x4] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x5x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x5] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x6] = { 0 },
   [PIPE_FORMAT_ASTC_3x3x3_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_4x3x3_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x3_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_4x4x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x4x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x4_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_5x5x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x5x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x5_SRGB] = { 0 },
   [PIPE_FORMAT_ASTC_6x6x6_SRGB] = { 0 },
   [PIPE_FORMAT_ATC_RGB] = { 0 },
   [PIPE_FORMAT_ATC_RGBA_EXPLICIT] = { 0 },
   [PIPE_FORMAT_ATC_RGBA_INTERPOLATED] = { 0 },
   [PIPE_FORMAT_R64_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r64_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r64_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R64G64_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r64g64_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r64g64_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R64G64B64_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r64g64b64_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r64g64b64_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R64G64B64A64_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r64g64b64a64_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r64g64b64a64_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r32g32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32A32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32a32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32a32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r32_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r32g32_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32A32_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32a32_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32a32_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r32_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r32g32_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32A32_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32a32_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32a32_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r32_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r32g32_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32A32_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32a32_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32a32_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r32_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r32g32_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32A32_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32a32_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32a32_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r16g16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16A16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16a16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16a16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16A16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16a16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16a16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r16_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r16g16_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16A16_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16a16_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16a16_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16A16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16a16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16a16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r16_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r16g16_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16A16_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16a16_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16a16_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8A8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8a8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8a8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r8g8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8A8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8a8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8a8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8A8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8a8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8a8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8B8G8R8_USCALED] = {
      .unpack_rgba_8unorm = &util_format_a8b8g8r8_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8b8g8r8_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8A8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8a8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8a8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8A8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8a8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8a8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r8g8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8A8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8a8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8a8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_B8G8R8A8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_b8g8r8a8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b8g8r8a8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8B8G8R8_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_a8b8g8r8_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8b8g8r8_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32_FIXED] = {
      .unpack_rgba_8unorm = &util_format_r32_fixed_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32_fixed_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32_FIXED] = {
      .unpack_rgba_8unorm = &util_format_r32g32_fixed_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32_fixed_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32_FIXED] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32_fixed_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32_fixed_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32A32_FIXED] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32a32_fixed_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32a32_fixed_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10X2_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10x2_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10x2_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10X2_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10x2_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10x2_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_YV12] = { 0 },
   [PIPE_FORMAT_YV16] = { 0 },
   [PIPE_FORMAT_IYUV] = { 0 },
   [PIPE_FORMAT_NV12] = { 0 },
   [PIPE_FORMAT_NV21] = { 0 },
   [PIPE_FORMAT_R8_G8B8_420_UNORM] = { 0 },
   [PIPE_FORMAT_R8_G8_B8_420_UNORM] = { 0 },
   [PIPE_FORMAT_Y8_U8_V8_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y8_U8V8_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y8_U8_V8_444_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16_V16_420_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16_V16_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16V16_422_UNORM] = { 0 },
   [PIPE_FORMAT_Y16_U16_V16_444_UNORM] = { 0 },
   [PIPE_FORMAT_P010] = { 0 },
   [PIPE_FORMAT_P012] = { 0 },
   [PIPE_FORMAT_P016] = { 0 },
   [PIPE_FORMAT_Y210] = { 0 },
   [PIPE_FORMAT_Y212] = { 0 },
   [PIPE_FORMAT_Y216] = { 0 },
   [PIPE_FORMAT_Y410] = { 0 },
   [PIPE_FORMAT_Y412] = { 0 },
   [PIPE_FORMAT_Y416] = { 0 },
   [PIPE_FORMAT_A4R4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a4r4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a4r4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R4A4_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r4a4_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r4a4_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8A8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r8a8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8a8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8R8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_a8r8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8r8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10A2_USCALED] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10a2_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10a2_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10A2_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10a2_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10a2_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_R10G10B10A2_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r10g10b10a2_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r10g10b10a2_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B10G10R10A2_USCALED] = {
      .unpack_rgba_8unorm = &util_format_b10g10r10a2_uscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b10g10r10a2_uscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_B10G10R10A2_SSCALED] = {
      .unpack_rgba_8unorm = &util_format_b10g10r10a2_sscaled_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b10g10r10a2_sscaled_unpack_rgba_float,
   },
   [PIPE_FORMAT_B10G10R10A2_SNORM] = {
      .unpack_rgba_8unorm = &util_format_b10g10r10a2_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b10g10r10a2_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8_UINT] = {
      .unpack_rgba = &util_format_r8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8G8_UINT] = {
      .unpack_rgba = &util_format_r8g8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8G8B8_UINT] = {
      .unpack_rgba = &util_format_r8g8b8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8G8B8A8_UINT] = {
      .unpack_rgba = &util_format_r8g8b8a8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8_SINT] = {
      .unpack_rgba = &util_format_r8_sint_unpack_signed,
   },
   [PIPE_FORMAT_R8G8_SINT] = {
      .unpack_rgba = &util_format_r8g8_sint_unpack_signed,
   },
   [PIPE_FORMAT_R8G8B8_SINT] = {
      .unpack_rgba = &util_format_r8g8b8_sint_unpack_signed,
   },
   [PIPE_FORMAT_R8G8B8A8_SINT] = {
      .unpack_rgba = &util_format_r8g8b8a8_sint_unpack_signed,
   },
   [PIPE_FORMAT_R16_UINT] = {
      .unpack_rgba = &util_format_r16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R16G16_UINT] = {
      .unpack_rgba = &util_format_r16g16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R16G16B16_UINT] = {
      .unpack_rgba = &util_format_r16g16b16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R16G16B16A16_UINT] = {
      .unpack_rgba = &util_format_r16g16b16a16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R16_SINT] = {
      .unpack_rgba = &util_format_r16_sint_unpack_signed,
   },
   [PIPE_FORMAT_R16G16_SINT] = {
      .unpack_rgba = &util_format_r16g16_sint_unpack_signed,
   },
   [PIPE_FORMAT_R16G16B16_SINT] = {
      .unpack_rgba = &util_format_r16g16b16_sint_unpack_signed,
   },
   [PIPE_FORMAT_R16G16B16A16_SINT] = {
      .unpack_rgba = &util_format_r16g16b16a16_sint_unpack_signed,
   },
   [PIPE_FORMAT_R32_UINT] = {
      .unpack_rgba = &util_format_r32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R32G32_UINT] = {
      .unpack_rgba = &util_format_r32g32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R32G32B32_UINT] = {
      .unpack_rgba = &util_format_r32g32b32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R32G32B32A32_UINT] = {
      .unpack_rgba = &util_format_r32g32b32a32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R32_SINT] = {
      .unpack_rgba = &util_format_r32_sint_unpack_signed,
   },
   [PIPE_FORMAT_R32G32_SINT] = {
      .unpack_rgba = &util_format_r32g32_sint_unpack_signed,
   },
   [PIPE_FORMAT_R32G32B32_SINT] = {
      .unpack_rgba = &util_format_r32g32b32_sint_unpack_signed,
   },
   [PIPE_FORMAT_R32G32B32A32_SINT] = {
      .unpack_rgba = &util_format_r32g32b32a32_sint_unpack_signed,
   },
   [PIPE_FORMAT_R64_UINT] = {
      .unpack_rgba = &util_format_r64_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R64G64_UINT] = {
      .unpack_rgba = &util_format_r64g64_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R64G64B64_UINT] = {
      .unpack_rgba = &util_format_r64g64b64_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R64G64B64A64_UINT] = {
      .unpack_rgba = &util_format_r64g64b64a64_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R64_SINT] = {
      .unpack_rgba = &util_format_r64_sint_unpack_signed,
   },
   [PIPE_FORMAT_A8_UINT] = {
      .unpack_rgba = &util_format_a8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_I8_UINT] = {
      .unpack_rgba = &util_format_i8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_L8_UINT] = {
      .unpack_rgba = &util_format_l8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_L8A8_UINT] = {
      .unpack_rgba = &util_format_l8a8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A8_SINT] = {
      .unpack_rgba = &util_format_a8_sint_unpack_signed,
   },
   [PIPE_FORMAT_I8_SINT] = {
      .unpack_rgba = &util_format_i8_sint_unpack_signed,
   },
   [PIPE_FORMAT_L8_SINT] = {
      .unpack_rgba = &util_format_l8_sint_unpack_signed,
   },
   [PIPE_FORMAT_L8A8_SINT] = {
      .unpack_rgba = &util_format_l8a8_sint_unpack_signed,
   },
   [PIPE_FORMAT_A16_UINT] = {
      .unpack_rgba = &util_format_a16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_I16_UINT] = {
      .unpack_rgba = &util_format_i16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_L16_UINT] = {
      .unpack_rgba = &util_format_l16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_L16A16_UINT] = {
      .unpack_rgba = &util_format_l16a16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A16_SINT] = {
      .unpack_rgba = &util_format_a16_sint_unpack_signed,
   },
   [PIPE_FORMAT_I16_SINT] = {
      .unpack_rgba = &util_format_i16_sint_unpack_signed,
   },
   [PIPE_FORMAT_L16_SINT] = {
      .unpack_rgba = &util_format_l16_sint_unpack_signed,
   },
   [PIPE_FORMAT_L16A16_SINT] = {
      .unpack_rgba = &util_format_l16a16_sint_unpack_signed,
   },
   [PIPE_FORMAT_A32_UINT] = {
      .unpack_rgba = &util_format_a32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_I32_UINT] = {
      .unpack_rgba = &util_format_i32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_L32_UINT] = {
      .unpack_rgba = &util_format_l32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_L32A32_UINT] = {
      .unpack_rgba = &util_format_l32a32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A32_SINT] = {
      .unpack_rgba = &util_format_a32_sint_unpack_signed,
   },
   [PIPE_FORMAT_I32_SINT] = {
      .unpack_rgba = &util_format_i32_sint_unpack_signed,
   },
   [PIPE_FORMAT_L32_SINT] = {
      .unpack_rgba = &util_format_l32_sint_unpack_signed,
   },
   [PIPE_FORMAT_L32A32_SINT] = {
      .unpack_rgba = &util_format_l32a32_sint_unpack_signed,
   },
   [PIPE_FORMAT_B8G8R8_UINT] = {
      .unpack_rgba = &util_format_b8g8r8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B8G8R8A8_UINT] = {
      .unpack_rgba = &util_format_b8g8r8a8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B8G8R8_SINT] = {
      .unpack_rgba = &util_format_b8g8r8_sint_unpack_signed,
   },
   [PIPE_FORMAT_B8G8R8A8_SINT] = {
      .unpack_rgba = &util_format_b8g8r8a8_sint_unpack_signed,
   },
   [PIPE_FORMAT_A8R8G8B8_UINT] = {
      .unpack_rgba = &util_format_a8r8g8b8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A8B8G8R8_UINT] = {
      .unpack_rgba = &util_format_a8b8g8r8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A2R10G10B10_UINT] = {
      .unpack_rgba = &util_format_a2r10g10b10_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A2B10G10R10_UINT] = {
      .unpack_rgba = &util_format_a2b10g10r10_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B10G10R10A2_UINT] = {
      .unpack_rgba = &util_format_b10g10r10a2_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B10G10R10A2_SINT] = {
      .unpack_rgba = &util_format_b10g10r10a2_sint_unpack_signed,
   },
   [PIPE_FORMAT_R5G6B5_UINT] = {
      .unpack_rgba = &util_format_r5g6b5_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B5G6R5_UINT] = {
      .unpack_rgba = &util_format_b5g6r5_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R3G3B2_UINT] = {
      .unpack_rgba = &util_format_r3g3b2_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B2G3R3_UINT] = {
      .unpack_rgba = &util_format_b2g3r3_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R4G4B4A4_UINT] = {
      .unpack_rgba = &util_format_r4g4b4a4_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B4G4R4A4_UINT] = {
      .unpack_rgba = &util_format_b4g4r4a4_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A4R4G4B4_UINT] = {
      .unpack_rgba = &util_format_a4r4g4b4_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A4B4G4R4_UINT] = {
      .unpack_rgba = &util_format_a4b4g4r4_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A1R5G5B5_UINT] = {
      .unpack_rgba = &util_format_a1r5g5b5_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_A1B5G5R5_UINT] = {
      .unpack_rgba = &util_format_a1b5g5r5_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R5G5B5A1_UINT] = {
      .unpack_rgba = &util_format_r5g5b5a1_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_B5G5R5A1_UINT] = {
      .unpack_rgba = &util_format_b5g5r5a1_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8G8B8X8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8x8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8x8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8X8_SRGB] = {
      .unpack_rgba_8unorm = &util_format_r8g8b8x8_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8g8b8x8_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8G8B8X8_UINT] = {
      .unpack_rgba = &util_format_r8g8b8x8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8G8B8X8_SINT] = {
      .unpack_rgba = &util_format_r8g8b8x8_sint_unpack_signed,
   },
   [PIPE_FORMAT_B10G10R10X2_UNORM] = {
      .unpack_rgba_8unorm = &util_format_b10g10r10x2_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b10g10r10x2_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_B10G10R10X2_SNORM] = {
      .unpack_rgba_8unorm = &util_format_b10g10r10x2_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b10g10r10x2_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16X16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16x16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16x16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16X16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16x16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16x16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16X16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r16g16b16x16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16g16b16x16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16G16B16X16_UINT] = {
      .unpack_rgba = &util_format_r16g16b16x16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R16G16B16X16_SINT] = {
      .unpack_rgba = &util_format_r16g16b16x16_sint_unpack_signed,
   },
   [PIPE_FORMAT_R32G32B32X32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r32g32b32x32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32g32b32x32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32G32B32X32_UINT] = {
      .unpack_rgba = &util_format_r32g32b32x32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R32G32B32X32_SINT] = {
      .unpack_rgba = &util_format_r32g32b32x32_sint_unpack_signed,
   },
   [PIPE_FORMAT_R8A8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r8a8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r8a8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16A16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_r16a16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16a16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16A16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_r16a16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16a16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_R16A16_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r16a16_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r16a16_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R32A32_FLOAT] = {
      .unpack_rgba_8unorm = &util_format_r32a32_float_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r32a32_float_unpack_rgba_float,
   },
   [PIPE_FORMAT_R8A8_UINT] = {
      .unpack_rgba = &util_format_r8a8_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R8A8_SINT] = {
      .unpack_rgba = &util_format_r8a8_sint_unpack_signed,
   },
   [PIPE_FORMAT_R16A16_UINT] = {
      .unpack_rgba = &util_format_r16a16_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R16A16_SINT] = {
      .unpack_rgba = &util_format_r16a16_sint_unpack_signed,
   },
   [PIPE_FORMAT_R32A32_UINT] = {
      .unpack_rgba = &util_format_r32a32_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R32A32_SINT] = {
      .unpack_rgba = &util_format_r32a32_sint_unpack_signed,
   },
   [PIPE_FORMAT_R10G10B10A2_UINT] = {
      .unpack_rgba = &util_format_r10g10b10a2_uint_unpack_unsigned,
   },
   [PIPE_FORMAT_R10G10B10A2_SINT] = {
      .unpack_rgba = &util_format_r10g10b10a2_sint_unpack_signed,
   },
   [PIPE_FORMAT_B5G6R5_SRGB] = {
      .unpack_rgba_8unorm = &util_format_b5g6r5_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_b5g6r5_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_R5G6B5_SRGB] = {
      .unpack_rgba_8unorm = &util_format_r5g6b5_srgb_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_r5g6b5_srgb_unpack_rgba_float,
   },
   [PIPE_FORMAT_G8R8_UNORM] = {
      .unpack_rgba_8unorm = &util_format_g8r8_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_g8r8_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_G8R8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_g8r8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_g8r8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_G8R8_SINT] = {
      .unpack_rgba = &util_format_g8r8_sint_unpack_signed,
   },
   [PIPE_FORMAT_G16R16_UNORM] = {
      .unpack_rgba_8unorm = &util_format_g16r16_unorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_g16r16_unorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_G16R16_SNORM] = {
      .unpack_rgba_8unorm = &util_format_g16r16_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_g16r16_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8B8G8R8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_a8b8g8r8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_a8b8g8r8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_A8B8G8R8_SINT] = {
      .unpack_rgba = &util_format_a8b8g8r8_sint_unpack_signed,
   },
   [PIPE_FORMAT_X8B8G8R8_SNORM] = {
      .unpack_rgba_8unorm = &util_format_x8b8g8r8_snorm_unpack_rgba_8unorm,
      .unpack_rgba = &util_format_x8b8g8r8_snorm_unpack_rgba_float,
   },
   [PIPE_FORMAT_X8B8G8R8_SINT] = {
      .unpack_rgba = &util_format_x8b8g8r8_sint_unpack_signed,
   },
};

const struct util_format_unpack_description *
util_format_unpack_description_generic(enum pipe_format format)
{
   if (format >= ARRAY_SIZE(util_format_unpack_descriptions))
      return NULL;

   return &util_format_unpack_descriptions[format];
}

static const util_format_fetch_rgba_func_ptr util_format_fetch_rgba_table[] = {
  [PIPE_FORMAT_NONE] = &util_format_none_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_UNORM] = &util_format_b8g8r8a8_unorm_fetch_rgba,
  [PIPE_FORMAT_B8G8R8X8_UNORM] = &util_format_b8g8r8x8_unorm_fetch_rgba,
  [PIPE_FORMAT_B8G8R8X8_SNORM] = &util_format_b8g8r8x8_snorm_fetch_rgba,
  [PIPE_FORMAT_B8G8R8X8_UINT] = &util_format_b8g8r8x8_uint_fetch_rgba,
  [PIPE_FORMAT_B8G8R8X8_SINT] = &util_format_b8g8r8x8_sint_fetch_rgba,
  [PIPE_FORMAT_A8R8G8B8_UNORM] = &util_format_a8r8g8b8_unorm_fetch_rgba,
  [PIPE_FORMAT_A8R8G8B8_SNORM] = &util_format_a8r8g8b8_snorm_fetch_rgba,
  [PIPE_FORMAT_A8R8G8B8_SINT] = &util_format_a8r8g8b8_sint_fetch_rgba,
  [PIPE_FORMAT_X8R8G8B8_UNORM] = &util_format_x8r8g8b8_unorm_fetch_rgba,
  [PIPE_FORMAT_X8R8G8B8_SNORM] = &util_format_x8r8g8b8_snorm_fetch_rgba,
  [PIPE_FORMAT_X8R8G8B8_SINT] = &util_format_x8r8g8b8_sint_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_UNORM] = &util_format_a8b8g8r8_unorm_fetch_rgba,
  [PIPE_FORMAT_X8B8G8R8_UNORM] = &util_format_x8b8g8r8_unorm_fetch_rgba,
  [PIPE_FORMAT_R8G8B8X8_UNORM] = &util_format_r8g8b8x8_unorm_fetch_rgba,
  [PIPE_FORMAT_R5G5B5A1_UNORM] = &util_format_r5g5b5a1_unorm_fetch_rgba,
  [PIPE_FORMAT_R5G5B5X1_UNORM] = &util_format_r5g5b5x1_unorm_fetch_rgba,
  [PIPE_FORMAT_B5G5R5X1_UNORM] = &util_format_b5g5r5x1_unorm_fetch_rgba,
  [PIPE_FORMAT_B5G5R5A1_UNORM] = &util_format_b5g5r5a1_unorm_fetch_rgba,
  [PIPE_FORMAT_X1B5G5R5_UNORM] = &util_format_x1b5g5r5_unorm_fetch_rgba,
  [PIPE_FORMAT_A1R5G5B5_UNORM] = &util_format_a1r5g5b5_unorm_fetch_rgba,
  [PIPE_FORMAT_X1R5G5B5_UNORM] = &util_format_x1r5g5b5_unorm_fetch_rgba,
  [PIPE_FORMAT_A1B5G5R5_UNORM] = &util_format_a1b5g5r5_unorm_fetch_rgba,
  [PIPE_FORMAT_R4G4B4A4_UNORM] = &util_format_r4g4b4a4_unorm_fetch_rgba,
  [PIPE_FORMAT_R4G4B4X4_UNORM] = &util_format_r4g4b4x4_unorm_fetch_rgba,
  [PIPE_FORMAT_B4G4R4A4_UNORM] = &util_format_b4g4r4a4_unorm_fetch_rgba,
  [PIPE_FORMAT_B4G4R4X4_UNORM] = &util_format_b4g4r4x4_unorm_fetch_rgba,
  [PIPE_FORMAT_A4R4G4B4_UNORM] = &util_format_a4r4g4b4_unorm_fetch_rgba,
  [PIPE_FORMAT_A4B4G4R4_UNORM] = &util_format_a4b4g4r4_unorm_fetch_rgba,
  [PIPE_FORMAT_R5G6B5_UNORM] = &util_format_r5g6b5_unorm_fetch_rgba,
  [PIPE_FORMAT_B5G6R5_UNORM] = &util_format_b5g6r5_unorm_fetch_rgba,
  [PIPE_FORMAT_R10G10B10A2_UNORM] = &util_format_r10g10b10a2_unorm_fetch_rgba,
  [PIPE_FORMAT_R10G10B10X2_UNORM] = &util_format_r10g10b10x2_unorm_fetch_rgba,
  [PIPE_FORMAT_B10G10R10A2_UNORM] = &util_format_b10g10r10a2_unorm_fetch_rgba,
  [PIPE_FORMAT_A2R10G10B10_UNORM] = &util_format_a2r10g10b10_unorm_fetch_rgba,
  [PIPE_FORMAT_A2B10G10R10_UNORM] = &util_format_a2b10g10r10_unorm_fetch_rgba,
  [PIPE_FORMAT_R3G3B2_UNORM] = &util_format_r3g3b2_unorm_fetch_rgba,
  [PIPE_FORMAT_B2G3R3_UNORM] = &util_format_b2g3r3_unorm_fetch_rgba,
  [PIPE_FORMAT_L8_UNORM] = &util_format_l8_unorm_fetch_rgba,
  [PIPE_FORMAT_A8_UNORM] = &util_format_a8_unorm_fetch_rgba,
  [PIPE_FORMAT_I8_UNORM] = &util_format_i8_unorm_fetch_rgba,
  [PIPE_FORMAT_L4A4_UNORM] = &util_format_l4a4_unorm_fetch_rgba,
  [PIPE_FORMAT_L8A8_UNORM] = &util_format_l8a8_unorm_fetch_rgba,
  [PIPE_FORMAT_L16_UNORM] = &util_format_l16_unorm_fetch_rgba,
  [PIPE_FORMAT_A16_UNORM] = &util_format_a16_unorm_fetch_rgba,
  [PIPE_FORMAT_I16_UNORM] = &util_format_i16_unorm_fetch_rgba,
  [PIPE_FORMAT_L16A16_UNORM] = &util_format_l16a16_unorm_fetch_rgba,
  [PIPE_FORMAT_A8_SNORM] = &util_format_a8_snorm_fetch_rgba,
  [PIPE_FORMAT_L8_SNORM] = &util_format_l8_snorm_fetch_rgba,
  [PIPE_FORMAT_L8A8_SNORM] = &util_format_l8a8_snorm_fetch_rgba,
  [PIPE_FORMAT_I8_SNORM] = &util_format_i8_snorm_fetch_rgba,
  [PIPE_FORMAT_A16_SNORM] = &util_format_a16_snorm_fetch_rgba,
  [PIPE_FORMAT_L16_SNORM] = &util_format_l16_snorm_fetch_rgba,
  [PIPE_FORMAT_L16A16_SNORM] = &util_format_l16a16_snorm_fetch_rgba,
  [PIPE_FORMAT_I16_SNORM] = &util_format_i16_snorm_fetch_rgba,
  [PIPE_FORMAT_A16_FLOAT] = &util_format_a16_float_fetch_rgba,
  [PIPE_FORMAT_L16_FLOAT] = &util_format_l16_float_fetch_rgba,
  [PIPE_FORMAT_L16A16_FLOAT] = &util_format_l16a16_float_fetch_rgba,
  [PIPE_FORMAT_I16_FLOAT] = &util_format_i16_float_fetch_rgba,
  [PIPE_FORMAT_A32_FLOAT] = &util_format_a32_float_fetch_rgba,
  [PIPE_FORMAT_L32_FLOAT] = &util_format_l32_float_fetch_rgba,
  [PIPE_FORMAT_L32A32_FLOAT] = &util_format_l32a32_float_fetch_rgba,
  [PIPE_FORMAT_I32_FLOAT] = &util_format_i32_float_fetch_rgba,
  [PIPE_FORMAT_L8_SRGB] = &util_format_l8_srgb_fetch_rgba,
  [PIPE_FORMAT_R8_SRGB] = &util_format_r8_srgb_fetch_rgba,
  [PIPE_FORMAT_L8A8_SRGB] = &util_format_l8a8_srgb_fetch_rgba,
  [PIPE_FORMAT_R8G8_SRGB] = &util_format_r8g8_srgb_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_SRGB] = &util_format_r8g8b8_srgb_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_SRGB] = &util_format_b8g8r8_srgb_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_SRGB] = &util_format_r8g8b8a8_srgb_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_SRGB] = &util_format_a8b8g8r8_srgb_fetch_rgba,
  [PIPE_FORMAT_X8B8G8R8_SRGB] = &util_format_x8b8g8r8_srgb_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_SRGB] = &util_format_b8g8r8a8_srgb_fetch_rgba,
  [PIPE_FORMAT_B8G8R8X8_SRGB] = &util_format_b8g8r8x8_srgb_fetch_rgba,
  [PIPE_FORMAT_A8R8G8B8_SRGB] = &util_format_a8r8g8b8_srgb_fetch_rgba,
  [PIPE_FORMAT_X8R8G8B8_SRGB] = &util_format_x8r8g8b8_srgb_fetch_rgba,
  [PIPE_FORMAT_R8SG8SB8UX8U_NORM] = &util_format_r8sg8sb8ux8u_norm_fetch_rgba,
  [PIPE_FORMAT_R10SG10SB10SA2U_NORM] = &util_format_r10sg10sb10sa2u_norm_fetch_rgba,
  [PIPE_FORMAT_R5SG5SB6U_NORM] = &util_format_r5sg5sb6u_norm_fetch_rgba,
  [PIPE_FORMAT_S8_UINT] = NULL,
  [PIPE_FORMAT_Z16_UNORM] = NULL,
  [PIPE_FORMAT_Z16_UNORM_S8_UINT] = NULL,
  [PIPE_FORMAT_Z32_UNORM] = NULL,
  [PIPE_FORMAT_Z32_FLOAT] = NULL,
  [PIPE_FORMAT_Z24_UNORM_S8_UINT] = NULL,
  [PIPE_FORMAT_S8_UINT_Z24_UNORM] = NULL,
  [PIPE_FORMAT_X24S8_UINT] = NULL,
  [PIPE_FORMAT_S8X24_UINT] = NULL,
  [PIPE_FORMAT_Z24X8_UNORM] = NULL,
  [PIPE_FORMAT_X8Z24_UNORM] = NULL,
  [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = NULL,
  [PIPE_FORMAT_X32_S8X24_UINT] = NULL,
  [PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8] = &util_format_z24_unorm_s8_uint_as_r8g8b8a8_fetch_rgba,
  [PIPE_FORMAT_UYVY] = &util_format_uyvy_fetch_rgba,
  [PIPE_FORMAT_YUYV] = &util_format_yuyv_fetch_rgba,
  [PIPE_FORMAT_AYUV] = NULL,
  [PIPE_FORMAT_XYUV] = NULL,
  [PIPE_FORMAT_R8G8_B8G8_UNORM] = &util_format_r8g8_b8g8_unorm_fetch_rgba,
  [PIPE_FORMAT_G8R8_G8B8_UNORM] = NULL,
  [PIPE_FORMAT_G8R8_B8R8_UNORM] = NULL,
  [PIPE_FORMAT_R8G8_R8B8_UNORM] = NULL,
  [PIPE_FORMAT_R11G11B10_FLOAT] = &util_format_r11g11b10_float_fetch_rgba,
  [PIPE_FORMAT_R9G9B9E5_FLOAT] = &util_format_r9g9b9e5_float_fetch_rgba,
  [PIPE_FORMAT_R1_UNORM] = NULL,
  [PIPE_FORMAT_R8G8Bx_SNORM] = &util_format_r8g8bx_snorm_fetch_rgba,
  [PIPE_FORMAT_DXT1_RGB] = &util_format_dxt1_rgb_fetch_rgba,
  [PIPE_FORMAT_DXT1_RGBA] = &util_format_dxt1_rgba_fetch_rgba,
  [PIPE_FORMAT_DXT3_RGBA] = &util_format_dxt3_rgba_fetch_rgba,
  [PIPE_FORMAT_DXT5_RGBA] = &util_format_dxt5_rgba_fetch_rgba,
  [PIPE_FORMAT_DXT1_SRGB] = &util_format_dxt1_srgb_fetch_rgba,
  [PIPE_FORMAT_DXT1_SRGBA] = &util_format_dxt1_srgba_fetch_rgba,
  [PIPE_FORMAT_DXT3_SRGBA] = &util_format_dxt3_srgba_fetch_rgba,
  [PIPE_FORMAT_DXT5_SRGBA] = &util_format_dxt5_srgba_fetch_rgba,
  [PIPE_FORMAT_FXT1_RGB] = &util_format_fxt1_rgb_fetch_rgba,
  [PIPE_FORMAT_FXT1_RGBA] = &util_format_fxt1_rgba_fetch_rgba,
  [PIPE_FORMAT_RGTC1_UNORM] = &util_format_rgtc1_unorm_fetch_rgba,
  [PIPE_FORMAT_RGTC1_SNORM] = &util_format_rgtc1_snorm_fetch_rgba,
  [PIPE_FORMAT_RGTC2_UNORM] = &util_format_rgtc2_unorm_fetch_rgba,
  [PIPE_FORMAT_RGTC2_SNORM] = &util_format_rgtc2_snorm_fetch_rgba,
  [PIPE_FORMAT_LATC1_UNORM] = &util_format_latc1_unorm_fetch_rgba,
  [PIPE_FORMAT_LATC1_SNORM] = &util_format_latc1_snorm_fetch_rgba,
  [PIPE_FORMAT_LATC2_UNORM] = &util_format_latc2_unorm_fetch_rgba,
  [PIPE_FORMAT_LATC2_SNORM] = &util_format_latc2_snorm_fetch_rgba,
  [PIPE_FORMAT_ETC1_RGB8] = &util_format_etc1_rgb8_fetch_rgba,
  [PIPE_FORMAT_ETC2_RGB8] = NULL,
  [PIPE_FORMAT_ETC2_SRGB8] = NULL,
  [PIPE_FORMAT_ETC2_RGB8A1] = NULL,
  [PIPE_FORMAT_ETC2_SRGB8A1] = NULL,
  [PIPE_FORMAT_ETC2_RGBA8] = NULL,
  [PIPE_FORMAT_ETC2_SRGBA8] = NULL,
  [PIPE_FORMAT_ETC2_R11_UNORM] = NULL,
  [PIPE_FORMAT_ETC2_R11_SNORM] = NULL,
  [PIPE_FORMAT_ETC2_RG11_UNORM] = NULL,
  [PIPE_FORMAT_ETC2_RG11_SNORM] = NULL,
  [PIPE_FORMAT_BPTC_RGBA_UNORM] = &util_format_bptc_rgba_unorm_fetch_rgba,
  [PIPE_FORMAT_BPTC_SRGBA] = &util_format_bptc_srgba_fetch_rgba,
  [PIPE_FORMAT_BPTC_RGB_FLOAT] = &util_format_bptc_rgb_float_fetch_rgba,
  [PIPE_FORMAT_BPTC_RGB_UFLOAT] = &util_format_bptc_rgb_ufloat_fetch_rgba,
  [PIPE_FORMAT_ASTC_4x4] = NULL,
  [PIPE_FORMAT_ASTC_5x4] = NULL,
  [PIPE_FORMAT_ASTC_5x5] = NULL,
  [PIPE_FORMAT_ASTC_6x5] = NULL,
  [PIPE_FORMAT_ASTC_6x6] = NULL,
  [PIPE_FORMAT_ASTC_8x5] = NULL,
  [PIPE_FORMAT_ASTC_8x6] = NULL,
  [PIPE_FORMAT_ASTC_8x8] = NULL,
  [PIPE_FORMAT_ASTC_10x5] = NULL,
  [PIPE_FORMAT_ASTC_10x6] = NULL,
  [PIPE_FORMAT_ASTC_10x8] = NULL,
  [PIPE_FORMAT_ASTC_10x10] = NULL,
  [PIPE_FORMAT_ASTC_12x10] = NULL,
  [PIPE_FORMAT_ASTC_12x12] = NULL,
  [PIPE_FORMAT_ASTC_4x4_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_5x4_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_5x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_6x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_6x6_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_8x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_8x6_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_8x8_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_10x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_10x6_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_10x8_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_10x10_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_12x10_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_12x12_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_3x3x3] = NULL,
  [PIPE_FORMAT_ASTC_4x3x3] = NULL,
  [PIPE_FORMAT_ASTC_4x4x3] = NULL,
  [PIPE_FORMAT_ASTC_4x4x4] = NULL,
  [PIPE_FORMAT_ASTC_5x4x4] = NULL,
  [PIPE_FORMAT_ASTC_5x5x4] = NULL,
  [PIPE_FORMAT_ASTC_5x5x5] = NULL,
  [PIPE_FORMAT_ASTC_6x5x5] = NULL,
  [PIPE_FORMAT_ASTC_6x6x5] = NULL,
  [PIPE_FORMAT_ASTC_6x6x6] = NULL,
  [PIPE_FORMAT_ASTC_3x3x3_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_4x3x3_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_4x4x3_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_4x4x4_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_5x4x4_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_5x5x4_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_5x5x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_6x5x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_6x6x5_SRGB] = NULL,
  [PIPE_FORMAT_ASTC_6x6x6_SRGB] = NULL,
  [PIPE_FORMAT_ATC_RGB] = NULL,
  [PIPE_FORMAT_ATC_RGBA_EXPLICIT] = NULL,
  [PIPE_FORMAT_ATC_RGBA_INTERPOLATED] = NULL,
  [PIPE_FORMAT_R64_FLOAT] = &util_format_r64_float_fetch_rgba,
  [PIPE_FORMAT_R64G64_FLOAT] = &util_format_r64g64_float_fetch_rgba,
  [PIPE_FORMAT_R64G64B64_FLOAT] = &util_format_r64g64b64_float_fetch_rgba,
  [PIPE_FORMAT_R64G64B64A64_FLOAT] = &util_format_r64g64b64a64_float_fetch_rgba,
  [PIPE_FORMAT_R32_FLOAT] = &util_format_r32_float_fetch_rgba,
  [PIPE_FORMAT_R32G32_FLOAT] = &util_format_r32g32_float_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_FLOAT] = &util_format_r32g32b32_float_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_FLOAT] = &util_format_r32g32b32a32_float_fetch_rgba,
  [PIPE_FORMAT_R32_UNORM] = &util_format_r32_unorm_fetch_rgba,
  [PIPE_FORMAT_R32G32_UNORM] = &util_format_r32g32_unorm_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_UNORM] = &util_format_r32g32b32_unorm_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_UNORM] = &util_format_r32g32b32a32_unorm_fetch_rgba,
  [PIPE_FORMAT_R32_USCALED] = &util_format_r32_uscaled_fetch_rgba,
  [PIPE_FORMAT_R32G32_USCALED] = &util_format_r32g32_uscaled_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_USCALED] = &util_format_r32g32b32_uscaled_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_USCALED] = &util_format_r32g32b32a32_uscaled_fetch_rgba,
  [PIPE_FORMAT_R32_SNORM] = &util_format_r32_snorm_fetch_rgba,
  [PIPE_FORMAT_R32G32_SNORM] = &util_format_r32g32_snorm_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_SNORM] = &util_format_r32g32b32_snorm_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_SNORM] = &util_format_r32g32b32a32_snorm_fetch_rgba,
  [PIPE_FORMAT_R32_SSCALED] = &util_format_r32_sscaled_fetch_rgba,
  [PIPE_FORMAT_R32G32_SSCALED] = &util_format_r32g32_sscaled_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_SSCALED] = &util_format_r32g32b32_sscaled_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_SSCALED] = &util_format_r32g32b32a32_sscaled_fetch_rgba,
  [PIPE_FORMAT_R16_FLOAT] = &util_format_r16_float_fetch_rgba,
  [PIPE_FORMAT_R16G16_FLOAT] = &util_format_r16g16_float_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_FLOAT] = &util_format_r16g16b16_float_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_FLOAT] = &util_format_r16g16b16a16_float_fetch_rgba,
  [PIPE_FORMAT_R16_UNORM] = &util_format_r16_unorm_fetch_rgba,
  [PIPE_FORMAT_R16G16_UNORM] = &util_format_r16g16_unorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_UNORM] = &util_format_r16g16b16_unorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_UNORM] = &util_format_r16g16b16a16_unorm_fetch_rgba,
  [PIPE_FORMAT_R16_USCALED] = &util_format_r16_uscaled_fetch_rgba,
  [PIPE_FORMAT_R16G16_USCALED] = &util_format_r16g16_uscaled_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_USCALED] = &util_format_r16g16b16_uscaled_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_USCALED] = &util_format_r16g16b16a16_uscaled_fetch_rgba,
  [PIPE_FORMAT_R16_SNORM] = &util_format_r16_snorm_fetch_rgba,
  [PIPE_FORMAT_R16G16_SNORM] = &util_format_r16g16_snorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_SNORM] = &util_format_r16g16b16_snorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_SNORM] = &util_format_r16g16b16a16_snorm_fetch_rgba,
  [PIPE_FORMAT_R16_SSCALED] = &util_format_r16_sscaled_fetch_rgba,
  [PIPE_FORMAT_R16G16_SSCALED] = &util_format_r16g16_sscaled_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_SSCALED] = &util_format_r16g16b16_sscaled_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_SSCALED] = &util_format_r16g16b16a16_sscaled_fetch_rgba,
  [PIPE_FORMAT_R8_UNORM] = &util_format_r8_unorm_fetch_rgba,
  [PIPE_FORMAT_R8G8_UNORM] = &util_format_r8g8_unorm_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_UNORM] = &util_format_r8g8b8_unorm_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_UNORM] = &util_format_b8g8r8_unorm_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_UNORM] = &util_format_r8g8b8a8_unorm_fetch_rgba,
  [PIPE_FORMAT_R8_USCALED] = &util_format_r8_uscaled_fetch_rgba,
  [PIPE_FORMAT_R8G8_USCALED] = &util_format_r8g8_uscaled_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_USCALED] = &util_format_r8g8b8_uscaled_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_USCALED] = &util_format_b8g8r8_uscaled_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_USCALED] = &util_format_r8g8b8a8_uscaled_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_USCALED] = &util_format_b8g8r8a8_uscaled_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_USCALED] = &util_format_a8b8g8r8_uscaled_fetch_rgba,
  [PIPE_FORMAT_R8_SNORM] = &util_format_r8_snorm_fetch_rgba,
  [PIPE_FORMAT_R8G8_SNORM] = &util_format_r8g8_snorm_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_SNORM] = &util_format_r8g8b8_snorm_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_SNORM] = &util_format_b8g8r8_snorm_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_SNORM] = &util_format_r8g8b8a8_snorm_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_SNORM] = &util_format_b8g8r8a8_snorm_fetch_rgba,
  [PIPE_FORMAT_R8_SSCALED] = &util_format_r8_sscaled_fetch_rgba,
  [PIPE_FORMAT_R8G8_SSCALED] = &util_format_r8g8_sscaled_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_SSCALED] = &util_format_r8g8b8_sscaled_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_SSCALED] = &util_format_b8g8r8_sscaled_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_SSCALED] = &util_format_r8g8b8a8_sscaled_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_SSCALED] = &util_format_b8g8r8a8_sscaled_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_SSCALED] = &util_format_a8b8g8r8_sscaled_fetch_rgba,
  [PIPE_FORMAT_R32_FIXED] = &util_format_r32_fixed_fetch_rgba,
  [PIPE_FORMAT_R32G32_FIXED] = &util_format_r32g32_fixed_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_FIXED] = &util_format_r32g32b32_fixed_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_FIXED] = &util_format_r32g32b32a32_fixed_fetch_rgba,
  [PIPE_FORMAT_R10G10B10X2_USCALED] = &util_format_r10g10b10x2_uscaled_fetch_rgba,
  [PIPE_FORMAT_R10G10B10X2_SNORM] = &util_format_r10g10b10x2_snorm_fetch_rgba,
  [PIPE_FORMAT_YV12] = NULL,
  [PIPE_FORMAT_YV16] = NULL,
  [PIPE_FORMAT_IYUV] = NULL,
  [PIPE_FORMAT_NV12] = NULL,
  [PIPE_FORMAT_NV21] = NULL,
  [PIPE_FORMAT_R8_G8B8_420_UNORM] = NULL,
  [PIPE_FORMAT_R8_G8_B8_420_UNORM] = NULL,
  [PIPE_FORMAT_Y8_U8_V8_422_UNORM] = NULL,
  [PIPE_FORMAT_Y8_U8V8_422_UNORM] = NULL,
  [PIPE_FORMAT_Y8_U8_V8_444_UNORM] = NULL,
  [PIPE_FORMAT_Y16_U16_V16_420_UNORM] = NULL,
  [PIPE_FORMAT_Y16_U16_V16_422_UNORM] = NULL,
  [PIPE_FORMAT_Y16_U16V16_422_UNORM] = NULL,
  [PIPE_FORMAT_Y16_U16_V16_444_UNORM] = NULL,
  [PIPE_FORMAT_P010] = NULL,
  [PIPE_FORMAT_P012] = NULL,
  [PIPE_FORMAT_P016] = NULL,
  [PIPE_FORMAT_Y210] = NULL,
  [PIPE_FORMAT_Y212] = NULL,
  [PIPE_FORMAT_Y216] = NULL,
  [PIPE_FORMAT_Y410] = NULL,
  [PIPE_FORMAT_Y412] = NULL,
  [PIPE_FORMAT_Y416] = NULL,
  [PIPE_FORMAT_A4R4_UNORM] = &util_format_a4r4_unorm_fetch_rgba,
  [PIPE_FORMAT_R4A4_UNORM] = &util_format_r4a4_unorm_fetch_rgba,
  [PIPE_FORMAT_R8A8_UNORM] = &util_format_r8a8_unorm_fetch_rgba,
  [PIPE_FORMAT_A8R8_UNORM] = &util_format_a8r8_unorm_fetch_rgba,
  [PIPE_FORMAT_R10G10B10A2_USCALED] = &util_format_r10g10b10a2_uscaled_fetch_rgba,
  [PIPE_FORMAT_R10G10B10A2_SSCALED] = &util_format_r10g10b10a2_sscaled_fetch_rgba,
  [PIPE_FORMAT_R10G10B10A2_SNORM] = &util_format_r10g10b10a2_snorm_fetch_rgba,
  [PIPE_FORMAT_B10G10R10A2_USCALED] = &util_format_b10g10r10a2_uscaled_fetch_rgba,
  [PIPE_FORMAT_B10G10R10A2_SSCALED] = &util_format_b10g10r10a2_sscaled_fetch_rgba,
  [PIPE_FORMAT_B10G10R10A2_SNORM] = &util_format_b10g10r10a2_snorm_fetch_rgba,
  [PIPE_FORMAT_R8_UINT] = &util_format_r8_uint_fetch_rgba,
  [PIPE_FORMAT_R8G8_UINT] = &util_format_r8g8_uint_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_UINT] = &util_format_r8g8b8_uint_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_UINT] = &util_format_r8g8b8a8_uint_fetch_rgba,
  [PIPE_FORMAT_R8_SINT] = &util_format_r8_sint_fetch_rgba,
  [PIPE_FORMAT_R8G8_SINT] = &util_format_r8g8_sint_fetch_rgba,
  [PIPE_FORMAT_R8G8B8_SINT] = &util_format_r8g8b8_sint_fetch_rgba,
  [PIPE_FORMAT_R8G8B8A8_SINT] = &util_format_r8g8b8a8_sint_fetch_rgba,
  [PIPE_FORMAT_R16_UINT] = &util_format_r16_uint_fetch_rgba,
  [PIPE_FORMAT_R16G16_UINT] = &util_format_r16g16_uint_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_UINT] = &util_format_r16g16b16_uint_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_UINT] = &util_format_r16g16b16a16_uint_fetch_rgba,
  [PIPE_FORMAT_R16_SINT] = &util_format_r16_sint_fetch_rgba,
  [PIPE_FORMAT_R16G16_SINT] = &util_format_r16g16_sint_fetch_rgba,
  [PIPE_FORMAT_R16G16B16_SINT] = &util_format_r16g16b16_sint_fetch_rgba,
  [PIPE_FORMAT_R16G16B16A16_SINT] = &util_format_r16g16b16a16_sint_fetch_rgba,
  [PIPE_FORMAT_R32_UINT] = &util_format_r32_uint_fetch_rgba,
  [PIPE_FORMAT_R32G32_UINT] = &util_format_r32g32_uint_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_UINT] = &util_format_r32g32b32_uint_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_UINT] = &util_format_r32g32b32a32_uint_fetch_rgba,
  [PIPE_FORMAT_R32_SINT] = &util_format_r32_sint_fetch_rgba,
  [PIPE_FORMAT_R32G32_SINT] = &util_format_r32g32_sint_fetch_rgba,
  [PIPE_FORMAT_R32G32B32_SINT] = &util_format_r32g32b32_sint_fetch_rgba,
  [PIPE_FORMAT_R32G32B32A32_SINT] = &util_format_r32g32b32a32_sint_fetch_rgba,
  [PIPE_FORMAT_R64_UINT] = &util_format_r64_uint_fetch_rgba,
  [PIPE_FORMAT_R64G64_UINT] = &util_format_r64g64_uint_fetch_rgba,
  [PIPE_FORMAT_R64G64B64_UINT] = &util_format_r64g64b64_uint_fetch_rgba,
  [PIPE_FORMAT_R64G64B64A64_UINT] = &util_format_r64g64b64a64_uint_fetch_rgba,
  [PIPE_FORMAT_R64_SINT] = &util_format_r64_sint_fetch_rgba,
  [PIPE_FORMAT_A8_UINT] = &util_format_a8_uint_fetch_rgba,
  [PIPE_FORMAT_I8_UINT] = &util_format_i8_uint_fetch_rgba,
  [PIPE_FORMAT_L8_UINT] = &util_format_l8_uint_fetch_rgba,
  [PIPE_FORMAT_L8A8_UINT] = &util_format_l8a8_uint_fetch_rgba,
  [PIPE_FORMAT_A8_SINT] = &util_format_a8_sint_fetch_rgba,
  [PIPE_FORMAT_I8_SINT] = &util_format_i8_sint_fetch_rgba,
  [PIPE_FORMAT_L8_SINT] = &util_format_l8_sint_fetch_rgba,
  [PIPE_FORMAT_L8A8_SINT] = &util_format_l8a8_sint_fetch_rgba,
  [PIPE_FORMAT_A16_UINT] = &util_format_a16_uint_fetch_rgba,
  [PIPE_FORMAT_I16_UINT] = &util_format_i16_uint_fetch_rgba,
  [PIPE_FORMAT_L16_UINT] = &util_format_l16_uint_fetch_rgba,
  [PIPE_FORMAT_L16A16_UINT] = &util_format_l16a16_uint_fetch_rgba,
  [PIPE_FORMAT_A16_SINT] = &util_format_a16_sint_fetch_rgba,
  [PIPE_FORMAT_I16_SINT] = &util_format_i16_sint_fetch_rgba,
  [PIPE_FORMAT_L16_SINT] = &util_format_l16_sint_fetch_rgba,
  [PIPE_FORMAT_L16A16_SINT] = &util_format_l16a16_sint_fetch_rgba,
  [PIPE_FORMAT_A32_UINT] = &util_format_a32_uint_fetch_rgba,
  [PIPE_FORMAT_I32_UINT] = &util_format_i32_uint_fetch_rgba,
  [PIPE_FORMAT_L32_UINT] = &util_format_l32_uint_fetch_rgba,
  [PIPE_FORMAT_L32A32_UINT] = &util_format_l32a32_uint_fetch_rgba,
  [PIPE_FORMAT_A32_SINT] = &util_format_a32_sint_fetch_rgba,
  [PIPE_FORMAT_I32_SINT] = &util_format_i32_sint_fetch_rgba,
  [PIPE_FORMAT_L32_SINT] = &util_format_l32_sint_fetch_rgba,
  [PIPE_FORMAT_L32A32_SINT] = &util_format_l32a32_sint_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_UINT] = &util_format_b8g8r8_uint_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_UINT] = &util_format_b8g8r8a8_uint_fetch_rgba,
  [PIPE_FORMAT_B8G8R8_SINT] = &util_format_b8g8r8_sint_fetch_rgba,
  [PIPE_FORMAT_B8G8R8A8_SINT] = &util_format_b8g8r8a8_sint_fetch_rgba,
  [PIPE_FORMAT_A8R8G8B8_UINT] = &util_format_a8r8g8b8_uint_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_UINT] = &util_format_a8b8g8r8_uint_fetch_rgba,
  [PIPE_FORMAT_A2R10G10B10_UINT] = &util_format_a2r10g10b10_uint_fetch_rgba,
  [PIPE_FORMAT_A2B10G10R10_UINT] = &util_format_a2b10g10r10_uint_fetch_rgba,
  [PIPE_FORMAT_B10G10R10A2_UINT] = &util_format_b10g10r10a2_uint_fetch_rgba,
  [PIPE_FORMAT_B10G10R10A2_SINT] = &util_format_b10g10r10a2_sint_fetch_rgba,
  [PIPE_FORMAT_R5G6B5_UINT] = &util_format_r5g6b5_uint_fetch_rgba,
  [PIPE_FORMAT_B5G6R5_UINT] = &util_format_b5g6r5_uint_fetch_rgba,
  [PIPE_FORMAT_R3G3B2_UINT] = &util_format_r3g3b2_uint_fetch_rgba,
  [PIPE_FORMAT_B2G3R3_UINT] = &util_format_b2g3r3_uint_fetch_rgba,
  [PIPE_FORMAT_R4G4B4A4_UINT] = &util_format_r4g4b4a4_uint_fetch_rgba,
  [PIPE_FORMAT_B4G4R4A4_UINT] = &util_format_b4g4r4a4_uint_fetch_rgba,
  [PIPE_FORMAT_A4R4G4B4_UINT] = &util_format_a4r4g4b4_uint_fetch_rgba,
  [PIPE_FORMAT_A4B4G4R4_UINT] = &util_format_a4b4g4r4_uint_fetch_rgba,
  [PIPE_FORMAT_A1R5G5B5_UINT] = &util_format_a1r5g5b5_uint_fetch_rgba,
  [PIPE_FORMAT_A1B5G5R5_UINT] = &util_format_a1b5g5r5_uint_fetch_rgba,
  [PIPE_FORMAT_R5G5B5A1_UINT] = &util_format_r5g5b5a1_uint_fetch_rgba,
  [PIPE_FORMAT_B5G5R5A1_UINT] = &util_format_b5g5r5a1_uint_fetch_rgba,
  [PIPE_FORMAT_R8G8B8X8_SNORM] = &util_format_r8g8b8x8_snorm_fetch_rgba,
  [PIPE_FORMAT_R8G8B8X8_SRGB] = &util_format_r8g8b8x8_srgb_fetch_rgba,
  [PIPE_FORMAT_R8G8B8X8_UINT] = &util_format_r8g8b8x8_uint_fetch_rgba,
  [PIPE_FORMAT_R8G8B8X8_SINT] = &util_format_r8g8b8x8_sint_fetch_rgba,
  [PIPE_FORMAT_B10G10R10X2_UNORM] = &util_format_b10g10r10x2_unorm_fetch_rgba,
  [PIPE_FORMAT_B10G10R10X2_SNORM] = &util_format_b10g10r10x2_snorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16X16_UNORM] = &util_format_r16g16b16x16_unorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16X16_SNORM] = &util_format_r16g16b16x16_snorm_fetch_rgba,
  [PIPE_FORMAT_R16G16B16X16_FLOAT] = &util_format_r16g16b16x16_float_fetch_rgba,
  [PIPE_FORMAT_R16G16B16X16_UINT] = &util_format_r16g16b16x16_uint_fetch_rgba,
  [PIPE_FORMAT_R16G16B16X16_SINT] = &util_format_r16g16b16x16_sint_fetch_rgba,
  [PIPE_FORMAT_R32G32B32X32_FLOAT] = &util_format_r32g32b32x32_float_fetch_rgba,
  [PIPE_FORMAT_R32G32B32X32_UINT] = &util_format_r32g32b32x32_uint_fetch_rgba,
  [PIPE_FORMAT_R32G32B32X32_SINT] = &util_format_r32g32b32x32_sint_fetch_rgba,
  [PIPE_FORMAT_R8A8_SNORM] = &util_format_r8a8_snorm_fetch_rgba,
  [PIPE_FORMAT_R16A16_UNORM] = &util_format_r16a16_unorm_fetch_rgba,
  [PIPE_FORMAT_R16A16_SNORM] = &util_format_r16a16_snorm_fetch_rgba,
  [PIPE_FORMAT_R16A16_FLOAT] = &util_format_r16a16_float_fetch_rgba,
  [PIPE_FORMAT_R32A32_FLOAT] = &util_format_r32a32_float_fetch_rgba,
  [PIPE_FORMAT_R8A8_UINT] = &util_format_r8a8_uint_fetch_rgba,
  [PIPE_FORMAT_R8A8_SINT] = &util_format_r8a8_sint_fetch_rgba,
  [PIPE_FORMAT_R16A16_UINT] = &util_format_r16a16_uint_fetch_rgba,
  [PIPE_FORMAT_R16A16_SINT] = &util_format_r16a16_sint_fetch_rgba,
  [PIPE_FORMAT_R32A32_UINT] = &util_format_r32a32_uint_fetch_rgba,
  [PIPE_FORMAT_R32A32_SINT] = &util_format_r32a32_sint_fetch_rgba,
  [PIPE_FORMAT_R10G10B10A2_UINT] = &util_format_r10g10b10a2_uint_fetch_rgba,
  [PIPE_FORMAT_R10G10B10A2_SINT] = &util_format_r10g10b10a2_sint_fetch_rgba,
  [PIPE_FORMAT_B5G6R5_SRGB] = &util_format_b5g6r5_srgb_fetch_rgba,
  [PIPE_FORMAT_R5G6B5_SRGB] = &util_format_r5g6b5_srgb_fetch_rgba,
  [PIPE_FORMAT_G8R8_UNORM] = &util_format_g8r8_unorm_fetch_rgba,
  [PIPE_FORMAT_G8R8_SNORM] = &util_format_g8r8_snorm_fetch_rgba,
  [PIPE_FORMAT_G8R8_SINT] = &util_format_g8r8_sint_fetch_rgba,
  [PIPE_FORMAT_G16R16_UNORM] = &util_format_g16r16_unorm_fetch_rgba,
  [PIPE_FORMAT_G16R16_SNORM] = &util_format_g16r16_snorm_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_SNORM] = &util_format_a8b8g8r8_snorm_fetch_rgba,
  [PIPE_FORMAT_A8B8G8R8_SINT] = &util_format_a8b8g8r8_sint_fetch_rgba,
  [PIPE_FORMAT_X8B8G8R8_SNORM] = &util_format_x8b8g8r8_snorm_fetch_rgba,
  [PIPE_FORMAT_X8B8G8R8_SINT] = &util_format_x8b8g8r8_sint_fetch_rgba,
};

util_format_fetch_rgba_func_ptr
util_format_fetch_rgba_func(enum pipe_format format)
{
   if (format >= ARRAY_SIZE(util_format_fetch_rgba_table))
      return NULL;

   return util_format_fetch_rgba_table[format];
}

