From 2aa2477208c029b0e1b8232d69f4f99a3bf1d473 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 6 Dec 2021 15:37:06 +0100 Subject: [PATCH] jpegdec: only allow conversions from RGB libjpeg-turbo only supports converting from RGB to other RGB formats. Fix runtime error when trying to convert from a YUV format for example. Fix #916 Part-of: --- subprojects/gst-plugins-good/ext/jpeg/gstjpegdec.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/jpeg/gstjpegdec.c b/subprojects/gst-plugins-good/ext/jpeg/gstjpegdec.c index db81b416a3..3b66e264a9 100644 --- a/subprojects/gst-plugins-good/ext/jpeg/gstjpegdec.c +++ b/subprojects/gst-plugins-good/ext/jpeg/gstjpegdec.c @@ -1071,8 +1071,9 @@ gst_jpeg_dec_negotiate (GstJpegDec * dec, gint width, gint height, gint clrspc, peerformat = gst_structure_get_string (peerstruct, "format"); peerfmt = gst_video_format_from_string (peerformat); + /* libjpeg-turbo only supports some colorspace conversions, see + * https://raw.githubusercontent.com/libjpeg-turbo/libjpeg-turbo/main/libjpeg.txt */ switch (peerfmt) { - case GST_VIDEO_FORMAT_RGB: case GST_VIDEO_FORMAT_RGBx: case GST_VIDEO_FORMAT_xRGB: case GST_VIDEO_FORMAT_RGBA: @@ -1082,11 +1083,14 @@ gst_jpeg_dec_negotiate (GstJpegDec * dec, gint width, gint height, gint clrspc, case GST_VIDEO_FORMAT_xBGR: case GST_VIDEO_FORMAT_BGRA: case GST_VIDEO_FORMAT_ABGR: - clrspc = JCS_RGB; - format = peerfmt; - dec->format_convert = TRUE; - dec->libjpeg_ext_format = gst_fmt_to_jpeg_turbo_ext_fmt (peerfmt); + if (clrspc == JCS_RGB) { + /* RGB -> other RGB formats */ + format = peerfmt; + dec->format_convert = TRUE; + dec->libjpeg_ext_format = gst_fmt_to_jpeg_turbo_ext_fmt (peerfmt); + } break; + /* TODO: implement conversion from/to other supported colorspaces */ default: break; }