From bfbe1342f7f9eebaf0fce7237f92e94987411528 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 30 Mar 2015 14:54:52 +0200 Subject: csputils: add some missing colorspaces With target-prim and target-trc it makes sense to include some common colorspaces that aren't strictly speaking used for video. --- DOCS/man/vf.rst | 4 ++++ DOCS/man/vo.rst | 14 ++++++++++++ video/csputils.c | 61 +++++++++++++++++++++++++++++++++++++++++++++------- video/csputils.h | 10 +++++++-- video/out/gl_video.c | 33 ++++++++++++++++++++++++++-- 5 files changed, 110 insertions(+), 12 deletions(-) diff --git a/DOCS/man/vf.rst b/DOCS/man/vf.rst index f0c5a88b43..2af1e8fda0 100644 --- a/DOCS/man/vf.rst +++ b/DOCS/man/vf.rst @@ -300,6 +300,10 @@ Available filters are: :bt.601-625: ITU-R BT.601 (SD) 625-line systems (PAL, SECAM) :bt.709: ITU-R BT.709 (HD) (same primaries as sRGB) :bt.2020: ITU-R BT.2020 (UHD) + :apple: Apple RGB + :adobe: Adobe RGB (1998) + :prophoto: ProPhoto RGB (ROMM) + :cie1931: CIE 1931 RGB ```` Set the stereo mode the video is assumed to be encoded in. Takes the diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst index 4b8c3d100c..e235aa9d70 100644 --- a/DOCS/man/vo.rst +++ b/DOCS/man/vo.rst @@ -616,6 +616,14 @@ Available video output drivers are: ITU-R BT.709 (HD), IEC 61966-2-4 (sRGB), SMPTE RP177 Annex B bt2020 ITU-R BT.2020 (UHD) + apple + Apple RGB + adobe + Adobe RGB (1998) + prophoto + ProPhoto RGB (ROMM) + cie1931 + CIE 1931 RGB (not to be confused with CIE XYZ) ``target-trc=`` Specifies the transfer characteristics (gamma) of the display. Video @@ -629,8 +637,14 @@ Available video output drivers are: IEC 61966-2-4 (sRGB) linear Linear light output + gamma18 + Pure power curve (gamma 1.8), also used for Apple RGB gamma22 Pure power curve (gamma 2.2) + gamma28 + Pure power curve (gamma 2.8), also used for BT.470-BG + prophoto + ProPhoto RGB (ROMM) ``icc-profile=`` Load an ICC profile and use it to transform linear RGB to screen output. diff --git a/video/csputils.c b/video/csputils.c index 3282e3b8ed..52deb6793f 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -66,15 +66,23 @@ const struct m_opt_choice_alternatives mp_csp_prim_names[] = { {"bt.709", MP_CSP_PRIM_BT_709}, {"bt.2020", MP_CSP_PRIM_BT_2020}, {"bt.470m", MP_CSP_PRIM_BT_470M}, + {"apple", MP_CSP_PRIM_APPLE}, + {"adobe", MP_CSP_PRIM_ADOBE}, + {"prophoto", MP_CSP_PRIM_PRO_PHOTO}, + {"cie1931", MP_CSP_PRIM_CIE_1931}, {0} }; -const char *const mp_csp_trc_names[MP_CSP_TRC_COUNT] = { - "auto", - "bt.1886", - "srgb", - "linear", - "gamma2.2", +const struct m_opt_choice_alternatives mp_csp_trc_names[] = { + {"auto", MP_CSP_TRC_AUTO}, + {"bt.1886", MP_CSP_TRC_BT_1886}, + {"srgb", MP_CSP_TRC_SRGB}, + {"linear", MP_CSP_TRC_LINEAR}, + {"gamma1.8", MP_CSP_TRC_GAMMA18}, + {"gamma2.2", MP_CSP_TRC_GAMMA22}, + {"gamma2.8", MP_CSP_TRC_GAMMA28}, + {"prophoto", MP_CSP_TRC_PRO_PHOTO}, + {0} }; const char *const mp_csp_equalizer_names[MP_CSP_EQ_COUNT] = { @@ -162,6 +170,7 @@ enum mp_csp_trc avcol_trc_to_mp_csp_trc(int avtrc) 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; + case AVCOL_TRC_GAMMA28: return MP_CSP_TRC_GAMMA28; default: return MP_CSP_TRC_AUTO; } } @@ -209,6 +218,7 @@ int mp_csp_trc_to_avcol_trc(enum mp_csp_trc trc) 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; + case MP_CSP_TRC_GAMMA28: return AVCOL_TRC_GAMMA28; default: return AVCOL_TRC_UNSPECIFIED; } } @@ -317,9 +327,16 @@ struct mp_csp_primaries mp_get_csp_primaries(enum mp_csp_prim spc) https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.709-5-200204-I!!PDF-E.pdf https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2020-0-201208-I!!PDF-E.pdf + + Other colorspaces from https://en.wikipedia.org/wiki/RGB_color_space#Specifications */ - static const struct mp_csp_col_xy d65 = {0.3127, 0.3290}; + // CIE standard illuminant series + static const struct mp_csp_col_xy + d50 = {0.34577, 0.35850}, + d65 = {0.31271, 0.32902}, + c = {0.31006, 0.31616}, + e = {1.0/3.0, 1.0/3.0}; switch (spc) { case MP_CSP_PRIM_BT_470M: @@ -327,7 +344,7 @@ struct mp_csp_primaries mp_get_csp_primaries(enum mp_csp_prim spc) .red = {0.670, 0.330}, .green = {0.210, 0.710}, .blue = {0.140, 0.080}, - .white = {0.310, 0.316} // Illuminant C + .white = c }; case MP_CSP_PRIM_BT_601_525: return (struct mp_csp_primaries) { @@ -360,6 +377,34 @@ struct mp_csp_primaries mp_get_csp_primaries(enum mp_csp_prim spc) .blue = {0.131, 0.046}, .white = d65 }; + case MP_CSP_PRIM_APPLE: + return (struct mp_csp_primaries) { + .red = {0.625, 0.340}, + .green = {0.280, 0.595}, + .blue = {0.115, 0.070}, + .white = d65 + }; + case MP_CSP_PRIM_ADOBE: + return (struct mp_csp_primaries) { + .red = {0.640, 0.330}, + .green = {0.210, 0.710}, + .blue = {0.150, 0.060}, + .white = d65 + }; + case MP_CSP_PRIM_PRO_PHOTO: + return (struct mp_csp_primaries) { + .red = {0.7347, 0.2653}, + .green = {0.1596, 0.8404}, + .blue = {0.0366, 0.0001}, + .white = d50 + }; + case MP_CSP_PRIM_CIE_1931: + return (struct mp_csp_primaries) { + .red = {0.7347, 0.2653}, + .green = {0.2738, 0.7174}, + .blue = {0.1666, 0.0089}, + .white = e + }; default: return (struct mp_csp_primaries) {{0}}; } diff --git a/video/csputils.h b/video/csputils.h index 449d883ecb..a0e4ef614f 100644 --- a/video/csputils.h +++ b/video/csputils.h @@ -65,6 +65,10 @@ enum mp_csp_prim { MP_CSP_PRIM_BT_709, MP_CSP_PRIM_BT_2020, MP_CSP_PRIM_BT_470M, + MP_CSP_PRIM_APPLE, + MP_CSP_PRIM_ADOBE, + MP_CSP_PRIM_PRO_PHOTO, + MP_CSP_PRIM_CIE_1931, MP_CSP_PRIM_COUNT }; @@ -75,12 +79,14 @@ enum mp_csp_trc { MP_CSP_TRC_BT_1886, MP_CSP_TRC_SRGB, MP_CSP_TRC_LINEAR, + MP_CSP_TRC_GAMMA18, MP_CSP_TRC_GAMMA22, + MP_CSP_TRC_GAMMA28, + MP_CSP_TRC_PRO_PHOTO, MP_CSP_TRC_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]; +extern const struct m_opt_choice_alternatives mp_csp_trc_names[]; // These constants are based on the ICC specification (Table 23) and match // up with the API of LittleCMS, which treats them as integers. diff --git a/video/out/gl_video.c b/video/out/gl_video.c index 36ba21da5d..34defb1db1 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -372,13 +372,20 @@ const struct m_sub_options gl_video_conf = { {"bt601-625", MP_CSP_PRIM_BT_601_625}, {"bt709", MP_CSP_PRIM_BT_709}, {"bt2020", MP_CSP_PRIM_BT_2020}, - {"bt470m", MP_CSP_PRIM_BT_470M})), + {"bt470m", MP_CSP_PRIM_BT_470M}, + {"apple", MP_CSP_PRIM_APPLE}, + {"adobe", MP_CSP_PRIM_ADOBE}, + {"prophoto", MP_CSP_PRIM_PRO_PHOTO}, + {"cie1931", MP_CSP_PRIM_CIE_1931})), OPT_CHOICE("target-trc", target_trc, 0, ({"auto", MP_CSP_TRC_AUTO}, {"bt1886", MP_CSP_TRC_BT_1886}, {"srgb", MP_CSP_TRC_SRGB}, {"linear", MP_CSP_TRC_LINEAR}, - {"gamma22", MP_CSP_TRC_GAMMA22})), + {"gamma18", MP_CSP_TRC_GAMMA18}, + {"gamma22", MP_CSP_TRC_GAMMA22}, + {"gamma28", MP_CSP_TRC_GAMMA28}, + {"prophoto", MP_CSP_TRC_PRO_PHOTO})), OPT_FLAG("npot", npot, 0), OPT_FLAG("pbo", pbo, 0), OPT_STRING_VALIDATE("scale", scaler[0].kernel.name, 0, validate_scaler_opt), @@ -1492,9 +1499,20 @@ static void pass_linearize(struct gl_video *p, enum mp_csp_trc trc) case MP_CSP_TRC_BT_1886: GLSL(color.rgb = pow(color.rgb, vec3(1.961));) break; + case MP_CSP_TRC_GAMMA18: + GLSL(color.rgb = pow(color.rgb, vec3(1.8));) + break; case MP_CSP_TRC_GAMMA22: GLSL(color.rgb = pow(color.rgb, vec3(2.2));) break; + case MP_CSP_TRC_GAMMA28: + GLSL(color.rgb = pow(color.rgb, vec3(2.8));) + break; + case MP_CSP_TRC_PRO_PHOTO: + GLSL(color.rgb = mix(color.rgb / vec3(16.0), + pow(color.rgb, vec3(1.8)), + lessThan(vec3(0.03125), color.rgb));) + break; } } @@ -1515,9 +1533,20 @@ static void pass_delinearize(struct gl_video *p, enum mp_csp_trc trc) case MP_CSP_TRC_BT_1886: GLSL(color.rgb = pow(color.rgb, vec3(1.0/1.961));) break; + case MP_CSP_TRC_GAMMA18: + GLSL(color.rgb = pow(color.rgb, vec3(1.0/1.8));) + break; case MP_CSP_TRC_GAMMA22: GLSL(color.rgb = pow(color.rgb, vec3(1.0/2.2));) break; + case MP_CSP_TRC_GAMMA28: + GLSL(color.rgb = pow(color.rgb, vec3(1.0/2.8));) + break; + case MP_CSP_TRC_PRO_PHOTO: + GLSL(color.rgb = mix(color.rgb * vec3(16.0), + pow(color.rgb, vec3(1.0/1.8)), + lessThanEqual(vec3(0.001953), color.rgb));) + break; } } -- cgit v1.2.3