annotate libmpcodecs/vf_dint.c @ 7396:cfb1bc3925eb

The granule position of pages contining Vorbis audio is in units of PCM audio samples (per channel; a stereo stream's granule position does no increment at twice the speed of a mono stream). patch by Moritz Bunkus <moritz@bunkus.org>
author arpi
date Sat, 14 Sep 2002 23:21:22 +0000
parents b34b005ab4f8
children 04a6df4fb976
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
1 #include <stdio.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
2 #include <stdlib.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
3 #include <string.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
4 #include <inttypes.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
5
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
6 #include "../config.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
7 #include "../mp_msg.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
8 #include "../libvo/fastmemcpy.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
9
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
10 #include "mp_image.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
11 #include "img_format.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
12 #include "vf.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
13
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
14 struct vf_priv_s {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
15 float sense; // first parameter
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
16 float level; // second parameter
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
17 unsigned int imgfmt;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
18 char diff;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
19 uint32_t max;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
20 // int dfr;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
21 // int rdfr;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
22 int was_dint;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
23 mp_image_t *pmpi; // previous mpi
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
24 };
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
25
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
26 #define MAXROWSIZE 1200
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
27
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
28 static int config (struct vf_instance_s* vf,
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
29 int width, int height, int d_width, int d_height,
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
30 unsigned int flags, unsigned int outfmt)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
31 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
32 int rowsize;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
33
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
34 vf->priv->pmpi = vf_get_image (vf->next, outfmt, MP_IMGTYPE_TEMP,
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
35 0, width, height);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
36 if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
37 outfmt != IMGFMT_RGB32 && outfmt != IMGFMT_BGR32 &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
38 outfmt != IMGFMT_RGB24 && outfmt != IMGFMT_BGR24 &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
39 outfmt != IMGFMT_RGB16 && outfmt != IMGFMT_BGR16)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
40 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
41 mp_msg (MSGT_VFILTER, MSGL_WARN, "Drop-interlaced filter doesn't support this outfmt :(\n");
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
42 return 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
43 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
44 vf->priv->imgfmt = outfmt;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
45 // recalculate internal values
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
46 rowsize = vf->priv->pmpi->width;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
47 if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
48 vf->priv->max = vf->priv->level * vf->priv->pmpi->height * rowsize / 2;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
49 if (vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) // planar YUV
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
50 vf->priv->diff = vf->priv->sense * 256;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
51 else
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
52 vf->priv->diff = vf->priv->sense * (1 << (vf->priv->pmpi->bpp/3));
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
53 if (vf->priv->diff < 0) vf->priv->diff = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
54 if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
55 vf->priv->pmpi->bpp < 24 && vf->priv->diff > 31)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
56 vf->priv->diff = 31;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
57 mp_msg (MSGT_VFILTER, MSGL_INFO, "Drop-interlaced: %dx%d diff %d / level %u\n",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
58 vf->priv->pmpi->width, vf->priv->pmpi->height,
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
59 (int)vf->priv->diff, (unsigned int)vf->priv->max);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
60 // vf->priv->rdfr = vf->priv->dfr = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
61 vf->priv->was_dint = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
62 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
63 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
64
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
65 static int put_image (struct vf_instance_s* vf, mp_image_t *mpi)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
66 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
67 char rrow0[MAXROWSIZE];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
68 char rrow1[MAXROWSIZE];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
69 char rrow2[MAXROWSIZE];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
70 char *row0 = rrow0, *row1 = rrow1, *row2 = rrow2/*, *row3 = rrow3*/;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
71 int rowsize = mpi->width;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
72 uint32_t nok = 0, max = vf->priv->max;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
73 int diff = vf->priv->diff;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
74 int i, j;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
75 register int n1, n2;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
76 unsigned char *cur0, *prv0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
77 register unsigned char *cur, *prv;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
78
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
79 // check if nothing to do
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
80 if (mpi->imgfmt == vf->priv->imgfmt)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
81 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
82 cur0 = mpi->planes[0] + mpi->stride[0];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
83 prv0 = mpi->planes[0];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
84 for (j = 1; j < mpi->height && nok <= max; j++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
85 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
86 cur = cur0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
87 prv = prv0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
88 // analyse row (row0)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
89 if (mpi->flags & MP_IMGFLAG_PLANAR) // planar YUV - check luminance
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
90 for (i = 0; i < rowsize; i++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
91 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
92 if (cur[0] - prv[0] > diff)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
93 row0[i] = 1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
94 else if (cur[0] - prv[0] < -diff)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
95 row0[i] = -1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
96 else
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
97 row0[i] = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
98 cur++;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
99 prv++;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
100 // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
101 // but row3 is 1 so it's interlaced ptr (nok++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
102 if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
103 (++nok) > max)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
104 break;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
105 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
106 else if (mpi->bpp < 24) // RGB/BGR 16 - check all colors
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
107 for (i = 0; i < rowsize; i++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
108 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
109 n1 = cur[0] + (cur[1]<<8);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
110 n2 = prv[0] + (prv[1]<<8);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
111 if ((n1&0x1f) - (n2&0x1f) > diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
112 ((n1>>5)&0x3f) - ((n2>>5)&0x3f) > diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
113 ((n1>>11)&0x1f) - ((n2>>11)&0x1f) > diff)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
114 row0[i] = 1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
115 else if ((n1&0x1f) - (n2&0x1f) < -diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
116 ((n1>>5)&0x3f) - ((n2>>5)&0x3f) < -diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
117 ((n1>>11)&0x1f) - ((n2>>11)&0x1f) < -diff)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
118 row0[i] = -1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
119 else
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
120 row0[i] = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
121 cur += 2;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
122 prv += 2;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
123 // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
124 // but row3 is 1 so it's interlaced ptr (nok++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
125 if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
126 (++nok) > max)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
127 break;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
128 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
129 else // RGB/BGR 24/32
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
130 for (i = 0; i < rowsize; i++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
131 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
132 if (cur[0] - prv[0] > diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
133 cur[1] - prv[1] > diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
134 cur[2] - prv[2] > diff)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
135 row0[i] = 1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
136 else if (prv[0] - cur[0] > diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
137 prv[1] - cur[1] > diff ||
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
138 prv[2] - cur[2] > diff)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
139 row0[i] = -1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
140 else
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
141 row0[i] = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
142 cur += mpi->bpp/8;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
143 prv += mpi->bpp/8;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
144 // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
145 // but row3 is 1 so it's interlaced ptr (nok++)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
146 if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
147 (++nok) > max)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
148 break;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
149 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
150 cur0 += mpi->stride[0];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
151 prv0 += mpi->stride[0];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
152 // rotate rows
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
153 cur = row2;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
154 row2 = row1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
155 row1 = row0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
156 row0 = cur;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
157 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
158 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
159 // check if number of interlaced is above of max
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
160 if (nok > max)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
161 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
162 // vf->priv->dfr++;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
163 if (vf->priv->was_dint < 1) // can skip at most one frame!
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
164 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
165 vf->priv->was_dint++;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
166 // vf->priv->rdfr++;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
167 // mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
168 return 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
169 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
170 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
171 vf->priv->was_dint = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
172 // mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
173 return vf_next_put_image (vf, mpi);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
174 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
175
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
176 static int open (vf_instance_t *vf, char* args){
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
177 vf->config = config;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
178 vf->put_image = put_image;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
179 // vf->default_reqs=VFCAP_ACCEPT_STRIDE;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
180 vf->priv = malloc (sizeof(struct vf_priv_s));
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
181 vf->priv->sense = 0.01;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
182 vf->priv->level = 0.15;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
183 vf->priv->pmpi = NULL;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
184 if (args)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
185 sscanf (args, "%f:%f", &vf->priv->sense, &vf->priv->level);
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
186 return 1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
187 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
188
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
189 vf_info_t vf_info_dint = {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
190 "drop interlaced frames",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
191 "dint",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
192 "A.G.",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
193 "",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
194 open
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
195 };