Commit e678f9a5f9 for ffmpeg

commit e678f9a5f96ea127ae71e83698519fe899f93336
Author: Ramiro Polla <ramiro.polla@gmail.com>
Date:   Thu Sep 24 21:30:36 2026 +0200

    swscale/uops: gate SWS_UOP_{EXPAND_BIT,READ_PALETTE,ADD} behind flags in ff_sws_ops_translate()

    The aarch64 backend doesn't implement them. These flags will be needed
    to convert the aarch64 backend to uops using ff_sws_ops_translate().

diff --git a/libswscale/tests/sws_ops.c b/libswscale/tests/sws_ops.c
index 677dc4db6e..b2ca5ec41e 100644
--- a/libswscale/tests/sws_ops.c
+++ b/libswscale/tests/sws_ops.c
@@ -39,7 +39,10 @@ static int print_ops(SwsContext *ctx, const SwsOpList *ops, SwsCompiledOp *out)
     if (!uops)
         return AVERROR(ENOMEM);

-    int ret = ff_sws_ops_translate(ctx, ops, 0, uops);
+    const SwsUOpFlags flags = SWS_UOP_FLAG_EXPAND_BIT
+                            | SWS_UOP_FLAG_READ_PALETTE
+                            | SWS_UOP_FLAG_ADD;
+    int ret = ff_sws_ops_translate(ctx, ops, flags, uops);
     if (ret == AVERROR(ENOTSUP))
         goto fail;

diff --git a/libswscale/uops.c b/libswscale/uops.c
index 95ce6c719d..127a19fab0 100644
--- a/libswscale/uops.c
+++ b/libswscale/uops.c
@@ -328,7 +328,7 @@ static int translate_rw_op(SwsContext *ctx, SwsUOpList *ops, SwsUOpFlags flags,
             return AVERROR(ENOTSUP);
         uop.uop = is_read ? SWS_UOP_READ_PACKED : SWS_UOP_WRITE_PACKED;
     } else if (op->rw.mode == SWS_RW_PALETTE) {
-        if (op->rw.frac || !is_read)
+        if (!(flags & SWS_UOP_FLAG_READ_PALETTE) || op->rw.frac || !is_read)
             return AVERROR(ENOTSUP);
         uop.uop = SWS_UOP_READ_PALETTE;
     } else if (op->rw.frac == 3) {
@@ -455,7 +455,7 @@ static int translate_swizzle(SwsUOpList *ops, const SwsOp *op)
     return ff_sws_uop_list_append(ops, &uop);
 }

