ext/: update of cairo-based timeoverlay to 1.0 Cairo API doesn't work yet for resizing of output sink

Original commit message from CVS:

* ext/Makefile.am:
* ext/cairo/Makefile.am:
* ext/cairo/gstcairo.c: (plugin_init):
* ext/cairo/gsttextoverlay.c: (gst_textoverlay_change_state):
* ext/cairo/gsttimeoverlay.c: (gst_timeoverlay_update_font_height),
(gst_timeoverlay_setup), (gst_timeoverlay_planar411):
* ext/cairo/gsttimeoverlay.h:
update of cairo-based timeoverlay to 1.0 Cairo API
doesn't work yet for resizing of output sink
This commit is contained in:
Thomas Vander Stichele 2005-10-12 03:12:57 +00:00
parent 722ec5e4ab
commit b51bde9b55
7 changed files with 102 additions and 52 deletions

View file

@ -1,3 +1,15 @@
2005-10-12 Thomas Vander Stichele <thomas at apestaart dot org>
* ext/Makefile.am:
* ext/cairo/Makefile.am:
* ext/cairo/gstcairo.c: (plugin_init):
* ext/cairo/gsttextoverlay.c: (gst_textoverlay_change_state):
* ext/cairo/gsttimeoverlay.c: (gst_timeoverlay_update_font_height),
(gst_timeoverlay_setup), (gst_timeoverlay_planar411):
* ext/cairo/gsttimeoverlay.h:
update of cairo-based timeoverlay to 1.0 Cairo API
doesn't work yet for resizing of output sink
2005-10-11 Wim Taymans <wim@fluendo.com>
* ext/speex/gstspeexdec.c: (speex_dec_event), (speex_dec_chain):

View file

@ -4,11 +4,11 @@ else
AALIB_DIR =
endif
# if USE_CAIRO
# CAIRO_DIR = cairo
# else
if USE_CAIRO
CAIRO_DIR = cairo
else
CAIRO_DIR =
# endif
endif
if USE_ESD
ESD_DIR = esd

View file

@ -1,14 +1,17 @@
plugin_LTLIBRARIES = libgstcairo.la
noinst_HEADERS = gsttimeoverlay.h gsttextoverlay.h
noinst_HEADERS = gsttimeoverlay.h # gsttextoverlay.h
libgstcairo_la_SOURCES = \
gsttimeoverlay.c \
gsttextoverlay.c \
gstcairo.c
libgstcairo_la_CFLAGS = $(GST_CFLAGS) $(CAIRO_CFLAGS) \
-I$(top_srcdir)/gst/videofilter
libgstcairo_la_LIBADD = $(GST_LIBS) $(CAIRO_LIBS) -lm
libgstcairo_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
# gsttextoverlay.c
libgstcairo_la_CFLAGS = \
-I$(top_srcdir)/gst/videofilter \
$(GST_CFLAGS) $(CAIRO_CFLAGS)
libgstcairo_la_LIBADD = \
$(top_builddir)/gst/videofilter/libgstvideofilter-$(GST_MAJORMINOR).la \
$(GST_LIBS) $(CAIRO_LIBS) -lm
libgstcairo_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)

View file

@ -33,11 +33,10 @@ GST_DEBUG_CATEGORY (cairo_debug);
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_library_load ("gstvideofilter"))
return FALSE;
#if 0
gst_element_register (plugin, "cairotextoverlay", GST_RANK_NONE,
GST_TYPE_TEXTOVERLAY);
#endif
gst_element_register (plugin, "cairotimeoverlay", GST_RANK_NONE,
GST_TYPE_TIMEOVERLAY);
@ -46,5 +45,6 @@ plugin_init (GstPlugin * plugin)
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "timeoverlay",
"Time overlay", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "cairo",
"Cairo-based overlaying", plugin_init, VERSION,
GST_LICENSE, GST_PACKAGE, GST_ORIGIN);

View file

@ -77,7 +77,8 @@ static void gst_textoverlay_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_textoverlay_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static GstStateChangeReturn gst_textoverlay_change_state (GstElement * element);
static GstStateChangeReturn gst_textoverlay_change_state (GstElement * element,
GstStateChange transition);
static void gst_textoverlay_finalize (GObject * object);
@ -563,6 +564,8 @@ gst_textoverlay_change_state (GstElement * element, GstStateChange transition)
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
break;
default:
break;
}
parent_class->change_state (element, transition);

View file

