~oah-dev/oah/gst-plugins-bad

« back to all changes in this revision

Viewing changes to gst/deinterlace2/tvtime/vfir.c

  • Committer: Haakon Sporsheim
  • Date: 2009-03-12 13:52:03 UTC
  • Revision ID: haakon.sporsheim@tandberg.com-20090312135203-i5k294hgkushb0mt
Initial import of git repository: git://anongit.freedesktop.org/gstreamer/gst-plugins-bad (tag: RELEASE-0_10_10)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * GStreamer
 
4
 * Copyright (C) 2004 Billy Biggs <vektor@dumbterm.net>
 
5
 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
 
6
 * Copyright (C) 2008 Sebastian Dröge <slomo@collabora.co.uk>
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Library General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Library General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Library General Public
 
19
 * License along with this library; if not, write to the
 
20
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
21
 * Boston, MA 02111-1307, USA.
 
22
 */
 
23
 
 
24
/*
 
25
 * This file contains code from ffmpeg, see http://ffmpeg.org/ (LGPL)
 
26
 * and modifications by Billy Biggs.
 
27
 *
 
28
 * Relicensed for GStreamer from GPL to LGPL with permit from Billy Biggs.
 
29
 * See: http://bugzilla.gnome.org/show_bug.cgi?id=163578
 
30
 */
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
# include "config.h"
 
34
#endif
 
35
 
 
36
#include "_stdint.h"
 
37
#include "gstdeinterlace2.h"
 
38
#include <string.h>
 
39
 
 
40
#define GST_TYPE_DEINTERLACE_METHOD_VFIR        (gst_deinterlace_method_vfir_get_type ())
 
41
#define GST_IS_DEINTERLACE_METHOD_VFIR(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_METHOD_VFIR))
 
42
#define GST_IS_DEINTERLACE_METHOD_VFIR_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_METHOD_VFIR))
 
43
#define GST_DEINTERLACE_METHOD_VFIR_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_METHOD_VFIR, GstDeinterlaceMethodVFIRClass))
 
44
#define GST_DEINTERLACE_METHOD_VFIR(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_METHOD_VFIR, GstDeinterlaceMethodVFIR))
 
45
#define GST_DEINTERLACE_METHOD_VFIR_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_METHOD_VFIR, GstDeinterlaceMethodVFIRClass))
 
46
#define GST_DEINTERLACE_METHOD_VFIR_CAST(obj)   ((GstDeinterlaceMethodVFIR*)(obj))
 
47
 
 
48
GType gst_deinterlace_method_vfir_get_type (void);
 
49
 
 
50
typedef GstDeinterlaceSimpleMethod GstDeinterlaceMethodVFIR;
 
51
 
 
52
typedef GstDeinterlaceSimpleMethodClass GstDeinterlaceMethodVFIRClass;
 
53
 
 
54
/*
 
55
 * The MPEG2 spec uses a slightly harsher filter, they specify
 
56
 * [-1 8 2 8 -1].  ffmpeg uses a similar filter but with more of
 
57
 * a tendancy to blur than to use the local information.  The
 
58
 * filter taps here are: [-1 4 2 4 -1].
 
59
 */
 
60
 
 
61
/**
 
62
  * C implementation.
 
63
  */
 
64
static inline void
 
65
deinterlace_line_c (GstDeinterlaceMethod * self, GstDeinterlace2 * parent,
 
66
    guint8 * dst, GstDeinterlaceScanlineData * scanlines, gint width)
 
67
{
 
68
  gint sum;
 
69
  guint8 *lum_m4 = scanlines->tt1;
 
70
  guint8 *lum_m3 = scanlines->t0;
 
71
  guint8 *lum_m2 = scanlines->m1;
 
72
  guint8 *lum_m1 = scanlines->b0;
 
73
  guint8 *lum = scanlines->bb1;
 
74
  gint size = width * 2;
 
75
 
 
76
  for (; size >= 0; size--) {
 
77
    sum = -lum_m4[0];
 
78
    sum += lum_m3[0] << 2;
 
79
    sum += lum_m2[0] << 1;
 
80
    sum += lum_m1[0] << 2;
 
81
    sum += -lum[0];
 
82
    dst[0] = (sum + 4) >> 3;    // This needs to be clipped at 0 and 255: cm[(sum + 4) >> 3];
 
83
    lum_m4++;
 
84
    lum_m3++;
 
85
    lum_m2++;
 
86
    lum_m1++;
 
87
    lum++;
 
88
    dst++;
 
89
  }
 
90
}
 
91
 
 
92
#ifdef BUILD_X86_ASM
 
