[FFmpeg-devel] [PATCH] avcodec/libopenjpeg: Interpret cinema profiles as XYZ

Valerii Zapodovnikov val.zapod.vz at gmail.com
Sun Jun 6 09:27:32 EEST 2021


From: Rémi Achard <remiachard at gmail.com>

Patch should be applied to decode XYZ samples with not native
decoder in ffmpeg (-c:v libopenjpeg, not -c:v jpeg2000). jpeg2000
works already.
Now, this is AFAIK a patch that should be applied after upstream's
patch: https://github.com/uclouvain/openjpeg/pull/1200
Please note that jpeg2000 XYZ is not bitperfect compared to openjpeg
see #4829#comment:3. Some pixels will be different, like in sYCC. I
consider both bugs. Also pixel_format can be forced by
"-pixel_format xyz12le".
---
 libavcodec/libopenjpegdec.c | 44 +++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 8982d21be4..dff19586bb 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -71,6 +71,10 @@ static const enum AVPixelFormat libopenjpeg_gray_pix_fmts[] = {
 static const enum AVPixelFormat libopenjpeg_yuv_pix_fmts[]  = {
     YUV_PIXEL_FORMATS
 };
+static const enum AVPixelFormat libopenjpeg_xyz_pix_fmts[]  = {
+    XYZ_PIXEL_FORMATS,
+    YUV_PIXEL_FORMATS
+};
 static const enum AVPixelFormat libopenjpeg_all_pix_fmts[]  = {
     RGB_PIXEL_FORMATS, GRAY_PIXEL_FORMATS, YUV_PIXEL_FORMATS, XYZ_PIXEL_FORMATS
 };
@@ -196,23 +200,29 @@ static inline enum AVPixelFormat libopenjpeg_guess_pix_fmt(const opj_image_t *im
     const enum AVPixelFormat *possible_fmts = NULL;
     int possible_fmts_nb = 0;
 
-    switch (image->color_space) {
-    case OPJ_CLRSPC_SRGB:
-        possible_fmts    = libopenjpeg_rgb_pix_fmts;
-        possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_rgb_pix_fmts);
-        break;
-    case OPJ_CLRSPC_GRAY:
-        possible_fmts    = libopenjpeg_gray_pix_fmts;
-        possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_gray_pix_fmts);
-        break;
-    case OPJ_CLRSPC_SYCC:
-        possible_fmts    = libopenjpeg_yuv_pix_fmts;
-        possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_yuv_pix_fmts);
-        break;
-    default:
-        possible_fmts    = libopenjpeg_all_pix_fmts;
-        possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_all_pix_fmts);
-        break;
+    if (image->rsiz == FF_PROFILE_JPEG2000_DCINEMA_2K ||
+        image->rsiz == FF_PROFILE_JPEG2000_DCINEMA_4K) {
+        possible_fmts = libopenjpeg_xyz_pix_fmts;
+        possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_xyz_pix_fmts);
+    } else {
+        switch (image->color_space) {
+        case OPJ_CLRSPC_SRGB:
+            possible_fmts    = libopenjpeg_rgb_pix_fmts;
+            possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_rgb_pix_fmts);
+            break;
+        case OPJ_CLRSPC_GRAY:
+            possible_fmts    = libopenjpeg_gray_pix_fmts;
+            possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_gray_pix_fmts);
+            break;
+        case OPJ_CLRSPC_SYCC:
+            possible_fmts    = libopenjpeg_yuv_pix_fmts;
+            possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_yuv_pix_fmts);
+            break;
+        default:
+            possible_fmts    = libopenjpeg_all_pix_fmts;
+            possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_all_pix_fmts);
+            break;
+        }
     }
 
     for (index = 0; index < possible_fmts_nb; ++index)
-- 
2.30.2



More information about the ffmpeg-devel mailing list