From 00e7d3bfe6c5d522014ef3da0ada069fe967b47b Mon Sep 17 00:00:00 2001
From: Marc-Antoine Arnaud <arnaud.marcantoine@gmail.com>
Date: Thu, 4 Oct 2018 17:57:09 +0200
Subject: [PATCH 1/1] prores_ks: use CodecContext for color information if
 specified
Content-Type: text/x-patch; charset="utf-8"

---
 libavcodec/proresenc_kostya.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 81f3865ea6..a6e1b86521 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -1033,9 +1033,21 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     bytestream_put_byte  (&buf, frame_flags);
 
     bytestream_put_byte  (&buf, 0);             // reserved
-    bytestream_put_byte  (&buf, pic->color_primaries);
-    bytestream_put_byte  (&buf, pic->color_trc);
-    bytestream_put_byte  (&buf, pic->colorspace);
+    if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
+        bytestream_put_byte  (&buf, avctx->color_primaries);
+    else
+        bytestream_put_byte  (&buf, pic->color_primaries);
+
+    if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
+        bytestream_put_byte  (&buf, avctx->color_trc);
+    else
+        bytestream_put_byte  (&buf, pic->color_trc);
+
+    if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
+        bytestream_put_byte  (&buf, avctx->colorspace);
+    else
+        bytestream_put_byte  (&buf, pic->colorspace);
+
     bytestream_put_byte  (&buf, 0x40 | (ctx->alpha_bits >> 3));
     bytestream_put_byte  (&buf, 0);             // reserved
     if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
-- 
2.18.0

