2002-09-27 21:08:36 +00:00
|
|
|
/*
|
2003-02-02 02:09:23 +00:00
|
|
|
* Software equalizer (brightness, contrast, gamma, saturation)
|
2002-09-27 21:08:36 +00:00
|
|
|
*
|
2003-02-02 02:09:23 +00:00
|
|
|
* Hampa Hug <hampa@hampa.ch> (original LUT gamma/contrast/brightness filter)
|
|
|
|
* Daniel Moreno <comac@comac.darktech.org> (saturation, R/G/B gamma support)
|
|
|
|
* Richard Felker (original MMX contrast/brightness code (vf_eq.c))
|
2003-10-17 17:15:38 +00:00
|
|
|
* Michael Niedermayer <michalni@gmx.at> (LUT16)
|
2010-02-13 21:32:19 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-01-30 16:57:40 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2010-01-30 16:57:40 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-30 16:57:40 +00:00
|
|
|
* 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
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2002-09-27 21:08:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2003-10-17 17:15:38 +00:00
|
|
|
#include <inttypes.h>
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
#include "config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2002-09-27 21:08:36 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2003-10-17 17:15:38 +00:00
|
|
|
#define LUT16
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
/* Per channel parameters */
|
|
|
|
typedef struct eq2_param_t {
|
|
|
|
unsigned char lut[256];
|
2003-10-17 17:15:38 +00:00
|
|
|
#ifdef LUT16
|
|
|
|
uint16_t lut16[256*256];
|
|
|
|
#endif
|
2003-02-02 02:09:23 +00:00
|
|
|
int lut_clean;
|
|
|
|
|
|
|
|
void (*adjust) (struct eq2_param_t *par, unsigned char *dst, unsigned char *src,
|
|
|
|
unsigned w, unsigned h, unsigned dstride, unsigned sstride);
|
|
|
|
|
|
|
|
double c;
|
|
|
|
double b;
|
|
|
|
double g;
|
2003-10-18 23:02:30 +00:00
|
|
|
double w;
|
2003-02-02 02:09:23 +00:00
|
|
|
} eq2_param_t;
|
|
|
|
|
2002-09-27 21:08:36 +00:00
|
|
|
typedef struct vf_priv_s {
|
2013-12-21 16:43:25 +00:00
|
|
|
struct mp_log *log;
|
2003-02-02 02:09:23 +00:00
|
|
|
eq2_param_t param[3];
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
double contrast;
|
2003-02-02 02:09:23 +00:00
|
|
|
double brightness;
|
|
|
|
double saturation;
|
|
|
|
|
2002-09-27 21:08:36 +00:00
|
|
|
double gamma;
|
2003-10-18 23:02:30 +00:00
|
|
|
double gamma_weight;
|
2003-02-02 02:09:23 +00:00
|
|
|
double rgamma;
|
|
|
|
double ggamma;
|
|
|
|
double bgamma;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
unsigned buf_w[3];
|
|
|
|
unsigned buf_h[3];
|
|
|
|
unsigned char *buf[3];
|
2013-08-20 14:11:07 +00:00
|
|
|
|
|
|
|
int gamma_i, contrast_i, brightness_i, saturation_i;
|
2013-12-03 22:32:49 +00:00
|
|
|
|
|
|
|
double par[8];
|
2002-09-27 21:08:36 +00:00
|
|
|
} vf_eq2_t;
|
|
|
|
|
|
|
|
|
|
|
|
static
|
2003-02-02 02:09:23 +00:00
|
|
|
void create_lut (eq2_param_t *par)
|
2002-09-27 21:08:36 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2003-02-02 02:09:23 +00:00
|
|
|
double g, v;
|
2003-10-18 23:02:30 +00:00
|
|
|
double lw, gw;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
g = par->g;
|
2003-10-18 23:02:30 +00:00
|
|
|
gw = par->w;
|
|
|
|
lw = 1.0 - gw;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
if ((g < 0.001) || (g > 1000.0)) {
|
|
|
|
g = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g = 1.0 / g;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
v = (double) i / 255.0;
|
2003-02-02 02:09:23 +00:00
|
|
|
v = par->c * (v - 0.5) + 0.5 + par->b;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
if (v <= 0.0) {
|
2003-02-02 02:09:23 +00:00
|
|
|
par->lut[i] = 0;
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-10-18 23:02:30 +00:00
|
|
|
v = v*lw + pow(v, g)*gw;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
if (v >= 1.0) {
|
2003-02-02 02:09:23 +00:00
|
|
|
par->lut[i] = 255;
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-02-02 02:09:23 +00:00
|
|
|
par->lut[i] = (unsigned char) (256.0 * v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-17 17:15:38 +00:00
|
|
|
#ifdef LUT16
|
|
|
|
for(i=0; i<256*256; i++){
|
|
|
|
par->lut16[i]= par->lut[i&0xFF] + (par->lut[i>>8]<<8);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
par->lut_clean = 1;
|
|
|
|
}
|
|
|
|
|
2002-09-27 21:08:36 +00:00
|
|
|
static
|
2003-02-02 02:09:23 +00:00
|
|
|
void apply_lut (eq2_param_t *par, unsigned char *dst, unsigned char *src,
|
|
|
|
unsigned w, unsigned h, unsigned dstride, unsigned sstride)
|
2002-09-27 21:08:36 +00:00
|
|
|
{
|
2003-10-17 17:15:38 +00:00
|
|
|
unsigned i, j, w2;
|
2003-02-02 02:09:23 +00:00
|
|
|
unsigned char *lut;
|
2003-10-17 17:15:38 +00:00
|
|
|
uint16_t *lut16;
|
2003-02-02 02:09:23 +00:00
|
|
|
|
|
|
|
if (!par->lut_clean) {
|
|
|
|
create_lut (par);
|
|
|
|
}
|
|
|
|
|
|
|
|
lut = par->lut;
|
2003-10-17 17:15:38 +00:00
|
|
|
#ifdef LUT16
|
|
|
|
lut16 = par->lut16;
|
|
|
|
w2= (w>>3)<<2;
|
2002-09-27 21:08:36 +00:00
|
|
|
for (j = 0; j < h; j++) {
|
2003-10-17 17:15:38 +00:00
|
|
|
uint16_t *src16= (uint16_t*)src;
|
|
|
|
uint16_t *dst16= (uint16_t*)dst;
|
|
|
|
for (i = 0; i < w2; i+=4) {
|
|
|
|
dst16[i+0] = lut16[src16[i+0]];
|
|
|
|
dst16[i+1] = lut16[src16[i+1]];
|
|
|
|
dst16[i+2] = lut16[src16[i+2]];
|
|
|
|
dst16[i+3] = lut16[src16[i+3]];
|
|
|
|
}
|
|
|
|
i <<= 1;
|
|
|
|
#else
|
|
|
|
w2= (w>>3)<<3;
|
|
|
|
for (j = 0; j < h; j++) {
|
|
|
|
for (i = 0; i < w2; i+=8) {
|
|
|
|
dst[i+0] = lut[src[i+0]];
|
|
|
|
dst[i+1] = lut[src[i+1]];
|
|
|
|
dst[i+2] = lut[src[i+2]];
|
|
|
|
dst[i+3] = lut[src[i+3]];
|
|
|
|
dst[i+4] = lut[src[i+4]];
|
|
|
|
dst[i+5] = lut[src[i+5]];
|
|
|
|
dst[i+6] = lut[src[i+6]];
|
|
|
|
dst[i+7] = lut[src[i+7]];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
for (; i < w; i++) {
|
2002-12-04 22:00:03 +00:00
|
|
|
dst[i] = lut[src[i]];
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
2003-02-02 02:09:23 +00:00
|
|
|
|
2002-12-04 22:00:03 +00:00
|
|
|
src += sstride;
|
|
|
|
dst += dstride;
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
static struct mp_image *filter(struct vf_instance *vf, struct mp_image *src)
|
2002-09-27 21:08:36 +00:00
|
|
|
{
|
2003-02-02 02:09:23 +00:00
|
|
|
vf_eq2_t *eq2;
|
|
|
|
unsigned long img_n,img_c;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
eq2 = vf->priv;
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
bool skip = true;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
skip &= eq2->param[i].adjust == NULL;
|
|
|
|
|
|
|
|
if (skip)
|
|
|
|
return src;
|
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
if ((eq2->buf_w[0] != src->w) || (eq2->buf_h[0] != src->h)) {
|
|
|
|
eq2->buf_w[0] = src->w;
|
|
|
|
eq2->buf_h[0] = src->h;
|
2015-04-10 19:02:16 +00:00
|
|
|
eq2->buf_w[1] = eq2->buf_w[2] = src->w >> src->fmt.chroma_xs;
|
|
|
|
eq2->buf_h[1] = eq2->buf_h[2] = src->h >> src->fmt.chroma_ys;
|
2003-02-02 02:09:23 +00:00
|
|
|
img_n = eq2->buf_w[0]*eq2->buf_h[0];
|
|
|
|
if(src->num_planes>1){
|
|
|
|
img_c = eq2->buf_w[1]*eq2->buf_h[1];
|
2010-02-26 15:01:37 +00:00
|
|
|
eq2->buf[0] = realloc (eq2->buf[0], img_n + 2*img_c);
|
2003-02-02 02:09:23 +00:00
|
|
|
eq2->buf[1] = eq2->buf[0] + img_n;
|
|
|
|
eq2->buf[2] = eq2->buf[1] + img_c;
|
|
|
|
} else
|
2010-02-26 15:01:37 +00:00
|
|
|
eq2->buf[0] = realloc (eq2->buf[0], img_n);
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct mp_image dst = *src;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
for (int i = 0; i < ((src->num_planes>1)?3:1); i++) {
|
2003-02-02 02:09:23 +00:00
|
|
|
if (eq2->param[i].adjust != NULL) {
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
dst.planes[i] = eq2->buf[i];
|
|
|
|
dst.stride[i] = eq2->buf_w[i];
|
2002-09-27 21:08:36 +00:00
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
eq2->param[i].adjust (&eq2->param[i], dst.planes[i], src->planes[i],
|
|
|
|
eq2->buf_w[i], eq2->buf_h[i], dst.stride[i], src->stride[i]);
|
2003-02-02 02:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-27 21:08:36 +00:00
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct mp_image *new = vf_alloc_out_image(vf);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (new) {
|
|
|
|
mp_image_copy(new, &dst);
|
|
|
|
mp_image_copy_attributes(new, &dst);
|
|
|
|
}
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
|
|
|
|
talloc_free(src);
|
|
|
|
return new;
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
static
|
|
|
|
void check_values (eq2_param_t *par)
|
|
|
|
{
|
|
|
|
/* yuck! floating point comparisons... */
|
|
|
|
|
|
|
|
if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) {
|
|
|
|
par->adjust = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
par->adjust = &apply_lut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void print_values (vf_eq2_t *eq2)
|
|
|
|
{
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_VERBOSE(eq2, "vf_eq2: c=%.2f b=%.2f g=%.4f s=%.2f \n",
|
2003-02-02 02:09:23 +00:00
|
|
|
eq2->contrast, eq2->brightness, eq2->gamma, eq2->saturation
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void set_contrast (vf_eq2_t *eq2, double c)
|
|
|
|
{
|
|
|
|
eq2->contrast = c;
|
|
|
|
eq2->param[0].c = c;
|
|
|
|
eq2->param[0].lut_clean = 0;
|
|
|
|
check_values (&eq2->param[0]);
|
|
|
|
print_values (eq2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void set_brightness (vf_eq2_t *eq2, double b)
|
|
|
|
{
|
|
|
|
eq2->brightness = b;
|
|
|
|
eq2->param[0].b = b;
|
|
|
|
eq2->param[0].lut_clean = 0;
|
|
|
|
check_values (&eq2->param[0]);
|
|
|
|
print_values (eq2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void set_gamma (vf_eq2_t *eq2, double g)
|
|
|
|
{
|
|
|
|
eq2->gamma = g;
|
|
|
|
|
|
|
|
eq2->param[0].g = eq2->gamma * eq2->ggamma;
|
|
|
|
eq2->param[1].g = sqrt (eq2->bgamma / eq2->ggamma);
|
|
|
|
eq2->param[2].g = sqrt (eq2->rgamma / eq2->ggamma);
|
2003-10-18 23:02:30 +00:00
|
|
|
eq2->param[0].w = eq2->param[1].w = eq2->param[2].w = eq2->gamma_weight;
|
2003-02-02 02:09:23 +00:00
|
|
|
|
|
|
|
eq2->param[0].lut_clean = 0;
|
|
|
|
eq2->param[1].lut_clean = 0;
|
|
|
|
eq2->param[2].lut_clean = 0;
|
|
|
|
|
|
|
|
check_values (&eq2->param[0]);
|
|
|
|
check_values (&eq2->param[1]);
|
|
|
|
check_values (&eq2->param[2]);
|
|
|
|
|
|
|
|
print_values (eq2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void set_saturation (vf_eq2_t *eq2, double s)
|
|
|
|
{
|
|
|
|
eq2->saturation = s;
|
|
|
|
|
|
|
|
eq2->param[1].c = s;
|
|
|
|
eq2->param[2].c = s;
|
|
|
|
|
|
|
|
eq2->param[1].lut_clean = 0;
|
|
|
|
eq2->param[2].lut_clean = 0;
|
|
|
|
|
|
|
|
check_values (&eq2->param[1]);
|
|
|
|
check_values (&eq2->param[2]);
|
|
|
|
|
|
|
|
print_values (eq2);
|
|
|
|
}
|
|
|
|
|
2002-09-27 21:08:36 +00:00
|
|
|
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) {
|
2003-02-02 02:09:23 +00:00
|
|
|
set_gamma (vf->priv, exp (log (8.0) * eq->value / 100.0));
|
2013-08-20 14:11:07 +00:00
|
|
|
vf->priv->gamma_i = eq->value;
|
2002-09-27 21:08:36 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (eq->item, "contrast") == 0) {
|
2003-02-02 02:09:23 +00:00
|
|
|
set_contrast (vf->priv, (1.0 / 100.0) * (eq->value + 100));
|
2013-08-20 14:11:07 +00:00
|
|
|
vf->priv->contrast_i = eq->value;
|
2002-09-27 21:08:36 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (eq->item, "brightness") == 0) {
|
2003-02-02 02:09:23 +00:00
|
|
|
set_brightness (vf->priv, (1.0 / 100.0) * eq->value);
|
2013-08-20 14:11:07 +00:00
|
|
|
vf->priv->brightness_i = eq->value;
|
2003-02-02 02:09:23 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (eq->item, "saturation") == 0) {
|
|
|
|
set_saturation (vf->priv, (double) (eq->value + 100) / 100.0);
|
2013-08-20 14:11:07 +00:00
|
|
|
vf->priv->saturation_i = eq->value;
|
2002-09-27 21:08:36 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VFCTRL_GET_EQUALIZER:
|
|
|
|
eq = (vf_equalizer_t *) data;
|
|
|
|
if (strcmp (eq->item, "gamma") == 0) {
|
2013-08-20 14:11:07 +00:00
|
|
|
eq->value = vf->priv->gamma_i;
|
2002-09-27 21:08:36 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (eq->item, "contrast") == 0) {
|
2013-08-20 14:11:07 +00:00
|
|
|
eq->value = vf->priv->contrast_i;
|
2002-09-27 21:08:36 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (eq->item, "brightness") == 0) {
|
2013-08-20 14:11:07 +00:00
|
|
|
eq->value = vf->priv->brightness_i;
|
2003-02-02 02:09:23 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (eq->item, "saturation") == 0) {
|
2013-08-20 14:11:07 +00:00
|
|
|
eq->value = vf->priv->saturation_i;
|
2002-09-27 21:08:36 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-07 18:33:38 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int query_format (vf_instance_t *vf, unsigned fmt)
|
|
|
|
{
|
|
|
|
switch (fmt) {
|
|
|
|
case IMGFMT_Y8:
|
|
|
|
case IMGFMT_444P:
|
|
|
|
case IMGFMT_422P:
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
case IMGFMT_440P:
|
|
|
|
case IMGFMT_420P:
|
2002-09-27 21:08:36 +00:00
|
|
|
case IMGFMT_411P:
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
case IMGFMT_410P:
|
2002-09-27 21:08:36 +00:00
|
|
|
return vf_next_query_format (vf, fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void uninit (vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
if (vf->priv != NULL) {
|
2003-02-02 02:09:23 +00:00
|
|
|
free (vf->priv->buf[0]);
|
2002-09-27 21:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2013-12-03 23:01:38 +00:00
|
|
|
int vf_open(vf_instance_t *vf)
|
2002-09-27 21:08:36 +00:00
|
|
|
{
|
2003-02-02 02:09:23 +00:00
|
|
|
unsigned i;
|
2002-09-27 21:08:36 +00:00
|
|
|
vf_eq2_t *eq2;
|
2013-12-03 22:32:49 +00:00
|
|
|
double *par = vf->priv->par;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
vf->control = control;
|
|
|
|
vf->query_format = query_format;
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
vf->filter = filter;
|
2002-09-27 21:08:36 +00:00
|
|
|
vf->uninit = uninit;
|
|
|
|
|
|
|
|
eq2 = vf->priv;
|
2013-12-21 16:43:25 +00:00
|
|
|
eq2->log = vf->log;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
eq2->buf[i] = NULL;
|
|
|
|
eq2->buf_w[i] = 0;
|
|
|
|
eq2->buf_h[i] = 0;
|
|
|
|
|
|
|
|
eq2->param[i].adjust = NULL;
|
|
|
|
eq2->param[i].c = 1.0;
|
|
|
|
eq2->param[i].b = 0.0;
|
|
|
|
eq2->param[i].g = 1.0;
|
|
|
|
eq2->param[i].lut_clean = 0;
|
|
|
|
}
|
2002-09-27 21:08:36 +00:00
|
|
|
|
2003-02-02 02:09:23 +00:00
|
|
|
eq2->rgamma = par[4];
|
|
|
|
eq2->ggamma = par[5];
|
|
|
|
eq2->bgamma = par[6];
|
2003-10-18 23:02:30 +00:00
|
|
|
eq2->gamma_weight = par[7];
|
2003-02-02 02:09:23 +00:00
|
|
|
|
|
|
|
set_gamma (eq2, par[0]);
|
2013-08-20 14:11:07 +00:00
|
|
|
eq2->gamma_i = (int) (100.0 * log (vf->priv->gamma) / log (8.0));
|
2003-02-02 02:09:23 +00:00
|
|
|
set_contrast (eq2, par[1]);
|
2013-08-20 14:11:07 +00:00
|
|
|
eq2->contrast_i = (int) (100.0 * vf->priv->contrast) - 100;
|
2003-02-02 02:09:23 +00:00
|
|
|
set_brightness (eq2, par[2]);
|
2013-08-20 14:11:07 +00:00
|
|
|
eq2->brightness_i = (int) (100.0 * vf->priv->brightness);
|
2003-02-02 02:09:23 +00:00
|
|
|
set_saturation (eq2, par[3]);
|
2013-08-20 14:11:07 +00:00
|
|
|
eq2->saturation_i = (int) (100.0 * vf->priv->saturation) - 100;
|
2002-09-27 21:08:36 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-03 22:32:49 +00:00
|
|
|
#define OPT_BASE_STRUCT struct vf_priv_s
|
2012-11-15 14:16:12 +00:00
|
|
|
const vf_info_t vf_info_eq = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "Software equalizer",
|
|
|
|
.name = "eq",
|
|
|
|
.open = &vf_open,
|
2013-12-03 22:32:49 +00:00
|
|
|
.priv_size = sizeof(struct vf_priv_s),
|
|
|
|
.options = (const struct m_option[]){
|
2013-12-04 00:51:27 +00:00
|
|
|
#define PARAM(name, n, def, min_, max_) \
|
|
|
|
OPT_DOUBLE(name, par[n], CONF_RANGE, .min = min_, .max = max_, OPTDEF_DOUBLE(def))
|
|
|
|
PARAM("gamma", 0, 1.0, 0.1, 10),
|
|
|
|
PARAM("contrast", 1, 1.0, -2, 2),
|
|
|
|
PARAM("brightness", 2, 0.0, -1, 1),
|
|
|
|
PARAM("saturation", 3, 1.0, 0, 3),
|
|
|
|
PARAM("rg", 4, 1.0, 0.1, 10),
|
|
|
|
PARAM("gg", 5, 1.0, 0.1, 10),
|
|
|
|
PARAM("bg", 6, 1.0, 0.1, 10),
|
|
|
|
PARAM("weight", 7, 1.0, 0, 1),
|
2013-12-03 22:32:49 +00:00
|
|
|
{0}
|
|
|
|
},
|
2002-09-27 21:08:36 +00:00
|
|
|
};
|