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

« back to all changes in this revision

Viewing changes to plugins/deinterlace/ditest.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
 
 *  Zapping TV viewer
3
 
 *
4
 
 *  Copyright (C) 2004 Michael H. Schimek
5
 
 *
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
21
 
/* $Id: ditest.c,v 1.2 2005/02/12 13:32:27 mschimek Exp $ */
22
 
 
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
#include <string.h>
26
 
#include <assert.h>
27
 
 
28
 
#include "windows.h"
29
 
#include "DS_Deinterlace.h"
30
 
 
31
 
static long                     cpu_feature_flags;
32
 
 
33
 
static DEINTERLACE_METHOD *     method;
34
 
 
35
 
static TDeinterlaceInfo         info;
36
 
static TPicture                 pictures[MAX_PICTURE_HISTORY];
37
 
 
38
 
static void
39
 
deinterlace                     (char *                 buffer,
40
 
                                 unsigned int           width,
41
 
                                 unsigned int           field_parity)
42
 
{
43
 
  static unsigned int field_count = 0;
44
 
  TPicture *p;
45
 
 
46
 
  fputc ('.', stderr);
47
 
  fflush (stderr);
48
 
 
49
 
  p = info.PictureHistory[MAX_PICTURE_HISTORY - 1];
50
 
 
51
 
  memmove (info.PictureHistory + 1,
52
 
           info.PictureHistory + 0,
53
 
           (MAX_PICTURE_HISTORY - 1) * sizeof (TPicture *));
54
 
 
55
 
  info.PictureHistory[0] = p;
56
 
 
57
 
  if (0 == field_parity)
58
 
    {
59
 
      p->pData = buffer;
60
 
      p->Flags = PICTURE_INTERLACED_EVEN;       /* sic, if PAL */
61
 
      p->IsFirstInSeries = (0 == field_count);
62
 
    }
63
 
  else
64
 
    {
65
 
      p->pData = buffer + width * 2;
66
 
      p->Flags = PICTURE_INTERLACED_ODD;
67
 
      p->IsFirstInSeries = (0 == field_count);
68
 
    }
69
 
 
70
 
  ++field_count;
71
 
 
72
 
  if (field_count < (unsigned int) method->nFieldsRequired)
73
 
    return;
74
 
 
75
 
  method->pfnAlgorithm (&info);
76
 
 
77
 
  /* NOTE if method->bIsHalfHeight only the upper half of out_buffer
78
 
     contains data, must be scaled. */
79
 
}
80
 
 
81
 
static char *
82
 
new_buffer                      (unsigned int           width,
83
 
                                 unsigned int           height)
84
 
{
85
 
  char *buffer;
86
 
  unsigned int size;
87
 
  unsigned int i;
88
 
 
89
 
  size = width * height * 2;
90
 
 
91
 
  buffer = malloc (size);
92
 
  assert (NULL != buffer);
93
 
 
94
 
  for (i = 0; i < size; i += 2)
95
 
    {
96
 
      buffer[i + 0] = 0x00;
97
 
      buffer[i + 1] = 0x80;
98
 
    }
99
 
 
100
 
  return buffer;
101
 
}
102
 
 
103
 
static void
104
 
init_info                       (char *                 out_buffer,
105
 
                                 unsigned int           width,
106
 
                                 unsigned int           height)
107
 
{
108
 
  unsigned int i;
109
 
 
110
 
  memset (&info, 0, sizeof (info));
111
 
  
112
 
  info.Version = DEINTERLACE_INFO_CURRENT_VERSION;
113
 
    
114
 
  for (i = 0; i < MAX_PICTURE_HISTORY; ++i)
115
 
    info.PictureHistory[i] = pictures + i;
116
 
 
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;
126
 
 
127
 
  assert (!method->bNeedFieldDiff);
128
 
  assert (!method->bNeedCombFactor);
129
 
}
130
 
 
131
 
static void
132
 
swab32                          (char *                 buffer,
133
 
                                 unsigned int           size)
134
 
{
135
 
  unsigned int i;
136
 
  char c;
137
 
  char d;
138
 
 
139
 
  assert (0 == (size % 4));
140
 
 
141
 
  for (i = 0; i < size; i += 4)
142
 
    {
143
 
      c = buffer[i + 0];
144
 
      d = buffer[i + 1];
145
 
      buffer[i + 0] = buffer[i + 3];
146
 
      buffer[i + 1] = buffer[i + 2];
147
 
      buffer[i + 2] = d;
148
 
      buffer[i + 3] = c;
149
 
    }
150
 
}
151
 
 
152
 
