matroska: Port to color_{primaries,transfer,matrix}_to_iso

... and remove duplicated code.
This commit is contained in:
Seungha Yang 2019-07-15 23:24:05 +09:00
parent 436d33b288
commit aa0544ab8f
2 changed files with 9 additions and 242 deletions

View file

@ -595,36 +595,7 @@ gst_matroska_demux_parse_colour (GstMatroskaDemux * demux, GstEbmlRead * ebml,
if ((ret = gst_ebml_read_uint (ebml, &id, &num)) != GST_FLOW_OK)
goto beach;
switch (num) {
case 0:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
break;
case 1:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT709;
break;
case 2:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
break;
case 4:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_FCC;
break;
/* FIXME: "5: BT470BG" is undefined in GstVideoColorMatrix
* but it's functionally same as "6: BT601" */
case 5:
case 6:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT601;
break;
case 7:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
break;
case 9:
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
break;
default:
GST_FIXME_OBJECT (demux, "Unsupported color matrix coefficients %"
G_GUINT64_FORMAT, num);
break;
}
colorimetry.matrix = gst_video_color_matrix_from_iso ((guint) num);
break;
}
@ -654,55 +625,7 @@ gst_matroska_demux_parse_colour (GstMatroskaDemux * demux, GstEbmlRead * ebml,
if ((ret = gst_ebml_read_uint (ebml, &id, &num)) != GST_FLOW_OK)
goto beach;
switch (num) {
/* FIXME: "6: BT601" and "14: BT2020_10" are undefined in
* GstVideoTransferFunction, but functionally same as "1: BT709" */
case 1:
case 6:
colorimetry.transfer = GST_VIDEO_TRANSFER_BT709;
break;
case 2:
colorimetry.transfer = GST_VIDEO_TRANSFER_UNKNOWN;
break;
case 4:
colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA22;
break;
case 5:
colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA28;
break;
case 7:
colorimetry.transfer = GST_VIDEO_TRANSFER_SMPTE240M;
break;
case 8:
colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA10;
break;
case 9:
colorimetry.transfer = GST_VIDEO_TRANSFER_LOG100;
break;
case 10:
colorimetry.transfer = GST_VIDEO_TRANSFER_LOG316;
break;
case 13:
colorimetry.transfer = GST_VIDEO_TRANSFER_SRGB;
break;
case 14:
colorimetry.transfer = GST_VIDEO_TRANSFER_BT2020_10;
break;
case 15:
colorimetry.transfer = GST_VIDEO_TRANSFER_BT2020_12;
break;
case 16:
colorimetry.transfer = GST_VIDEO_TRANSFER_SMPTE2084;
break;
case 18:
colorimetry.transfer = GST_VIDEO_TRANSFER_ARIB_STD_B67;
break;
default:
GST_FIXME_OBJECT (demux,
"Unsupported color transfer characteristics %"
G_GUINT64_FORMAT, num);
break;
}
colorimetry.transfer = gst_video_color_transfer_from_iso ((guint) num);
break;
}
@ -710,48 +633,8 @@ gst_matroska_demux_parse_colour (GstMatroskaDemux * demux, GstEbmlRead * ebml,
if ((ret = gst_ebml_read_uint (ebml, &id, &num)) != GST_FLOW_OK)
goto beach;
switch (num) {
case 1:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
break;
case 2:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
break;
case 4:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT470M;
break;
case 5:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT470BG;
break;
case 6:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M;
break;
case 7:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE240M;
break;
case 8:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_FILM;
break;
case 9:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020;
break;
case 10:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTEST428;
break;
case 11:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTERP431;
break;
case 12:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTEEG432;
break;
case 22:
colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_EBU3213;
break;
default:
GST_FIXME_OBJECT (demux, "Unsupported color primaries %"
G_GUINT64_FORMAT, num);
break;
}
colorimetry.primaries =
gst_video_color_primaries_from_iso ((guint) num);
break;
}

View file

