[MPlayer-dev-eng] [PATCH] vf_eq2 default parameter fix

Diego Biurrun diego at biurrun.de
Fri Nov 7 02:16:29 CET 2003


What's up with this patch?  Arpi and Alex said on IRC that it is ugly
but could still be committed (at least that's what I understood).  Is
there a better way to give the filter default parameters?  Should it
be applied anyway?

Diego

Hampa Hug writes:
 > Diego Biurrun wrote:
 > 
 > > g:c:b, the status quo is the way to go.
 > 
 > A poet ;-)
 > 
 > Here it is.
 > 
 > Hampa
 > diff -ur mplayer-cvs/libmpcodecs/vf_eq2.c mplayer-dev/libmpcodecs/vf_eq2.c
 > --- mplayer-cvs/libmpcodecs/vf_eq2.c	2003-10-21 02:01:23.000000000 +0200
 > +++ mplayer-dev/libmpcodecs/vf_eq2.c	2003-10-28 17:31:56.000000000 +0100
 > @@ -23,6 +23,9 @@
 >  #include "mp_image.h"
 >  #include "vf.h"
 >  
 > +#include "m_option.h"
 > +#include "m_struct.h"
 > +
 >  #ifdef USE_SETLOCALE
 >  #include <locale.h>
 >  #endif
 > @@ -47,8 +50,6 @@
 >  } eq2_param_t;
 >  
 >  typedef struct vf_priv_s {
 > -  eq2_param_t param[3];
 > -
 >    double        contrast;
 >    double        brightness;
 >    double        saturation;
 > @@ -59,12 +60,27 @@
 >    double        ggamma;
 >    double        bgamma;
 >  
 > +  eq2_param_t   param[3];
 > +
 >    unsigned      buf_w[3];
 >    unsigned      buf_h[3];
 >    unsigned char *buf[3];
 >  } vf_eq2_t;
 >  
 >  
 > +static vf_eq2_t vf_eq2_dflt = {
 > +  1.0,
 > +  0.0,
 > +  1.0,
 > +  1.0,
 > +  1.0,
 > +  1.0,
 > +  1.0,
 > +  1.0
 > +  /* remaining fields are initialized at run time */
 > +};
 > +
 > +
 >  static
 >  void create_lut (eq2_param_t *par)
 >  {
 > @@ -440,14 +456,17 @@
 >  {
 >    unsigned i;
 >    vf_eq2_t *eq2;
 > -  double   par[8];
 >  
 >    vf->control = control;
 >    vf->query_format = query_format;
 >    vf->put_image = put_image;
 >    vf->uninit = uninit;
 >  
 > -  vf->priv = (vf_eq2_t *) malloc (sizeof (vf_eq2_t));
 > +  if (vf->priv == NULL) {
 > +    vf->priv = (vf_eq2_t *) malloc (sizeof (vf_eq2_t));
 > +    memcpy (vf->priv, &vf_eq2_dflt, sizeof (vf_eq2_t));
 > +  }
 > +
 >    eq2 = vf->priv;
 >  
 >    for (i = 0; i < 3; i++) {
 > @@ -459,20 +478,13 @@
 >      eq2->param[i].c = 1.0;
 >      eq2->param[i].b = 0.0;
 >      eq2->param[i].g = 1.0;
 > +    eq2->param[i].w = 1.0;
 >      eq2->param[i].lut_clean = 0;
 >    }
 >  
 > -  eq2->contrast = 1.0;
 > -  eq2->brightness = 0.0;
 > -  eq2->saturation = 1.0;
 > -
 > -  eq2->gamma = 1.0;
 > -  eq2->gamma_weight = 1.0;
 > -  eq2->rgamma = 1.0;
 > -  eq2->ggamma = 1.0;
 > -  eq2->bgamma = 1.0;
 > -
 >    if (args != NULL) {
 > +    double par[8];
 > +
 >      par[0] = 1.0;
 >      par[1] = 1.0;
 >      par[2] = 0.0;
 > @@ -491,25 +503,50 @@
 >      setlocale (LC_NUMERIC, "");
 >  #endif
 >  
 > +    eq2->gamma = par[0];
 > +    eq2->contrast = par[1];
 > +    eq2->brightness = par[2];
 > +    eq2->saturation = par[3];
 > +
 >      eq2->rgamma = par[4];
 >      eq2->ggamma = par[5];
 >      eq2->bgamma = par[6];
 >      eq2->gamma_weight = par[7];
 > -
 > -    set_gamma (eq2, par[0]);
 > -    set_contrast (eq2, par[1]);
 > -    set_brightness (eq2, par[2]);
 > -    set_saturation (eq2, par[3]);
 >    }
 >  
 > +  set_gamma (eq2, eq2->gamma);
 > +  set_contrast (eq2, eq2->contrast);
 > +  set_brightness (eq2, eq2->brightness);
 > +  set_saturation (eq2, eq2->saturation);
 > +
 >    return 1;
 >  }
 >  
 > +#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
 > +static m_option_t vf_opts_fields[] = {
 > +  {"gamma", ST_OFF(gamma), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.001, 1000.0, NULL},
 > +  {"contrast", ST_OFF(contrast), CONF_TYPE_DOUBLE, 0, 0.0, 0.0, NULL},
 > +  {"brightness", ST_OFF(brightness), CONF_TYPE_DOUBLE, 0, 0.0, 0.0, NULL},
 > +  {"saturation", ST_OFF(saturation), CONF_TYPE_DOUBLE, M_OPT_MIN, 0.0, 0.0, NULL},
 > +  {"gamma_red", ST_OFF(rgamma), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.001, 1000.0, NULL},
 > +  {"gamma_green", ST_OFF(ggamma), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.001, 1000.0, NULL},
 > +  {"gamma_blue", ST_OFF(bgamma), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.001, 1000.0, NULL},
 > +  {"gamma_weight", ST_OFF(gamma_weight), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 1.0, NULL},
 > +  { NULL, NULL, 0, 0, 0, 0,  NULL }
 > +};
 > +
 > +static m_struct_t vf_opts = {
 > +  "eq2",
 > +  sizeof (vf_eq2_t),
 > +  &vf_eq2_dflt,
 > +  vf_opts_fields
 > +};
 > +
 >  vf_info_t vf_info_eq2 = {
 >    "Software equalizer",
 >    "eq2",
 >    "Hampa Hug, Daniel Moreno, Richard Felker",
 >    "",
 >    &open,
 > -  NULL
 > +  &vf_opts
 >  };
 > diff -ur mplayer-cvs/m_option.c mplayer-dev/m_option.c
 > --- mplayer-cvs/m_option.c	2003-10-27 12:36:17.000000000 +0100
 > +++ mplayer-dev/m_option.c	2003-10-28 17:29:45.000000000 +0100
 > @@ -243,6 +243,49 @@
 >    NULL
 >  };
 >  
 > +
 > +// Double
 > +
 > +#undef VAL
 > +#define VAL(x) (*(double*)(x))
 > +
 > +static
 > +int parse_double (m_option_t *opt, char *name, char *param, void *dst, int src)
 > +{
 > +  int   r;
 > +  float val;
 > +
 > +  /* parse_double() calls parse_float(). better would be the other way around. */
 > +  r = parse_float (opt, name, param, &val, src);
 > +
 > +  if ((r == 1) && (dst != NULL)) {
 > +    VAL(dst) = val;
 > +  }
 > +
 > +  return (r);
 > +}
 > +
 > +static
 > +char *print_double (m_option_t *opt, void *val)
 > +{
 > +  opt = NULL;
 > +  return dup_printf ("%f", VAL(val));
 > +}
 > +
 > +m_option_type_t m_option_type_double = {
 > +  "Double",
 > +  "floating point number or ratio (numerator[:/]denominator)",
 > +  sizeof(double),
 > +  0,
 > +  parse_double,
 > +  print_double,
 > +  copy_opt,
 > +  copy_opt,
 > +  NULL,
 > +  NULL
 > +};
 > +
 > +
 >  ///////////// Position
 >  #undef VAL
 >  #define VAL(x) (*(off_t*)(x))
 > diff -ur mplayer-cvs/m_option.h mplayer-dev/m_option.h
 > --- mplayer-cvs/m_option.h	2003-08-27 01:49:19.000000000 +0200
 > +++ mplayer-dev/m_option.h	2003-10-28 17:29:45.000000000 +0100
 > @@ -11,6 +11,7 @@
 >  extern m_option_type_t m_option_type_flag;
 >  extern m_option_type_t m_option_type_int;
 >  extern m_option_type_t m_option_type_float;
 > +extern m_option_type_t m_option_type_double;
 >  extern m_option_type_t m_option_type_string;
 >  extern m_option_type_t m_option_type_string_list;
 >  extern m_option_type_t m_option_type_position;
 > @@ -78,6 +79,7 @@
 >  #define CONF_TYPE_FLAG		(&m_option_type_flag)
 >  #define CONF_TYPE_INT		(&m_option_type_int)
 >  #define CONF_TYPE_FLOAT		(&m_option_type_float)
 > +#define CONF_TYPE_DOUBLE        (&m_option_type_double)
 >  #define CONF_TYPE_STRING	(&m_option_type_string)
 >  #define CONF_TYPE_FUNC		(&m_option_type_func)
 >  #define CONF_TYPE_FUNC_PARAM	(&m_option_type_func_param)
 > _______________________________________________
 > MPlayer-dev-eng mailing list
 > MPlayer-dev-eng at mplayerhq.hu
 > http://mplayerhq.hu/mailman/listinfo/mplayer-dev-eng



More information about the MPlayer-dev-eng mailing list