video: Add support for BT2020 colorspace (UHD)

This commit is contained in:
Sebastian Dröge 2015-01-08 10:45:46 +01:00
parent ff8129267e
commit 7a35321710
3 changed files with 41 additions and 6 deletions

View file

@ -46,6 +46,7 @@ typedef struct
#define DEFAULT_RGB 3
#define DEFAULT_GRAY 4
#define DEFAULT_UNKNOWN 5
#define DEFAULT_YUV_UHD 6
static const ColorimetryInfo colorimetry[] = {
MAKE_COLORIMETRY (BT601, _16_235, BT601, BT709, SMPTE170M),
@ -54,6 +55,7 @@ static const ColorimetryInfo colorimetry[] = {
MAKE_COLORIMETRY (SRGB, _0_255, RGB, SRGB, BT709),
MAKE_COLORIMETRY (NONAME, _0_255, BT601, UNKNOWN, UNKNOWN),
MAKE_COLORIMETRY (NONAME, _UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN),
MAKE_COLORIMETRY (BT2020, _16_235, BT2020, BT2020_12, BT2020),
};
static const ColorimetryInfo *
@ -234,7 +236,9 @@ static const GstVideoColorPrimariesInfo color_primaries[] = {
{GST_VIDEO_COLOR_PRIMARIES_SMPTE240M, WP_D65, 0.63, 0.34, 0.31, 0.595, 0.155,
0.07},
{GST_VIDEO_COLOR_PRIMARIES_FILM, WP_C, 0.681, 0.319, 0.243, 0.692, 0.145,
0.049}
0.049},
{GST_VIDEO_COLOR_PRIMARIES_BT2020, WP_D65, 0.708, 0.292, 0.170, 0.797, 0.131,
0.046}
};
/**
@ -250,7 +254,8 @@ static const GstVideoColorPrimariesInfo color_primaries[] = {
const GstVideoColorPrimariesInfo *
gst_video_color_primaries_get_info (GstVideoColorPrimaries primaries)
{
g_return_val_if_fail (primaries < G_N_ELEMENTS (color_primaries), NULL);
g_return_val_if_fail (primaries <
(GstVideoColorPrimaries) G_N_ELEMENTS (color_primaries), NULL);
return &color_primaries[primaries];
}
@ -320,6 +325,10 @@ gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr,
*Kr = 0.212;
*Kb = 0.087;
break;
case GST_VIDEO_COLOR_MATRIX_BT2020:
*Kr = 0.2627;
*Kb = 0.0593;
break;
}
GST_DEBUG ("matrix: %d, Kr %f, Kb %f", matrix, *Kr, *Kb);
@ -400,6 +409,12 @@ gst_video_color_transfer_encode (GstVideoTransferFunction func, gdouble val)
else
res = 1.0 + log10 (val) / 2.5;
break;
case GST_VIDEO_TRANSFER_BT2020_12:
if (val < 0.0181)
res = 4.5 * val;
else
res = 1.0993 * pow (val, 0.45) - 0.0993;
break;
}
return res;
}
@ -479,6 +494,12 @@ gst_video_color_transfer_decode (GstVideoTransferFunction func, gdouble val)
else
res = pow (10.0, 2.5 * (val - 1.0));
break;
case GST_VIDEO_TRANSFER_BT2020_12:
if (val < 0.08145)
res = val / 4.5;
else
res = pow ((val + 0.0993) / 1.0993, 1.0 / 0.45);
break;
}
return res;
}

View file

@ -50,6 +50,7 @@ typedef enum {
* @GST_VIDEO_COLOR_MATRIX_BT709: ITU-R BT.709 color matrix
* @GST_VIDEO_COLOR_MATRIX_BT601: ITU-R BT.601 color matrix
* @GST_VIDEO_COLOR_MATRIX_SMPTE240M: SMPTE 240M color matrix
* @GST_VIDEO_COLOR_MATRIX_BT2020: ITU-R BT.2020 color matrix. Since: 1.6.
*
* The color matrix is used to convert between Y'PbPr and
* non-linear RGB (R'G'B')
@ -60,7 +61,8 @@ typedef enum {
GST_VIDEO_COLOR_MATRIX_FCC,
GST_VIDEO_COLOR_MATRIX_BT709,
GST_VIDEO_COLOR_MATRIX_BT601,
GST_VIDEO_COLOR_MATRIX_SMPTE240M
GST_VIDEO_COLOR_MATRIX_SMPTE240M,
GST_VIDEO_COLOR_MATRIX_BT2020
} GstVideoColorMatrix;
gboolean gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb);
@ -83,6 +85,9 @@ gboolean gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble *
* 100:1 range
* @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
* 316.22777:1 range
* @GST_VIDEO_TRANSFER_BT2020_12: Gamma 2.2 curve with a linear segment in the lower
* range. Used for BT.2020 with 12 bits per
* component. Since: 1.6.
*
* The video transfer function defines the formula for converting between
* non-linear RGB (R'G'B') and linear RGB
@ -98,7 +103,8 @@ typedef enum {
GST_VIDEO_TRANSFER_SRGB,
GST_VIDEO_TRANSFER_GAMMA28,
GST_VIDEO_TRANSFER_LOG100,
GST_VIDEO_TRANSFER_LOG316
GST_VIDEO_TRANSFER_LOG316,
GST_VIDEO_TRANSFER_BT2020_12
} GstVideoTransferFunction;
gdouble gst_video_color_transfer_encode (GstVideoTransferFunction func, gdouble val);
@ -113,6 +119,7 @@ gdouble gst_video_color_transfer_decode (GstVideoTransferFunction func, gdo
* @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries
* @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
* @GST_VIDEO_COLOR_PRIMARIES_FILM: Generic film
* @GST_VIDEO_COLOR_PRIMARIES_BT2020: BT2020 primaries. Since: 1.6.
*
* The color primaries define the how to transform linear RGB values to and from
* the CIE XYZ colorspace.
@ -124,7 +131,8 @@ typedef enum {
GST_VIDEO_COLOR_PRIMARIES_BT470BG,
GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
GST_VIDEO_COLOR_PRIMARIES_SMPTE240M,
GST_VIDEO_COLOR_PRIMARIES_FILM
GST_VIDEO_COLOR_PRIMARIES_FILM,
GST_VIDEO_COLOR_PRIMARIES_BT2020
} GstVideoColorPrimaries;
/**
@ -179,6 +187,7 @@ typedef struct {
#define GST_VIDEO_COLORIMETRY_BT709 "bt709"
#define GST_VIDEO_COLORIMETRY_SMPTE240M "smpte240m"
#define GST_VIDEO_COLORIMETRY_SRGB "sRGB"
#define GST_VIDEO_COLORIMETRY_BT2020 "bt2020"
gboolean gst_video_colorimetry_matches (GstVideoColorimetry *cinfo, const gchar *color);
gboolean gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);

View file

@ -63,6 +63,7 @@ gst_video_info_init (GstVideoInfo * info)
#define DEFAULT_RGB 2
#define DEFAULT_GRAY 3
#define DEFAULT_UNKNOWN 4
#define DEFAULT_YUV_UHD 5
static const GstVideoColorimetry default_color[] = {
MAKE_COLORIMETRY (_16_235, BT601, BT709, SMPTE170M),
@ -70,6 +71,7 @@ static const GstVideoColorimetry default_color[] = {
MAKE_COLORIMETRY (_0_255, RGB, SRGB, BT709),
MAKE_COLORIMETRY (_0_255, BT601, UNKNOWN, UNKNOWN),
MAKE_COLORIMETRY (_UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN),
MAKE_COLORIMETRY (_16_235, BT2020, BT2020_12, BT2020),
};
static void
@ -78,7 +80,10 @@ set_default_colorimetry (GstVideoInfo * info)
const GstVideoFormatInfo *finfo = info->finfo;
if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
if (info->height > 576) {
if (info->height >= 2160) {
info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
info->colorimetry = default_color[DEFAULT_YUV_UHD];
} else if (info->height > 576) {
info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
info->colorimetry = default_color[DEFAULT_YUV_HD];
} else {