From d97eddff25afce7a49975b9b2fab1bedb9d18843 Mon Sep 17 00:00:00 2001 From: Rafael Antognolli Date: Fri, 8 Mar 2019 14:01:58 -0800 Subject: [PATCH] intel/isl: Add isl_format_has_color_component() function. v2: Get luminance bits from luminance component (Ken). Reviewed-by: Kenneth Graunke --- src/intel/isl/isl.h | 3 +++ src/intel/isl/isl_format.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h index a792e18e5d1..6790ba002ad 100644 --- a/src/intel/isl/isl.h +++ b/src/intel/isl/isl.h @@ -1503,6 +1503,9 @@ isl_format_has_int_channel(enum isl_format fmt) isl_format_has_sint_channel(fmt); } +bool isl_format_has_color_component(enum isl_format fmt, + int component) ATTRIBUTE_CONST; + unsigned isl_format_get_num_channels(enum isl_format fmt); uint32_t isl_format_get_depth_format(enum isl_format fmt, bool has_stencil); diff --git a/src/intel/isl/isl_format.c b/src/intel/isl/isl_format.c index 968f981cdee..b429e7779a4 100644 --- a/src/intel/isl/isl_format.c +++ b/src/intel/isl/isl_format.c @@ -688,6 +688,28 @@ isl_format_has_sint_channel(enum isl_format fmt) return isl_format_has_channel_type(fmt, ISL_SINT); } +bool +isl_format_has_color_component(enum isl_format fmt, int component) +{ + const struct isl_format_layout *fmtl = isl_format_get_layout(fmt); + const uint8_t intensity = fmtl->channels.i.bits; + const uint8_t luminance = fmtl->channels.l.bits; + + switch (component) { + case 0: + return (fmtl->channels.r.bits + intensity + luminance) > 0; + case 1: + return (fmtl->channels.g.bits + intensity + luminance) > 0; + case 2: + return (fmtl->channels.b.bits + intensity + luminance) > 0; + case 3: + return (fmtl->channels.a.bits + intensity) > 0; + default: + assert(!"Invalid color component: must be 0..3"); + return false; + } +} + unsigned isl_format_get_num_channels(enum isl_format fmt) { -- 2.30.2