mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 10:10:32 +00:00
video-color: Add util functions for conversion from/to ISO/IEC 23001-8
... and also as known as ITU-T H.273. The conversion has been handled per plugin for now. That causes code duplication a lot also some plugins might not be updated with newly introduced color{matrix,transfer,primaries} enum value(s). Instead of handling it per plugin, centralized handling can remove such code duplication and make plugins be up-to-dated.
This commit is contained in:
parent
1381e3e2be
commit
6a4e2f4fc9
2 changed files with 291 additions and 0 deletions
|
@ -628,3 +628,272 @@ gst_video_color_transfer_decode (GstVideoTransferFunction func, gdouble val)
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* conversion between GStreamer color{matrix,transfer,primaries} enum
|
||||
* and indices defined by ITU-T H.273 and ISO/IEC 230001-8 specification */
|
||||
|
||||
/* FIXME 2.0: Define color{matrix,transfer,primaries} with explicit numbering
|
||||
* to be matched with specification
|
||||
*/
|
||||
|
||||
/**
|
||||
* gst_video_color_matrix_to_iso:
|
||||
* @matrix: a #GstVideoColorMatrix
|
||||
*
|
||||
* Converts #GstVideoColorMatrix to the "matrix coefficients"
|
||||
* (MatrixCoefficients) value defined by "ISO/IEC 23001-8 Section 7.3 Table 4"
|
||||
* and "ITU-T H.273 Table 4".
|
||||
* "H.264 Table E-5" and "H.265 Table E.5" share the identical values.
|
||||
*
|
||||
* Returns: The value of ISO/IEC 23001-8 matrix coefficients.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
guint
|
||||
gst_video_color_matrix_to_iso (GstVideoColorMatrix matrix)
|
||||
{
|
||||
switch (matrix) {
|
||||
case GST_VIDEO_COLOR_MATRIX_RGB:
|
||||
return 0;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT709:
|
||||
return 1;
|
||||
case GST_VIDEO_COLOR_MATRIX_FCC:
|
||||
return 4;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT601:
|
||||
return 6;
|
||||
case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
|
||||
return 7;
|
||||
case GST_VIDEO_COLOR_MATRIX_BT2020:
|
||||
return 9;
|
||||
case GST_VIDEO_COLOR_MATRIX_UNKNOWN:
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_color_transfer_to_iso:
|
||||
* @func: a #GstVideoTransferFunction
|
||||
*
|
||||
* Converts #GstVideoTransferFunction to the "transfer characteristics"
|
||||
* (TransferCharacteristics) value defined by "ISO/IEC 23001-8 Section 7.2 Table 3"
|
||||
* and "ITU-T H.273 Table 3".
|
||||
* "H.264 Table E-4" and "H.265 Table E.4" share the identical values.
|
||||
*
|
||||
* Returns: The value of ISO/IEC 23001-8 transfer characteristics.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
guint
|
||||
gst_video_color_transfer_to_iso (GstVideoTransferFunction func)
|
||||
{
|
||||
switch (func) {
|
||||
case GST_VIDEO_TRANSFER_BT709:
|
||||
return 1;
|
||||
case GST_VIDEO_TRANSFER_GAMMA22:
|
||||
return 4;
|
||||
case GST_VIDEO_TRANSFER_GAMMA28:
|
||||
return 5;
|
||||
case GST_VIDEO_TRANSFER_SMPTE240M:
|
||||
return 7;
|
||||
case GST_VIDEO_TRANSFER_GAMMA10:
|
||||
return 8;
|
||||
case GST_VIDEO_TRANSFER_LOG100:
|
||||
return 9;
|
||||
case GST_VIDEO_TRANSFER_LOG316:
|
||||
return 10;
|
||||
case GST_VIDEO_TRANSFER_SRGB:
|
||||
return 13;
|
||||
case GST_VIDEO_TRANSFER_BT2020_10:
|
||||
return 14;
|
||||
case GST_VIDEO_TRANSFER_BT2020_12:
|
||||
return 15;
|
||||
case GST_VIDEO_TRANSFER_SMPTE2084:
|
||||
return 16;
|
||||
case GST_VIDEO_TRANSFER_ARIB_STD_B67:
|
||||
return 18;
|
||||
case GST_VIDEO_TRANSFER_GAMMA18:
|
||||
case GST_VIDEO_TRANSFER_GAMMA20:
|
||||
case GST_VIDEO_TRANSFER_ADOBERGB:
|
||||
case GST_VIDEO_TRANSFER_UNKNOWN:
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_color_primaries_to_iso:
|
||||
* @primaries: a #GstVideoColorPrimaries
|
||||
*
|
||||
* Converts #GstVideoColorPrimaries to the "colour primaries" (ColourPrimaries)
|
||||
* value defined by "ISO/IEC 23001-8 Section 7.1 Table 2"
|
||||
* and "ITU-T H.273 Table 2".
|
||||
* "H.264 Table E-3" and "H.265 Table E.3" share the identical values.
|
||||
*
|
||||
* Returns: The value of ISO/IEC 23001-8 colour primaries.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
guint
|
||||
gst_video_color_primaries_to_iso (GstVideoColorPrimaries primaries)
|
||||
{
|
||||
switch (primaries) {
|
||||
case GST_VIDEO_COLOR_PRIMARIES_BT709:
|
||||
return 1;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_BT470M:
|
||||
return 4;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
|
||||
return 5;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
|
||||
return 6;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
|
||||
return 7;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_FILM:
|
||||
return 8;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_BT2020:
|
||||
return 9;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_SMPTEST428:
|
||||
return 10;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_SMPTERP431:
|
||||
return 11;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_SMPTEEG432:
|
||||
return 12;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_EBU3213:
|
||||
return 22;
|
||||
case GST_VIDEO_COLOR_PRIMARIES_ADOBERGB:
|
||||
case GST_VIDEO_COLOR_PRIMARIES_UNKNOWN:
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_color_matrix_from_iso:
|
||||
* @value: a ITU-T H.273 matrix coefficients value
|
||||
*
|
||||
* Converts the @value to the #GstVideoColorMatrix
|
||||
* The matrix coefficients (MatrixCoefficients) value is
|
||||
* defined by "ISO/IEC 23001-8 Section 7.3 Table 4"
|
||||
* and "ITU-T H.273 Table 4".
|
||||
* "H.264 Table E-5" and "H.265 Table E.5" share the identical values.
|
||||
*
|
||||
* Returns: the matched #GstVideoColorMatrix
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
GstVideoColorMatrix
|
||||
gst_video_color_matrix_from_iso (guint value)
|
||||
{
|
||||
switch (value) {
|
||||
case 0:
|
||||
return GST_VIDEO_COLOR_MATRIX_RGB;
|
||||
case 1:
|
||||
return GST_VIDEO_COLOR_MATRIX_BT709;
|
||||
case 4:
|
||||
return GST_VIDEO_COLOR_MATRIX_FCC;
|
||||
case 5:
|
||||
case 6:
|
||||
return GST_VIDEO_COLOR_MATRIX_BT601;
|
||||
case 7:
|
||||
return GST_VIDEO_COLOR_MATRIX_SMPTE240M;
|
||||
case 9:
|
||||
return GST_VIDEO_COLOR_MATRIX_BT2020;
|
||||
case 2:
|
||||
default:
|
||||
return GST_VIDEO_COLOR_MATRIX_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_color_transfer_from_iso:
|
||||
* @value: a ITU-T H.273 transfer characteristics value
|
||||
*
|
||||
* Converts the @value to the #GstVideoTransferFunction
|
||||
* The transfer characteristics (TransferCharacteristics) value is
|
||||
* defined by "ISO/IEC 23001-8 Section 7.2 Table 3"
|
||||
* and "ITU-T H.273 Table 3".
|
||||
* "H.264 Table E-4" and "H.265 Table E.4" share the identical values.
|
||||
*
|
||||
* Returns: the matched #GstVideoTransferFunction
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
GstVideoTransferFunction
|
||||
gst_video_color_transfer_from_iso (guint value)
|
||||
{
|
||||
switch (value) {
|
||||
case 1:
|
||||
case 6:
|
||||
return GST_VIDEO_TRANSFER_BT709;
|
||||
case 4:
|
||||
return GST_VIDEO_TRANSFER_GAMMA22;
|
||||
case 5:
|
||||
return GST_VIDEO_TRANSFER_GAMMA28;
|
||||
case 7:
|
||||
return GST_VIDEO_TRANSFER_SMPTE240M;
|
||||
case 8:
|
||||
return GST_VIDEO_TRANSFER_GAMMA10;
|
||||
case 9:
|
||||
return GST_VIDEO_TRANSFER_LOG100;
|
||||
case 10:
|
||||
return GST_VIDEO_TRANSFER_LOG316;
|
||||
case 13:
|
||||
return GST_VIDEO_TRANSFER_SRGB;
|
||||
case 14:
|
||||
return GST_VIDEO_TRANSFER_BT2020_10;
|
||||
case 15:
|
||||
return GST_VIDEO_TRANSFER_BT2020_12;
|
||||
case 16:
|
||||
return GST_VIDEO_TRANSFER_SMPTE2084;
|
||||
case 18:
|
||||
return GST_VIDEO_TRANSFER_ARIB_STD_B67;
|
||||
case 2:
|
||||
default:
|
||||
return GST_VIDEO_TRANSFER_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_color_primaries_from_iso:
|
||||
* @value: a ITU-T H.273 colour primaries value
|
||||
*
|
||||
* Converts the @value to the #GstVideoColorPrimaries
|
||||
* The colour primaries (ColourPrimaries) value is
|
||||
* defined by "ISO/IEC 23001-8 Section 7.1 Table 2" and "ITU-T H.273 Table 2".
|
||||
* "H.264 Table E-3" and "H.265 Table E.3" share the identical values.
|
||||
*
|
||||
* Returns: the matched #GstVideoColorPrimaries
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
GstVideoColorPrimaries
|
||||
gst_video_color_primaries_from_iso (guint value)
|
||||
{
|
||||
switch (value) {
|
||||
case 1:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_BT709;
|
||||
case 4:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_BT470M;
|
||||
case 5:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_BT470BG;
|
||||
case 6:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_SMPTE170M;
|
||||
case 7:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_SMPTE240M;
|
||||
case 8:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_FILM;
|
||||
case 9:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_BT2020;
|
||||
case 10:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_SMPTEST428;
|
||||
case 11:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_SMPTERP431;
|
||||
case 12:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_SMPTEEG432;
|
||||
case 22:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_EBU3213;
|
||||
case 2:
|
||||
default:
|
||||
return GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,6 +242,28 @@ void gst_video_color_range_offsets (GstVideoColorRange range,
|
|||
gint offset[GST_VIDEO_MAX_COMPONENTS],
|
||||
gint scale[GST_VIDEO_MAX_COMPONENTS]);
|
||||
|
||||
/* conversion between GStreamer color{matrix,transfer,primaries} enum and
|
||||
* values defined by ISO/IEC 23001-8 and ITU-T H.273 specification.
|
||||
* Also H264 and H265 specifications follow the color{matrix,trasfer,primaries}
|
||||
* values */
|
||||
|
||||
GST_VIDEO_API
|
||||
guint gst_video_color_matrix_to_iso (GstVideoColorMatrix matrix);
|
||||
|
||||
GST_VIDEO_API
|
||||
guint gst_video_color_transfer_to_iso (GstVideoTransferFunction func);
|
||||
|
||||
GST_VIDEO_API
|
||||
guint gst_video_color_primaries_to_iso (GstVideoColorPrimaries primaries);
|
||||
|
||||
GST_VIDEO_API
|
||||
GstVideoColorMatrix gst_video_color_matrix_from_iso (guint value);
|
||||
|
||||
GST_VIDEO_API
|
||||
GstVideoTransferFunction gst_video_color_transfer_from_iso (guint value);
|
||||
|
||||
GST_VIDEO_API
|
||||
GstVideoColorPrimaries gst_video_color_primaries_from_iso (guint value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in a new issue