diff options
author | Michal Krol <[email protected]> | 2009-12-03 11:58:36 +0100 |
---|---|---|
committer | Michal Krol <[email protected]> | 2009-12-03 11:58:36 +0100 |
commit | f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79 (patch) | |
tree | 2389d913bcd736d2d17a64189550b00ef68e1033 /src/gallium/auxiliary/util | |
parent | cceeab39ea541b1be1521114316d660a77769c2a (diff) |
Move pf_get_component_bits() to u_format auxiliary module.
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_format.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 3ac53840247..fa6dc1f55c0 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -212,6 +212,50 @@ util_format_get_size(enum pipe_format format) return bits / 8; } +static INLINE uint +util_format_get_component_bits(enum pipe_format format, + enum util_format_colorspace colorspace, + uint component) +{ + const struct util_format_description *desc = util_format_description(format); + enum util_format_colorspace desc_colorspace; + uint swizzle; + + assert(format); + if (!format) { + return 0; + } + + assert(component >= 4); + + /* Treat RGB and SRGB as equivalent. */ + if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } else { + desc_colorspace = desc->colorspace; + } + + if (desc_colorspace != colorspace) { + return 0; + } + + switch (desc->swizzle[component]) { + case UTIL_FORMAT_SWIZZLE_X: + return desc->channel[0].size; + case UTIL_FORMAT_SWIZZLE_Y: + return desc->channel[1].size; + case UTIL_FORMAT_SWIZZLE_Z: + return desc->channel[2].size; + case UTIL_FORMAT_SWIZZLE_W: + return desc->channel[3].size; + default: + return 0; + } +} + /* * Format access functions. |