~ubuntu-branches/ubuntu/maverick/zapping/maverick

« back to all changes in this revision

Viewing changes to plugins/deinterlace/DI_Misc/DI_Greedy2Frame.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-08 11:07:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051108110734-ygvf6uljvgcjmca7
Tags: 0.9.6-1ubuntu1
* Resynchronise with Debian (Closes: #4022):
  - Fix desktop file to not use absolute path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
///////////////////////////////////////////////////////////////////////////////
2
 
// $Id: DI_Greedy2Frame.c,v 1.2 2005/02/05 22:19:53 mschimek Exp $
 
1
/*////////////////////////////////////////////////////////////////////////////
 
2
// $Id: DI_Greedy2Frame.c,v 1.5 2005/06/28 19:17:10 mschimek Exp $
3
3
/////////////////////////////////////////////////////////////////////////////
4
4
// Copyright (c) 2000 John Adcock, Tom Barry, Steve Grimm  All rights reserved.
5
5
/////////////////////////////////////////////////////////////////////////////
25
25
// CVS Log
26
26
//
27
27
// $Log: DI_Greedy2Frame.c,v $
 
28
// Revision 1.5  2005/06/28 19:17:10  mschimek
 
29
// *** empty log message ***
 
30
//
 
31
// Revision 1.4  2005/06/28 00:50:03  mschimek
 
32
// Cleaned up.
 
33
// Upper limit of GreedyTwoFrameThreshold is 127, not 128.
 
34
//
 
35
// Revision 1.3.2.5  2005/06/17 02:54:20  mschimek
 
36
// *** empty log message ***
 
37
//
 
38
// Revision 1.3.2.4  2005/05/31 02:40:34  mschimek
 
39
// *** empty log message ***
 
40
//
 
41
// Revision 1.3.2.3  2005/05/20 05:45:14  mschimek
 
42
// *** empty log message ***
 
43
//
 
44
// Revision 1.3.2.2  2005/05/17 19:58:32  mschimek
 
45
// *** empty log message ***
 
46
//
 
47
// Revision 1.3.2.1  2005/05/05 09:46:01  mschimek
 
48
// *** empty log message ***
 
49
//
 
50
// Revision 1.3  2005/03/30 21:27:32  mschimek
 
51
// Integrated and converted the MMX code to vector intrinsics.
 
52
//
28
53
// Revision 1.2  2005/02/05 22:19:53  mschimek
29
54
// Completed l18n.
30
55
//
48
73
// Revision 1.6  2001/07/13 16:13:33  adcockj
49
74
// Added CVS tags and removed tabs
50
75
//
51
 
/////////////////////////////////////////////////////////////////////////////
 
76
///////////////////////////////////////////////////////////////////////////*/
52
77
 
53
78
#include "windows.h"
54
79
#include "DS_Deinterlace.h"
55
 
//Z #include "..\help\helpids.h"
56
 
 
57
 
long GreedyTwoFrameThreshold = 4;
58
 
long GreedyTwoFrameThreshold2 = 8;
59
 
 
60
 
#define IS_SSE 1
61
 
#include "DI_Greedy2Frame.asm"
62
 
#undef IS_SSE
63
 
 
64
 
#define IS_3DNOW 1
65
 
#include "DI_Greedy2Frame.asm"
66
 
#undef IS_3DNOW
67
 
 
68
 
#define IS_MMX 1
69
 
#include "DI_Greedy2Frame.asm"
70
 
#undef IS_MMX
71
 
 
72
 
////////////////////////////////////////////////////////////////////////////
 
80
 
 
81
extern int GreedyTwoFrameThreshold;
 
82
 
 
83
SIMD_FN_PROTOS (DEINTERLACE_FUNC, DeinterlaceGreedy2Frame);
 
84
 
 
85
#if SIMD & (CPU_FEATURE_MMX | CPU_FEATURE_3DNOW |                       \
 
86
            CPU_FEATURE_SSE | CPU_FEATURE_SSE2 | CPU_FEATURE_ALTIVEC)
 
