2006-10-16 15:47:32 +00:00
|
|
|
/*
|
2008-05-13 10:16:20 +00:00
|
|
|
* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2006-10-16 15:47:32 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "cpudetect.h"
|
|
|
|
|
2007-10-12 03:17:43 +00:00
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
|
|
|
#include "vf.h"
|
|
|
|
|
2006-10-16 15:47:32 +00:00
|
|
|
#include "libavcodec/avcodec.h"
|
2010-06-05 13:44:20 +00:00
|
|
|
#include "libavutil/eval.h"
|
2006-10-16 15:47:32 +00:00
|
|
|
|
|
|
|
struct vf_priv_s {
|
2010-04-11 13:47:13 +00:00
|
|
|
AVExpr * e[3];
|
2006-10-27 21:33:01 +00:00
|
|
|
int framenum;
|
|
|
|
mp_image_t *mpi;
|
2006-10-16 15:47:32 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2006-10-16 15:47:32 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
2006-10-27 21:33:01 +00:00
|
|
|
unsigned int flags, unsigned int outfmt){
|
|
|
|
return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static inline double getpix(struct vf_instance *vf, double x, double y, int plane){
|
2006-10-16 20:21:31 +00:00
|
|
|
int xi, yi;
|
|
|
|
mp_image_t *mpi= vf->priv->mpi;
|
|
|
|
int stride= mpi->stride[plane];
|
|
|
|
uint8_t *src= mpi->planes[plane];
|
|
|
|
xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1);
|
|
|
|
yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1);
|
|
|
|
|
|
|
|
x-=xi;
|
|
|
|
y-=yi;
|
|
|
|
|
|
|
|
return
|
|
|
|
(1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride])
|
|
|
|
+ y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME cubic interpolate
|
2006-10-16 15:47:32 +00:00
|
|
|
//FIXME keep the last few frames
|
2010-07-01 20:52:17 +00:00
|
|
|
static double lum(void *vf, double x, double y){
|
2006-10-16 20:21:31 +00:00
|
|
|
return getpix(vf, x, y, 0);
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:52:17 +00:00
|
|
|
static double cb(void *vf, double x, double y){
|
2006-10-16 20:21:31 +00:00
|
|
|
return getpix(vf, x, y, 1);
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:52:17 +00:00
|
|
|
static double cr(void *vf, double x, double y){
|
2006-10-16 20:21:31 +00:00
|
|
|
return getpix(vf, x, y, 2);
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
|
2006-10-27 21:33:01 +00:00
|
|
|
mp_image_t *dmpi;
|
|
|
|
int x,y, plane;
|
|
|
|
|
|
|
|
if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
|
|
|
|
// no DR, so get a new image! hope we'll get DR buffer:
|
|
|
|
vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP,
|
|
|
|
MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
|
|
|
|
mpi->w,mpi->h);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmpi= vf->dmpi;
|
|
|
|
vf->priv->mpi= mpi;
|
|
|
|
|
|
|
|
vf_clone_mpi_attributes(dmpi, mpi);
|
|
|
|
|
|
|
|
for(plane=0; plane<3; plane++){
|
|
|
|
int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0);
|
|
|
|
int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0);
|
|
|
|
uint8_t *dst = dmpi->planes[plane];
|
|
|
|
int dst_stride= dmpi->stride[plane];
|
|
|
|
double const_values[]={
|
|
|
|
M_PI,
|
|
|
|
M_E,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
vf->priv->framenum,
|
|
|
|
w/(double)mpi->w,
|
|
|
|
h/(double)mpi->h,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
if (!vf->priv->e[plane]) continue;
|
|
|
|
for(y=0; y<h; y++){
|
|
|
|
const_values[3]=y;
|
|
|
|
for(x=0; x<w; x++){
|
|
|
|
const_values[2]=x;
|
2011-04-19 23:59:45 +00:00
|
|
|
dst[x + y * dst_stride] = av_expr_eval(vf->priv->e[plane],
|
2010-04-12 08:03:39 +00:00
|
|
|
const_values, vf);
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-27 21:33:01 +00:00
|
|
|
}
|
2006-10-16 15:47:32 +00:00
|
|
|
|
2006-10-27 21:33:01 +00:00
|
|
|
vf->priv->framenum++;
|
2006-10-16 15:47:32 +00:00
|
|
|
|
2006-10-27 21:33:01 +00:00
|
|
|
return vf_next_put_image(vf,dmpi, pts);
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void uninit(struct vf_instance *vf){
|
2006-10-27 21:33:01 +00:00
|
|
|
av_free(vf->priv);
|
|
|
|
vf->priv=NULL;
|
2006-10-16 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
2006-10-27 19:40:48 +00:00
|
|
|
char eq[3][2000] = { { 0 }, { 0 }, { 0 } };
|
2010-06-01 10:28:45 +00:00
|
|
|
int plane, res;
|
2006-10-27 19:40:48 +00:00
|
|
|
|
2006-10-16 15:47:32 +00:00
|
|
|
vf->config=config;
|
|
|
|
vf->put_image=put_image;
|
|
|
|
// vf->get_image=get_image;
|
|
|
|
vf->uninit=uninit;
|
|
|
|
vf->priv=av_malloc(sizeof(struct vf_priv_s));
|
|
|
|
memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
|
|
|
|
2006-10-28 09:50:22 +00:00
|
|
|
if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]);
|
2006-10-27 19:40:48 +00:00
|
|
|
|
|
|
|
if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1);
|
|
|
|
if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1);
|
2006-10-16 15:47:32 +00:00
|
|
|
|
2006-10-27 19:40:48 +00:00
|
|
|
for(plane=0; plane<3; plane++){
|
2008-04-26 13:35:40 +00:00
|
|
|
const char * const const_names[]={
|
2006-10-27 19:40:48 +00:00
|
|
|
"PI",
|
|
|
|
"E",
|
|
|
|
"X",
|
|
|
|
"Y",
|
|
|
|
"W",
|
|
|
|
"H",
|
|
|
|
"N",
|
|
|
|
"SW",
|
|
|
|
"SH",
|
|
|
|
NULL
|
|
|
|
};
|
2008-04-26 13:35:40 +00:00
|
|
|
const char * const func2_names[]={
|
2006-10-27 19:40:48 +00:00
|
|
|
"lum",
|
|
|
|
"cb",
|
|
|
|
"cr",
|
|
|
|
"p",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
double (*func2[])(void *, double, double)={
|
|
|
|
lum,
|
|
|
|
cb,
|
|
|
|
cr,
|
|
|
|
plane==0 ? lum : (plane==1 ? cb : cr),
|
|
|
|
NULL
|
|
|
|
};
|
2011-04-19 23:59:45 +00:00
|
|
|
res = av_expr_parse(&vf->priv->e[plane], eq[plane], const_names, NULL, NULL, func2_names, func2, 0, NULL);
|
2006-10-27 19:40:48 +00:00
|
|
|
|
2010-06-01 10:28:45 +00:00
|
|
|
if (res < 0) {
|
2010-05-20 23:17:41 +00:00
|
|
|
mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s'\n", eq[plane]);
|
|
|
|
return 0;
|
2006-10-27 19:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-16 15:47:32 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_geq = {
|
2006-10-16 15:47:32 +00:00
|
|
|
"generic equation filter",
|
|
|
|
"geq",
|
|
|
|
"Michael Niedermayer",
|
|
|
|
"",
|
2010-02-21 13:40:49 +00:00
|
|
|
vf_open,
|
2006-10-16 15:47:32 +00:00
|
|
|
NULL
|
|
|
|
};
|