-static int translate_dither_op(SwsUOpList *ops, const SwsOp *op)
+static int translate_dither_op(SwsUOpList *ops, SwsUOpFlags flags, const SwsOp *op)
 {
     SwsUOp uop = {
         .type = op->type,
@@ -463,7 +463,7 @@ static int translate_dither_op(SwsUOpList *ops, const SwsOp *op)
         .par.dither.size_log2 = op->dither.size_log2,
     };

-    if (op->dither.size_log2 == 0) {
+    if ((flags & SWS_UOP_FLAG_ADD) && op->dither.size_log2 == 0) {
         /* Constant offset */
         const SwsPixel val = Q2PIXEL(op->dither.matrix[0]);
         uop.uop = SWS_UOP_ADD;
@@ -578,7 +578,7 @@ static int translate_op(SwsContext *ctx, SwsUOpList *uops, SwsUOpFlags flags,
     case SWS_OP_SWIZZLE:
         return translate_swizzle(uops, op);
     case SWS_OP_DITHER:
-        return translate_dither_op(uops, op);
+        return translate_dither_op(uops, flags, op);
     case SWS_OP_LINEAR:
         return translate_linear_op(ctx, uops, flags, op, input);
     default:
@@ -641,7 +641,7 @@ static int translate_op(SwsContext *ctx, SwsUOpList *uops, SwsUOpFlags flags,
         }
         break;
     case SWS_OP_SCALE:
-        if (is_expand_bit(op->type, op->scale.factor)) {
+        if ((flags & SWS_UOP_FLAG_EXPAND_BIT) && is_expand_bit(op->type, op->scale.factor)) {
             uop.uop = SWS_UOP_EXPAND_BIT;
         } else {
             uop.uop = SWS_UOP_SCALE;
diff --git a/libswscale/uops.h b/libswscale/uops.h
index feb8744865..f044da4547 100644
--- a/libswscale/uops.h
+++ b/libswscale/uops.h
@@ -121,9 +121,12 @@ static inline char *ff_sws_comp_mask_print(SwsCompMask mask, char buf[5])

 typedef uint32_t SwsUOpFlags;
 typedef enum SwsUOpFlagBits {
-    SWS_UOP_FLAG_NONE   = 0,
-    SWS_UOP_FLAG_FMA    = (1 << 0), /* platform supports FMA ops */
-    SWS_UOP_FLAG_PSHUFB = (1 << 1), /* platform supports pshufb equivalent */
+    SWS_UOP_FLAG_NONE         = 0,
+    SWS_UOP_FLAG_FMA          = (1 << 0), /* platform supports FMA ops */
+    SWS_UOP_FLAG_PSHUFB       = (1 << 1), /* platform supports pshufb equivalent */
+    SWS_UOP_FLAG_EXPAND_BIT   = (1 << 2), /* backend implements SWS_UOP_EXPAND_BIT */
+    SWS_UOP_FLAG_READ_PALETTE = (1 << 3), /* backend implements SWS_UOP_READ_PALETTE */
+    SWS_UOP_FLAG_ADD          = (1 << 4), /* backend implements SWS_UOP_ADD */
 } SwsUOpFlagBits;

 typedef enum SwsUOpType {
diff --git a/libswscale/uops_backend.c b/libswscale/uops_backend.c
index 5208155706..5dfb829b4e 100644
--- a/libswscale/uops_backend.c
+++ b/libswscale/uops_backend.c
@@ -185,7 +185,10 @@ static int compile_c(SwsContext *ctx, const SwsOpList *ops, SwsCompiledOp *out)
     if (!uops)
         return AVERROR(ENOMEM);

-    int ret = ff_sws_ops_translate(ctx, ops, 0, uops);
+    const SwsUOpFlags flags = SWS_UOP_FLAG_EXPAND_BIT
+                            | SWS_UOP_FLAG_READ_PALETTE
+                            | SWS_UOP_FLAG_ADD;
+    int ret = ff_sws_ops_translate(ctx, ops, flags, uops);
     if (ret < 0)
         goto fail;

diff --git a/libswscale/uops_macros_gen.c b/libswscale/uops_macros_gen.c
index 1fe7230a0e..5cdf35e802 100644
--- a/libswscale/uops_macros_gen.c
+++ b/libswscale/uops_macros_gen.c
@@ -242,7 +242,8 @@ fail:
 }

 static const SwsUOpFlags uop_flags[] = {
-    0,
+    SWS_UOP_FLAG_EXPAND_BIT | SWS_UOP_FLAG_READ_PALETTE | SWS_UOP_FLAG_ADD,
+    SWS_UOP_FLAG_EXPAND_BIT | SWS_UOP_FLAG_READ_PALETTE | SWS_UOP_FLAG_ADD |
     SWS_UOP_FLAG_PSHUFB | SWS_UOP_FLAG_FMA, /* x86 backend */
 };

diff --git a/libswscale/x86/ops.c b/libswscale/x86/ops.c
index b3eb00af65..00994e4d64 100644
--- a/libswscale/x86/ops.c
+++ b/libswscale/x86/ops.c
@@ -683,7 +683,10 @@ static int compile_x86(SwsContext *ctx, const SwsOpList *ops, SwsCompiledOp *out
     if (mmsize < 0)
         return mmsize;

-    SwsUOpFlags flags = SWS_UOP_FLAG_PSHUFB;
+    SwsUOpFlags flags = SWS_UOP_FLAG_PSHUFB
+                      | SWS_UOP_FLAG_EXPAND_BIT
+                      | SWS_UOP_FLAG_READ_PALETTE
+                      | SWS_UOP_FLAG_ADD;
     if (EXTERNAL_FMA3(cpu_flags))
         flags |= SWS_UOP_FLAG_FMA;