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

« back to all changes in this revision

Viewing changes to plugins/deinterlace/DI_Misc/DI_Adaptive.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_Adaptive.c,v 1.2 2005/02/05 22:20:54 mschimek Exp $
3
 
/////////////////////////////////////////////////////////////////////////////
4
 
// Copyright (c) 2000 Mark Rejhon and Steve Grimm.  All rights reserved.
5
 
/////////////////////////////////////////////////////////////////////////////
6
 
//
7
 
//  This file is subject to the terms of the GNU General Public License as
8
 
//  published by the Free Software Foundation.  A copy of this license is
9
 
//  included with this software distribution in the file COPYING.  If you
10
 
//  do not have a copy, you may obtain a copy by writing to the Free
11
 
//  Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
12
 
//
13
 
//  This software 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
16
 
//  GNU General Public License for more details
17
 
/////////////////////////////////////////////////////////////////////////////
18
 
// Change Log
19
 
//
20
 
// Date          Developer             Changes
21
 
//
22
 
// 07 Jan 2001   John Adcock           Split into separate module
23
 
//
24
 
/////////////////////////////////////////////////////////////////////////////
25
 
// CVS Log
26
 
//
27
 
// $Log: DI_Adaptive.c,v $
28
 
// Revision 1.2  2005/02/05 22:20:54  mschimek
29
 
// Completed l18n.
30
 
//
31
 
// Revision 1.1  2005/01/08 14:54:23  mschimek
32
 
// *** empty log message ***
33
 
//
34
 
// Revision 1.2  2004/11/15 23:03:19  michael
35
 
// *** empty log message ***
36
 
//
37
 
// Revision 1.1  2004/11/14 15:35:14  michael
38
 
// *** empty log message ***
39
 
//
40
 
// Revision 1.17  2003/02/14 21:53:49  laurentg
41
 
// TomsMoComp used as default mode instead of GreedyHM for low and high motion modes
42
 
//
43
 
// Revision 1.16  2002/06/18 19:46:06  adcockj
44
 
// Changed appliaction Messages to use WM_APP instead of WM_USER
45
 
//
46
 
// Revision 1.15  2002/06/13 12:10:23  adcockj
47
 
// Move to new Setings dialog for filers, video deint and advanced settings
48
 
//
49
 
// Revision 1.14  2002/06/13 08:22:07  adcockj
50
 
// Changed default motion methods to greedyHM
51
 
//
52
 
// Revision 1.13  2001/11/21 15:21:40  adcockj
53
 
// Renamed DEINTERLACE_INFO to TDeinterlaceInfo in line with standards
54
 
// Changed TDeinterlaceInfo structure to have history of pictures.
55
 
//
56
 
// Revision 1.12  2001/07/13 16:13:32  adcockj
57
 
// Added CVS tags and removed tabs
58
 
//
59
 
/////////////////////////////////////////////////////////////////////////////
60
 
 
61
 
#include "windows.h"
62
 
#include "DS_Deinterlace.h"
63
 
//Z #include "..\help\helpids.h"
64
 
 
65
 
long        StaticImageFieldCount = 100;
66
 
long        LowMotionFieldCount = 4;
67
 
long        StaticImageMode = INDEX_WEAVE;
68
 
long        LowMotionMode = INDEX_VIDEO_2FRAME;
69
 
long        HighMotionMode = INDEX_VIDEO_2FRAME;
70
 
long        AdaptiveThres32Pulldown = 15;
71
 
long        AdaptiveThresPulldownMismatch = 900;
72
 
 
73
 
long NumVideoModes = 0;
74
 
long CurrentIndex = -1;
75
 
DEINTERLACE_METHOD** DeintMethods = NULL;
76
 
DEINTERLACE_METHOD* CurrentMethod = NULL;
77
 
DEINTERLACEPLUGINSETSTATUS* pfnSetStatus;
78
 
LPCSTR ModeList[100];
79
 
 
80
 
 
81
 
///////////////////////////////////////////////////////////////////////////////
82
 
// UpdateAdaptiveMode
83
 
//
84
 
// Switches to a new adaptive mode.  Updates the status bar if needed.
85
 
///////////////////////////////////////////////////////////////////////////////
86
 
void UpdateAdaptiveMode(long Index)
87
 