87
 
 
88
/*/////////////////////////////////////////////////////////////////////////////
 
89
// Field 1 | Field 2 | Field 3 | Field 4 |
 
90
//   T0    |         |    T1   |         | 
 
91
//         |   M0    |         |    M1   | 
 
92
//   B0    |         |    B1   |         | 
 
93
*/
 
94
 
 
95
/* debugging feature
 
96
   output the value of mm4 at this point which is pink where we will weave
 
97
   and green were we are going to bob */
 
98
#define CHECK_BOBWEAVE 0
 
99
 
 
100
static always_inline v32
 
101
thresh_cmp                      (vu8                    a,
 
102
                                 vu8                    b,
 
103
                                 v8                     thresh,
 
104
                                 v32                    c)
 
105
{
 
106
    vu8 t;
 
107
 
 
108
    // XXX emulates vcmpgtu8, AVEC has this instruction
 
109
    t = vsr1u8 (vabsdiffu8 (a, b));
 
110
    t = (vu8) vcmpgt8 ((v8) t, thresh);
 
111
 
 
112
    t = vand (t, vsplatu8_127); // get rid of any sign bit
 
113
 
 
114
    // XXX can be replaced by logic ops.
 
115
    return vand ((v32) vcmpgt32 ((v32) t, vsplat32_1), c);
 
116
}
 
117
 
 
118
BOOL
 
119
SIMD_NAME (DeinterlaceGreedy2Frame) (TDeinterlaceInfo *pInfo)
 
