upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / gst / deinterlace / tvtime / tomsmocomp / TomsMoCompAll.inc
1 /*
2  * GStreamer
3  * Copyright (c) 2002 Tom Barry  All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Relicensed for GStreamer from GPL to LGPL with permit from Tom Barry.
23  * See: http://bugzilla.gnome.org/show_bug.cgi?id=163578
24  */
25
26
27 #ifndef TopFirst
28 #define TopFirst IsOdd
29 #endif
30
31 #ifdef SEFUNC
32 #undef SEFUNC
33 #endif
34
35 #if defined(IS_MMXEXT)
36 #define SEFUNC(x) Search_Effort_MMXEXT_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
37 #elif defined(IS_3DNOW)
38 #define SEFUNC(x) Search_Effort_3DNOW_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
39 #elif defined(IS_MMX)
40 #define SEFUNC(x) Search_Effort_MMX_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
41 #else
42 #define SEFUNC(x) Search_Effort_C_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
43 #endif
44
45 #include "TomsMoCompAll2.inc"
46
47 #define USE_STRANGE_BOB
48
49 #include "TomsMoCompAll2.inc"
50
51 #undef USE_STRANGE_BOB
52
53 #undef SEFUNC
54 #if defined(IS_MMXEXT)
55 #define SEFUNC(x) Search_Effort_MMXEXT_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
56 #elif defined(IS_3DNOW)
57 #define SEFUNC(x) Search_Effort_3DNOW_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
58 #elif defined(IS_MMX)
59 #define SEFUNC(x) Search_Effort_MMX_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
60 #else
61 #define SEFUNC(x) Search_Effort_C_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
62 #endif
63
64 static void FUNCT_NAME(GstDeinterlaceMethod *d_method, const GstDeinterlaceField* history, guint history_count, GstBuffer *outbuf)
65 {
66   GstDeinterlaceMethodTomsMoComp *self = GST_DEINTERLACE_METHOD_TOMSMOCOMP (d_method);
67   glong SearchEffort = self->search_effort;
68   gint UseStrangeBob = self->strange_bob;
69   gint IsOdd;
70   const guint8 *pWeaveSrc;
71   const guint8 *pWeaveSrcP;
72   guint8 *pWeaveDest;
73   const guint8 *pCopySrc;
74   const guint8 *pCopySrcP;
75   guint8 *pCopyDest;
76   gint src_pitch;
77   gint dst_pitch;
78   gint rowsize;
79   gint FldHeight;
80
81   /* double stride do address just every odd/even scanline */
82   src_pitch = self->parent.row_stride[0]*2;
83   dst_pitch = self->parent.row_stride[0];
84   rowsize   = self->parent.row_stride[0];
85   FldHeight = self->parent.frame_height / 2;
86
87   pCopySrc   = GST_BUFFER_DATA(history[history_count-1].buf);
88   if (history[history_count - 1].flags & PICTURE_INTERLACED_BOTTOM)
89     pCopySrc += rowsize;
90   pCopySrcP  = GST_BUFFER_DATA(history[history_count-3].buf);
91   if (history[history_count - 3].flags & PICTURE_INTERLACED_BOTTOM)
92     pCopySrcP += rowsize;
93   pWeaveSrc  = GST_BUFFER_DATA(history[history_count-2].buf);  
94   if (history[history_count - 2].flags & PICTURE_INTERLACED_BOTTOM)
95     pWeaveSrc += rowsize;
96   pWeaveSrcP = GST_BUFFER_DATA(history[history_count-4].buf);
97   if (history[history_count - 4].flags & PICTURE_INTERLACED_BOTTOM)
98     pWeaveSrcP += rowsize;
99
100   /* use bottom field and interlace top field */
101   if (history[history_count-2].flags == PICTURE_INTERLACED_BOTTOM) {
102     IsOdd      = 1;
103
104     // if we have an odd field we copy an even field and weave an odd field
105     pCopyDest = GST_BUFFER_DATA(outbuf);
106     pWeaveDest = pCopyDest + dst_pitch;
107   }
108   /* do it vice verca */
109   else {
110
111     IsOdd      = 0;
112     // if we have an even field we copy an odd field and weave an even field
113     pCopyDest = GST_BUFFER_DATA(outbuf) + dst_pitch;
114     pWeaveDest = GST_BUFFER_DATA(outbuf);
115   }
116
117   
118   // copy 1st and last weave lines 
119   Fieldcopy(pWeaveDest, pCopySrc, rowsize,              
120             1, dst_pitch*2, src_pitch);
121   Fieldcopy(pWeaveDest+(FldHeight-1)*dst_pitch*2,
122             pCopySrc+(FldHeight-1)*src_pitch, rowsize, 
123             1, dst_pitch*2, src_pitch);
124   
125 #ifdef USE_VERTICAL_FILTER
126   // Vertical Filter currently not implemented for DScaler !!
127   // copy 1st and last lines the copy field
128   Fieldcopy(pCopyDest, pCopySrc, rowsize, 
129             1, dst_pitch*2, src_pitch);
130   Fieldcopy(pCopyDest+(FldHeight-1)*dst_pitch*2,
131             pCopySrc+(FldHeight-1)*src_pitch, rowsize, 
132             1, dst_pitch*2, src_pitch);
133 #else
134   
135   // copy all of the copy field
136   Fieldcopy(pCopyDest, pCopySrc, rowsize, 
137             FldHeight, dst_pitch*2, src_pitch);
138 #endif  
139   // then go fill in the hard part, being variously lazy depending upon
140   // SearchEffort
141
142   if(!UseStrangeBob) {
143     if (SearchEffort == 0)
144       {
145         SEFUNC(0);
146       }
147     else if (SearchEffort <= 1)
148       {
149         SEFUNC(1);
150       }
151     /*  else if (SearchEffort <= 2)
152         {
153         SEFUNC(2);
154         }
155     */
156     else if (SearchEffort <= 3)
157       {
158         SEFUNC(3);
159       }
160     else if (SearchEffort <= 5)
161       {
162         SEFUNC(5);
163       }
164     else if (SearchEffort <= 9)
165       {
166         SEFUNC(9);
167       }
168     else if (SearchEffort <= 11)
169       {
170         SEFUNC(11);
171       }
172     else if (SearchEffort <= 13)
173       {
174         SEFUNC(13);
175       }
176     else if (SearchEffort <= 15)
177       {
178         SEFUNC(15);
179       }
180     else if (SearchEffort <= 19)
181       {
182         SEFUNC(19);
183       }
184     else if (SearchEffort <= 21)
185       {
186         SEFUNC(21);
187       }
188     else 
189       {
190         SEFUNC(Max);
191       }
192   }
193   else
194     {
195       if (SearchEffort == 0)
196         {
197           SEFUNC(0SB);
198         }
199       else if (SearchEffort <= 1)
200         {
201           SEFUNC(1SB);
202         }
203       /*        else if (SearchEffort <= 2)
204                 {
205                 SEFUNC(2SB);
206                 }
207       */
208       else if (SearchEffort <= 3)
209         {
210           SEFUNC(3SB);
211         }
212       else if (SearchEffort <= 5)
213         {
214           SEFUNC(5SB);
215         }
216       else if (SearchEffort <= 9)
217         {
218           SEFUNC(9SB);
219         }
220       else if (SearchEffort <= 11)
221         {
222           SEFUNC(11SB);
223         }
224       else if (SearchEffort <= 13)
225         {
226           SEFUNC(13SB);
227         }
228       else if (SearchEffort <= 15)
229         {
230           SEFUNC(15SB);
231         }
232       else if (SearchEffort <= 19)
233         {
234           SEFUNC(19SB);
235         }
236       else if (SearchEffort <= 21)
237         {
238           SEFUNC(21SB);
239         }
240       else 
241         {
242           SEFUNC(MaxSB);
243         }
244     }
245
246 #if defined(BUILD_X86_ASM) && !defined(IS_C)
247   __asm__ __volatile__("emms");
248 #endif
249 }