diff options
author | Niklas Haas <git@haasn.dev> | 2022-12-12 22:01:57 +0100 |
---|---|---|
committer | Niklas Haas <github-daiK1o@haasn.dev> | 2023-02-13 21:53:41 +0100 |
commit | 6d9e72cd89652aaf73fa5a8256c439221e86b94a (patch) | |
tree | 12727e918c14cc9626e6e8a9870b25f5165814b4 /video/image_writer.c | |
parent | 01351a6412be8751d06c8ccc9baa3979c530325c (diff) | |
download | mpv-6d9e72cd89652aaf73fa5a8256c439221e86b94a.tar.bz2 mpv-6d9e72cd89652aaf73fa5a8256c439221e86b94a.tar.xz |
video/image_writer: force sRGB for unsupported formats
After commit c98e7353, we blindly pass the screenshot colorspace to the
image writer. But since we want to introduces the ability to save images
in HDR and other exotic formats, we should strip this for unsupported
formats.
See-Also: #10988
Diffstat (limited to 'video/image_writer.c')
-rw-r--r-- | video/image_writer.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/video/image_writer.c b/video/image_writer.c index 67eb2aa7a8..4a9b4bc785 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -356,6 +356,7 @@ int image_writer_format_from_ext(const char *ext) static struct mp_image *convert_image(struct mp_image *image, int destfmt, enum mp_csp_levels yuv_levels, + const struct image_writer_opts *opts, struct mpv_global *global, struct mp_log *log) { @@ -372,13 +373,17 @@ static struct mp_image *convert_image(struct mp_image *image, int destfmt, }; mp_image_params_guess_csp(&p); - // If RGB, just assume everything is correct. - if (p.color.space != MP_CSP_RGB) { - // Currently, assume what FFmpeg's jpg encoder or libwebp needs. - // Of course this works only for non-HDR (no HDR support in libswscale). - p.color.levels = yuv_levels; - p.color.space = MP_CSP_BT_601; - p.chroma_location = MP_CHROMA_CENTER; + if (!image_writer_flexible_csp(opts)) { + // Formats that don't support non-sRGB csps should be forced to sRGB + p.color.primaries = MP_CSP_PRIM_BT_709; + p.color.gamma = MP_CSP_TRC_SRGB; + p.color.light = MP_CSP_LIGHT_DISPLAY; + p.color.sig_peak = 0; + if (p.color.space != MP_CSP_RGB) { + p.color.levels = yuv_levels; + p.color.space = MP_CSP_BT_601; + p.chroma_location = MP_CHROMA_CENTER; + } mp_image_params_guess_csp(&p); } @@ -445,7 +450,7 @@ bool write_image(struct mp_image *image, const struct image_writer_opts *opts, levels = MP_CSP_LEVELS_PC; } - struct mp_image *dst = convert_image(image, destfmt, levels, global, log); + struct mp_image *dst = convert_image(image, destfmt, levels, opts, global, log); if (!dst) return false; |