120
{
 
121
    v8 qwGreedyTwoFrameThreshold;
 
122
    uint8_t *Dest;
 
123
    const uint8_t *T0;
 
124
    const uint8_t *T1;
 
125
    const uint8_t *M0;
 
126
    const uint8_t *M1;
 
127
    unsigned int byte_width;
 
128
    unsigned int height;
 
129
    unsigned long dst_padding;
 
130
    unsigned long src_padding;
 
131
    unsigned long dst_bpl;
 
132
    unsigned long src_bpl;
 
133
 
 
134
    if (SIMD == CPU_FEATURE_SSE2) {
 
135
        if (((unsigned long) pInfo->Overlay |
 
136
             (unsigned long) pInfo->PictureHistory[0]->pData |
 
137
             (unsigned long) pInfo->PictureHistory[1]->pData |
 
138
             (unsigned long) pInfo->PictureHistory[2]->pData |
 
139
             (unsigned long) pInfo->PictureHistory[3]->pData |
 
140
             (unsigned long) pInfo->OverlayPitch |
 
141
             (unsigned long) pInfo->InputPitch |
 
142
             (unsigned long) pInfo->LineLength) & 15)
 
143
            return DeinterlaceGreedy2Frame_SSE (pInfo);
 
144
    }
 
145
 
 
146
    qwGreedyTwoFrameThreshold = vsplat8 (GreedyTwoFrameThreshold);
 
147
 
 
148
    byte_width = pInfo->LineLength;
 
149
 
 
150
    dst_bpl = pInfo->OverlayPitch;
 
151
    src_bpl = pInfo->InputPitch;
 
152
 
 
153
    Dest = pInfo->Overlay;
 
154
 
 
155
    M1 = pInfo->PictureHistory[0]->pData;
 
156
    T1 = pInfo->PictureHistory[1]->pData;
 
157
    M0 = pInfo->PictureHistory[2]->pData;
 
158
    T0 = pInfo->PictureHistory[3]->pData;
 
159
 
 
160
    if (!(pInfo->PictureHistory[0]->Flags & PICTURE_INTERLACED_ODD)) {
 
161
        copy_line (Dest, M1, byte_width);
 
162
        Dest += dst_bpl;
 
163
 
 
164
        M1 = (const uint8_t *) pInfo->PictureHistory[0]->pData + src_bpl;
 
165
        M0 = (const uint8_t *) pInfo->PictureHistory[2]->pData + src_bpl;
 
166
    }
 
167
 
 
168
    dst_padding = dst_bpl * 2 - byte_width;
 
169
    src_padding = src_bpl - byte_width;
 
170
 
 
171
    for (height = pInfo->FieldHeight - 1; height > 0; --height) {
 
172
        unsigned int count;
 
173
 
 
174
        for (count = byte_width / sizeof (vu8); count > 0; --count) {
 
175
            vu8 m0, m1, t0, t1, b0, b1, avg, mm4;
 
176
            v32 sum;
 
177
 
 
178
            t1 = vload (T1, 0);
 
179
            b1 = vload (T1, src_bpl);
 
180
            T1 += sizeof (vu8);
 
181
 
 
182
            /* Always use the most recent data verbatim.  By definition it's
 
183
               correct (it'd be shown on an interlaced display) and our job is
 
184
               to fill in the spaces between the new lines. */
 
185
            vstorent (Dest, 0, t1);
 
186
 
 
187
            avg = fast_vavgu8 (t1, b1);
 
188
 
 
189
            m0 = vload (M0, 0);
 
190
            M0 += sizeof (vu8);
 
191
            m1 = vload (M1, 0);
 
192
            M1 += sizeof (vu8);
 
193
 
 
194
            /* if we have a good processor then make mm0 the average of M1
 
195
               and M0 which should make weave look better when there is
 
196
               small amounts of movement */
 
197
            if (SIMD != CPU_FEATURE_MMX)
 
198
                m1 = vavgu8 (m1, m0);
 
199
 
 
200
            /* if |M1-M0| > Threshold we want dword worth of twos */
 
201
            sum = thresh_cmp (m1, m0, qwGreedyTwoFrameThreshold, vsplat32_2);
 
202
 
 
203
            /* if |T1-T0| > Threshold we want dword worth of ones */
 
204
            t0 = vload (T0, 0);
 
205
            sum = vadd32 (sum, thresh_cmp (t1, t0, qwGreedyTwoFrameThreshold,
 
206
                                           vsplat32_1));
 
207
 
 
208
            /* if |B1-B0| > Threshold we want dword worth of ones */
 
209
            b0 = vload (T0, src_bpl);
 
210
            T0 += sizeof (vu8);
 
211
            sum = vadd32 (sum, thresh_cmp (b1, b0, qwGreedyTwoFrameThreshold,
 
212
                                           vsplat32_1));
 
213
 
 
214
            mm4 = (vu8) vcmpgt32 (sum, vsplat32_2);
 
215
 
 
216
            /* debugging feature
 
217
               output the value of mm4 at this point which is pink
 
218
               where we will weave and green were we are going to bob */
 
219
            if (CHECK_BOBWEAVE)
 
220
                vstorent (Dest, dst_bpl, mm4);
 
221
            else
 
222
                vstorent (Dest, dst_bpl, vsel (mm4, m1, avg));
 
223
 
 
224
            Dest += sizeof (vu8);
 
225
        }
 
226
 
 
227
        M1 += src_padding;
 
228
        T1 += src_padding;
 
229
        M0 += src_padding;
 
230
        T0 += src_padding;
 
231
        Dest += dst_padding;
 
232
    }
 
233
 
 
234
    if (pInfo->PictureHistory[0]->Flags & PICTURE_INTERLACED_ODD) {
 
235
        copy_line (Dest, T1, byte_width);
 
236
        Dest += dst_bpl;
 
237
        copy_line (Dest, M1, byte_width);
 
238
    } else {
 
239
        copy_line (Dest, T1, byte_width);
 
240
    }
 
241
 
 
242
    vempty ();
 
243
 
 
244
    return TRUE;
 
245
}
 
246
 
 
247
#elif !SIMD
 
248
 
 
249
int GreedyTwoFrameThreshold = 4;
 
250
 
 
251
 
 
252
/*//////////////////////////////////////////////////////////////////////////
73
253
// Start of Settings related code
74
 
/////////////////////////////////////////////////////////////////////////////
75
 
SETTING DI_Greedy2FrameSettings[DI_GREEDY2FRAME_SETTING_LASTONE] =
76
 
{
 
254
//////////////////////////////////////////////////////////////////////////*/
 
255
static const SETTING
 
