comparison libmpcodecs/vf_crop.c @ 6060:61f39b98ba4d

keep aspect ratio - based on Fredrik Kuivinen's idea
author arpi
date Sun, 12 May 2002 19:06:15 +0000
parents b2b1942b16d5
children a894e99c1e51
comparison
equal deleted inserted replaced
6059:c0ae8c0eda72 6060:61f39b98ba4d
11 struct vf_priv_s { 11 struct vf_priv_s {
12 int crop_w,crop_h; 12 int crop_w,crop_h;
13 int crop_x,crop_y; 13 int crop_x,crop_y;
14 }; 14 };
15 15
16 extern int opt_screen_size_x;
17 extern int opt_screen_size_y;
18
16 //===========================================================================// 19 //===========================================================================//
17 20
18 static int config(struct vf_instance_s* vf, 21 static int config(struct vf_instance_s* vf,
19 int width, int height, int d_width, int d_height, 22 int width, int height, int d_width, int d_height,
20 unsigned int flags, unsigned int outfmt){ 23 unsigned int flags, unsigned int outfmt){
21 int ret;
22 printf("crop->config() called\n");
23 // calculate the missing parameters: 24 // calculate the missing parameters:
24 if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width; 25 if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width;
25 if(vf->priv->crop_h<=0 || vf->priv->crop_h>height) vf->priv->crop_h=height; 26 if(vf->priv->crop_h<=0 || vf->priv->crop_h>height) vf->priv->crop_h=height;
26 if(vf->priv->crop_x<0) vf->priv->crop_x=(width-vf->priv->crop_w)/2; 27 if(vf->priv->crop_x<0) vf->priv->crop_x=(width-vf->priv->crop_w)/2;
27 if(vf->priv->crop_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2; 28 if(vf->priv->crop_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2;
28 // check: 29 // check:
29 if(vf->priv->crop_w+vf->priv->crop_x>width) return 0; // bad width 30 if(vf->priv->crop_w+vf->priv->crop_x>width ||
30 if(vf->priv->crop_h+vf->priv->crop_y>height) return 0; // bad height 31 vf->priv->crop_h+vf->priv->crop_y>height){
31 ret=vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt); 32 printf("crop: bad position/width/height - cropped area is out of the original!\n");
32 printf("crop->config() return %d\n",ret); 33 return 0;
33 return ret; 34 }
35 if(!opt_screen_size_x && !opt_screen_size_y){
36 d_width=d_width*vf->priv->crop_w/width;
37 d_height=d_height*vf->priv->crop_h/height;
38 }
39 return vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt);
34 } 40 }
35 41
36 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ 42 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
37 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, 43 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
38 MP_IMGTYPE_EXPORT, 0, 44 MP_IMGTYPE_EXPORT, 0,