{
88
 
    int i;
89
 
    BOOL bFound = FALSE;
90
 
 
91
 
    if (CurrentIndex == Index && CurrentMethod != NULL)
92
 
        return;
93
 
 
94
 
    if (Index == INDEX_ADAPTIVE)
95
 
    {
96
 
        CurrentMethod = DeintMethods[0];
97
 
        if(pfnSetStatus != NULL)
98
 
        {
99
 
            pfnSetStatus("Adaptive - Recursion Error");
100
 
        }
101
 
        return;
102
 
    }
103
 
 
104
 
    for(i = 0; i < NumVideoModes && bFound == FALSE; i++)
105
 
    {
106
 
        if(DeintMethods[i]->nMethodIndex == Index)
107
 
        {
108
 
            CurrentMethod = DeintMethods[i];
109
 
            bFound = TRUE;
110
 
#if 0 /* Z */
111
 
            if(pfnSetStatus != NULL)
112
 
            {
113
 
                static char AdaptiveName[200];
114
 
                char* ModeName;
115
 
 
116
 
                ModeName = DeintMethods[i]->szShortName;
117
 
                if (ModeName == NULL)
118
 
                {
119
 
                    ModeName = DeintMethods[i]->szName;
120
 
                }
121
 
                wsprintf(AdaptiveName, "Adaptive - %s", ModeName);
122
 
                pfnSetStatus(AdaptiveName);
123
 
            }
124
 
#endif /* 0 */
125
 
            CurrentIndex = Index;
126
 
        }
127
 
    }
128
 
 
129
 
    if(bFound == FALSE)
130
 
    {
131
 
        CurrentMethod = DeintMethods[0];
132
 
        if(pfnSetStatus != NULL)
133
 
        {
134
 
            pfnSetStatus("Adaptive - Error Finding Index");
135
 
        }
136
 
    }
137
 
}
138
 
 
139
 
 
140
 
///////////////////////////////////////////////////////////////////////////////
141
 
// DeinterlaceAdaptive
142
 
//
143
 
// This mode supports three styles of deinterlacing and switch among
144
 
// them depending on the amount of motion in the scene.  If there's a lot of
145
 
// motion, we use HighMotionMode.  If there's little or no motion for at least
146
 
// LowMotionFieldCount fields, we switch to LowMotionMode.  And if, after that,
147
 
// there's no motion for StaticImageFieldCount fields, we switch to
148
 
// StaticImageMode.
149
 
//
150
 
// Exactly which modes are used in these three cases is configurable in the INI
151
 
// file. It is entirely legal for some or all of the three video modes to be the
152
 
// same; by default, VIDEO_MODE_2FRAME is used for both the high and low motion
153
 
// modes.  On slower machines VIDEO_MODE_BOB (high) and VIDEO_MODE_WEAVE (low)
154
 
// can be used instead since they're less CPU-intensive.
155
 
///////////////////////////////////////////////////////////////////////////////
156
 
BOOL DeinterlaceAdaptive(TDeinterlaceInfo* pInfo)
157
 
{
158
 
    static long StaticMatchCount = 0;
159
 
    static long LowMatchCount = 0;
160
 
 
161
 
    // If this is our first time, update the current adaptive mode to whatever
162
 
    // the ini file said our high-motion mode should be.
163
 
    if (CurrentIndex == -1 || CurrentMethod == NULL)
164
 
    {
165
 
        UpdateAdaptiveMode(HighMotionMode);
166
 
        StaticMatchCount = 0;
167
 
        LowMatchCount = 0;
168
 
    }
169
 
 
170
 
    // reset MATCH_COUNT when we are called and the pInfo
171
 
    // struct doesn't contain at least an odd and an even frame
172
 
    if(pInfo->PictureHistory[0] == NULL || pInfo->PictureHistory[1] == NULL)
173
 
    {
174
 
        return FALSE;
175
 
    }
176
 
 
177
 
    // if we have very liitle motion update
178
 
    // to static after StaticImageFieldCount consecutive 
179
 
    // static fields
180
 
    // also check if its OK to go into low motion mode
181
 
    if(pInfo->FieldDiff < AdaptiveThres32Pulldown)
182
 
    {
183
 
        StaticMatchCount++;
184
 
        LowMatchCount++;
185
 
        if(CurrentIndex != StaticImageMode &&
186
 
            StaticMatchCount >= StaticImageFieldCount)
187
 
        {
188
 
            UpdateAdaptiveMode(StaticImageMode);
189
 
        }
190
 
        else if(CurrentIndex == HighMotionMode &&
191
 
            LowMatchCount >= LowMotionFieldCount)
192
 
        {
193
 
            UpdateAdaptiveMode(LowMotionMode);
194
 
        }
195
 
    }
196
 
    // if there is some motion then
197
 
    // switch back to low from high only after LowMotionFieldCount
198
 
    // consecutive low or static fields
199
 
    // if we are in static then switch straight away
200
 
    else if(pInfo->FieldDiff < AdaptiveThresPulldownMismatch)
201
 
    {
202
 
        LowMatchCount++;
203
 
        StaticMatchCount = 0;
204
 
 
205
 
        if ((CurrentIndex == HighMotionMode &&
206
 
            LowMatchCount >= LowMotionFieldCount) ||
207
 
            CurrentIndex == StaticImageMode)
208
 
        {
209
 
            UpdateAdaptiveMode(LowMotionMode);
210
 
        }
211
 
    }
212
 
    // high levels of motion just switch to high mode
213
 
    else
214
 
    {
215
 
        LowMatchCount = 0;
216
 
        StaticMatchCount = 0;
217
 
 
218
 
        if(CurrentIndex != HighMotionMode)
219
 
        {
220
 
            UpdateAdaptiveMode(HighMotionMode);
221
 
        }
222
 
    }
223
 
 
224
 
    if(CurrentMethod != NULL)
225
 
    {
226
 
        return CurrentMethod->pfnAlgorithm(pInfo);
227
 
    }
228
 
    else
229
 
    {
230
 
        return FALSE;
231
 
    }
232
 
}
233
 
 
234
 
