mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 14:56:36 +00:00
video-color: add gst_video_color_matrix_get_Kr_Kb()
Move the function to get the color matrix coefficients from videoconvert to the video library.
This commit is contained in:
parent
8242676dc2
commit
0c40b83ed4
5 changed files with 77 additions and 35 deletions
|
@ -2299,6 +2299,7 @@ gst_video_colorimetry_matches
|
|||
gst_video_colorimetry_from_string
|
||||
gst_video_colorimetry_to_string
|
||||
gst_video_color_range_offsets
|
||||
gst_video_color_matrix_get_Kr_Kb
|
||||
<SUBSECTION Standard>
|
||||
gst_video_color_range_get_type
|
||||
GST_TYPE_VIDEO_COLOR_RANGE
|
||||
|
|
|
@ -243,3 +243,74 @@ static const PrimariesInfo primaries[] = {
|
|||
0.049}
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* gst_video_color_matrix_get_Kr_Kb:
|
||||
* @matrix: a #GstVideoColorMatrix
|
||||
* @Kr: result red channel coefficient
|
||||
* @Kb: result blue channel coefficient
|
||||
*
|
||||
* Get the coefficients used to convert between Y'PbPr and R'G'B' using @matrix.
|
||||
*
|
||||
* When:
|
||||
*
|
||||
* |[
|
||||
* 0.0 <= [Y',R',G',B'] <= 1.0)
|
||||
* (-0.5 <= [Pb,Pr] <= 0.5)
|
||||
* ]|
|
||||
*
|
||||
* the general conversion is given by:
|
||||
*
|
||||
* |[
|
||||
* Y' = Kr*R' + (1-Kr-Kb)*G' + Kb*B'
|
||||
* Pb = (B'-Y')/(2*(1-Kb))
|
||||
* Pr = (R'-Y')/(2*(1-Kr))
|
||||
* ]|
|
||||
*
|
||||
* and the other way around:
|
||||
*
|
||||
* |[
|
||||
* R' = Y' + Cr*2*(1-Kr)
|
||||
* G' = Y' - Cb*2*(1-Kb)*Kb/(1-Kr-Kb) - Cr*2*(1-Kr)*Kr/(1-Kr-Kb)
|
||||
* B' = Y' + Cb*2*(1-Kb)
|
||||
* ]|
|
||||
*
|
||||
* Returns: TRUE if @matrix was a YUV color format and @Kr and @Kb contain valid
|
||||
* values.
|
||||
*
|
||||
* Since: 1.6
|
||||
*/
|
||||
gboolean
|
||||
gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr,
|
||||
gdouble * Kb)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
|
||||
switch (matrix) {
|
||||
/* RGB */
|
||||
default:
|
||||
case GST_VIDEO_COLOR_MATRIX_RGB:
|
||||
res = FALSE;
|
||||
break;
|
||||
/* YUV */
|
||||
case GST_VIDEO_COLOR_MATRIX_FCC:
|
||||
*Kr = 0.30;
|
||||
*Kb = 0.11;
|
||||
break;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT709:
|
||||
*Kr = 0.2126;
|
||||
*Kb = 0.0722;
|
||||
break;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT601:
|
||||
*Kr = 0.2990;
|
||||
*Kb = 0.1140;
|
||||
break;
|
||||
case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
|
||||
*Kr = 0.212;
|
||||
*Kb = 0.087;
|
||||
break;
|
||||
}
|
||||
GST_DEBUG ("matrix: %d, Kr %f, Kb %f", matrix, *Kr, *Kb);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ typedef enum {
|
|||
GST_VIDEO_COLOR_MATRIX_SMPTE240M
|
||||
} GstVideoColorMatrix;
|
||||
|
||||
gboolean gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb);
|
||||
|
||||
/**
|
||||
* GstVideoTransferFunction:
|
||||
* @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
|
||||
|
|
|
@ -182,39 +182,6 @@ videoconvert_convert_matrix16 (VideoConvert * convert, gpointer pixels)
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
|
||||
switch (matrix) {
|
||||
/* RGB */
|
||||
default:
|
||||
case GST_VIDEO_COLOR_MATRIX_RGB:
|
||||
res = FALSE;
|
||||
break;
|
||||
/* YUV */
|
||||
case GST_VIDEO_COLOR_MATRIX_FCC:
|
||||
*Kr = 0.30;
|
||||
*Kb = 0.11;
|
||||
break;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT709:
|
||||
*Kr = 0.2126;
|
||||
*Kb = 0.0722;
|
||||
break;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT601:
|
||||
*Kr = 0.2990;
|
||||
*Kb = 0.1140;
|
||||
break;
|
||||
case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
|
||||
*Kr = 0.212;
|
||||
*Kb = 0.087;
|
||||
break;
|
||||
}
|
||||
GST_DEBUG ("matrix: %d, Kr %f, Kb %f", matrix, *Kr, *Kb);
|
||||
return res;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
videoconvert_convert_compute_matrix (VideoConvert * convert)
|
||||
{
|
||||
|
@ -283,7 +250,7 @@ videoconvert_convert_compute_matrix (VideoConvert * convert)
|
|||
1 / ((float) scale[1]), 1 / ((float) scale[2]));
|
||||
|
||||
/* 2. bring components to R'G'B' space */
|
||||
if (get_Kr_Kb (in_info->colorimetry.matrix, &Kr, &Kb))
|
||||
if (gst_video_color_matrix_get_Kr_Kb (in_info->colorimetry.matrix, &Kr, &Kb))
|
||||
color_matrix_YCbCr_to_RGB (&dst, Kr, Kb);
|
||||
|
||||
/* 3. inverse transfer function. R'G'B' to linear RGB */
|
||||
|
@ -295,7 +262,7 @@ videoconvert_convert_compute_matrix (VideoConvert * convert)
|
|||
/* 6. transfer function. linear RGB to R'G'B' */
|
||||
|
||||
/* 7. bring components to YCbCr space */
|
||||
if (get_Kr_Kb (out_info->colorimetry.matrix, &Kr, &Kb))
|
||||
if (gst_video_color_matrix_get_Kr_Kb (out_info->colorimetry.matrix, &Kr, &Kb))
|
||||
color_matrix_RGB_to_YCbCr (&dst, Kr, Kb);
|
||||
|
||||
/* 8, bring color components to nominal range */
|
||||
|
|
|
@ -71,6 +71,7 @@ EXPORTS
|
|||
gst_video_codec_state_get_type
|
||||
gst_video_codec_state_ref
|
||||
gst_video_codec_state_unref
|
||||
gst_video_color_matrix_get_Kr_Kb
|
||||
gst_video_color_matrix_get_type
|
||||
gst_video_color_primaries_get_type
|
||||
gst_video_color_range_get_type
|
||||
|
|
Loading…
Reference in a new issue