edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! An HDR stream reaching the window tone-mapped, through the door the window |
| 2 | //! itself opens ([`PlaybackSession`]) rather than through [`engine::tonemap`] |
| 3 | //! alone -- which is the whole of the claim: a PQ file used to be shown as if |
| 4 | //! its curve were SDR, i.e. grey-washed and flat, and the map has to run inside |
| 5 | //! the decode funnel for that to stop. |
| 6 | //! |
| 7 | //! `test_pq.mp4` is four flat patches whose codes `scripts/gen_fixtures.sh` |
| 8 | //! writes into the planes by hand, so every number below is named rather than |
| 9 | //! measured-and-blessed: BT.2408 diffuse white (203 cd/m^2 is PQ code 144), the |
| 10 | //! 1000 cd/m^2 highlight (code 181) and a saturated BT.2020 red. |
| 11 | //! |
| 12 | //! ```text |
| 13 | //! cargo test -p engine --release --test tonemap_render -- --test-threads=1 |
| 14 | //! ``` |
| 15 | |
| 16 | use PathBuf; |
| 17 | use sleep; |
| 18 | use ; |
| 19 | |
| 20 | use PlaybackSession; |
| 21 | use ; |
| 22 | use ; |
| 23 | use i420_to_bgra; |
| 24 | use Lane; |
| 25 | use ; |
| 26 | |
| 27 | /// The fixture's patches: the source codes, and where the centre of each one |
| 28 | /// sits in the 320x240 picture. |
| 29 | const DIFFUSE: = ; |
| 30 | const HIGHLIGHT: = ; |
| 31 | const RED: = ; |
| 32 | |
| 33 | /// What the tone map hands the rest of the funnel: BT.709, SDR, limited range. |
| 34 | const SDR: ColorDescription = ColorDescription |
| 35 | |
| 36 | |
| 37 | |
| 38 | ; |
| 39 | |
| 40 | /// Frame 0 of `test_h264.mkv` as this engine rendered it before the tone map |
| 41 | /// existed -- passthrough, ungraded -- and the same file on a 640x360 canvas |
| 42 | /// with a grade on it, which is the other branch of the funnel. Measured on |
| 43 | /// `main`; an SDR stream may not move by one byte. |
| 44 | const SDR_PASSTHROUGH: u64 = 0x9EF1_6F6F_5310_BCEE; |
| 45 | /// Re-pinned at the colour merge: lane-colour keeps graded samples inside the valid code range (1-254), which moves a graded SDR picture; the passthrough hash is unchanged. |
| 46 | const SDR_GRADED_AND_PLACED: u64 = 0x6078_31F1_73F3_1AEF; |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | /// Silent and software-decoded: the fixture is H.264 on purpose, so the bytes |
| 61 | /// are the same on a machine with a VA-API plugin and one without (hence |
| 62 | /// `--test-threads=1`). |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | /// One pixel of a rendered frame, as (B, G, R). |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | /// The limited-range BT.709 luma code a rendered pixel carries: the unit the |
| 88 | /// tone map's own anchors are named in, read back off the BGRA the window gets. |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | /// How far one pixel is from grey. |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | /// One flat patch of `codes`, rendered by hand the way the funnel is supposed |
| 100 | /// to render it: tone-mapped first, then graded, then converted as BT.709 SDR. |
| 101 | /// `grade` is applied in whichever domain `before` says -- which is the point of |
| 102 | /// [`the_grade_lands_after_the_tone_map`]. |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | /// The claim itself: a PQ stream is shown as an SDR display can show it. |
| 126 | /// Diffuse white lands where BT.2446 Method A puts it at the mastering peak the |
| 127 | /// content really has (~166, not the 144 an untouched code would convert to and |
| 128 | /// not clipped white -- the reference rendition, which is what a project nobody |
| 129 | /// has picked for is shown in), the 1000 cd/m^2 highlight stays a highlight, and |
| 130 | /// the saturated red is still red -- a grey wash is exactly what the missing map |
| 131 | /// looked like. |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | /// The preset is a thing a viewer *sees*: picked on the running session, the |
| 164 | /// very next frame out of the funnel is the new rendition, and the three are in |
| 165 | /// the order their names promise -- reference darkest, vivid brightest and |
| 166 | /// richest. Measured on the rendered BGRA the window gets, so it covers the |
| 167 | /// whole chain (project setting -> reseek -> decode worker -> LUT), not the |
| 168 | /// table alone. |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | /// ...and an SDR stream is not any of this: no clip of it builds a tone map at |
| 198 | /// all, so all three presets are the same bytes. The hash is the passthrough |
| 199 | /// branch's own, from the test below -- if a preset ever reached an SDR picture, |
| 200 | /// this is where it would show. |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | /// The other half: an SDR stream may not move by one byte for any of this. |
| 214 | /// Both branches of the funnel -- the fused passthrough conversion and the |
| 215 | /// graded-then-placed one -- against hashes measured before the tone map was |
| 216 | /// wired in. |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | /// Order: the grade is a look applied to the picture the viewer sees, so it |
| 247 | /// lands on the *tone-mapped* samples. Graded before the map instead, the same |
| 248 | /// numbers give a different pixel -- the second assert is what makes the first |
| 249 | /// one mean anything. |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | /// The film's own declared peak, all the way to the window: `test_hdr_bright.mkv` |
| 282 | /// carries the same four patches as `test_pq.mp4` and a container MaxCLL of |
| 283 | /// 4000 cd/m^2, so a funnel that read the metadata renders it at 4000 and one |
| 284 | /// that ignored it renders it at the 1000 an undeclared file is assumed at -- |
| 285 | /// two plainly different pictures, which is why that fixture says 4000 and the |
| 286 | /// older metadata ones say the 1000 nothing can tell apart from the fallback. |
| 287 | /// |
| 288 | /// Both sides are computed by hand through the same `ToneMapper`, so what is |
| 289 | /// asserted is which number the *funnel* built its table with, not where Method |
| 290 | /// A puts a patch. |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | /// ...and both tiers a peak can live in reach the table, on the fixtures that |
| 314 | /// exist for each: `test_hdr_meta.mkv` declares its 1000 in the container, |
| 315 | /// `test_hdr_sei.mkv` only inside the HEVC bitstream. Neither can be told apart |
| 316 | /// from the fallback in a *picture* (1000 is what an undeclared file is assumed |
| 317 | /// at, and both are black), so what is asserted is the number the table is |
| 318 | /// built at -- the same `Demuxer::light().peak()` hand-off the decode funnel |
| 319 | /// and the export table make. |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 |