Add support for VDPAU video out, including hardware decoding.
[mplayer/glamo.git] / libmpcodecs / vf_yuvcsp.c
blob1cb6a187f50dd6b2b2cc72ec1d2cbf6c92a3795f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "config.h"
7 #include "mp_msg.h"
9 #include "img_format.h"
10 #include "mp_image.h"
11 #include "vf.h"
13 struct vf_priv_s {
14 int csp;
17 //===========================================================================//
19 static int config(struct vf_instance_s* vf,
20 int width, int height, int d_width, int d_height,
21 unsigned int flags, unsigned int outfmt){
22 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
25 static inline int clamp_y(int x){
26 return (x > 235) ? 235 : (x < 16) ? 16 : x;
29 static inline int clamp_c(int x){
30 return (x > 240) ? 240 : (x < 16) ? 16 : x;
33 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
34 int i,j;
35 uint8_t *y_in, *cb_in, *cr_in;
36 uint8_t *y_out, *cb_out, *cr_out;
38 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
39 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
40 mpi->width, mpi->height);
42 y_in = mpi->planes[0];
43 cb_in = mpi->planes[1];
44 cr_in = mpi->planes[2];
46 y_out = vf->dmpi->planes[0];
47 cb_out = vf->dmpi->planes[1];
48 cr_out = vf->dmpi->planes[2];
50 for (i = 0; i < mpi->height; i++)
51 for (j = 0; j < mpi->width; j++)
52 y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]);
54 for (i = 0; i < mpi->chroma_height; i++)
55 for (j = 0; j < mpi->chroma_width; j++)
57 cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]);
58 cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]);
61 return vf_next_put_image(vf,vf->dmpi, pts);
64 //===========================================================================//
67 static void uninit(struct vf_instance_s* vf){
68 free(vf->priv);
72 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
73 switch(fmt){
74 case IMGFMT_YV12:
75 case IMGFMT_I420:
76 case IMGFMT_IYUV:
77 return 1;
79 return 0;
82 static int open(vf_instance_t *vf, char* args){
83 vf->config=config;
84 vf->put_image=put_image;
85 // vf->uninit=uninit;
86 vf->query_format=query_format;
87 // vf->priv=calloc(1, sizeof(struct vf_priv_s));
88 // if (args)
89 // vf->priv->csp = atoi(args);
90 return 1;
93 const vf_info_t vf_info_yuvcsp = {
94 "yuv colorspace converter",
95 "yuvcsp",
96 "Alex Beregszaszi",
97 "",
98 open,
99 NULL
102 //===========================================================================//