swscale/ops: add explicit row offset to SwsDitherOp

To improve decorrelation between components, we offset the dither matrix
slightly for each component. This is currently done by adding a hard-coded
offset of {0, 3, 2, 5} to each of the four components, respectively.

However, this represents a serious challenge when re-ordering SwsDitherOp
past a swizzle, or when splitting an SwsOpList into multiple sub-operations
(e.g. for decoupling luma from subsampled chroma when they are independent).

To fix this on a fundamental level, we have to keep track of the offset per
channel as part of the SwsDitherOp metadata, and respect those values at
runtime.

This commit merely adds the metadata; the update to the underlying backends
will come in a follow-up commit. The FATE change is merely due to the
added offsets in the op list print-out.
This commit is contained in:
Niklas Haas
2025-12-09 10:50:33 +01:00
committed by Niklas Haas
parent b9078c0939
commit 960cf3015e
5 changed files with 16 additions and 4 deletions

View File

@@ -624,6 +624,7 @@ static void check_dither(void)
/* Test all sizes up to 256x256 */
for (int size_log2 = 0; size_log2 <= 8; size_log2++) {
const int size = 1 << size_log2;
const int mask = size - 1;
AVRational *matrix = av_refstruct_allocz(size * size * sizeof(*matrix));
if (!matrix) {
fail();
@@ -641,7 +642,8 @@ static void check_dither(void)
.op = SWS_OP_DITHER,
.type = t,
.dither.size_log2 = size_log2,
.dither.matrix = matrix,
.dither.matrix = matrix,
.dither.y_offset = {0, 3 & mask, 2 & mask, 5 & mask},
});
av_refstruct_unref(&matrix);

View File

@@ -1 +1 @@
eae3a49ac3af42c13ad274883611ac21
0f38d0a1cb1f9367352c92b23bcb954e