[FFmpeg-devel] [PATCH] Add test foravpriv_get_trc_function_from_trc function

NagaChaitanya Vellanki nagachaitanya.vellanki at gmail.com
Thu Mar 3 01:35:08 CET 2016


---
 libavutil/Makefile         |  1 +
 libavutil/color_utils.c    | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak   |  4 +++
 tests/ref/fate/color_utils | 38 +++++++++++++++++++++++++++
 4 files changed, 108 insertions(+)
 create mode 100644 tests/ref/fate/color_utils

diff --git a/libavutil/Makefile b/libavutil/Makefile
index a4d79cd..934564f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -176,6 +176,7 @@ TESTPROGS = adler32                                                     \
             bprint                                                      \
             cast5                                                       \
             camellia                                                    \
+            color_utils                                                 \
             cpu                                                         \
             crc                                                         \
             des                                                         \
diff --git a/libavutil/color_utils.c b/libavutil/color_utils.c
index b68b402..e53f408 100644
--- a/libavutil/color_utils.c
+++ b/libavutil/color_utils.c
@@ -21,6 +21,7 @@
 #include <stddef.h>
 #include <math.h>
 
+#include "common.h"
 #include "libavutil/color_utils.h"
 #include "libavutil/pixfmt.h"
 
@@ -216,3 +217,67 @@ avpriv_trc_function avpriv_get_trc_function_from_trc(enum AVColorTransferCharact
     }
     return func;
 }