void __cdecl AdaptiveStart(long NumPlugIns, DEINTERLACE_METHOD** OtherPlugins, DEINTERLACEPLUGINSETSTATUS* SetStatus)
235
 
{
236
 
    int i;
237
 
    int j;
238
 
    
239
 
    DeintMethods = OtherPlugins;
240
 
    NumVideoModes = NumPlugIns;
241
 
    pfnSetStatus = SetStatus;
242
 
 
243
 
    for(i = 0; i < 100; i++)
244
 
    {
245
 
        ModeList[i] = "";
246
 
        for(j = 0; j < NumPlugIns; j++)
247
 
        {
248
 
            if(DeintMethods[j]->nMethodIndex == i)
249
 
            {
250
 
                ModeList[i] = DeintMethods[j]->szName;
251
 
                break;
252
 
            }
253
 
        }
254
 
    }
255
 
}
256
 
 
257
 
////////////////////////////////////////////////////////////////////////////
258
 
// Start of Settings related code
259
 
/////////////////////////////////////////////////////////////////////////////
260
 
SETTING DI_AdaptiveSettings[DI_ADAPTIVE_SETTING_LASTONE] =
261
 
{
262
 
    {
263
 
        "Low Motion Field Count", SLIDER, 0, &LowMotionFieldCount,
264
 
        4, 1, 1000, 1, 1,
265
 
        NULL,
266
 
        "Pulldown", "LowMotionFieldCount", NULL,
267
 
    },
268
 
    {
269
 
        "Static Image Field Count", SLIDER, 0, &StaticImageFieldCount,
270
 
        100, 1, 1000, 1, 1,
271
 
        NULL,
272
 
        "Pulldown", "StaticImageFieldCount", NULL,
273
 
    },
274
 
    {
275
 
        "Static Image Mode", ITEMFROMLIST, 0, &StaticImageMode,
276
 
        INDEX_WEAVE, 0, 99, 1, 1,
277
 
        ModeList,
278
 
        "Pulldown", "StaticImageMode", NULL,
279
 
    },
280
 
    {
281
 
        "Low Motion Mode", ITEMFROMLIST, 0, &LowMotionMode,
282
 
        INDEX_VIDEO_TOMSMOCOMP, 0, 99, 1, 1,
283
 
        ModeList,
284
 
        "Pulldown", "LowMotionMode", NULL,
285
 
    },
286
 
    {
287
 
        "High Motion Mode", ITEMFROMLIST, 0, &HighMotionMode,
288
 
        INDEX_VIDEO_TOMSMOCOMP, 0, 99, 1, 1,
289
 
        ModeList,
290
 
        "Pulldown", "HighMotionMode", NULL,
291
 
    },
292
 
    {
293
 
        "Adaptive Threshold 3:2 Pulldown", SLIDER, 0, &AdaptiveThres32Pulldown,
294
 
        15, 1, 5000, 5, 1,
295
 
        NULL,
296
 
        "Pulldown", "AdaptiveThres32Pulldown", NULL,
297
 
    },
298
 
    {
299
 
        "Adaptive Threshold 3:2 Pulldown Mismatch", SLIDER, 0, &AdaptiveThresPulldownMismatch,
300
 
        900, 1, 10000, 10, 1,
301
 
        NULL,
302
 
        "Pulldown", "AdaptiveThresPulldownMismatch", NULL,
303
 
    },
304
 
};
305
 
 
306
 
DEINTERLACE_METHOD AdaptiveMethod =
307
 
{
308
 
    sizeof(DEINTERLACE_METHOD),
309
 
    DEINTERLACE_CURRENT_VERSION,
310
 
    N_("Adaptive"), 
311
 
    NULL, 
312
 
    FALSE, 
313
 
    FALSE, 
314
 
    DeinterlaceAdaptive, 
315
 
    50, 
316
 
    60,
317
 
    DI_ADAPTIVE_SETTING_LASTONE,
318
 
    DI_AdaptiveSettings,
319
 
    INDEX_ADAPTIVE,
320
 
    NULL,
321
 
    AdaptiveStart,
322
 
    NULL,
323
 
    NULL,
324
 
    4,
325
 
    0,
326
 
    0,
327
 
    WM_DI_ADAPTIVE_GETVALUE - WM_APP,
328
 
    NULL,
329
 
    0,
330
 
    TRUE,
331
 
    FALSE,
332
 
    IDH_ADAPTIVE,
333
 
};
334
 
 
335
 
DEINTERLACE_METHOD* DI_Adaptive_GetDeinterlacePluginInfo(long CpuFeatureFlags)
336
 
{
337
 
    return &AdaptiveMethod;
338
 
}
339
 
 
340
 
#if 0
341
 
 
342
 
 
343
 
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
344
 
{
345
 
    return TRUE;
346
 
}
347
 
 
348
 
#endif /* 0 */