1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

vo_opengl: refactor shader generation (part 2)

This adds stuff related to gamma, linear light, sigmoid, BT.2020-CL,
etc, as well as color management. Also adds a new gamma function (gamma22).

This adds new parameters to configure the CMS settings, in particular
letting us target simple colorspaces without requiring usage of a 3DLUT.

This adds smoothmotion. Mostly working, but it's still sensitive to
timing issues. It's based on an actual queue now, but the queue size
is kept small to avoid larger amounts of latency.

Also makes “upscale before blending” the default strategy.
This is justified because the "render after blending" thing doesn't seme
to work consistently any way (introduces stutter due to the way vsync
timing works, or something), so this behavior is a bit closer to master
and makes pausing/unpausing less weird/jumpy.

This adds the remaining scalers, including bicubic_fast, sharpen3,
sharpen5, polar filters and antiringing. Apparently, sharpen3/5 also
consult scale-param1, which was undocumented in master.

This also implements cropping and chroma transformation, plus
rotation/flipping. These are inherently part of the same logic, although
it's a bit rough around the edges in some case, mainly due to the fallback
code paths (for bilinear scaling without indirection).
This commit is contained in:
Niklas Haas 2015-03-12 22:18:16 +01:00 committed by wm4
parent e74a4d5bc0
commit 3974a5ca5e
8 changed files with 749 additions and 222 deletions

View File

