Statistics
| Branch: | Revision:

ffmpeg / libavfilter / libmpcodecs / vf_telecine.c @ e4852fb3

History | View | Annotate | Download (4.95 KB)

1
/*
2
 * This file is part of MPlayer.
3
 *
4
 * MPlayer is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * MPlayer is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License along
15
 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 */
18

    
19
#include <stdio.h>
20
#include <stdlib.h>
21
#include <string.h>
22

    
23
#include "config.h"
24
#include "mp_msg.h"
25

    
26
#include "img_format.h"
27
#include "mp_image.h"
28
#include "vf.h"
29

    
30
#include "libvo/fastmemcpy.h"
31

    
32
struct vf_priv_s {
33
    int frame;
34
};
35

    
36
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
37
{
38
    mp_image_t *dmpi;
39
    int ret;
40

    
41
    vf->priv->frame = (vf->priv->frame+1)%4;
42

    
43
    dmpi = vf_get_image(vf->next, mpi->imgfmt,
44
        MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
45
        MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
46

    
47
    ret = 0;
48
    //    0/0  1/1  2/2  2/3  3/0
49
    switch (vf->priv->frame) {
50
    case 0:
51
        my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
52
            mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
53
            dmpi->stride[0]*2, mpi->stride[0]*2);
54
        if (mpi->flags & MP_IMGFLAG_PLANAR) {
55
            my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
56
                mpi->planes[1]+mpi->stride[1],
57
                mpi->chroma_width, mpi->chroma_height/2,
58
                dmpi->stride[1]*2, mpi->stride[1]*2);
59
            my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
60
                mpi->planes[2]+mpi->stride[2],
61
                mpi->chroma_width, mpi->chroma_height/2,
62
                dmpi->stride[2]*2, mpi->stride[2]*2);
63
        }
64
        ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
65
    case 1:
66
    case 2:
67
        memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
68
            dmpi->stride[0], mpi->stride[0]);
69
        if (mpi->flags & MP_IMGFLAG_PLANAR) {
70
            memcpy_pic(dmpi->planes[1], mpi->planes[1],
71
                mpi->chroma_width, mpi->chroma_height,
72
                dmpi->stride[1], mpi->stride[1]);
73
            memcpy_pic(dmpi->planes[2], mpi->planes[2],
74
                mpi->chroma_width, mpi->chroma_height,
75
                dmpi->stride[2], mpi->stride[2]);
76
        }
77
        return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret;
78
    case 3:
79
        my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
80
            mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
81
            dmpi->stride[0]*2, mpi->stride[0]*2);
82
        if (mpi->flags & MP_IMGFLAG_PLANAR) {
83
            my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
84
                mpi->planes[1]+mpi->stride[1],
85
                mpi->chroma_width, mpi->chroma_height/2,
86
                dmpi->stride[1]*2, mpi->stride[1]*2);
87
            my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
88
                mpi->planes[2]+mpi->stride[2],
89
                mpi->chroma_width, mpi->chroma_height/2,
90
                dmpi->stride[2]*2, mpi->stride[2]*2);
91
        }
92
        ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
93
        my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
94
            dmpi->stride[0]*2, mpi->stride[0]*2);
95
        if (mpi->flags & MP_IMGFLAG_PLANAR) {
96
            my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
97
                mpi->chroma_width, mpi->chroma_height/2,
98
                dmpi->stride[1]*2, mpi->stride[1]*2);
99
            my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
100
                mpi->chroma_width, mpi->chroma_height/2,
101
                dmpi->stride[2]*2, mpi->stride[2]*2);
102
        }
103
        return ret;
104
    }
105
    return 0;
106
}
107

    
108
#if 0
109
static int query_format(struct vf_instance *vf, unsigned int fmt)
110
{
111
    /* FIXME - figure out which other formats work */
112
    switch (fmt) {
113
    case IMGFMT_YV12:
114
    case IMGFMT_IYUV:
115
    case IMGFMT_I420:
116
        return vf_next_query_format(vf, fmt);
117
    }
118
    return 0;
119
}
120

121
static int config(struct vf_instance *vf,
122
        int width, int height, int d_width, int d_height,
123
    unsigned int flags, unsigned int outfmt)
124
{
125
    return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
126
}
127
#endif
128

    
129
static void uninit(struct vf_instance *vf)
130
{
131
    free(vf->priv);
132
}
133

    
134
static int vf_open(vf_instance_t *vf, char *args)
135
{
136
    //vf->config = config;
137
    vf->put_image = put_image;
138
    //vf->query_format = query_format;
139
    vf->uninit = uninit;
140
    vf->default_reqs = VFCAP_ACCEPT_STRIDE;
141
    vf->priv = calloc(1, sizeof(struct vf_priv_s));
142
    vf->priv->frame = 1;
143
    if (args) sscanf(args, "%d", &vf->priv->frame);
144
    vf->priv->frame--;
145
    return 1;
146
}
147

    
148
const vf_info_t vf_info_telecine = {
149
    "telecine filter",
150
    "telecine",
151
    "Rich Felker",
152
    "",
153
    vf_open,
154
    NULL
155
};