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.
24 * SECTION:element-sparrow
26 * Performs sparrow correction on a video stream.
29 * <title>Example launch line</title>
31 * gst-launch videotestsrc ! ffmpegcolorspace ! sparrow ! ximagesink
36 #include "gstsparrow.h"
37 #include <gst/video/gstvideofilter.h>
38 #include <gst/video/video.h>
40 #include "sparrow_gamma_lut.h"
44 #include <liboil/liboil.h>
45 #include <liboil/liboilcpu.h>
46 #include <liboil/liboilfunction.h>
54 GST_DEBUG_CATEGORY_STATIC (sparrow_debug
);
55 #define GST_CAT_DEFAULT sparrow_debug
57 /* GstSparrow signals and args */
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",
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",
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
,
99 static GstFlowReturn
gst_sparrow_transform_ip (GstBaseTransform
* transform
,
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
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
));
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
);
149 gst_sparrow_init (GstSparrow
* sparrow
, GstSparrowClass
* g_class
)
151 GST_DEBUG_OBJECT (sparrow
, "gst_sparrow_init");
155 gst_sparrow_set_property (GObject
* object
, guint prop_id
, const GValue
* value
,
160 g_return_if_fail (GST_IS_SPARROW (object
));
161 sparrow
= GST_SPARROW (object
);
163 GST_DEBUG ("gst_sparrow_set_property");
166 sparrow
->calibrate
= g_value_get_boolean (value
);
167 g_print ("Calibrate argument was changed to %s\n",
168 sparrow
->calibrate
? "true" : "false");
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
177 gst_sparrow_get_property (GObject
* object
, guint prop_id
, GValue
* value
,
182 g_return_if_fail (GST_IS_SPARROW (object
));
183 sparrow
= GST_SPARROW (object
);
187 g_value_set_boolean (value
, sparrow
->calibrate
);
190 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
196 gst_sparrow_set_caps (GstBaseTransform
* base
, GstCaps
* incaps
,
200 GstStructure
*structure
;
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
);
215 this->size
= this->width
* this->height
* 4;
223 simple_negation(guint8
* bytes
, guint size
){
225 guint32
* data
= (guint32
*)bytes
;
226 //could use sse for superspeed
227 for (i
= 0; i
< size
/ 4; i
++){
233 gamma_negation(guint8
* bytes
, guint size
){
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
]];
243 gst_sparrow_transform_ip (GstBaseTransform
* base
, GstBuffer
* outbuf
)
249 sparrow
= GST_SPARROW (base
);
251 if (base
->passthrough
)
254 data
= GST_BUFFER_DATA (outbuf
);
255 size
= GST_BUFFER_SIZE (outbuf
);
257 if (size
!= sparrow
->size
)
260 gamma_negation(data
, size
);
268 GST_ELEMENT_ERROR (sparrow
, STREAM
, FORMAT
,
269 (NULL
), ("Invalid buffer size %d, expected %d", size
, sparrow
->size
));
270 return GST_FLOW_ERROR
;
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
,
286 "Changes sparrow on video images",
287 plugin_init
, VERSION
, GST_LICENSE
, GST_PACKAGE_NAME
, GST_PACKAGE_ORIGIN
);