annotate libmpcodecs/vf_dint.c @ 32906:b623edea8e3c

Use samplefmt2affmt helper function in ad_ffmpeg.c
author reimar
date Tue, 01 Mar 2011 21:48:04 +0000
parents 7af3e6f901fd
children d494a6d78677
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
18
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
19 #include <stdio.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
20 #include <stdlib.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
21 #include <string.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
22 #include <inttypes.h>
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
23
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16125
diff changeset
24 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16125
diff changeset
25 #include "mp_msg.h"
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
26
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
27 #include "mp_image.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
28 #include "img_format.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
29 #include "vf.h"
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
30
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
31 struct vf_priv_s {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
32 float sense; // first parameter
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
33 float level; // second parameter
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
34 unsigned int imgfmt;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
35 char diff;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
36 uint32_t max;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
37 // int dfr;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
38 // int rdfr;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
39 int was_dint;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
40 mp_image_t *pmpi; // previous mpi
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
41 };
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
42
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
43 #define MAXROWSIZE 1200
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
44
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
45 static int config (struct vf_instance *vf,
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
46 int width, int height, int d_width, int d_height,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
47 unsigned int flags, unsigned int outfmt)
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
48 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
49 int rowsize;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
50
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
51 vf->priv->pmpi = vf_get_image (vf->next, outfmt, MP_IMGTYPE_TEMP,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
52 0, width, height);
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
53 if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) &&
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
54 outfmt != IMGFMT_RGB32 && outfmt != IMGFMT_BGR32 &&
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
55 outfmt != IMGFMT_RGB24 && outfmt != IMGFMT_BGR24 &&
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
56 outfmt != IMGFMT_RGB16 && outfmt != IMGFMT_BGR16)
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
57 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
58 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
59 return 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
60 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
61 vf->priv->imgfmt = outfmt;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
62 // recalculate internal values
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
63 rowsize = vf->priv->pmpi->width;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
64 if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
65 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
66 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
67 vf->priv->diff = vf->priv->sense * 256;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
68 else
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
69 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
70 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
71 if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) &&
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
72 vf->priv->pmpi->bpp < 24 && vf->priv->diff > 31)
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
73 vf->priv->diff = 31;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
74 mp_msg (MSGT_VFILTER, MSGL_INFO, "Drop-interlaced: %dx%d diff %d / level %u\n",
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
75 vf->priv->pmpi->width, vf->priv->pmpi->height,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
76 (int)vf->priv->diff, (unsigned int)vf->priv->max);
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
77 // vf->priv->rdfr = vf->priv->dfr = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
78 vf->priv->was_dint = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
79 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
80 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
81
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
82 static int put_image (struct vf_instance *vf, mp_image_t *mpi, double pts)
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
83 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
84 char rrow0[MAXROWSIZE];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
85 char rrow1[MAXROWSIZE];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
86 char rrow2[MAXROWSIZE];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
87 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
88 int rowsize = mpi->width;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
89 uint32_t nok = 0, max = vf->priv->max;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
90 int diff = vf->priv->diff;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
91 int i, j;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
92 register int n1, n2;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
93 unsigned char *cur0, *prv0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
94 register unsigned char *cur, *prv;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
95
16125
e2bcf37fe028 Fix crash with large images
reimar
parents: 9593
diff changeset
96 if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE;
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
97 // check if nothing to do
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
98 if (mpi->imgfmt == vf->priv->imgfmt)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
99 {
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
100 cur0 = mpi->planes[0] + mpi->stride[0];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
101 prv0 = mpi->planes[0];
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
102 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
103 {
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
104 cur = cur0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
105 prv = prv0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
106 // analyse row (row0)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
107 if (mpi->flags & MP_IMGFLAG_PLANAR) // planar YUV - check luminance
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
108 for (i = 0; i < rowsize; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
109 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
110 if (cur[0] - prv[0] > diff)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
111 row0[i] = 1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
112 else if (cur[0] - prv[0] < -diff)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
113 row0[i] = -1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
114 else
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
115 row0[i] = 0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
116 cur++;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
117 prv++;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
118 // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
119 // but row3 is 1 so it's interlaced ptr (nok++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
120 if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
121 (++nok) > max)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
122 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
123 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
124 else if (mpi->bpp < 24) // RGB/BGR 16 - check all colors
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
125 for (i = 0; i < rowsize; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
126 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
127 n1 = cur[0] + (cur[1]<<8);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
128 n2 = prv[0] + (prv[1]<<8);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
129 if ((n1&0x1f) - (n2&0x1f) > diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
130 ((n1>>5)&0x3f) - ((n2>>5)&0x3f) > diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
131 ((n1>>11)&0x1f) - ((n2>>11)&0x1f) > diff)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
132 row0[i] = 1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
133 else if ((n1&0x1f) - (n2&0x1f) < -diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
134 ((n1>>5)&0x3f) - ((n2>>5)&0x3f) < -diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
135 ((n1>>11)&0x1f) - ((n2>>11)&0x1f) < -diff)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
136 row0[i] = -1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
137 else
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
138 row0[i] = 0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
139 cur += 2;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
140 prv += 2;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
141 // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
142 // but row3 is 1 so it's interlaced ptr (nok++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
143 if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
144 (++nok) > max)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
145 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
146 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
147 else // RGB/BGR 24/32
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
148 for (i = 0; i < rowsize; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
149 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
150 if (cur[0] - prv[0] > diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
151 cur[1] - prv[1] > diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
152 cur[2] - prv[2] > diff)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
153 row0[i] = 1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
154 else if (prv[0] - cur[0] > diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
155 prv[1] - cur[1] > diff ||
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
156 prv[2] - cur[2] > diff)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
157 row0[i] = -1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
158 else
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
159 row0[i] = 0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
160 cur += mpi->bpp/8;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
161 prv += mpi->bpp/8;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
162 // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
163 // but row3 is 1 so it's interlaced ptr (nok++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
164 if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
165 (++nok) > max)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
166 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
167 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
168 cur0 += mpi->stride[0];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
169 prv0 += mpi->stride[0];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
170 // rotate rows
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
171 cur = row2;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
172 row2 = row1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
173 row1 = row0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
174 row0 = cur;
7369
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 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
177 // 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
178 if (nok > max)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
179 {
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
180 // vf->priv->dfr++;
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
181 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
182 {
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
183 vf->priv->was_dint++;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
184 // vf->priv->rdfr++;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
185 // mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
186 return 0;
7369
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->priv->was_dint = 0;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
190 // mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr);
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
191 return vf_next_put_image (vf, mpi, pts);
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
192 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
193
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
194 static int vf_open(vf_instance_t *vf, char *args){
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
195 vf->config = config;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
196 vf->put_image = put_image;
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
197 // vf->default_reqs=VFCAP_ACCEPT_STRIDE;
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
198 vf->priv = malloc (sizeof(struct vf_priv_s));
7631
04a6df4fb976 I found that default isn't optimal so it's changed a bit. :)
arpi
parents: 7369
diff changeset
199 vf->priv->sense = 0.1;
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
200 vf->priv->level = 0.15;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
201 vf->priv->pmpi = NULL;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
202 if (args)
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
203 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
204 return 1;
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
205 }
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
206
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 23373
diff changeset
207 const vf_info_t vf_info_dint = {
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
208 "drop interlaced frames",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
209 "dint",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
210 "A.G.",
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
211 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
212 vf_open,
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7631
diff changeset
213 NULL
7369
b34b005ab4f8 drop-deinterlace (dint) filter by Andriy N. Gritsenko <andrej@lucky.net>
arpi
parents:
diff changeset
214 };