comparison libmpcodecs/vf_expand.c @ 5507:d0d029fda134

video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
author arpi
date Sat, 06 Apr 2002 22:05:01 +0000
parents
children e974e82be748
comparison
equal deleted inserted replaced
5506:b8b6fcb5062a 5507:d0d029fda134
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "../config.h"
6 #include "../mp_msg.h"
7
8 #include "../mp_image.h"
9 #include "vf.h"
10
11 #include "../libvo/fastmemcpy.h"
12
13 struct vf_priv_s {
14 int exp_w,exp_h;
15 int exp_x,exp_y;
16 mp_image_t *dmpi;
17 };
18
19 //===========================================================================//
20
21 static int config(struct vf_instance_s* vf,
22 int width, int height, int d_width, int d_height,
23 unsigned int flags, unsigned int outfmt){
24 int ret;
25 // calculate the missing parameters:
26 if(vf->priv->exp_w<width) vf->priv->exp_w=width;
27 if(vf->priv->exp_h<height) vf->priv->exp_h=height;
28 if(vf->priv->exp_x<0) vf->priv->exp_x=(vf->priv->exp_w-width)/2;
29 if(vf->priv->exp_y<0) vf->priv->exp_y=(vf->priv->exp_h-height)/2;
30 // check:
31 // if(vf->priv->exp_w+vf->priv->exp_x>width) return 0; // bad width
32 // if(vf->priv->exp_h+vf->priv->exp_y>height) return 0; // bad height
33 ret=vf_next_config(vf,vf->priv->exp_w,vf->priv->exp_h,d_width,d_height,flags,outfmt);
34 return ret;
35 }
36
37 // there are 4 cases:
38 // codec --DR--> expand --DR--> vo
39 // codec --DR--> expand -copy-> vo
40 // codec -copy-> expand --DR--> vo
41 // codec -copy-> expand -copy-> vo (worst case)
42
43 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
44 if(vf->priv->exp_w==mpi->width ||
45 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)) ){
46 // try full DR !
47 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt,
48 mpi->type, mpi->flags, vf->priv->exp_w, vf->priv->exp_h);
49 // set up mpi as a cropped-down image of dmpi:
50 if(mpi->flags&MP_IMGFLAG_PLANAR){
51 mpi->planes[0]=vf->priv->dmpi->planes[0]+
52 vf->priv->exp_y*vf->priv->dmpi->stride[0]+vf->priv->exp_x;
53 mpi->planes[1]=vf->priv->dmpi->planes[1]+
54 (vf->priv->exp_y>>1)*vf->priv->dmpi->stride[1]+(vf->priv->exp_x>>1);
55 mpi->planes[2]=vf->priv->dmpi->planes[2]+
56 (vf->priv->exp_y>>1)*vf->priv->dmpi->stride[2]+(vf->priv->exp_x>>1);
57 mpi->stride[0]=vf->priv->dmpi->stride[0];
58 mpi->stride[1]=vf->priv->dmpi->stride[1];
59 mpi->stride[2]=vf->priv->dmpi->stride[2];
60 } else {
61 mpi->planes[0]=vf->priv->dmpi->planes[0]+
62 vf->priv->exp_y*vf->priv->dmpi->stride[0]+
63 vf->priv->exp_x*(vf->priv->dmpi->bpp/8);
64 mpi->stride[0]=vf->priv->dmpi->stride[0];
65 }
66 mpi->flags|=MP_IMGFLAG_DIRECT;
67 }
68 }
69
70 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
71 if(mpi->flags&MP_IMGFLAG_DIRECT){
72 vf_next_put_image(vf,vf->priv->dmpi);
73 return; // we've used DR, so we're ready...
74 }
75
76 // hope we'll get DR buffer:
77 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt,
78 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
79 vf->priv->exp_w, vf->priv->exp_h);
80
81 // copy mpi->dmpi...
82 if(mpi->flags&MP_IMGFLAG_PLANAR){
83 memcpy_pic(vf->priv->dmpi->planes[0]+
84 vf->priv->exp_y*vf->priv->dmpi->stride[0]+vf->priv->exp_x,
85 mpi->planes[0], mpi->w, mpi->h,
86 vf->priv->dmpi->stride[0],mpi->stride[0]);
87 memcpy_pic(vf->priv->dmpi->planes[1]+
88 (vf->priv->exp_y>>1)*vf->priv->dmpi->stride[1]+(vf->priv->exp_x>>1),
89 mpi->planes[1], mpi->w>>1, mpi->h>>1,
90 vf->priv->dmpi->stride[1],mpi->stride[1]);
91 memcpy_pic(vf->priv->dmpi->planes[2]+
92 (vf->priv->exp_y>>1)*vf->priv->dmpi->stride[2]+(vf->priv->exp_x>>1),
93 mpi->planes[2], mpi->w>>1, mpi->h>>1,
94 vf->priv->dmpi->stride[2],mpi->stride[2]);
95 } else {
96 memcpy_pic(vf->priv->dmpi->planes[0]+
97 vf->priv->exp_y*vf->priv->dmpi->stride[0]+vf->priv->exp_x*(vf->priv->dmpi->bpp/8),
98 mpi->planes[0], mpi->w*(vf->priv->dmpi->bpp/8), mpi->h,
99 vf->priv->dmpi->stride[0],mpi->stride[0]);
100 }
101 vf_next_put_image(vf,vf->priv->dmpi);
102 }
103
104 //===========================================================================//
105
106 static int open(vf_instance_t *vf, char* args){
107 vf->config=config;
108 vf->get_image=get_image;
109 vf->put_image=put_image;
110 vf->priv=malloc(sizeof(struct vf_priv_s));
111 // TODO: parse args ->
112 vf->priv->exp_x=
113 vf->priv->exp_y=
114 vf->priv->exp_w=
115 vf->priv->exp_h=-1;
116 if(args) sscanf(args, "%d:%d:%d:%d",
117 &vf->priv->exp_w,
118 &vf->priv->exp_h,
119 &vf->priv->exp_x,
120 &vf->priv->exp_y);
121 printf("Expand: %d x %d, %d ; %d\n",
122 vf->priv->exp_w,
123 vf->priv->exp_h,
124 vf->priv->exp_x,
125 vf->priv->exp_y);
126 return 1;
127 }
128
129 vf_info_t vf_info_expand = {
130 "expanding",
131 "expand",
132 "A'rpi",
133 "",
134 open
135 };
136
137 //===========================================================================//