00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <inttypes.h>
00025 #include <assert.h>
00026
00027 #include "mp_msg.h"
00028 #include "img_format.h"
00029 #include "mp_image.h"
00030 #include "vf.h"
00031 #include "libvo/fastmemcpy.h"
00032
00033
00034
00035
00036 typedef struct FilterParam{
00037 int interleave;
00038 int swap;
00039 }FilterParam;
00040
00041 struct vf_priv_s {
00042 FilterParam lumaParam;
00043 FilterParam chromaParam;
00044 };
00045
00046
00047
00048 static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){
00049 const int a= swap;
00050 const int b= 1-a;
00051 const int m= h>>1;
00052 int y;
00053
00054 switch(interleave){
00055 case -1:
00056 for(y=0; y < m; y++){
00057 fast_memcpy(dst + dstStride* y , src + srcStride*(y*2 + a), w);
00058 fast_memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w);
00059 }
00060 break;
00061 case 0:
00062 for(y=0; y < m; y++){
00063 fast_memcpy(dst + dstStride* y*2 , src + srcStride*(y*2 + a), w);
00064 fast_memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w);
00065 }
00066 break;
00067 case 1:
00068 for(y=0; y < m; y++){
00069 fast_memcpy(dst + dstStride*(y*2+a), src + srcStride* y , w);
00070 fast_memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w);
00071 }
00072 break;
00073 }
00074 }
00075
00076 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00077 int w;
00078 FilterParam *luma = &vf->priv->lumaParam;
00079 FilterParam *chroma= &vf->priv->chromaParam;
00080
00081 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
00082 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
00083 mpi->w,mpi->h);
00084
00085 if(mpi->flags&MP_IMGFLAG_PLANAR)
00086 w= mpi->w;
00087 else
00088 w= mpi->w * mpi->bpp/8;
00089
00090 interleave(dmpi->planes[0], mpi->planes[0],
00091 w, mpi->h, dmpi->stride[0], mpi->stride[0], luma->interleave, luma->swap);
00092
00093 if(mpi->flags&MP_IMGFLAG_PLANAR){
00094 int cw= mpi->w >> mpi->chroma_x_shift;
00095 int ch= mpi->h >> mpi->chroma_y_shift;
00096
00097 interleave(dmpi->planes[1], mpi->planes[1], cw,ch,
00098 dmpi->stride[1], mpi->stride[1], chroma->interleave, luma->swap);
00099 interleave(dmpi->planes[2], mpi->planes[2], cw,ch,
00100 dmpi->stride[2], mpi->stride[2], chroma->interleave, luma->swap);
00101 }
00102
00103 return vf_next_put_image(vf,dmpi, pts);
00104 }
00105
00106
00107
00108 static void parse(FilterParam *fp, char* args){
00109 char *pos;
00110 char *max= strchr(args, ':');
00111
00112 if(!max) max= args + strlen(args);
00113
00114 pos= strchr(args, 's');
00115 if(pos && pos<max) fp->swap=1;
00116 pos= strchr(args, 'i');
00117 if(pos && pos<max) fp->interleave=1;
00118 pos= strchr(args, 'd');
00119 if(pos && pos<max) fp->interleave=-1;
00120 }
00121
00122 static int vf_open(vf_instance_t *vf, char *args){
00123
00124 vf->put_image=put_image;
00125
00126 vf->priv=malloc(sizeof(struct vf_priv_s));
00127 memset(vf->priv, 0, sizeof(struct vf_priv_s));
00128
00129 if(args)
00130 {
00131 char *arg2= strchr(args,':');
00132 if(arg2) parse(&vf->priv->chromaParam, arg2+1);
00133 parse(&vf->priv->lumaParam, args);
00134 }
00135
00136 return 1;
00137 }
00138
00139 const vf_info_t vf_info_il = {
00140 "(de)interleave",
00141 "il",
00142 "Michael Niedermayer",
00143 "",
00144 vf_open,
00145 NULL
00146 };
00147
00148