summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorNiklas Haas <git@nand.wakku.to>2015-02-28 20:15:12 +0100
committerNiklas Haas <git@nand.wakku.to>2015-02-28 20:23:47 +0100
commita76cc1dafcf948cce93f6d258e33444206a83c45 (patch)
tree89e3bb2afb4192ee1e8f54aa9943927535845269 /video
parent8d24e9d9b8ad1b5d82139980eca148dc0f4a1eab (diff)
downloadmpv-a76cc1dafcf948cce93f6d258e33444206a83c45.tar.bz2
mpv-a76cc1dafcf948cce93f6d258e33444206a83c45.tar.xz
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");
Diffstat (limited to 'video')
-rw-r--r--video/csputils.c33
-rw-r--r--video/csputils.h16
-rw-r--r--video/decode/vd_lavc.c1
-rw-r--r--video/image_writer.c8
-rw-r--r--video/image_writer.h1
-rw-r--r--video/mp_image.c11
-rw-r--r--video/mp_image.h1
-rw-r--r--video/out/gl_video.c21
8 files changed, 69 insertions, 23 deletions
diff --git a/video/csputils.c b/video/csputils.c
index 90eec39d36..cbd9734819 100644
--- a/video/csputils.c
+++ b/video/csputils.c
@@ -65,6 +65,13 @@ const char *const mp_csp_prim_names[MP_CSP_PRIM_COUNT] = {
"BT.470 M",
};
+const char *const mp_csp_trc_names[MP_CSP_TRC_COUNT] = {
+ "Autoselect",
+ "BT.1886 (SD, HD, UHD)",
+ "sRGB (IEC 61966-2-1)",
+ "Linear light",
+};
+
const char *const mp_csp_equalizer_names[MP_CSP_EQ_COUNT] = {
"brightness",
"contrast",
@@ -142,6 +149,21 @@ enum mp_csp_prim avcol_pri_to_mp_csp_prim(int avpri)
}
}
+enum mp_csp_trc avcol_trc_to_mp_csp_trc(int avtrc)
+{
+ switch (avtrc) {
+ case AVCOL_TRC_BT709:
+ case AVCOL_TRC_SMPTE170M:
+ case AVCOL_TRC_SMPTE240M:
+ case AVCOL_TRC_BT1361_ECG:
+ case AVCOL_TRC_BT2020_10:
+ 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;
+ default: return MP_CSP_TRC_AUTO;
+ }
+}
+
int mp_csp_to_avcol_spc(enum mp_csp colorspace)
{
switch (colorspace) {
@@ -181,6 +203,17 @@ int mp_csp_prim_to_avcol_pri(enum mp_csp_prim prim)
}
}
+int mp_csp_trc_to_avcol_trc(enum mp_csp_trc trc)
+{
+ switch (trc) {
+ // We just call it BT.1886 since we're decoding, but it's still BT.709
+ 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;
+ default: return AVCOL_TRC_UNSPECIFIED;
+ }
+}
+
enum mp_csp mp_csp_guess_colorspace(int width, int height)
{
return width >= 1280 || height > 576 ? MP_CSP_BT_709 : MP_CSP_BT_601;
diff --git a/video/csputils.h b/video/csputils.h
index b6d17c1815..a082682e43 100644
--- a/video/csputils.h
+++ b/video/csputils.h
@@ -68,15 +68,19 @@ enum mp_csp_prim {
MP_CSP_PRIM_COUNT
};
+// Any enum mp_csp_prim value is a valid index (except MP_CSP_PRIM_COUNT)
+extern const char *const mp_csp_prim_names[MP_CSP_PRIM_COUNT];
+
enum mp_csp_trc {
- MP_CSP_TRC_NONE,
+ MP_CSP_TRC_AUTO,
MP_CSP_TRC_BT_1886,
MP_CSP_TRC_SRGB,
- MP_CSP_TRC_LINEAR
+ MP_CSP_TRC_LINEAR,
+ MP_CSP_TRC_COUNT
};
-// Any enum mp_csp_prim value is a valid index (except MP_CSP_PRIM_COUNT)
-extern const char *const mp_csp_prim_names[MP_CSP_PRIM_COUNT];
+// Any enum mp_csp_trc value is a valid index (except MP_CSP_TRC_COUNT)
+extern const char *const mp_csp_trc_names[MP_CSP_TRC_COUNT];
// These constants are based on the ICC specification (Table 23) and match
// up with the API of LittleCMS, which treats them as integers.
@@ -199,12 +203,16 @@ enum mp_csp_levels avcol_range_to_mp_csp_levels(int avrange);
enum mp_csp_prim avcol_pri_to_mp_csp_prim(int avpri);
+enum mp_csp_trc avcol_trc_to_mp_csp_trc(int avtrc);
+
int mp_csp_to_avcol_spc(enum mp_csp colorspace);
int mp_csp_levels_to_avcol_range(enum mp_csp_levels range);
int mp_csp_prim_to_avcol_pri(enum mp_csp_prim prim);
+int mp_csp_trc_to_avcol_trc(enum mp_csp_trc trc);
+
enum mp_csp mp_csp_guess_colorspace(int width, int height);
enum mp_csp_prim mp_csp_guess_primaries(int width, int height);
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 9e0a778990..e32ff6b01e 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -477,6 +477,7 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
.colorspace = avcol_spc_to_mp_csp(ctx->avctx->colorspace),
.colorlevels = avcol_range_to_mp_csp_levels(ctx->avctx->color_range),
.primaries = avcol_pri_to_mp_csp_prim(ctx->avctx->color_primaries),
+ .gamma = avcol_trc_to_mp_csp_trc(ctx->avctx->color_trc),
.chroma_location =
avchroma_location_to_mp(ctx->avctx->chroma_sample_location),
.rotate = vd->header->video->rotate,
diff --git a/video/image_writer.c b/video/image_writer.c
index ff321cfd1f..700e1c4284 100644
--- a/video/image_writer.c
+++ b/video/image_writer.c
@@ -50,6 +50,7 @@ const struct image_writer_opts image_writer_opts_defaults = {
.jpeg_dpi = 72,
.jpeg_progressive = 0,
.jpeg_baseline = 1,
+ .tag_csp = 1,
};
#define OPT_BASE_STRUCT struct image_writer_opts
@@ -65,6 +66,7 @@ const struct m_sub_options image_writer_conf = {
OPT_INTRANGE("png-compression", png_compression, 0, 0, 9),
OPT_INTRANGE("png-filter", png_filter, 0, 0, 5),
OPT_STRING("format", format, 0),
+ OPT_FLAG("tag-colorspace", tag_csp, 0),
{0},
},
.size = sizeof(struct image_writer_opts),
@@ -131,6 +133,12 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
pic->format = avctx->pix_fmt;
pic->width = avctx->width;
pic->height = avctx->height;
+#if HAVE_AVFRAME_CSP
+ if (ctx->opts->tag_csp) {
+ pic->color_primaries = mp_csp_prim_to_avcol_pri(image->params.primaries);
+ pic->color_trc = mp_csp_trc_to_avcol_trc(image->params.gamma);
+ }
+#endif
int ret = avcodec_encode_video2(avctx, &pkt, pic, &got_output);
if (ret < 0)
goto error_exit;
diff --git a/video/image_writer.h b/video/image_writer.h
index 2fce63065e..272af73b05 100644
--- a/video/image_writer.h
+++ b/video/image_writer.h
@@ -28,6 +28,7 @@ struct image_writer_opts {
int jpeg_dpi;
int jpeg_progressive;
int jpeg_baseline;
+ int tag_csp;
};
extern const struct image_writer_opts image_writer_opts_defaults;
diff --git a/video/mp_image.c b/video/mp_image.c
index 44f5ab903c..fcf265f699 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -368,10 +368,11 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src)
dst->params.d_w = src->params.d_w;
dst->params.d_h = src->params.d_h;
}
+ dst->params.primaries = src->params.primaries;
+ dst->params.gamma = src->params.gamma;
if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) {
dst->params.colorspace = src->params.colorspace;
dst->params.colorlevels = src->params.colorlevels;
- dst->params.primaries = src->params.primaries;
dst->params.chroma_location = src->params.chroma_location;
dst->params.outputlevels = src->params.outputlevels;
}
@@ -516,6 +517,7 @@ bool mp_image_params_equal(const struct mp_image_params *p1,
p1->colorlevels == p2->colorlevels &&
p1->outputlevels == p2->outputlevels &&
p1->primaries == p2->primaries &&
+ p1->gamma == p2->gamma &&
p1->chroma_location == p2->chroma_location &&
p1->rotate == p2->rotate &&
p1->stereo_in == p2->stereo_in &&
@@ -578,6 +580,8 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
params->primaries = mp_csp_guess_primaries(params->w, params->h);
}
}
+ if (params->gamma == MP_CSP_TRC_AUTO)
+ params->gamma = MP_CSP_TRC_BT_1886;
} else if (fmt.flags & MP_IMGFLAG_RGB) {
params->colorspace = MP_CSP_RGB;
params->colorlevels = MP_CSP_LEVELS_PC;
@@ -589,6 +593,8 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
// Note: sRGB primaries = BT.709 primaries
if (params->primaries == MP_CSP_PRIM_AUTO)
params->primaries = MP_CSP_PRIM_BT_709;
+ if (params->gamma == MP_CSP_TRC_AUTO)
+ params->gamma = MP_CSP_TRC_SRGB;
} else if (fmt.flags & MP_IMGFLAG_XYZ) {
params->colorspace = MP_CSP_XYZ;
params->colorlevels = MP_CSP_LEVELS_PC;
@@ -603,11 +609,14 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
// tagged with.
if (params->primaries == MP_CSP_PRIM_AUTO)
params->primaries = MP_CSP_PRIM_BT_709;
+ if (params->gamma == MP_CSP_TRC_AUTO)
+ params->gamma = MP_CSP_TRC_LINEAR;
} else {
// We have no clue.
params->colorspace = MP_CSP_AUTO;
params->colorlevels = MP_CSP_LEVELS_AUTO;
params->primaries = MP_CSP_PRIM_AUTO;
+ params->gamma = MP_CSP_TRC_AUTO;
}
}
diff --git a/video/mp_image.h b/video/mp_image.h
index 5263249987..3017ef46eb 100644
--- a/video/mp_image.h
+++ b/video/mp_image.h
@@ -48,6 +48,7 @@ struct mp_image_params {
enum mp_csp colorspace;
enum mp_csp_levels colorlevels;
enum mp_csp_prim primaries;
+ enum mp_csp_trc gamma;
enum mp_chroma_location chroma_location;
// The image should be converted to these levels. Unlike colorlevels, it
// does not describe the current state of the image. (Somewhat similar to
diff --git a/video/out/gl_video.c b/video/out/gl_video.c
index 23b19b3125..f1ea03ed80 100644
--- a/video/out/gl_video.c
+++ b/video/out/gl_video.c
@@ -937,8 +937,7 @@ static void compile_shaders(struct gl_video *p)
bool use_input_gamma = p->input_gamma != 1.0;
bool use_conv_gamma = p->conv_gamma != 1.0;
bool use_const_luma = p->image_params.colorspace == MP_CSP_BT_2020_C;
-
- enum mp_csp_trc gamma_fun = MP_CSP_TRC_NONE;
+ enum mp_csp_trc gamma_fun = p->image_params.gamma;
// If either color correction option (3dlut or srgb) is enabled, or if
// sigmoidal upscaling is requested, or if the source is linear XYZ, we
@@ -946,20 +945,6 @@ static void compile_shaders(struct gl_video *p)
bool use_linear_light = p->opts.linear_scaling || p->opts.sigmoid_upscaling
|| use_cms || is_xyz;
- if (use_linear_light) {
- // We use the color level range to distinguish between PC
- // content like images, which are most likely sRGB, and TV content
- // like movies, which are most likely BT.1886. XYZ input is always
- // treated as linear.
- if (is_xyz) {
- gamma_fun = MP_CSP_TRC_LINEAR;
- } else if (p->image_params.colorlevels == MP_CSP_LEVELS_PC) {
- gamma_fun = MP_CSP_TRC_SRGB;
- } else {
- gamma_fun = MP_CSP_TRC_BT_1886;
- }
- }
-
// The inverse of the above transformation is normally handled by
// the CMS cases, but if CMS is disabled we need to go back manually
bool use_inv_bt1886 = false;
@@ -1049,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");