Add missing multiple inclusion guards.
[mplayer/glamo.git] / libmpcodecs / vf_il.c
blob63626aa4691fac6538824357bfce94c2b7facdf5
1 /*
2 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <inttypes.h>
25 #include <assert.h>
27 #include "config.h"
28 #include "mp_msg.h"
30 #ifdef HAVE_MALLOC_H
31 #include <malloc.h>
32 #endif
34 #include "img_format.h"
35 #include "mp_image.h"
36 #include "vf.h"
37 #include "libvo/fastmemcpy.h"
40 //===========================================================================//
42 typedef struct FilterParam{
43 int interleave;
44 int swap;
45 }FilterParam;
47 struct vf_priv_s {
48 FilterParam lumaParam;
49 FilterParam chromaParam;
52 /***************************************************************************/
54 static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){
55 const int a= swap;
56 const int b= 1-a;
57 const int m= h>>1;
58 int y;
60 switch(interleave){
61 case -1:
62 for(y=0; y < m; y++){
63 fast_memcpy(dst + dstStride* y , src + srcStride*(y*2 + a), w);
64 fast_memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w);
66 break;
67 case 0:
68 for(y=0; y < m; y++){
69 fast_memcpy(dst + dstStride* y*2 , src + srcStride*(y*2 + a), w);
70 fast_memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w);
72 break;
73 case 1:
74 for(y=0; y < m; y++){
75 fast_memcpy(dst + dstStride*(y*2+a), src + srcStride* y , w);
76 fast_memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w);
78 break;
82 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
83 int w;
84 FilterParam *luma = &vf->priv->lumaParam;
85 FilterParam *chroma= &vf->priv->chromaParam;
87 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
88 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
89 mpi->w,mpi->h);
91 if(mpi->flags&MP_IMGFLAG_PLANAR)
92 w= mpi->w;
93 else
94 w= mpi->w * mpi->bpp/8;
96 interleave(dmpi->planes[0], mpi->planes[0],
97 w, mpi->h, dmpi->stride[0], mpi->stride[0], luma->interleave, luma->swap);
99 if(mpi->flags&MP_IMGFLAG_PLANAR){
100 int cw= mpi->w >> mpi->chroma_x_shift;
101 int ch= mpi->h >> mpi->chroma_y_shift;
103 interleave(dmpi->planes[1], mpi->planes[1], cw,ch,
104 dmpi->stride[1], mpi->stride[1], chroma->interleave, luma->swap);
105 interleave(dmpi->planes[2], mpi->planes[2], cw,ch,
106 dmpi->stride[2], mpi->stride[2], chroma->interleave, luma->swap);
109 return vf_next_put_image(vf,dmpi, pts);
112 //===========================================================================//
114 static void parse(FilterParam *fp, char* args){
115 char *pos;
116 char *max= strchr(args, ':');
118 if(!max) max= args + strlen(args);
120 pos= strchr(args, 's');
121 if(pos && pos<max) fp->swap=1;
122 pos= strchr(args, 'i');
123 if(pos && pos<max) fp->interleave=1;
124 pos= strchr(args, 'd');
125 if(pos && pos<max) fp->interleave=-1;
128 static int open(vf_instance_t *vf, char* args){
130 vf->put_image=put_image;
131 // vf->get_image=get_image;
132 vf->priv=malloc(sizeof(struct vf_priv_s));
133 memset(vf->priv, 0, sizeof(struct vf_priv_s));
135 if(args)
137 char *arg2= strchr(args,':');
138 if(arg2) parse(&vf->priv->chromaParam, arg2+1);
139 parse(&vf->priv->lumaParam, args);
142 return 1;
145 const vf_info_t vf_info_il = {
146 "(de)interleave",
147 "il",
148 "Michael Niedermayer",
150 open,
151 NULL
154 //===========================================================================//