2008-08-18 14:16:58 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-08-18 14:16:58 +00:00
|
|
|
*/
|
|
|
|
|
2009-01-15 17:39:48 +00:00
|
|
|
/**
|
2009-02-05 21:13:51 +00:00
|
|
|
* SECTION:element-gloverlay
|
2009-01-15 17:39:48 +00:00
|
|
|
*
|
2009-02-05 00:57:14 +00:00
|
|
|
* Overlay GL video texture with a PNG image
|
2009-01-15 17:39:48 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Examples</title>
|
|
|
|
* |[
|
2009-02-05 21:13:51 +00:00
|
|
|
* gst-launch videotestsrc ! "video/x-raw-rgb" ! glupload ! gloverlay location=imagefile ! glimagesink
|
2009-01-15 17:39:48 +00:00
|
|
|
* ]|
|
|
|
|
* FBO (Frame Buffer Object) is required.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2013-11-15 07:28:49 +00:00
|
|
|
/* FIXME: Redo this */
|
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-11 09:03:31 +00:00
|
|
|
#include <gst/gl/gstglconfig.h>
|
2013-03-10 02:37:48 +00:00
|
|
|
|
|
|
|
#include "gstgloverlay.h"
|
2013-07-11 09:03:31 +00:00
|
|
|
#include "effects/gstgleffectssources.h"
|
2013-03-10 02:37:48 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
#include <stdio.h>
|
2009-02-23 11:35:48 +00:00
|
|
|
#include <stdlib.h>
|
2011-11-17 14:22:06 +00:00
|
|
|
#include <jpeglib.h>
|
2009-01-22 01:19:31 +00:00
|
|
|
#include <png.h>
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2010-03-09 00:24:06 +00:00
|
|
|
#if PNG_LIBPNG_VER >= 10400
|
|
|
|
#define int_p_NULL NULL
|
|
|
|
#define png_infopp_NULL NULL
|
|
|
|
#endif
|
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_overlay_debug
|
2008-08-18 14:16:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2009-02-05 21:13:51 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_overlay_debug, "gloverlay", 0, "gloverlay element");
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLOverlay, gst_gl_overlay, GST_TYPE_GL_FILTER,
|
|
|
|
DEBUG_INIT);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2011-11-17 10:39:50 +00:00
|
|
|
static gboolean gst_gl_overlay_set_caps (GstGLFilter * filter,
|
|
|
|
GstCaps * incaps, GstCaps * outcaps);
|
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
static void gst_gl_overlay_set_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-02-05 21:13:51 +00:00
|
|
|
static void gst_gl_overlay_get_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_overlay_init_resources (GstGLFilter * filter);
|
|
|
|
static void gst_gl_overlay_reset_resources (GstGLFilter * filter);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2012-09-20 13:03:55 +00:00
|
|
|
static gboolean gst_gl_overlay_filter_texture (GstGLFilter * filter,
|
|
|
|
guint in_tex, guint out_tex);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
static gint gst_gl_overlay_load_png (GstGLFilter * filter);
|
|
|
|
static gint gst_gl_overlay_load_jpeg (GstGLFilter * filter);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LOCATION,
|
2009-09-21 13:00:02 +00:00
|
|
|
PROP_XPOS_PNG,
|
|
|
|
PROP_YPOS_PNG,
|
|
|
|
PROP_SIZE_PNG,
|
|
|
|
PROP_XPOS_VIDEO,
|
|
|
|
PROP_YPOS_VIDEO,
|
|
|
|
PROP_SIZE_VIDEO,
|
2009-11-16 13:32:16 +00:00
|
|
|
PROP_VIDEOTOP,
|
|
|
|
PROP_ROTATE_PNG,
|
|
|
|
PROP_ROTATE_VIDEO,
|
|
|
|
PROP_ANGLE_PNG,
|
2011-11-17 10:39:50 +00:00
|
|
|
PROP_ANGLE_VIDEO,
|
|
|
|
PROP_RATIO_VIDEO
|
2008-08-18 14:16:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* init resources that need a gl context */
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_init_gl_resources (GstGLFilter * filter)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
// GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free resources that need a gl context */
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_reset_gl_resources (GstGLFilter * filter)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
2013-09-15 04:23:43 +00:00
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->DeleteTextures (1, &overlay->pbuftexture);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_class_init (GstGLOverlayClass * klass)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-05-30 03:46:21 +00:00
|
|
|
GstElementClass *element_class;
|
2008-08-18 14:16:58 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-05-30 03:46:21 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
gobject_class->set_property = gst_gl_overlay_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_overlay_get_property;
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2011-11-17 10:39:50 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->set_caps = gst_gl_overlay_set_caps;
|
2012-09-20 13:03:55 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->filter_texture = gst_gl_overlay_filter_texture;
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->display_init_cb =
|
|
|
|
gst_gl_overlay_init_gl_resources;
|
|
|
|
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
|
|
|
|
gst_gl_overlay_reset_gl_resources;
|
2009-02-05 21:13:51 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->onStart = gst_gl_overlay_init_resources;
|
|
|
|
GST_GL_FILTER_CLASS (klass)->onStop = gst_gl_overlay_reset_resources;
|
2008-08-18 14:16:58 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2009-02-11 06:39:14 +00:00
|
|
|
PROP_LOCATION,
|
|
|
|
g_param_spec_string ("location",
|
|
|
|
"Location of the image",
|
2010-10-19 15:00:33 +00:00
|
|
|
"Location of the image", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-02 08:06:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2009-09-21 13:00:02 +00:00
|
|
|
PROP_XPOS_PNG,
|
|
|
|
g_param_spec_int ("xpos-png",
|
2009-09-02 08:06:36 +00:00
|
|
|
"X position of overlay image in percents",
|
|
|
|
"X position of overlay image in percents",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 100, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-21 13:00:02 +00:00
|
|
|
|
2009-09-02 08:06:36 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
2009-09-21 13:00:02 +00:00
|
|
|
PROP_YPOS_PNG,
|
|
|
|
g_param_spec_int ("ypos-png",
|
2009-09-02 08:06:36 +00:00
|
|
|
"Y position of overlay image in percents",
|
|
|
|
"Y position of overlay image in percents",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 100, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-21 13:00:02 +00:00
|
|
|
|
2009-09-02 08:06:36 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
2009-09-21 13:00:02 +00:00
|
|
|
PROP_SIZE_PNG,
|
|
|
|
g_param_spec_int ("proportion-png",
|
2009-09-02 08:06:36 +00:00
|
|
|
"Relative size of overlay image, in percents",
|
|
|
|
"Relative size of iverlay image, in percents",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 100, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-02 08:06:36 +00:00
|
|
|
|
2009-09-21 13:00:02 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_XPOS_VIDEO,
|
|
|
|
g_param_spec_int ("xpos-video",
|
|
|
|
"X position of overlay video in percents",
|
|
|
|
"X position of overlay video in percents",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 100, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-21 13:00:02 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_YPOS_VIDEO,
|
|
|
|
g_param_spec_int ("ypos-video",
|
|
|
|
"Y position of overlay video in percents",
|
|
|
|
"Y position of overlay video in percents",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 100, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-21 13:00:02 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SIZE_VIDEO,
|
|
|
|
g_param_spec_int ("proportion-video",
|
|
|
|
"Relative size of overlay video, in percents",
|
|
|
|
"Relative size of iverlay video, in percents",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 100, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-21 13:00:02 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_VIDEOTOP,
|
|
|
|
g_param_spec_boolean ("video-top",
|
2010-10-19 15:00:33 +00:00
|
|
|
"Video-top", "Video is over png image", FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-11-16 13:32:16 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ROTATE_PNG,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_int ("rotate-png",
|
2009-11-16 13:32:16 +00:00
|
|
|
"choose rotation axis for the moment only Y axis is implemented",
|
|
|
|
"choose rotation axis for the moment only Y axis is implemented",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 3, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-11-16 13:32:16 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ROTATE_VIDEO,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_int ("rotate-video",
|
2009-11-16 13:32:16 +00:00
|
|
|
"choose rotation axis for the moment only Y axis is implemented",
|
|
|
|
"choose rotation axis for the moment only Y axis is implemented",
|
2010-10-19 15:00:33 +00:00
|
|
|
0, 3, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-11-16 13:32:16 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ANGLE_PNG,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_int ("angle-png",
|
2009-11-16 13:32:16 +00:00
|
|
|
"choose angle in axis to choosen between -90 and 90",
|
|
|
|
"choose angle in axis to choosen between -90 and 90",
|
2010-10-19 15:00:33 +00:00
|
|
|
-90, 90, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-11-16 13:32:16 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ANGLE_VIDEO,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_int ("angle-video",
|
2009-11-16 13:32:16 +00:00
|
|
|
"choose angle in axis to choosen between -90 and 90",
|
|
|
|
"choose angle in axis to choosen between -90 and 90",
|
2010-10-19 15:00:33 +00:00
|
|
|
-90, 90, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-11-17 10:39:50 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_RATIO_VIDEO,
|
|
|
|
g_param_spec_int ("ratio-video",
|
|
|
|
"choose ratio video between 0 and 3\n \t\t\t0 : Default ratio\n\t\t\t1 : 4 / 3\n\t\t\t2 : 16 / 9\n\t\t\t3 : 16 / 10",
|
|
|
|
"choose ratio video between 0 and 3\n \t\t\t0 : Default ratio\n\t\t\t1 : 4 / 3\n\t\t\t2 : 16 / 9\n\t\t\t3 : 16 / 10",
|
|
|
|
0, 3, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-11-21 02:34:15 +00:00
|
|
|
gst_element_class_set_metadata (element_class,
|
2013-07-17 23:41:05 +00:00
|
|
|
"Gstreamer OpenGL Overlay", "Filter/Effect/Video",
|
2012-05-30 03:46:21 +00:00
|
|
|
"Overlay GL video texture with a PNG image",
|
|
|
|
"Filippo Argiolas <filippo.argiolas@gmail.com>");
|
|
|
|
|
2008-08-20 08:02:02 +00:00
|
|
|
/*
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_STRETCH,
|
|
|
|
g_param_spec_boolean ("stretch",
|
2009-09-21 13:00:02 +00:00
|
|
|
"Stretch the image to texture size",
|
|
|
|
"Stretch the image to fit video texture size",
|
2010-10-19 15:00:33 +00:00
|
|
|
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-11 06:39:14 +00:00
|
|
|
*/
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
2009-09-21 13:00:02 +00:00
|
|
|
static void
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_calc_ratio_video (GstGLOverlay * o, gfloat * video_ratio_w,
|
|
|
|
gfloat * video_ratio_h)
|
2009-09-21 13:00:02 +00:00
|
|
|
{
|
2011-11-17 10:39:50 +00:00
|
|
|
if (o->ratio_video == 0) {
|
|
|
|
o->ratio_texture = (gfloat) o->ratio_window;
|
2011-11-17 14:22:06 +00:00
|
|
|
*video_ratio_w = (gfloat) o->width_window;
|
|
|
|
*video_ratio_h = (gfloat) o->height_window;
|
|
|
|
} else if (o->ratio_video == 1) {
|
2011-11-17 10:39:50 +00:00
|
|
|
o->ratio_texture = (gfloat) 1.33;
|
2011-11-17 14:22:06 +00:00
|
|
|
*video_ratio_w = 4.0;
|
|
|
|
*video_ratio_h = 3.0;
|
2011-11-17 10:39:50 +00:00
|
|
|
} else if (o->ratio_video == 2) {
|
|
|
|
o->ratio_texture = (gfloat) 1.77;
|
2011-11-17 14:22:06 +00:00
|
|
|
*video_ratio_w = 16.0;
|
|
|
|
*video_ratio_h = 9.0;
|
2011-11-17 10:39:50 +00:00
|
|
|
} else {
|
|
|
|
o->ratio_texture = (gfloat) 1.6;
|
2011-11-17 14:22:06 +00:00
|
|
|
*video_ratio_w = 16.0;
|
|
|
|
*video_ratio_h = 10.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_overlay_init_texture (GstGLOverlay * o, GLuint tex, int flag)
|
|
|
|
{
|
2013-03-10 02:37:48 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (o);
|
2013-09-15 04:23:43 +00:00
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
2013-03-10 02:37:48 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
if (flag == 0 && o->type_file == 2) {
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->Enable (GL_TEXTURE_2D);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, tex);
|
2011-11-17 14:22:06 +00:00
|
|
|
} else {
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Enable (GL_TEXTURE_2D);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, tex);
|
2011-11-17 10:39:50 +00:00
|
|
|
}
|
2011-11-17 14:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_overlay_draw (GstGLOverlay * o, int flag)
|
|
|
|
{
|
2013-03-10 02:37:48 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (o);
|
2013-09-15 04:23:43 +00:00
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
2013-03-10 02:37:48 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
float y = 0.0f;
|
|
|
|
float width = 0.0f;
|
|
|
|
float height = 0.0f;
|
|
|
|
|
2013-03-10 02:37:48 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
float v_vertices[] = {
|
|
|
|
/*| Vertex | TexCoord |*/
|
|
|
|
-o->ratio_x + o->posx, y, 0.0f, 0.0f, 0.0f,
|
|
|
|
o->ratio_x + o->posx, y, 0.0f, width, 0.0f,
|
|
|
|
o->ratio_x + o->posx, y, 0.0f, width, height,
|
|
|
|
-o->ratio_x + o->posx, y, 0.0f, 0.0, height,
|
|
|
|
};
|
|
|
|
|
|
|
|
GLushort indices[] = {
|
|
|
|
0, 1, 2,
|
|
|
|
0, 2, 3,
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
if (flag == 1) {
|
2013-11-15 07:28:49 +00:00
|
|
|
width = 1.0f;
|
|
|
|
height = 1.0f;
|
2011-11-17 14:22:06 +00:00
|
|
|
} else if (flag == 0 && o->type_file == 1) {
|
2011-11-21 15:46:51 +00:00
|
|
|
width = (gfloat) o->width;
|
|
|
|
height = (gfloat) o->height;
|
2011-11-17 14:22:06 +00:00
|
|
|
} else if (flag == 0 && o->type_file == 2) {
|
2011-11-21 15:46:51 +00:00
|
|
|
width = 1.0f;
|
|
|
|
height = 1.0f;
|
2011-11-17 14:22:06 +00:00
|
|
|
}
|
2013-03-10 02:37:48 +00:00
|
|
|
|
|
|
|
v_vertices[8] = width;
|
|
|
|
v_vertices[13] = width;
|
|
|
|
v_vertices[14] = height;
|
|
|
|
v_vertices[19] = height;
|
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
y = (o->type_file == 2 && flag == 0 ? o->ratio_y : -o->ratio_y) + o->posy;
|
2013-03-10 02:37:48 +00:00
|
|
|
v_vertices[1] = y;
|
|
|
|
v_vertices[6] = y;
|
2011-11-17 14:22:06 +00:00
|
|
|
y = (o->type_file == 2 && flag == 0 ? -o->ratio_y : o->ratio_y) + o->posy;
|
2013-03-10 02:37:48 +00:00
|
|
|
v_vertices[11] = y;
|
|
|
|
v_vertices[16] = y;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (filter->context);
|
2013-03-10 02:37:48 +00:00
|
|
|
|
|
|
|
gl->ClientActiveTexture (GL_TEXTURE0);
|
|
|
|
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
gl->EnableClientState (GL_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
gl->VertexPointer (3, GL_FLOAT, 5 * sizeof (float), v_vertices);
|
|
|
|
gl->TexCoordPointer (2, GL_FLOAT, 5 * sizeof (float), &v_vertices[3]);
|
|
|
|
|
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
|
|
|
|
|
|
|
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
gl->DisableClientState (GL_VERTEX_ARRAY);
|
2011-11-17 14:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_overlay_calc_proportion (GstGLOverlay * o, int flag, float size_texture,
|
|
|
|
float width, float height)
|
|
|
|
{
|
2011-11-21 15:46:51 +00:00
|
|
|
if ((1.59f < o->ratio_window && o->ratio_window < 1.61f
|
|
|
|
&& 1.77f < o->ratio_texture && o->ratio_texture < 1.78f)
|
|
|
|
|| (1.3f < o->ratio_window && o->ratio_window < 1.34f
|
|
|
|
&& ((1.7f < o->ratio_texture && o->ratio_texture < 1.78f)
|
|
|
|
|| (1.59f < o->ratio_texture && o->ratio_texture < 1.61f)))) {
|
|
|
|
o->ratio_x = o->ratio_window * (gfloat) size_texture / 100.0f;
|
2011-11-17 10:39:50 +00:00
|
|
|
o->ratio_y =
|
2011-11-21 15:46:51 +00:00
|
|
|
(o->ratio_window / width) * height * (gfloat) size_texture / 100.0f;
|
2011-11-17 10:39:50 +00:00
|
|
|
} else {
|
2011-11-21 15:46:51 +00:00
|
|
|
o->ratio_x = o->ratio_texture * (gfloat) size_texture / 100.0f;
|
|
|
|
o->ratio_y = 1.0f * size_texture / 100.0f;
|
2011-11-17 10:39:50 +00:00
|
|
|
}
|
2011-11-17 14:22:06 +00:00
|
|
|
o->posx =
|
|
|
|
((o->ratio_window - o->ratio_x) * ((flag ==
|
2011-11-21 15:46:51 +00:00
|
|
|
1 ? o->pos_x_video : o->pos_x_png) - 50.0f) / 50.0f);
|
2011-11-17 14:22:06 +00:00
|
|
|
o->posy =
|
2011-11-21 15:46:51 +00:00
|
|
|
(1.0f - o->ratio_y) * (((flag ==
|
|
|
|
1 ? o->pos_y_video : o->pos_y_png) - 50.0f) / 50.0f);
|
2009-09-21 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_load_texture (GstGLOverlay * o, GLuint tex, int flag)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2013-03-10 02:37:48 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (o);
|
2013-09-15 04:23:43 +00:00
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
2013-03-10 02:37:48 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
gfloat video_ratio_w;
|
|
|
|
gfloat video_ratio_h;
|
|
|
|
|
2011-11-17 10:39:50 +00:00
|
|
|
o->ratio_window = (gfloat) o->width_window / (gfloat) o->height_window;
|
2013-03-10 02:37:48 +00:00
|
|
|
|
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_init_texture (o, tex, flag);
|
2013-03-10 02:37:48 +00:00
|
|
|
|
|
|
|
gl->BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
gl->Enable (GL_BLEND);
|
|
|
|
gl->Translatef (0.0f, 0.0f, -1.43f);
|
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
if (flag == 1) {
|
|
|
|
if (o->rotate_video)
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->Rotatef (o->angle_video, 0, 1, 0);
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_calc_ratio_video (o, &video_ratio_w, &video_ratio_h);
|
|
|
|
gst_gl_overlay_calc_proportion (o, flag, o->size_video, video_ratio_w,
|
|
|
|
video_ratio_h);
|
2011-11-17 10:39:50 +00:00
|
|
|
} else {
|
2011-11-17 14:22:06 +00:00
|
|
|
o->ratio_texture = (gfloat) o->width / (gfloat) o->height;
|
|
|
|
if (o->rotate_png == 2)
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->Rotatef (o->angle_png, 0, 1, 0);
|
2011-11-21 15:46:51 +00:00
|
|
|
gst_gl_overlay_calc_proportion (o, flag, o->size_png, (gfloat) o->width,
|
|
|
|
(gfloat) o->height);
|
2011-11-17 10:39:50 +00:00
|
|
|
}
|
2013-03-10 02:37:48 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_draw (o, flag);
|
|
|
|
if (flag == 1)
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Disable (GL_TEXTURE_2D);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_overlay_init (GstGLOverlay * overlay)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
overlay->location = NULL;
|
|
|
|
overlay->pixbuf = NULL;
|
|
|
|
overlay->pbuftexture = 0;
|
|
|
|
overlay->pbuftexture = 0;
|
|
|
|
overlay->width = 0;
|
|
|
|
overlay->height = 0;
|
2009-11-17 00:08:09 +00:00
|
|
|
overlay->pos_x_png = 0;
|
|
|
|
overlay->pos_y_png = 0;
|
2009-09-21 13:00:02 +00:00
|
|
|
overlay->size_png = 100;
|
2009-11-17 00:08:09 +00:00
|
|
|
overlay->pos_x_video = 0;
|
|
|
|
overlay->pos_y_video = 0;
|
2009-09-21 13:00:02 +00:00
|
|
|
overlay->size_video = 100;
|
|
|
|
overlay->video_top = FALSE;
|
2009-11-16 13:32:16 +00:00
|
|
|
overlay->rotate_png = 0;
|
|
|
|
overlay->rotate_video = 0;
|
|
|
|
overlay->angle_png = 0;
|
|
|
|
overlay->angle_video = 0;
|
2011-11-17 10:39:50 +00:00
|
|
|
overlay->ratio_video = 0;
|
2009-11-16 13:32:16 +00:00
|
|
|
// overlay->stretch = TRUE;
|
2009-02-05 21:13:51 +00:00
|
|
|
overlay->pbuf_has_changed = FALSE;
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_reset_resources (GstGLFilter * filter)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
// GstGLOverlay* overlay = GST_GL_OVERLAY(filter);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_set_property (GObject * object, guint prop_id,
|
2008-08-18 14:16:58 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (object);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-02-11 06:39:14 +00:00
|
|
|
case PROP_LOCATION:
|
|
|
|
if (overlay->location != NULL)
|
|
|
|
g_free (overlay->location);
|
|
|
|
overlay->pbuf_has_changed = TRUE;
|
|
|
|
overlay->location = g_value_dup_string (value);
|
|
|
|
break;
|
2009-09-21 13:00:02 +00:00
|
|
|
case PROP_XPOS_PNG:
|
|
|
|
overlay->pos_x_png = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_YPOS_PNG:
|
|
|
|
overlay->pos_y_png = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_SIZE_PNG:
|
|
|
|
overlay->size_png = g_value_get_int (value);
|
2009-09-02 08:06:36 +00:00
|
|
|
break;
|
2009-09-21 13:00:02 +00:00
|
|
|
case PROP_XPOS_VIDEO:
|
|
|
|
overlay->pos_x_video = g_value_get_int (value);
|
2009-09-02 08:06:36 +00:00
|
|
|
break;
|
2009-09-21 13:00:02 +00:00
|
|
|
case PROP_YPOS_VIDEO:
|
|
|
|
overlay->pos_y_video = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_SIZE_VIDEO:
|
|
|
|
overlay->size_video = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_VIDEOTOP:
|
|
|
|
overlay->video_top = g_value_get_boolean (value);
|
2009-09-02 08:06:36 +00:00
|
|
|
break;
|
2009-11-16 13:32:16 +00:00
|
|
|
case PROP_ROTATE_PNG:
|
|
|
|
overlay->rotate_png = g_value_get_int (value);
|
|
|
|
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;
|
2011-11-17 10:39:50 +00:00
|
|
|
case PROP_RATIO_VIDEO:
|
2011-11-21 15:46:51 +00:00
|
|
|
overlay->ratio_video = (gfloat) g_value_get_int (value);
|
2011-11-17 10:39:50 +00:00
|
|
|
break;
|
2009-11-16 13:32:16 +00:00
|
|
|
/* case PROP_STRETCH:
|
|
|
|
overlay->stretch = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
*/
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_get_property (GObject * object, guint prop_id,
|
2008-08-18 14:16:58 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (object);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-02-11 06:39:14 +00:00
|
|
|
case PROP_LOCATION:
|
|
|
|
g_value_set_string (value, overlay->location);
|
|
|
|
break;
|
2009-09-21 13:00:02 +00:00
|
|
|
case PROP_XPOS_PNG:
|
|
|
|
g_value_set_int (value, overlay->pos_x_png);
|
|
|
|
break;
|
|
|
|
case PROP_YPOS_PNG:
|
|
|
|
g_value_set_int (value, overlay->pos_y_png);
|
|
|
|
break;
|
|
|
|
case PROP_SIZE_PNG:
|
|
|
|
g_value_set_int (value, overlay->size_png);
|
|
|
|
break;
|
|
|
|
case PROP_XPOS_VIDEO:
|
|
|
|
g_value_set_int (value, overlay->pos_x_video);
|
|
|
|
break;
|
|
|
|
case PROP_YPOS_VIDEO:
|
|
|
|
g_value_set_int (value, overlay->pos_y_video);
|
2009-09-02 08:06:36 +00:00
|
|
|
break;
|
2009-09-21 13:00:02 +00:00
|
|
|
case PROP_SIZE_VIDEO:
|
|
|
|
g_value_set_int (value, overlay->size_video);
|
2009-09-02 08:06:36 +00:00
|
|
|
break;
|
2009-09-21 13:00:02 +00:00
|
|
|
case PROP_VIDEOTOP:
|
|
|
|
g_value_set_boolean (value, overlay->video_top);
|
2009-09-02 08:06:36 +00:00
|
|
|
break;
|
2009-11-16 13:32:16 +00:00
|
|
|
case PROP_ROTATE_PNG:
|
|
|
|
g_value_set_int (value, overlay->rotate_png);
|
|
|
|
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;
|
2011-11-17 10:39:50 +00:00
|
|
|
case PROP_RATIO_VIDEO:
|
2011-11-21 15:46:51 +00:00
|
|
|
g_value_set_int (value, (gint) overlay->ratio_video);
|
2011-11-17 10:39:50 +00:00
|
|
|
break;
|
2009-11-16 13:32:16 +00:00
|
|
|
/* case PROP_STRETCH:
|
|
|
|
g_value_set_boolean (value, overlay->stretch);
|
|
|
|
break;
|
|
|
|
*/
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 10:39:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_overlay_set_caps (GstGLFilter * filter, GstCaps * incaps,
|
|
|
|
GstCaps * outcaps)
|
|
|
|
{
|
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
2011-11-21 15:46:51 +00:00
|
|
|
GstStructure *s = gst_caps_get_structure (incaps, 0);
|
|
|
|
gint width = 0;
|
|
|
|
gint height = 0;
|
|
|
|
|
|
|
|
gst_structure_get_int (s, "width", &width);
|
|
|
|
gst_structure_get_int (s, "height", &height);
|
|
|
|
|
|
|
|
overlay->width_window = (gfloat) width;
|
|
|
|
overlay->height_window = (gfloat) height;
|
2011-11-17 10:39:50 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_init_resources (GstGLFilter * filter)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
// GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (stuff);
|
2013-03-10 02:37:48 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (overlay);
|
2013-09-15 04:23:43 +00:00
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
2011-11-17 10:39:50 +00:00
|
|
|
gluPerspective (70.0f,
|
|
|
|
(GLfloat) overlay->width_window / (GLfloat) overlay->height_window, 1.0f,
|
|
|
|
1000.0f);
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->Enable (GL_DEPTH_TEST);
|
2011-11-17 10:39:50 +00:00
|
|
|
gluLookAt (0.0, 0.0, 0.01, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
|
2013-03-11 04:51:06 +00:00
|
|
|
if (!overlay->video_top) {
|
|
|
|
if (overlay->pbuftexture != 0)
|
|
|
|
gst_gl_overlay_load_texture (overlay, overlay->pbuftexture, 0);
|
2011-11-17 10:39:50 +00:00
|
|
|
// if (overlay->stretch) {
|
|
|
|
// width = (gfloat) overlay->width;
|
|
|
|
// height = (gfloat) overlay->height;
|
|
|
|
// }
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->LoadIdentity ();
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_load_texture (overlay, texture, 1);
|
2011-11-17 10:39:50 +00:00
|
|
|
} else {
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_load_texture (overlay, texture, 1);
|
2011-11-17 10:39:50 +00:00
|
|
|
if (overlay->pbuftexture == 0)
|
|
|
|
return;
|
|
|
|
// if (overlay->stretch) {
|
|
|
|
// width = (gfloat) overlay->width;
|
|
|
|
// height = (gfloat) overlay->height;
|
|
|
|
// }
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->LoadIdentity ();
|
2011-11-17 14:22:06 +00:00
|
|
|
gst_gl_overlay_load_texture (overlay, overlay->pbuftexture, 0);
|
2011-11-17 10:39:50 +00:00
|
|
|
}
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
init_pixbuf_texture (GstGLContext * context, gpointer data)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (data);
|
2013-03-10 02:37:48 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (overlay);
|
2013-09-15 04:23:43 +00:00
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
if (overlay->pixbuf) {
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->DeleteTextures (1, &overlay->pbuftexture);
|
|
|
|
gl->GenTextures (1, &overlay->pbuftexture);
|
2011-11-17 14:22:06 +00:00
|
|
|
if (overlay->type_file == 1) {
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, overlay->pbuftexture);
|
|
|
|
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
|
2011-11-17 14:22:06 +00:00
|
|
|
(gint) overlay->width, (gint) overlay->height, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, overlay->pixbuf);
|
|
|
|
} else if (overlay->type_file == 2) {
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, overlay->pbuftexture);
|
|
|
|
gl->TexImage2D (GL_TEXTURE_2D, 0, overlay->internalFormat,
|
2011-11-17 14:22:06 +00:00
|
|
|
overlay->width, overlay->height, 0, overlay->format,
|
|
|
|
GL_UNSIGNED_BYTE, overlay->pixbuf);
|
2013-03-10 02:37:48 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2011-11-17 14:22:06 +00:00
|
|
|
}
|
2013-06-12 13:17:30 +00:00
|
|
|
}
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-20 13:03:55 +00:00
|
|
|
gst_gl_overlay_filter_texture (GstGLFilter * filter, guint in_tex,
|
|
|
|
guint out_tex)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
if (overlay->pbuf_has_changed && (overlay->location != NULL)) {
|
2011-11-17 14:22:06 +00:00
|
|
|
if ((overlay->type_file = gst_gl_overlay_load_png (filter)) == 0)
|
|
|
|
if ((overlay->type_file = gst_gl_overlay_load_jpeg (filter)) == 0)
|
|
|
|
overlay->pixbuf = NULL;
|
2013-09-15 04:23:43 +00:00
|
|
|
/* if loader failed then context is turned off */
|
|
|
|
gst_gl_context_thread_add (filter->context, init_pixbuf_texture, overlay);
|
2009-02-05 21:13:51 +00:00
|
|
|
if (overlay->pixbuf) {
|
|
|
|
free (overlay->pixbuf);
|
|
|
|
overlay->pixbuf = NULL;
|
2009-01-23 01:04:23 +00:00
|
|
|
}
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
overlay->pbuf_has_changed = FALSE;
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-09-25 08:06:14 +00:00
|
|
|
gst_gl_filter_render_to_target (filter, TRUE, in_tex, out_tex,
|
2012-09-20 13:03:55 +00:00
|
|
|
gst_gl_overlay_callback, overlay);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void
|
|
|
|
user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
|
2009-01-22 01:19:31 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
g_warning ("%s\n", warning_msg);
|
2009-01-22 01:19:31 +00:00
|
|
|
}
|
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
#define LOAD_ERROR(msg) { GST_WARNING ("unable to load %s: %s", overlay->location, msg); return FALSE; }
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
static gint
|
|
|
|
gst_gl_overlay_load_jpeg (GstGLFilter * filter)
|
|
|
|
{
|
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
|
|
|
FILE *fp = NULL;
|
|
|
|
struct jpeg_decompress_struct cinfo;
|
|
|
|
struct jpeg_error_mgr jerr;
|
|
|
|
JSAMPROW j;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fp = fopen (overlay->location, "rb");
|
|
|
|
if (!fp) {
|
|
|
|
g_error ("error: couldn't open file!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
jpeg_create_decompress (&cinfo);
|
|
|
|
cinfo.err = jpeg_std_error (&jerr);
|
|
|
|
jpeg_stdio_src (&cinfo, fp);
|
|
|
|
jpeg_read_header (&cinfo, TRUE);
|
|
|
|
jpeg_start_decompress (&cinfo);
|
|
|
|
overlay->width = cinfo.image_width;
|
|
|
|
overlay->height = cinfo.image_height;
|
|
|
|
overlay->internalFormat = cinfo.num_components;
|
|
|
|
if (cinfo.num_components == 1)
|
|
|
|
overlay->format = GL_LUMINANCE;
|
|
|
|
else
|
|
|
|
overlay->format = GL_RGB;
|
|
|
|
overlay->pixbuf = (GLubyte *) malloc (sizeof (GLubyte) * overlay->width
|
|
|
|
* overlay->height * overlay->internalFormat);
|
2012-07-16 12:40:15 +00:00
|
|
|
for (i = 0; i < overlay->height; ++i) {
|
2011-11-17 14:22:06 +00:00
|
|
|
j = (overlay->pixbuf +
|
|
|
|
(((int) overlay->height - (i +
|
|
|
|
1)) * (int) overlay->width * overlay->internalFormat));
|
|
|
|
jpeg_read_scanlines (&cinfo, &j, 1);
|
|
|
|
}
|
|
|
|
jpeg_finish_decompress (&cinfo);
|
|
|
|
jpeg_destroy_decompress (&cinfo);
|
|
|
|
fclose (fp);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gst_gl_overlay_load_png (GstGLFilter * filter)
|
2009-01-22 01:19:31 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
|
|
|
png_structp png_ptr;
|
|
|
|
png_infop info_ptr;
|
|
|
|
png_uint_32 width = 0;
|
|
|
|
png_uint_32 height = 0;
|
|
|
|
gint bit_depth = 0;
|
|
|
|
gint color_type = 0;
|
|
|
|
gint interlace_type = 0;
|
|
|
|
png_FILE_p fp = NULL;
|
|
|
|
guint y = 0;
|
|
|
|
guchar **rows = NULL;
|
2009-09-21 08:51:47 +00:00
|
|
|
gint filler;
|
2011-11-17 14:22:06 +00:00
|
|
|
png_byte magic[8];
|
2012-07-16 11:40:59 +00:00
|
|
|
gint n_read;
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (!filter->context)
|
2011-11-17 14:22:06 +00:00
|
|
|
return 1;
|
2012-07-16 11:40:59 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
if ((fp = fopen (overlay->location, "rb")) == NULL)
|
|
|
|
LOAD_ERROR ("file not found");
|
2012-07-16 11:40:59 +00:00
|
|
|
|
|
|
|
/* Read magic number */
|
|
|
|
n_read = fread (magic, 1, sizeof (magic), fp);
|
|
|
|
if (n_read != sizeof (magic)) {
|
2011-11-17 14:22:06 +00:00
|
|
|
fclose (fp);
|
2012-07-16 11:40:59 +00:00
|
|
|
LOAD_ERROR ("can't read PNG magic number");
|
2011-11-17 14:22:06 +00:00
|
|
|
}
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2012-07-16 11:40:59 +00:00
|
|
|
/* Check for valid magic number */
|
|
|
|
if (png_sig_cmp (magic, 0, sizeof (magic))) {
|
|
|
|
fclose (fp);
|
|
|
|
LOAD_ERROR ("not a valid PNG image");
|
|
|
|
}
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (png_ptr == NULL) {
|
|
|
|
fclose (fp);
|
2009-01-22 01:19:31 +00:00
|
|
|
LOAD_ERROR ("failed to initialize the png_struct");
|
|
|
|
}
|
|
|
|
|
|
|
|
png_set_error_fn (png_ptr, NULL, NULL, user_warning_fn);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
info_ptr = png_create_info_struct (png_ptr);
|
|
|
|
if (info_ptr == NULL) {
|
|
|
|
fclose (fp);
|
|
|
|
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
|
2009-01-22 01:19:31 +00:00
|
|
|
LOAD_ERROR ("failed to initialize the memory for image information");
|
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_init_io (png_ptr, fp);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2012-07-16 11:40:59 +00:00
|
|
|
png_set_sig_bytes (png_ptr, sizeof (magic));
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_read_info (png_ptr, info_ptr);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
|
|
|
&interlace_type, int_p_NULL, int_p_NULL);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-09-21 08:51:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
|
|
|
|
fclose (fp);
|
|
|
|
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
|
2009-01-22 01:19:31 +00:00
|
|
|
LOAD_ERROR ("color type is not rgb");
|
|
|
|
}
|
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
overlay->width = width;
|
|
|
|
overlay->height = height;
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
overlay->pixbuf = (guchar *) malloc (sizeof (guchar) * width * height * 4);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
rows = (guchar **) malloc (sizeof (guchar *) * height);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
for (y = 0; y < height; ++y)
|
|
|
|
rows[y] = (guchar *) (overlay->pixbuf + y * width * 4);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_read_image (png_ptr, rows);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
free (rows);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_read_end (png_ptr, info_ptr);
|
|
|
|
png_destroy_read_struct (&png_ptr, &info_ptr, png_infopp_NULL);
|
|
|
|
fclose (fp);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2011-11-17 14:22:06 +00:00
|
|
|
return 1;
|
2009-01-22 01:19:31 +00:00
|
|
|
}
|