@ -352,6 +352,10 @@ Available video output drivers are:
blurrier. Defaults to 1. Note that setting this too low (eg. 0.5)
leads to bad results. It's recommended to stay between 0.9 and 1.1.
``sharpen3``, ``sharpen5``
Sharpening strength. Increasing this makes the image sharper but
adds more ringing and aliasing. Defaults to 0.5.
``scale-radius=<r>``
Set radius for filters listed below, must be a float number between 1.0
and 16.0. Defaults to be 3.0 if not specified.
@ -377,21 +381,6 @@ Available video output drivers are:
will reproduce the source image perfectly if no scaling is performed.
Note that this option never affects ``cscale``.
``srgb``
Convert and color correct the output to sRGB before displaying it on
the screen. This option enables ``linear-scaling``.
This option is equivalent to using ``icc-profile`` with an sRGB ICC
profile, but it is implemented without a 3DLUT and does not require
LittleCMS 2. If both ``srgb`` and ``icc-profile`` are present, the
latter takes precedence, as they are somewhat redundant.
Note: When playing back BT.2020 content with this option enabled, out
of gamut colors will be numerically clipped, which can potentially
change the hue and/or luminance. If this is not desired, it is
recommended to use ``icc-profile`` with an sRGB ICC profile instead,
when playing back wide-gamut BT.2020 content.
``pbo``
Enable use of PBOs. This is slightly faster, but can sometimes lead to
sporadic and temporary image corruption (in theory, because reupload
@ -460,9 +449,10 @@ Available video output drivers are:
``scale-antiring``.
``linear-scaling``
Scale in linear light. This is automatically enabled if ``srgb``,
``icc-profile`` or ``sigmoid-upscaling`` is set. It should only
be used with a ``fbo-format`` that has at least 16 bit precision.
Scale in linear light. This is automatically enabled if
``target-prim``, ``target-trc``, ``icc-profile`` or
``sigmoid-upscaling`` is set. It should only be used with a
``fbo-format`` that has at least 16 bit precision.
``fancy-downscaling``
When using convolution based filters, extend the filter size
@ -553,13 +543,44 @@ Available video output drivers are:
NOTE: Only implemented on OS X.
``target-prim=<value>``
Specifies the primaries of the display. Video colors will be adapted
to this colorspace if necessary. Valid values are:
auto
Disable any adaptation (default)
bt470m
ITU-R BT.470 M
bt601-525
ITU-R BT.601 (525-line SD systems, eg. NTSC), SMPTE 170M/240M
bt601-625
ITU-R BT.601 (625-line SD systems, eg. PAL/SECAM), ITU-R BT.470 B/G
bt709
ITU-R BT.709 (HD), IEC 61966-2-4 (sRGB), SMPTE RP177 Annex B
bt2020
ITU-R BT.2020 (UHD)
``target-trc=<value>``
Specifies the transfer characteristics (gamma) of the display. Video
colors will be adjusted to this curve. Valid values are:
auto
Disable any adaptation (default)
bt1886
ITU-R BT.1886 curve, without the brightness drop (approx. 1.961)
srgb
IEC 61966-2-4 (sRGB)
linear
Linear light output
gamma22
Pure power curve (gamma 2.2)
``icc-profile=<file>``
Load an ICC profile and use it to transform linear RGB to screen output.
Needs LittleCMS 2 support compiled in. This option overrides the ``srgb``
property, as using both is somewhat redundant. It also enables
Needs LittleCMS 2 support compiled in. This option overrides the
``target-prim`` and ``target-trc`` options. It also enables
``linear-scaling``.
``icc-profile-auto``
Automatically select the ICC display profile currently specified by
the display settings of the operating system.
@ -573,9 +594,8 @@ Available video output drivers are:
Its size depends on the ``3dlut-size``, and can be very big.
``icc-intent=<value>``
Specifies the ICC Intent used for transformations between color spaces.
This affects the rendering when using ``icc-profile`` or ``srgb`` and
also affects the way DCP XYZ content gets converted to RGB.
Specifies the ICC intent used for the color transformation (when using
``icc-profile``).
0
perceptual

View File

@ -70,6 +70,7 @@ const char *const mp_csp_trc_names[MP_CSP_TRC_COUNT] = {
"BT.1886 (SD, HD, UHD)",
"sRGB (IEC 61966-2-1)",
"Linear light",
"Pure power (gamma 2.2)",
};
const char *const mp_csp_equalizer_names[MP_CSP_EQ_COUNT] = {
@ -156,6 +157,7 @@ enum mp_csp_trc avcol_trc_to_mp_csp_trc(int avtrc)
case AVCOL_TRC_BT2020_12: return MP_CSP_TRC_BT_1886;
case AVCOL_TRC_IEC61966_2_1: return MP_CSP_TRC_SRGB;
case AVCOL_TRC_LINEAR: return MP_CSP_TRC_LINEAR;
case AVCOL_TRC_GAMMA22: return MP_CSP_TRC_GAMMA22;
default: return MP_CSP_TRC_AUTO;
}
}
@ -202,6 +204,7 @@ int mp_csp_trc_to_avcol_trc(enum mp_csp_trc trc)
case MP_CSP_TRC_BT_1886: return AVCOL_TRC_BT709;
case MP_CSP_TRC_SRGB: return AVCOL_TRC_IEC61966_2_1;
case MP_CSP_TRC_LINEAR: return AVCOL_TRC_LINEAR;
case MP_CSP_TRC_GAMMA22: return AVCOL_TRC_GAMMA22;
default: return AVCOL_TRC_UNSPECIFIED;
}
}

View File

@ -76,6 +76,7 @@ enum mp_csp_trc {
MP_CSP_TRC_BT_1886,
MP_CSP_TRC_SRGB,
MP_CSP_TRC_LINEAR,
MP_CSP_TRC_GAMMA22,
MP_CSP_TRC_COUNT
};

View File

