edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB03dc6e9Tahinli3 months ago178 commits
| 1 | //! Forward transforms and quantisation. |
| 2 | //! |
| 3 | //! Nothing here is normative: the standard specifies only the *inverse* |
| 4 | //! transforms, which the decoder side of this crate already implements |
| 5 | //! ([`crate::transform`]). The forward direction is chosen so that the |
| 6 | //! round trip through the normative inverse lands back on the source, and |
| 7 | //! that is what the tests at the bottom check across the whole QP range. |
| 8 | //! |
| 9 | //! The multiplier table pairs with `normAdjust4x4` (Table 8-15 through the |
| 10 | //! `LevelScale` of Equation 8-313): `MF[m][class] * normAdjust4x4[m][class] * |
| 11 | //! 16 ~= 2^21`, which is what makes `level = (|c| * MF + f) >> (15 + qp / 6)` |
| 12 | //! invert the decoder's dequantisation. |
| 13 | |
| 14 | use crate; |
| 15 | |
| 16 | /// Quantisation multipliers per `qp % 6`, indexed by the same position class |
| 17 | /// as [`NORM_ADJUST_CLASS_4X4`] (0 = even/even, 1 = odd/odd, 2 = mixed). |
| 18 | const MF: = |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | ; |
| 26 | |
| 27 | /// Rounding offset numerator: an intra block rounds at 1/3 of a step, an inter |
| 28 | /// block at 1/6 — the classic asymmetry, which spends bits where prediction is |
| 29 | /// weakest. Measured against 1/3 and 1/2 for the inter case on 1080p camera |
| 30 | /// and screen-capture clips: 1/6 is level or ahead at matched bitrate. |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | /// Forward 4x4 core transform (the inverse of spec 8.5.12.2), raster in and |
| 37 | /// out, integer and exact. |
| 38 | pub |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | /// Forward 4x4 Hadamard over the sixteen luma DC coefficients of an |
| 59 | /// Intra_16x16 macroblock (the inverse of spec 8.5.10), raster in and out. |
| 60 | pub |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | /// Forward 2x2 Hadamard over the four chroma DC coefficients (the inverse of |
| 79 | /// spec 8.5.11). |
| 80 | pub |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | /// Quantise a transformed 4x4 block into scan (zig-zag) order. |
| 89 | /// |
| 90 | /// `skip_dc` leaves scan position 0 out and writes the fifteen AC levels into |
| 91 | /// `out[0..15]`, which is the layout the AC residual blocks of Intra_16x16 and |
| 92 | /// chroma use. Returns the number of non-zero levels. |
| 93 | pub |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | /// Quantise the sixteen Hadamard-transformed luma DC coefficients into scan |
| 120 | /// order. Two extra bits of shift pay for the gain of the forward Hadamard, |
| 121 | /// which the decoder's inverse (8.5.10, a `>> 6` where the AC path shifts by |
| 122 | /// four) takes back out. |
| 123 | pub |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | /// Quantise the four Hadamard-transformed chroma DC coefficients (raster |
| 141 | /// order, which is also their scan order). |
| 142 | pub |
| 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 |