diff options
author | Eric Anholt <[email protected]> | 2020-07-01 16:50:02 -0700 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-07-07 18:19:23 +0000 |
commit | e7010eeff03d96179f79a93b7766bb8e998ca8bf (patch) | |
tree | 7100e471bcf781de63650d5fcdf7441e743749a0 /src/util/format | |
parent | 2f4d557a561b468dcbe806e02e703ec7a26791a1 (diff) |
util: Merge util_format_read_4* functions.
Everyone wants the same thing: unpack 4-bytes-per-channel data based on the
base type of the format.
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5728>
Diffstat (limited to 'src/util/format')
-rw-r--r-- | src/util/format/u_format.c | 59 | ||||
-rw-r--r-- | src/util/format/u_format.h | 20 | ||||
-rw-r--r-- | src/util/format/u_format_bptc.c | 32 |
3 files changed, 30 insertions, 81 deletions
diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index 12af0ed6562..5bb4b0fdb00 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -326,14 +326,13 @@ util_get_depth_format_mrd(const struct util_format_description *desc) void -util_format_read_4f(enum pipe_format format, - float *dst, unsigned dst_stride, - const void *src, unsigned src_stride, - unsigned x, unsigned y, unsigned w, unsigned h) +util_format_read_4(enum pipe_format format, + void *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h) { const struct util_format_description *format_desc; const uint8_t *src_row; - float *dst_row; format_desc = util_format_description(format); @@ -341,9 +340,13 @@ util_format_read_4f(enum pipe_format format, assert(y % format_desc->block.height == 0); src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); - dst_row = dst; - format_desc->unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h); + if (util_format_is_pure_uint(format)) + format_desc->unpack_rgba_sint(dst, dst_stride, src_row, src_stride, w, h); + else if (util_format_is_pure_uint(format)) + format_desc->unpack_rgba_uint(dst, dst_stride, src_row, src_stride, w, h); + else + format_desc->unpack_rgba_float(dst, dst_stride, src_row, src_stride, w, h); } @@ -409,48 +412,6 @@ util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_ format_desc->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); } -void -util_format_read_4ui(enum pipe_format format, - unsigned *dst, unsigned dst_stride, - const void *src, unsigned src_stride, - unsigned x, unsigned y, unsigned w, unsigned h) -{ - const struct util_format_description *format_desc; - const uint8_t *src_row; - uint32_t *dst_row; - - format_desc = util_format_description(format); - - assert(x % format_desc->block.width == 0); - assert(y % format_desc->block.height == 0); - - src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); - dst_row = dst; - - format_desc->unpack_rgba_uint(dst_row, dst_stride, src_row, src_stride, w, h); -} - -void -util_format_read_4i(enum pipe_format format, - int *dst, unsigned dst_stride, - const void *src, unsigned src_stride, - unsigned x, unsigned y, unsigned w, unsigned h) -{ - const struct util_format_description *format_desc; - const uint8_t *src_row; - int32_t *dst_row; - - format_desc = util_format_description(format); - - assert(x % format_desc->block.width == 0); - assert(y % format_desc->block.height == 0); - - src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); - dst_row = dst; - - format_desc->unpack_rgba_sint(dst_row, dst_stride, src_row, src_stride, w, h); -} - /** * Check if we can safely memcopy from the source format to the dest format. * This basically covers the cases of a "used" channel copied to a typeless diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index 961b0ac72b7..4ce3b58bde2 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -1551,10 +1551,10 @@ util_format_pack_rgba(enum pipe_format format, void *dst, */ void -util_format_read_4f(enum pipe_format format, - float *dst, unsigned dst_stride, - const void *src, unsigned src_stride, - unsigned x, unsigned y, unsigned w, unsigned h); +util_format_read_4(enum pipe_format format, + void *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h); void util_format_write_4(enum pipe_format format, @@ -1574,18 +1574,6 @@ util_format_write_4ub(enum pipe_format format, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h); -void -util_format_read_4ui(enum pipe_format format, - unsigned *dst, unsigned dst_stride, - const void *src, unsigned src_stride, - unsigned x, unsigned y, unsigned w, unsigned h); - -void -util_format_read_4i(enum pipe_format format, - int *dst, unsigned dst_stride, - const void *src, unsigned src_stride, - unsigned x, unsigned y, unsigned w, unsigned h); - /* * Generic format conversion; */ diff --git a/src/util/format/u_format_bptc.c b/src/util/format/u_format_bptc.c index 2d02e11f48b..60f789ce0e0 100644 --- a/src/util/format/u_format_bptc.c +++ b/src/util/format/u_format_bptc.c @@ -61,10 +61,10 @@ util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_strid decompress_rgba_unorm(width, height, src_row, src_stride, temp_block, width * 4 * sizeof(uint8_t)); - util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM, - dst_row, dst_stride, - temp_block, width * 4 * sizeof(uint8_t), - 0, 0, width, height); + util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM, + dst_row, dst_stride, + temp_block, width * 4 * sizeof(uint8_t), + 0, 0, width, height); free((void *) temp_block); } @@ -94,10 +94,10 @@ util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src, fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16, temp_block, (width % 4) + (height % 4) * 4); - util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM, - dst, 4 * sizeof(float), - temp_block, 4 * sizeof(uint8_t), - 0, 0, 1, 1); + util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM, + dst, 4 * sizeof(float), + temp_block, 4 * sizeof(uint8_t), + 0, 0, 1, 1); } void @@ -130,10 +130,10 @@ util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, decompress_rgba_unorm(width, height, src_row, src_stride, temp_block, width * 4 * sizeof(uint8_t)); - util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB, - dst_row, dst_stride, - temp_block, width * 4 * sizeof(uint8_t), - 0, 0, width, height); + util_format_read_4(PIPE_FORMAT_R8G8B8A8_SRGB, + dst_row, dst_stride, + temp_block, width * 4 * sizeof(uint8_t), + 0, 0, width, height); free((void *) temp_block); } @@ -156,10 +156,10 @@ util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src, fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16, temp_block, (width % 4) + (height % 4) * 4); - util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB, - dst, 4 * sizeof(float), - temp_block, width * 4 * sizeof(uint8_t), - 0, 0, 1, 1); + util_format_read_4(PIPE_FORMAT_R8G8B8A8_SRGB, + dst, 4 * sizeof(float), + temp_block, width * 4 * sizeof(uint8_t), + 0, 0, 1, 1); } void |