upload tizen1.0 source
[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   /* FIXME - is this safe or just a hack? */
76   guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
77
78   deinterlace_line_greedy (out, scanlines->m3, scanlines->t2, scanlines->b2,
79       scanlines->m1, max_comb, self->parent.row_stride[0]);
80 }
81
82 static inline void
83 deinterlace_greedy_interpolate_scanline_orc_planar_u (GstDeinterlaceSimpleMethod
84     * self, guint8 * out, const GstDeinterlaceScanlineData * scanlines)
85 {
86   /* FIXME - is this safe or just a hack? */
87   guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
88
89   deinterlace_line_greedy (out, scanlines->m3, scanlines->t2, scanlines->b2,
90       scanlines->m1, max_comb, self->parent.row_stride[1]);
91 }
92
93 static inline void
94 deinterlace_greedy_interpolate_scanline_orc_planar_v (GstDeinterlaceSimpleMethod
95     * self, guint8 * out, const GstDeinterlaceScanlineData * scanlines)
96 {
97   /* FIXME - is this safe or just a hack? */
98   guint max_comb = GST_DEINTERLACE_METHOD_GREEDY_L (self)->max_comb;
99
100   deinterlace_line_greedy (out, scanlines->m3, scanlines->t2, scanlines->b2,
101       scanlines->m1, max_comb, self->parent.row_stride[2]);
102 }
103
104 static void
105 deinterlace_greedy_copy_scanline (GstDeinterlaceSimpleMethod * self,
106     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
107 {
108   memcpy (out, scanlines->m2, self->parent.row_stride[0]);
109 }
110
111 static void
112 deinterlace_greedy_copy_scanline_planar_u (GstDeinterlaceSimpleMethod * self,
113     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
114 {
115   memcpy (out, scanlines->m2, self->parent.row_stride[1]);
116 }
117
118 static void
119 deinterlace_greedy_copy_scanline_planar_v (GstDeinterlaceSimpleMethod * self,
120     guint8 * out, const GstDeinterlaceScanlineData * scanlines)
121 {
122   memcpy (out, scanlines->m2, self->parent.row_stride[2]);
123 }
124
125 G_DEFINE_TYPE (GstDeinterlaceMethodGreedyL, gst_deinterlace_method_greedy_l,
126     GST_TYPE_DEINTERLACE_SIMPLE_METHOD);
127
128 enum
129 {
130   PROP_0,
131   PROP_MAX_COMB
132 };
133
134 static void
135 gst_deinterlace_method_greedy_l_set_property (GObject * object, guint prop_id,
136     const GValue * value, GParamSpec * pspec)
137 {
138   GstDeinterlaceMethodGreedyL *self = GST_DEINTERLACE_METHOD_GREEDY_L (object);
139
140   switch (prop_id) {
141     case PROP_MAX_COMB:
142       self->max_comb = g_value_get_uint (value);
143       break;
144     default:
145       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146   }
147 }
148
149 static void
150 gst_deinterlace_method_greedy_l_get_property (GObject * object, guint prop_id,
151     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       g_value_set_uint (value, self->max_comb);
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_class_init (GstDeinterlaceMethodGreedyLClass *
166     klass)
167 {
168   GstDeinterlaceMethodClass *dim_class = (GstDeinterlaceMethodClass *) klass;
169   GstDeinterlaceSimpleMethodClass *dism_class =
170       (GstDeinterlaceSimpleMethodClass *) klass;
171   GObjectClass *gobject_class = (GObjectClass *) klass;
172
173   gobject_class->set_property = gst_deinterlace_method_greedy_l_set_property;
174   gobject_class->get_property = gst_deinterlace_method_greedy_l_get_property;
175
176   g_object_class_install_property (gobject_class, PROP_MAX_COMB,
177       g_param_spec_uint ("max-comb",
178           "Max comb",
179           "Max Comb", 0, 255, 15, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
180       );
181
182   dim_class->fields_required = 4;
183   dim_class->name = "Motion Adaptive: Simple Detection";
184   dim_class->nick = "greedyl";
185   dim_class->latency = 1;
186
187   dism_class->interpolate_scanline_ayuv =
188       deinterlace_greedy_interpolate_scanline_orc;
189   dism_class->interpolate_scanline_yuy2 =
190       deinterlace_greedy_interpolate_scanline_orc;
191   dism_class->interpolate_scanline_yvyu =
192       deinterlace_greedy_interpolate_scanline_orc;
193   dism_class->interpolate_scanline_uyvy =
194       deinterlace_greedy_interpolate_scanline_orc;
195   dism_class->interpolate_scanline_argb =
196       deinterlace_greedy_interpolate_scanline_orc;
197   dism_class->interpolate_scanline_abgr =
198       deinterlace_greedy_interpolate_scanline_orc;
199   dism_class->interpolate_scanline_rgba =
200       deinterlace_greedy_interpolate_scanline_orc;
201   dism_class->interpolate_scanline_bgra =
202       deinterlace_greedy_interpolate_scanline_orc;
203   dism_class->interpolate_scanline_rgb =
204       deinterlace_greedy_interpolate_scanline_orc;
205   dism_class->interpolate_scanline_bgr =
206       deinterlace_greedy_interpolate_scanline_orc;
207   dism_class->interpolate_scanline_planar_y =
208       deinterlace_greedy_interpolate_scanline_orc;
209   dism_class->interpolate_scanline_planar_u =
210       deinterlace_greedy_interpolate_scanline_orc_planar_u;
211   dism_class->interpolate_scanline_planar_v =
212       deinterlace_greedy_interpolate_scanline_orc_planar_v;
213
214   dism_class->copy_scanline_ayuv = deinterlace_greedy_copy_scanline;
215   dism_class->copy_scanline_yuy2 = deinterlace_greedy_copy_scanline;
216   dism_class->copy_scanline_yvyu = deinterlace_greedy_copy_scanline;
217   dism_class->copy_scanline_uyvy = deinterlace_greedy_copy_scanline;
218   dism_class->copy_scanline_argb = deinterlace_greedy_copy_scanline;
219   dism_class->copy_scanline_abgr = deinterlace_greedy_copy_scanline;
220   dism_class->copy_scanline_rgba = deinterlace_greedy_copy_scanline;
221   dism_class->copy_scanline_bgra = deinterlace_greedy_copy_scanline;
222   dism_class->copy_scanline_rgb = deinterlace_greedy_copy_scanline;
223   dism_class->copy_scanline_bgr = deinterlace_greedy_copy_scanline;
224   dism_class->copy_scanline_planar_y = deinterlace_greedy_copy_scanline;
225   dism_class->copy_scanline_planar_u =
226       deinterlace_greedy_copy_scanline_planar_u;
227   dism_class->copy_scanline_planar_v =
228       deinterlace_greedy_copy_scanline_planar_v;
229 }
230
231 static void
232 gst_deinterlace_method_greedy_l_init (GstDeinterlaceMethodGreedyL * self)
233 {
234   self->max_comb = 15;
235 }