[premultiplication] Be more conservative with what data gets premultiplied

We don't want to force texture data to be premultipled if the user
explicitly specifies a non premultiplied internal_format such as
COGL_PIXEL_FORMAT_RGBA_8888.  So now Cogl will only automatically
premultiply data when COGL_PIXEL_FORMAT_ANY is given for the
internal_format, or a premultiplied internal format such as
COGL_PIXEL_FORMAT_RGBA_8888_PRE is requested but non-premultiplied source
data is given.

This approach is consistent with OpenVG image formats which have already
influenced Cogl's pixel format semantics.
This commit is contained in:
Robert Bragg 2009-06-06 21:45:05 +01:00
parent 7cb4b93432
commit e6da6df8a8
2 changed files with 22 additions and 26 deletions

View File

@ -1085,16 +1085,8 @@ _cogl_pixel_format_to_gl (CoglPixelFormat format,
GLenum glformat = 0;
GLenum gltype = 0;
/* If PREMULT_BIT isn't specified, that means that we premultiply
* textures with alpha before uploading to GL; once we are in GL land,
* everything is premultiplied.
*
* Everything else accepted (FIXME: check YUV support)
*/
if ((format & COGL_A_BIT) != 0 &&
format != COGL_PIXEL_FORMAT_A_8)
required_format = format | COGL_PREMULT_BIT;
else
/* FIXME: check YUV support */
required_format = format;
/* Find GL equivalents */
@ -1197,9 +1189,15 @@ _cogl_texture_bitmap_prepare (CoglTexture *tex,
CoglPixelFormat new_data_format;
gboolean success;
/* Was there any internal conversion requested? */
/* Was there any internal conversion requested?
* By default Cogl will use a premultiplied internal format. Later we will
* add control over this. */
if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = tex->bitmap.format;
{
if ((tex->bitmap.format & COGL_A_BIT) &&
tex->bitmap.format != COGL_PIXEL_FORMAT_A_8)
internal_format = tex->bitmap.format | COGL_PREMULT_BIT;
}
/* Find closest format accepted by GL */
new_data_format = _cogl_pixel_format_to_gl (internal_format,

View File

@ -1184,16 +1184,8 @@ _cogl_pixel_format_to_gl (CoglPixelFormat format,
GLenum glformat = 0;
GLenum gltype = 0;
/* If PREMULT_BIT isn't specified, that means that we premultiply
* textures with alpha before uploading to GL; once we are in GL land,
* everything is premultiplied.
*
* Everything else accepted (FIXME: check YUV support)
*/
if ((format & COGL_A_BIT) != 0 &&
format != COGL_PIXEL_FORMAT_A_8)
required_format = format | COGL_PREMULT_BIT;
else
/* FIXME: check YUV support */
required_format = format;
/* Find GL equivalents */
@ -1273,9 +1265,15 @@ _cogl_texture_bitmap_prepare (CoglTexture *tex,
CoglPixelFormat new_data_format;
gboolean success;
/* Was there any internal conversion requested? */
/* Was there any internal conversion requested?
* By default Cogl will use a premultiplied internal format. Later we will
* add control over this. */
if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = tex->bitmap.format;
{
if ((tex->bitmap.format & COGL_A_BIT) &&
tex->bitmap.format != COGL_PIXEL_FORMAT_A_8)
internal_format = tex->bitmap.format | COGL_PREMULT_BIT;
}
/* Find closest format accepted by GL */
new_data_format = _cogl_pixel_format_to_gl (internal_format,