00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <inttypes.h>
00023
00024 #include "config.h"
00025 #include "mp_msg.h"
00026
00027 #include "img_format.h"
00028 #include "mp_image.h"
00029 #include "vf.h"
00030
00031 struct vf_priv_s {
00032 int csp;
00033 };
00034
00035
00036
00037 static int config(struct vf_instance *vf,
00038 int width, int height, int d_width, int d_height,
00039 unsigned int flags, unsigned int outfmt){
00040 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
00041 }
00042
00043 static inline int clamp_y(int x){
00044 return (x > 235) ? 235 : (x < 16) ? 16 : x;
00045 }
00046
00047 static inline int clamp_c(int x){
00048 return (x > 240) ? 240 : (x < 16) ? 16 : x;
00049 }
00050
00051 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00052 int i,j;
00053 uint8_t *y_in, *cb_in, *cr_in;
00054 uint8_t *y_out, *cb_out, *cr_out;
00055
00056 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
00057 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
00058 mpi->width, mpi->height);
00059
00060 y_in = mpi->planes[0];
00061 cb_in = mpi->planes[1];
00062 cr_in = mpi->planes[2];
00063
00064 y_out = vf->dmpi->planes[0];
00065 cb_out = vf->dmpi->planes[1];
00066 cr_out = vf->dmpi->planes[2];
00067
00068 for (i = 0; i < mpi->height; i++)
00069 for (j = 0; j < mpi->width; j++)
00070 y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]);
00071
00072 for (i = 0; i < mpi->chroma_height; i++)
00073 for (j = 0; j < mpi->chroma_width; j++)
00074 {
00075 cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]);
00076 cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]);
00077 }
00078
00079 return vf_next_put_image(vf,vf->dmpi, pts);
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static int query_format(struct vf_instance *vf, unsigned int fmt){
00091 switch(fmt){
00092 case IMGFMT_YV12:
00093 case IMGFMT_I420:
00094 case IMGFMT_IYUV:
00095 return 1;
00096 }
00097 return 0;
00098 }
00099
00100 static int vf_open(vf_instance_t *vf, char *args){
00101 vf->config=config;
00102 vf->put_image=put_image;
00103
00104 vf->query_format=query_format;
00105
00106
00107
00108 return 1;
00109 }
00110
00111 const vf_info_t vf_info_yuvcsp = {
00112 "yuv colorspace converter",
00113 "yuvcsp",
00114 "Alex Beregszaszi",
00115 "",
00116 vf_open,
00117 NULL
00118 };
00119
00120