[395/906] differencematte: fix regressions from gdkpixbuf to libpng migration

The background image needs to be scaled to fit current texture size.
Previously this was done by gdk_pixbuf_scale_simple but that's been
removed.
Create a texture from the background pixbuf with correct dimensions and
use interpolation shader to scale it to the right size. Interpolation
fragment shader doesn't have too much sense if all the textures don't
have the same size so this seemed the most natural place to do the
scaling. It could probably be done with some custom texture mapping
outside the shader but it involved more code.

Fixes bug #599883.
This commit is contained in:
Filippo Argiolas 2009-10-28 10:41:53 +01:00 committed by Matthew Waters
parent 34c5e17187
commit d02a585e7b
3 changed files with 35 additions and 6 deletions

View file

@ -357,8 +357,20 @@ const gchar *texture_interp_fragment_source =
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform sampler2DRect alpha;"
"uniform float final_width, final_height;"
"uniform float base_width, base_height;"
/*
"uniform float blend_width, blend_height;"
"uniform float alpha_width, alpha_height;"
*/
"void main () {"
"vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
"vec2 base_scale = vec2 (base_width, base_height) / vec2 (final_width, final_height);"
/*
"vec2 blend_scale = vec2 (blend_width, blend_height) / vec2 (final_width, final_height);"
"vec2 alpha_scale = vec2 (alpha_width, alpha_height) / vec2 (final_width, final_height);"
*/
"vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st * base_scale);"
"vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
"vec4 alphacolor = texture2DRect (alpha, gl_TexCoord[0].st);"
// "gl_FragColor = alphacolor;"

View file

@ -272,7 +272,7 @@ init_pixbuf_texture (GstGLDisplay * display, gpointer data)
glGenTextures (1, &differencematte->newbgtexture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, differencematte->newbgtexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
filter->width, filter->height, 0,
(gint) differencematte->pbuf_width, (gint) differencematte->pbuf_height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, differencematte->pixbuf);
if (differencematte->savedbgtexture == 0) {
@ -390,6 +390,7 @@ gst_gl_differencematte_interp (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
GstGLFilter *filter = GST_GL_FILTER (stuff);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -409,6 +410,15 @@ gst_gl_differencematte_interp (gint width, gint height, guint texture,
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (differencematte->shader[3], "base", 1);
gst_gl_shader_set_uniform_1f (differencematte->shader[3],
"base_width", differencematte->pbuf_width);
gst_gl_shader_set_uniform_1f (differencematte->shader[3],
"base_height", differencematte->pbuf_height);
gst_gl_shader_set_uniform_1f (differencematte->shader[3],
"final_width", filter->width);
gst_gl_shader_set_uniform_1f (differencematte->shader[3],
"final_height", filter->height);
glActiveTexture (GL_TEXTURE2);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
@ -512,6 +522,7 @@ gst_gl_differencematte_loader (GstGLFilter * filter)
png_FILE_p fp = NULL;
guint y = 0;
guchar **rows = NULL;
gint filler;
if (!filter->display)
return TRUE;
@ -544,17 +555,22 @@ gst_gl_differencematte_loader (GstGLFilter * filter)
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
if (color_type == PNG_COLOR_TYPE_RGB) {
filler = 0xff;
png_set_filler (png_ptr, filler, PNG_FILLER_AFTER);
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
}
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("color type is not rgb");
}
filter->width = width;
filter->height = height;
differencematte->pbuf_width = width;
differencematte->pbuf_height = height;
differencematte->pixbuf =
(guchar *) malloc (sizeof (guchar) * width * height * 4);
differencematte->pixbuf = (guchar *) malloc (sizeof (guchar) * width * height * 4);
rows = (guchar **) malloc (sizeof (guchar *) * height);

View file

@ -43,6 +43,7 @@ struct _GstGLDifferenceMatte
gboolean bg_has_changed;
guchar *pixbuf;
gint pbuf_width, pbuf_height;
GLuint savedbgtexture;
GLuint newbgtexture;
GLuint midtexture[4];