static void
153
 
write_buffer                    (const char *           name,
154
 
                                 char *                 buffer,
155
 
                                 unsigned int           width,
156
 
                                 unsigned int           height)
157
 
{
158
 
  unsigned int size;
159
 
  size_t actual;
160
 
  FILE *fp;
161
 
 
162
 
  size = width * height * 2;
163
 
 
164
 
  fp = fopen (name, "wb");
165
 
  assert (NULL != fp);
166
 
 
167
 
  actual = fwrite (buffer, 1, size, fp);
168
 
  if (actual < size || ferror (fp))
169
 
    {
170
 
      perror ("fwrite");
171
 
      exit (EXIT_FAILURE);
172
 
    }
173
 
 
174
 
  fclose (fp);
175
 
}
176
 
 
177
 
int
178
 
main                            (int                    argc,
179
 
                                 char **                argv)
180
 
{
181
 
  char *out_buffer;
182
 
  char *in_buffers[(MAX_PICTURE_HISTORY + 1) / 2];
183
 
  unsigned int n_frames;
184
 
  unsigned int width;
185
 
  unsigned int height;
186
 
  unsigned int size;
187
 
  unsigned int i;
188
 
 
189
 
  cpu_feature_flags = (FEATURE_MMX |            /* XXX */
190
 
                       FEATURE_TSC);
191
 
 
192
 
  assert (5 == argc);
193
 
 
194
 
  n_frames = strtoul (argv[1], NULL, 0);
195
 
 
196
 
  assert (n_frames > 0);
197
 
 
198
 
  width = strtoul (argv[2], NULL, 0);
199
 
  height = strtoul (argv[3], NULL, 0);
200
 
 
201
 
  assert (width > 0 && 0 == (width % 2));       /* YUYV */
202
 
  assert (height > 0 && 0 == (height % 2));     /* interlaced */
203
 
 
204
 
  size = width * height * 2;
205
 
 
206
 
  i = 0;
207
 
 
208
 
#undef ELSEIF
209
 
#define ELSEIF(x)                                                       \
210
 
  else if (++i == strtoul (argv[4], NULL, 0)                            \
211
 
           || 0 == strcmp (#x, argv[4]))                                \
212
 
    {                                                                   \
213
 
      extern DEINTERLACE_METHOD *DI_##x##_GetDeinterlacePluginInfo (long); \
214
 
      method = DI_##x##_GetDeinterlacePluginInfo (cpu_feature_flags);   \
215
 
    }
216
 
 
217
 
  if (0)
218
 
    {
219
 
      exit (EXIT_FAILURE);    
220
 
    }
221
 
  ELSEIF (VideoBob)
222
 
  ELSEIF (VideoWeave)
223
 
  ELSEIF (TwoFrame)
224
 
  ELSEIF (Weave)
225
 
  ELSEIF (Bob)
226
 
  ELSEIF (ScalerBob)
227
 
  ELSEIF (EvenOnly)
228
 
  ELSEIF (OddOnly)
229
 
  ELSEIF (BlendedClip)
230
 
  ELSEIF (Adaptive)
231
 
  ELSEIF (Greedy)
232
 
  ELSEIF (Greedy2Frame)
233
 
  ELSEIF (GreedyH)
234
 
  ELSEIF (OldGame)
235
 
  ELSEIF (TomsMoComp)
236
 
  ELSEIF (MoComp2)
237
 
  else
238
 
    {
239
 
      assert (!"unknown method");
240
 
    }
241
 
 
242
 
  out_buffer = new_buffer (width, height);
243
 
 
244
 
  for (i = 0; i < (MAX_PICTURE_HISTORY + 1) / 2; ++i)
245
 
    in_buffers[i] = new_buffer (width, height);
246
 
 
247
 
  init_info (out_buffer, width, height);
248
 
 
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);
257
 
 
258
 
  for (i = 0; i < n_frames; ++i) {
259
 
    char name[40];
260
 
    size_t actual;
261
 
 
262
 
    assert (!feof (stdin));
263
 
 
264
 
    actual = fread (in_buffers[i % 4], 1, size, stdin);
265
 
    if (actual < size || ferror (stdin))
266
 
      {
267
 
        perror ("fread");
268
 
        exit (EXIT_FAILURE);
269
 
      }
270
 
 
271
 
    swab32 (in_buffers[i % 4], size);
272
 
 
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);
276
 
 
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);
280
 
  }
281
 
 
282
 
  fprintf (stderr, "\n");
283
 
 
284
 
  return EXIT_SUCCESS;
285
 
}