256
DI_Greedy2FrameSettings [] = {
77
257
    {
78
 
        N_("Greedy 2 Frame Luma Threshold"), SLIDER, 0, &GreedyTwoFrameThreshold,
79
 
        4, 0, 128, 1, 1,
 
258
        N_("Greedy 2 Frame Luma Threshold"), SLIDER, 0,
 
259
        &GreedyTwoFrameThreshold,
 
260
        4, 0, 127, 1, 1,
80
261
        NULL,
81
262
        "Deinterlace", "GreedyTwoFrameThreshold", NULL,
82
263
    },
83
 
    {
84
 
        N_("Greedy 2 Frame Chroma Threshold"), SLIDER, 0, &GreedyTwoFrameThreshold2,
85
 
        8, 0, 128, 1, 1,
86
 
        NULL,
87
 
        "Deinterlace", "GreedyTwoFrameThreshold2", NULL,
88
 
    },
89
264
};
90
265
 
91
 
 
92
 
DEINTERLACE_METHOD Greedy2FrameMethod =
93
 
{
94
 
    sizeof(DEINTERLACE_METHOD),
 
266
static const DEINTERLACE_METHOD
 
267
Greedy2FrameMethod = {
 
268
    sizeof (DEINTERLACE_METHOD),
95
269
    DEINTERLACE_CURRENT_VERSION,
96
270
    N_("Greedy 2 Frame"), 
97
271
    "Greedy2", 
98
272
    FALSE, 
99
273
    FALSE, 
100
 
    DeinterlaceGreedy2Frame_MMX, 
 
274
    /* pfnAlgorithm */ NULL,
101
275
    50, 
102
276
    60,
103
 
    DI_GREEDY2FRAME_SETTING_LASTONE,
 
277
    N_ELEMENTS (DI_Greedy2FrameSettings),
104
278
    DI_Greedy2FrameSettings,
105
279
    INDEX_VIDEO_GREEDY2FRAME,
106
280
    NULL,
110
284
    4,
111
285
    0,
112
286
    0,
113
 
    WM_DI_GREEDY2FRAME_GETVALUE - WM_APP,
 
287
    0,
114
288
    NULL,
115
289
    0,
116
290
    FALSE,
118
292
    IDH_GREEDY2
119
293
};
120
294
 
121
 
 
122
 
DEINTERLACE_METHOD* DI_Greedy2Frame_GetDeinterlacePluginInfo(long CpuFeatureFlags)
123
 
{
124
 
    if (CpuFeatureFlags & FEATURE_SSE)
125
 
    {
126
 
        Greedy2FrameMethod.pfnAlgorithm = DeinterlaceGreedy2Frame_SSE;
127
 
    }
128
 
    else if (CpuFeatureFlags & FEATURE_3DNOW)
129
 
    {
130
 
        Greedy2FrameMethod.pfnAlgorithm = DeinterlaceGreedy2Frame_3DNOW;
131
 
    }
132
 
    else
133
 
    {
134
 
        Greedy2FrameMethod.pfnAlgorithm = DeinterlaceGreedy2Frame_MMX;
135
 
    }
136
 
    return &Greedy2FrameMethod;
137
 
}
138
 
 
139
 
#if 0
140
 
 
141
 
 
142
 
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
143
 
{
144
 
    return TRUE;
145
 
}
146
 
 
147
 
#endif /* 0 */
 
295
DEINTERLACE_METHOD *
 
296
DI_Greedy2Frame_GetDeinterlacePluginInfo (void)
 
297
{
 
298
    DEINTERLACE_METHOD *m;
 
299
    DEINTERLACE_FUNC *f;
 
300
 
 
301
    m = NULL;
 
302
 
 
303
    f = SIMD_FN_SELECT (DeinterlaceGreedy2Frame,
 
304
                        CPU_FEATURE_MMX | CPU_FEATURE_3DNOW |
 
305
                        CPU_FEATURE_SSE | CPU_FEATURE_SSE2 |
 
306
                        CPU_FEATURE_ALTIVEC);
 
307
 
 
308
    if (f) {
 
309
        m = malloc (sizeof (*m));
 
310
        *m = Greedy2FrameMethod;
 
311
 
 
312
        m->pfnAlgorithm = f;
 
313
    }
 
314
 
 
315
    return m;
 
316
}
 
317
 
 
318
#endif /* !SIMD */
 
319
 
 
320
/*
 
321
Local Variables:
 
322
c-basic-offset: 4
 
323
End:
 
324
 */