summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/libs/gst-plugins-base-libs-sections.txt1
-rw-r--r--gst-libs/gst/video/video-color.c71
-rw-r--r--gst-libs/gst/video/video-color.h2
-rw-r--r--gst/videoconvert/videoconvert.c37
-rw-r--r--win32/common/libgstvideo.def1
5 files changed, 77 insertions, 35 deletions
diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt
index 6dee9c09b..4ad9afd77 100644
--- a/docs/libs/gst-plugins-base-libs-sections.txt
+++ b/docs/libs/gst-plugins-base-libs-sections.txt
@@ -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
diff --git a/gst-libs/gst/video/video-color.c b/gst-libs/gst/video/video-color.c
index 7a576d5de..cc89b1190 100644
--- a/gst-libs/gst/video/video-color.c
+++ b/gst-libs/gst/video/video-color.c
@@ -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;
+}
diff --git a/gst-libs/gst/video/video-color.h b/gst-libs/gst/video/video-color.h
index d1b30fa66..fc0193e6d 100644
--- a/gst-libs/gst/video/video-color.h
+++ b/gst-libs/gst/video/video-color.h
@@ -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
diff --git a/gst/videoconvert/videoconvert.c b/gst/videoconvert/videoconvert.c
index 380822dae..a78218b56 100644
--- a/gst/videoconvert/videoconvert.c
+++ b/gst/videoconvert/videoconvert.c
@@ -183,39 +183,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)
{
GstVideoInfo *in_info, *out_info;
@@ -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 */
diff --git a/win32/common/libgstvideo.def b/win32/common/libgstvideo.def
index ed49c4e29..b0477b73a 100644
--- a/win32/common/libgstvideo.def
+++ b/win32/common/libgstvideo.def
@@ -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