[gst-devel] [PATCH] new videofilter: gamma correction
Arwed von Merkatz
a.v.merkatz at t-online.de
Sat Jan 10 10:31:02 CET 2004
Hi,
due to a very old monitor i need gamma correction to see anything when
playing video. gst was missing such a filter, so i wrote a simple one.
--
Arwed v. Merkatz
Grimoire Guru for video
Grimoire Guru for xfce
Sourcemage GNU/Linux
http://www.sourcemage.org
-------------- next part --------------
diff -Nur -x CVS gst-plugins/gst/videofilter/gstvideogamma.c gst-plugins-gamma/gst/videofilter/gstvideogamma.c
--- gst-plugins/gst/videofilter/gstvideogamma.c 1970-01-01 01:00:00.000000000 +0100
+++ gst-plugins-gamma/gst/videofilter/gstvideogamma.c 2004-01-10 19:25:26.000000000 +0100
@@ -0,0 +1,249 @@
+/* GStreamer
+ * (c) 2003 Arwed v. Merkatz <v.merkatz at gmx.net>
+ *
+ * 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.
+ */
+
+/*
+ * This file was (probably) generated from gstvideotemplate.c,
+ * gstvideotemplate.c,v 1.9 2003/12/04 10:37:28 wingo Exp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*#define DEBUG_ENABLED */
+#include <gstvideogamma.h>
+#include <string.h>
+#include <math.h>
+
+/* Gstvideogamma signals and args */
+enum {
+ /* FILL ME */
+ LAST_SIGNAL
+};
+
+enum {
+ ARG_0,
+ ARG_GAMMA,
+ /* FILL ME */
+};
+
+static void gst_videogamma_base_init (gpointer g_class);
+static void gst_videogamma_class_init (gpointer g_class, gpointer class_data);
+static void gst_videogamma_init (GTypeInstance *instance, gpointer g_class);
+
+static void gst_videogamma_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static void gst_videogamma_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+
+static void gst_videogamma_planar411(GstVideofilter *videofilter, void *dest, void *src);
+static void gst_videogamma_setup(GstVideofilter *videofilter);
+
+GType
+gst_videogamma_get_type (void)
+{
+ static GType videogamma_type = 0;
+
+ if (!videogamma_type) {
+ static const GTypeInfo videogamma_info = {
+ sizeof(GstvideogammaClass),
+ gst_videogamma_base_init,
+ NULL,
+ gst_videogamma_class_init,
+ NULL,
+ NULL,
+ sizeof(Gstvideogamma),
+ 0,
+ gst_videogamma_init,
+ };
+ videogamma_type = g_type_register_static(GST_TYPE_VIDEOFILTER,
+ "Gstvideogamma", &videogamma_info, 0);
+ }
+ return videogamma_type;
+}
+
+static GstVideofilterFormat gst_videogamma_formats[] = {
+ { "I420", 12, gst_videogamma_planar411, },
+};
+
+
+static void
+gst_videogamma_base_init (gpointer g_class)
+{
+ static GstElementDetails videogamma_details = GST_ELEMENT_DETAILS (
+ "Video Gamma Correction",
+ "Filter/Effect/Video",
+ "Adjusts gamma on a video stream",
+ "Arwed v. Merkatz <v.merkatz at gmx.net"
+ );
+ GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+ GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
+ int i;
+
+ gst_element_class_set_details (element_class, &videogamma_details);
+
+ for(i=0;i<G_N_ELEMENTS(gst_videogamma_formats);i++){
+ gst_videofilter_class_add_format(videofilter_class,
+ gst_videogamma_formats + i);
+ }
+
+ gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
+}
+
+static void
+gst_videogamma_class_init (gpointer g_class, gpointer class_data)
+{
+ GObjectClass *gobject_class;
+ GstVideofilterClass *videofilter_class;
+
+ gobject_class = G_OBJECT_CLASS (g_class);
+ videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
+
+ g_object_class_install_property(gobject_class, ARG_GAMMA,
+ g_param_spec_double("gamma", "Gamma", "gamma",
+ 0.01, 10, 1, G_PARAM_READWRITE));
+
+ gobject_class->set_property = gst_videogamma_set_property;
+ gobject_class->get_property = gst_videogamma_get_property;
+
+ videofilter_class->setup = gst_videogamma_setup;
+}
+
+static void
+gst_videogamma_init (GTypeInstance *instance, gpointer g_class)
+{
+ Gstvideogamma *videogamma = GST_VIDEOGAMMA (instance);
+ GstVideofilter *videofilter;
+
+ GST_DEBUG("gst_videogamma_init");
+
+ videofilter = GST_VIDEOFILTER(videogamma);
+
+ /* do stuff */
+ videogamma->gamma = 1;
+ videogamma->gamma_table_calculated = 0;
+}
+
+static void
+gst_videogamma_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ Gstvideogamma *src;
+
+ /* it's not null if we got it, but it might not be ours */
+ g_return_if_fail(GST_IS_VIDEOGAMMA(object));
+ src = GST_VIDEOGAMMA(object);
+
+ GST_DEBUG("gst_videogamma_set_property");
+ switch (prop_id) {
+ case ARG_GAMMA:
+ src->gamma = 1.0 / g_value_get_double (value);
+ src->gamma_table_calculated = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+gst_videogamma_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ Gstvideogamma *src;
+
+ /* it's not null if we got it, but it might not be ours */
+ g_return_if_fail(GST_IS_VIDEOGAMMA(object));
+ src = GST_VIDEOGAMMA(object);
+
+ switch (prop_id) {
+ case ARG_GAMMA:
+ g_value_set_double (value, 1.0 / src->gamma);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static gboolean plugin_init (GstPlugin *plugin)
+{
+ if(!gst_library_load("gstvideofilter"))
+ return FALSE;
+
+ return gst_element_register (plugin, "videogamma", GST_RANK_NONE,
+ GST_TYPE_VIDEOGAMMA);
+}
+
+GST_PLUGIN_DEFINE (
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "videogamma",
+ "Changes gamma on video images",
+ plugin_init,
+ VERSION,
+ GST_LICENSE,
+ GST_PACKAGE,
+ GST_ORIGIN
+)
+
+static void gst_videogamma_setup(GstVideofilter *videofilter)
+{
+ Gstvideogamma *videogamma;
+
+ g_return_if_fail(GST_IS_VIDEOGAMMA(videofilter));
+ videogamma = GST_VIDEOGAMMA(videofilter);
+
+ /* if any setup needs to be done, do it here */
+
+}
+
+static void gst_videogamma_planar411(GstVideofilter *videofilter,
+ void *dest, void *src)
+{
+ Gstvideogamma *videogamma;
+ int width = gst_videofilter_get_input_width(videofilter);
+ int height = gst_videofilter_get_input_height(videofilter);
+ int n;
+ double val;
+
+ g_return_if_fail(GST_IS_VIDEOGAMMA(videofilter));
+ videogamma = GST_VIDEOGAMMA(videofilter);
+
+ memcpy(dest,src,width * height + (width/2) * (height/2) * 2);
+
+ if (videogamma->gamma != 1.0) {
+ if (!videogamma->gamma_table_calculated) {
+ for (n = 0; n < 256; n++) {
+ val = n/255.0;
+ val = pow(val, videogamma->gamma);
+ val = 255.0 * val;
+ videogamma->gamma_table[n] = (unsigned char) val;
+ }
+ videogamma->gamma_table_calculated = 1;
+ }
+
+ {
+ guint8 *cdest = dest;
+ guint8 *csrc = src;
+ int x,y;
+ for (y=0; y < height; y++) {
+ for (x=0; x < width; x++) {
+ cdest[y*width + x] = videogamma->gamma_table[(unsigned char)csrc[y*width + x]];
+ }
+ }
+ }
+ }
+}
+
diff -Nur -x CVS gst-plugins/gst/videofilter/gstvideogamma.h gst-plugins-gamma/gst/videofilter/gstvideogamma.h
--- gst-plugins/gst/videofilter/gstvideogamma.h 1970-01-01 01:00:00.000000000 +0100
+++ gst-plugins-gamma/gst/videofilter/gstvideogamma.h 2004-01-10 19:24:11.000000000 +0100
@@ -0,0 +1,63 @@
+/* GStreamer
+ * (c) 2003 Arwed v. Merkatz <v.merkatz at gmx.net>
+ *
+ * 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.
+ */
+
+
+#ifndef __GST_VIDEOGAMMA_H__
+#define __GST_VIDEOGAMMA_H__
+
+
+#include <gst/gst.h>
+
+#include "gstvideofilter.h"
+
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_VIDEOGAMMA \
+ (gst_videogamma_get_type())
+#define GST_VIDEOGAMMA(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEOGAMMA,Gstvideogamma))
+#define GST_VIDEOGAMMA_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEOGAMMA,GstvideogammaClass))
+#define GST_IS_VIDEOGAMMA(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEOGAMMA))
+#define GST_IS_VIDEOGAMMA_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEOGAMMA))
+
+typedef struct _Gstvideogamma Gstvideogamma;
+typedef struct _GstvideogammaClass GstvideogammaClass;
+
+struct _Gstvideogamma {
+ GstVideofilter videofilter;
+
+ double gamma;
+ int gamma_table_calculated;
+ unsigned char gamma_table[256];
+};
+
+struct _GstvideogammaClass {
+ GstVideofilterClass parent_class;
+};
+
+GType gst_videogamma_get_type(void);
+
+G_END_DECLS
+
+#endif /* __GST_VIDEOGAMMA_H__ */
+
diff -Nur -x CVS gst-plugins/gst/videofilter/Makefile.am gst-plugins-gamma/gst/videofilter/Makefile.am
--- gst-plugins/gst/videofilter/Makefile.am 2004-01-10 19:18:31.000000000 +0100
+++ gst-plugins-gamma/gst/videofilter/Makefile.am 2004-01-10 19:17:42.000000000 +0100
@@ -1,9 +1,9 @@
plugin_LTLIBRARIES = libgstvideofilter.la libgstvideoflip.la \
- libgstvideobalance.la
+ libgstvideobalance.la libgstvideogamma.la
noinst_LTLIBRARIES = libgstvideoexample.la
-noinst_HEADERS = gstvideofilter.h gstvideoflip.h gstvideobalance.h
+noinst_HEADERS = gstvideofilter.h gstvideoflip.h gstvideobalance.h gstvideogamma.h
EXTRA_DIST = gstvideotemplate.c make_filter
CLEANFILES = gstvideoexample.c
@@ -28,6 +28,10 @@
libgstvideobalance_la_LIBADD =
libgstvideobalance_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -lm
+libgstvideogamma_la_SOURCES = gstvideogamma.c
+libgstvideogamma_la_CFLAGS = $(GST_CFLAGS)
+libgstvideogamma_la_LIBADD =
+libgstvideogamma_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -lm
gstvideoexample.c: $(srcdir)/make_filter $(srcdir)/gstvideotemplate.c
$(srcdir)/make_filter Videoexample $(srcdir)/gstvideotemplate.c
More information about the gstreamer-devel
mailing list