diff options
author | Eric Anholt <[email protected]> | 2019-11-08 12:30:02 -0800 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-02-04 19:02:59 +0000 |
commit | c574cda3c6a3f880f99e4e22967fc82e34609942 (patch) | |
tree | 4624753a3a745e978b1942c532982ded0e189603 /src/util | |
parent | 333c9d5bb054d5ac5518e830b535e8a4f3f80187 (diff) |
util: Make helper functions for pack/unpacking pixel rows.
Almost all users of the unpack functions don't have strides to plug in
(and many are only doing one pixel!), and this will help simplify
them.
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2744>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/format/u_format.c | 8 | ||||
-rw-r--r-- | src/util/format/u_format.h | 100 |
2 files changed, 104 insertions, 4 deletions
diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index d96874114ad..7af030108ad 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -717,13 +717,13 @@ util_format_translate(enum pipe_format dst_format, while (height--) { if (tmp_z) { - src_format_desc->unpack_z_float(tmp_z, 0, src_row, src_stride, width, 1); - dst_format_desc->pack_z_float(dst_row, dst_stride, tmp_z, 0, width, 1); + util_format_unpack_z_float(src_format, tmp_z, src_row, width); + util_format_pack_z_float(dst_format, dst_row, tmp_z, width); } if (tmp_s) { - src_format_desc->unpack_s_8uint(tmp_s, 0, src_row, src_stride, width, 1); - dst_format_desc->pack_s_8uint(dst_row, dst_stride, tmp_s, 0, width, 1); + util_format_unpack_s_8uint(src_format, tmp_s, src_row, width); + util_format_pack_s_8uint(dst_format, dst_row, tmp_s, width); } dst_row += dst_step; diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index 796373c3f67..1b6f0b88289 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -1439,6 +1439,106 @@ util_format_is_unorm8(const struct util_format_description *desc) return desc->is_unorm && desc->is_array && desc->channel[c].size == 8; } +static inline void +util_format_unpack_z_float(enum pipe_format format, float *dst, + const void *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->unpack_z_float(dst, 0, (const uint8_t *)src, 0, w, 1); +} + +static inline void +util_format_unpack_z_32unorm(enum pipe_format format, uint32_t *dst, + const void *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->unpack_z_32unorm(dst, 0, (const uint8_t *)src, 0, w, 1); +} + +static inline void +util_format_unpack_s_8uint(enum pipe_format format, uint8_t *dst, + const void *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->unpack_s_8uint(dst, 0, (const uint8_t *)src, 0, w, 1); +} + +static inline void +util_format_unpack_rgba_float(enum pipe_format format, float *dst, + const void *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->unpack_rgba_float(dst, 0, (const uint8_t *)src, 0, w, 1); +} + +/** + * Unpacks a row of color data to 32-bit RGBA, either integers for pure + * integer formats (sign-extended for signed data), or 32-bit floats. + */ +static inline void +util_format_unpack_rgba(enum pipe_format format, void *dst, + const void *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + if (util_format_is_pure_uint(format)) + desc->unpack_rgba_uint((uint32_t *)dst, 0, (const uint8_t *)src, 0, w, 1); + else if (util_format_is_pure_sint(format)) + desc->unpack_rgba_sint((int32_t *)dst, 0, (const uint8_t *)src, 0, w, 1); + else + desc->unpack_rgba_float((float *)dst, 0, (const uint8_t *)src, 0, w, 1); +} + +static inline void +util_format_pack_z_float(enum pipe_format format, void *dst, + const float *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->pack_z_float((uint8_t *)dst, 0, src, 0, w, 1); +} + +static inline void +util_format_pack_z_32unorm(enum pipe_format format, void *dst, + const uint32_t *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->pack_z_32unorm((uint8_t *)dst, 0, src, 0, w, 1); +} + +static inline void +util_format_pack_s_8uint(enum pipe_format format, void *dst, + const uint8_t *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + desc->pack_s_8uint((uint8_t *)dst, 0, src, 0, w, 1); +} + +/** + * Packs a row of color data from 32-bit RGBA, either integers for pure + * integer formats, or 32-bit floats. Values are clamped to the packed + * representation's range. + */ +static inline void +util_format_pack_rgba(enum pipe_format format, void *dst, + const void *src, unsigned w) +{ + const struct util_format_description *desc = util_format_description(format); + + if (util_format_is_pure_uint(format)) + desc->pack_rgba_uint((uint8_t *)dst, 0, (const uint32_t *)src, 0, w, 1); + else if (util_format_is_pure_sint(format)) + desc->pack_rgba_sint((uint8_t *)dst, 0, (const int32_t *)src, 0, w, 1); + else + desc->pack_rgba_float((uint8_t *)dst, 0, (const float *)src, 0, w, 1); +} + /* * Format access functions. */ |