isl: Add isl_format_layout::uniform_channel_type

If each format channel has the same base type (such unorm), then that
is the format's "uniform channel type".

Calculating the field at buildtime is probably better than looping over
all channels at runtime each time we wish to query it.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Chad Versace
2020-10-16 11:09:09 -07:00
parent f665bae4eb
commit 486ae7c655
2 changed files with 32 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ isl_format_layouts[] = {
% endif
% endfor
},
.uniform_channel_type = ISL_${format.uniform_channel_type},
.colorspace = ISL_COLORSPACE_${format.colorspace},
.txc = ISL_TXC_${format.txc},
},
@@ -179,6 +180,23 @@ class Format(object):
chan.start = bit
bit = bit + chan.size
# Set the uniform channel type, if the format has one.
#
# Iterate over all channels, not just those in self.order, because
# some formats have an empty 'order' field in the CSV (such as
# YCRCB_NORMAL).
self.uniform_channel_type = 'VOID'
for chan in self.channels:
if chan.type in (None, 'VOID'):
pass
elif self.uniform_channel_type == 'VOID':
self.uniform_channel_type = chan.type
elif self.uniform_channel_type == chan.type:
pass
else:
self.uniform_channel_type = 'VOID'
break
# alpha doesn't have a colorspace of it's own.
self.colorspace = line[13].strip().upper()
if self.colorspace in ['']:
@@ -188,6 +206,17 @@ class Format(object):
self.txc = line[14].strip().upper() or 'NONE'
@property
def channels(self):
yield self.r
yield self.g
yield self.b
yield self.a
yield self.l
yield self.i
yield self.p
def reader(csvfile):
"""Wrapper around csv.reader that skips comments and blanks."""
# csv.reader actually reads the file one line at a time (it was designed to

View File

@@ -1133,6 +1133,9 @@ struct isl_format_layout {
struct isl_channel_layout channels_array[7];
};
/** Set if all channels have the same isl_base_type. Otherwise, ISL_BASE_VOID. */
enum isl_base_type uniform_channel_type;
enum isl_colorspace colorspace;
enum isl_txc txc;
};