[Mplayer-cvslog] CVS: main/libmpcodecs vf_eq2.c,NONE,1.1 Makefile,1.62,1.63 vf.c,1.49,1.50

Arpi of Ize arpi at mplayerhq.hu
Fri Sep 27 23:08:51 CEST 2002


Update of /cvsroot/mplayer/main/libmpcodecs
In directory mail:/var/tmp.root/cvs-serv21148/libmpcodecs

Modified Files:
	Makefile vf.c 
Added Files:
	vf_eq2.c 
Log Message:
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
by Hampa Hug <hhug at student.ethz.ch>


--- NEW FILE ---
/*
 * vf_eq2.c
 *
 * Extended software equalizer (brightness, contrast, gamma)
 *
 * Hampa Hug <hhug at student.ethz.ch>
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "../config.h"
#include "../mp_msg.h"

#include "img_format.h"
#include "mp_image.h"
#include "vf.h"


typedef struct vf_priv_s {
  unsigned char *buf;
  int           buf_w;
  int           buf_h;

  double        contrast;
  double        bright;
  double        gamma;

  unsigned char lut[256];
} vf_eq2_t;


static
void create_lut (vf_eq2_t *eq2)
{
  unsigned i;
  double   c, b, g;
  double   v;

  c = eq2->contrast;
  b = eq2->bright;
  g = eq2->gamma;

  if ((g < 0.001) || (g > 1000.0)) {
    g = 1.0;
  }

  fprintf (stderr, "vf_eq2: c=%.2f b=%.2f g=%.4f\n", c, b, g);

  g = 1.0 / g;

  for (i = 0; i < 256; i++) {
    v = (double) i / 255.0;
    v = c * (v - 0.5) + 0.5 + b;

    if (v <= 0.0) {
      eq2->lut[i] = 0;
    }
    else {
      v = pow (v, g);

      if (v >= 1.0) {
        eq2->lut[i] = 255;
      }
      else {
        eq2->lut[i] = (unsigned char) (256.0 * v);
      }
    }
  }
}

/* could inline this */
static
void process (unsigned char *dst, int dstride, unsigned char *src, int sstride,
  int w, int h, unsigned char lut[256])
{
  int i, j;

  for (j = 0; j < h; j++) {
    for (i = 0; i < w; i++) {
      *(dst++) = lut[*(src++)];
    }

    src += sstride - w;
    dst += dstride - w;
  }
}

static
int put_image (vf_instance_t *vf, mp_image_t *src)
{
  mp_image_t *dst;
  vf_eq2_t   *eq2;

  eq2 = vf->priv;

  if ((eq2->buf == NULL) || (eq2->buf_w != src->stride[0]) || (eq2->buf_h != src->h)) {
    eq2->buf = (unsigned char *) realloc (eq2->buf, src->stride[0] * src->h);
    eq2->buf_w = src->stride[0];
    eq2->buf_h = src->h;
  }

  dst = vf_get_image (vf->next, src->imgfmt, MP_IMGTYPE_EXPORT, 0, src->w, src->h);

  dst->stride[0] = src->stride[0];
  dst->stride[1] = src->stride[1];
  dst->stride[2] = src->stride[2];
  dst->planes[0] = vf->priv->buf;
  dst->planes[1] = src->planes[1];
  dst->planes[2] = src->planes[2];

  process (
    dst->planes[0], dst->stride[0], src->planes[0], src->stride[0],
    src->w, src->h, eq2->lut
  );

  return vf_next_put_image (vf, dst);
}

