Browse Source

swscale: add sws_is_noop()

Exactly what it says on the tin.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
Niklas Haas 4 months ago
parent
commit
b03c758600
4 changed files with 24 additions and 1 deletions
  1. 3 0
      doc/APIchanges
  2. 6 0
      libswscale/swscale.h
  3. 14 0
      libswscale/utils.c
  4. 1 1
      libswscale/version.h

+ 3 - 0
doc/APIchanges

@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-10-23 - xxxxxxxxxx - lsws 8.9.100 - swscale.h
+  Add sws_is_noop().
+
 2024-10-23 - xxxxxxxxxx - lsws 8.8.100 - swscale.h
   Add frame property testing API:
     - sws_test_format()

+ 6 - 0
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

+ 14 - 0
libswscale/utils.c

@@ -2777,3 +2777,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;
+}

+ 1 - 1
libswscale/version.h

@@ -28,7 +28,7 @@
 
 #include "version_major.h"
 
-#define LIBSWSCALE_VERSION_MINOR   8
+#define LIBSWSCALE_VERSION_MINOR   9
 #define LIBSWSCALE_VERSION_MICRO 100
 
 #define LIBSWSCALE_VERSION_INT  AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \