1 /*
2 *
3 * GStreamer
4 * Copyright (c) 2000 Tom Barry All rights reserved.
5 * mmx.h port copyright (c) 2002 Billy Biggs <vektor@dumbterm.net>.
6 *
7 * Copyright (C) 2008,2010 Sebastian Dröge <slomo@collabora.co.uk>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 /*
26 * Relicensed for GStreamer from GPL to LGPL with permit from Tom Barry
27 * and Billy Biggs.
28 * See: http://bugzilla.gnome.org/show_bug.cgi?id=163578
29 */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include "gstdeinterlacemethod.h"
36 #include <string.h>
37 #include "tvtime.h"
38
39
40 #define GST_TYPE_DEINTERLACE_METHOD_GREEDY_L (gst_deinterlace_method_greedy_l_get_type ())
41 #define GST_IS_DEINTERLACE_METHOD_GREEDY_L(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_METHOD_GREEDY_L))
42 #define GST_IS_DEINTERLACE_METHOD_GREEDY_L_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_METHOD_GREEDY_L))
43 #define GST_DEINTERLACE_METHOD_GREEDY_L_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_METHOD_GREEDY_L, GstDeinterlaceMethodGreedyLClass))
44 #define GST_DEINTERLACE_METHOD_GREEDY_L(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_METHOD_GREEDY_L, GstDeinterlaceMethodGreedyL))
45 #define GST_DEINTERLACE_METHOD_GREEDY_L_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_METHOD_GREEDY_L, GstDeinterlaceMethodGreedyLClass))
46 #define GST_DEINTERLACE_METHOD_GREEDY_L_CAST(obj) ((GstDeinterlaceMethodGreedyL*)(obj))
47
48 GType gst_deinterlace_method_greedy_l_get_type (void);
49
50 typedef struct
51 {
52 GstDeinterlaceSimpleMethod parent;
53
54 guint max_comb;
55 } GstDeinterlaceMethodGreedyL;
56
57 typedef GstDeinterlaceSimpleMethodClass GstDeinterlaceMethodGreedyLClass;
58
59 // This is a simple lightweight DeInterlace method that uses little CPU time
60 // but gives very good results for low or intermedite motion.
61 // It defers frames by one field, but that does not seem to produce noticeable
62 // lip sync problems.
63 //
64 // The method used is to take either the older or newer weave pixel depending
65 // upon which give the smaller comb factor, and then clip to avoid large damage
66 // when wrong.
67 //
68 // I'd intended this to be part of a larger more elaborate method added to
69 // Blended Clip but this give too good results for the CPU to ignore here.
70
71 static inline void
deinterlace_greedy_interpolate_scanline_orc(GstDeinterlaceSimpleMethod * self,guint8 * out,const GstDeinterlaceScanlineData * scanlines,guint size)72 deinterlace_greedy_interpolate_scanline_orc (GstDeinterlaceSimpleMethod * self,
73 guint8 * out, const GstDeinterlaceScanlineData * scanlines, guint size)
74 {
75 guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
76
77 if (scanlines->m1 == NULL || scanlines->mp == NULL) {
78 deinterlace_line_linear (out, scanlines->t0, scanlines->b0, size);
79 } else {
80 deinterlace_line_greedy (out, scanlines->m1, scanlines->t0, scanlines->b0,
81 scanlines->mp ? scanlines->mp : scanlines->m1, max_comb, size);
82 }
83 }
84
85 static inline void
deinterlace_greedy_interpolate_scanline_orc_planar_u(GstDeinterlaceSimpleMethod * self,guint8 * out,const GstDeinterlaceScanlineData * scanlines,guint size)86 deinterlace_greedy_interpolate_scanline_orc_planar_u (GstDeinterlaceSimpleMethod
87 * self, guint8 * out, const GstDeinterlaceScanlineData * scanlines, guint
88 size)
89 {
90 guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
91
92 if (scanlines->m1 == NULL || scanlines->mp == NULL) {
93 deinterlace_line_linear (out, scanlines->t0, scanlines->b0, size);
94 } else {
95 deinterlace_line_greedy (out, scanlines->m1, scanlines->t0, scanlines->b0,
96 scanlines->mp ? scanlines->mp : scanlines->m1, max_comb, size);
97 }
98 }
99
100 static inline void
deinterlace_greedy_interpolate_scanline_orc_planar_v(GstDeinterlaceSimpleMethod * self,guint8 * out,const GstDeinterlaceScanlineData * scanlines,guint size)101 deinterlace_greedy_interpolate_scanline_orc_planar_v (GstDeinterlaceSimpleMethod
102 * self, guint8 * out, const GstDeinterlaceScanlineData * scanlines, guint
103 size)
104 {
105 guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
106
107 if (scanlines->m1 == NULL || scanlines->mp == NULL) {
108 deinterlace_line_linear (out, scanlines->t0, scanlines->b0, size);
109 } else {
110 deinterlace_line_greedy (out, scanlines->m1, scanlines->t0, scanlines->b0,
111 scanlines->mp ? scanlines->mp : scanlines->m1, max_comb, size);
112 }
113 }
114
115 static void
deinterlace_greedy_copy_scanline(GstDeinterlaceSimpleMethod * self,guint8 * out,const GstDeinterlaceScanlineData * scanlines,guint size)116 deinterlace_greedy_copy_scanline (GstDeinterlaceSimpleMethod * self,
117 guint8 * out, const GstDeinterlaceScanlineData * scanlines, guint size)
118 {
119 memcpy (out, scanlines->m0, size);
120 }
121
122 static void
deinterlace_greedy_copy_scanline_planar_u(GstDeinterlaceSimpleMethod * self,guint8 * out,const GstDeinterlaceScanlineData * scanlines,guint size)123 deinterlace_greedy_copy_scanline_planar_u (GstDeinterlaceSimpleMethod * self,
124 guint8 * out, const GstDeinterlaceScanlineData * scanlines, guint size)
125 {
126 memcpy (out, scanlines->m0, size);
127 }
128
129 static void
deinterlace_greedy_copy_scanline_planar_v(GstDeinterlaceSimpleMethod * self,guint8 * out,const GstDeinterlaceScanlineData * scanlines,guint size)130 deinterlace_greedy_copy_scanline_planar_v (GstDeinterlaceSimpleMethod * self,
131 guint8 * out, const GstDeinterlaceScanlineData * scanlines, guint size)
132 {
133 memcpy (out, scanlines->m0, size);
134 }
135
136 G_DEFINE_TYPE (GstDeinterlaceMethodGreedyL, gst_deinterlace_method_greedy_l,
137 GST_TYPE_DEINTERLACE_SIMPLE_METHOD);
138
139 enum
140 {
141 PROP_0,
142 PROP_MAX_COMB
143 };
144
145 static void
gst_deinterlace_method_greedy_l_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)146 gst_deinterlace_method_greedy_l_set_property (GObject * object, guint prop_id,
147 const GValue * value, GParamSpec * pspec)
148 {
149 GstDeinterlaceMethodGreedyL *self = GST_DEINTERLACE_METHOD_GREEDY_L (object);
150
151 switch (prop_id) {
152 case PROP_MAX_COMB:
153 self->max_comb = g_value_get_uint (value);
154 break;
155 default:
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
157 }
158 }
159
160 static void
gst_deinterlace_method_greedy_l_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)161 gst_deinterlace_method_greedy_l_get_property (GObject * object, guint prop_id,
162 GValue * value, GParamSpec * pspec)
163 {
164 GstDeinterlaceMethodGreedyL *self = GST_DEINTERLACE_METHOD_GREEDY_L (object);
165
166 switch (prop_id) {
167 case PROP_MAX_COMB:
168 g_value_set_uint (value, self->max_comb);
169 break;
170 default:
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172 }
173 }
174
175 static void
gst_deinterlace_method_greedy_l_class_init(GstDeinterlaceMethodGreedyLClass * klass)176 gst_deinterlace_method_greedy_l_class_init (GstDeinterlaceMethodGreedyLClass *
177 klass)
178 {
179 GstDeinterlaceMethodClass *dim_class = (GstDeinterlaceMethodClass *) klass;
180 GstDeinterlaceSimpleMethodClass *dism_class =
181 (GstDeinterlaceSimpleMethodClass *) klass;
182 GObjectClass *gobject_class = (GObjectClass *) klass;
183
184 gobject_class->set_property = gst_deinterlace_method_greedy_l_set_property;
185 gobject_class->get_property = gst_deinterlace_method_greedy_l_get_property;
186
187 g_object_class_install_property (gobject_class, PROP_MAX_COMB,
188 g_param_spec_uint ("max-comb",
189 "Max comb",
190 "Max Comb", 0, 255, 15, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
191 );
192
193 dim_class->fields_required = 2;
194 dim_class->name = "Motion Adaptive: Simple Detection";
195 dim_class->nick = "greedyl";
196 dim_class->latency = 1;
197
198 dism_class->interpolate_scanline_ayuv =
199 deinterlace_greedy_interpolate_scanline_orc;
200 dism_class->interpolate_scanline_yuy2 =
201 deinterlace_greedy_interpolate_scanline_orc;
202 dism_class->interpolate_scanline_yvyu =
203 deinterlace_greedy_interpolate_scanline_orc;
204 dism_class->interpolate_scanline_uyvy =
205 deinterlace_greedy_interpolate_scanline_orc;
206 dism_class->interpolate_scanline_nv12 =
207 deinterlace_greedy_interpolate_scanline_orc;
208 dism_class->interpolate_scanline_nv21 =
209 deinterlace_greedy_interpolate_scanline_orc;
210 dism_class->interpolate_scanline_argb =
211 deinterlace_greedy_interpolate_scanline_orc;
212 dism_class->interpolate_scanline_abgr =
213 deinterlace_greedy_interpolate_scanline_orc;
214 dism_class->interpolate_scanline_rgba =
215 deinterlace_greedy_interpolate_scanline_orc;
216 dism_class->interpolate_scanline_bgra =
217 deinterlace_greedy_interpolate_scanline_orc;
218 dism_class->interpolate_scanline_rgb =
219 deinterlace_greedy_interpolate_scanline_orc;
220 dism_class->interpolate_scanline_bgr =
221 deinterlace_greedy_interpolate_scanline_orc;
222 dism_class->interpolate_scanline_planar_y =
223 deinterlace_greedy_interpolate_scanline_orc;
224 dism_class->interpolate_scanline_planar_u =
225 deinterlace_greedy_interpolate_scanline_orc_planar_u;
226 dism_class->interpolate_scanline_planar_v =
227 deinterlace_greedy_interpolate_scanline_orc_planar_v;
228
229 dism_class->copy_scanline_ayuv = deinterlace_greedy_copy_scanline;
230 dism_class->copy_scanline_yuy2 = deinterlace_greedy_copy_scanline;
231 dism_class->copy_scanline_yvyu = deinterlace_greedy_copy_scanline;
232 dism_class->copy_scanline_uyvy = deinterlace_greedy_copy_scanline;
233 dism_class->copy_scanline_argb = deinterlace_greedy_copy_scanline;
234 dism_class->copy_scanline_abgr = deinterlace_greedy_copy_scanline;
235 dism_class->copy_scanline_rgba = deinterlace_greedy_copy_scanline;
236 dism_class->copy_scanline_bgra = deinterlace_greedy_copy_scanline;
237 dism_class->copy_scanline_rgb = deinterlace_greedy_copy_scanline;
238 dism_class->copy_scanline_bgr = deinterlace_greedy_copy_scanline;
239 dism_class->copy_scanline_planar_y = deinterlace_greedy_copy_scanline;
240 dism_class->copy_scanline_planar_u =
241 deinterlace_greedy_copy_scanline_planar_u;
242 dism_class->copy_scanline_planar_v =
243 deinterlace_greedy_copy_scanline_planar_v;
244 }
245
246 static void
gst_deinterlace_method_greedy_l_init(GstDeinterlaceMethodGreedyL * self)247 gst_deinterlace_method_greedy_l_init (GstDeinterlaceMethodGreedyL * self)
248 {
249 self->max_comb = 15;
250 }
251