remove some warnings about unused functions
[sparrow.git] / src / gstsparrow.c
blob3e010a34f97882c7a892d6b6ff8a2b1268285e2e
1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
4 * Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 /**
24 * SECTION:element-sparrow
26 * Performs sparrow correction on a video stream.
28 * <refsect2>
29 * <title>Example launch line</title>
30 * |[
31 * gst-launch videotestsrc ! ffmpegcolorspace ! sparrow ! ximagesink
32 * ]|
33 * </refsect2>
36 #include "gstsparrow.h"
37 #include <gst/video/gstvideofilter.h>
38 #include <gst/video/video.h>
40 #include "sparrow_gamma_lut.h"
43 #ifdef HAVE_LIBOIL
44 #include <liboil/liboil.h>
45 #include <liboil/liboilcpu.h>
46 #include <liboil/liboilfunction.h>
47 #endif
50 #include <string.h>
51 #include <math.h>
54 GST_DEBUG_CATEGORY_STATIC (sparrow_debug);
55 #define GST_CAT_DEFAULT sparrow_debug
57 /* GstSparrow signals and args */
58 enum
60 /* FILL ME */
61 LAST_SIGNAL
64 enum
66 PROP_0,
67 PROP_CALIBRATE
68 /* FILL ME */
71 #define DEFAULT_PROP_CALIBRATE FALSE
73 /* the capabilities of the inputs and outputs.
75 * Use RGB, not YUV, because inverting video is trivial in RGB, not so in YUV
77 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
78 GST_PAD_SINK,
79 GST_PAD_ALWAYS,
80 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx ";"
81 GST_VIDEO_CAPS_xBGR "; " GST_VIDEO_CAPS_xRGB)
84 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
85 GST_PAD_SRC,
86 GST_PAD_ALWAYS,
87 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx ";"
88 GST_VIDEO_CAPS_xBGR "; " GST_VIDEO_CAPS_xRGB)
92 static void gst_sparrow_set_property (GObject * object, guint prop_id,
93 const GValue * value, GParamSpec * pspec);
94 static void gst_sparrow_get_property (GObject * object, guint prop_id,
95 GValue * value, GParamSpec * pspec);
97 static gboolean gst_sparrow_set_caps (GstBaseTransform * base, GstCaps * incaps,
98 GstCaps * outcaps);
99 static GstFlowReturn gst_sparrow_transform_ip (GstBaseTransform * transform,
100 GstBuffer * buf);
102 //static void gst_sparrow_RGB_ip (GstSparrow * sparrow, guint8 * data, gint size);
104 GST_BOILERPLATE (GstSparrow, gst_sparrow, GstVideoFilter, GST_TYPE_VIDEO_FILTER);
106 /* plugin_init - registers plugin (once)
107 XXX_base_init - for the gobject class (once)
108 XXX_class_init - for global state (once)
109 XXX_init - for each plugin instance
112 static void
113 gst_sparrow_base_init (gpointer g_class)
115 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
117 gst_element_class_set_details_simple (element_class, "Video sparrow correction",
118 "Filter/Effect/Video",
119 "Adds sparrows to a video stream",
120 "Douglas Bagnall <douglas@halo.gen.nz>");
122 gst_element_class_add_pad_template (element_class,
123 gst_static_pad_template_get (&sink_factory));
124 gst_element_class_add_pad_template (element_class,
125 gst_static_pad_template_get (&src_factory));
128 static void
129 gst_sparrow_class_init (GstSparrowClass * g_class)
131 GObjectClass *gobject_class;
132 GstBaseTransformClass *trans_class;
134 gobject_class = G_OBJECT_CLASS (g_class);
135 trans_class = GST_BASE_TRANSFORM_CLASS (g_class);
137 gobject_class->set_property = gst_sparrow_set_property;
138 gobject_class->get_property = gst_sparrow_get_property;
140 g_object_class_install_property (gobject_class, PROP_CALIBRATE,
141 g_param_spec_boolean ("calibrate", "Calibrate", "calibrate against projection",
142 DEFAULT_PROP_CALIBRATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
144 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_sparrow_set_caps);
145 trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_sparrow_transform_ip);
148 static void
149 gst_sparrow_init (GstSparrow * sparrow, GstSparrowClass * g_class)
151 GST_DEBUG_OBJECT (sparrow, "gst_sparrow_init");
154 static void
155 gst_sparrow_set_property (GObject * object, guint prop_id, const GValue * value,
156 GParamSpec * pspec)
158 GstSparrow *sparrow;
160 g_return_if_fail (GST_IS_SPARROW (object));
161 sparrow = GST_SPARROW (object);
163 GST_DEBUG ("gst_sparrow_set_property");
164 switch (prop_id) {
165 case PROP_CALIBRATE:
166 sparrow->calibrate = g_value_get_boolean (value);
167 g_print ("Calibrate argument was changed to %s\n",
168 sparrow->calibrate ? "true" : "false");
169 break;
170 default:
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172 break;
176 static void
177 gst_sparrow_get_property (GObject * object, guint prop_id, GValue * value,
178 GParamSpec * pspec)
180 GstSparrow *sparrow;
182 g_return_if_fail (GST_IS_SPARROW (object));
183 sparrow = GST_SPARROW (object);
185 switch (prop_id) {
186 case PROP_CALIBRATE:
187 g_value_set_boolean (value, sparrow->calibrate);
188 break;
189 default:
190 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
191 break;
195 static gboolean
196 gst_sparrow_set_caps (GstBaseTransform * base, GstCaps * incaps,
197 GstCaps * outcaps)
199 GstSparrow *this;
200 GstStructure *structure;
201 gboolean res;
203 this = GST_SPARROW (base);
205 GST_DEBUG_OBJECT (this,
206 "set_caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
208 structure = gst_caps_get_structure (incaps, 0);
210 res = gst_structure_get_int (structure, "width", &this->width);
211 res &= gst_structure_get_int (structure, "height", &this->height);
212 if (!res)
213 goto done;
215 this->size = this->width * this->height * 4;
217 done:
218 return res;
221 UNUSED
222 static void
223 simple_negation(guint8 * bytes, guint size){
224 guint i;
225 guint32 * data = (guint32 *)bytes;
226 //could use sse for superspeed
227 for (i = 0; i < size / 4; i++){
228 data[i] = ~data[i];
232 static void
233 gamma_negation(guint8 * bytes, guint size){
234 guint i;
235 //XXX could try oil_tablelookup_u8
236 for (i = 0; i < size; i++){
237 bytes[i] = sparrow_rgb_gamma_full_range_REVERSE[bytes[i]];
242 static GstFlowReturn
243 gst_sparrow_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
245 GstSparrow *sparrow;
246 guint8 *data;
247 guint size;
249 sparrow = GST_SPARROW (base);
251 if (base->passthrough)
252 goto done;
254 data = GST_BUFFER_DATA (outbuf);
255 size = GST_BUFFER_SIZE (outbuf);
257 if (size != sparrow->size)
258 goto wrong_size;
260 gamma_negation(data, size);
262 done:
263 return GST_FLOW_OK;
265 /* ERRORS */
266 wrong_size:
268 GST_ELEMENT_ERROR (sparrow, STREAM, FORMAT,
269 (NULL), ("Invalid buffer size %d, expected %d", size, sparrow->size));
270 return GST_FLOW_ERROR;
275 static gboolean
276 plugin_init (GstPlugin * plugin)
278 GST_DEBUG_CATEGORY_INIT (sparrow_debug, "sparrow", 0, "sparrow");
280 return gst_element_register (plugin, "sparrow", GST_RANK_NONE, GST_TYPE_SPARROW);
283 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
284 GST_VERSION_MINOR,
285 "sparrow",
286 "Changes sparrow on video images",
287 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);