edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB8c7bf80Tahinli3 months ago114 commits
| 1 | //! Per-segment colour transform, applied engine-side on the decoded YUV samples |
| 2 | //! so that playback and export produce the same picture from the same numbers. |
| 3 | //! |
| 4 | //! The maths lives on YUV rather than RGB because every path already has YUV in |
| 5 | //! hand -- the decoders hand back I420 and the encoders take it -- and because |
| 6 | //! the four controls are each a straight per-sample affine there: |
| 7 | //! |
| 8 | //! * brightness and contrast move Y alone (contrast pivots on limited-range mid |
| 9 | //! grey, `(16 + 235) / 2`; brightness shifts by a fraction of the 219-code |
| 10 | //! luma range, so `1.0` lifts black to white), |
| 11 | //! * saturation scales U and V about 128, so `0.0` is exactly grey, |
| 12 | //! * tint is a warm/cool *temperature* axis, not a magenta/green one: U carries |
| 13 | //! blue-difference and V red-difference, so warm (positive) pushes V up and U |
| 14 | //! down by the same amount. A hue rotation would need a 2x2 matrix on (U,V) |
| 15 | //! and buys nothing a colourist asks for by name. |
| 16 | //! |
| 17 | //! Every control therefore collapses into three 256-entry lookup tables built |
| 18 | //! once per call, and the pixel loop is a byte indexing a table -- no float per |
| 19 | //! pixel, no chance of a `u8` wrap. Identity params short-circuit before the |
| 20 | //! tables exist, which is what makes "no colour set" byte-identical rather than |
| 21 | //! merely close. |
| 22 | |
| 23 | /// Limited-range mid grey; contrast pivots here so a change does not also |
| 24 | /// shift the picture's overall level. |
| 25 | const MID_Y: f32 = 125.5; |
| 26 | /// Codes between limited-range black (16) and white (235). |
| 27 | const LUMA_RANGE: f32 = 219.0; |
| 28 | /// Chroma codes a full-warm or full-cool tint moves U and V by. Picked so the |
| 29 | /// extreme is a strong grade rather than a broken picture. |
| 30 | const TINT_RANGE: f32 = 32.0; |
| 31 | |
| 32 | /// One segment's colour setting. Plain data with no invariants: out-of-range or |
| 33 | /// non-finite values are clamped where the tables are built, so a deserializer |
| 34 | /// can hand this over unchecked. |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | /// The three per-plane tables. Built once per frame (768 float ops against ~3 M |
| 68 | /// samples at 1080p, so the build never shows up in a measurement). |
| 69 | pub |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | /// A parameter that survived a file or a UI edit; NaN and infinity fall back to |
| 101 | /// the identity value rather than blanking the picture. |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | /// Applies `params` in place to one planar 8-bit frame. |
| 111 | /// |
| 112 | /// Per-sample, so the plane layout is free: I420 with `stride == width` (what |
| 113 | /// [`crate::convert`] and the export path use) or any other planar 8-bit YUV, |
| 114 | /// padding included. Interleaved chroma (NV12) is *not* this function's frame. |
| 115 | /// |
| 116 | /// Identity params return without touching a byte. |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 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 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 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 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 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 | |
| 247 | |
| 248 | |
| 249 | |
| 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 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 |