2002-07-27 11:40:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-04 02:21:50 +00:00
|
|
|
#include <string.h>
|
2002-07-27 11:40:15 +00:00
|
|
|
#include "mp_image.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "mp_msg.h"
|
2002-07-27 11:40:15 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "libvo/fastmemcpy.h"
|
2002-08-28 22:45:48 +00:00
|
|
|
|
2002-07-27 11:40:15 +00:00
|
|
|
struct vf_priv_s {
|
|
|
|
int x, y, w, h;
|
|
|
|
};
|
|
|
|
|
2002-08-04 02:21:50 +00:00
|
|
|
static int
|
|
|
|
config(struct vf_instance_s* vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt)
|
|
|
|
{
|
|
|
|
if (vf->priv->w < 0 || width < vf->priv->w)
|
|
|
|
vf->priv->w = width;
|
|
|
|
if (vf->priv->h < 0 || height < vf->priv->h)
|
|
|
|
vf->priv->h = height;
|
|
|
|
if (vf->priv->x < 0)
|
|
|
|
vf->priv->x = (width - vf->priv->w) / 2;
|
|
|
|
if (vf->priv->y < 0)
|
|
|
|
vf->priv->y = (height - vf->priv->h) / 2;
|
|
|
|
if (vf->priv->w + vf->priv->x > width
|
|
|
|
|| vf->priv->h + vf->priv->y > height) {
|
2002-10-14 15:12:04 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_WARN,"rectangle: bad position/width/height - rectangle area is out of the original!\n");
|
2002-08-04 02:21:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
control(struct vf_instance_s* vf, int request, void *data)
|
|
|
|
{
|
|
|
|
const int *const tmp = data;
|
|
|
|
switch(request){
|
|
|
|
case VFCTRL_CHANGE_RECTANGLE:
|
|
|
|
switch (tmp[0]){
|
|
|
|
case 0:
|
|
|
|
vf->priv->w += tmp[1];
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
vf->priv->h += tmp[1];
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
vf->priv->x += tmp[1];
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
vf->priv->y += tmp[1];
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
default:
|
2002-10-14 15:12:04 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_FATAL,"Unknown param %d \n", tmp[0]);
|
2002-08-04 02:21:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vf_next_control(vf, request, data);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-10 22:18:32 +00:00
|
|
|
static int
|
2006-03-21 21:26:42 +00:00
|
|
|
put_image(struct vf_instance_s* vf, mp_image_t* mpi, double pts){
|
2002-07-27 11:40:15 +00:00
|
|
|
mp_image_t* dmpi;
|
2003-01-03 12:53:48 +00:00
|
|
|
unsigned int bpp = mpi->bpp / 8;
|
2002-08-04 02:21:50 +00:00
|
|
|
unsigned int x, y, w, h;
|
|
|
|
dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP,
|
|
|
|
MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
|
|
|
|
mpi->w, mpi->h);
|
2003-01-03 12:53:48 +00:00
|
|
|
|
|
|
|
memcpy_pic(dmpi->planes[0],mpi->planes[0],mpi->w*bpp, mpi->h,
|
|
|
|
dmpi->stride[0],mpi->stride[0]);
|
|
|
|
if(mpi->flags&MP_IMGFLAG_PLANAR && mpi->flags&MP_IMGFLAG_YUV){
|
|
|
|
memcpy_pic(dmpi->planes[1],mpi->planes[1],
|
|
|
|
mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift,
|
|
|
|
dmpi->stride[1],mpi->stride[1]);
|
|
|
|
memcpy_pic(dmpi->planes[2],mpi->planes[2],
|
|
|
|
mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift,
|
|
|
|
dmpi->stride[2],mpi->stride[2]);
|
|
|
|
}
|
2002-07-27 11:40:15 +00:00
|
|
|
|
|
|
|
/* Draw the rectangle */
|
2002-08-04 02:21:50 +00:00
|
|
|
|
2003-10-25 18:44:41 +00:00
|
|
|
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);
|
2002-08-04 02:21:50 +00:00
|
|
|
|
|
|
|
if (vf->priv->x < 0)
|
2002-07-27 11:40:15 +00:00
|
|
|
x = 0;
|
2002-08-04 02:21:50 +00:00
|
|
|
else if (dmpi->width < vf->priv->x)
|
|
|
|
x = dmpi->width;
|
|
|
|
else
|
|
|
|
x = vf->priv->x;
|
|
|
|
if (vf->priv->x + vf->priv->w - 1 < 0)
|
|
|
|
w = vf->priv->x + vf->priv->w - 1 - x;
|
|
|
|
else if (dmpi->width < vf->priv->x + vf->priv->w - 1)
|
|
|
|
w = dmpi->width - x;
|
|
|
|
else
|
|
|
|
w = vf->priv->x + vf->priv->w - 1 - x;
|
|
|
|
if (vf->priv->y < 0)
|
2002-07-27 11:40:15 +00:00
|
|
|
y = 0;
|
2002-08-04 02:21:50 +00:00
|
|
|
else if (dmpi->height < vf->priv->y)
|
|
|
|
y = dmpi->height;
|
|
|
|
else
|
|
|
|
y = vf->priv->y;
|
|
|
|
if (vf->priv->y + vf->priv->h - 1 < 0)
|
|
|
|
h = vf->priv->y + vf->priv->h - 1 - y;
|
|
|
|
else if (dmpi->height < vf->priv->y + vf->priv->h - 1)
|
|
|
|
h = dmpi->height - y;
|
|
|
|
else
|
|
|
|
h = vf->priv->y + vf->priv->h - 1 - y;
|
|
|
|
|
|
|
|
if (0 <= vf->priv->y && vf->priv->y <= dmpi->height) {
|
|
|
|
unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
|
|
|
|
unsigned int count = w * bpp;
|
|
|
|
while (count--)
|
|
|
|
p[count] = 0xff - p[count];
|
|
|
|
}
|
|
|
|
if (h != 1 && vf->priv->y + vf->priv->h - 1 <= mpi->height) {
|
|
|
|
unsigned char *p = dmpi->planes[0] + (vf->priv->y + vf->priv->h - 1) * dmpi->stride[0] + x * bpp;
|
|
|
|
unsigned int count = w * bpp;
|
|
|
|
while (count--)
|
|
|
|
p[count] = 0xff - p[count];
|
2002-07-27 11:40:15 +00:00
|
|
|
}
|
2002-08-04 02:21:50 +00:00
|
|
|
if (0 <= vf->priv->x && vf->priv->x <= dmpi->width) {
|
|
|
|
unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
|
|
|
|
unsigned int count = h;
|
2002-07-27 11:40:15 +00:00
|
|
|
while (count--) {
|
2002-08-04 02:21:50 +00:00
|
|
|
unsigned int i = bpp;
|
2002-07-27 11:40:15 +00:00
|
|
|
while (i--)
|
2002-08-04 02:21:50 +00:00
|
|
|
p[i] = 0xff - p[i];
|
|
|
|
p += dmpi->stride[0];
|
2002-07-27 11:40:15 +00:00
|
|
|
}
|
2002-08-04 02:21:50 +00:00
|
|
|
}
|
|
|
|
if (w != 1 && vf->priv->x + vf->priv->w - 1 <= mpi->width) {
|
|
|
|
unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + (vf->priv->x + vf->priv->w - 1) * bpp;
|
|
|
|
unsigned int count = h;
|
2002-07-27 11:40:15 +00:00
|
|
|
while (count--) {
|
2002-08-04 02:21:50 +00:00
|
|
|
unsigned int i = bpp;
|
|
|
|
while (i--)
|
|
|
|
p[i] = 0xff - p[i];
|
|
|
|
p += dmpi->stride[0];
|
2002-07-27 11:40:15 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 21:26:42 +00:00
|
|
|
return vf_next_put_image(vf, dmpi, pts);
|
2002-07-27 11:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
open(vf_instance_t* vf, char* args) {
|
2002-08-04 02:21:50 +00:00
|
|
|
vf->config = config;
|
|
|
|
vf->control = control;
|
2002-07-27 11:40:15 +00:00
|
|
|
vf->put_image = put_image;
|
|
|
|
vf->priv = malloc(sizeof(struct vf_priv_s));
|
|
|
|
vf->priv->x = -1;
|
|
|
|
vf->priv->y = -1;
|
|
|
|
vf->priv->w = -1;
|
|
|
|
vf->priv->h = -1;
|
|
|
|
if (args)
|
|
|
|
sscanf(args, "%d:%d:%d:%d",
|
|
|
|
&vf->priv->w, &vf->priv->h, &vf->priv->x, &vf->priv->y);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_info_t vf_info_rectangle = {
|
|
|
|
"draw rectangle",
|
|
|
|
"rectangle",
|
|
|
|
"Kim Minh Kaplan",
|
|
|
|
"",
|
2003-03-15 18:01:02 +00:00
|
|
|
open,
|
|
|
|
NULL
|
2002-07-27 11:40:15 +00:00
|
|
|
};
|