2002-08-21 23:08:20 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "../config.h"
|
|
|
|
#include "../mp_msg.h"
|
2002-08-22 04:59:45 +00:00
|
|
|
#include "../cpudetect.h"
|
2002-08-21 23:08:20 +00:00
|
|
|
|
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
|
|
|
#include "vf.h"
|
|
|
|
|
|
|
|
#include "../libvo/video_out.h"
|
|
|
|
#include "../libvo/fastmemcpy.h"
|
|
|
|
#include "../postproc/rgb2rgb.h"
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
unsigned char *buf;
|
|
|
|
int brightness;
|
|
|
|
int contrast;
|
|
|
|
};
|
|
|
|
|
2002-08-22 04:59:45 +00:00
|
|
|
#ifdef HAVE_MMX
|
|
|
|
static void process_MMX(unsigned char *dest, int dstride, unsigned char *src, int sstride,
|
2002-08-21 23:08:20 +00:00
|
|
|
int w, int h, int brightness, int contrast)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int pel;
|
|
|
|
int dstep = dstride-w;
|
|
|
|
int sstep = sstride-w;
|
2002-08-22 04:59:45 +00:00
|
|
|
short brvec[4];
|
|
|
|
short contvec[4];
|
2002-08-21 23:08:20 +00:00
|
|
|
|
2002-08-23 21:55:57 +00:00
|
|
|
contrast = ((contrast+100)*256*16)/100;
|
|
|
|
brightness = ((brightness+100)*511)/200-128 - contrast/32;
|
2002-08-21 23:08:20 +00:00
|
|
|
|
2002-08-22 04:59:45 +00:00
|
|
|
brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
|
|
|
|
contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
|
|
|
|
|
2002-08-21 23:08:20 +00:00
|
|
|
while (h--) {
|
2002-08-23 21:55:57 +00:00
|
|
|
asm volatile (
|
2002-08-22 04:59:45 +00:00
|
|
|
"movq (%5), %%mm3 \n\t"
|
|
|
|
"movq (%6), %%mm4 \n\t"
|
|
|
|
"pxor %%mm0, %%mm0 \n\t"
|
2002-08-23 21:55:57 +00:00
|
|
|
"movl %4, %%eax\n\t"
|
2002-08-28 00:24:27 +00:00
|
|
|
".balign 16 \n\t"
|
2002-08-22 04:59:45 +00:00
|
|
|
"1: \n\t"
|
|
|
|
"movq (%0), %%mm1 \n\t"
|
|
|
|
"movq (%0), %%mm2 \n\t"
|
|
|
|
"punpcklbw %%mm0, %%mm1 \n\t"
|
|
|
|
"punpckhbw %%mm0, %%mm2 \n\t"
|
2002-08-23 21:55:57 +00:00
|
|
|
"psllw $4, %%mm1 \n\t"
|
|
|
|
"psllw $4, %%mm2 \n\t"
|
|
|
|
"pmulhw %%mm4, %%mm1 \n\t"
|
|
|
|
"pmulhw %%mm4, %%mm2 \n\t"
|
|
|
|
"paddw %%mm3, %%mm1 \n\t"
|
|
|
|
"paddw %%mm3, %%mm2 \n\t"
|
2002-08-22 04:59:45 +00:00
|
|
|
"packuswb %%mm2, %%mm1 \n\t"
|
|
|
|
"addl $8, %0 \n\t"
|
|
|
|
"movq %%mm1, (%1) \n\t"
|
|
|
|
"addl $8, %1 \n\t"
|
2002-08-23 21:55:57 +00:00
|
|
|
"decl %%eax \n\t"
|
2002-08-22 04:59:45 +00:00
|
|
|
"jnz 1b \n\t"
|
|
|
|
: "=r" (src), "=r" (dest)
|
2002-08-23 21:55:57 +00:00
|
|
|
: "0" (src), "1" (dest), "r" (w>>3), "r" (brvec), "r" (contvec)
|
|
|
|
: "%eax"
|
2002-08-22 04:59:45 +00:00
|
|
|
);
|
2002-08-23 21:55:57 +00:00
|
|
|
|
2002-08-22 04:59:45 +00:00
|
|
|
for (i = w&7; i; i--)
|
2002-08-21 23:08:20 +00:00
|
|
|
{
|
2002-08-23 21:55:57 +00:00
|
|
|
pel = ((*src++* contrast)>>12) + brightness;
|
|
|
|
if(pel&768) pel = (-pel)>>31;
|
|
|
|
*dest++ = pel;
|
2002-08-21 23:08:20 +00:00
|
|
|
}
|
2002-08-23 21:55:57 +00:00
|
|
|
|
2002-08-21 23:08:20 +00:00
|
|
|
src += sstep;
|
|
|
|
dest += dstep;
|
|
|
|
}
|
2002-08-22 04:59:45 +00:00
|
|
|
asm volatile ( "emms \n\t" ::: "memory" );
|
2002-08-21 23:08:20 +00:00
|
|
|
}
|
2002-08-22 04:59:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void process_C(unsigned char *dest, int dstride, unsigned char *src, int sstride,
|
|
|
|
int w, int h, int brightness, int contrast)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int pel;
|
|
|
|
int dstep = dstride-w;
|
|
|
|
int sstep = sstride-w;
|
2002-08-21 23:08:20 +00:00
|
|
|
|
2002-08-23 21:55:57 +00:00
|
|
|
contrast = ((contrast+100)*256*256)/100;
|
|
|
|
brightness = ((brightness+100)*511)/200-128 - contrast/512;
|
2002-08-22 04:59:45 +00:00
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
for (i = w; i; i--)
|
|
|
|
{
|
2002-08-23 21:55:57 +00:00
|
|
|
pel = ((*src++* contrast)>>16) + brightness;
|
|
|
|
if(pel&768) pel = (-pel)>>31;
|
|
|
|
*dest++ = pel;
|
2002-08-22 04:59:45 +00:00
|
|
|
}
|
|
|
|
src += sstep;
|
|
|
|
dest += dstep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void (*process)(unsigned char *dest, int dstride, unsigned char *src, int sstride,
|
|
|
|
int w, int h, int brightness, int contrast);
|
|
|
|
|
|
|
|
/* FIXME: add packed yuv version of process */
|
2002-08-21 23:08:20 +00:00
|
|
|
|
|
|
|
static void put_image(struct vf_instance_s* vf, mp_image_t *mpi)
|
|
|
|
{
|
|
|
|
mp_image_t *dmpi;
|
|
|
|
|
|
|
|
dmpi=vf_get_image(vf->next, mpi->imgfmt,
|
|
|
|
MP_IMGTYPE_EXPORT, 0,
|
|
|
|
mpi->w, mpi->h);
|
|
|
|
|
|
|
|
dmpi->stride[0] = mpi->stride[0];
|
|
|
|
dmpi->planes[1] = mpi->planes[1];
|
|
|
|
dmpi->planes[2] = mpi->planes[2];
|
|
|
|
dmpi->stride[1] = mpi->stride[1];
|
|
|
|
dmpi->stride[2] = mpi->stride[2];
|
|
|
|
|
|
|
|
if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h);
|
|
|
|
|
|
|
|
if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0))
|
|
|
|
dmpi->planes[0] = mpi->planes[0];
|
|
|
|
else {
|
|
|
|
dmpi->planes[0] = vf->priv->buf;
|
|
|
|
process(dmpi->planes[0], dmpi->stride[0],
|
|
|
|
mpi->planes[0], mpi->stride[0],
|
|
|
|
mpi->w, mpi->h, vf->priv->brightness,
|
|
|
|
vf->priv->contrast);
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_next_put_image(vf,dmpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(struct vf_instance_s* vf, int request, void* data)
|
|
|
|
{
|
|
|
|
vf_equalizer_t *eq;
|
|
|
|
|
|
|
|
switch (request) {
|
|
|
|
case VFCTRL_SET_EQUALIZER:
|
|
|
|
eq = data;
|
|
|
|
if (!strcmp(eq->item,"brightness")) {
|
|
|
|
vf->priv->brightness = eq->value;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (!strcmp(eq->item,"contrast")) {
|
|
|
|
vf->priv->contrast = eq->value;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VFCTRL_GET_EQUALIZER:
|
|
|
|
eq = data;
|
|
|
|
if (!strcmp(eq->item,"brightness")) {
|
|
|
|
eq->value = vf->priv->brightness;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (!strcmp(eq->item,"contrast")) {
|
|
|
|
eq->value = vf->priv->contrast;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return vf_next_control(vf, request, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance_s* vf, unsigned int 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(struct vf_instance_s* vf)
|
|
|
|
{
|
|
|
|
if (vf->priv->buf) free(vf->priv->buf);
|
|
|
|
free(vf->priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int open(vf_instance_t *vf, char* args)
|
|
|
|
{
|
|
|
|
vf->control=control;
|
|
|
|
vf->query_format=query_format;
|
|
|
|
vf->put_image=put_image;
|
|
|
|
vf->uninit=uninit;
|
|
|
|
|
|
|
|
vf->priv = malloc(sizeof(struct vf_priv_s));
|
|
|
|
memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
|
|
|
if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast);
|
2002-08-22 04:59:45 +00:00
|
|
|
|
|
|
|
process = process_C;
|
|
|
|
#ifdef HAVE_MMX
|
|
|
|
if(gCpuCaps.hasMMX) process = process_MMX;
|
|
|
|
#endif
|
|
|
|
|
2002-08-21 23:08:20 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_info_t vf_info_eq = {
|
|
|
|
"soft video equalizer",
|
|
|
|
"eq",
|
|
|
|
"Richard Felker",
|
|
|
|
"",
|
|
|
|
open
|
|
|
|
};
|
|
|
|
|