2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "libvo/fastmemcpy.h"
27 #include "libavutil/common.h"
34 config(struct vf_instance
* vf
,
35 int width
, int height
, int d_width
, int d_height
,
36 unsigned int flags
, unsigned int outfmt
)
38 if (vf
->priv
->w
< 0 || width
< vf
->priv
->w
)
40 if (vf
->priv
->h
< 0 || height
< vf
->priv
->h
)
43 vf
->priv
->x
= (width
- vf
->priv
->w
) / 2;
45 vf
->priv
->y
= (height
- vf
->priv
->h
) / 2;
46 if (vf
->priv
->w
+ vf
->priv
->x
> width
47 || vf
->priv
->h
+ vf
->priv
->y
> height
) {
48 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"rectangle: bad position/width/height - rectangle area is out of the original!\n");
51 return vf_next_config(vf
, width
, height
, d_width
, d_height
, flags
, outfmt
);
55 control(struct vf_instance
* vf
, int request
, void *data
)
57 const int *const tmp
= data
;
59 case VFCTRL_CHANGE_RECTANGLE
:
62 vf
->priv
->w
+= tmp
[1];
66 vf
->priv
->h
+= tmp
[1];
70 vf
->priv
->x
+= tmp
[1];
74 vf
->priv
->y
+= tmp
[1];
78 mp_msg(MSGT_VFILTER
,MSGL_FATAL
,"Unknown param %d \n", tmp
[0]);
82 return vf_next_control(vf
, request
, data
);
86 put_image(struct vf_instance
* vf
, mp_image_t
* mpi
, double pts
){
88 unsigned int bpp
= mpi
->bpp
/ 8;
90 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
, MP_IMGTYPE_TEMP
,
91 MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
94 memcpy_pic(dmpi
->planes
[0],mpi
->planes
[0],mpi
->w
*bpp
, mpi
->h
,
95 dmpi
->stride
[0],mpi
->stride
[0]);
96 if(mpi
->flags
&MP_IMGFLAG_PLANAR
&& mpi
->flags
&MP_IMGFLAG_YUV
){
97 memcpy_pic(dmpi
->planes
[1],mpi
->planes
[1],
98 mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
,
99 dmpi
->stride
[1],mpi
->stride
[1]);
100 memcpy_pic(dmpi
->planes
[2],mpi
->planes
[2],
101 mpi
->w
>>mpi
->chroma_x_shift
, mpi
->h
>>mpi
->chroma_y_shift
,
102 dmpi
->stride
[2],mpi
->stride
[2]);
105 /* Draw the rectangle */
107 mp_msg(MSGT_VFILTER
,MSGL_INFO
, "rectangle: -vf rectangle=%d:%d:%d:%d \n", vf
->priv
->w
, vf
->priv
->h
, vf
->priv
->x
, vf
->priv
->y
);
109 x
= FFMIN(vf
->priv
->x
, dmpi
->width
);
112 w
= vf
->priv
->x
+ vf
->priv
->w
- 1 - x
;
113 w
= FFMIN(w
, dmpi
->width
- x
);
116 y
= FFMIN(vf
->priv
->y
, dmpi
->height
);
119 h
= vf
->priv
->y
+ vf
->priv
->h
- 1 - y
;
120 h
= FFMIN(h
, dmpi
->height
- y
);
123 if (0 <= vf
->priv
->y
&& vf
->priv
->y
<= dmpi
->height
) {
124 unsigned char *p
= dmpi
->planes
[0] + y
* dmpi
->stride
[0] + x
* bpp
;
125 unsigned int count
= w
* bpp
;
127 p
[count
] = 0xff - p
[count
];
129 if (h
!= 1 && vf
->priv
->y
+ vf
->priv
->h
- 1 <= mpi
->height
) {
130 unsigned char *p
= dmpi
->planes
[0] + (vf
->priv
->y
+ vf
->priv
->h
- 1) * dmpi
->stride
[0] + x
* bpp
;
131 unsigned int count
= w
* bpp
;
133 p
[count
] = 0xff - p
[count
];
135 if (0 <= vf
->priv
->x
&& vf
->priv
->x
<= dmpi
->width
) {
136 unsigned char *p
= dmpi
->planes
[0] + y
* dmpi
->stride
[0] + x
* bpp
;
137 unsigned int count
= h
;
139 unsigned int i
= bpp
;
142 p
+= dmpi
->stride
[0];
145 if (w
!= 1 && vf
->priv
->x
+ vf
->priv
->w
- 1 <= mpi
->width
) {
146 unsigned char *p
= dmpi
->planes
[0] + y
* dmpi
->stride
[0] + (vf
->priv
->x
+ vf
->priv
->w
- 1) * bpp
;
147 unsigned int count
= h
;
149 unsigned int i
= bpp
;
152 p
+= dmpi
->stride
[0];
155 return vf_next_put_image(vf
, dmpi
, pts
);
159 open(vf_instance_t
* vf
, char* args
) {
161 vf
->control
= control
;
162 vf
->put_image
= put_image
;
163 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
169 sscanf(args
, "%d:%d:%d:%d",
170 &vf
->priv
->w
, &vf
->priv
->h
, &vf
->priv
->x
, &vf
->priv
->y
);
174 const vf_info_t vf_info_rectangle
= {