View Bug Details

IDProjectCategoryView StatusLast Update
0002318DCP-o-maticBugspublic2023-09-01 21:52
Reportercarl Assigned Tocarl  
PriorityurgentSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Target Version2.16.31 
Summary0002318: Messed up colours with "HDR" yuv420p10le source
Description

[]

TagsNo tags attached.
Branchrec2020 (in libdcp and dom)
Estimated weeks required
Estimated work requiredMedium

Relationships

related to 0002355 acknowledgedcarl Add a tonemapping filter to make Rec.2020 sources look better 

Activities

carl

2022-09-04 13:17

administrator   ~0005188

Last edited: 2022-10-05 19:44

Seems OK in VLC and ffplay

...later, trying again and looks good in VLC but washed out in ffplay

carl

2022-10-05 19:15

administrator   ~0005254

Last edited: 2022-10-05 19:17

hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084)

carl

2022-10-05 20:03

administrator   ~0005255

Making a DCP and playing it back in DoM looks closer than ffmpeg but still not a very deep red on the marvel logo. Part of the problem (at least) may be a lack of colourspace conversion / tone mapping for the preview.

carl

2022-10-05 21:17

administrator   ~0005256

Last edited: 2022-10-05 22:55

ffplay -vf colorspace=iall=bt2020:all=bt709 looks better.

also
ffplay -vf zscale=transfer=linear,tonemap=hable,zscale=transfer=bt709:primaries=709

carl

2022-10-05 22:58

administrator   ~0005257

The main problem here seems to be that for the preview there's no accounting for the difference in primaries between Rec 709 and Rec 2020. Since sRGB and Rec 708 use the same primaries I think we get away with this normally.

Putting in a conversion from Rec 2020 to XYZ and back to Rec 709 makes it look a lot better:

+       for (int y = 0; y < out->size().height; ++y) {
+               uint8_t* p = out->data()[0] + y * out->stride()[0];
+               for (int x = 0; x < out->size().width; ++x) {
+                       int const R = p[0];
+                       int const G = p[1];
+                       int const B = p[2];
+
+                       auto const X = R * source_to_xyz(0, 0) + G * source_to_xyz(0, 1) + B * source_to_xyz(0, 2);
+                       auto const Y = R * source_to_xyz(1, 0) + G * source_to_xyz(1, 1) + B * source_to_xyz(1, 2);
+                       auto const Z = R * source_to_xyz(2, 0) + G * source_to_xyz(2, 1) + B * source_to_xyz(2, 2);
+
+                       p[0] = std::max(0.0, std::min(255.0, X * xyz_to_dest(0, 0) + Y * xyz_to_dest(0, 1) + Z * xyz_to_dest(0, 2)));
+                       p[1] = std::max(0.0, std::min(255.0, X * xyz_to_dest(1, 0) + Y * xyz_to_dest(1, 1) + Z * xyz_to_dest(1, 2)));
+                       p[2] = std::max(0.0, std::min(255.0, X * xyz_to_dest(2, 0) + Y * xyz_to_dest(2, 1) + Z * xyz_to_dest(2, 2)));
+
+                       p += 3;
+               }
+       }

Also it looks like there is a different YUV -> RGB conversion for Rec 2020 (I don't understand why) which FFmpeg now supports but libdcp/DoM do not. I haven't managed to see a difference when using that, so either I'm doing it wrong or it's quite subtle.

We should also offer tone mapping to account for the fact that Rec 2020 is a wider gamut than DCI P3. FFmpeg has tonemap for this.

carl

2022-10-05 23:03

administrator   ~0005258

Last edited: 2022-10-17 23:10

What needs doing

  • DONE: support FFmpeg's Rec2020/YUV conversion SWS_CS_BT2020
  • DONE: add in a video filter (I guess) to change the primaries of rec2020 to rec709/sRGB for the preview, somehow transparently
  • add an option for tonemapping, to work with the preview and the DCP I guess (could maybe just be a video filter; but we need either parameters or different filters for rec2020/display and rec2020/dcp)

carl

2022-10-06 23:45

administrator   ~0005259

Try using VideoFilterGraphSet in the simple video view and an OpenGL matrix in the GL view.

carl

2022-10-17 23:25

administrator   ~0005269

This might be enough for now, it should at least make things a little better. @carl tests running

carl

2022-10-18 20:42

administrator   ~0005270

Last edited: 2022-10-18 20:43

Merged at 94eff17bdb94c170d456c7dab5ad3d4c00af4b14

Bug History

Date Modified Username Field Change
2022-09-04 13:15 carl New Bug
2022-09-04 13:16 carl Status new => confirmed
2022-09-04 13:16 carl Target Version => 2.16.25
2022-09-04 13:16 carl Estimated work required => Undecided
2022-09-04 13:17 carl Note Added: 0005188
2022-09-11 08:37 carl Target Version 2.16.25 => 2.16.26
2022-09-18 20:55 carl Target Version 2.16.26 => 2.16.27
2022-09-24 21:55 carl Target Version 2.16.27 => 2.16.28
2022-10-05 17:48 carl Target Version 2.16.28 => 2.16.30
2022-10-05 19:15 carl Note Added: 0005254
2022-10-05 19:17 carl Note Edited: 0005254
2022-10-05 19:44 carl Note Edited: 0005188
2022-10-05 20:03 carl Note Added: 0005255
2022-10-05 21:17 carl Note Added: 0005256
2022-10-05 22:55 carl Note Edited: 0005256
2022-10-05 22:58 carl Note Added: 0005257
2022-10-05 23:03 carl Note Added: 0005258
2022-10-05 23:10 carl Branch => rec2020 (in libdcp and dom)
2022-10-05 23:12 carl Note Edited: 0005258
2022-10-05 23:13 carl Note Edited: 0005258
2022-10-05 23:13 carl Note Edited: 0005258
2022-10-05 23:14 carl Estimated work required Undecided => Medium
2022-10-05 23:21 carl Assigned To => carl
2022-10-05 23:21 carl Status confirmed => in progress
2022-10-06 23:45 carl Note Added: 0005259
2022-10-12 11:53 carl Target Version 2.16.30 => 2.16.31
2022-10-17 23:09 carl Note Edited: 0005258
2022-10-17 23:10 carl Note Edited: 0005258
2022-10-17 23:25 carl Relationship added related to 0002355
2022-10-17 23:25 carl Note Added: 0005269
2022-10-18 20:42 carl Status in progress => resolved
2022-10-18 20:42 carl Resolution open => fixed
2022-10-18 20:42 carl Note Added: 0005270
2022-10-18 20:43 carl Note Edited: 0005270
2023-09-01 21:52 carl Status resolved => closed