Commit 7b60f3469e for ffmpeg
commit 7b60f3469e1ff909f059068bee23c640a1165a7b
Author: Niklas Haas <git@haasn.dev>
Date: Fri Jul 17 12:45:38 2026 +0200
swscale/ops: lift the SWS_OP_LINEAR float-only restriction
The reference backend does not need any change, it's already written to
handle integer linear ops as a result of the previous commits.
The x86 and aarch64 implementations will be updated in a future commit.
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com>
diff --git a/libswscale/ops.c b/libswscale/ops.c
index 0df8ec5acb..c07261c61e 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -244,7 +244,6 @@ void ff_sws_apply_op_q(const SwsOp *op, AVRational64 x[4])
x[i] = av_max_q64(x[i], op->clamp.limit[i]);
return;
case SWS_OP_LINEAR: {
- av_assert1(!ff_sws_pixel_type_is_int(op->type));
const AVRational64 orig[4] = { x[0], x[1], x[2], x[3] };
for (int i = 0; i < 4; i++) {
AVRational64 sum = op->lin.m[i][4];
diff --git a/libswscale/ops.h b/libswscale/ops.h
index 465f5d4d49..1bebae6455 100644
--- a/libswscale/ops.h
+++ b/libswscale/ops.h
@@ -54,9 +54,9 @@ typedef enum SwsOpType {
SWS_OP_MIN, /* numeric minimum */
SWS_OP_MAX, /* numeric maximum */
SWS_OP_SCALE, /* multiplication by scalar */
+ SWS_OP_LINEAR, /* generalized linear affine transform */
/* Floating-point only arithmetic operations. */
- SWS_OP_LINEAR, /* generalized linear affine transform */
SWS_OP_DITHER, /* add dithering noise */
/* Filtering operations. */
@@ -195,6 +195,11 @@ typedef struct SwsLinearOp {
* [ Out.y ] = [ F G H I J ] * [ x y z w 1 ]
* [ Out.z ] = [ K L M N O ]
* [ Out.w ] = [ P Q R S T ]
+ *
+ * Note: For integer types, these entries may exceed the value range of
+ * the pixel type itself. It's implied that implementations will perform
+ * all intermediate calculations modulo 2^N where N is the bit depth of
+ * the pixel type, including the final result.
*/
AVRational64 m[4][5];
} SwsLinearOp;
diff --git a/libswscale/uops.c b/libswscale/uops.c
index bd9c729402..316572d472 100644
--- a/libswscale/uops.c
+++ b/libswscale/uops.c
@@ -538,7 +538,7 @@ static int translate_linear_op(SwsContext *ctx, SwsUOpList *ops,
}
}
- if (flags & SWS_UOP_FLAG_FMA) {
+ if ((flags & SWS_UOP_FLAG_FMA) && !ff_sws_pixel_type_is_int(op->type)) {
/* multiplication by 1 and 0 are always exact by definition */
uop.uop = SWS_UOP_LINEAR_FMA;
uop.par.lin.exact = exact | uop.par.lin.zero | uop.par.lin.one;