[401/906] gloverlay: Added rotate texture

fix #601277
This commit is contained in:
Anthony Violo 2009-11-16 14:32:16 +01:00 committed by Matthew Waters
parent 32e401427f
commit a7a5c7ee8a
2 changed files with 195 additions and 130 deletions

View file

@ -79,7 +79,11 @@ enum
PROP_XPOS_VIDEO, PROP_XPOS_VIDEO,
PROP_YPOS_VIDEO, PROP_YPOS_VIDEO,
PROP_SIZE_VIDEO, PROP_SIZE_VIDEO,
PROP_VIDEOTOP PROP_VIDEOTOP,
PROP_ROTATE_PNG,
PROP_ROTATE_VIDEO,
PROP_ANGLE_PNG,
PROP_ANGLE_VIDEO
}; };
@ -176,6 +180,34 @@ gst_gl_overlay_class_init (GstGLOverlayClass * klass)
PROP_VIDEOTOP, PROP_VIDEOTOP,
g_param_spec_boolean ("video-top", g_param_spec_boolean ("video-top",
"Video-top", "Video is over png image", FALSE, G_PARAM_READWRITE)); "Video-top", "Video is over png image", FALSE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ROTATE_PNG,
g_param_spec_int ("rotate_png",
"choose rotation axis for the moment only Y axis is implemented",
"choose rotation axis for the moment only Y axis is implemented",
0, 3, 0, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ROTATE_VIDEO,
g_param_spec_int ("rotate_video",
"choose rotation axis for the moment only Y axis is implemented",
"choose rotation axis for the moment only Y axis is implemented",
0, 3, 0, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ANGLE_PNG,
g_param_spec_int ("angle_png",
"choose angle in axis to choosen between -90 and 90",
"choose angle in axis to choosen between -90 and 90",
-90, 90, 0, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ANGLE_VIDEO,
g_param_spec_int ("angle_video",
"choose angle in axis to choosen between -90 and 90",
"choose angle in axis to choosen between -90 and 90",
-90, 90, 0, G_PARAM_READWRITE));
/* /*
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_STRETCH, PROP_STRETCH,
@ -190,156 +222,157 @@ static void
gst_gl_overlay_draw_texture_video_on_png (GstGLOverlay * overlay, GLuint tex) gst_gl_overlay_draw_texture_video_on_png (GstGLOverlay * overlay, GLuint tex)
{ {
GstGLFilter *filter = GST_GL_FILTER (overlay); GstGLFilter *filter = GST_GL_FILTER (overlay);
gfloat posx = 0.0; gfloat posx = 0.0;
gfloat posy = 0.0; gfloat posy = 0.0;
gfloat size = 0.0; gfloat size = 0.0;
gfloat width = (gfloat) overlay->width; gfloat width = (gfloat) filter->width;
gfloat height = (gfloat) overlay->height; gfloat height = (gfloat) filter->height;
gfloat ratio = 0.0;
gfloat translate = 0.0;
if (overlay->pbuftexture == 0) // if (overlay->stretch) {
return; // width = (gfloat) overlay->width;
// height = (gfloat) overlay->height;
// if (overlay->stretch) { // }
// width = (gfloat) overlay->width; if (overlay->pbuftexture != 0) {
// height = (gfloat) overlay->height; size = (overlay->size_png) / 50.0;
// } posx = (overlay->pos_x_png - 50.0) / 50.0;
posx =
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); (posx - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posx + (size / 2) >
glEnable (GL_BLEND); 1.00) ? (1.0 - size / 2) : posx;
posy = (overlay->pos_y_png - 50.0) / 50.0;
glEnable (GL_TEXTURE_RECTANGLE_ARB); posy =
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture); (posy - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posy + (size / 2) >
1.00) ? (1.0 - size / 2) : posy;
glBegin (GL_QUADS); ratio = ((posx + (size / 2)) - (posx - (size / 2))) * height / width;
translate = overlay->size_png / 400.0;
size = (overlay->size_png) / 50.0f; glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
posx = (overlay->pos_x_png - 50.0f) / 50.0f; glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture);
glLoadIdentity ();
glTranslatef (0.0f, translate, -1.0f);
if (overlay->rotate_png == 2)
glRotatef (overlay->angle_png, 0, 1, 0);
glBegin (GL_QUADS);
glTexCoord3f (0.0, 0.0, 0.0);
glVertex3f (posx - (size / 2), posy - (size / 2), 0.0);
glTexCoord3f (width, 0.0, 0.0);
glVertex3f (posx + (size / 2), posy - (size / 2), 0.0);
glTexCoord3f (width, height, 0.0);
glVertex3f (posx + (size / 2), posy - (size / 2) + ratio, 0.0);
glTexCoord3f (0.0, height, 0.0);
glVertex3f (posx - (size / 2), posy - (size / 2) + ratio, 0.0);
glEnd ();
}
size = (overlay->size_video) / 50.0;
posx = (overlay->pos_x_video - 50.0) / 50.0;
posx = posx =
(posx - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posx + (size / 2) > (posx - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posx + (size / 2) >
1.00) ? (1.0f - size / 2) : posx; 1.00) ? (1.0 - size / 2) : posx;
posy = (overlay->pos_y_png - 50.0f) / 50.0f; posy = (overlay->pos_y_video - 50.0) / 50.0;
posy = posy =
(posy - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posy + (size / 2) > (posy - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posy + (size / 2) >
1.00) ? (1.0f - size / 2) : posy; 1.00) ? (1.0 - size / 2) : posy;
ratio = ((posx + (size / 2)) - (posx - (size / 2))) * height / width;
glTexCoord2f (0.0f, 0.0f); translate = overlay->size_video / 400.0;
glVertex2f (posx - (size / 2), posy - (size / 2));
glTexCoord2f (width, 0.0f);
glVertex2f (posx + (size / 2), posy - (size / 2));
glTexCoord2f (width, height);
glVertex2f (posx + (size / 2), posy + (size / 2));
glTexCoord2f (0.0f, height);
glVertex2f (posx - (size / 2), posy + (size / 2));
glEnd ();
width = (gfloat) filter->width;
height = (gfloat) filter->height;
glActiveTexture (GL_TEXTURE0); glActiveTexture (GL_TEXTURE0);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_TEXTURE_RECTANGLE_ARB); glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
glLoadIdentity ();
glTranslatef (0.0f, translate, -1.0f);
if (overlay->rotate_video)
glRotatef (overlay->angle_video, 0, 1, 0);
glBegin (GL_QUADS); glBegin (GL_QUADS);
glTexCoord3f (0.0, 0.0, 0.0);
size = (overlay->size_video) / 50.0f; glVertex3f (posx - (size / 2), posy - (size / 2), 0.0);
posx = (overlay->pos_x_video - 50.0f) / 50.0f; glTexCoord3f (width, 0.0, 0.0);
posx = glVertex3f (posx + (size / 2), posy - (size / 2), 0.0);
(posx - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posx + (size / 2) > glTexCoord3f (width, height, 0.0);
1.00) ? (1.0f - size / 2) : posx; glVertex3f (posx + (size / 2), posy - (size / 2) + ratio, 0.0);
posy = (overlay->pos_y_video - 50.0f) / 50.0f; glTexCoord3f (0.0, height, 0.0);
posy = glVertex3f (posx - (size / 2), posy - (size / 2) + ratio, 0.0);
(posy - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posy + (size / 2) >
1.00) ? (1.0f - size / 2) : posy;
glTexCoord2f (0.0, 0.0);
glVertex2f (posx - (size / 2), posy - (size / 2));
glTexCoord2f (width, 0.0);
glVertex2f (posx + (size / 2), posy - (size / 2));
glTexCoord2f (width, height);
glVertex2f (posx + (size / 2), posy + (size / 2));
glTexCoord2f (0.0, height);
glVertex2f (posx - (size / 2), posy + (size / 2));
glEnd (); glEnd ();
glFlush (); glFlush ();
} }
static void static void
gst_gl_overlay_draw_texture_png_on_video (GstGLOverlay * overlay, GLuint tex) gst_gl_overlay_draw_texture_png_on_video (GstGLOverlay * overlay, GLuint tex)
{ {
GstGLFilter *filter = GST_GL_FILTER (overlay);
GstGLFilter *filter = GST_GL_FILTER (overlay);
gfloat posx = 0.0; gfloat posx = 0.0;
gfloat posy = 0.0; gfloat posy = 0.0;
gfloat size = 0.0; gfloat size = 0.0;
gfloat width = (gfloat) filter->width; gfloat width = (gfloat) filter->width;
gfloat height = (gfloat) filter->height; gfloat height = (gfloat) filter->height;
gfloat ratio = 0.0;
gfloat translate = 0.0;
size = (overlay->size_video) / 50.0;
posx = (overlay->pos_x_video - 50.0) / 50.0;
posx =
(posx - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posx + (size / 2) >
1.00) ? (1.0 - size / 2) : posx;
posy = (overlay->pos_y_video - 50.0) / 50.0;
posy =
(posy - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posy + (size / 2) >
1.00) ? (1.0 - size / 2) : posy;
ratio = ((posx + (size / 2)) - (posx - (size / 2))) * height / width;
translate = overlay->size_video / 400.0;
glActiveTexture (GL_TEXTURE0); glActiveTexture (GL_TEXTURE0);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_TEXTURE_RECTANGLE_ARB); glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
glLoadIdentity ();
glTranslatef (0.0f, translate, -1.0f);
if (overlay->rotate_video)
glRotatef (overlay->angle_video, 0, 1, 0);
glBegin (GL_QUADS); glBegin (GL_QUADS);
glTexCoord3f (0.0, 0.0, 0.0);
size = (overlay->size_video) / 50.0f; glVertex3f (posx - (size / 2), posy - (size / 2), 0.0);
posx = (overlay->pos_x_video - 50.0f) / 50.0f; glTexCoord3f (width, 0.0, 0.0);
posx = glVertex3f (posx + (size / 2), posy - (size / 2), 0.0);
(posx - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posx + (size / 2) > glTexCoord3f (width, height, 0.0);
1.00) ? (1.0f - size / 2) : posx; glVertex3f (posx + (size / 2), posy - (size / 2) + ratio, 0.0);
posy = (overlay->pos_y_video - 50.0f) / 50.0f; glTexCoord3f (0.0, height, 0.0);
posy = glVertex3f (posx - (size / 2), posy - (size / 2) + ratio, 0.0);
(posy - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posy + (size / 2) >
1.00) ? (1.0f - size / 2) : posy;
glTexCoord2f (0.0, 0.0);
glVertex2f (posx - (size / 2), posy - (size / 2));
glTexCoord2f (width, 0.0);
glVertex2f (posx + (size / 2), posy - (size / 2));
glTexCoord2f (width, height);
glVertex2f (posx + (size / 2), posy + (size / 2));
glTexCoord2f (0.0, height);
glVertex2f (posx - (size / 2), posy + (size / 2));
glEnd (); glEnd ();
if (overlay->pbuftexture == 0) if (overlay->pbuftexture == 0)
return; return;
// if (overlay->stretch) { // if (overlay->stretch) {
width = (gfloat) overlay->width; //width = (gfloat) overlay->width;
height = (gfloat) overlay->height; //height = (gfloat) overlay->height;
// } // }
size = (overlay->size_png) / 50.0;
posx = (overlay->pos_x_png - 50.0) / 50.0;
posx =
(posx - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posx + (size / 2) >
1.00) ? (1.0 - size / 2) : posx;
posy = (overlay->pos_y_png - 50.0) / 50.0;
posy =
(posy - (size / 2) < -1.00) ? (-1.0 + size / 2) : (posy + (size / 2) >
1.00) ? (1.0 - size / 2) : posy;
ratio = ((posx + (size / 2)) - (posx - (size / 2))) * height / width;
translate = overlay->size_png / 400.0;
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_BLEND);
glEnable (GL_TEXTURE_RECTANGLE_ARB); glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture);
glLoadIdentity ();
glTranslatef (0.0f, translate, -1.0f);
if (overlay->rotate_png == 2)
glRotatef (overlay->angle_png, 0, 1, 0);
glBegin (GL_QUADS); glBegin (GL_QUADS);
glTexCoord3f (0.0, 0.0, 0.0);
size = (overlay->size_png) / 50.0f; glVertex3f (posx - (size / 2), posy - (size / 2), 0.0);
posx = (overlay->pos_x_png - 50.0f) / 50.0f; glTexCoord3f (width, 0.0, 0.0);
posx = glVertex3f (posx + (size / 2), posy - (size / 2), 0.0);
(posx - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posx + (size / 2) > glTexCoord3f (width, height, 0.0);
1.00) ? (1.0f - size / 2) : posx; glVertex3f (posx + (size / 2), posy - (size / 2) + ratio, 0.0);
posy = (overlay->pos_y_png - 50.0f) / 50.0f; glTexCoord3f (0.0, height, 0.0);
posy = glVertex3f (posx - (size / 2), posy - (size / 2) + ratio, 0.0);
(posy - (size / 2) < -1.00) ? (-1.0f + size / 2) : (posy + (size / 2) >
1.00) ? (1.0f - size / 2) : posy;
glTexCoord2f (0.0f, 0.0f);
glVertex2f (posx - (size / 2), posy - (size / 2));
glTexCoord2f (width, 0.0);
glVertex2f (posx + (size / 2), posy - (size / 2));
glTexCoord2f (width, height);
glVertex2f (posx + (size / 2), posy + (size / 2));
glTexCoord2f (0.0, height);
glVertex2f (posx - (size / 2), posy + (size / 2));
glEnd (); glEnd ();
glFlush (); glFlush ();
} }
@ -354,14 +387,18 @@ gst_gl_overlay_init (GstGLOverlay * overlay, GstGLOverlayClass * klass)
overlay->pbuftexture = 0; overlay->pbuftexture = 0;
overlay->width = 0; overlay->width = 0;
overlay->height = 0; overlay->height = 0;
overlay->pos_x_png = 0; overlay->pos_x_png = 0.0;
overlay->pos_y_png = 0; overlay->pos_y_png = 0.0;
overlay->size_png = 100; overlay->size_png = 100;
overlay->pos_x_video = 0; overlay->pos_x_video = 0.0;
overlay->pos_y_video = 0; overlay->pos_y_video = 0.0;
overlay->size_video = 100; overlay->size_video = 100;
overlay->video_top = FALSE; overlay->video_top = FALSE;
// overlay->stretch = TRUE; overlay->rotate_png = 0;
overlay->rotate_video = 0;
overlay->angle_png = 0;
overlay->angle_video = 0;
// overlay->stretch = TRUE;
overlay->pbuf_has_changed = FALSE; overlay->pbuf_has_changed = FALSE;
} }
@ -405,10 +442,22 @@ gst_gl_overlay_set_property (GObject * object, guint prop_id,
case PROP_VIDEOTOP: case PROP_VIDEOTOP:
overlay->video_top = g_value_get_boolean (value); overlay->video_top = g_value_get_boolean (value);
break; break;
/* case PROP_STRETCH: case PROP_ROTATE_PNG:
overlay->stretch = g_value_get_boolean (value); overlay->rotate_png = g_value_get_int (value);
break; break;
*/ case PROP_ROTATE_VIDEO:
overlay->rotate_video = g_value_get_int (value);
break;
case PROP_ANGLE_PNG:
overlay->angle_png = g_value_get_int (value);
break;
case PROP_ANGLE_VIDEO:
overlay->angle_video = g_value_get_int (value);
break;
/* case PROP_STRETCH:
overlay->stretch = g_value_get_boolean (value);
break;
*/
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -446,10 +495,22 @@ gst_gl_overlay_get_property (GObject * object, guint prop_id,
case PROP_VIDEOTOP: case PROP_VIDEOTOP:
g_value_set_boolean (value, overlay->video_top); g_value_set_boolean (value, overlay->video_top);
break; break;
/* case PROP_STRETCH: case PROP_ROTATE_PNG:
g_value_set_boolean (value, overlay->stretch); g_value_set_int (value, overlay->rotate_png);
break; break;
*/ case PROP_ROTATE_VIDEO:
g_value_set_int (value, overlay->rotate_video);
break;
case PROP_ANGLE_PNG:
g_value_set_int (value, overlay->angle_png);
break;
case PROP_ANGLE_VIDEO:
g_value_set_int (value, overlay->angle_video);
break;
/* case PROP_STRETCH:
g_value_set_boolean (value, overlay->stretch);
break;
*/
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -469,7 +530,9 @@ gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
gluPerspective (70.0f, (GLfloat) width / (GLfloat) height, 0.0f, 1000.0f);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
if (overlay->video_top) if (overlay->video_top)
gst_gl_overlay_draw_texture_video_on_png (overlay, texture); gst_gl_overlay_draw_texture_video_on_png (overlay, texture);
else else

View file

@ -36,10 +36,8 @@ typedef struct _GstGLOverlayClass GstGLOverlayClass;
struct _GstGLOverlay struct _GstGLOverlay
{ {
GstGLFilter filter; GstGLFilter filter;
gchar *location; gchar *location;
gboolean pbuf_has_changed; gboolean pbuf_has_changed;
gint8 pos_x_png; gint8 pos_x_png;
gint8 pos_y_png; gint8 pos_y_png;
guint8 size_png; guint8 size_png;
@ -47,6 +45,10 @@ struct _GstGLOverlay
gint8 pos_y_video; gint8 pos_y_video;
guint8 size_video; guint8 size_video;
gboolean video_top; gboolean video_top;
guint8 rotate_png;
guint8 rotate_video;
gint8 angle_png;
gint8 angle_video;
guchar *pixbuf; guchar *pixbuf;
gint width, height; gint width, height;
GLuint pbuftexture; GLuint pbuftexture;