@ -294,7 +294,7 @@ static void gen_osd_cb(void *pctx, struct sub_bitmaps *imgs)
osd->num_subparts * sizeof(osd->subparts[0]));
}
static void write_quad(struct vertex *va, float matrix[3][3],
static void write_quad(struct vertex *va, float matrix[3][2],
float x0, float y0, float x1, float y1,
float tx0, float ty0, float tx1, float ty1,
float tex_w, float tex_h, const uint8_t color[4])
@ -312,7 +312,7 @@ static void write_quad(struct vertex *va, float matrix[3][3],
#undef COLOR_INIT
}
static int generate_verts(struct mpgl_osd_part *part, float matrix[3][3])
static int generate_verts(struct mpgl_osd_part *part, float matrix[3][2])
{
int num_vertices = part->num_subparts * 6;
MP_TARRAY_GROW(part, part->vertices, num_vertices);
@ -337,7 +337,7 @@ static int generate_verts(struct mpgl_osd_part *part, float matrix[3][3])
return num_vertices;
}
static void draw_part(struct mpgl_osd *ctx, int index, float matrix[3][3])
static void draw_part(struct mpgl_osd *ctx, int index, float matrix[3][2])
{
GL *gl = ctx->gl;
struct mpgl_osd_part *part = ctx->parts[index];
@ -377,7 +377,7 @@ void mpgl_osd_draw_part(struct mpgl_osd *ctx, int vp_w, int vp_h, int index)
for (int x = 0; x < div[0]; x++) {
for (int y = 0; y < div[1]; y++) {
float matrix[3][3];
float matrix[3][2];
gl_matrix_ortho2d(matrix, 0, vp_w, 0, vp_h);

View File

@ -418,7 +418,7 @@ void fbotex_uninit(struct fbotex *fbo)
// Standard parallel 2D projection, except y1 < y0 means that the coordinate
// system is flipped, not the projection.
void gl_matrix_ortho2d(float m[3][3], float x0, float x1, float y0, float y1)
void gl_matrix_ortho2d(float m[3][2], float x0, float x1, float y0, float y1)
{
if (y1 < y0) {
float t = y0;
@ -426,12 +426,12 @@ void gl_matrix_ortho2d(float m[3][3], float x0, float x1, float y0, float y1)
y1 = t;
}
memset(m, 0, 9 * sizeof(float));
m[0][0] = 2.0f / (x1 - x0);
m[0][1] = 0.0f;
m[1][0] = 0.0f;
m[1][1] = 2.0f / (y1 - y0);
m[2][0] = -(x1 + x0) / (x1 - x0);
m[2][1] = -(y1 + y0) / (y1 - y0);
m[2][2] = 1.0f;
}
static void GLAPIENTRY gl_debug_cb(GLenum source, GLenum type, GLuint id,

View File

@ -86,15 +86,27 @@ bool fbotex_change(struct fbotex *fbo, GL *gl, struct mp_log *log, int w, int h,
#define FBOTEX_FUZZY_H 2
void fbotex_set_filter(struct fbotex *fbo, GLenum gl_filter);
void gl_matrix_ortho2d(float m[3][3], float x0, float x1, float y0, float y1);
void gl_matrix_ortho2d(float m[3][2], float x0, float x1, float y0, float y1);
static inline void gl_matrix_mul_vec(float m[3][3], float *x, float *y)
// This treats m as an affine transformation, in other words m[2][n] gets
// added to the output.
static inline void gl_matrix_mul_vec(float m[3][2], float *x, float *y)
{
float vx = *x, vy = *y;
*x = vx * m[0][0] + vy * m[1][0] + m[2][0];
*y = vx * m[0][1] + vy * m[1][1] + m[2][1];
}
struct mp_rect_f {
float x0, y0, x1, y1;
};
static inline void gl_matrix_mul_rect(float m[3][2], struct mp_rect_f *r)
{
gl_matrix_mul_vec(m, &r->x0, &r->y0);
gl_matrix_mul_vec(m, &r->x1, &r->y1);
}
void gl_set_debug_logger(GL *gl, struct mp_log *log);
struct gl_shader_cache;

File diff suppressed because it is too large Load Diff

View File

@ -31,12 +31,13 @@ struct lut3d {
struct gl_video_opts {
char *scalers[2];
char *dscaler;
float gamma;
int gamma_auto;
int target_prim;
int target_trc;
float scaler_params[2][2];
float scaler_radius[2];
float scaler_antiring[2];
float gamma;
int gamma_auto;
int srgb;
int linear_scaling;
int fancy_downscaling;
int sigmoid_upscaling;