/* 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 "u_format.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 "u_math.h"
#include "u_half.h"
#include "u_format.h"
#include "u_format_other.h"
#include "u_format_srgb.h"
#include "u_format_yuv.h"
#include "u_format_zs.h"
union util_format_none {
uint8_t value;
struct {
uint8_t r;
} chan;
};
static INLINE void
util_format_none_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t r;
r = value;
dst[0] = (float)r; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = 1; /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_none_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 255);
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_none_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
uint8_t r;
r = value;
dst[0] = (float)r; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = 1; /* a */
}
static INLINE void
util_format_none_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t r;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_none_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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);
}
}
union util_format_b8g8r8a8_unorm {
uint32_t value;
struct {
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
} chan;
};
static INLINE void
util_format_b8g8r8a8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
uint32_t a;
b = (value) & 0xff;
g = (value >> 8) & 0xff;
r = (value >> 16) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_b8g8r8a8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= (float_to_ubyte(src[2])) & 0xff;
value |= ((float_to_ubyte(src[1])) & 0xff) << 8;
value |= ((float_to_ubyte(src[0])) & 0xff) << 16;
value |= (float_to_ubyte(src[3])) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_b8g8r8a8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
uint32_t a;
b = (value) & 0xff;
g = (value >> 8) & 0xff;
r = (value >> 16) & 0xff;
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 */
}
static INLINE void
util_format_b8g8r8a8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
uint32_t a;
b = (value) & 0xff;
g = (value >> 8) & 0xff;
r = (value >> 16) & 0xff;
a = value >> 24;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = a; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_b8g8r8a8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= (src[2]) & 0xff;
value |= ((src[1]) & 0xff) << 8;
value |= ((src[0]) & 0xff) << 16;
value |= (src[3]) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_b8g8r8x8_unorm {
uint32_t value;
struct {
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t x;
} chan;
};
static INLINE void
util_format_b8g8r8x8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
b = (value) & 0xff;
g = (value >> 8) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_b8g8r8x8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= (float_to_ubyte(src[2])) & 0xff;
value |= ((float_to_ubyte(src[1])) & 0xff) << 8;
value |= ((float_to_ubyte(src[0])) & 0xff) << 16;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_b8g8r8x8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
b = (value) & 0xff;
g = (value >> 8) & 0xff;
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 */
}
static INLINE void
util_format_b8g8r8x8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
b = (value) & 0xff;
g = (value >> 8) & 0xff;
r = (value >> 16) & 0xff;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = 255; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_b8g8r8x8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= (src[2]) & 0xff;
value |= ((src[1]) & 0xff) << 8;
value |= ((src[0]) & 0xff) << 16;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_a8r8g8b8_unorm {
uint32_t value;
struct {
uint8_t a;
uint8_t r;
uint8_t g;
uint8_t b;
} chan;
};
static INLINE void
util_format_a8r8g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t a;
uint32_t r;
uint32_t g;
uint32_t b;
a = (value) & 0xff;
r = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8r8g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= (float_to_ubyte(src[3])) & 0xff;
value |= ((float_to_ubyte(src[0])) & 0xff) << 8;
value |= ((float_to_ubyte(src[1])) & 0xff) << 16;
value |= (float_to_ubyte(src[2])) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_a8r8g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t a;
uint32_t r;
uint32_t g;
uint32_t b;
a = (value) & 0xff;
r = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
}
static INLINE void
util_format_a8r8g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t a;
uint32_t r;
uint32_t g;
uint32_t b;
a = (value) & 0xff;
r = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
b = value >> 24;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = a; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8r8g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= (src[3]) & 0xff;
value |= ((src[0]) & 0xff) << 8;
value |= ((src[1]) & 0xff) << 16;
value |= (src[2]) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_x8r8g8b8_unorm {
uint32_t value;
struct {
uint8_t x;
uint8_t r;
uint8_t g;
uint8_t b;
} chan;
};
static INLINE void
util_format_x8r8g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t r;
uint32_t g;
uint32_t b;
r = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_x8r8g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= ((float_to_ubyte(src[0])) & 0xff) << 8;
value |= ((float_to_ubyte(src[1])) & 0xff) << 16;
value |= (float_to_ubyte(src[2])) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_x8r8g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t r;
uint32_t g;
uint32_t b;
r = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
}
static INLINE void
util_format_x8r8g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t r;
uint32_t g;
uint32_t b;
r = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
b = value >> 24;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = 255; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_x8r8g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= ((src[0]) & 0xff) << 8;
value |= ((src[1]) & 0xff) << 16;
value |= (src[2]) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_a8b8g8r8_unorm {
uint32_t value;
struct {
uint8_t a;
uint8_t b;
uint8_t g;
uint8_t r;
} chan;
};
static INLINE void
util_format_a8b8g8r8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t a;
uint32_t b;
uint32_t g;
uint32_t r;
a = (value) & 0xff;
b = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8b8g8r8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= (float_to_ubyte(src[3])) & 0xff;
value |= ((float_to_ubyte(src[2])) & 0xff) << 8;
value |= ((float_to_ubyte(src[1])) & 0xff) << 16;
value |= (float_to_ubyte(src[0])) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_a8b8g8r8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t a;
uint32_t b;
uint32_t g;
uint32_t r;
a = (value) & 0xff;
b = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
}
static INLINE void
util_format_a8b8g8r8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t a;
uint32_t b;
uint32_t g;
uint32_t r;
a = (value) & 0xff;
b = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
r = value >> 24;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = a; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8b8g8r8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= (src[3]) & 0xff;
value |= ((src[2]) & 0xff) << 8;
value |= ((src[1]) & 0xff) << 16;
value |= (src[0]) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_x8b8g8r8_unorm {
uint32_t value;
struct {
uint8_t x;
uint8_t b;
uint8_t g;
uint8_t r;
} chan;
};
static INLINE void
util_format_x8b8g8r8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
b = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_x8b8g8r8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= ((float_to_ubyte(src[2])) & 0xff) << 8;
value |= ((float_to_ubyte(src[1])) & 0xff) << 16;
value |= (float_to_ubyte(src[0])) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_x8b8g8r8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
b = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
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 */
}
static INLINE void
util_format_x8b8g8r8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t b;
uint32_t g;
uint32_t r;
b = (value >> 8) & 0xff;
g = (value >> 16) & 0xff;
r = value >> 24;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = 255; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_x8b8g8r8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= ((src[2]) & 0xff) << 8;
value |= ((src[1]) & 0xff) << 16;
value |= (src[0]) << 24;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_r8g8b8x8_unorm {
uint32_t value;
struct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t x;
} chan;
};
static INLINE void
util_format_r8g8b8x8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t r;
uint32_t g;
uint32_t b;
r = (value) & 0xff;
g = (value >> 8) & 0xff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_r8g8b8x8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= (float_to_ubyte(src[0])) & 0xff;
value |= ((float_to_ubyte(src[1])) & 0xff) << 8;
value |= ((float_to_ubyte(src[2])) & 0xff) << 16;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_r8g8b8x8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t r;
uint32_t g;
uint32_t b;
r = (value) & 0xff;
g = (value >> 8) & 0xff;
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 */
}
static INLINE void
util_format_r8g8b8x8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t r;
uint32_t g;
uint32_t b;
r = (value) & 0xff;
g = (value >> 8) & 0xff;
b = (value >> 16) & 0xff;
dst[0] = r; /* r */
dst[1] = g; /* g */
dst[2] = b; /* b */
dst[3] = 255; /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_r8g8b8x8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= (src[0]) & 0xff;
value |= ((src[1]) & 0xff) << 8;
value |= ((src[2]) & 0xff) << 16;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_l8_unorm {
uint8_t value;
struct {
uint8_t rgb;
} chan;
};
static INLINE void
util_format_l8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t rgb;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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);
}
}
static INLINE void
util_format_l8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
uint8_t rgb;
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 */
}
static INLINE void
util_format_l8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t rgb;
rgb = value;
dst[0] = rgb; /* r */
dst[1] = rgb; /* g */
dst[2] = rgb; /* b */
dst[3] = 255; /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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);
}
}
union util_format_a8_unorm {
uint8_t value;
struct {
uint8_t a;
} chan;
};
static INLINE void
util_format_a8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t a;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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);
}
}
static INLINE void
util_format_a8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
uint8_t a;
a = value;
dst[0] = 0; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = ubyte_to_float(a); /* a */
}
static INLINE void
util_format_a8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t a;
a = value;
dst[0] = 0; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = a; /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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);
}
}
union util_format_i8_unorm {
uint8_t value;
struct {
uint8_t rgba;
} chan;
};
static INLINE void
util_format_i8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t rgba;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_i8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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);
}
}
static INLINE void
util_format_i8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
uint8_t rgba;
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 */
}
static INLINE void
util_format_i8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t rgba;
rgba = value;
dst[0] = rgba; /* r */
dst[1] = rgba; /* g */
dst[2] = rgba; /* b */
dst[3] = rgba; /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_i8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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);
}
}
union util_format_l4a4_unorm {
uint8_t value;
struct {
unsigned rgb:4;
unsigned a:4;
} chan;
};
static INLINE void
util_format_l4a4_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t rgb;
uint8_t a;
rgb = (value) & 0xf;
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 */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l4a4_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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)util_iround(CLAMP(src[0], 0, 1) * 0xf)) & 0xf;
value |= ((uint8_t)util_iround(CLAMP(src[3], 0, 1) * 0xf)) << 4;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_l4a4_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
uint8_t rgb;
uint8_t a;
rgb = (value) & 0xf;
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 */
}
static INLINE void
util_format_l4a4_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
uint8_t rgb;
uint8_t a;
rgb = (value) & 0xf;
a = value >> 4;
dst[0] = (uint8_t)(((uint32_t)rgb) * 0xff / 0xf); /* r */
dst[1] = (uint8_t)(((uint32_t)rgb) * 0xff / 0xf); /* g */
dst[2] = (uint8_t)(((uint32_t)rgb) * 0xff / 0xf); /* b */
dst[3] = (uint8_t)(((uint32_t)a) * 0xff / 0xf); /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l4a4_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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)(src[0] >> 4)) & 0xf;
value |= ((uint8_t)(src[3] >> 4)) << 4;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_l8a8_unorm {
uint16_t value;
struct {
uint8_t rgb;
uint8_t a;
} chan;
};
static INLINE void
util_format_l8a8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t rgb;
uint16_t a;
rgb = (value) & 0xff;
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 */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8a8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= (float_to_ubyte(src[0])) & 0xff;
value |= (float_to_ubyte(src[3])) << 8;
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_l8a8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint16_t value = *(const uint16_t *)src;
uint16_t rgb;
uint16_t a;
rgb = (value) & 0xff;
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 */
}
static INLINE void
util_format_l8a8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t rgb;
uint16_t a;
rgb = (value) & 0xff;
a = value >> 8;
dst[0] = rgb; /* r */
dst[1] = rgb; /* g */
dst[2] = rgb; /* b */
dst[3] = a; /* a */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8a8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= (src[0]) & 0xff;
value |= (src[3]) << 8;
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_l16_unorm {
uint16_t value;
struct {
uint16_t rgb;
} chan;
};
static INLINE void
util_format_l16_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t rgb;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l16_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 1) * 0xffff);
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_l16_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint16_t value = *(const uint16_t *)src;
uint16_t rgb;
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 */
}
static INLINE void
util_format_l16_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t rgb;
rgb = value;
dst[0] = (uint8_t)(rgb >> 8); /* r */
dst[1] = (uint8_t)(rgb >> 8); /* g */
dst[2] = (uint8_t)(rgb >> 8); /* b */
dst[3] = 255; /* a */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l16_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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]) * 0xffff / 0xff);
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_a16_unorm {
uint16_t value;
struct {
uint16_t a;
} chan;
};
static INLINE void
util_format_a16_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t a;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a16_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 1) * 0xffff);
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_a16_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint16_t value = *(const uint16_t *)src;
uint16_t a;
a = value;
dst[0] = 0; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = (float)(a * (1.0f/0xffff)); /* a */
}
static INLINE void
util_format_a16_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t a;
a = value;
dst[0] = 0; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = (uint8_t)(a >> 8); /* a */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a16_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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[3]) * 0xffff / 0xff);
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_i16_unorm {
uint16_t value;
struct {
uint16_t rgba;
} chan;
};
static INLINE void
util_format_i16_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t rgba;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_i16_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 1) * 0xffff);
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_i16_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint16_t value = *(const uint16_t *)src;
uint16_t rgba;
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 */
}
static INLINE void
util_format_i16_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
uint16_t rgba;
rgba = value;
dst[0] = (uint8_t)(rgba >> 8); /* r */
dst[1] = (uint8_t)(rgba >> 8); /* g */
dst[2] = (uint8_t)(rgba >> 8); /* b */
dst[3] = (uint8_t)(rgba >> 8); /* a */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_i16_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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]) * 0xffff / 0xff);
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_l16a16_unorm {
uint32_t value;
struct {
uint16_t rgb;
uint16_t a;
} chan;
};
static INLINE void
util_format_l16a16_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t rgb;
uint32_t a;
rgb = (value) & 0xffff;
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 */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l16a16_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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 |= ((uint16_t)util_iround(CLAMP(src[0], 0, 1) * 0xffff)) & 0xffff;
value |= ((uint16_t)util_iround(CLAMP(src[3], 0, 1) * 0xffff)) << 16;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_l16a16_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint32_t value = *(const uint32_t *)src;
uint32_t rgb;
uint32_t a;
rgb = (value) & 0xffff;
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 */
}
static INLINE void
util_format_l16a16_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint32_t value = *(const uint32_t *)src;
uint32_t rgb;
uint32_t a;
rgb = (value) & 0xffff;
a = value >> 16;
dst[0] = (uint8_t)(rgb >> 8); /* r */
dst[1] = (uint8_t)(rgb >> 8); /* g */
dst[2] = (uint8_t)(rgb >> 8); /* b */
dst[3] = (uint8_t)(a >> 8); /* a */
src += 4;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l16a16_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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 |= ((uint16_t)(((uint32_t)src[0]) * 0xffff / 0xff)) & 0xffff;
value |= ((uint16_t)(((uint32_t)src[3]) * 0xffff / 0xff)) << 16;
*(uint32_t *)dst = value;
src += 4;
dst += 4;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_a8_snorm {
uint8_t value;
struct {
int8_t a;
} chan;
};
static INLINE void
util_format_a8_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
int8_t a;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 1) * 0x7f)) ;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_a8_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
int8_t a;
a = (int8_t)(value) ;
dst[0] = 0; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = (float)(a * (1.0f/0x7f)); /* a */
}
static INLINE void
util_format_a8_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
int8_t a;
a = (int8_t)(value) ;
dst[0] = 0; /* r */
dst[1] = 0; /* g */
dst[2] = 0; /* b */
dst[3] = (uint8_t)(((uint32_t)MAX2(a, 0)) * 0xff / 0x7f); /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_a8_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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)(src[3] >> 1)) ;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_l8_snorm {
uint8_t value;
struct {
int8_t rgb;
} chan;
};
static INLINE void
util_format_l8_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
int8_t rgb;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 1) * 0x7f)) ;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_l8_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
int8_t rgb;
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 */
}
static INLINE void
util_format_l8_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
int8_t rgb;
rgb = (int8_t)(value) ;
dst[0] = (uint8_t)(((uint32_t)MAX2(rgb, 0)) * 0xff / 0x7f); /* r */
dst[1] = (uint8_t)(((uint32_t)MAX2(rgb, 0)) * 0xff / 0x7f); /* g */
dst[2] = (uint8_t)(((uint32_t)MAX2(rgb, 0)) * 0xff / 0x7f); /* b */
dst[3] = 255; /* a */
src += 1;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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)(src[0] >> 1)) ;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_l8a8_snorm {
uint16_t value;
struct {
int8_t rgb;
int8_t a;
} chan;
};
static INLINE void
util_format_l8a8_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
int16_t rgb;
int16_t a;
rgb = ((int16_t)(value << 8) ) >> 8;
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 */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8a8_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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)(((int8_t)util_iround(CLAMP(src[0], -1, 1) * 0x7f)) & 0xff) ;
value |= (uint16_t)(((int8_t)util_iround(CLAMP(src[3], -1, 1) * 0x7f)) << 8) ;
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_l8a8_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint16_t value = *(const uint16_t *)src;
int16_t rgb;
int16_t a;
rgb = ((int16_t)(value << 8) ) >> 8;
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 */
}
static INLINE void
util_format_l8a8_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint16_t value = *(const uint16_t *)src;
int16_t rgb;
int16_t a;
rgb = ((int16_t)(value << 8) ) >> 8;
a = ((int16_t)(value) ) >> 8;
dst[0] = (uint8_t)(((uint32_t)MAX2(rgb, 0)) * 0xff / 0x7f); /* r */
dst[1] = (uint8_t)(((uint32_t)MAX2(rgb, 0)) * 0xff / 0x7f); /* g */
dst[2] = (uint8_t)(((uint32_t)MAX2(rgb, 0)) * 0xff / 0x7f); /* b */
dst[3] = (uint8_t)(((uint32_t)MAX2(a, 0)) * 0xff / 0x7f); /* a */
src += 2;
dst += 4;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_l8a8_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *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)(((int8_t)(src[0] >> 1)) & 0xff) ;
value |= (uint16_t)(((int8_t)(src[3] >> 1)) << 8) ;
*(uint16_t *)dst = value;
src += 4;
dst += 2;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
union util_format_i8_snorm {
uint8_t value;
struct {
int8_t rgba;
} chan;
};
static INLINE void
util_format_i8_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
int8_t rgba;
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;
}
src_row += src_stride;
dst_row += dst_stride/sizeof(*dst_row);
}
}
static INLINE void
util_format_i8_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *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, 1) * 0x7f)) ;
*(uint8_t *)dst = value;
src += 4;
dst += 1;
}
dst_row += dst_stride;
src_row += src_stride/sizeof(*src_row);
}
}
static INLINE void
util_format_i8_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
uint8_t value = *(const uint8_t *)src;
int8_t rgba;
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 */
}
static INLINE void
util_format_i8_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; y += 1) {
uint8_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; x += 1) {
uint8_t value = *(const uint8_t *)src;
int8_t rgba;
rgba = (int8_t)(value) ;
dst[0] = (uint8_t)(((uint32_t)MAX2(rgba, 0)) * 0xff / 0x7f); /* r */
dst[1] = (uint8_t)(((uint32_t)MAX2(rgba, 0)) * 0xff / 0x7f); /* g */
dst[2] = (uint8_t)(((uint32_t)MAX2(rgba, 0)) * 0xff / 0x7f