edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The pieces of a ProRes export that are not the picture walk: the chroma |
| 2 | //! upsampling that takes the compositor's 4:2:0 to the 4:2:2 / 4:4:4 a ProRes |
| 3 | //! profile codes, and the QuickTime `.mov` writer. |
| 4 | //! |
| 5 | //! # Chroma upsampling |
| 6 | //! |
| 7 | //! The compositor and every decoder here hand the export 4:2:0 (8-bit, or 10-bit |
| 8 | //! where the span passes a 10-bit source through untouched). ProRes 422 codes |
| 9 | //! 4:2:2 and ProRes 4444 codes 4:4:4, so the chroma is upsampled -- not by |
| 10 | //! duplicating samples, which would double every chroma edge into a blocky |
| 11 | //! staircase, but by the linear filter the siting of 4:2:0 asks for: |
| 12 | //! |
| 13 | //! * vertically, 4:2:0 chroma sits half way between two luma rows |
| 14 | //! (MPEG-2 / H.264 "left" siting), so the two luma rows of a chroma row take |
| 15 | //! `3/4 * own + 1/4 * neighbour` (the row above for the upper, the row below |
| 16 | //! for the lower), edges clamped; |
| 17 | //! * horizontally (4:4:4 only), chroma is co-sited with the even luma column, so |
| 18 | //! even columns copy and odd columns average their two neighbours. |
| 19 | //! |
| 20 | //! An 8-bit picture is widened first to 10 bits with the same `x << 2 | x >> 6` |
| 21 | //! scale the HEVC and AV1 seats use (255 maps to 1023), so the encoder always |
| 22 | //! sees 10-bit samples and the filter runs at 10-bit precision. Nothing here can |
| 23 | //! recover chroma detail the 4:2:0 picture never had: a ProRes 422 file of a |
| 24 | //! 4:2:0 timeline is a 4:2:2 *container* of 4:2:0 information. |
| 25 | |
| 26 | use File; |
| 27 | use ; |
| 28 | use Path; |
| 29 | |
| 30 | use ; |
| 31 | use ; |
| 32 | use ; |
| 33 | |
| 34 | /// Little-endian bytes of 16-bit samples. |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /// An 8-bit sample at 10 bits: the same scale as the HEVC/AV1 widening. |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | /// Vertical 4:2:0 -> 4:2:2: a `cw` x `ch` chroma plane to `cw` x `h` rows. |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | /// Horizontal 4:2:2 -> 4:4:4: `cw` columns to `w`, even columns copied and odd |
| 57 | /// columns the mean of their two neighbours. |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | /// Planes of an `w` x `h` 4:2:0 picture at 10 bits as the 4:2:2 (`I210`) or |
| 75 | /// 4:4:4 (`I410`) frame the encoder takes. |
| 76 | pub |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | /// [`upsampled_frame`] from 8-bit planes, widened to 10 bits first. |
| 102 | pub |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | /// PCM frames per packet the sound is written in: about a second at 48 kHz. |
| 116 | const PCM_CHUNK: usize = 48_000; |
| 117 | |
| 118 | /// A QuickTime `.mov`: one ProRes picture track and, where the timeline has |
| 119 | /// sound, one 16-bit little-endian PCM track (`sowt`). |
| 120 | pub |
| 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 |