summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-02-13 23:28:28 +0000
committerRobert Bragg <robert@linux.intel.com>2012-02-17 23:48:50 +0000
commit27366766716b0a1e5f0a68e19f98dbb3e9bc4073 (patch)
tree14814c5b8f371f045896daa656b3b88e0d1e9dea
parentf9bf1805b5a35ebd531caba20ed57c175734046b (diff)
downloadcogl-27366766716b0a1e5f0a68e19f98dbb3e9bc4073.tar.gz
Adds _cogl_pixel_format_is_endian_dependant api
This adds an internal utility function _cogl_pixel_format_is_endian_dependant() that can query whether accessing the components of a given format depends on the endianness of the current host CPU or whether a pixel can be loaded as a word and channels accessed using bit masking and shifting.
-rw-r--r--cogl/cogl-private.h16
-rw-r--r--cogl/cogl.c21
2 files changed, 37 insertions, 0 deletions
diff --git a/cogl/cogl-private.h b/cogl/cogl-private.h
index b4ff4205..ef333928 100644
--- a/cogl/cogl-private.h
+++ b/cogl/cogl-private.h
@@ -75,6 +75,22 @@ _cogl_get_enable_legacy_state (void);
int
_cogl_pixel_format_get_bytes_per_pixel (CoglPixelFormat format);
+/*
+ * _cogl_pixel_format_has_aligned_components:
+ * @format: a #CoglPixelFormat
+ *
+ * Queries whether the ordering of the components for the given
+ * @format depend on the endianness of the host CPU or if the
+ * components can be accessed using bit shifting and bitmasking by
+ * loading a whole pixel into a word.
+ *
+ * Return value: %TRUE if you need to consider the host CPU
+ * endianness when dealing with the given @format
+ * else %FALSE.
+ */
+gboolean
+_cogl_pixel_format_is_endian_dependant (CoglPixelFormat format);
+
G_END_DECLS
#endif /* __COGL_PRIVATE_H__ */
diff --git a/cogl/cogl.c b/cogl/cogl.c
index 26870d0c..28ab1469 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -1023,3 +1023,24 @@ _cogl_pixel_format_get_bytes_per_pixel (CoglPixelFormat format)
return bpp_lut [format & 0xf];
}
+
+/* Note: this also refers to the mapping defined above for
+ * _cogl_pixel_format_get_bytes_per_pixel() */
+gboolean
+_cogl_pixel_format_is_endian_dependant (CoglPixelFormat format)
+{
+ int aligned_lut[] = { -1, 1, 1, 1,
+ 0, 0, 0, -1,
+ 1, 1, -1, -1,
+ 0, 0, -1, -1};
+ int aligned = aligned_lut[format & 0xf];
+
+ _COGL_RETURN_VAL_IF_FAIL (aligned != -1, FALSE);
+
+ /* NB: currently checking whether the format components are aligned
+ * or not determines whether the format is endian dependent or not.
+ * In the future though we might consider adding formats with
+ * aligned components that are also endian independant. */
+
+ return aligned;
+}