2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-04-07 20:21:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "cpudetect.h"
|
2008-04-24 04:23:15 +00:00
|
|
|
#include "options.h"
|
2002-04-07 20:21:37 +00:00
|
|
|
|
2002-04-13 19:14:34 +00:00
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
2002-04-07 20:21:37 +00:00
|
|
|
#include "vf.h"
|
2006-09-17 15:02:13 +00:00
|
|
|
#include "fmt-conversion.h"
|
2008-04-28 14:43:30 +00:00
|
|
|
#include "mpbswap.h"
|
2002-04-07 20:21:37 +00:00
|
|
|
|
2006-06-30 12:00:31 +00:00
|
|
|
#include "libswscale/swscale.h"
|
2003-06-01 21:59:29 +00:00
|
|
|
#include "vf_scale.h"
|
2002-04-07 20:21:37 +00:00
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
#include "libvo/csputils.h"
|
2011-11-03 13:47:50 +00:00
|
|
|
// VOFLAG_SWSCALE
|
|
|
|
#include "libvo/video_out.h"
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
|
2003-03-15 18:01:02 +00:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_struct.h"
|
|
|
|
|
|
|
|
static struct vf_priv_s {
|
2002-04-07 20:21:37 +00:00
|
|
|
int w,h;
|
2011-12-12 20:16:05 +00:00
|
|
|
int cfg_w, cfg_h;
|
2002-06-24 01:05:41 +00:00
|
|
|
int v_chr_drop;
|
2004-09-18 00:08:17 +00:00
|
|
|
double param[2];
|
2002-04-07 21:33:42 +00:00
|
|
|
unsigned int fmt;
|
2003-02-23 22:05:55 +00:00
|
|
|
struct SwsContext *ctx;
|
2003-12-29 14:16:07 +00:00
|
|
|
struct SwsContext *ctx2; //for interlaced slices only
|
2002-10-17 21:53:30 +00:00
|
|
|
unsigned char* palette;
|
2003-12-29 14:16:07 +00:00
|
|
|
int interlaced;
|
2006-02-18 21:12:56 +00:00
|
|
|
int noup;
|
2006-07-24 10:36:06 +00:00
|
|
|
int accurate_rnd;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
struct mp_csp_details colorspace;
|
2007-01-28 16:48:01 +00:00
|
|
|
} const vf_priv_dflt = {
|
2011-12-12 20:16:05 +00:00
|
|
|
0, 0,
|
2003-03-15 18:01:02 +00:00
|
|
|
-1,-1,
|
|
|
|
0,
|
2004-09-18 00:08:17 +00:00
|
|
|
{SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
|
2003-03-15 18:01:02 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
2003-12-29 14:16:07 +00:00
|
|
|
NULL,
|
2003-03-15 18:01:02 +00:00
|
|
|
NULL
|
2002-04-07 20:21:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
2003-04-25 11:26:34 +00:00
|
|
|
void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam);
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const unsigned int outfmt_list[]={
|
2004-04-23 15:24:24 +00:00
|
|
|
// YUV:
|
|
|
|
IMGFMT_444P,
|
2009-12-31 23:25:21 +00:00
|
|
|
IMGFMT_444P16_LE,
|
|
|
|
IMGFMT_444P16_BE,
|
2011-06-25 22:22:53 +00:00
|
|
|
IMGFMT_444P10_LE,
|
|
|
|
IMGFMT_444P10_BE,
|
|
|
|
IMGFMT_444P9_LE,
|
|
|
|
IMGFMT_444P9_BE,
|
2004-04-23 15:24:24 +00:00
|
|
|
IMGFMT_422P,
|
2009-12-31 23:25:21 +00:00
|
|
|
IMGFMT_422P16_LE,
|
|
|
|
IMGFMT_422P16_BE,
|
2011-06-25 22:22:53 +00:00
|
|
|
IMGFMT_422P10_LE,
|
|
|
|
IMGFMT_422P10_BE,
|
2004-04-23 15:24:24 +00:00
|
|
|
IMGFMT_YV12,
|
|
|
|
IMGFMT_I420,
|
2009-12-31 23:25:21 +00:00
|
|
|
IMGFMT_420P16_LE,
|
|
|
|
IMGFMT_420P16_BE,
|
2011-06-25 22:22:53 +00:00
|
|
|
IMGFMT_420P10_LE,
|
|
|
|
IMGFMT_420P10_BE,
|
|
|
|
IMGFMT_420P9_LE,
|
|
|
|
IMGFMT_420P9_BE,
|
2009-12-31 23:45:07 +00:00
|
|
|
IMGFMT_420A,
|
2004-04-23 15:24:24 +00:00
|
|
|
IMGFMT_IYUV,
|
|
|
|
IMGFMT_YVU9,
|
|
|
|
IMGFMT_IF09,
|
|
|
|
IMGFMT_411P,
|
2005-02-16 23:47:00 +00:00
|
|
|
IMGFMT_NV12,
|
|
|
|
IMGFMT_NV21,
|
2004-04-23 15:24:24 +00:00
|
|
|
IMGFMT_YUY2,
|
|
|
|
IMGFMT_UYVY,
|
2009-12-30 12:06:09 +00:00
|
|
|
IMGFMT_440P,
|
2004-05-14 21:08:53 +00:00
|
|
|
// RGB and grayscale (Y8 and Y800):
|
2002-04-07 21:33:42 +00:00
|
|
|
IMGFMT_BGR32,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB32,
|
2002-09-15 13:36:37 +00:00
|
|
|
IMGFMT_BGR24,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB24,
|
2009-11-21 18:58:03 +00:00
|
|
|
IMGFMT_RGB48LE,
|
|
|
|
IMGFMT_RGB48BE,
|
2002-09-15 13:36:37 +00:00
|
|
|
IMGFMT_BGR16,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB16,
|
2002-09-15 13:36:37 +00:00
|
|
|
IMGFMT_BGR15,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB15,
|
2010-05-06 10:18:25 +00:00
|
|
|
IMGFMT_BGR12,
|
|
|
|
IMGFMT_RGB12,
|
2004-05-14 21:08:53 +00:00
|
|
|
IMGFMT_Y800,
|
|
|
|
IMGFMT_Y8,
|
2002-09-15 13:36:37 +00:00
|
|
|
IMGFMT_BGR8,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB8,
|
2002-09-15 13:36:37 +00:00
|
|
|
IMGFMT_BGR4,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB4,
|
2003-01-30 09:15:09 +00:00
|
|
|
IMGFMT_BG4B,
|
|
|
|
IMGFMT_RG4B,
|
2002-09-15 13:36:37 +00:00
|
|
|
IMGFMT_BGR1,
|
2002-07-04 13:08:37 +00:00
|
|
|
IMGFMT_RGB1,
|
2002-05-25 13:22:28 +00:00
|
|
|
0
|
2002-04-07 21:33:42 +00:00
|
|
|
};
|
|
|
|
|
2010-01-23 19:00:09 +00:00
|
|
|
/**
|
|
|
|
* A list of preferred conversions, in order of preference.
|
|
|
|
* This should be used for conversions that e.g. involve no scaling
|
|
|
|
* or to stop vf_scale from choosing a conversion that has no
|
|
|
|
* fast assembler implementation.
|
|
|
|
*/
|
|
|
|
static int preferred_conversions[][2] = {
|
|
|
|
{IMGFMT_YUY2, IMGFMT_UYVY},
|
|
|
|
{IMGFMT_YUY2, IMGFMT_422P},
|
|
|
|
{IMGFMT_UYVY, IMGFMT_YUY2},
|
|
|
|
{IMGFMT_UYVY, IMGFMT_422P},
|
|
|
|
{IMGFMT_422P, IMGFMT_YUY2},
|
|
|
|
{IMGFMT_422P, IMGFMT_UYVY},
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int find_best_out(vf_instance_t *vf, int in_format){
|
2002-04-07 21:33:42 +00:00
|
|
|
unsigned int best=0;
|
2010-01-23 19:00:09 +00:00
|
|
|
int i = -1;
|
|
|
|
int j = -1;
|
|
|
|
int format = 0;
|
2003-11-03 12:15:32 +00:00
|
|
|
|
2002-04-07 21:33:42 +00:00
|
|
|
// find the best outfmt:
|
2010-01-23 19:00:09 +00:00
|
|
|
while (1) {
|
|
|
|
int ret;
|
|
|
|
if (j < 0) {
|
|
|
|
format = in_format;
|
|
|
|
j = 0;
|
|
|
|
} else if (i < 0) {
|
|
|
|
while (preferred_conversions[j][0] &&
|
|
|
|
preferred_conversions[j][0] != in_format)
|
|
|
|
j++;
|
|
|
|
format = preferred_conversions[j++][1];
|
|
|
|
// switch to standard list
|
|
|
|
if (!format)
|
|
|
|
i = 0;
|
2003-11-03 12:15:32 +00:00
|
|
|
}
|
2010-01-23 19:00:09 +00:00
|
|
|
if (i >= 0)
|
|
|
|
format = outfmt_list[i++];
|
|
|
|
if (!format)
|
|
|
|
break;
|
|
|
|
ret = vf_next_query_format(vf, format);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-11-03 12:15:32 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
|
|
|
|
if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
|
|
|
|
best=format; // no conversion -> bingo!
|
|
|
|
break;
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
|
|
|
if(ret&VFCAP_CSP_SUPPORTED && !best)
|
2003-11-03 12:15:32 +00:00
|
|
|
best=format; // best with conversion
|
2002-04-07 21:33:42 +00:00
|
|
|
}
|
2002-04-11 20:56:17 +00:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2002-04-11 20:56:17 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
2008-04-24 04:23:15 +00:00
|
|
|
struct MPOpts *opts = vf->opts;
|
2010-01-23 19:00:09 +00:00
|
|
|
unsigned int best=find_best_out(vf, outfmt);
|
2002-04-11 20:56:17 +00:00
|
|
|
int vo_flags;
|
2002-06-24 01:05:41 +00:00
|
|
|
int int_sws_flags=0;
|
2005-03-06 21:15:24 +00:00
|
|
|
int round_w=0, round_h=0;
|
2008-05-11 12:37:04 +00:00
|
|
|
int i;
|
2002-06-24 01:05:41 +00:00
|
|
|
SwsFilter *srcFilter, *dstFilter;
|
2006-09-17 15:02:13 +00:00
|
|
|
enum PixelFormat dfmt, sfmt;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
vf->priv->colorspace = (struct mp_csp_details) {0};
|
|
|
|
|
2002-04-07 21:33:42 +00:00
|
|
|
if(!best){
|
2002-05-20 03:25:26 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
|
2002-04-07 21:33:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-09-17 15:02:13 +00:00
|
|
|
sfmt = imgfmt2pixfmt(outfmt);
|
2007-06-07 19:11:25 +00:00
|
|
|
if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
|
2006-09-17 15:02:13 +00:00
|
|
|
dfmt = imgfmt2pixfmt(best);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-04-11 20:56:17 +00:00
|
|
|
vo_flags=vf->next->query_format(vf->next,best);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-12-12 20:16:05 +00:00
|
|
|
vf->priv->w = vf->priv->cfg_w;
|
|
|
|
vf->priv->h = vf->priv->cfg_h;
|
|
|
|
|
2002-04-11 20:56:17 +00:00
|
|
|
// scaling to dwidth*d_height, if all these TRUE:
|
|
|
|
// - option -zoom
|
|
|
|
// - no other sw/hw up/down scaling avail.
|
|
|
|
// - we're after postproc
|
|
|
|
// - user didn't set w:h
|
2011-11-03 13:47:50 +00:00
|
|
|
if(!(vo_flags&VFCAP_POSTPROC) && (flags&VOFLAG_SWSCALE) &&
|
2002-04-11 20:56:17 +00:00
|
|
|
vf->priv->w<0 && vf->priv->h<0){ // -zoom
|
|
|
|
int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
|
|
|
|
if(d_width<width || d_height<height){
|
|
|
|
// downscale!
|
|
|
|
if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
|
|
|
|
} else {
|
|
|
|
// upscale:
|
|
|
|
if(vo_flags&VFCAP_HWSCALE_UP) x=0;
|
|
|
|
}
|
|
|
|
if(x){
|
|
|
|
// user wants sw scaling! (-zoom)
|
|
|
|
vf->priv->w=d_width;
|
|
|
|
vf->priv->h=d_height;
|
|
|
|
}
|
|
|
|
}
|
2002-04-07 21:33:42 +00:00
|
|
|
|
2006-02-18 21:12:56 +00:00
|
|
|
if(vf->priv->noup){
|
2006-02-24 15:22:59 +00:00
|
|
|
if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
|
2006-02-18 21:12:56 +00:00
|
|
|
vf->priv->w= width;
|
|
|
|
vf->priv->h= height;
|
2006-02-24 15:22:59 +00:00
|
|
|
}
|
2006-02-18 21:12:56 +00:00
|
|
|
}
|
|
|
|
|
2005-12-17 20:00:16 +00:00
|
|
|
if (vf->priv->w <= -8) {
|
|
|
|
vf->priv->w += 8;
|
2005-03-06 21:15:24 +00:00
|
|
|
round_w = 1;
|
|
|
|
}
|
2005-12-17 20:00:16 +00:00
|
|
|
if (vf->priv->h <= -8) {
|
|
|
|
vf->priv->h += 8;
|
2005-03-06 21:15:24 +00:00
|
|
|
round_h = 1;
|
|
|
|
}
|
|
|
|
|
2004-11-12 11:15:26 +00:00
|
|
|
if (vf->priv->w < -3 || vf->priv->h < -3 ||
|
|
|
|
(vf->priv->w < -1 && vf->priv->h < -1)) {
|
|
|
|
// TODO: establish a direct connection to the user's brain
|
|
|
|
// and find out what the heck he thinks MPlayer should do
|
|
|
|
// with this nonsense.
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vf->priv->w == -1)
|
|
|
|
vf->priv->w = width;
|
|
|
|
if (vf->priv->w == 0)
|
|
|
|
vf->priv->w = d_width;
|
|
|
|
|
|
|
|
if (vf->priv->h == -1)
|
|
|
|
vf->priv->h = height;
|
|
|
|
if (vf->priv->h == 0)
|
|
|
|
vf->priv->h = d_height;
|
|
|
|
|
|
|
|
if (vf->priv->w == -3)
|
|
|
|
vf->priv->w = vf->priv->h * width / height;
|
|
|
|
if (vf->priv->w == -2)
|
|
|
|
vf->priv->w = vf->priv->h * d_width / d_height;
|
|
|
|
|
|
|
|
if (vf->priv->h == -3)
|
|
|
|
vf->priv->h = vf->priv->w * height / width;
|
|
|
|
if (vf->priv->h == -2)
|
|
|
|
vf->priv->h = vf->priv->w * d_height / d_width;
|
|
|
|
|
2005-03-06 21:15:24 +00:00
|
|
|
if (round_w)
|
|
|
|
vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
|
|
|
|
if (round_h)
|
|
|
|
vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
|
|
|
|
|
2002-04-07 20:21:37 +00:00
|
|
|
// calculate the missing parameters:
|
2002-07-18 14:06:32 +00:00
|
|
|
switch(best) {
|
|
|
|
case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
|
2003-10-09 22:32:30 +00:00
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
2005-02-16 23:47:00 +00:00
|
|
|
case IMGFMT_NV12:
|
|
|
|
case IMGFMT_NV21:
|
2004-11-12 11:15:26 +00:00
|
|
|
vf->priv->h = (vf->priv->h + 1) & ~1;
|
|
|
|
case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
vf->priv->w = (vf->priv->w + 1) & ~1;
|
2002-07-18 14:06:32 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-05-20 03:25:26 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
|
2002-04-07 21:33:42 +00:00
|
|
|
width,height,vo_format_name(outfmt),
|
|
|
|
vf->priv->w,vf->priv->h,vo_format_name(best));
|
2002-04-07 23:30:59 +00:00
|
|
|
|
|
|
|
// free old ctx:
|
2003-02-23 22:05:55 +00:00
|
|
|
if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
|
2003-12-29 14:16:07 +00:00
|
|
|
if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-04-07 20:21:37 +00:00
|
|
|
// new swscaler:
|
2003-02-23 22:05:55 +00:00
|
|
|
sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
|
2002-06-24 01:05:41 +00:00
|
|
|
int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
|
2006-07-24 10:36:06 +00:00
|
|
|
int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
|
2003-12-29 14:16:07 +00:00
|
|
|
vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
|
2006-09-17 15:02:13 +00:00
|
|
|
sfmt,
|
2003-12-29 14:16:07 +00:00
|
|
|
vf->priv->w, vf->priv->h >> vf->priv->interlaced,
|
2006-09-17 15:02:13 +00:00
|
|
|
dfmt,
|
2004-09-18 00:08:17 +00:00
|
|
|
int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
|
2003-12-29 14:16:07 +00:00
|
|
|
if(vf->priv->interlaced){
|
|
|
|
vf->priv->ctx2=sws_getContext(width, height >> 1,
|
2006-09-17 15:02:13 +00:00
|
|
|
sfmt,
|
2003-12-29 14:16:07 +00:00
|
|
|
vf->priv->w, vf->priv->h >> 1,
|
2006-09-17 15:02:13 +00:00
|
|
|
dfmt,
|
2004-09-18 00:08:17 +00:00
|
|
|
int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
|
2003-12-29 14:16:07 +00:00
|
|
|
}
|
2002-04-07 20:21:37 +00:00
|
|
|
if(!vf->priv->ctx){
|
|
|
|
// error...
|
2002-05-20 03:25:26 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
|
2002-04-07 20:21:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-04-07 21:33:42 +00:00
|
|
|
vf->priv->fmt=best;
|
2002-05-12 19:06:15 +00:00
|
|
|
|
2010-11-14 09:12:34 +00:00
|
|
|
free(vf->priv->palette);
|
|
|
|
vf->priv->palette=NULL;
|
2002-10-17 21:53:30 +00:00
|
|
|
switch(best){
|
2007-02-17 11:34:25 +00:00
|
|
|
case IMGFMT_RGB8: {
|
|
|
|
/* set 332 palette for 8 bpp */
|
|
|
|
vf->priv->palette=malloc(4*256);
|
|
|
|
for(i=0; i<256; i++){
|
|
|
|
vf->priv->palette[4*i+0]=4*(i>>6)*21;
|
|
|
|
vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
|
|
|
|
vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
|
|
|
|
vf->priv->palette[4*i+3]=0;
|
|
|
|
}
|
|
|
|
break; }
|
2002-10-17 21:53:30 +00:00
|
|
|
case IMGFMT_BGR8: {
|
|
|
|
/* set 332 palette for 8 bpp */
|
|
|
|
vf->priv->palette=malloc(4*256);
|
|
|
|
for(i=0; i<256; i++){
|
|
|
|
vf->priv->palette[4*i+0]=4*(i&3)*21;
|
|
|
|
vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
|
|
|
|
vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
|
2007-02-17 11:04:13 +00:00
|
|
|
vf->priv->palette[4*i+3]=0;
|
2002-10-17 21:53:30 +00:00
|
|
|
}
|
|
|
|
break; }
|
2009-07-06 23:26:13 +00:00
|
|
|
case IMGFMT_BGR4:
|
2003-01-30 09:15:09 +00:00
|
|
|
case IMGFMT_BG4B: {
|
2002-10-17 21:53:30 +00:00
|
|
|
vf->priv->palette=malloc(4*16);
|
|
|
|
for(i=0; i<16; i++){
|
|
|
|
vf->priv->palette[4*i+0]=4*(i&1)*63;
|
|
|
|
vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
|
|
|
|
vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
|
2007-02-17 11:04:13 +00:00
|
|
|
vf->priv->palette[4*i+3]=0;
|
2002-10-17 21:53:30 +00:00
|
|
|
}
|
|
|
|
break; }
|
2009-07-06 23:26:13 +00:00
|
|
|
case IMGFMT_RGB4:
|
2007-02-17 11:40:01 +00:00
|
|
|
case IMGFMT_RG4B: {
|
|
|
|
vf->priv->palette=malloc(4*16);
|
|
|
|
for(i=0; i<16; i++){
|
|
|
|
vf->priv->palette[4*i+0]=4*(i>>3)*63;
|
|
|
|
vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
|
|
|
|
vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
|
|
|
|
vf->priv->palette[4*i+3]=0;
|
|
|
|
}
|
|
|
|
break; }
|
2002-10-17 21:53:30 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 04:23:15 +00:00
|
|
|
if (!opts->screen_size_x && !opts->screen_size_y
|
2008-04-24 04:28:20 +00:00
|
|
|
&& !(opts->screen_size_xy >= 0.001)) {
|
2003-04-27 10:04:39 +00:00
|
|
|
// Compute new d_width and d_height, preserving aspect
|
|
|
|
// while ensuring that both are >= output size in pixels.
|
|
|
|
if (vf->priv->h * d_width > vf->priv->w * d_height) {
|
|
|
|
d_width = vf->priv->h * d_width / d_height;
|
|
|
|
d_height = vf->priv->h;
|
|
|
|
} else {
|
|
|
|
d_height = vf->priv->w * d_height / d_width;
|
|
|
|
d_width = vf->priv->w;
|
|
|
|
}
|
|
|
|
//d_width=d_width*vf->priv->w/width;
|
|
|
|
//d_height=d_height*vf->priv->h/height;
|
2002-05-12 19:06:15 +00:00
|
|
|
}
|
2002-04-07 22:45:07 +00:00
|
|
|
return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
|
2002-04-07 20:21:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void start_slice(struct vf_instance *vf, mp_image_t *mpi){
|
2003-02-23 20:40:46 +00:00
|
|
|
// printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
|
|
|
|
if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
|
|
|
|
// they want slices!!! allocate the buffer.
|
2003-05-20 17:42:33 +00:00
|
|
|
mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
|
2003-02-23 20:40:46 +00:00
|
|
|
// mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
|
|
|
|
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
|
|
|
|
vf->priv->w, vf->priv->h);
|
|
|
|
}
|
|
|
|
|
2009-03-29 14:46:59 +00:00
|
|
|
static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
|
|
|
|
int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
|
2011-05-04 20:12:55 +00:00
|
|
|
const uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2], src[3]};
|
2009-07-26 19:53:00 +00:00
|
|
|
#if HAVE_BIGENDIAN
|
2007-02-17 12:58:35 +00:00
|
|
|
uint32_t pal2[256];
|
|
|
|
if (src[1] && !src[2]){
|
|
|
|
int i;
|
|
|
|
for(i=0; i<256; i++)
|
|
|
|
pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
|
|
|
|
src2[1]= pal2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-12-29 14:16:07 +00:00
|
|
|
if(interlaced){
|
|
|
|
int i;
|
2010-01-01 01:06:34 +00:00
|
|
|
uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2], dst[3]};
|
|
|
|
int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2], 2*src_stride[3]};
|
|
|
|
int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2], 2*dst_stride[3]};
|
2003-12-29 14:16:07 +00:00
|
|
|
|
2010-01-03 17:12:12 +00:00
|
|
|
sws_scale(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
|
2010-01-01 01:25:35 +00:00
|
|
|
for(i=0; i<MP_MAX_PLANES; i++){
|
2003-12-29 14:16:07 +00:00
|
|
|
src2[i] += src_stride[i];
|
|
|
|
dst2[i] += dst_stride[i];
|
|
|
|
}
|
2010-01-03 17:12:12 +00:00
|
|
|
sws_scale(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
|
2003-12-29 14:16:07 +00:00
|
|
|
}else{
|
2010-01-03 17:12:12 +00:00
|
|
|
sws_scale(sws1, src2, src_stride, y, h, dst, dst_stride);
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2003-12-29 14:16:07 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void draw_slice(struct vf_instance *vf,
|
2003-02-23 20:40:46 +00:00
|
|
|
unsigned char** src, int* stride, int w,int h, int x, int y){
|
2003-05-20 17:42:33 +00:00
|
|
|
mp_image_t *dmpi=vf->dmpi;
|
2003-02-23 20:40:46 +00:00
|
|
|
if(!dmpi){
|
2007-08-28 17:06:00 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
|
2003-02-23 20:40:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
|
2003-12-29 14:16:07 +00:00
|
|
|
scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
|
2003-02-23 20:40:46 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
|
2003-02-23 20:40:46 +00:00
|
|
|
mp_image_t *dmpi=mpi->priv;
|
2002-04-07 20:21:37 +00:00
|
|
|
|
2003-02-23 20:40:46 +00:00
|
|
|
// printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
|
|
|
|
// dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-23 20:40:46 +00:00
|
|
|
if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-04-07 20:21:37 +00:00
|
|
|
// hope we'll get DR buffer:
|
2002-04-07 21:33:42 +00:00
|
|
|
dmpi=vf_get_image(vf->next,vf->priv->fmt,
|
2002-08-02 22:57:58 +00:00
|
|
|
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
|
2002-04-07 20:21:37 +00:00
|
|
|
vf->priv->w, vf->priv->h);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-12-29 14:16:07 +00:00
|
|
|
scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
|
2003-02-23 20:40:46 +00:00
|
|
|
}
|
|
|
|
|
2002-04-08 00:06:03 +00:00
|
|
|
if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
|
|
|
|
// just conversion, no scaling -> keep postprocessing data
|
|
|
|
// this way we can apply pp filter to non-yv12 source using scaler
|
2003-04-19 02:48:53 +00:00
|
|
|
vf_clone_mpi_attributes(dmpi, mpi);
|
2002-04-08 00:06:03 +00:00
|
|
|
}
|
2002-10-17 21:53:30 +00:00
|
|
|
|
|
|
|
if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-03-21 21:26:42 +00:00
|
|
|
return vf_next_put_image(vf,dmpi, pts);
|
2002-04-07 20:21:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int control(struct vf_instance *vf, int request, void* data){
|
2003-02-21 20:35:18 +00:00
|
|
|
int *table;
|
|
|
|
int *inv_table;
|
|
|
|
int r;
|
|
|
|
int brightness, contrast, saturation, srcRange, dstRange;
|
|
|
|
vf_equalizer_t *eq;
|
|
|
|
|
2003-08-16 19:22:11 +00:00
|
|
|
if(vf->priv->ctx)
|
2003-02-21 20:35:18 +00:00
|
|
|
switch(request){
|
|
|
|
case VFCTRL_GET_EQUALIZER:
|
|
|
|
r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
|
|
|
|
if(r<0) break;
|
|
|
|
|
|
|
|
eq = data;
|
|
|
|
if (!strcmp(eq->item,"brightness")) {
|
|
|
|
eq->value = ((brightness*100) + (1<<15))>>16;
|
|
|
|
}
|
|
|
|
else if (!strcmp(eq->item,"contrast")) {
|
|
|
|
eq->value = (((contrast *100) + (1<<15))>>16) - 100;
|
|
|
|
}
|
|
|
|
else if (!strcmp(eq->item,"saturation")) {
|
|
|
|
eq->value = (((saturation*100) + (1<<15))>>16) - 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
case VFCTRL_SET_EQUALIZER:
|
|
|
|
r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
|
|
|
|
if(r<0) break;
|
|
|
|
//printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
|
|
|
|
eq = data;
|
|
|
|
|
|
|
|
if (!strcmp(eq->item,"brightness")) {
|
|
|
|
brightness = (( eq->value <<16) + 50)/100;
|
|
|
|
}
|
|
|
|
else if (!strcmp(eq->item,"contrast")) {
|
|
|
|
contrast = (((eq->value+100)<<16) + 50)/100;
|
|
|
|
}
|
|
|
|
else if (!strcmp(eq->item,"saturation")) {
|
|
|
|
saturation = (((eq->value+100)<<16) + 50)/100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
|
|
|
|
if(r<0) break;
|
2003-12-29 14:16:07 +00:00
|
|
|
if(vf->priv->ctx2){
|
|
|
|
r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
|
|
|
|
if(r<0) break;
|
|
|
|
}
|
2003-02-21 20:35:18 +00:00
|
|
|
|
|
|
|
return CONTROL_TRUE;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
case VFCTRL_SET_YUV_COLORSPACE: {
|
|
|
|
struct mp_csp_details colorspace = *(struct mp_csp_details *)data;
|
|
|
|
if (mp_sws_set_colorspace(vf->priv->ctx, &colorspace) >= 0) {
|
|
|
|
if (vf->priv->ctx2)
|
|
|
|
mp_sws_set_colorspace(vf->priv->ctx2, &colorspace);
|
|
|
|
vf->priv->colorspace = colorspace;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VFCTRL_GET_YUV_COLORSPACE: {
|
|
|
|
/* This scale filter should never react to colorspace commands if it
|
|
|
|
* doesn't do YUV->RGB conversion. But because finding out whether this
|
|
|
|
* is really YUV->RGB (and not YUV->YUV or anything else) is hard,
|
|
|
|
* react only if the colorspace has been set explicitly before. The
|
|
|
|
* trick is that mp_sws_set_colorspace does not succeed for YUV->YUV
|
|
|
|
* and RGB->YUV conversions, which makes this code correct in "most"
|
|
|
|
* cases. (This would be trivial to do correctly if libswscale exposed
|
|
|
|
* functionality like isYUV()).
|
|
|
|
*/
|
|
|
|
if (vf->priv->colorspace.format) {
|
|
|
|
*(struct mp_csp_details *)data = vf->priv->colorspace;
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-02-21 20:35:18 +00:00
|
|
|
default:
|
2003-06-01 21:59:29 +00:00
|
|
|
break;
|
2003-02-21 20:35:18 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-21 20:35:18 +00:00
|
|
|
return vf_next_control(vf,request,data);
|
|
|
|
}
|
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
static const int mp_csp_to_swscale[MP_CSP_COUNT] = {
|
|
|
|
[MP_CSP_BT_601] = SWS_CS_ITU601,
|
|
|
|
[MP_CSP_BT_709] = SWS_CS_ITU709,
|
|
|
|
[MP_CSP_SMPTE_240M] = SWS_CS_SMPTE240M,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Adjust the colorspace used for YUV->RGB conversion. On other conversions,
|
|
|
|
// do nothing or return an error.
|
|
|
|
// The csp argument is set to the supported values.
|
|
|
|
// Return 0 on success and -1 on error.
|
|
|
|
int mp_sws_set_colorspace(struct SwsContext *sws, struct mp_csp_details *csp)
|
|
|
|
{
|
|
|
|
int *table, *inv_table;
|
|
|
|
int brightness, contrast, saturation, srcRange, dstRange;
|
|
|
|
|
|
|
|
csp->levels_out = MP_CSP_LEVELS_PC;
|
|
|
|
|
|
|
|
// NOTE: returns an error if the destination format is YUV
|
|
|
|
if (sws_getColorspaceDetails(sws, &inv_table, &srcRange, &table, &dstRange,
|
|
|
|
&brightness, &contrast, &saturation) == -1)
|
|
|
|
goto error_out;
|
|
|
|
|
|
|
|
int sws_csp = mp_csp_to_swscale[csp->format];
|
|
|
|
if (sws_csp == 0) {
|
|
|
|
// colorspace not supported, go with a reasonable default
|
|
|
|
csp->format = SWS_CS_ITU601;
|
|
|
|
sws_csp = MP_CSP_BT_601;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The swscale API for these is hardly documented.
|
|
|
|
* Apparently table/range only apply to YUV. Thus dstRange has no effect
|
|
|
|
* for YUV->RGB conversions, and conversions to limited-range RGB are
|
|
|
|
* not supported.
|
|
|
|
*/
|
|
|
|
srcRange = csp->levels_in == MP_CSP_LEVELS_PC;
|
|
|
|
const int *new_inv_table = sws_getCoefficients(sws_csp);
|
|
|
|
|
|
|
|
if (sws_setColorspaceDetails(sws, new_inv_table, srcRange, table, dstRange,
|
|
|
|
brightness, contrast, saturation) == -1)
|
|
|
|
goto error_out;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
*csp = (struct mp_csp_details){0};
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-04-07 20:21:37 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
2003-01-23 09:35:22 +00:00
|
|
|
// supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
|
2002-04-07 21:33:42 +00:00
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt){
|
2010-11-03 16:42:24 +00:00
|
|
|
if (!IMGFMT_IS_HWACCEL(fmt) && imgfmt2pixfmt(fmt) != PIX_FMT_NONE) {
|
2010-01-23 19:00:09 +00:00
|
|
|
unsigned int best=find_best_out(vf, fmt);
|
2002-04-11 20:56:17 +00:00
|
|
|
int flags;
|
|
|
|
if(!best) return 0; // no matching out-fmt
|
|
|
|
flags=vf_next_query_format(vf,best);
|
2005-05-21 15:00:27 +00:00
|
|
|
if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
|
2002-04-11 20:56:17 +00:00
|
|
|
if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
|
|
|
|
// do not allow scaling, if we are before the PP fliter!
|
|
|
|
if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
|
|
|
|
return flags;
|
2002-04-07 21:33:42 +00:00
|
|
|
}
|
2002-04-11 20:56:17 +00:00
|
|
|
return 0; // nomatching in-fmt
|
2002-04-07 21:33:42 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
static void uninit(struct vf_instance *vf){
|
2003-11-29 19:40:30 +00:00
|
|
|
if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
|
2003-12-29 14:16:07 +00:00
|
|
|
if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
|
2010-11-14 09:12:34 +00:00
|
|
|
free(vf->priv->palette);
|
2003-11-29 19:40:30 +00:00
|
|
|
free(vf->priv);
|
|
|
|
}
|
|
|
|
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
2002-04-07 20:21:37 +00:00
|
|
|
vf->config=config;
|
2003-02-23 20:40:46 +00:00
|
|
|
vf->start_slice=start_slice;
|
|
|
|
vf->draw_slice=draw_slice;
|
2002-04-07 20:21:37 +00:00
|
|
|
vf->put_image=put_image;
|
2002-04-07 23:30:59 +00:00
|
|
|
vf->query_format=query_format;
|
2003-02-21 20:35:18 +00:00
|
|
|
vf->control= control;
|
2003-11-29 19:40:30 +00:00
|
|
|
vf->uninit=uninit;
|
2002-05-20 03:25:26 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
|
2011-12-12 20:16:05 +00:00
|
|
|
vf->priv->cfg_w,
|
|
|
|
vf->priv->cfg_h);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-04-07 20:21:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-04-24 17:04:20 +00:00
|
|
|
//global sws_flags from the command line
|
|
|
|
int sws_flags=2;
|
|
|
|
|
|
|
|
//global srcFilter
|
2003-04-25 11:26:34 +00:00
|
|
|
static SwsFilter *src_filter= NULL;
|
2003-04-24 17:04:20 +00:00
|
|
|
|
|
|
|
float sws_lum_gblur= 0.0;
|
|
|
|
float sws_chr_gblur= 0.0;
|
|
|
|
int sws_chr_vshift= 0;
|
|
|
|
int sws_chr_hshift= 0;
|
|
|
|
float sws_chr_sharpen= 0.0;
|
|
|
|
float sws_lum_sharpen= 0.0;
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
int get_sws_cpuflags(void){
|
2009-07-06 23:26:13 +00:00
|
|
|
return
|
2003-04-24 17:04:20 +00:00
|
|
|
(gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
|
|
|
|
| (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
|
2004-03-11 17:58:11 +00:00
|
|
|
| (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
|
|
|
|
| (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
|
2003-04-24 17:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
|
|
|
|
{
|
|
|
|
static int firstTime=1;
|
|
|
|
*flags=0;
|
|
|
|
|
2009-01-16 09:21:21 +00:00
|
|
|
#if ARCH_X86
|
2003-04-24 17:04:20 +00:00
|
|
|
if(gCpuCaps.hasMMX)
|
2008-10-16 18:59:27 +00:00
|
|
|
__asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
|
2003-04-24 17:04:20 +00:00
|
|
|
#endif
|
|
|
|
if(firstTime)
|
|
|
|
{
|
|
|
|
firstTime=0;
|
|
|
|
*flags= SWS_PRINT_INFO;
|
|
|
|
}
|
2006-03-24 08:12:03 +00:00
|
|
|
else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
|
2003-04-24 17:04:20 +00:00
|
|
|
|
2003-04-25 11:26:34 +00:00
|
|
|
if(src_filter) sws_freeFilter(src_filter);
|
2003-04-24 17:04:20 +00:00
|
|
|
|
2003-04-25 11:26:34 +00:00
|
|
|
src_filter= sws_getDefaultFilter(
|
|
|
|
sws_lum_gblur, sws_chr_gblur,
|
|
|
|
sws_lum_sharpen, sws_chr_sharpen,
|
2003-11-03 12:15:32 +00:00
|
|
|
sws_chr_hshift, sws_chr_vshift, verbose>1);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-04-24 17:04:20 +00:00
|
|
|
switch(sws_flags)
|
|
|
|
{
|
|
|
|
case 0: *flags|= SWS_FAST_BILINEAR; break;
|
|
|
|
case 1: *flags|= SWS_BILINEAR; break;
|
|
|
|
case 2: *flags|= SWS_BICUBIC; break;
|
|
|
|
case 3: *flags|= SWS_X; break;
|
|
|
|
case 4: *flags|= SWS_POINT; break;
|
|
|
|
case 5: *flags|= SWS_AREA; break;
|
|
|
|
case 6: *flags|= SWS_BICUBLIN; break;
|
|
|
|
case 7: *flags|= SWS_GAUSS; break;
|
|
|
|
case 8: *flags|= SWS_SINC; break;
|
|
|
|
case 9: *flags|= SWS_LANCZOS; break;
|
|
|
|
case 10:*flags|= SWS_SPLINE; break;
|
|
|
|
default:*flags|= SWS_BILINEAR; break;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-04-25 11:26:34 +00:00
|
|
|
*srcFilterParam= src_filter;
|
2003-04-24 17:04:20 +00:00
|
|
|
*dstFilterParam= NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// will use sws_flags & src_filter (from cmd line)
|
|
|
|
struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
SwsFilter *dstFilterParam, *srcFilterParam;
|
2006-09-17 15:02:13 +00:00
|
|
|
enum PixelFormat dfmt, sfmt;
|
|
|
|
|
|
|
|
dfmt = imgfmt2pixfmt(dstFormat);
|
|
|
|
sfmt = imgfmt2pixfmt(srcFormat);
|
2007-06-07 20:01:05 +00:00
|
|
|
if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
|
2003-04-24 17:04:20 +00:00
|
|
|
sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
|
|
|
|
|
2006-09-17 15:02:13 +00:00
|
|
|
return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
|
2003-04-24 17:04:20 +00:00
|
|
|
}
|
|
|
|
|
2003-03-15 18:01:02 +00:00
|
|
|
/// An example of presets usage
|
2008-04-26 13:35:40 +00:00
|
|
|
static const struct size_preset {
|
2003-03-15 18:01:02 +00:00
|
|
|
char* name;
|
|
|
|
int w, h;
|
|
|
|
} vf_size_presets_defs[] = {
|
|
|
|
// TODO add more 'standard' resolutions
|
2003-09-05 15:30:46 +00:00
|
|
|
{ "qntsc", 352, 240 },
|
|
|
|
{ "qpal", 352, 288 },
|
|
|
|
{ "ntsc", 720, 480 },
|
|
|
|
{ "pal", 720, 576 },
|
|
|
|
{ "sntsc", 640, 480 },
|
|
|
|
{ "spal", 768, 576 },
|
2003-03-15 18:01:02 +00:00
|
|
|
{ NULL, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(f) M_ST_OFF(struct size_preset,f)
|
2008-04-26 13:35:40 +00:00
|
|
|
static const m_option_t vf_size_preset_fields[] = {
|
2003-03-15 18:01:02 +00:00
|
|
|
{"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
|
|
|
|
{"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
|
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const m_struct_t vf_size_preset = {
|
2003-03-15 18:01:02 +00:00
|
|
|
"scale_size_preset",
|
|
|
|
sizeof(struct size_preset),
|
|
|
|
NULL,
|
|
|
|
vf_size_preset_fields
|
|
|
|
};
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const m_struct_t vf_opts;
|
|
|
|
static const m_obj_presets_t size_preset = {
|
2003-03-15 18:01:02 +00:00
|
|
|
&vf_size_preset, // Input struct desc
|
|
|
|
&vf_opts, // Output struct desc
|
|
|
|
vf_size_presets_defs, // The list of presets
|
|
|
|
ST_OFF(name) // At wich offset is the name field in the preset struct
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Now the options
|
|
|
|
#undef ST_OFF
|
|
|
|
#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
|
2008-04-26 13:35:40 +00:00
|
|
|
static const m_option_t vf_opts_fields[] = {
|
2011-12-12 20:16:05 +00:00
|
|
|
{"w", ST_OFF(cfg_w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
|
|
|
|
{"h", ST_OFF(cfg_h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
|
2003-12-29 14:16:07 +00:00
|
|
|
{"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
|
2003-03-15 18:01:02 +00:00
|
|
|
{"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
|
2004-09-18 00:08:17 +00:00
|
|
|
{"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
|
|
|
|
{"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
|
2003-03-15 18:01:02 +00:00
|
|
|
// Note that here the 2 field is NULL (ie 0)
|
|
|
|
// As we want this option to act on the option struct itself
|
2011-05-04 20:12:55 +00:00
|
|
|
{"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, (void *)&size_preset},
|
2006-08-24 17:21:03 +00:00
|
|
|
{"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
|
2006-07-24 10:36:06 +00:00
|
|
|
{"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
2003-03-15 18:01:02 +00:00
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const m_struct_t vf_opts = {
|
2003-03-15 18:01:02 +00:00
|
|
|
"scale",
|
|
|
|
sizeof(struct vf_priv_s),
|
|
|
|
&vf_priv_dflt,
|
|
|
|
vf_opts_fields
|
|
|
|
};
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_scale = {
|
2002-04-07 20:21:37 +00:00
|
|
|
"software scaling",
|
|
|
|
"scale",
|
|
|
|
"A'rpi",
|
|
|
|
"",
|
2010-02-21 13:40:49 +00:00
|
|
|
vf_open,
|
2003-03-15 18:01:02 +00:00
|
|
|
&vf_opts
|
2002-04-07 20:21:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|