static
int control (vf_instance_t *vf, int request, void *data)
{
  vf_equalizer_t *eq;

  switch (request) {
    case VFCTRL_SET_EQUALIZER:
      eq = (vf_equalizer_t *) data;

      if (strcmp (eq->item, "gamma") == 0) {
        vf->priv->gamma = exp (log (8.0) * eq->value / 100.0);
        create_lut (vf->priv);
        return CONTROL_TRUE;
      }
      else if (strcmp (eq->item, "contrast") == 0) {
        vf->priv->contrast = (1.0 / 100.0) * (eq->value + 100);
        create_lut (vf->priv);
        return CONTROL_TRUE;
      }
      else if (strcmp (eq->item, "brightness") == 0) {
        vf->priv->bright = (1.0 / 100.0) * eq->value;
        create_lut (vf->priv);
        return CONTROL_TRUE;
      }
      break;

    case VFCTRL_GET_EQUALIZER:
      eq = (vf_equalizer_t *) data;
      if (strcmp (eq->item, "gamma") == 0) {
        eq->value = (int) (100.0 * log (vf->priv->gamma) / log (8.0));
        return CONTROL_TRUE;
      }
      else if (strcmp (eq->item, "contrast") == 0) {
        eq->value = (int) (100.0 * vf->priv->contrast) - 100;
        return CONTROL_TRUE;
      }
      else if (strcmp (eq->item, "brightness") == 0) {
        eq->value = (int) (100.0 * vf->priv->bright);
        return CONTROL_TRUE;
      }
      break;
  }

  return vf_next_control (vf, request, data);
}

static
int query_format (vf_instance_t *vf, unsigned fmt)
{
  switch (fmt) {
    case IMGFMT_YVU9:
    case IMGFMT_IF09:
    case IMGFMT_YV12:
    case IMGFMT_I420:
    case IMGFMT_IYUV:
    case IMGFMT_CLPL:
    case IMGFMT_Y800:
    case IMGFMT_Y8:
    case IMGFMT_NV12:
    case IMGFMT_444P:
    case IMGFMT_422P:
    case IMGFMT_411P:
      return vf_next_query_format (vf, fmt);
  }

  return 0;
}

static
void uninit (vf_instance_t *vf)
{
  if (vf->priv != NULL) {
    free (vf->priv->buf);
    free (vf->priv);
  }
}

static
int open (vf_instance_t *vf, char *args)
{
  vf_eq2_t *eq2;

  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));
  eq2 = vf->priv;

  eq2->buf = NULL;
  eq2->buf_w = 0;
  eq2->buf_h = 0;

  eq2->gamma = 1.0;
  eq2->contrast = 1.0;
  eq2->bright = 0.0;

  if (args != NULL) {
    sscanf (args, "%lf:%lf:%lf", &eq2->gamma, &eq2->contrast, &eq2->bright);
  }

  create_lut (eq2);

  return 1;
}

vf_info_t vf_info_eq2 = {
  "extended software equalizer",
  "eq2",
  "Hampa Hug",
  "",
  &open
};

Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/Makefile,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- Makefile	21 Sep 2002 12:34:02 -0000	1.62
+++ Makefile	27 Sep 2002 21:08:36 -0000	1.63
@@ -6,7 +6,7 @@
 
 AUDIO_SRCS=dec_audio.c ad.c ad_liba52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3lib.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_libvorbis.c ad_libmad.c ad_realaud.c ad_libdv.c
 VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_realvid.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c vd_lcl.c vd_mtga.c
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_halfpack.c vf_dint.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c
 ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c
 NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/cyuv.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/svq1.c
 

Index: vf.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- vf.c	10 Sep 2002 23:18:31 -0000	1.49
+++ vf.c	27 Sep 2002 21:08:36 -0000	1.50
@@ -39,6 +39,7 @@
 extern vf_info_t vf_info_yvu9;
 extern vf_info_t vf_info_lavcdeint;
 extern vf_info_t vf_info_eq;
+extern vf_info_t vf_info_eq2;
 extern vf_info_t vf_info_halfpack;
 extern vf_info_t vf_info_dint;
 
@@ -73,6 +74,7 @@
     &vf_info_noise,
     &vf_info_yvu9,
     &vf_info_eq,
+    &vf_info_eq2,
     &vf_info_halfpack,
     &vf_info_dint,
     NULL




More information about the MPlayer-cvslog mailing list