93
#include "mmx.h"
 
94
static void
 
95
deinterlace_line_mmx (GstDeinterlaceMethod * self, GstDeinterlace2 * parent,
 
96
    guint8 * dst, GstDeinterlaceScanlineData * scanlines, gint width)
 
97
{
 
98
  mmx_t rounder;
 
99
  guint8 *lum_m4 = scanlines->tt1;
 
100
  guint8 *lum_m3 = scanlines->t0;
 
101
  guint8 *lum_m2 = scanlines->m1;
 
102
  guint8 *lum_m1 = scanlines->b0;
 
103
  guint8 *lum = scanlines->bb1;
 
104
 
 
105
  rounder.uw[0] = 4;
 
106
  rounder.uw[1] = 4;
 
107
  rounder.uw[2] = 4;
 
108
  rounder.uw[3] = 4;
 
109
  pxor_r2r (mm7, mm7);
 
110
  movq_m2r (rounder, mm6);
 
111
 
 
112
  for (; width > 1; width -= 2) {
 
113
    movd_m2r (*lum_m4, mm0);
 
114
    movd_m2r (*lum_m3, mm1);
 
115
    movd_m2r (*lum_m2, mm2);
 
116
    movd_m2r (*lum_m1, mm3);
 
117
    movd_m2r (*lum, mm4);
 
118
    punpcklbw_r2r (mm7, mm0);
 
119
    punpcklbw_r2r (mm7, mm1);
 
120
    punpcklbw_r2r (mm7, mm2);
 
121
    punpcklbw_r2r (mm7, mm3);
 
122
    punpcklbw_r2r (mm7, mm4);
 
123
    paddw_r2r (mm3, mm1);
 
124
    psllw_i2r (1, mm2);
 
125
    paddw_r2r (mm4, mm0);
 
126
    psllw_i2r (2, mm1);         // 2
 
127
    paddw_r2r (mm6, mm2);
 
128
    paddw_r2r (mm2, mm1);
 
129
    psubusw_r2r (mm0, mm1);
 
130
    psrlw_i2r (3, mm1);         // 3
 
131
    packuswb_r2r (mm7, mm1);
 
132
    movd_r2m (mm1, *dst);
 
133
    lum_m4 += 4;
 
134
    lum_m3 += 4;
 
135
    lum_m2 += 4;
 
136
    lum_m1 += 4;
 
137
    lum += 4;
 
138
    dst += 4;
 
139
  }
 
140
  emms ();
 
141
 
 
142
  /* Handle odd widths */
 
143
  if (width > 0) {
 
144
    scanlines->tt1 = lum_m4;
 
145
    scanlines->t0 = lum_m3;
 
146
    scanlines->m1 = lum_m2;
 
147
    scanlines->b0 = lum_m1;
 
148
    scanlines->bb1 = lum;
 
149
 
 
150
    deinterlace_line_c (self, parent, dst, scanlines, width);
 
151
  }
 
152
}
 
153
#endif
 
154
 
 
155
G_DEFINE_TYPE (GstDeinterlaceMethodVFIR, gst_deinterlace_method_vfir,
 
156
    GST_TYPE_DEINTERLACE_SIMPLE_METHOD);
 
157
 
 
158
static void
 
159
gst_deinterlace_method_vfir_class_init (GstDeinterlaceMethodVFIRClass * klass)
 
160
{
 
161
  GstDeinterlaceMethodClass *dim_class = (GstDeinterlaceMethodClass *) klass;
 
162
  GstDeinterlaceSimpleMethodClass *dism_class =
 
163
      (GstDeinterlaceSimpleMethodClass *) klass;
 
164
#ifdef BUILD_X86_ASM
 
165
  guint cpu_flags = oil_cpu_get_flags ();
 
166
#endif
 
167
 
 
168
  dim_class->fields_required = 2;
 
169
  dim_class->name = "Blur Vertical";
 
170
  dim_class->nick = "vfir";
 
171
  dim_class->latency = 0;
 
172
 
 
173
#ifdef BUILD_X86_ASM
 
174
  if (cpu_flags & OIL_IMPL_FLAG_MMX) {
 
175
    dism_class->interpolate_scanline = deinterlace_line_mmx;
 
176
  } else {
 
177
    dism_class->interpolate_scanline = deinterlace_line_c;
 
178
  }
 
179
#else
 
180
  dism_class->interpolate_scanline = deinterlace_line_c;
 
181
#endif
 
182
}
 
183
 
 
184
static void
 
185
gst_deinterlace_method_vfir_init (GstDeinterlaceMethodVFIR * self)
 
186
{
 
187
}