2004-02-05 15:56:05 +00:00
|
|
|
/*
|
2008-05-13 10:16:20 +00:00
|
|
|
* Copyright (C) 2004 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.
|
|
|
|
*/
|
2004-02-05 15:56:05 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-07-17 21:15:08 +00:00
|
|
|
#include <libavutil/eval.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "cpudetect.h"
|
2007-11-09 15:44:47 +00:00
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
|
|
|
#include "vf.h"
|
|
|
|
#include "libvo/fastmemcpy.h"
|
2004-02-05 15:56:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
char eq[200];
|
|
|
|
int8_t *qp;
|
|
|
|
int8_t lut[257];
|
|
|
|
int qp_stride;
|
|
|
|
};
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2004-02-05 15:56:05 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
|
|
|
int h= (height+15)>>4;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vf->priv->qp_stride= (width+15)>>4;
|
2005-10-05 09:39:08 +00:00
|
|
|
vf->priv->qp= av_malloc(vf->priv->qp_stride*h*sizeof(int8_t));
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-02-05 15:56:05 +00:00
|
|
|
for(i=-129; i<128; i++){
|
|
|
|
double const_values[]={
|
|
|
|
M_PI,
|
|
|
|
M_E,
|
|
|
|
i != -129,
|
|
|
|
i,
|
|
|
|
0
|
|
|
|
};
|
2008-04-26 13:35:40 +00:00
|
|
|
const char * const const_names[]={
|
2004-02-05 15:56:05 +00:00
|
|
|
"PI",
|
|
|
|
"E",
|
|
|
|
"known",
|
|
|
|
"qp",
|
|
|
|
NULL
|
|
|
|
};
|
2010-05-20 23:17:41 +00:00
|
|
|
double temp_val;
|
2010-06-01 10:28:45 +00:00
|
|
|
int res;
|
2004-02-05 15:56:05 +00:00
|
|
|
|
2011-07-17 21:15:08 +00:00
|
|
|
res= av_expr_parse_and_eval(&temp_val, vf->priv->eq, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
2010-05-20 23:17:41 +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, "qp: Error evaluating \"%s\" \n", vf->priv->eq);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
vf->priv->lut[i+129]= lrintf(temp_val);
|
2004-02-05 15:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
|
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void get_image(struct vf_instance *vf, mp_image_t *mpi){
|
2004-02-05 15:56:05 +00:00
|
|
|
if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
|
|
|
|
// ok, we can do pp in-place (or pp disabled):
|
|
|
|
vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
|
|
|
|
mpi->type, mpi->flags, mpi->w, mpi->h);
|
|
|
|
mpi->planes[0]=vf->dmpi->planes[0];
|
|
|
|
mpi->stride[0]=vf->dmpi->stride[0];
|
|
|
|
mpi->width=vf->dmpi->width;
|
|
|
|
if(mpi->flags&MP_IMGFLAG_PLANAR){
|
|
|
|
mpi->planes[1]=vf->dmpi->planes[1];
|
|
|
|
mpi->planes[2]=vf->dmpi->planes[2];
|
|
|
|
mpi->stride[1]=vf->dmpi->stride[1];
|
|
|
|
mpi->stride[2]=vf->dmpi->stride[2];
|
|
|
|
}
|
|
|
|
mpi->flags|=MP_IMGFLAG_DIRECT;
|
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
|
2004-02-05 15:56:05 +00:00
|
|
|
mp_image_t *dmpi;
|
|
|
|
int x,y;
|
|
|
|
|
|
|
|
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;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-02-05 15:56:05 +00:00
|
|
|
if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
|
|
|
|
memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
|
|
|
|
if(mpi->flags&MP_IMGFLAG_PLANAR){
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vf_clone_mpi_attributes(dmpi, mpi);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-02-05 15:56:05 +00:00
|
|
|
dmpi->qscale = vf->priv->qp;
|
|
|
|
dmpi->qstride= vf->priv->qp_stride;
|
|
|
|
if(mpi->qscale){
|
|
|
|
for(y=0; y<((dmpi->h+15)>>4); y++){
|
|
|
|
for(x=0; x<vf->priv->qp_stride; x++){
|
2009-07-06 23:26:13 +00:00
|
|
|
dmpi->qscale[x + dmpi->qstride*y]=
|
2004-02-05 15:56:05 +00:00
|
|
|
vf->priv->lut[ 129 + ((int8_t)mpi->qscale[x + mpi->qstride*y]) ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
int qp= vf->priv->lut[0];
|
|
|
|
for(y=0; y<((dmpi->h+15)>>4); y++){
|
|
|
|
for(x=0; x<vf->priv->qp_stride; x++){
|
|
|
|
dmpi->qscale[x + dmpi->qstride*y]= qp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 21:26:42 +00:00
|
|
|
return vf_next_put_image(vf,dmpi, pts);
|
2004-02-05 15:56:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void uninit(struct vf_instance *vf){
|
2004-02-05 15:56:05 +00:00
|
|
|
if(!vf->priv) return;
|
|
|
|
|
2010-11-14 09:12:34 +00:00
|
|
|
av_free(vf->priv->qp);
|
2004-02-05 15:56:05 +00:00
|
|
|
vf->priv->qp= NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-05 09:39:08 +00:00
|
|
|
av_free(vf->priv);
|
2004-02-05 15:56:05 +00:00
|
|
|
vf->priv=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
2004-02-05 15:56:05 +00:00
|
|
|
vf->config=config;
|
|
|
|
vf->put_image=put_image;
|
|
|
|
vf->get_image=get_image;
|
|
|
|
vf->uninit=uninit;
|
2005-10-05 09:39:08 +00:00
|
|
|
vf->priv=av_malloc(sizeof(struct vf_priv_s));
|
2004-02-05 15:56:05 +00:00
|
|
|
memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-02-05 15:56:05 +00:00
|
|
|
// avcodec_init();
|
|
|
|
|
|
|
|
if (args) strncpy(vf->priv->eq, args, 199);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-02-05 15:56:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_qp = {
|
2004-02-05 15:56:05 +00:00
|
|
|
"QP changer",
|
|
|
|
"qp",
|
|
|
|
"Michael Niedermayer",
|
|
|
|
"",
|
2010-02-21 13:40:49 +00:00
|
|
|
vf_open,
|
2004-02-05 15:56:05 +00:00
|
|
|
NULL
|
|
|
|
};
|