2009-12-31 18:25:35 +00:00
|
|
|
/*
|
|
|
|
* Common code related to colorspaces and conversion
|
|
|
|
*
|
|
|
|
* Copyleft (C) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2009-12-31 18:25:35 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-12-31 18:25:35 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-12-31 18:25:35 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-01-19 17:36:34 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2010-06-13 10:42:32 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2009-12-31 18:25:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <math.h>
|
2011-08-29 02:38:44 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <libavutil/common.h>
|
2013-06-28 19:14:43 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2011-08-29 02:38:44 +00:00
|
|
|
|
2015-01-06 14:21:26 +00:00
|
|
|
#include "mp_image.h"
|
2009-12-31 18:25:35 +00:00
|
|
|
#include "csputils.h"
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
#include "options/m_config.h"
|
2015-03-30 21:52:28 +00:00
|
|
|
#include "options/m_option.h"
|
2009-12-31 18:25:35 +00:00
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
const struct m_opt_choice_alternatives pl_csp_names[] = {
|
|
|
|
{"auto", PL_COLOR_SYSTEM_UNKNOWN},
|
|
|
|
{"bt.601", PL_COLOR_SYSTEM_BT_601},
|
|
|
|
{"bt.709", PL_COLOR_SYSTEM_BT_709},
|
|
|
|
{"smpte-240m", PL_COLOR_SYSTEM_SMPTE_240M},
|
|
|
|
{"bt.2020-ncl", PL_COLOR_SYSTEM_BT_2020_NC},
|
|
|
|
{"bt.2020-cl", PL_COLOR_SYSTEM_BT_2020_C},
|
2024-02-10 23:51:58 +00:00
|
|
|
{"bt.2100-pq", PL_COLOR_SYSTEM_BT_2100_PQ},
|
|
|
|
{"bt.2100-hlg", PL_COLOR_SYSTEM_BT_2100_HLG},
|
|
|
|
{"dolbyvision", PL_COLOR_SYSTEM_DOLBYVISION},
|
2023-11-04 02:55:38 +00:00
|
|
|
{"rgb", PL_COLOR_SYSTEM_RGB},
|
|
|
|
{"xyz", PL_COLOR_SYSTEM_XYZ},
|
|
|
|
{"ycgco", PL_COLOR_SYSTEM_YCGCO},
|
2015-03-30 21:52:28 +00:00
|
|
|
{0}
|
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
|
|
|
};
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
const struct m_opt_choice_alternatives pl_csp_levels_names[] = {
|
|
|
|
{"auto", PL_COLOR_LEVELS_UNKNOWN},
|
|
|
|
{"limited", PL_COLOR_LEVELS_LIMITED},
|
|
|
|
{"full", PL_COLOR_LEVELS_FULL},
|
2015-03-30 21:52:28 +00:00
|
|
|
{0}
|
2013-07-14 23:48:25 +00:00
|
|
|
};
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
const struct m_opt_choice_alternatives pl_csp_prim_names[] = {
|
|
|
|
{"auto", PL_COLOR_PRIM_UNKNOWN},
|
|
|
|
{"bt.601-525", PL_COLOR_PRIM_BT_601_525},
|
|
|
|
{"bt.601-625", PL_COLOR_PRIM_BT_601_625},
|
|
|
|
{"bt.709", PL_COLOR_PRIM_BT_709},
|
|
|
|
{"bt.2020", PL_COLOR_PRIM_BT_2020},
|
|
|
|
{"bt.470m", PL_COLOR_PRIM_BT_470M},
|
|
|
|
{"apple", PL_COLOR_PRIM_APPLE},
|
|
|
|
{"adobe", PL_COLOR_PRIM_ADOBE},
|
|
|
|
{"prophoto", PL_COLOR_PRIM_PRO_PHOTO},
|
|
|
|
{"cie1931", PL_COLOR_PRIM_CIE_1931},
|
|
|
|
{"dci-p3", PL_COLOR_PRIM_DCI_P3},
|
|
|
|
{"display-p3", PL_COLOR_PRIM_DISPLAY_P3},
|
|
|
|
{"v-gamut", PL_COLOR_PRIM_V_GAMUT},
|
|
|
|
{"s-gamut", PL_COLOR_PRIM_S_GAMUT},
|
|
|
|
{"ebu3213", PL_COLOR_PRIM_EBU_3213},
|
|
|
|
{"film-c", PL_COLOR_PRIM_FILM_C},
|
|
|
|
{"aces-ap0", PL_COLOR_PRIM_ACES_AP0},
|
|
|
|
{"aces-ap1", PL_COLOR_PRIM_ACES_AP1},
|
2015-03-30 21:52:28 +00:00
|
|
|
{0}
|
2014-03-26 00:46:38 +00:00
|
|
|
};
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
const struct m_opt_choice_alternatives pl_csp_trc_names[] = {
|
|
|
|
{"auto", PL_COLOR_TRC_UNKNOWN},
|
|
|
|
{"bt.1886", PL_COLOR_TRC_BT_1886},
|
|
|
|
{"srgb", PL_COLOR_TRC_SRGB},
|
|
|
|
{"linear", PL_COLOR_TRC_LINEAR},
|
|
|
|
{"gamma1.8", PL_COLOR_TRC_GAMMA18},
|
|
|
|
{"gamma2.0", PL_COLOR_TRC_GAMMA20},
|
|
|
|
{"gamma2.2", PL_COLOR_TRC_GAMMA22},
|
|
|
|
{"gamma2.4", PL_COLOR_TRC_GAMMA24},
|
|
|
|
{"gamma2.6", PL_COLOR_TRC_GAMMA26},
|
|
|
|
{"gamma2.8", PL_COLOR_TRC_GAMMA28},
|
|
|
|
{"prophoto", PL_COLOR_TRC_PRO_PHOTO},
|
|
|
|
{"pq", PL_COLOR_TRC_PQ},
|
|
|
|
{"hlg", PL_COLOR_TRC_HLG},
|
|
|
|
{"v-log", PL_COLOR_TRC_V_LOG},
|
|
|
|
{"s-log1", PL_COLOR_TRC_S_LOG1},
|
|
|
|
{"s-log2", PL_COLOR_TRC_S_LOG2},
|
|
|
|
{"st428", PL_COLOR_TRC_ST428},
|
2015-03-30 12:54:52 +00:00
|
|
|
{0}
|
Revert "Revert recent vo_opengl related commits"
Omitted a simple, but devastasting check. Fixed the relevant commits
now.
This reverts commit 8d24e9d9b8ad1b5d82139980eca148dc0f4a1eab.
diff --git a/video/out/gl_video.c b/video/out/gl_video.c
index 9c8a643..f1ea03e 100644
--- a/video/out/gl_video.c
+++ b/video/out/gl_video.c
@@ -1034,9 +1034,9 @@ static void compile_shaders(struct gl_video *p)
shader_def_opt(&header_conv, "USE_CONV_GAMMA", use_conv_gamma);
shader_def_opt(&header_conv, "USE_CONST_LUMA", use_const_luma);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_BT1886",
- gamma_fun == MP_CSP_TRC_BT_1886);
+ use_linear_light && gamma_fun == MP_CSP_TRC_BT_1886);
shader_def_opt(&header_conv, "USE_LINEAR_LIGHT_SRGB",
- gamma_fun == MP_CSP_TRC_SRGB);
+ use_linear_light && gamma_fun == MP_CSP_TRC_SRGB);
shader_def_opt(&header_conv, "USE_SIGMOID", use_sigmoid);
if (p->opts.alpha_mode > 0 && p->has_alpha && p->plane_count > 3)
shader_def(&header_conv, "USE_ALPHA_PLANE", "3");
2015-02-28 19:15:12 +00:00
|
|
|
};
|
|
|
|
|
2017-06-14 18:06:56 +00:00
|
|
|
const struct m_opt_choice_alternatives mp_csp_light_names[] = {
|
|
|
|
{"auto", MP_CSP_LIGHT_AUTO},
|
|
|
|
{"display", MP_CSP_LIGHT_DISPLAY},
|
|
|
|
{"hlg", MP_CSP_LIGHT_SCENE_HLG},
|
|
|
|
{"709-1886", MP_CSP_LIGHT_SCENE_709_1886},
|
|
|
|
{"gamma1.2", MP_CSP_LIGHT_SCENE_1_2},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2023-11-04 04:15:27 +00:00
|
|
|
const struct m_opt_choice_alternatives pl_chroma_names[] = {
|
|
|
|
{"unknown", PL_CHROMA_UNKNOWN},
|
|
|
|
{"uhd", PL_CHROMA_TOP_LEFT},
|
|
|
|
{"mpeg2/4/h264",PL_CHROMA_LEFT},
|
|
|
|
{"mpeg1/jpeg", PL_CHROMA_CENTER},
|
|
|
|
{"top", PL_CHROMA_TOP_CENTER},
|
2024-08-24 09:04:21 +00:00
|
|
|
{"bottom-left", PL_CHROMA_BOTTOM_LEFT},
|
2023-11-04 04:15:27 +00:00
|
|
|
{"bottom", PL_CHROMA_BOTTOM_CENTER},
|
2015-03-30 21:52:28 +00:00
|
|
|
{0}
|
2014-02-15 15:28:39 +00:00
|
|
|
};
|
|
|
|
|
2023-11-04 03:54:51 +00:00
|
|
|
const struct m_opt_choice_alternatives pl_alpha_names[] = {
|
|
|
|
{"auto", PL_ALPHA_UNKNOWN},
|
|
|
|
{"straight", PL_ALPHA_INDEPENDENT},
|
|
|
|
{"premul", PL_ALPHA_PREMULTIPLIED},
|
2020-04-24 12:41:50 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2014-08-30 21:24:46 +00:00
|
|
|
// The short name _must_ match with what vf_stereo3d accepts (if supported).
|
2015-04-02 21:54:08 +00:00
|
|
|
// The long name in comments is closer to the Matroska spec (StereoMode element).
|
2014-08-30 21:54:19 +00:00
|
|
|
// The numeric index matches the Matroska StereoMode value. If you add entries
|
|
|
|
// that don't match Matroska, make sure demux_mkv.c rejects them properly.
|
2015-04-02 21:54:08 +00:00
|
|
|
const struct m_opt_choice_alternatives mp_stereo3d_names[] = {
|
2015-07-10 16:04:34 +00:00
|
|
|
{"no", -1}, // disable/invalid
|
2015-04-02 21:54:08 +00:00
|
|
|
{"mono", 0},
|
|
|
|
{"sbs2l", 1}, // "side_by_side_left"
|
|
|
|
{"ab2r", 2}, // "top_bottom_right"
|
|
|
|
{"ab2l", 3}, // "top_bottom_left"
|
|
|
|
{"checkr", 4}, // "checkboard_right" (unsupported by vf_stereo3d)
|
|
|
|
{"checkl", 5}, // "checkboard_left" (unsupported by vf_stereo3d)
|
|
|
|
{"irr", 6}, // "row_interleaved_right"
|
|
|
|
{"irl", 7}, // "row_interleaved_left"
|
|
|
|
{"icr", 8}, // "column_interleaved_right" (unsupported by vf_stereo3d)
|
|
|
|
{"icl", 9}, // "column_interleaved_left" (unsupported by vf_stereo3d)
|
|
|
|
{"arcc", 10}, // "anaglyph_cyan_red" (Matroska: unclear which mode)
|
|
|
|
{"sbs2r", 11}, // "side_by_side_right"
|
|
|
|
{"agmc", 12}, // "anaglyph_green_magenta" (Matroska: unclear which mode)
|
2015-12-18 15:06:09 +00:00
|
|
|
{"al", 13}, // "alternating frames left first"
|
|
|
|
{"ar", 14}, // "alternating frames right first"
|
2015-04-02 21:54:08 +00:00
|
|
|
{0}
|
2014-08-30 21:24:46 +00:00
|
|
|
};
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
enum pl_color_system mp_csp_guess_colorspace(int width, int height)
|
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
|
|
|
{
|
2023-11-04 02:55:38 +00:00
|
|
|
return width >= 1280 || height > 576 ? PL_COLOR_SYSTEM_BT_709 : PL_COLOR_SYSTEM_BT_601;
|
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
|
|
|
}
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
enum pl_color_primaries mp_csp_guess_primaries(int width, int height)
|
2014-04-01 22:40:36 +00:00
|
|
|
{
|
|
|
|
// HD content
|
|
|
|
if (width >= 1280 || height > 576)
|
2023-11-04 02:55:38 +00:00
|
|
|
return PL_COLOR_PRIM_BT_709;
|
2014-04-01 22:40:36 +00:00
|
|
|
|
|
|
|
switch (height) {
|
|
|
|
case 576: // Typical PAL content, including anamorphic/squared
|
2023-11-04 02:55:38 +00:00
|
|
|
return PL_COLOR_PRIM_BT_601_625;
|
2014-04-01 22:40:36 +00:00
|
|
|
|
|
|
|
case 480: // Typical NTSC content, including squared
|
|
|
|
case 486: // NTSC Pro or anamorphic NTSC
|
2023-11-04 02:55:38 +00:00
|
|
|
return PL_COLOR_PRIM_BT_601_525;
|
2014-04-01 22:40:36 +00:00
|
|
|
|
|
|
|
default: // No good metric, just pick BT.709 to minimize damage
|
2023-11-04 02:55:38 +00:00
|
|
|
return PL_COLOR_PRIM_BT_709;
|
2014-04-01 22:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-04 05:27:38 +00:00
|
|
|
// LMS<-XYZ revised matrix from CIECAM97, based on a linear transform and
|
|
|
|
// normalized for equal energy on monochrome inputs
|
|
|
|
static const pl_matrix3x3 m_cat97 = {{
|
|
|
|
{ 0.8562, 0.3372, -0.1934 },
|
|
|
|
{ -0.8360, 1.8327, 0.0033 },
|
|
|
|
{ 0.0357, -0.0469, 1.0112 },
|
|
|
|
}};
|
2014-06-22 06:33:43 +00:00
|
|
|
|
2014-03-31 22:17:07 +00:00
|
|
|
// M := M * XYZd<-XYZs
|
2023-11-04 05:27:38 +00:00
|
|
|
static void apply_chromatic_adaptation(struct pl_cie_xy src,
|
|
|
|
struct pl_cie_xy dest, pl_matrix3x3 *mat)
|
2014-03-31 22:17:07 +00:00
|
|
|
{
|
|
|
|
// If the white points are nearly identical, this is a wasteful identity
|
|
|
|
// operation.
|
|
|
|
if (fabs(src.x - dest.x) < 1e-6 && fabs(src.y - dest.y) < 1e-6)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// XYZd<-XYZs = Ma^-1 * (I*[Cd/Cs]) * Ma
|
|
|
|
// http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
|
2023-11-04 05:27:38 +00:00
|
|
|
// For Ma, we use the CIECAM97 revised (linear) matrix
|
|
|
|
float C[3][2];
|
2014-03-31 22:17:07 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
// source cone
|
2023-11-04 05:27:38 +00:00
|
|
|
C[i][0] = m_cat97.m[i][0] * pl_cie_X(src)
|
|
|
|
+ m_cat97.m[i][1] * 1
|
|
|
|
+ m_cat97.m[i][2] * pl_cie_Z(src);
|
2014-03-31 22:17:07 +00:00
|
|
|
|
|
|
|
// dest cone
|
2023-11-04 05:27:38 +00:00
|
|
|
C[i][1] = m_cat97.m[i][0] * pl_cie_X(dest)
|
|
|
|
+ m_cat97.m[i][1] * 1
|
|
|
|
+ m_cat97.m[i][2] * pl_cie_Z(dest);
|
2014-03-31 22:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tmp := I * [Cd/Cs] * Ma
|
2023-11-04 05:27:38 +00:00
|
|
|
pl_matrix3x3 tmp = {0};
|
2014-03-31 22:17:07 +00:00
|
|
|
for (int i = 0; i < 3; i++)
|
2023-11-04 05:27:38 +00:00
|
|
|
tmp.m[i][i] = C[i][1] / C[i][0];
|
2014-03-31 22:17:07 +00:00
|
|
|
|
2023-11-04 05:27:38 +00:00
|
|
|
pl_matrix3x3_mul(&tmp, &m_cat97);
|
2014-03-31 22:17:07 +00:00
|
|
|
|
|
|
|
// M := M * Ma^-1 * tmp
|
2023-11-04 05:27:38 +00:00
|
|
|
pl_matrix3x3 ma_inv = m_cat97;
|
|
|
|
pl_matrix3x3_invert(&ma_inv);
|
|
|
|
pl_matrix3x3_mul(mat, &ma_inv);
|
|
|
|
pl_matrix3x3_mul(mat, &tmp);
|
2015-01-06 12:46:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 22:41:29 +00:00
|
|
|
// Get multiplication factor required if image data is fit within the LSBs of a
|
2020-05-09 16:00:15 +00:00
|
|
|
// higher smaller bit depth fixed-point texture data.
|
|
|
|
// This is broken. Use mp_get_csp_uint_mul().
|
2023-11-04 02:55:38 +00:00
|
|
|
double mp_get_csp_mul(enum pl_color_system csp, int input_bits, int texture_bits)
|
2015-12-07 22:41:29 +00:00
|
|
|
{
|
|
|
|
assert(texture_bits >= input_bits);
|
|
|
|
|
|
|
|
// Convenience for some irrelevant cases, e.g. rgb565 or disabling expansion.
|
|
|
|
if (!input_bits)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// RGB always uses the full range available.
|
2023-11-04 02:55:38 +00:00
|
|
|
if (csp == PL_COLOR_SYSTEM_RGB)
|
2015-12-07 22:41:29 +00:00
|
|
|
return ((1LL << input_bits) - 1.) / ((1LL << texture_bits) - 1.);
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
if (csp == PL_COLOR_SYSTEM_XYZ)
|
2015-12-07 22:41:29 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
// High bit depth YUV uses a range shifted from 8 bit.
|
|
|
|
return (1LL << input_bits) / ((1LL << texture_bits) - 1.) * 255 / 256;
|
|
|
|
}
|
|
|
|
|
2020-05-09 16:00:15 +00:00
|
|
|
// Return information about color fixed point representation.his is needed for
|
|
|
|
// converting color from integer formats to or from float. Use as follows:
|
|
|
|
// float_val = uint_val * m + o
|
|
|
|
// uint_val = clamp(round((float_val - o) / m))
|
|
|
|
// See H.264/5 Annex E.
|
|
|
|
// csp: colorspace
|
|
|
|
// levels: full range flag
|
|
|
|
// component: ID of the channel, as in mp_regular_imgfmt:
|
|
|
|
// 1 is red/luminance/gray, 2 is green/Cb, 3 is blue/Cr, 4 is alpha.
|
|
|
|
// bits: number of significant bits, e.g. 10 for yuv420p10, 16 for p010
|
|
|
|
// out_m: returns factor to multiply the uint number with
|
|
|
|
// out_o: returns offset to add after multiplication
|
2023-11-04 02:55:38 +00:00
|
|
|
void mp_get_csp_uint_mul(enum pl_color_system csp, enum pl_color_levels levels,
|
2020-05-09 16:00:15 +00:00
|
|
|
int bits, int component, double *out_m, double *out_o)
|
|
|
|
{
|
|
|
|
uint16_t i_min = 0;
|
|
|
|
uint16_t i_max = (1u << bits) - 1;
|
|
|
|
double f_min = 0; // min. float value
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
if (csp != PL_COLOR_SYSTEM_RGB && component != 4) {
|
2020-05-09 16:00:15 +00:00
|
|
|
if (component == 2 || component == 3) {
|
|
|
|
f_min = (1u << (bits - 1)) / -(double)i_max; // force center => 0
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
if (levels != PL_COLOR_LEVELS_FULL && bits >= 8) {
|
2020-05-09 16:00:15 +00:00
|
|
|
i_min = 16 << (bits - 8); // => -0.5
|
|
|
|
i_max = 240 << (bits - 8); // => 0.5
|
|
|
|
f_min = -0.5;
|
|
|
|
}
|
|
|
|
} else {
|
2023-11-04 02:55:38 +00:00
|
|
|
if (levels != PL_COLOR_LEVELS_FULL && bits >= 8) {
|
2020-05-09 16:00:15 +00:00
|
|
|
i_min = 16 << (bits - 8); // => 0
|
|
|
|
i_max = 235 << (bits - 8); // => 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_m = 1.0 / (i_max - i_min);
|
|
|
|
*out_o = (1 + f_min) - i_max * *out_m;
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:22:12 +00:00
|
|
|
/* Fill in the Y, U, V vectors of a yuv-to-rgb conversion matrix
|
2011-08-29 02:38:44 +00:00
|
|
|
* based on the given luma weights of the R, G and B components (lr, lg, lb).
|
|
|
|
* lr+lg+lb is assumed to equal 1.
|
|
|
|
* This function is meant for colorspaces satisfying the following
|
|
|
|
* conditions (which are true for common YUV colorspaces):
|
|
|
|
* - The mapping from input [Y, U, V] to output [R, G, B] is linear.
|
|
|
|
* - Y is the vector [1, 1, 1]. (meaning input Y component maps to 1R+1G+1B)
|
|
|
|
* - U maps to a value with zero R and positive B ([0, x, y], y > 0;
|
|
|
|
* i.e. blue and green only).
|
|
|
|
* - V maps to a value with zero B and positive R ([x, y, 0], x > 0;
|
|
|
|
* i.e. red and green only).
|
|
|
|
* - U and V are orthogonal to the luma vector [lr, lg, lb].
|
|
|
|
* - The magnitudes of the vectors U and V are the minimal ones for which
|
|
|
|
* the image of the set Y=[0...1],U=[-0.5...0.5],V=[-0.5...0.5] under the
|
|
|
|
* conversion function will cover the set R=[0...1],G=[0...1],B=[0...1]
|
|
|
|
* (the resulting matrix can be converted for other input/output ranges
|
|
|
|
* outside this function).
|
|
|
|
* Under these conditions the given parameters lr, lg, lb uniquely
|
|
|
|
* determine the mapping of Y, U, V to R, G, B.
|
|
|
|
*/
|
2023-11-04 05:27:38 +00:00
|
|
|
static void luma_coeffs(struct pl_transform3x3 *mat, float lr, float lg, float lb)
|
2011-08-29 02:38:44 +00:00
|
|
|
{
|
|
|
|
assert(fabs(lr+lg+lb - 1) < 1e-6);
|
2023-11-04 05:27:38 +00:00
|
|
|
*mat = (struct pl_transform3x3) {
|
|
|
|
{ {{1, 0, 2 * (1-lr) },
|
|
|
|
{1, -2 * (1-lb) * lb/lg, -2 * (1-lr) * lr/lg },
|
|
|
|
{1, 2 * (1-lb), 0 }} },
|
2015-01-06 15:49:53 +00:00
|
|
|
// Constant coefficients (mat->c) not set here
|
|
|
|
};
|
2011-08-29 02:38:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 12:46:08 +00:00
|
|
|
// get the coefficients of the yuv -> rgb conversion matrix
|
2023-11-04 05:27:38 +00:00
|
|
|
void mp_get_csp_matrix(struct mp_csp_params *params, struct pl_transform3x3 *m)
|
2011-08-28 02:52:46 +00:00
|
|
|
{
|
2023-11-04 02:55:38 +00:00
|
|
|
enum pl_color_system colorspace = params->repr.sys;
|
|
|
|
if (colorspace <= PL_COLOR_SYSTEM_UNKNOWN || colorspace >= PL_COLOR_SYSTEM_COUNT)
|
|
|
|
colorspace = PL_COLOR_SYSTEM_BT_601;
|
2024-02-10 23:51:58 +00:00
|
|
|
// Not supported. TODO: replace with pl_color_repr_decode
|
|
|
|
if (colorspace == PL_COLOR_SYSTEM_BT_2100_PQ ||
|
|
|
|
colorspace == PL_COLOR_SYSTEM_BT_2100_HLG ||
|
|
|
|
colorspace == PL_COLOR_SYSTEM_DOLBYVISION) {
|
|
|
|
colorspace = PL_COLOR_SYSTEM_BT_2020_NC;
|
|
|
|
}
|
2023-11-04 02:55:38 +00:00
|
|
|
enum pl_color_levels levels_in = params->repr.levels;
|
|
|
|
if (levels_in <= PL_COLOR_LEVELS_UNKNOWN || levels_in >= PL_COLOR_LEVELS_COUNT)
|
|
|
|
levels_in = PL_COLOR_LEVELS_LIMITED;
|
2013-05-01 21:59:00 +00:00
|
|
|
|
2015-01-06 14:04:29 +00:00
|
|
|
switch (colorspace) {
|
2023-11-04 02:55:38 +00:00
|
|
|
case PL_COLOR_SYSTEM_BT_601: luma_coeffs(m, 0.299, 0.587, 0.114 ); break;
|
|
|
|
case PL_COLOR_SYSTEM_BT_709: luma_coeffs(m, 0.2126, 0.7152, 0.0722); break;
|
|
|
|
case PL_COLOR_SYSTEM_SMPTE_240M: luma_coeffs(m, 0.2122, 0.7013, 0.0865); break;
|
|
|
|
case PL_COLOR_SYSTEM_BT_2020_NC: luma_coeffs(m, 0.2627, 0.6780, 0.0593); break;
|
|
|
|
case PL_COLOR_SYSTEM_BT_2020_C: {
|
2014-03-26 22:00:09 +00:00
|
|
|
// Note: This outputs into the [-0.5,0.5] range for chroma information.
|
|
|
|
// If this clips on any VO, a constant 0.5 coefficient can be added
|
|
|
|
// to the chroma channels to normalize them into [0,1]. This is not
|
|
|
|
// currently needed by anything, though.
|
2023-11-04 05:27:38 +00:00
|
|
|
*m = (struct pl_transform3x3){{{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}}}};
|
2014-03-26 22:00:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-11-04 02:55:38 +00:00
|
|
|
case PL_COLOR_SYSTEM_RGB: {
|
2023-11-04 05:27:38 +00:00
|
|
|
*m = (struct pl_transform3x3){{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}};
|
2013-05-01 21:59:00 +00:00
|
|
|
levels_in = -1;
|
|
|
|
break;
|
|
|
|
}
|
2023-11-04 02:55:38 +00:00
|
|
|
case PL_COLOR_SYSTEM_XYZ: {
|
2023-11-04 05:27:38 +00:00
|
|
|
// For lack of anything saner to do, just assume the caller wants
|
|
|
|
// DCI-P3 primaries, which is a reasonable assumption.
|
|
|
|
const struct pl_raw_primaries *dst = pl_raw_primaries_get(PL_COLOR_PRIM_DCI_P3);
|
|
|
|
pl_matrix3x3 mat = pl_get_xyz2rgb_matrix(dst);
|
|
|
|
// DCDM X'Y'Z' is expected to have equal energy white point (EG 432-1 Annex H)
|
|
|
|
apply_chromatic_adaptation((struct pl_cie_xy){1.0/3.0, 1.0/3.0}, dst->white, &mat);
|
|
|
|
*m = (struct pl_transform3x3) { .mat = mat };
|
2013-05-01 21:59:00 +00:00
|
|
|
levels_in = -1;
|
|
|
|
break;
|
|
|
|
}
|
2023-11-04 02:55:38 +00:00
|
|
|
case PL_COLOR_SYSTEM_YCGCO: {
|
2023-11-04 05:27:38 +00:00
|
|
|
*m = (struct pl_transform3x3) {
|
|
|
|
{{{1, -1, 1},
|
|
|
|
{1, 1, 0},
|
|
|
|
{1, -1, -1}}},
|
2013-05-02 23:37:13 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
2011-08-29 02:38:44 +00:00
|
|
|
default:
|
2023-01-10 18:26:51 +00:00
|
|
|
MP_ASSERT_UNREACHABLE();
|
2011-08-28 02:52:46 +00:00
|
|
|
};
|
2009-12-31 19:59:58 +00:00
|
|
|
|
2020-05-09 15:57:48 +00:00
|
|
|
if (params->is_float)
|
|
|
|
levels_in = -1;
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
if ((colorspace == PL_COLOR_SYSTEM_BT_601 || colorspace == PL_COLOR_SYSTEM_BT_709 ||
|
|
|
|
colorspace == PL_COLOR_SYSTEM_SMPTE_240M || colorspace == PL_COLOR_SYSTEM_BT_2020_NC))
|
2015-12-12 13:47:30 +00:00
|
|
|
{
|
|
|
|
// Hue is equivalent to rotating input [U, V] subvector around the origin.
|
|
|
|
// Saturation scales [U, V].
|
2015-12-26 17:36:55 +00:00
|
|
|
float huecos = params->gray ? 0 : params->saturation * cos(params->hue);
|
|
|
|
float huesin = params->gray ? 0 : params->saturation * sin(params->hue);
|
2015-12-12 13:47:30 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2023-11-04 05:27:38 +00:00
|
|
|
float u = m->mat.m[i][1], v = m->mat.m[i][2];
|
|
|
|
m->mat.m[i][1] = huecos * u - huesin * v;
|
|
|
|
m->mat.m[i][2] = huesin * u + huecos * v;
|
2015-12-12 13:47:30 +00:00
|
|
|
}
|
2011-08-29 02:38:44 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 22:41:29 +00:00
|
|
|
// The values below are written in 0-255 scale - thus bring s into range.
|
|
|
|
double s =
|
|
|
|
mp_get_csp_mul(colorspace, params->input_bits, params->texture_bits) / 255;
|
2016-07-05 16:03:19 +00:00
|
|
|
// NOTE: The yuvfull ranges as presented here are arguably ambiguous,
|
|
|
|
// and conflict with at least the full-range YCbCr/ICtCp values as defined
|
|
|
|
// by ITU-R BT.2100. If somebody ever complains about full-range YUV looking
|
|
|
|
// different from their reference display, this comment is probably why.
|
2017-05-13 15:20:28 +00:00
|
|
|
struct yuvlevels { double ymin, ymax, cmax, cmid; }
|
|
|
|
yuvlim = { 16*s, 235*s, 240*s, 128*s },
|
|
|
|
yuvfull = { 0*s, 255*s, 255*s, 128*s },
|
|
|
|
anyfull = { 0*s, 255*s, 255*s/2, 0 }, // cmax picked to make cmul=ymul
|
2011-08-29 02:38:44 +00:00
|
|
|
yuvlev;
|
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
|
|
|
switch (levels_in) {
|
2023-11-04 02:55:38 +00:00
|
|
|
case PL_COLOR_LEVELS_LIMITED: yuvlev = yuvlim; break;
|
|
|
|
case PL_COLOR_LEVELS_FULL: yuvlev = yuvfull; break;
|
2013-05-01 21:59:00 +00:00
|
|
|
case -1: yuvlev = anyfull; break;
|
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
|
|
|
default:
|
2023-01-10 18:26:51 +00:00
|
|
|
MP_ASSERT_UNREACHABLE();
|
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
|
|
|
}
|
|
|
|
|
2015-01-06 14:04:29 +00:00
|
|
|
int levels_out = params->levels_out;
|
2023-11-04 02:55:38 +00:00
|
|
|
if (levels_out <= PL_COLOR_LEVELS_UNKNOWN || levels_out >= PL_COLOR_LEVELS_COUNT)
|
|
|
|
levels_out = PL_COLOR_LEVELS_FULL;
|
2011-08-29 02:38:44 +00:00
|
|
|
struct rgblevels { double min, max; }
|
2012-03-08 03:25:33 +00:00
|
|
|
rgblim = { 16/255., 235/255. },
|
|
|
|
rgbfull = { 0, 1 },
|
2011-08-29 02:38:44 +00:00
|
|
|
rgblev;
|
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
|
|
|
switch (levels_out) {
|
2023-11-04 02:55:38 +00:00
|
|
|
case PL_COLOR_LEVELS_LIMITED: rgblev = rgblim; break;
|
|
|
|
case PL_COLOR_LEVELS_FULL: rgblev = rgbfull; break;
|
2011-08-29 02:38:44 +00:00
|
|
|
default:
|
2023-01-10 18:26:51 +00:00
|
|
|
MP_ASSERT_UNREACHABLE();
|
2011-08-29 02:38:44 +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
|
|
|
|
2011-08-29 02:38:44 +00:00
|
|
|
double ymul = (rgblev.max - rgblev.min) / (yuvlev.ymax - yuvlev.ymin);
|
2017-05-13 15:20:28 +00:00
|
|
|
double cmul = (rgblev.max - rgblev.min) / (yuvlev.cmax - yuvlev.cmid) / 2;
|
2015-04-29 20:04:11 +00:00
|
|
|
|
|
|
|
// Contrast scales the output value range (gain)
|
|
|
|
ymul *= params->contrast;
|
|
|
|
cmul *= params->contrast;
|
|
|
|
|
2011-08-29 02:38:44 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2023-11-04 05:27:38 +00:00
|
|
|
m->mat.m[i][0] *= ymul;
|
|
|
|
m->mat.m[i][1] *= cmul;
|
|
|
|
m->mat.m[i][2] *= cmul;
|
2015-04-29 20:04:11 +00:00
|
|
|
// Set c so that Y=umin,UV=cmid maps to RGB=min (black to black),
|
|
|
|
// also add brightness offset (black lift)
|
2023-11-04 05:27:38 +00:00
|
|
|
m->c[i] = rgblev.min - m->mat.m[i][0] * yuvlev.ymin
|
|
|
|
- (m->mat.m[i][1] + m->mat.m[i][2]) * yuvlev.cmid
|
2015-04-29 20:04:11 +00:00
|
|
|
+ params->brightness;
|
2011-08-29 02:38:44 +00:00
|
|
|
}
|
2009-12-31 18:25:35 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 14:21:26 +00:00
|
|
|
// Set colorspace related fields in p from f. Don't touch other fields.
|
|
|
|
void mp_csp_set_image_params(struct mp_csp_params *params,
|
|
|
|
const struct mp_image_params *imgparams)
|
|
|
|
{
|
|
|
|
struct mp_image_params p = *imgparams;
|
|
|
|
mp_image_params_guess_csp(&p); // ensure consistency
|
2024-01-26 15:08:48 +00:00
|
|
|
params->repr = p.repr;
|
2016-06-29 07:16:13 +00:00
|
|
|
params->color = p.color;
|
|
|
|
}
|
|
|
|
|
2023-02-15 21:08:51 +00:00
|
|
|
enum mp_csp_equalizer_param {
|
|
|
|
MP_CSP_EQ_BRIGHTNESS,
|
|
|
|
MP_CSP_EQ_CONTRAST,
|
|
|
|
MP_CSP_EQ_HUE,
|
|
|
|
MP_CSP_EQ_SATURATION,
|
|
|
|
MP_CSP_EQ_GAMMA,
|
|
|
|
MP_CSP_EQ_COUNT,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Default initialization with 0 is enough, except for the capabilities field
|
|
|
|
struct mp_csp_equalizer_opts {
|
|
|
|
// Value for each property is in the range [-100.0, 100.0].
|
|
|
|
// 0.0 is default, meaning neutral or no change.
|
|
|
|
float values[MP_CSP_EQ_COUNT];
|
|
|
|
int output_levels;
|
|
|
|
};
|
|
|
|
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
#define OPT_BASE_STRUCT struct mp_csp_equalizer_opts
|
|
|
|
|
|
|
|
const struct m_sub_options mp_csp_equalizer_conf = {
|
|
|
|
.opts = (const m_option_t[]) {
|
2023-02-15 21:01:50 +00:00
|
|
|
{"brightness", OPT_FLOAT(values[MP_CSP_EQ_BRIGHTNESS]),
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
M_RANGE(-100, 100)},
|
2023-02-15 21:01:50 +00:00
|
|
|
{"saturation", OPT_FLOAT(values[MP_CSP_EQ_SATURATION]),
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
M_RANGE(-100, 100)},
|
2023-02-15 21:01:50 +00:00
|
|
|
{"contrast", OPT_FLOAT(values[MP_CSP_EQ_CONTRAST]),
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
M_RANGE(-100, 100)},
|
2023-02-15 21:01:50 +00:00
|
|
|
{"hue", OPT_FLOAT(values[MP_CSP_EQ_HUE]),
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
M_RANGE(-100, 100)},
|
2023-02-15 21:01:50 +00:00
|
|
|
{"gamma", OPT_FLOAT(values[MP_CSP_EQ_GAMMA]),
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
M_RANGE(-100, 100)},
|
|
|
|
{"video-output-levels",
|
2023-11-04 02:55:38 +00:00
|
|
|
OPT_CHOICE_C(output_levels, pl_csp_levels_names)},
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.size = sizeof(struct mp_csp_equalizer_opts),
|
2024-02-01 22:41:43 +00:00
|
|
|
.change_flags = UPDATE_VIDEO,
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +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
|
|
|
// Copy settings from eq into params.
|
2023-02-15 21:08:51 +00:00
|
|
|
static void mp_csp_copy_equalizer_values(struct mp_csp_params *params,
|
|
|
|
const struct mp_csp_equalizer_opts *eq)
|
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
|
|
|
{
|
|
|
|
params->brightness = eq->values[MP_CSP_EQ_BRIGHTNESS] / 100.0;
|
|
|
|
params->contrast = (eq->values[MP_CSP_EQ_CONTRAST] + 100) / 100.0;
|
2015-01-06 15:50:33 +00:00
|
|
|
params->hue = eq->values[MP_CSP_EQ_HUE] / 100.0 * M_PI;
|
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
|
|
|
params->saturation = (eq->values[MP_CSP_EQ_SATURATION] + 100) / 100.0;
|
2015-02-03 15:52:44 +00:00
|
|
|
params->gamma = exp(log(8.0) * eq->values[MP_CSP_EQ_GAMMA] / 100.0);
|
2023-02-15 21:01:50 +00:00
|
|
|
params->levels_out = eq->output_levels;
|
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
|
|
|
}
|
|
|
|
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
struct mp_csp_equalizer_state *mp_csp_equalizer_create(void *ta_parent,
|
|
|
|
struct mpv_global *global)
|
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
|
|
|
{
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
struct m_config_cache *c = m_config_cache_alloc(ta_parent, global,
|
|
|
|
&mp_csp_equalizer_conf);
|
|
|
|
// The terrible, terrible truth.
|
|
|
|
return (struct mp_csp_equalizer_state *)c;
|
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
|
|
|
}
|
|
|
|
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
bool mp_csp_equalizer_state_changed(struct mp_csp_equalizer_state *state)
|
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
|
|
|
{
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
struct m_config_cache *c = (struct m_config_cache *)state;
|
|
|
|
return m_config_cache_update(c);
|
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
|
|
|
}
|
|
|
|
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
void mp_csp_equalizer_state_get(struct mp_csp_equalizer_state *state,
|
|
|
|
struct mp_csp_params *params)
|
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
|
|
|
{
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
struct m_config_cache *c = (struct m_config_cache *)state;
|
|
|
|
m_config_cache_update(c);
|
|
|
|
struct mp_csp_equalizer_opts *opts = c->opts;
|
|
|
|
mp_csp_copy_equalizer_values(params, opts);
|
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
|
|
|
}
|
2012-10-24 17:11:42 +00:00
|
|
|
|
2012-10-07 22:14:51 +00:00
|
|
|
// Multiply the color in c with the given matrix.
|
2015-12-08 23:08:00 +00:00
|
|
|
// i/o is {R, G, B} or {Y, U, V} (depending on input/output and matrix), using
|
|
|
|
// a fixed point representation with the given number of bits (so for bits==8,
|
|
|
|
// [0,255] maps to [0,1]). The output is clipped to the range as needed.
|
2023-11-04 05:27:38 +00:00
|
|
|
void mp_map_fixp_color(struct pl_transform3x3 *matrix, int ibits, int in[3],
|
2015-12-08 23:08:00 +00:00
|
|
|
int obits, int out[3])
|
2012-10-07 22:14:51 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2015-01-06 15:49:53 +00:00
|
|
|
double val = matrix->c[i];
|
2012-10-07 22:14:51 +00:00
|
|
|
for (int x = 0; x < 3; x++)
|
2023-11-04 05:27:38 +00:00
|
|
|
val += matrix->mat.m[i][x] * in[x] / ((1 << ibits) - 1);
|
2015-12-08 23:08:00 +00:00
|
|
|
int ival = lrint(val * ((1 << obits) - 1));
|
|
|
|
out[i] = av_clip(ival, 0, (1 << obits) - 1);
|
2012-10-07 22:14:51 +00:00
|
|
|
}
|
|
|
|
}
|