[cogl/wip/pbo-read-pixels: 3/18] Avoid making up the format COGL_PIXEL_FORMAT_A_8_PRE
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/pbo-read-pixels: 3/18] Avoid making up the format COGL_PIXEL_FORMAT_A_8_PRE
- Date: Fri, 2 Mar 2012 18:11:16 +0000 (UTC)
commit 9fc7caf397d3276bca142a6e97162e0d3d16d42a
Author: Neil Roberts <neil linux intel com>
Date: Wed Feb 29 12:27:19 2012 +0000
Avoid making up the format COGL_PIXEL_FORMAT_A_8_PRE
There are a few places in Cogl that try to set the premult bit on a
pixel format depending on whether it has an alpha channel. However
this breaks if the pixel format is alpha-only because premultiplying
data without any RGB components doesn't make any sense. This adds an
internal macro to check for cases where we should add the premult bit
called COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT. This now gets used in all
places that previously just checking for COGL_A_BIT.
https://bugzilla.gnome.org/show_bug.cgi?id=671016
cogl/cogl-bitmap-fallback.c | 2 +-
cogl/cogl-bitmap.c | 4 +++-
cogl/cogl-private.h | 12 ++++++++++++
cogl/cogl-texture.c | 5 ++---
cogl/cogl.c | 2 +-
5 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/cogl/cogl-bitmap-fallback.c b/cogl/cogl-bitmap-fallback.c
index 0ce229a..71a7ba7 100644
--- a/cogl/cogl-bitmap-fallback.c
+++ b/cogl/cogl-bitmap-fallback.c
@@ -375,7 +375,7 @@ _cogl_bitmap_fallback_convert (CoglBitmap *src_bmp,
/* Initialize destination bitmap */
dst_rowstride = sizeof(guint8) * dst_bpp * width;
/* Copy the premult bit if the new format has an alpha channel */
- if ((dst_format & COGL_A_BIT))
+ if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (dst_format))
dst_format = ((src_format & COGL_PREMULT_BIT) |
(dst_format & ~COGL_PREMULT_BIT));
diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c
index 20fd808..bb178ce 100644
--- a/cogl/cogl-bitmap.c
+++ b/cogl/cogl-bitmap.c
@@ -85,7 +85,8 @@ _cogl_bitmap_convert_premult_status (CoglBitmap *bmp,
{
/* Do we need to unpremultiply? */
if ((bmp->format & COGL_PREMULT_BIT) > 0 &&
- (dst_format & COGL_PREMULT_BIT) == 0)
+ (dst_format & COGL_PREMULT_BIT) == 0 &&
+ COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (dst_format))
/* Try unpremultiplying using imaging library */
return (_cogl_bitmap_unpremult (bmp)
/* ... or try fallback */
@@ -93,6 +94,7 @@ _cogl_bitmap_convert_premult_status (CoglBitmap *bmp,
/* Do we need to premultiply? */
if ((bmp->format & COGL_PREMULT_BIT) == 0 &&
+ COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (bmp->format) &&
(dst_format & COGL_PREMULT_BIT) > 0)
/* Try premultiplying using imaging library */
return (_cogl_bitmap_premult (bmp)
diff --git a/cogl/cogl-private.h b/cogl/cogl-private.h
index 8f2a72e..41275fe 100644
--- a/cogl/cogl-private.h
+++ b/cogl/cogl-private.h
@@ -102,6 +102,18 @@ _cogl_pixel_format_get_bytes_per_pixel (CoglPixelFormat format);
gboolean
_cogl_pixel_format_is_endian_dependant (CoglPixelFormat format);
+/*
+ * COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT(format):
+ * @format: a #CoglPixelFormat
+ *
+ * Returns TRUE if the pixel format can take a premult bit. This is
+ * currently true for all formats that have an alpha channel except
+ * COGL_PIXEL_FORMAT_A_8 (because that doesn't have any other
+ * components to multiply by the alpha).
+ */
+#define COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT(format) \
+ (((format) & COGL_A_BIT) && (format) != COGL_PIXEL_FORMAT_A_8)
+
G_END_DECLS
#endif /* __COGL_PRIVATE_H__ */
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 79f5070..d9eec4a 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -160,8 +160,7 @@ _cogl_texture_determine_internal_format (CoglPixelFormat src_format,
* this. */
if (dst_format == COGL_PIXEL_FORMAT_ANY)
{
- if ((src_format & COGL_A_BIT) &&
- src_format != COGL_PIXEL_FORMAT_A_8)
+ if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (src_format))
return src_format | COGL_PREMULT_BIT;
else
return src_format;
@@ -1231,7 +1230,7 @@ cogl_texture_get_data (CoglTexture *texture,
/* We can assume that whatever data GL gives us will have the
premult status of the original texture */
- if ((closest_format & COGL_A_BIT))
+ if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (closest_format))
closest_format = ((closest_format & ~COGL_PREMULT_BIT) |
(texture_format & COGL_PREMULT_BIT));
diff --git a/cogl/cogl.c b/cogl/cogl.c
index 3784836..f9aa3ca 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -438,7 +438,7 @@ _cogl_read_pixels_with_rowstride (int x,
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
bmp_format = format;
- if ((format & COGL_A_BIT))
+ if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format & COGL_A_BIT))
{
/* We match the premultiplied state of the target buffer to the
* premultiplied state of the framebuffer so that it will get
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]