Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / gst / deinterlace / tvtime / greedy.c
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., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, 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
72 deinterlace_greedy_interpolate_scanline_orc (GstDeinterlaceSimpleMethod * self,
73     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
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,
79         self->parent.row_stride[0]);
80   } else {
81     deinterlace_line_greedy (out, scanlines->m1, scanlines->t0, scanlines->b0,
82         scanlines->mp ? scanlines->mp : scanlines->m1,
83         max_comb, self->parent.row_stride[0]);
84   }
85 }
86
87 static inline void
88 deinterlace_greedy_interpolate_scanline_orc_planar_u (GstDeinterlaceSimpleMethod
89     * self, guint8 * out, const GstDeinterlaceScanlineData * scanlines)
90 {
91   guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
92
93   if (scanlines->m1 == NULL || scanlines->mp == NULL) {
94     deinterlace_line_linear (out, scanlines->t0, scanlines->b0,
95         self->parent.row_stride[1]);
96   } else {
97     deinterlace_line_greedy (out, scanlines->m1, scanlines->t0, scanlines->b0,
98         scanlines->mp ? scanlines->mp : scanlines->m1,
99         max_comb, self->parent.row_stride[1]);
100   }
101 }
102
103 static inline void
104 deinterlace_greedy_interpolate_scanline_orc_planar_v (GstDeinterlaceSimpleMethod
105     * self, guint8 * out, const GstDeinterlaceScanlineData * scanlines)
106 {
107   guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
108
109   if (scanlines->m1 == NULL || scanlines->mp == NULL) {
110     deinterlace_line_linear (out, scanlines->t0, scanlines->b0,
111         self->parent.row_stride[2]);
112   } else {
113     deinterlace_line_greedy (out, scanlines->m1, scanlines->t0, scanlines->b0,
114         scanlines->mp ? scanlines->mp : scanlines->m1,
115         max_comb, self->parent.row_stride[2]);
116   }
117 }
118
119 static void
120 deinterlace_greedy_copy_scanline (GstDeinterlaceSimpleMethod * self,
121     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
122 {
123   memcpy (out, scanlines->m0, self->parent.row_stride[0]);
124 }
125
126 static void
127 deinterlace_greedy_copy_scanline_planar_u (GstDeinterlaceSimpleMethod * self,
128     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
129 {
130   memcpy (out, scanlines->m0, self->parent.row_stride[1]);
131 }
132
133 static void
134 deinterlace_greedy_copy_scanline_planar_v (GstDeinterlaceSimpleMethod * self,
135     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
136 {
137   memcpy (out, scanlines->m0, self->parent.row_stride[2]);
138 }
139
140 G_DEFINE_TYPE (GstDeinterlaceMethodGreedyL, gst_deinterlace_method_greedy_l,
141     GST_TYPE_DEINTERLACE_SIMPLE_METHOD);
142
143 enum
144 {
145   PROP_0,
146   PROP_MAX_COMB
147 };
148
149 static void
150 gst_deinterlace_method_greedy_l_set_property (GObject * object, guint prop_id,
151     const GValue * value, GParamSpec * pspec)
152 {
153   GstDeinterlaceMethodGreedyL *self = GST_DEINTERLACE_METHOD_GREEDY_L (object);
154
155   switch (prop_id) {
156     case PROP_MAX_COMB:
157       self->max_comb = g_value_get_uint (value);
158       break;
159     default:
160       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
161   }
162 }
163
164 static void
165 gst_deinterlace_method_greedy_l_get_property (GObject * object, guint prop_id,
166     GValue * value, GParamSpec * pspec)
167 {
168   GstDeinterlaceMethodGreedyL *self = GST_DEINTERLACE_METHOD_GREEDY_L (object);
169
170   switch (prop_id) {
171     case PROP_MAX_COMB:
172       g_value_set_uint (value, self->max_comb);
173       break;
174     default:
175       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
176   }
177 }
178
179 static void
180 gst_deinterlace_method_greedy_l_class_init (GstDeinterlaceMethodGreedyLClass *
181     klass)
182 {
183   GstDeinterlaceMethodClass *dim_class = (GstDeinterlaceMethodClass *) klass;
184   GstDeinterlaceSimpleMethodClass *dism_class =
185       (GstDeinterlaceSimpleMethodClass *) klass;
186   GObjectClass *gobject_class = (GObjectClass *) klass;
187
188   gobject_class->set_property = gst_deinterlace_method_greedy_l_set_property;
189   gobject_class->get_property = gst_deinterlace_method_greedy_l_get_property;
190
191   g_object_class_install_property (gobject_class, PROP_MAX_COMB,
192       g_param_spec_uint ("max-comb",
193           "Max comb",
194           "Max Comb", 0, 255, 15, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
195       );
196
197   dim_class->fields_required = 2;
198   dim_class->name = "Motion Adaptive: Simple Detection";
199   dim_class->nick = "greedyl";
200   dim_class->latency = 1;
201
202   dism_class->interpolate_scanline_ayuv =
203       deinterlace_greedy_interpolate_scanline_orc;
204   dism_class->interpolate_scanline_yuy2 =
205       deinterlace_greedy_interpolate_scanline_orc;
206   dism_class->interpolate_scanline_yvyu =
207       deinterlace_greedy_interpolate_scanline_orc;
208   dism_class->interpolate_scanline_uyvy =
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
247 gst_deinterlace_method_greedy_l_init (GstDeinterlaceMethodGreedyL * self)
248 {
249   self->max_comb = 15;
250 }