2009-12-31 18:25:35 +00:00
|
|
|
/*
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPLAYER_CSPUTILS_H
|
|
|
|
#define MPLAYER_CSPUTILS_H
|
|
|
|
|
2012-10-27 16:01:51 +00:00
|
|
|
#include <stdbool.h>
|
2009-12-31 18:25:35 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-10-23 22:46:05 +00:00
|
|
|
#include <libplacebo/colorspace.h>
|
|
|
|
|
2015-03-30 21:52:28 +00:00
|
|
|
#include "options/m_option.h"
|
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 21:50:21 +00:00
|
|
|
/* NOTE: the csp and levels AUTO values are converted to specific ones
|
|
|
|
* above vf/vo level. At least vf_scale relies on all valid settings being
|
|
|
|
* nonzero at vf/vo level.
|
|
|
|
*/
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
extern const struct m_opt_choice_alternatives pl_csp_names[];
|
|
|
|
extern const struct m_opt_choice_alternatives pl_csp_levels_names[];
|
|
|
|
extern const struct m_opt_choice_alternatives pl_csp_prim_names[];
|
|
|
|
extern const struct m_opt_choice_alternatives pl_csp_trc_names[];
|
2014-03-26 00:46:38 +00:00
|
|
|
|
2017-06-14 18:06:56 +00:00
|
|
|
enum mp_csp_light {
|
|
|
|
MP_CSP_LIGHT_AUTO,
|
|
|
|
MP_CSP_LIGHT_DISPLAY,
|
|
|
|
MP_CSP_LIGHT_SCENE_HLG,
|
|
|
|
MP_CSP_LIGHT_SCENE_709_1886,
|
|
|
|
MP_CSP_LIGHT_SCENE_1_2,
|
|
|
|
MP_CSP_LIGHT_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct m_opt_choice_alternatives mp_csp_light_names[];
|
|
|
|
|
2014-08-30 21:54:19 +00:00
|
|
|
// The numeric values (except -1) match the Matroska StereoMode element value.
|
2014-08-30 21:24:46 +00:00
|
|
|
enum mp_stereo3d_mode {
|
|
|
|
MP_STEREO3D_INVALID = -1,
|
2014-10-29 22:14:46 +00:00
|
|
|
/* only modes explicitly referenced in the code are listed */
|
2014-08-30 21:24:46 +00:00
|
|
|
MP_STEREO3D_MONO = 0,
|
2014-10-29 22:14:46 +00:00
|
|
|
MP_STEREO3D_SBS2L = 1,
|
|
|
|
MP_STEREO3D_AB2R = 2,
|
|
|
|
MP_STEREO3D_AB2L = 3,
|
|
|
|
MP_STEREO3D_SBS2R = 11,
|
2014-08-30 21:54:19 +00:00
|
|
|
/* no explicit enum entries for most valid values */
|
2015-12-18 18:29:59 +00:00
|
|
|
MP_STEREO3D_COUNT = 15, // 14 is last valid mode
|
2014-08-30 21:24:46 +00:00
|
|
|
};
|
|
|
|
|
2015-04-02 21:54:08 +00:00
|
|
|
extern const struct m_opt_choice_alternatives mp_stereo3d_names[];
|
|
|
|
|
|
|
|
#define MP_STEREO3D_NAME(x) m_opt_choice_str(mp_stereo3d_names, x)
|
2014-08-30 21:24:46 +00:00
|
|
|
|
2014-11-12 18:30:34 +00:00
|
|
|
#define MP_STEREO3D_NAME_DEF(x, def) \
|
|
|
|
(MP_STEREO3D_NAME(x) ? MP_STEREO3D_NAME(x) : (def))
|
2014-08-30 21:24:46 +00:00
|
|
|
|
2017-06-10 12:01:25 +00:00
|
|
|
// For many colorspace conversions, in particular those involving HDR, an
|
|
|
|
// implicit reference white level is needed. Since this magic constant shows up
|
2020-05-17 01:17:28 +00:00
|
|
|
// a lot, give it an explicit name. The value of 203 cd/m² comes from ITU-R
|
|
|
|
// Report BT.2408, and the value for HLG comes from the cited HLG 75% level
|
|
|
|
// (transferred to scene space).
|
|
|
|
#define MP_REF_WHITE 203.0
|
|
|
|
#define MP_REF_WHITE_HLG 3.17955
|
2017-06-10 12:01:25 +00:00
|
|
|
|
2016-06-29 07:16:13 +00:00
|
|
|
struct mp_csp_params {
|
2023-11-04 02:55:38 +00:00
|
|
|
struct pl_color_repr repr;
|
|
|
|
struct pl_color_space color;
|
|
|
|
enum pl_color_levels levels_out; // output device
|
2011-08-28 02:52:46 +00:00
|
|
|
float brightness;
|
|
|
|
float contrast;
|
|
|
|
float hue;
|
|
|
|
float saturation;
|
2015-02-03 15:52:44 +00:00
|
|
|
float gamma;
|
2015-01-21 18:29:18 +00:00
|
|
|
// discard U/V components
|
|
|
|
bool gray;
|
2020-05-09 15:57:48 +00:00
|
|
|
// input is already centered and range-expanded
|
|
|
|
bool is_float;
|
2012-10-25 19:23:18 +00:00
|
|
|
// texture_bits/input_bits is for rescaling fixed point input to range [0,1]
|
2012-03-08 03:25:33 +00:00
|
|
|
int texture_bits;
|
|
|
|
int input_bits;
|
2009-12-31 18:25:35 +00:00
|
|
|
};
|
|
|
|
|
2012-10-07 22:14:51 +00:00
|
|
|
#define MP_CSP_PARAMS_DEFAULTS { \
|
2023-11-04 02:55:38 +00:00
|
|
|
.repr = pl_color_repr_sdtv, \
|
|
|
|
.levels_out = PL_COLOR_LEVELS_FULL, \
|
2012-10-07 22:14:51 +00:00
|
|
|
.brightness = 0, .contrast = 1, .hue = 0, .saturation = 1, \
|
2015-02-03 15:52:44 +00:00
|
|
|
.gamma = 1, .texture_bits = 8, .input_bits = 8}
|
2012-10-07 22:14:51 +00:00
|
|
|
|
2015-01-06 14:21:26 +00:00
|
|
|
struct mp_image_params;
|
|
|
|
void mp_csp_set_image_params(struct mp_csp_params *params,
|
|
|
|
const struct mp_image_params *imgparams);
|
|
|
|
|
2023-11-04 04:15:27 +00:00
|
|
|
extern const struct m_opt_choice_alternatives pl_chroma_names[];
|
2023-11-04 03:54:51 +00:00
|
|
|
extern const struct m_opt_choice_alternatives pl_alpha_names[];
|
2020-04-24 12:41:50 +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
|
|
|
extern const struct m_sub_options mp_csp_equalizer_conf;
|
|
|
|
|
|
|
|
struct mpv_global;
|
|
|
|
struct mp_csp_equalizer_state *mp_csp_equalizer_create(void *ta_parent,
|
|
|
|
struct mpv_global *global);
|
|
|
|
bool mp_csp_equalizer_state_changed(struct mp_csp_equalizer_state *state);
|
|
|
|
void mp_csp_equalizer_state_get(struct mp_csp_equalizer_state *state,
|
|
|
|
struct mp_csp_params *params);
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
enum pl_color_system mp_csp_guess_colorspace(int width, int height);
|
|
|
|
enum pl_color_primaries mp_csp_guess_primaries(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
|
|
|
double mp_get_csp_mul(enum pl_color_system csp, int input_bits, int texture_bits);
|
|
|
|
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);
|
2023-11-04 05:27:38 +00:00
|
|
|
void mp_get_csp_matrix(struct mp_csp_params *params, struct pl_transform3x3 *out);
|
2009-12-31 18:25:35 +00:00
|
|
|
|
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
|
|
|
|
2009-12-31 18:25:35 +00:00
|
|
|
#endif /* MPLAYER_CSPUTILS_H */
|