Mercurial > mplayer.hg
annotate libmpcodecs/vf_crop.c @ 9861:178a3d9f2523
sync
author | gabucino |
---|---|
date | Sun, 06 Apr 2003 16:58:07 +0000 |
parents | 74e8cd83708f |
children | b2d257e35577 |
rev | line source |
---|---|
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
1 #include <stdio.h> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
2 #include <stdlib.h> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
3 #include <string.h> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
4 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
5 #include "../config.h" |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
6 #include "../mp_msg.h" |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
7 |
8802 | 8 #include "img_format.h" |
5607 | 9 #include "mp_image.h" |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
10 #include "vf.h" |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
11 |
9599 | 12 #include "m_option.h" |
13 #include "m_struct.h" | |
14 | |
15 static struct vf_priv_s { | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
16 int crop_w,crop_h; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
17 int crop_x,crop_y; |
9599 | 18 } vf_priv_dflt = { |
19 -1,-1, | |
20 -1,-1 | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
21 }; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
22 |
6060 | 23 extern int opt_screen_size_x; |
24 extern int opt_screen_size_y; | |
25 | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
26 //===========================================================================// |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
27 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
28 static int config(struct vf_instance_s* vf, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
29 int width, int height, int d_width, int d_height, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
30 unsigned int flags, unsigned int outfmt){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
31 // calculate the missing parameters: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
32 if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
33 if(vf->priv->crop_h<=0 || vf->priv->crop_h>height) vf->priv->crop_h=height; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
34 if(vf->priv->crop_x<0) vf->priv->crop_x=(width-vf->priv->crop_w)/2; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
35 if(vf->priv->crop_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2; |
8801
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
36 // rounding: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
37 if(!IMGFMT_IS_RGB(outfmt) && !IMGFMT_IS_BGR(outfmt)){ |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
38 switch(outfmt){ |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
39 case IMGFMT_444P: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
40 case IMGFMT_Y800: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
41 case IMGFMT_Y8: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
42 break; |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
43 case IMGFMT_YVU9: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
44 case IMGFMT_IF09: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
45 vf->priv->crop_y&=~3; |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
46 case IMGFMT_411P: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
47 vf->priv->crop_x&=~3; |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
48 break; |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
49 case IMGFMT_YV12: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
50 case IMGFMT_I420: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
51 case IMGFMT_IYUV: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
52 vf->priv->crop_y&=~1; |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
53 default: |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
54 vf->priv->crop_x&=~1; |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
55 } |
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
56 } |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
57 // check: |
6060 | 58 if(vf->priv->crop_w+vf->priv->crop_x>width || |
59 vf->priv->crop_h+vf->priv->crop_y>height){ | |
60 printf("crop: bad position/width/height - cropped area is out of the original!\n"); | |
61 return 0; | |
62 } | |
63 if(!opt_screen_size_x && !opt_screen_size_y){ | |
64 d_width=d_width*vf->priv->crop_w/width; | |
65 d_height=d_height*vf->priv->crop_h/height; | |
66 } | |
67 return vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt); | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
68 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
69 |
7368 | 70 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
71 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
72 MP_IMGTYPE_EXPORT, 0, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
73 vf->priv->crop_w, vf->priv->crop_h); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
74 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
75 dmpi->planes[0]=mpi->planes[0]+ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
76 vf->priv->crop_y*mpi->stride[0]+vf->priv->crop_x; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
77 dmpi->planes[1]=mpi->planes[1]+ |
8801
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
78 (vf->priv->crop_y>>mpi->chroma_y_shift)*mpi->stride[1]+(vf->priv->crop_x>>mpi->chroma_x_shift); |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
79 dmpi->planes[2]=mpi->planes[2]+ |
8801
db98910fea8f
- added x/y rounding for YUV formats (should be moved to mp_image.c|h later)
arpi
parents:
7368
diff
changeset
|
80 (vf->priv->crop_y>>mpi->chroma_y_shift)*mpi->stride[2]+(vf->priv->crop_x>>mpi->chroma_x_shift); |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
81 dmpi->stride[1]=mpi->stride[1]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
82 dmpi->stride[2]=mpi->stride[2]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
83 } else { |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
84 dmpi->planes[0]=mpi->planes[0]+ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
85 vf->priv->crop_y*mpi->stride[0]+ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
86 vf->priv->crop_x*(mpi->bpp/8); |
9279 | 87 dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
88 } |
5614 | 89 dmpi->stride[0]=mpi->stride[0]; |
90 dmpi->width=mpi->width; | |
7368 | 91 return vf_next_put_image(vf,dmpi); |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
92 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
93 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
94 //===========================================================================// |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
95 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
96 static int open(vf_instance_t *vf, char* args){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
97 vf->config=config; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
98 vf->put_image=put_image; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5507
diff
changeset
|
99 vf->default_reqs=VFCAP_ACCEPT_STRIDE; |
9599 | 100 if(!vf->priv) { |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
101 vf->priv=malloc(sizeof(struct vf_priv_s)); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
102 // TODO: parse args -> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
103 vf->priv->crop_x= |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
104 vf->priv->crop_y= |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
105 vf->priv->crop_w= |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
106 vf->priv->crop_h=-1; |
9599 | 107 } //if(!vf->priv) |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
108 if(args) sscanf(args, "%d:%d:%d:%d", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
109 &vf->priv->crop_w, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
110 &vf->priv->crop_h, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
111 &vf->priv->crop_x, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
112 &vf->priv->crop_y); |
8869
9df3c03b2ffe
use mp_msg for messages. prolly more filters need to be fixed like this too
rfelker
parents:
8802
diff
changeset
|
113 mp_msg(MSGT_VFILTER, MSGL_INFO, "Crop: %d x %d, %d ; %d\n", |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
114 vf->priv->crop_w, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
115 vf->priv->crop_h, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
116 vf->priv->crop_x, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
117 vf->priv->crop_y); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
118 return 1; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
119 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
120 |
9599 | 121 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) |
122 static m_option_t vf_opts_fields[] = { | |
9602 | 123 {"w", ST_OFF(crop_w), CONF_TYPE_INT, M_OPT_MIN,0 ,0, NULL}, |
124 {"h", ST_OFF(crop_h), CONF_TYPE_INT, M_OPT_MIN,0 ,0, NULL}, | |
125 {"x", ST_OFF(crop_x), CONF_TYPE_INT, M_OPT_MIN,-1 ,0, NULL}, | |
126 {"y", ST_OFF(crop_y), CONF_TYPE_INT, M_OPT_MIN,-1 ,0, NULL}, | |
9599 | 127 { NULL, NULL, 0, 0, 0, 0, NULL } |
128 }; | |
129 | |
130 static m_struct_t vf_opts = { | |
131 "crop", | |
132 sizeof(struct vf_priv_s), | |
133 &vf_priv_dflt, | |
134 vf_opts_fields | |
135 }; | |
136 | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
137 vf_info_t vf_info_crop = { |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
138 "cropping", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
139 "crop", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
140 "A'rpi", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
141 "", |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9279
diff
changeset
|
142 open, |
9599 | 143 &vf_opts |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
144 }; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
145 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
146 //===========================================================================// |