+
+#ifdef TEST
+// LCOV_EXCL_START
+
+int main(int argc, char *argv[])
+{
+  int i;
+  struct test {
+      enum AVColorTransferCharacteristic trc;
+      const char* func_name;
+      double arg;
+      double result;
+  }   tests[] = {
+      { AVCOL_TRC_BT709, "avpriv_trc_bt709",  -0.01, 0.0 },
+      { AVCOL_TRC_SMPTE170M, "avpriv_trc_bt709", 0.005, 0.022500 },
+      { AVCOL_TRC_BT2020_10, "avpriv_trc_bt709", 0.015, 0.067500 },
+      { AVCOL_TRC_BT2020_12, "avpriv_trc_bt709", 1.0, 1.0 },
+      { AVCOL_TRC_BT2020_12, "avpriv_trc_bt709", 15123.4567, 83.452916 },
+      { AVCOL_TRC_GAMMA22, "avpriv_trc_gamma22", -0.01, 0.0 },
+      { AVCOL_TRC_GAMMA22, "avpriv_trc_gamma22", 1.0, 1.0 },
+      { AVCOL_TRC_GAMMA22, "avpriv_trc_gamma22", 125.098765, 8.980424 },
+      { AVCOL_TRC_GAMMA28, "avpriv_trc_gamma28", -0.01, 0.0 },
+      { AVCOL_TRC_GAMMA28, "avpriv_trc_gamma28", 1.0, 1.0 },
+      { AVCOL_TRC_GAMMA28, "avpriv_trc_gamma28", 99999.899998, 61.054001 },
+      { AVCOL_TRC_SMPTE240M, "avpriv_trc_smpte240M", -0.01, 0.0 },
+      { AVCOL_TRC_SMPTE240M, "avpriv_trc_smpte240M", 0.015, 0.060000 },
+      { AVCOL_TRC_LINEAR, "avpriv_trc_linear", 0.0, 0.0 },
+      { AVCOL_TRC_LINEAR, "avpriv_trc_linear", 0.1, 0.1 },
+      { AVCOL_TRC_LINEAR, "avpriv_trc_linear", -0.1, -0.1 },
+      { AVCOL_TRC_LOG, "avpriv_trc_log", 0.009, 0.0 },
+      { AVCOL_TRC_LOG, "avpriv_trc_log", 1.0, 1.0 },
+      { AVCOL_TRC_LOG, "avpriv_trc_log", 98678.4231, 3.497111 },
+      { AVCOL_TRC_LOG_SQRT, "avpriv_trc_log_sqrt", 0.00316227760, 0.0 },
+      { AVCOL_TRC_LOG_SQRT, "avpriv_trc_log_sqrt", 1.0, 1.0 },
+      { AVCOL_TRC_LOG_SQRT, "avpriv_trc_log_sqrt", 19845.88923, 2.719068 },
+      { AVCOL_TRC_IEC61966_2_4, "avpriv_trc_iec61966_2_4", 0.0, 0.0 },
+      { AVCOL_TRC_IEC61966_2_4, "avpriv_trc_iec61966_2_4", -0.018053968510807, -0.081243 },
+      { AVCOL_TRC_IEC61966_2_4, "avpriv_trc_iec61966_2_4", 0.015, 0.067500 },
+      { AVCOL_TRC_IEC61966_2_4, "avpriv_trc_iec61966_2_4", 98245.76983, 193.835711 },
+      { AVCOL_TRC_BT1361_ECG, "avpriv_trc_bt1361", 0.0, 0.0 },
+      { AVCOL_TRC_BT1361_ECG, "avpriv_trc_bt1361", -0.0045, -0.069898 },
+      { AVCOL_TRC_BT1361_ECG, "avpriv_trc_bt1361", 0.015, 0.067500 },
+      { AVCOL_TRC_BT1361_ECG, "avpriv_trc_bt1361", 1999.11123, 33.512490 },
+      { AVCOL_TRC_IEC61966_2_1, "avpriv_trc_iec61966_2_1", 0.0, 0.0 },
+      { AVCOL_TRC_IEC61966_2_1, "avpriv_trc_iec61966_2_1", 0.015, 0.128354 },
+      { AVCOL_TRC_IEC61966_2_1, "avpriv_trc_iec61966_2_1", 6945.443, 42.013863 },
+      { AVCOL_TRC_SMPTEST2084, "avpriv_trc_smpte_st2084", -0.01, 0.0 },
+      { AVCOL_TRC_SMPTEST2084, "avpriv_trc_smpte_st2084", 0.0, 0.000001 },
+      { AVCOL_TRC_SMPTEST428_1, "avpriv_trc_smpte_st428_1", -0.01, 0.0 },
+      { AVCOL_TRC_SMPTEST428_1, "avpriv_trc_smpte_st428_1", 52.37, 4.432321 },
+      { AVCOL_TRC_SMPTEST428_1, "avpriv_trc_smpte_st428_1", 0.0, 0.0 }
+  };
+
+  for(i = 0; i < FF_ARRAY_ELEMS(tests); i++) {
+      avpriv_trc_function func = avpriv_get_trc_function_from_trc(tests[i].trc);
+      double result = func(tests[i].arg);
+      printf("AVColorTransferCharacteristic=%d calling %s(%f) expected=%f got=%f\n",
+             tests[i].trc, tests[i].func_name, tests[i].arg,
+             tests[i].result, result);
+  }
+}
+
+// LCOV_EXCL_STOP
+#endif
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 022ae6a..a89bc1d 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -48,6 +48,10 @@ FATE_LIBAVUTIL += fate-crc
 fate-crc: libavutil/crc-test$(EXESUF)
 fate-crc: CMD = run libavutil/crc-test
 
+FATE_LIBAVUTIL += fate-color_utils
+fate-color_utils: libavutil/color_utils-test$(EXESUF)
+fate-color_utils: CMD = run libavutil/color_utils-test
+
 FATE_LIBAVUTIL += fate-des
 fate-des: libavutil/des-test$(EXESUF)
 fate-des: CMD = run libavutil/des-test
