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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
*/
|
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-02-23 11:35:48 +00:00
|
|
|
#include <stdlib.h>
|
2009-01-22 01:19:31 +00:00
|
|
|
#include <png.h>
|
2009-07-29 23:36:30 +00:00
|
|
|
#include "gstgloverlay.h"
|
2008-08-18 18:25:25 +00:00
|
|
|
#include <gstgleffectssources.h>
|
2008-08-18 14:16:58 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
#define DEBUG_INIT(bla) \
|
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
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstGLOverlay, gst_gl_overlay, GstGLFilter,
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_TYPE_GL_FILTER, DEBUG_INIT);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
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
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
static gboolean gst_gl_overlay_filter (GstGLFilter * filter,
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static gboolean gst_gl_overlay_loader (GstGLFilter * filter);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static const GstElementDetails element_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Gstreamer OpenGL Overlay",
|
|
|
|
"Filter/Effect",
|
|
|
|
"Overlay GL video texture with a PNG image",
|
|
|
|
"Filippo Argiolas <filippo.argiolas@gmail.com>");
|
2008-08-18 14:16:58 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LOCATION,
|
2008-08-20 08:02:02 +00:00
|
|
|
// PROP_STRETCH,
|
2008-08-18 14:16:58 +00:00
|
|
|
/* future properties? */
|
|
|
|
/* PROP_WIDTH, */
|
|
|
|
/* PROP_HEIGHT, */
|
|
|
|
/* PROP_XPOS, */
|
|
|
|
/* PROP_YPOS */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
glDeleteTextures (1, &overlay->pbuftexture);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_base_init (gpointer klass)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &element_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) 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
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_overlay_filter;
|
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",
|
|
|
|
"Location of the image", NULL, G_PARAM_READWRITE));
|
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",
|
|
|
|
"Stretch the image to texture size",
|
|
|
|
"Stretch the image to fit video texture size",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
|
|
|
*/
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_draw_texture (GstGLOverlay * overlay, GLuint tex)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (overlay);
|
2008-08-18 14:16:58 +00:00
|
|
|
|
2008-08-20 08:02:02 +00:00
|
|
|
gfloat width = (gfloat) filter->width;
|
|
|
|
gfloat height = (gfloat) filter->height;
|
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
glActiveTexture (GL_TEXTURE0);
|
|
|
|
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
|
|
|
|
glTexCoord2f (0.0, 0.0);
|
|
|
|
glVertex2f (-1.0, -1.0);
|
2008-08-20 08:02:02 +00:00
|
|
|
glTexCoord2f (width, 0.0);
|
2008-08-18 14:16:58 +00:00
|
|
|
glVertex2f (1.0, -1.0);
|
2008-08-20 08:02:02 +00:00
|
|
|
glTexCoord2f (width, height);
|
2008-08-18 14:16:58 +00:00
|
|
|
glVertex2f (1.0, 1.0);
|
2008-08-20 08:02:02 +00:00
|
|
|
glTexCoord2f (0.0, height);
|
2008-08-18 14:16:58 +00:00
|
|
|
glVertex2f (-1.0, 1.0);
|
|
|
|
|
|
|
|
glEnd ();
|
2008-08-20 07:26:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (overlay->pbuftexture == 0)
|
|
|
|
return;
|
2008-08-20 07:26:46 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
// if (overlay->stretch) {
|
2009-02-11 06:39:14 +00:00
|
|
|
width = (gfloat) overlay->width;
|
|
|
|
height = (gfloat) overlay->height;
|
2008-08-20 08:02:02 +00:00
|
|
|
// }
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable (GL_BLEND);
|
2008-08-20 07:26:46 +00:00
|
|
|
|
|
|
|
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
2009-02-05 21:13:51 +00:00
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture);
|
2008-08-20 07:26:46 +00:00
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
|
|
|
|
glTexCoord2f (0.0, 0.0);
|
|
|
|
glVertex2f (-1.0, -1.0);
|
2008-08-20 08:02:02 +00:00
|
|
|
glTexCoord2f (width, 0.0);
|
2008-08-20 07:26:46 +00:00
|
|
|
glVertex2f (1.0, -1.0);
|
2008-08-20 08:02:02 +00:00
|
|
|
glTexCoord2f (width, height);
|
2008-08-20 07:26:46 +00:00
|
|
|
glVertex2f (1.0, 1.0);
|
2008-08-20 08:02:02 +00:00
|
|
|
glTexCoord2f (0.0, height);
|
2008-08-20 07:26:46 +00:00
|
|
|
glVertex2f (-1.0, 1.0);
|
|
|
|
|
|
|
|
glEnd ();
|
|
|
|
|
|
|
|
|
|
|
|
glFlush ();
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_init (GstGLOverlay * overlay, GstGLOverlayClass * klass)
|
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;
|
|
|
|
// overlay->stretch = TRUE;
|
|
|
|
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;
|
2008-08-20 08:02:02 +00:00
|
|
|
/* case PROP_STRETCH:
|
2009-02-05 21:13:51 +00:00
|
|
|
overlay->stretch = g_value_get_boolean (value);
|
2008-08-20 08:02:02 +00:00
|
|
|
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;
|
2008-08-20 08:02:02 +00:00
|
|
|
/* case PROP_STRETCH:
|
2009-02-05 21:13:51 +00:00
|
|
|
g_value_set_boolean (value, overlay->stretch);
|
2008-08-20 08:02:02 +00:00
|
|
|
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-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);
|
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
glMatrixMode (GL_PROJECTION);
|
|
|
|
glLoadIdentity ();
|
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_overlay_draw_texture (overlay, texture);
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void
|
|
|
|
init_pixbuf_texture (GstGLDisplay * display, gpointer data)
|
2008-08-18 14:16:58 +00:00
|
|
|
{
|
2009-02-05 21:13:51 +00:00
|
|
|
GstGLOverlay *overlay = GST_GL_OVERLAY (data);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
if (overlay->pixbuf) {
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
glDeleteTextures (1, &overlay->pbuftexture);
|
|
|
|
glGenTextures (1, &overlay->pbuftexture);
|
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture);
|
2009-01-22 01:19:31 +00:00
|
|
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
|
2009-02-11 06:39:14 +00:00
|
|
|
(gint) overlay->width, (gint) overlay->height, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, overlay->pixbuf);
|
|
|
|
} else
|
2009-01-22 01:19:31 +00:00
|
|
|
display->isAlive = FALSE;
|
2008-08-18 14:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
|
|
|
|
GstGLBuffer * outbuf)
|
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)) {
|
2009-01-22 01:19:31 +00:00
|
|
|
|
2009-02-05 21:13:51 +00:00
|
|
|
if (!gst_gl_overlay_loader (filter))
|
|
|
|
overlay->pixbuf = NULL;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2009-01-23 01:04:23 +00:00
|
|
|
/* if loader failed then display is turned off */
|
2009-02-05 21:13:51 +00:00
|
|
|
gst_gl_display_thread_add (filter->display, init_pixbuf_texture, overlay);
|
2009-01-22 01:19:31 +00:00
|
|
|
|
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
|
|
|
|
2008-08-18 14:16:58 +00:00
|
|
|
gst_gl_filter_render_to_target (filter, inbuf->texture, outbuf->texture,
|
2009-02-11 06:39:14 +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
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_overlay_loader (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;
|
|
|
|
guint sig_read = 0;
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!filter->display)
|
|
|
|
return TRUE;
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if ((fp = fopen (overlay->location, "rb")) == NULL)
|
2009-01-22 01:19:31 +00:00
|
|
|
LOAD_ERROR ("file not found");
|
|
|
|
|
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
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
png_set_sig_bytes (png_ptr, sig_read);
|
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-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
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|