Commit cb2b7fde78 for ffmpeg
commit cb2b7fde781cc377ed4b85c963426644249b28f4
Author: Niklas Haas <git@haasn.dev>
Date: Thu Oct 8 13:57:39 2026 +0200
swscale/ops: add helper functions to determine op input/output types
Only works for homogeneous ops, which is the current assumption anyways.
Likely will be deleted again once the ops are fully migrated to a per-lane
type accounting, though that will require some changes to the vulkan backend
which I'm not willing to do right now.
Signed-off-by: Niklas Haas <git@haasn.dev>
diff --git a/libswscale/ops.c b/libswscale/ops.c
index caf933bd58..85fd0b074e 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -168,6 +168,26 @@ const SwsOp *ff_sws_op_next(const SwsOp *op)
return idx < ops->num_ops - 1 ? &ops->ops[idx + 1] : NULL;
}
+SwsPixelType ff_sws_op_output_type(const SwsOp *op)
+{
+ SwsPixelType type = SWS_PIXEL_NONE;
+ for (int i = 0; op && i < 4; i++) {
+ if (!SWS_OP_NEEDED(op, i) || !op->outputs[i].type)
+ continue;
+ else if (!type)
+ type = op->outputs[i].type;
+ else if (op->outputs[i].type != type)
+ return SWS_PIXEL_NONE;
+ }
+
+ return type;
+}
+
+SwsPixelType ff_sws_op_input_type(const SwsOp *op)
+{
+ return ff_sws_op_output_type(ff_sws_op_prev(op));
+}
+
/* biased towards `a` */
static AVRational64 av_min_q64(AVRational64 a, AVRational64 b)
{
diff --git a/libswscale/ops.h b/libswscale/ops.h
index bfb5085ae5..8dcabb2ead 100644
--- a/libswscale/ops.h
+++ b/libswscale/ops.h
@@ -291,6 +291,13 @@ SwsCompMask ff_sws_comp_mask_needed(const SwsOp *op);
*/
int ff_sws_rw_op_planes(const SwsOp *op);
+/**
+ * Return the input/output type of an operation, if all inputs/outputs are
+ * the same type, or SWS_PIXEL_NONE if no type can be established.
+ */
+SwsPixelType ff_sws_op_input_type(const SwsOp *op);
+SwsPixelType ff_sws_op_output_type(const SwsOp *op);
+
/**
* Describe an operation in human-readable form.
*/