From 465f530a3fb80eb42b3539dc253c029ca0f1ab02 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Wed, 14 Jul 2021 02:09:05 +0300
Subject: [PATCH 7/8] Attempt at differenciating bt2020 ncl vs bt2020 cl

---
 cinelerra-5.1/cinelerra/appearanceprefs.C |  3 ++-
 cinelerra-5.1/cinelerra/appearanceprefs.h |  2 +-
 cinelerra-5.1/cinelerra/ffmpeg.C          | 13 +++++++++----
 cinelerra-5.1/guicast/bccolors.C          |  3 ++-
 cinelerra-5.1/guicast/bccolors.inc        |  3 ++-
 5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/appearanceprefs.C b/cinelerra-5.1/cinelerra/appearanceprefs.C
index 6289bfac..83233e2b 100644
--- a/cinelerra-5.1/cinelerra/appearanceprefs.C
+++ b/cinelerra-5.1/cinelerra/appearanceprefs.C
@@ -891,8 +891,9 @@ int HighlightInverseColor::handle_event()
 const char *YuvColorSpace::color_space[] = {
 	N_("BT601_NTSC"), // COLOR SPACE BT601_NTSC
 	N_("BT709"), // COLOR_SPACE_BT709
-	N_("BT2020"), // COLOR_SPACE_BT2020
+	N_("BT2020 NCL"), // COLOR_SPACE_BT2020_NCL
 	N_("BT601_PAL"), // COLOR_SPACE_BT601_PAL
+	N_("BT2020 CL"), // COLOR_SPACE_BT2020_CL
 };
 
 YuvColorSpace::YuvColorSpace(int x, int y, PreferencesWindow *pwindow)
diff --git a/cinelerra-5.1/cinelerra/appearanceprefs.h b/cinelerra-5.1/cinelerra/appearanceprefs.h
index ba6763e9..c479da47 100644
--- a/cinelerra-5.1/cinelerra/appearanceprefs.h
+++ b/cinelerra-5.1/cinelerra/appearanceprefs.h
@@ -377,7 +377,7 @@ public:
 class YuvColorSpace : public BC_PopupMenu
 {
 public:
-	static const char *color_space[4];
+	static const char *color_space[5];
 	YuvColorSpace(int x, int y, PreferencesWindow *pwindow);
 	~YuvColorSpace();
 
diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 952c3ca4..63144ec1 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -1596,7 +1596,8 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame *
 	case BC_COLORS_BT601_PAL:  color_space = SWS_CS_ITU601;  break;
 	case BC_COLORS_BT601_NTSC: color_space = SWS_CS_SMPTE170M; break;
 	case BC_COLORS_BT709:  color_space = SWS_CS_ITU709;  break;
-	case BC_COLORS_BT2020: color_space = SWS_CS_BT2020;  break;
+	case BC_COLORS_BT2020_NCL: 
+	case BC_COLORS_BT2020_CL: color_space = SWS_CS_BT2020;  break;
 	}
 	const int *color_table = sws_getCoefficients(color_space);
 
@@ -1726,7 +1727,8 @@ int FFVideoConvert::convert_vframe_picture(VFrame *frame, AVFrame *op, AVFrame *
 	case BC_COLORS_BT601_PAL:  color_space = SWS_CS_ITU601;  break;
 	case BC_COLORS_BT601_NTSC: color_space = SWS_CS_SMPTE170M; break;
 	case BC_COLORS_BT709:  color_space = SWS_CS_ITU709;  break;
-	case BC_COLORS_BT2020: color_space = SWS_CS_BT2020;  break;
+	case BC_COLORS_BT2020_NCL:
+	case BC_COLORS_BT2020_CL: color_space = SWS_CS_BT2020;  break;
 	}
 	const int *color_table = sws_getCoefficients(color_space);
 
@@ -2653,8 +2655,10 @@ int FFMPEG::open_decoder()
 				vid->color_space = BC_COLORS_BT709;
 				break;
 			case AVCOL_SPC_BT2020_NCL:
+				vid->color_space = BC_COLORS_BT2020_NCL;
+				break;
 			case AVCOL_SPC_BT2020_CL:
-				vid->color_space = BC_COLORS_BT2020;
+				vid->color_space = BC_COLORS_BT2020_CL;
 				break;
 			default:
 				vid->color_space = !file_base ? BC_COLORS_BT601_NTSC :
@@ -2911,7 +2915,8 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 			case BC_COLORS_BT601_NTSC:  ctx->colorspace = AVCOL_SPC_SMPTE170M;  break;
 			case BC_COLORS_BT601_PAL: ctx->colorspace = AVCOL_SPC_BT470BG; break;
 			case BC_COLORS_BT709:  ctx->colorspace = AVCOL_SPC_BT709;      break;
-			case BC_COLORS_BT2020: ctx->colorspace = AVCOL_SPC_BT2020_NCL; break;
+			case BC_COLORS_BT2020_NCL: ctx->colorspace = AVCOL_SPC_BT2020_NCL; break;
+			case BC_COLORS_BT2020_CL: ctx->colorspace = AVCOL_SPC_BT2020_CL; break;
 			}
 			AVPixelFormat pix_fmt = av_get_pix_fmt(asset->ff_pixel_format);
 			if( opt_hw_dev != 0 ) {
diff --git a/cinelerra-5.1/guicast/bccolors.C b/cinelerra-5.1/guicast/bccolors.C
index 94dfd20b..287cc9f8 100644
--- a/cinelerra-5.1/guicast/bccolors.C
+++ b/cinelerra-5.1/guicast/bccolors.C
@@ -146,7 +146,8 @@ void YUV::yuv_set_colors(int color_space, int color_range)
 	case BC_COLORS_BT601_NTSC:  kr = BT601_NTSC_Kr;   kb = BT601_NTSC_Kb;   break;
 	case BC_COLORS_BT601_PAL: kr = BT601_PAL_Kr; kb = BT601_PAL_Kb; break;
 	case BC_COLORS_BT709:  kr = BT709_Kr;   kb = BT709_Kb;   break;
-	case BC_COLORS_BT2020: kr = BT2020_Kr;  kb = BT2020_Kb;  break;
+	case BC_COLORS_BT2020_NCL: 
+	case BC_COLORS_BT2020_CL: kr = BT2020_Kr;  kb = BT2020_Kb;  break;
 	}
 	switch( color_range ) {
 	default:
diff --git a/cinelerra-5.1/guicast/bccolors.inc b/cinelerra-5.1/guicast/bccolors.inc
index 58afbaee..3557587b 100644
--- a/cinelerra-5.1/guicast/bccolors.inc
+++ b/cinelerra-5.1/guicast/bccolors.inc
@@ -28,7 +28,8 @@ class YUV;
 #define BC_COLORS_BT601_NTSC 0
 #define BC_COLORS_BT601_PAL 3
 #define BC_COLORS_BT709 1
-#define BC_COLORS_BT2020 2
+#define BC_COLORS_BT2020_NCL 2
+#define BC_COLORS_BT2020_CL 4
 
 #define BC_COLORS_JPEG 0
 #define BC_COLORS_MPEG 1
-- 
2.32.0

