10l initial patch by Oded Shimon <ods15 at ods15.dyndns.org>
[mplayer/greg.git] / libmpcodecs / vf_yuvcsp.c
blob387f2f8011a2f9a7a00faefc4c1ad55a5c765c3f
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){
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);
64 //===========================================================================//
66 static void uninit(struct vf_instance_s* vf){
67 free(vf->priv);
70 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
71 switch(fmt){
72 case IMGFMT_YV12:
73 case IMGFMT_I420:
74 case IMGFMT_IYUV:
75 return 1;
77 return 0;
80 static int open(vf_instance_t *vf, char* args){
81 vf->config=config;
82 vf->put_image=put_image;
83 // vf->uninit=uninit;
84 vf->query_format=query_format;
85 // vf->priv=calloc(1, sizeof(struct vf_priv_s));
86 // if (args)
87 // vf->priv->csp = atoi(args);
88 return 1;
91 vf_info_t vf_info_yuvcsp = {
92 "yuv colorspace converter",
93 "yuvcsp",
94 "Alex Beregszaszi",
95 "",
96 open,
97 NULL
100 //===========================================================================//