@ -189,27 +189,42 @@ gst_timeoverlay_get_property (GObject * object, guint prop_id, GValue * value,
}
}
static void
gst_timeoverlay_update_font_height (GstVideofilter * videofilter)
{
GstTimeoverlay *timeoverlay = GST_TIMEOVERLAY (videofilter);
gint width, height;
cairo_surface_t *font_surface;
cairo_t *font_cairo;
cairo_font_extents_t font_extents;
width = gst_videofilter_get_input_width (videofilter);
height = gst_videofilter_get_input_height (videofilter);
font_surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
font_cairo = cairo_create (font_surface);
cairo_surface_destroy (font_surface);
font_surface = NULL;
cairo_select_font_face (font_cairo, "monospace", 0, 0);
cairo_set_font_size (font_cairo, 20);
cairo_font_extents (font_cairo, &font_extents);
timeoverlay->text_height = font_extents.height;
GST_DEBUG_OBJECT (timeoverlay, "font height is %d", font_extents.height);
cairo_destroy (font_cairo);
font_cairo = NULL;
}
static void
gst_timeoverlay_setup (GstVideofilter * videofilter)
{
GstTimeoverlay *timeoverlay;
cairo_font_extents_t font_extents;
g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter));
timeoverlay = GST_TIMEOVERLAY (videofilter);
/* if any setup needs to be done, do it here */
timeoverlay->cr = cairo_create ();
cairo_set_rgb_color (timeoverlay->cr, 0, 0, 0);
cairo_select_font (timeoverlay->cr, "monospace", 0, 0);
cairo_scale_font (timeoverlay->cr, 20);
cairo_current_font_extents (timeoverlay->cr, &font_extents);
timeoverlay->text_height = font_extents.height;
gst_timeoverlay_update_font_height (videofilter);
}
static char *
@ -234,6 +249,7 @@ gst_timeoverlay_print_smpte_time (guint64 time)
return g_strdup_printf ("%02d:%02d:%02d.%03d", hours, minutes, seconds, ms);
}
static void
gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
{
@ -243,37 +259,49 @@ gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
int b_width;
char *string;
int i, j;
uint8_t *image;
unsigned char *image;
cairo_text_extents_t extents;
cairo_surface_t *font_surface;
cairo_t *text_cairo;
g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter));
timeoverlay = GST_TIMEOVERLAY (videofilter);
width = gst_videofilter_get_input_width (videofilter);
height = gst_videofilter_get_input_height (videofilter);
/* create surface for font rendering */
/* FIXME: preparation of the surface could also be done once when settings
* change */
image = g_malloc (4 * width * timeoverlay->text_height);
font_surface =
cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32, width,
timeoverlay->text_height, width * 4);
text_cairo = cairo_create (font_surface);
cairo_surface_destroy (font_surface);
font_surface = NULL;
/* we draw a rectangle because the compositing on the buffer below
* doesn't do alpha */
cairo_save (text_cairo);
cairo_rectangle (text_cairo, 0, 0, width, timeoverlay->text_height);
cairo_set_source_rgba (text_cairo, 0, 0, 0, 1);
cairo_set_operator (text_cairo, CAIRO_OPERATOR_SOURCE);
cairo_fill (text_cairo);
cairo_restore (text_cairo);
string =
gst_timeoverlay_print_smpte_time (GST_BUFFER_TIMESTAMP (videofilter->
in_buf));
image = g_malloc (4 * width * timeoverlay->text_height);
cairo_set_target_image (timeoverlay->cr, image, CAIRO_FORMAT_ARGB32,
width, timeoverlay->text_height, width * 4);
cairo_save (timeoverlay->cr);
cairo_rectangle (timeoverlay->cr, 0, 0, width, timeoverlay->text_height);
cairo_set_alpha (timeoverlay->cr, 0);
cairo_set_operator (timeoverlay->cr, CAIRO_OPERATOR_SRC);
cairo_fill (timeoverlay->cr);
cairo_restore (timeoverlay->cr);
cairo_save (timeoverlay->cr);
cairo_text_extents (timeoverlay->cr, string, &extents);
cairo_set_rgb_color (timeoverlay->cr, 1, 1, 1);
cairo_move_to (timeoverlay->cr, 0, timeoverlay->text_height - 2);
cairo_show_text (timeoverlay->cr, string);
cairo_save (text_cairo);
cairo_select_font_face (text_cairo, "monospace", 0, 0);
cairo_set_font_size (text_cairo, 20);
cairo_text_extents (text_cairo, string, &extents);
cairo_set_source_rgb (text_cairo, 1, 1, 1);
cairo_move_to (text_cairo, 0, timeoverlay->text_height - 2);
cairo_show_text (text_cairo, string);
g_free (string);
#if 0
cairo_text_path (timeoverlay->cr, string);
@ -282,8 +310,9 @@ gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
cairo_stroke (timeoverlay->cr);
#endif
cairo_restore (timeoverlay->cr);
cairo_restore (text_cairo);
/* blend width; should retain a max text width so it doesn't jitter */
b_width = extents.width;
if (b_width > width)
b_width = width;
@ -291,7 +320,7 @@ gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
memcpy (dest, src, videofilter->from_buf_size);
for (i = 0; i < timeoverlay->text_height; i++) {
for (j = 0; j < b_width; j++) {
((uint8_t *) dest)[i * width + j] = image[(i * width + j) * 4 + 0];
((unsigned char *) dest)[i * width + j] = image[(i * width + j) * 4 + 0];
}
}
for (i = 0; i < timeoverlay->text_height / 2; i++) {
@ -300,5 +329,7 @@ gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
i * (width / 2), 128, b_width / 2);
}
cairo_destroy (text_cairo);
text_cairo = NULL;
g_free (image);
}

View file

@ -47,6 +47,7 @@ typedef struct _GstTimeoverlayClass GstTimeoverlayClass;
struct _GstTimeoverlay {
GstVideofilter videofilter;
cairo_surface_t *surface;
cairo_t *cr;
int text_height;