mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
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 Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
2b9aca20a8
commit
323adc0c14
@ -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));
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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__ */
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user