[FFmpeg-devel] [PATCH] Added more tests to libswscale/utils.c

Petru Rares Sincraian psincraian at outlook.com
Sun Mar 27 18:39:39 CEST 2016


	- Added test for: swscale_license()
	- Added test for: alphaless_fmt()
	- Added test for: alloc_gamma_tbl()
---
 libswscale/Makefile       |   1 +
 libswscale/utils.c        | 158 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/Makefile            |   1 +
 tests/fate/libswscale.mak |   6 ++
 tests/ref/fate/utils      | 143 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 309 insertions(+)
 create mode 100644 tests/fate/libswscale.mak
 create mode 100644 tests/ref/fate/utils

diff --git a/libswscale/Makefile b/libswscale/Makefile
index a9f9e03..a6ae81d 100644
--- a/libswscale/Makefile
+++ b/libswscale/Makefile
@@ -27,3 +27,4 @@ SLIBOBJS-$(HAVE_GNU_WINDRES) += swscaleres.o
 
 TESTPROGS = colorspace                                                  \
             swscale                                                     \
+            utils                                                       \
diff --git a/libswscale/utils.c b/libswscale/utils.c
index ba409d6..da27808 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2410,3 +2410,161 @@ struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW,
     }
     return context;
 }
+
+#ifdef TEST
+
+static void test_swscale_license(void)
+{
+    const char *license = swscale_license();
+    printf("%s\n", license);
+}
+
+static void test_alloc_gamma_tbl(void)
+{
+    uint16_t *tbl = alloc_gamma_tbl(1.);
+    int i;
+
+    // print only 32 elements
+    printf("e = 1.0\n");
+    for (i = 0; i < 65536; i += 2048)
+        printf("it: %d\t value: %d\n", i, tbl[i]);
+
+    tbl = alloc_gamma_tbl(0.75);
+    printf("\ne = 0.75\n");
+    for (i = 0; i < 65536; i += 2048)
+        printf("it: %d\t value: %d\n", i, tbl[i]);
+
+    tbl = alloc_gamma_tbl(2.8);
+    printf("\ne = 2.8\n");
+    for (i = 0; i < 65536; i += 2048)
+        printf("it: %d\t value: %d\n", i, tbl[i]);
+
+}
+
+static void test_alphaless_fmt(void)
+{
+    int result;
+
+    result = alphaless_fmt(AV_PIX_FMT_ARGB) == AV_PIX_FMT_RGB24;
+    printf("AV_PIX_FMT_ARGB == AV_PIX_FMT_RGB24 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_RGBA) == AV_PIX_FMT_RGB24;
+    printf("AV_PIX_FMT_RGBA == AV_PIX_FMT_RGB24 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_ABGR) == AV_PIX_FMT_BGR24;
+    printf("AV_PIX_FMT_ABGR == AV_PIX_FMT_BGR24 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_BGRA) == AV_PIX_FMT_BGR24;
+    printf("AV_PIX_FMT_BGRA == AV_PIX_FMT_BGR24 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YA8) == AV_PIX_FMT_GRAY8;
+    printf("AV_PIX_FMT_YA8 == AV_PIX_FMT_GRAY8 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P) == AV_PIX_FMT_YUV420P;
+    printf("AV_PIX_FMT_YUVA420P == AV_PIX_FMT_YUV420P ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P) == AV_PIX_FMT_YUV422P;
+    printf("AV_PIX_FMT_YUVA422P == AV_PIX_FMT_YUV422P ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P) == AV_PIX_FMT_YUV444P;
+    printf("AV_PIX_FMT_YUVA444P == AV_PIX_FMT_YUV444P ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_GBRAP) == AV_PIX_FMT_GBRP;
+    printf("AV_PIX_FMT_GBRAP == AV_PIX_FMT_GBRP ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_GBRAP12LE) == AV_PIX_FMT_GBRP12;
+    printf("AV_PIX_FMT_GBRAP12LE == AV_PIX_FMT_GBRP12 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_GBRAP12BE) == AV_PIX_FMT_GBRP12;
+    printf("AV_PIX_FMT_GBRAP12BE == AV_PIX_FMT_GBRP12 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_RGBA64LE) == AV_PIX_FMT_RGB48;
+    printf("AV_PIX_FMT_RGBA64LE == AV_PIX_FMT_RGB48 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_RGBA64BE) == AV_PIX_FMT_RGB48;
+    printf("AV_PIX_FMT_RGBA64BE == AV_PIX_FMT_RGB48 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_BGRA64LE) == AV_PIX_FMT_BGR48;
+    printf("AV_PIX_FMT_BGRA64LE == AV_PIX_FMT_BGR48 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_BGRA64BE) == AV_PIX_FMT_BGR48;
+    printf("AV_PIX_FMT_BGRA64BE == AV_PIX_FMT_BGR48 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YA16BE) == AV_PIX_FMT_GRAY16;
+    printf("AV_PIX_FMT_YA16LE == AV_PIX_FMT_GRAY16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YA16LE) == AV_PIX_FMT_GRAY16;
+    printf("AV_PIX_FMT_YA16LE == AV_PIX_FMT_GRAY16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P9BE) == AV_PIX_FMT_YUV420P9;
+    printf("AV_PIX_FMT_YUVA420P9BE == AV_PIX_FMT_YUV420P9 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P9BE) == AV_PIX_FMT_YUV422P9;
+    printf("AV_PIX_FMT_YUVA422P9BE == AV_PIX_FMT_YUV422P9 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P9BE) == AV_PIX_FMT_YUV444P9;
+    printf("AV_PIX_FMT_YUVA444P9BE == AV_PIX_FMT_YUV444P9 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P9LE) == AV_PIX_FMT_YUV420P9;
+    printf("AV_PIX_FMT_YUVA420P9LE == AV_PIX_FMT_YUV420P9 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P9LE) == AV_PIX_FMT_YUV422P9;
+    printf("AV_PIX_FMT_YUVA422P9LE == AV_PIX_FMT_YUV422P9 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P9LE) == AV_PIX_FMT_YUV444P9;
+    printf("AV_PIX_FMT_YUVA444P9LE == AV_PIX_FMT_YUV444P9 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P10BE) == AV_PIX_FMT_YUV420P10;
+    printf("AV_PIX_FMT_YUVA420P10BE == AV_PIX_FMT_YUV420P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P10BE) == AV_PIX_FMT_YUV422P10;
+    printf("AV_PIX_FMT_YUVA422P10BE == AV_PIX_FMT_YUV422P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P10BE) == AV_PIX_FMT_YUV444P10;
+    printf("AV_PIX_FMT_YUVA444P10BE == AV_PIX_FMT_YUV444P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P10LE) == AV_PIX_FMT_YUV420P10;
+    printf("AV_PIX_FMT_YUVA420P10LE == AV_PIX_FMT_YUV420P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P10LE) == AV_PIX_FMT_YUV422P10;
+    printf("AV_PIX_FMT_YUVA422P10LE == AV_PIX_FMT_YUV422P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P10LE) == AV_PIX_FMT_YUV444P10;
+    printf("AV_PIX_FMT_YUVA444P10LE == AV_PIX_FMT_YUV444P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P10LE) == AV_PIX_FMT_YUV444P10;
+    printf("AV_PIX_FMT_YUVA444P10LE == AV_PIX_FMT_YUV444P10 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P16BE) == AV_PIX_FMT_YUV420P16;
+    printf("AV_PIX_FMT_YUVA420P16BE == AV_PIX_FMT_YUV420P16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P16BE) == AV_PIX_FMT_YUV422P16;
+    printf("AV_PIX_FMT_YUVA422P16BE == AV_PIX_FMT_YUV422P16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P16BE) == AV_PIX_FMT_YUV444P16;
+    printf("AV_PIX_FMT_YUVA444P16BE == AV_PIX_FMT_YUV444P16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA420P16LE) == AV_PIX_FMT_YUV420P16;
+    printf("AV_PIX_FMT_YUVA420P16LE == AV_PIX_FMT_YUV420P16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA422P16LE) == AV_PIX_FMT_YUV422P16;
+    printf("AV_PIX_FMT_YUVA422P16LE == AV_PIX_FMT_YUV422P16 ? %d\n", result);
+
+    result = alphaless_fmt(AV_PIX_FMT_YUVA444P16LE) == AV_PIX_FMT_YUV444P16;
+    printf("AV_PIX_FMT_YUVA444P16LE == AV_PIX_FMT_YUV444P16 ? %d\n", result);
+
+}
+
+int main(void)
+{
+    printf("Testing swscale_license()\n");
+    test_swscale_license();
+
+    printf("\nTesting alloc_gamma_tbl()\n");
+    test_alloc_gamma_tbl();
+
+    printf("\nTesting alphaless_fmt()\n");
+    test_alphaless_fmt();
+}
+
+#endif
diff --git a/tests/Makefile b/tests/Makefile
index 6fef0cd..4e82a69 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -140,6 +140,7 @@ include $(SRC_PATH)/tests/fate/libavformat.mak
 include $(SRC_PATH)/tests/fate/libavresample.mak
 include $(SRC_PATH)/tests/fate/libavutil.mak
 include $(SRC_PATH)/tests/fate/libswresample.mak
+include $(SRC_PATH)/tests/fate/libswscale.mak
 include $(SRC_PATH)/tests/fate/lossless-audio.mak
 include $(SRC_PATH)/tests/fate/lossless-video.mak
 include $(SRC_PATH)/tests/fate/microsoft.mak
diff --git a/tests/fate/libswscale.mak b/tests/fate/libswscale.mak
new file mode 100644
index 0000000..2bd7139
--- /dev/null
+++ b/tests/fate/libswscale.mak
@@ -0,0 +1,6 @@
+FATE_LIBAVSWSCALE += fate-utils
+fate-utils: libswscale/utils-test$(EXESUF)
+fate-utils: CMD = run libswscale/utils-test
+
+FATE-$(CONFIG_SWSCALE) += $(FATE_LIBAVSWSCALE)
+fate-libavswscale: $(FATE_LIBAVSWSCALE)
diff --git a/tests/ref/fate/utils b/tests/ref/fate/utils
new file mode 100644
index 0000000..d3268aa
--- /dev/null
+++ b/tests/ref/fate/utils
@@ -0,0 +1,143 @@
+Testing swscale_license()
+LGPL version 2.1 or later
+
+Testing alloc_gamma_tbl()
+e = 1.0
+it: 0	 value: 0
+it: 2048	 value: 2048
+it: 4096	 value: 4096
+it: 6144	 value: 6144
+it: 8192	 value: 8192
+it: 10240	 value: 10240
+it: 12288	 value: 12288
+it: 14336	 value: 14336
+it: 16384	 value: 16384
+it: 18432	 value: 18432
+it: 20480	 value: 20480
+it: 22528	 value: 22528
+it: 24576	 value: 24576
+it: 26624	 value: 26624
+it: 28672	 value: 28672
+it: 30720	 value: 30720
+it: 32768	 value: 32768
+it: 34816	 value: 34816
+it: 36864	 value: 36864
+it: 38912	 value: 38912
+it: 40960	 value: 40960
+it: 43008	 value: 43008
+it: 45056	 value: 45056
+it: 47104	 value: 47104
+it: 49152	 value: 49152
+it: 51200	 value: 51200
+it: 53248	 value: 53248
+it: 55296	 value: 55296
+it: 57344	 value: 57344
+it: 59392	 value: 59392
+it: 61440	 value: 61440
+it: 63488	 value: 63488
+
+e = 0.75
+it: 0	 value: 0
+it: 2048	 value: 4870
+it: 4096	 value: 8191
+it: 6144	 value: 11103
+it: 8192	 value: 13777
+it: 10240	 value: 16287
+it: 12288	 value: 18673
+it: 14336	 value: 20962
+it: 16384	 value: 23170
+it: 18432	 value: 25310
+it: 20480	 value: 27391
+it: 22528	 value: 29421
+it: 24576	 value: 31405
+it: 26624	 value: 33348
+it: 28672	 value: 35254
+it: 30720	 value: 37126
+it: 32768	 value: 38967
+it: 34816	 value: 40780
+it: 36864	 value: 42566
+it: 38912	 value: 44328
+it: 40960	 value: 46066
+it: 43008	 value: 47783
+it: 45056	 value: 49480
+it: 47104	 value: 51157
+it: 49152	 value: 52817
+it: 51200	 value: 54459
+it: 53248	 value: 56084
+it: 55296	 value: 57695
+it: 57344	 value: 59290
+it: 59392	 value: 60871
+it: 61440	 value: 62439
+it: 63488	 value: 63993
+
+e = 2.8
+it: 0	 value: 0
+it: 2048	 value: 4
+it: 4096	 value: 27
+it: 6144	 value: 86
+it: 8192	 value: 194
+it: 10240	 value: 362
+it: 12288	 value: 603
+it: 14336	 value: 929
+it: 16384	 value: 1351
+it: 18432	 value: 1879
+it: 20480	 value: 2523
+it: 22528	 value: 3295
+it: 24576	 value: 4205
+it: 26624	 value: 5261
+it: 28672	 value: 6474
+it: 30720	 value: 7854
+it: 32768	 value: 9410
+it: 34816	 value: 11151
+it: 36864	 value: 13086
+it: 38912	 value: 15225
+it: 40960	 value: 17577
+it: 43008	 value: 20150
+it: 45056	 value: 22953
+it: 47104	 value: 25996
+it: 49152	 value: 29286
+it: 51200	 value: 32832
+it: 53248	 value: 36643
+it: 55296	 value: 40727
+it: 57344	 value: 45093
+it: 59392	 value: 49749
+it: 61440	 value: 54703
+it: 63488	 value: 59963
+
+Testing alphaless_fmt()
+AV_PIX_FMT_ARGB == AV_PIX_FMT_RGB24 ? 1
+AV_PIX_FMT_RGBA == AV_PIX_FMT_RGB24 ? 1
+AV_PIX_FMT_ABGR == AV_PIX_FMT_BGR24 ? 1
+AV_PIX_FMT_BGRA == AV_PIX_FMT_BGR24 ? 1
+AV_PIX_FMT_YA8 == AV_PIX_FMT_GRAY8 ? 1
+AV_PIX_FMT_YUVA420P == AV_PIX_FMT_YUV420P ? 1
+AV_PIX_FMT_YUVA422P == AV_PIX_FMT_YUV422P ? 1
+AV_PIX_FMT_YUVA444P == AV_PIX_FMT_YUV444P ? 1
+AV_PIX_FMT_GBRAP == AV_PIX_FMT_GBRP ? 1
+AV_PIX_FMT_GBRAP12LE == AV_PIX_FMT_GBRP12 ? 1
+AV_PIX_FMT_GBRAP12BE == AV_PIX_FMT_GBRP12 ? 1
+AV_PIX_FMT_RGBA64LE == AV_PIX_FMT_RGB48 ? 1
+AV_PIX_FMT_RGBA64BE == AV_PIX_FMT_RGB48 ? 1
+AV_PIX_FMT_BGRA64LE == AV_PIX_FMT_BGR48 ? 1
+AV_PIX_FMT_BGRA64BE == AV_PIX_FMT_BGR48 ? 1
+AV_PIX_FMT_YA16LE == AV_PIX_FMT_GRAY16 ? 1
+AV_PIX_FMT_YA16LE == AV_PIX_FMT_GRAY16 ? 1
+AV_PIX_FMT_YUVA420P9BE == AV_PIX_FMT_YUV420P9 ? 1
+AV_PIX_FMT_YUVA422P9BE == AV_PIX_FMT_YUV422P9 ? 1
+AV_PIX_FMT_YUVA444P9BE == AV_PIX_FMT_YUV444P9 ? 1
+AV_PIX_FMT_YUVA420P9LE == AV_PIX_FMT_YUV420P9 ? 1
+AV_PIX_FMT_YUVA422P9LE == AV_PIX_FMT_YUV422P9 ? 1
+AV_PIX_FMT_YUVA444P9LE == AV_PIX_FMT_YUV444P9 ? 1
+AV_PIX_FMT_YUVA420P10BE == AV_PIX_FMT_YUV420P10 ? 1
+AV_PIX_FMT_YUVA422P10BE == AV_PIX_FMT_YUV422P10 ? 1
+AV_PIX_FMT_YUVA444P10BE == AV_PIX_FMT_YUV444P10 ? 1
+AV_PIX_FMT_YUVA420P10LE == AV_PIX_FMT_YUV420P10 ? 1
+AV_PIX_FMT_YUVA422P10LE == AV_PIX_FMT_YUV422P10 ? 1
+AV_PIX_FMT_YUVA444P10LE == AV_PIX_FMT_YUV444P10 ? 1
+AV_PIX_FMT_YUVA444P10LE == AV_PIX_FMT_YUV444P10 ? 1
+AV_PIX_FMT_YUVA420P16BE == AV_PIX_FMT_YUV420P16 ? 1
+AV_PIX_FMT_YUVA422P16BE == AV_PIX_FMT_YUV422P16 ? 1
+AV_PIX_FMT_YUVA444P16BE == AV_PIX_FMT_YUV444P16 ? 1
+AV_PIX_FMT_YUVA420P16LE == AV_PIX_FMT_YUV420P16 ? 1
+AV_PIX_FMT_YUVA422P16LE == AV_PIX_FMT_YUV422P16 ? 1
+AV_PIX_FMT_YUVA444P16LE == AV_PIX_FMT_YUV444P16 ? 1
-- 
1.9.1



More information about the ffmpeg-devel mailing list