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
/////////////////////////////////////////////////////////////////////////////
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.
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
/////////////////////////////////////////////////////////////////////////////
20
// Date Developer Changes
22
// 07 Jan 2001 John Adcock Split into separate module
24
/////////////////////////////////////////////////////////////////////////////
27
// $Log: DI_Adaptive.c,v $
28
// Revision 1.2 2005/02/05 22:20:54 mschimek
31
// Revision 1.1 2005/01/08 14:54:23 mschimek
32
// *** empty log message ***
34
// Revision 1.2 2004/11/15 23:03:19 michael
35
// *** empty log message ***
37
// Revision 1.1 2004/11/14 15:35:14 michael
38
// *** empty log message ***
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
43
// Revision 1.16 2002/06/18 19:46:06 adcockj
44
// Changed appliaction Messages to use WM_APP instead of WM_USER
46
// Revision 1.15 2002/06/13 12:10:23 adcockj
47
// Move to new Setings dialog for filers, video deint and advanced settings
49
// Revision 1.14 2002/06/13 08:22:07 adcockj
50
// Changed default motion methods to greedyHM
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.
56
// Revision 1.12 2001/07/13 16:13:32 adcockj
57
// Added CVS tags and removed tabs
59
/////////////////////////////////////////////////////////////////////////////
62
#include "DS_Deinterlace.h"
63
//Z #include "..\help\helpids.h"
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;
73
long NumVideoModes = 0;
74
long CurrentIndex = -1;
75
DEINTERLACE_METHOD** DeintMethods = NULL;
76
DEINTERLACE_METHOD* CurrentMethod = NULL;
77
DEINTERLACEPLUGINSETSTATUS* pfnSetStatus;
81
///////////////////////////////////////////////////////////////////////////////
84
// Switches to a new adaptive mode. Updates the status bar if needed.
85
///////////////////////////////////////////////////////////////////////////////
86
void UpdateAdaptiveMode(long Index)
91
if (CurrentIndex == Index && CurrentMethod != NULL)
94
if (Index == INDEX_ADAPTIVE)
96
CurrentMethod = DeintMethods[0];
97
if(pfnSetStatus != NULL)
99
pfnSetStatus("Adaptive - Recursion Error");
104
for(i = 0; i < NumVideoModes && bFound == FALSE; i++)
106
if(DeintMethods[i]->nMethodIndex == Index)
108
CurrentMethod = DeintMethods[i];
111
if(pfnSetStatus != NULL)
113
static char AdaptiveName[200];
116
ModeName = DeintMethods[i]->szShortName;
117
if (ModeName == NULL)
119
ModeName = DeintMethods[i]->szName;
121
wsprintf(AdaptiveName, "Adaptive - %s", ModeName);
122
pfnSetStatus(AdaptiveName);
125
CurrentIndex = Index;
131
CurrentMethod = DeintMethods[0];
132
if(pfnSetStatus != NULL)
134
pfnSetStatus("Adaptive - Error Finding Index");
140
///////////////////////////////////////////////////////////////////////////////
141
// DeinterlaceAdaptive
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
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)
158
static long StaticMatchCount = 0;
159
static long LowMatchCount = 0;
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)
165
UpdateAdaptiveMode(HighMotionMode);
166
StaticMatchCount = 0;
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)
177
// if we have very liitle motion update
178
// to static after StaticImageFieldCount consecutive
180
// also check if its OK to go into low motion mode
181
if(pInfo->FieldDiff < AdaptiveThres32Pulldown)
185
if(CurrentIndex != StaticImageMode &&
186
StaticMatchCount >= StaticImageFieldCount)
188
UpdateAdaptiveMode(StaticImageMode);
190
else if(CurrentIndex == HighMotionMode &&
191
LowMatchCount >= LowMotionFieldCount)
193
UpdateAdaptiveMode(LowMotionMode);
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)
203
StaticMatchCount = 0;
205
if ((CurrentIndex == HighMotionMode &&
206
LowMatchCount >= LowMotionFieldCount) ||
207
CurrentIndex == StaticImageMode)
209
UpdateAdaptiveMode(LowMotionMode);
212
// high levels of motion just switch to high mode
216
StaticMatchCount = 0;
218
if(CurrentIndex != HighMotionMode)
220
UpdateAdaptiveMode(HighMotionMode);
224
if(CurrentMethod != NULL)
226
return CurrentMethod->pfnAlgorithm(pInfo);
234
void __cdecl AdaptiveStart(long NumPlugIns, DEINTERLACE_METHOD** OtherPlugins, DEINTERLACEPLUGINSETSTATUS* SetStatus)
239
DeintMethods = OtherPlugins;
240
NumVideoModes = NumPlugIns;
241
pfnSetStatus = SetStatus;
243
for(i = 0; i < 100; i++)
246
for(j = 0; j < NumPlugIns; j++)
248
if(DeintMethods[j]->nMethodIndex == i)
250
ModeList[i] = DeintMethods[j]->szName;
257
////////////////////////////////////////////////////////////////////////////
258
// Start of Settings related code
259
/////////////////////////////////////////////////////////////////////////////
260
SETTING DI_AdaptiveSettings[DI_ADAPTIVE_SETTING_LASTONE] =
263
"Low Motion Field Count", SLIDER, 0, &LowMotionFieldCount,
266
"Pulldown", "LowMotionFieldCount", NULL,
269
"Static Image Field Count", SLIDER, 0, &StaticImageFieldCount,
272
"Pulldown", "StaticImageFieldCount", NULL,
275
"Static Image Mode", ITEMFROMLIST, 0, &StaticImageMode,
276
INDEX_WEAVE, 0, 99, 1, 1,
278
"Pulldown", "StaticImageMode", NULL,
281
"Low Motion Mode", ITEMFROMLIST, 0, &LowMotionMode,
282
INDEX_VIDEO_TOMSMOCOMP, 0, 99, 1, 1,
284
"Pulldown", "LowMotionMode", NULL,
287
"High Motion Mode", ITEMFROMLIST, 0, &HighMotionMode,
288
INDEX_VIDEO_TOMSMOCOMP, 0, 99, 1, 1,
290
"Pulldown", "HighMotionMode", NULL,
293
"Adaptive Threshold 3:2 Pulldown", SLIDER, 0, &AdaptiveThres32Pulldown,
296
"Pulldown", "AdaptiveThres32Pulldown", NULL,
299
"Adaptive Threshold 3:2 Pulldown Mismatch", SLIDER, 0, &AdaptiveThresPulldownMismatch,
300
900, 1, 10000, 10, 1,
302
"Pulldown", "AdaptiveThresPulldownMismatch", NULL,
306
DEINTERLACE_METHOD AdaptiveMethod =
308
sizeof(DEINTERLACE_METHOD),
309
DEINTERLACE_CURRENT_VERSION,
317
DI_ADAPTIVE_SETTING_LASTONE,
327
WM_DI_ADAPTIVE_GETVALUE - WM_APP,
335
DEINTERLACE_METHOD* DI_Adaptive_GetDeinterlacePluginInfo(long CpuFeatureFlags)
337
return &AdaptiveMethod;
343
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)