comparison libmpcodecs/vf_crop.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 0b301fec999a
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 struct vf_priv_s {
12 int crop_w,crop_h;
13 int crop_x,crop_y;
14 };
15
16 //===========================================================================//
17
18 static int config(struct vf_instance_s* vf,
19 int width, int height, int d_width, int d_height,
20 unsigned int flags, unsigned int outfmt){
21 int ret;
22 printf("crop->config() called\n");
23 // 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_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_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2;
28 // check:
29 if(vf->priv->crop_w+vf->priv->crop_x>width) return 0; // bad width
30 if(vf->priv->crop_h+vf->priv->crop_y>height) return 0; // bad height
31 ret=vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt);
32 printf("crop->config() return %d\n",ret);
33 return ret;
34 }
35
36 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,
38 MP_IMGTYPE_EXPORT, 0,
39 vf->priv->crop_w, vf->priv->crop_h);
40 if(mpi->flags&MP_IMGFLAG_PLANAR){
41 dmpi->planes[0]=mpi->planes[0]+
42 vf->priv->crop_y*mpi->stride[0]+vf->priv->crop_x;
43 dmpi->planes[1]=mpi->planes[1]+
44 (vf->priv->crop_y>>1)*mpi->stride[1]+(vf->priv->crop_x>>1);
45 dmpi->planes[2]=mpi->planes[2]+
46 (vf->priv->crop_y>>1)*mpi->stride[2]+(vf->priv->crop_x>>1);
47 dmpi->stride[0]=mpi->stride[0];
48 dmpi->stride[1]=mpi->stride[1];
49 dmpi->stride[2]=mpi->stride[2];
50 } else {
51 dmpi->planes[0]=mpi->planes[0]+
52 vf->priv->crop_y*mpi->stride[0]+
53 vf->priv->crop_x*(mpi->bpp/8);
54 dmpi->stride[0]=mpi->stride[0];
55 }
56 vf_next_put_image(vf,dmpi);
57 }
58
59 //===========================================================================//
60
61 static int open(vf_instance_t *vf, char* args){
62 vf->config=config;
63 vf->put_image=put_image;
64 vf->priv=malloc(sizeof(struct vf_priv_s));
65 // TODO: parse args ->
66 vf->priv->crop_x=
67 vf->priv->crop_y=
68 vf->priv->crop_w=
69 vf->priv->crop_h=-1;
70 if(args) sscanf(args, "%d:%d:%d:%d",
71 &vf->priv->crop_w,
72 &vf->priv->crop_h,
73 &vf->priv->crop_x,
74 &vf->priv->crop_y);
75 printf("Crop: %d x %d, %d ; %d\n",
76 vf->priv->crop_w,
77 vf->priv->crop_h,
78 vf->priv->crop_x,
79 vf->priv->crop_y);
80 return 1;
81 }
82
83 vf_info_t vf_info_crop = {
84 "cropping",
85 "crop",
86 "A'rpi",
87 "",
88 open
89 };
90
91 //===========================================================================//