4
* Copyright (C) 2004 Michael H. Schimek
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
/* $Id: ditest.c,v 1.2 2005/02/12 13:32:27 mschimek Exp $ */
29
#include "DS_Deinterlace.h"
31
static long cpu_feature_flags;
33
static DEINTERLACE_METHOD * method;
35
static TDeinterlaceInfo info;
36
static TPicture pictures[MAX_PICTURE_HISTORY];
39
deinterlace (char * buffer,
41
unsigned int field_parity)
43
static unsigned int field_count = 0;
49
p = info.PictureHistory[MAX_PICTURE_HISTORY - 1];
51
memmove (info.PictureHistory + 1,
52
info.PictureHistory + 0,
53
(MAX_PICTURE_HISTORY - 1) * sizeof (TPicture *));
55
info.PictureHistory[0] = p;
57
if (0 == field_parity)
60
p->Flags = PICTURE_INTERLACED_EVEN; /* sic, if PAL */
61
p->IsFirstInSeries = (0 == field_count);
65
p->pData = buffer + width * 2;
66
p->Flags = PICTURE_INTERLACED_ODD;
67
p->IsFirstInSeries = (0 == field_count);
72
if (field_count < (unsigned int) method->nFieldsRequired)
75
method->pfnAlgorithm (&info);
77
/* NOTE if method->bIsHalfHeight only the upper half of out_buffer
78
contains data, must be scaled. */
82
new_buffer (unsigned int width,
89
size = width * height * 2;
91
buffer = malloc (size);
92
assert (NULL != buffer);
94
for (i = 0; i < size; i += 2)
104
init_info (char * out_buffer,
110
memset (&info, 0, sizeof (info));
112
info.Version = DEINTERLACE_INFO_CURRENT_VERSION;
114
for (i = 0; i < MAX_PICTURE_HISTORY; ++i)
115
info.PictureHistory[i] = pictures + i;
117
info.Overlay = out_buffer;
118
info.OverlayPitch = width * 2;
119
info.LineLength = width * 2;
120
info.FrameWidth = width;
121
info.FrameHeight = height;
122
info.FieldHeight = height / 2;
123
info.pMemcpy = (void *) memcpy; /* XXX */
124
info.CpuFeatureFlags = cpu_feature_flags;
125
info.InputPitch = width * 2 * 2;
127
assert (!method->bNeedFieldDiff);
128
assert (!method->bNeedCombFactor);
132
swab32 (char * buffer,
139
assert (0 == (size % 4));
141
for (i = 0; i < size; i += 4)
145
buffer[i + 0] = buffer[i + 3];
146
buffer[i + 1] = buffer[i + 2];
153
write_buffer (const char * name,
162
size = width * height * 2;
164
fp = fopen (name, "wb");
167
actual = fwrite (buffer, 1, size, fp);
168
if (actual < size || ferror (fp))
182
char *in_buffers[(MAX_PICTURE_HISTORY + 1) / 2];
183
unsigned int n_frames;
189
cpu_feature_flags = (FEATURE_MMX | /* XXX */
194
n_frames = strtoul (argv[1], NULL, 0);
196
assert (n_frames > 0);
198
width = strtoul (argv[2], NULL, 0);
199
height = strtoul (argv[3], NULL, 0);
201
assert (width > 0 && 0 == (width % 2)); /* YUYV */
202
assert (height > 0 && 0 == (height % 2)); /* interlaced */
204
size = width * height * 2;
210
else if (++i == strtoul (argv[4], NULL, 0) \
211
|| 0 == strcmp (#x, argv[4])) \
213
extern DEINTERLACE_METHOD *DI_##x##_GetDeinterlacePluginInfo (long); \
214
method = DI_##x##_GetDeinterlacePluginInfo (cpu_feature_flags); \
232
ELSEIF (Greedy2Frame)
239
assert (!"unknown method");
242
out_buffer = new_buffer (width, height);
244
for (i = 0; i < (MAX_PICTURE_HISTORY + 1) / 2; ++i)
245
in_buffers[i] = new_buffer (width, height);
247
init_info (out_buffer, width, height);
249
fprintf (stderr, "Using '%s' ShortName='%s' HalfHeight=%d FilmMode=%d\n"
250
"FrameRate=%lu,%lu ModeChanges=%ld ModeTicks=%ld\n"
251
"NeedFieldDiff=%d NeedCombFactor=%d\n",
252
method->szName, method->szShortName,
253
method->bIsHalfHeight, method->bIsFilmMode,
254
method->FrameRate50Hz, method->FrameRate60Hz,
255
method->ModeChanges, method->ModeTicks,
256
method->bNeedFieldDiff, method->bNeedCombFactor);
258
for (i = 0; i < n_frames; ++i) {
262
assert (!feof (stdin));
264
actual = fread (in_buffers[i % 4], 1, size, stdin);
265
if (actual < size || ferror (stdin))
271
swab32 (in_buffers[i % 4], size);
273
deinterlace (in_buffers[i % 4], width, 0);
274
snprintf (name, sizeof (name), "di%03u0.yuv", i);
275
write_buffer (name, out_buffer, width, height);
277
deinterlace (in_buffers[i % 4], width, 1);
278
snprintf (name, sizeof (name), "di%03u1.yuv", i);
279
write_buffer (name, out_buffer, width, height);
282
fprintf (stderr, "\n");