]> source.dussan.org Git - tigervnc.git/commitdiff
H264Libav: Handle colour space conversion
authorAndri Yngvason <andri@yngvason.is>
Mon, 19 Aug 2024 22:34:37 +0000 (22:34 +0000)
committerLinn Mattsson <linma@cendio.se>
Tue, 22 Oct 2024 10:41:33 +0000 (12:41 +0200)
The scaler is now informed of the colour space encoded into the stream
so that it may do the proper conversion.

(cherry picked from commit 28cc17e309fc6117370b38ec11d803dc36e8ef01)

common/rfb/H264LibavDecoderContext.cxx

index f1599f4c4e43dcf90c498d0222605fd9fe39272f..a7c817bfe3630555da5c03fd3faf47593116559a 100644 (file)
@@ -217,6 +217,21 @@ void H264LibavDecoderContext::decode(const uint8_t* h264_in_buffer,
                              frame->width, frame->height, AV_PIX_FMT_RGB32,
                              0, NULL, NULL, NULL);
 
+  int inFull, outFull, brightness, contrast, saturation;
+  const int* inTable;
+  const int* outTable;
+
+  sws_getColorspaceDetails(sws, (int**)&inTable, &inFull, (int**)&outTable,
+      &outFull, &brightness, &contrast, &saturation);
+  if (frame->colorspace != AVCOL_SPC_UNSPECIFIED) {
+    inTable = sws_getCoefficients(frame->colorspace);
+  }
+  if (frame->color_range != AVCOL_RANGE_UNSPECIFIED) {
+    inFull = frame->color_range == AVCOL_RANGE_JPEG;
+  }
+  sws_setColorspaceDetails(sws, inTable, inFull, outTable, outFull, brightness,
+      contrast, saturation);
+
   if (rgbFrame && (rgbFrame->width != frame->width || rgbFrame->height != frame->height)) {
     av_frame_free(&rgbFrame);