util: Add callback to fetch a single pixel.
This commit is contained in:
@@ -33,6 +33,37 @@
|
||||
#include "util/u_format_tests.h"
|
||||
|
||||
|
||||
static boolean
|
||||
test_format_fetch_float(const struct util_format_description *format_desc,
|
||||
const struct util_format_test_case *test)
|
||||
{
|
||||
float unpacked[4];
|
||||
unsigned i;
|
||||
boolean success;
|
||||
|
||||
/*
|
||||
* TODO: test block formats too.
|
||||
*/
|
||||
if (format_desc->block.width != 1 && format_desc->block.height != 1) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
format_desc->fetch_float(unpacked, test->packed, 0, 0);
|
||||
|
||||
success = TRUE;
|
||||
for (i = 0; i < 4; ++i)
|
||||
if (test->unpacked[i] != unpacked[i])
|
||||
success = FALSE;
|
||||
|
||||
if (!success) {
|
||||
printf("FAILED: (%f %f %f %f) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]);
|
||||
printf(" (%f %f %f %f) expected\n", test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
static boolean
|
||||
test_format_unpack_float(const struct util_format_description *format_desc,
|
||||
const struct util_format_test_case *test)
|
||||
@@ -225,6 +256,9 @@ test_all(void)
|
||||
{
|
||||
bool success = TRUE;
|
||||
|
||||
if (!test_one(&test_format_fetch_float, "fetch_float"))
|
||||
success = FALSE;
|
||||
|
||||
if (!test_one(&test_format_pack_float, "pack_float"))
|
||||
success = FALSE;
|
||||
|
||||
|
@@ -191,21 +191,34 @@ struct util_format_description
|
||||
enum util_format_colorspace colorspace;
|
||||
|
||||
/**
|
||||
* Accessor functions.
|
||||
* Unpack a span of pixel blocks to R8G8B8A8_UNORM.
|
||||
*/
|
||||
|
||||
void
|
||||
(*unpack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks);
|
||||
|
||||
/**
|
||||
* Pack a span of pixel blocks from R8G8B8A8_UNORM.
|
||||
*/
|
||||
void
|
||||
(*pack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks);
|
||||
|
||||
/**
|
||||
* Unpack a span of pixel blocks to R32G32B32A32_FLOAT.
|
||||
*/
|
||||
void
|
||||
(*unpack_float)(float *dst, const uint8_t *src, unsigned nr_blocks);
|
||||
|
||||
/**
|
||||
* Pack a span of pixel blocks from R32G32B32A32_FLOAT.
|
||||
*/
|
||||
void
|
||||
(*pack_float)(uint8_t *dst, const float *src, unsigned nr_blocks);
|
||||
|
||||
/**
|
||||
* Fetch a single pixel (i, j) from a block.
|
||||
*/
|
||||
void
|
||||
(*fetch_float)(float *dst, const uint8_t *src, unsigned i, unsigned j);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -324,23 +324,15 @@ def conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=True
|
||||
assert False
|
||||
|
||||
|
||||
def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix):
|
||||
'''Generate the function to unpack pixels from a particular format'''
|
||||
def generate_unpack_kernel(format, dst_channel, dst_native_type):
|
||||
|
||||
name = format.short_name()
|
||||
|
||||
print 'static INLINE void'
|
||||
print 'util_format_%s_unpack_%s(%s *dst, const uint8_t *src, unsigned length)' % (name, dst_suffix, dst_native_type)
|
||||
print '{'
|
||||
|
||||
if is_format_supported(format):
|
||||
if not is_format_supported(format):
|
||||
return
|
||||
|
||||
assert format.layout == PLAIN
|
||||
|
||||
src_native_type = native_type(format)
|
||||
|
||||
print ' while(length--) {'
|
||||
|
||||
if format.is_bitmask():
|
||||
depth = format.block_size()
|
||||
print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth)
|
||||
@@ -434,32 +426,18 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix):
|
||||
value = 'dst[0]'
|
||||
print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i])
|
||||
|
||||
print ' src += %u;' % (format.block_size() / 8,)
|
||||
print ' dst += 4;'
|
||||
print ' }'
|
||||
|
||||
print '}'
|
||||
print
|
||||
def generate_pack_kernel(format, src_channel, src_native_type):
|
||||
|
||||
if not is_format_supported(format):
|
||||
return
|
||||
|
||||
def generate_format_pack(format, src_channel, src_native_type, src_suffix):
|
||||
'''Generate the function to pack pixels to a particular format'''
|
||||
|
||||
name = format.short_name()
|
||||
|
||||
print 'static INLINE void'
|
||||
print 'util_format_%s_pack_%s(uint8_t *dst, const %s *src, unsigned length)' % (name, src_suffix, src_native_type)
|
||||
print '{'
|
||||
|
||||
if is_format_supported(format):
|
||||
dst_native_type = native_type(format)
|
||||
|
||||
assert format.layout == PLAIN
|
||||
|
||||
inv_swizzle = format.inv_swizzles()
|
||||
|
||||
print ' while(length--) {'
|
||||
|
||||
if format.is_bitmask():
|
||||
depth = format.block_size()
|
||||
print ' uint%u_t value = 0;' % depth
|
||||
@@ -516,6 +494,43 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix):
|
||||
bswap_format(format)
|
||||
print ' memcpy(dst, &pixel, sizeof pixel);'
|
||||
|
||||
|
||||
def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix):
|
||||
'''Generate the function to unpack pixels from a particular format'''
|
||||
|
||||
name = format.short_name()
|
||||
|
||||
print 'static INLINE void'
|
||||
print 'util_format_%s_unpack_%s(%s *dst, const uint8_t *src, unsigned length)' % (name, dst_suffix, dst_native_type)
|
||||
print '{'
|
||||
|
||||
if is_format_supported(format):
|
||||
print ' while(length--) {'
|
||||
|
||||
generate_unpack_kernel(format, dst_channel, dst_native_type)
|
||||
|
||||
print ' src += %u;' % (format.block_size() / 8,)
|
||||
print ' dst += 4;'
|
||||
print ' }'
|
||||
|
||||
print '}'
|
||||
print
|
||||
|
||||
|
||||
def generate_format_pack(format, src_channel, src_native_type, src_suffix):
|
||||
'''Generate the function to pack pixels to a particular format'''
|
||||
|
||||
name = format.short_name()
|
||||
|
||||
print 'static INLINE void'
|
||||
print 'util_format_%s_pack_%s(uint8_t *dst, const %s *src, unsigned length)' % (name, src_suffix, src_native_type)
|
||||
print '{'
|
||||
|
||||
if is_format_supported(format):
|
||||
print ' while(length--) {'
|
||||
|
||||
generate_pack_kernel(format, src_channel, src_native_type)
|
||||
|
||||
print ' src += 4;'
|
||||
print ' dst += %u;' % (format.block_size() / 8,)
|
||||
print ' }'
|
||||
@@ -524,18 +539,20 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix):
|
||||
print
|
||||
|
||||
|
||||
def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix):
|
||||
'''Generate the dispatch function to unpack pixels from any format'''
|
||||
def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix):
|
||||
'''Generate the function to unpack pixels from a particular format'''
|
||||
|
||||
for format in formats:
|
||||
generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix)
|
||||
name = format.short_name()
|
||||
|
||||
print 'static INLINE void'
|
||||
print 'util_format_%s_fetch_%s(%s *dst, const uint8_t *src, unsigned i, unsigned j)' % (name, dst_suffix, dst_native_type)
|
||||
print '{'
|
||||
|
||||
def generate_pack(formats, src_channel, src_native_type, src_suffix):
|
||||
'''Generate the dispatch function to pack pixels to any format'''
|
||||
if is_format_supported(format):
|
||||
generate_unpack_kernel(format, dst_channel, dst_native_type)
|
||||
|
||||
for format in formats:
|
||||
generate_format_pack(format, src_channel, src_native_type, src_suffix)
|
||||
print '}'
|
||||
print
|
||||
|
||||
|
||||
def generate(formats):
|
||||
@@ -555,13 +572,16 @@ def generate(formats):
|
||||
native_type = 'float'
|
||||
suffix = 'float'
|
||||
|
||||
generate_unpack(formats, channel, native_type, suffix)
|
||||
generate_pack(formats, channel, native_type, suffix)
|
||||
for format in formats:
|
||||
generate_format_unpack(format, channel, native_type, suffix)
|
||||
generate_format_pack(format, channel, native_type, suffix)
|
||||
generate_format_fetch(format, channel, native_type, suffix)
|
||||
|
||||
channel = Channel(UNSIGNED, True, 8)
|
||||
native_type = 'uint8_t'
|
||||
suffix = '8unorm'
|
||||
|
||||
generate_unpack(formats, channel, native_type, suffix)
|
||||
generate_pack(formats, channel, native_type, suffix)
|
||||
for format in formats:
|
||||
generate_format_unpack(format, channel, native_type, suffix)
|
||||
generate_format_pack(format, channel, native_type, suffix)
|
||||
|
||||
|
@@ -106,6 +106,11 @@ util_format_none_unpack_float(float *dst, const uint8_t *src, unsigned length)
|
||||
static void
|
||||
util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
util_format_none_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
|
||||
{
|
||||
}
|
||||
'''
|
||||
print 'const struct util_format_description'
|
||||
@@ -125,7 +130,8 @@ util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length)
|
||||
print " &util_format_none_unpack_8unorm,"
|
||||
print " &util_format_none_pack_8unorm,"
|
||||
print " &util_format_none_unpack_float,"
|
||||
print " &util_format_none_pack_float"
|
||||
print " &util_format_none_pack_float,"
|
||||
print " &util_format_none_fetch_float"
|
||||
print "};"
|
||||
print
|
||||
|
||||
@@ -172,7 +178,8 @@ util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length)
|
||||
print " &util_format_%s_unpack_8unorm," % format.short_name()
|
||||
print " &util_format_%s_pack_8unorm," % format.short_name()
|
||||
print " &util_format_%s_unpack_float," % format.short_name()
|
||||
print " &util_format_%s_pack_float" % format.short_name()
|
||||
print " &util_format_%s_pack_float," % format.short_name()
|
||||
print " &util_format_%s_fetch_float" % format.short_name()
|
||||
print "};"
|
||||
print
|
||||
|
||||
|
Reference in New Issue
Block a user