[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 9d3aa57604
commit a9b011f3ed
2 changed files with 22 additions and 26 deletions

View File

@ -1085,17 +1085,9 @@ _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
required_format = format;
/* FIXME: check YUV support */
required_format = format;
/* Find GL equivalents */
switch (format & COGL_UNPREMULT_MASK)
@ -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,17 +1184,9 @@ _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
required_format = format;
/* FIXME: check YUV support */
required_format = format;
/* Find GL equivalents */
switch (format & COGL_UNPREMULT_MASK)
@ -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,