diff mbox series

[FFmpeg-devel,v3,07/18] swscale: add sws_is_noop()

Message ID 20241020200851.1414766-8-ffmpeg@haasn.xyz
State New
Headers show
Series major refactor and new scaling API | expand

Commit Message

Niklas Haas Oct. 20, 2024, 8:05 p.m. UTC
From: Niklas Haas <git@haasn.dev>

Exactly what it says on the tin.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
---
 libswscale/swscale.h |  6 ++++++
 libswscale/utils.c   | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

Comments

Michael Niedermayer Oct. 23, 2024, 6:06 p.m. UTC | #1
On Sun, Oct 20, 2024 at 10:05:16PM +0200, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
> 
> Exactly what it says on the tin.
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Niklas Haas <git@haasn.dev>
> ---
>  libswscale/swscale.h |  6 ++++++
>  libswscale/utils.c   | 14 ++++++++++++++
>  2 files changed, 20 insertions(+)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libswscale/swscale.h b/libswscale/swscale.h
index ba944cdc6f..f544387769 100644
--- a/libswscale/swscale.h
+++ b/libswscale/swscale.h
@@ -140,6 +140,12 @@  int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output);
  */
 int sws_test_frame(const AVFrame *frame, int output);
 
+/**
+ * Check if a given conversion is a noop. Returns a positive integer if
+ * no operation needs to be performed, 0 otherwise.
+ */
+int sws_is_noop(const AVFrame *dst, const AVFrame *src);
+
 /* values for the flags, the stuff on the command line is different */
 #define SWS_FAST_BILINEAR     1
 #define SWS_BILINEAR          2
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 5339bbe099..5dff3c5476 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2785,3 +2785,17 @@  int sws_test_frame(const AVFrame *frame, int output)
 
     return 1;
 }
+
+int sws_is_noop(const AVFrame *dst, const AVFrame *src)
+{
+    for (int field = 0; field < 2; field++) {
+        SwsFormat dst_fmt = ff_fmt_from_frame(dst, field);
+        SwsFormat src_fmt = ff_fmt_from_frame(src, field);
+        if (!ff_fmt_equal(&dst_fmt, &src_fmt))
+            return 0;
+        if (!dst_fmt.interlaced)
+            break;
+    }
+
+    return 1;
+}