@ -2579,33 +2579,6 @@ gst_matroska_mux_write_colour (GstMatroskaMux * mux,
master = gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_VIDEOCOLOUR);
switch (videocontext->colorimetry.matrix) {
case GST_VIDEO_COLOR_MATRIX_RGB:
matrix_id = 0;
break;
case GST_VIDEO_COLOR_MATRIX_BT709:
matrix_id = 1;
break;
case GST_VIDEO_COLOR_MATRIX_UNKNOWN:
matrix_id = 2;
break;
case GST_VIDEO_COLOR_MATRIX_FCC:
matrix_id = 4;
break;
case GST_VIDEO_COLOR_MATRIX_BT601:
matrix_id = 6;
break;
case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
matrix_id = 7;
break;
case GST_VIDEO_COLOR_MATRIX_BT2020:
matrix_id = 9;
break;
default:
GST_FIXME_OBJECT (mux, "Unhandled color matrix %d", matrix_id);
break;
}
switch (videocontext->colorimetry.range) {
case GST_VIDEO_COLOR_RANGE_UNKNOWN:
range_id = 0;
@ -2617,100 +2590,11 @@ gst_matroska_mux_write_colour (GstMatroskaMux * mux,
range_id = 2;
}
switch (videocontext->colorimetry.transfer) {
case GST_VIDEO_TRANSFER_BT709:
transfer_id = 1;
break;
/* FIXME: can't tell what the code should be for these */
case GST_VIDEO_TRANSFER_GAMMA18:
case GST_VIDEO_TRANSFER_GAMMA20:
case GST_VIDEO_TRANSFER_ADOBERGB:
case GST_VIDEO_TRANSFER_UNKNOWN:
transfer_id = 2;
break;
/* Adobe RGB transfer is gamma 2.19921875 */
case GST_VIDEO_TRANSFER_GAMMA22:
transfer_id = 4;
break;
case GST_VIDEO_TRANSFER_GAMMA28:
transfer_id = 5;
break;
case GST_VIDEO_TRANSFER_SMPTE240M:
transfer_id = 7;
break;
case GST_VIDEO_TRANSFER_GAMMA10:
transfer_id = 8;
break;
case GST_VIDEO_TRANSFER_LOG100:
transfer_id = 9;
break;
case GST_VIDEO_TRANSFER_LOG316:
transfer_id = 10;
break;
case GST_VIDEO_TRANSFER_SRGB:
transfer_id = 13;
break;
case GST_VIDEO_TRANSFER_BT2020_10:
transfer_id = 14;
break;
case GST_VIDEO_TRANSFER_BT2020_12:
transfer_id = 15;
break;
case GST_VIDEO_TRANSFER_SMPTE2084:
transfer_id = 16;
break;
case GST_VIDEO_TRANSFER_ARIB_STD_B67:
transfer_id = 18;
break;
default:
GST_FIXME_OBJECT (mux,
"Unhandled transfer characteristic %d", transfer_id);
break;
}
switch (videocontext->colorimetry.primaries) {
case GST_VIDEO_COLOR_PRIMARIES_BT709:
primaries_id = 1;
break;
/* FIXME: can't tell what the code should be for this one */
case GST_VIDEO_COLOR_PRIMARIES_ADOBERGB:
case GST_VIDEO_COLOR_PRIMARIES_UNKNOWN:
primaries_id = 2;
break;
case GST_VIDEO_COLOR_PRIMARIES_BT470M:
primaries_id = 4;
break;
case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
primaries_id = 5;
break;
case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
primaries_id = 6;
break;
case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
primaries_id = 7;
break;
case GST_VIDEO_COLOR_PRIMARIES_FILM:
primaries_id = 8;
break;
case GST_VIDEO_COLOR_PRIMARIES_BT2020:
primaries_id = 9;
break;
case GST_VIDEO_COLOR_PRIMARIES_SMPTEST428:
primaries_id = 10;
break;
case GST_VIDEO_COLOR_PRIMARIES_SMPTERP431:
primaries_id = 11;
break;
case GST_VIDEO_COLOR_PRIMARIES_SMPTEEG432:
primaries_id = 12;
break;
case GST_VIDEO_COLOR_PRIMARIES_EBU3213:
primaries_id = 22;
break;
default:
GST_FIXME_OBJECT (mux, "Unhandled color primaries %d", primaries_id);
break;
}
matrix_id = gst_video_color_matrix_to_iso (videocontext->colorimetry.matrix);
transfer_id =
gst_video_color_transfer_to_iso (videocontext->colorimetry.transfer);
primaries_id =
gst_video_color_primaries_to_iso (videocontext->colorimetry.primaries);
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_VIDEORANGE, range_id);
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_VIDEOMATRIXCOEFFICIENTS,