diff --git a/tests/ref/fate/color_utils b/tests/ref/fate/color_utils
new file mode 100644
index 0000000..bc88288
--- /dev/null
+++ b/tests/ref/fate/color_utils
@@ -0,0 +1,38 @@
+AVColorTransferCharacteristic=1 calling avpriv_trc_bt709(-0.010000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=6 calling avpriv_trc_bt709(0.005000) expected=0.022500 got=0.022500
+AVColorTransferCharacteristic=14 calling avpriv_trc_bt709(0.015000) expected=0.067500 got=0.067500
+AVColorTransferCharacteristic=15 calling avpriv_trc_bt709(1.000000) expected=1.000000 got=1.000000
+AVColorTransferCharacteristic=15 calling avpriv_trc_bt709(15123.456700) expected=83.452916 got=83.452916
+AVColorTransferCharacteristic=4 calling avpriv_trc_gamma22(-0.010000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=4 calling avpriv_trc_gamma22(1.000000) expected=1.000000 got=1.000000
+AVColorTransferCharacteristic=4 calling avpriv_trc_gamma22(125.098765) expected=8.980424 got=8.980424
+AVColorTransferCharacteristic=5 calling avpriv_trc_gamma28(-0.010000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=5 calling avpriv_trc_gamma28(1.000000) expected=1.000000 got=1.000000
+AVColorTransferCharacteristic=5 calling avpriv_trc_gamma28(99999.899998) expected=61.054001 got=61.054001
+AVColorTransferCharacteristic=7 calling avpriv_trc_smpte240M(-0.010000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=7 calling avpriv_trc_smpte240M(0.015000) expected=0.060000 got=0.060000
+AVColorTransferCharacteristic=8 calling avpriv_trc_linear(0.000000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=8 calling avpriv_trc_linear(0.100000) expected=0.100000 got=0.100000
+AVColorTransferCharacteristic=8 calling avpriv_trc_linear(-0.100000) expected=-0.100000 got=-0.100000
+AVColorTransferCharacteristic=9 calling avpriv_trc_log(0.009000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=9 calling avpriv_trc_log(1.000000) expected=1.000000 got=1.000000
+AVColorTransferCharacteristic=9 calling avpriv_trc_log(98678.423100) expected=3.497111 got=3.497111
+AVColorTransferCharacteristic=10 calling avpriv_trc_log_sqrt(0.003162) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=10 calling avpriv_trc_log_sqrt(1.000000) expected=1.000000 got=1.000000
+AVColorTransferCharacteristic=10 calling avpriv_trc_log_sqrt(19845.889230) expected=2.719068 got=2.719068
+AVColorTransferCharacteristic=11 calling avpriv_trc_iec61966_2_4(0.000000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=11 calling avpriv_trc_iec61966_2_4(-0.018054) expected=-0.081243 got=-0.081243
+AVColorTransferCharacteristic=11 calling avpriv_trc_iec61966_2_4(0.015000) expected=0.067500 got=0.067500
+AVColorTransferCharacteristic=11 calling avpriv_trc_iec61966_2_4(98245.769830) expected=193.835711 got=193.835711
+AVColorTransferCharacteristic=12 calling avpriv_trc_bt1361(0.000000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=12 calling avpriv_trc_bt1361(-0.004500) expected=-0.069898 got=-0.069898
+AVColorTransferCharacteristic=12 calling avpriv_trc_bt1361(0.015000) expected=0.067500 got=0.067500
+AVColorTransferCharacteristic=12 calling avpriv_trc_bt1361(1999.111230) expected=33.512490 got=33.512490
+AVColorTransferCharacteristic=13 calling avpriv_trc_iec61966_2_1(0.000000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=13 calling avpriv_trc_iec61966_2_1(0.015000) expected=0.128354 got=0.128354
+AVColorTransferCharacteristic=13 calling avpriv_trc_iec61966_2_1(6945.443000) expected=42.013863 got=42.013863
+AVColorTransferCharacteristic=16 calling avpriv_trc_smpte_st2084(-0.010000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=16 calling avpriv_trc_smpte_st2084(0.000000) expected=0.000001 got=0.000001
+AVColorTransferCharacteristic=17 calling avpriv_trc_smpte_st428_1(-0.010000) expected=0.000000 got=0.000000
+AVColorTransferCharacteristic=17 calling avpriv_trc_smpte_st428_1(52.370000) expected=4.432321 got=4.432321
+AVColorTransferCharacteristic=17 calling avpriv_trc_smpte_st428_1(0.000000) expected=0.000000 got=0.000000
-- 
2.7.2



More information about the ffmpeg-devel mailing list