Commit 7c15cb8b34 for ffmpeg
commit 7c15cb8b343017aa4f3264af841ff080f6dd4ac0
Author: Niklas Haas <git@haasn.dev>
Date: Thu Oct 8 02:22:39 2026 +0200
swscale/ops: nuke SWS_COMP_GARBAGE
Output pad neededness is redundant with `outputs[i].dep_out`.
Output pad liveness is redundant with `outputs[i].type != SWS_PIXEL_NONE`.
This covers both previous usages of this flag cleanly.
As an aside, two checks gets more strict in a good way - the redundant
clear-to-zero also checks that there isn't an implicit type change, and
the write type assertion also verifies that the type matches.
Signed-off-by: Niklas Haas <git@haasn.dev>
diff --git a/libswscale/ops.c b/libswscale/ops.c
index 4442ae7c81..a06fcc2f25 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -322,7 +322,7 @@ enum {
/* merge_comp_flags() forms a monoid with SWS_COMP_IDENTITY as the null element */
static SwsCompFlags merge_comp_flags(SwsCompFlags a, SwsCompFlags b)
{
- const SwsCompFlags flags_or = SWS_COMP_GARBAGE | SWS_COMP_SWAPPED;
+ const SwsCompFlags flags_or = SWS_COMP_SWAPPED;
const SwsCompFlags flags_and = SWS_COMP_IDENTITY;
return ((a & b) & flags_and) | ((a | b) & flags_or);
}
@@ -349,12 +349,7 @@ static void apply_filter_weights(SwsOpPad outputs[4], const SwsOpPad inputs[4],
/* Infer + propagate known information about components */
void ff_sws_op_list_update_comps(SwsOpList *ops)
{
- SwsOpPad prev[4] = {
- { .flags = SWS_COMP_GARBAGE },
- { .flags = SWS_COMP_GARBAGE },
- { .flags = SWS_COMP_GARBAGE },
- { .flags = SWS_COMP_GARBAGE },
- };
+ SwsOpPad prev[4] = {0};
/* Forwards pass, propagates knowledge about the incoming pixel values */
for (int n = 0; n < ops->num_ops; n++) {
@@ -406,7 +401,7 @@ void ff_sws_op_list_update_comps(SwsOpList *ops)
#define RESET(I) do { \
SwsOpPad *dst = &op->outputs[I]; \
dst->type = SWS_PIXEL_NONE; \
- dst->flags = SWS_COMP_GARBAGE; \
+ dst->flags = 0; \
dst->min = dst->max = (AVRational64) {0}; \
dst->dep_in = SWS_COMP_NONE; \
} while (0)
@@ -425,7 +420,6 @@ void ff_sws_op_list_update_comps(SwsOpList *ops)
const SwsOpPad *src = &ops->inputs[idx];
SwsOpPad *dst = &op->outputs[i];
- av_assert0(!(src->flags & SWS_COMP_GARBAGE));
dst->type = op->rw.type;
dst->flags = src->flags & SWS_COMP_DIRTY;
dst->min = src->min;
@@ -459,7 +453,7 @@ void ff_sws_op_list_update_comps(SwsOpList *ops)
break;
case SWS_OP_WRITE:
for (int i = 0; i < op->rw.elems; i++)
- av_assert1(!(prev[i].flags & SWS_COMP_GARBAGE));
+ av_assert1(prev[i].type == op->rw.type);
for (int i = 0; i < 4; i++)
FORWARD(i, i, flags);
break;
@@ -595,10 +589,9 @@ void ff_sws_op_list_update_comps(SwsOpList *ops)
}
case SWS_OP_LUT_3D:
for (int i = 0; i < 3; i++) {
- /* 3x3 dependency matrix; strip all information except
- * SWS_COMP_GARBAGE (for correctness validation) */
+ /* 3x3 dependency matrix; strip all information */
for (int j = 0; j < 3; j++)
- FORWARD(i, j, flags & SWS_COMP_GARBAGE);
+ FORWARD(i, j, flags & 0);
/* LUT output domain is always scaled to full 16-bit range */
op->outputs[i].min = Q(0);
op->outputs[i].max = Q(UINT16_MAX);
@@ -879,9 +872,7 @@ uint32_t ff_sws_linear_mask(const SwsLinearOp *c)
static const char *describe_comp_flags(SwsCompFlags flags)
{
- if (flags & SWS_COMP_GARBAGE)
- return "garbage";
- else if (flags & SWS_COMP_ZERO)
+ if (flags & SWS_COMP_ZERO)
return "zero";
else if (flags & SWS_COMP_SWAPPED)
return "swapped";
diff --git a/libswscale/ops.h b/libswscale/ops.h
index 613ff5e538..0aca2048f0 100644
--- a/libswscale/ops.h
+++ b/libswscale/ops.h
@@ -227,12 +227,11 @@ typedef struct SwsLut3dOp {
} SwsLut3dOp;
typedef enum SwsCompFlags {
- SWS_COMP_GARBAGE = 1 << 0, /* contents are undefined / garbage data */
- SWS_COMP_EXACT = 1 << 1, /* value is an exact integer */
- SWS_COMP_ZERO = 1 << 2, /* known to be a constant zero */
- SWS_COMP_SWAPPED = 1 << 3, /* byte order is swapped */
- SWS_COMP_COPY = 1 << 4, /* value is unmodified from the source plane */
- SWS_COMP_CONST = 1 << 5, /* value is a fixed constant */
+ SWS_COMP_EXACT = 1 << 0, /* value is an exact integer */
+ SWS_COMP_ZERO = 1 << 1, /* known to be a constant zero */
+ SWS_COMP_SWAPPED = 1 << 2, /* byte order is swapped */
+ SWS_COMP_COPY = 1 << 3, /* value is unmodified from the source plane */
+ SWS_COMP_CONST = 1 << 4, /* value is a fixed constant */
} SwsCompFlags;
typedef struct SwsOpPad {
@@ -280,7 +279,7 @@ struct SwsOp {
SwsOpList *ops;
};
-#define SWS_OP_NEEDED(op, idx) (!((op)->outputs[idx].flags & SWS_COMP_GARBAGE))
+#define SWS_OP_NEEDED(op, idx) ((op)->outputs[idx].dep_out != 0)
/* Compute SwsCompMask from a mask of needed components */
SwsCompMask ff_sws_comp_mask_needed(const SwsOp *op);
diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c
index 7d6b6de770..e910fb4e3d 100644
--- a/libswscale/ops_optimizer.c
+++ b/libswscale/ops_optimizer.c
@@ -250,8 +250,7 @@ static bool extract_scalar(const SwsLinearOp *c,
for (int i = 0; i < 4; i++) {
const AVRational64 s = c->m[i][i];
- if ((inputs[i].flags & SWS_COMP_ZERO) ||
- (outputs[i].flags & SWS_COMP_GARBAGE))
+ if ((inputs[i].flags & SWS_COMP_ZERO) || !outputs[i].dep_out)
continue;
if (scale.factor.den && ff_cmp_q64(s, scale.factor))
return false;
@@ -468,7 +467,7 @@ retry:
continue;
if ((prev->outputs[i].flags & SWS_COMP_ZERO) &&
- !(prev->outputs[i].flags & SWS_COMP_GARBAGE) &&
+ prev->outputs[i].type == op->clear.type[i] &&
op->clear.value[i].num == 0)
{
/* Redundant clear-to-zero of zero component */