Statistics
| Branch: | Revision:

ffmpeg / libavfilter / libmpcodecs / vf_yuvcsp.c @ e4852fb3

History | View | Annotate | Download (3.22 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
#include <inttypes.h>
23

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

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

    
31
struct vf_priv_s {
32
    int csp;
33
};
34

    
35
//===========================================================================//
36

    
37
static int config(struct vf_instance *vf,
38
        int width, int height, int d_width, int d_height,
39
        unsigned int flags, unsigned int outfmt){
40
    return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
41
}
42

    
43
static inline int clamp_y(int x){
44
    return (x > 235) ? 235 : (x < 16) ? 16 : x;
45
}
46

    
47
static inline int clamp_c(int x){
48
    return (x > 240) ? 240 : (x < 16) ? 16 : x;
49
}
50

    
51
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
52
    int i,j;
53
    uint8_t *y_in, *cb_in, *cr_in;
54
    uint8_t *y_out, *cb_out, *cr_out;
55

    
56
    vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
57
        MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
58
        mpi->width, mpi->height);
59

    
60
    y_in = mpi->planes[0];
61
    cb_in = mpi->planes[1];
62
    cr_in = mpi->planes[2];
63

    
64
    y_out = vf->dmpi->planes[0];
65
    cb_out = vf->dmpi->planes[1];
66
    cr_out = vf->dmpi->planes[2];
67

    
68
    for (i = 0; i < mpi->height; i++)
69
        for (j = 0; j < mpi->width; j++)
70
            y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]);
71

    
72
    for (i = 0; i < mpi->chroma_height; i++)
73
        for (j = 0; j < mpi->chroma_width; j++)
74
        {
75
            cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]);
76
            cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]);
77
        }
78

    
79
    return vf_next_put_image(vf,vf->dmpi, pts);
80
}
81

    
82
//===========================================================================//
83

    
84
/*
85
static void uninit(struct vf_instance *vf){
86
        free(vf->priv);
87
}
88
*/
89

    
90
static int query_format(struct vf_instance *vf, unsigned int fmt){
91
    switch(fmt){
92
        case IMGFMT_YV12:
93
        case IMGFMT_I420:
94
        case IMGFMT_IYUV:
95
            return 1;
96
    }
97
    return 0;
98
}
99

    
100
static int vf_open(vf_instance_t *vf, char *args){
101
    vf->config=config;
102
    vf->put_image=put_image;
103
//    vf->uninit=uninit;
104
    vf->query_format=query_format;
105
//    vf->priv=calloc(1, sizeof(struct vf_priv_s));
106
//    if (args)
107
//        vf->priv->csp = atoi(args);
108
    return 1;
109
}
110

    
111
const vf_info_t vf_info_yuvcsp = {
112
    "yuv colorspace converter",
113
    "yuvcsp",
114
    "Alex Beregszaszi",
115
    "",
116
    vf_open,
117
    NULL
118
};
119

    
120
//===========================================================================//