edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli4 days ago4021 commits
| 1 | //! Sample adaptive offset (clause 8.7.3). It runs on the whole picture after |
| 2 | //! deblocking. Every CTB and colour component whose `SaoTypeIdx` is not 0 is |
| 3 | //! rewritten from a copy of the deblocked planes, so an edge offset always |
| 4 | //! compares against deblocked neighbours and never against a sample that SAO |
| 5 | //! has already changed. Samples of PCM units (when `pcm_loop_filter_disabled` |
| 6 | //! is set) and of transquant-bypass units are left alone. So are edge samples |
| 7 | //! whose neighbour lies outside the picture or across a slice boundary that |
| 8 | //! the slice header forbids. |
| 9 | |
| 10 | use ; |
| 11 | |
| 12 | /// `hPos` and `vPos` of the two neighbours for each `SaoEoClass`. |
| 13 | const EO_NEIGHBOURS: = |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | ; |
| 19 | |
| 20 | /// The size of one colour plane and how luma positions map onto it. |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | /// Apply SAO to the whole picture in place. |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /// [`sao_picture`] with each plane's CTB rows split into `threads` bands, filtered |
| 40 | /// in parallel. A band reads the deblocked input (shared, read-only) and writes only |
| 41 | /// its own rows of the output, so the bands never touch the same sample. |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | /// The SAO output of colour component `c`, computed from the input plane `src`. |
| 56 | /// |
| 57 | /// Each CTB is handled with its neighbour availability worked out once (see |
| 58 | /// [`neighbour_cells`]), so the per-sample loop only compares a neighbour's CTB |
| 59 | /// cell against a 3x3 table instead of looking up slice and tile state. |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 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 | /// SAO for the CTB rows `rows` of plane `c`, writing into `dst`, which holds the |
| 97 | /// plane rows from `row0` down (so `dst` may be a band of the whole output). |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 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 | /// SAO of the CTB row `ry` of colour component `c` (8.7.3), written into `dst`, which |
| 188 | /// holds the plane rows of that CTB row from its first row on. `src` is the deblocked |
| 189 | /// plane (a full-size buffer; the rows of `ry` and the row of each side are read from it). |
| 190 | pub |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | /// The size of colour component `c` of `pic`. |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | /// The index of plane position `(x, y)` in a buffer that starts at plane row `row0`. |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | /// The luma-to-plane bounds of one CTB: `[x0, x1) x [y0, y1)` in plane samples, |
| 221 | /// clipped to the picture, and the unclipped CTB size in plane samples. |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | /// Sum of the two edge signs of sample `(x, y)` (each in -1..=1), or `None` when a |
| 233 | /// neighbour is outside the picture or across a forbidden slice or tile boundary. |
| 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 | /// Which of the three CTB columns (or rows) a neighbouring plane position falls in, |
| 264 | /// given the first position of the current CTB: 0 before it, 2 past its end, else 1. |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | /// Whether a neighbouring CTB may be used by the CTB at `(rx, ry)`, for each cell |
| 276 | /// of its 3x3 neighbourhood (row-major, `cell = cy * 3 + cx`). The centre cell is |
| 277 | /// always usable; a cell off the CTB grid is not. Slice and tile rules are decided |
| 278 | /// per CTB pair by [`across_slice_allowed`] on the CTB origins. |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | /// Whether any 4x4 unit of the CTB is excluded from SAO (see [`excluded`]). |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | /// `SaoOffsetVal[idx]` of component `c`: 0 for index 0, else the signed, |
| 318 | /// scaled offset `idx`. |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | /// Whether the neighbouring luma position `nb` may be used by a sample at |
| 326 | /// luma position `cur` under the slice and tile boundary rules of 8.7.3.2. For a |
| 327 | /// slice boundary the flag of the later slice in decoding order decides. |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | /// Whether the luma unit at `(x, y)` is a PCM unit with loop filtering |
| 352 | /// disabled or a transquant-bypass unit, whose samples SAO must not change. |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 |