LCOV - code coverage report
Current view: top level - src/libavutil/tests - pixfmt_best.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 65 65 100.0 %
Date: 2017-09-20 05:29:53 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19             : #include "libavutil/pixdesc.c"
      20             : 
      21             : static const enum AVPixelFormat pixfmt_list[] = {
      22             :     AV_PIX_FMT_MONOWHITE,
      23             :     AV_PIX_FMT_GRAY8,
      24             :     AV_PIX_FMT_GRAY10,
      25             :     AV_PIX_FMT_GRAY16,
      26             :     AV_PIX_FMT_YUV420P,
      27             :     AV_PIX_FMT_YUV420P10,
      28             :     AV_PIX_FMT_YUV420P16,
      29             :     AV_PIX_FMT_YUV422P,
      30             :     AV_PIX_FMT_YUV422P10,
      31             :     AV_PIX_FMT_YUV422P16,
      32             :     AV_PIX_FMT_YUV444P,
      33             :     AV_PIX_FMT_YUV444P10,
      34             :     AV_PIX_FMT_YUV444P16,
      35             :     AV_PIX_FMT_RGB565,
      36             :     AV_PIX_FMT_RGB24,
      37             :     AV_PIX_FMT_RGB48,
      38             :     AV_PIX_FMT_VDPAU,
      39             :     AV_PIX_FMT_VAAPI,
      40             : };
      41             : 
      42          72 : static enum AVPixelFormat find_best(enum AVPixelFormat pixfmt)
      43             : {
      44          72 :     enum AVPixelFormat best = AV_PIX_FMT_NONE;
      45             :     int i;
      46        1368 :     for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
      47        1296 :         best = av_find_best_pix_fmt_of_2(best, pixfmt_list[i],
      48             :                                          pixfmt, 0, NULL);
      49          72 :     return best;
      50             : }
      51             : 
      52           1 : int main(void)
      53             : {
      54             :     enum AVPixelFormat output;
      55           1 :     int i, pass = 0, fail = 0;
      56             : 
      57             : #define TEST(input, expected) do {                              \
      58             :         output = find_best(input);                              \
      59             :         if (output != expected) {                               \
      60             :             printf("Matching %s: got %s, expected %s\n",        \
      61             :                    av_get_pix_fmt_name(input),                  \
      62             :                    av_get_pix_fmt_name(output),                 \
      63             :                    av_get_pix_fmt_name(expected));              \
      64             :             ++fail;                                             \
      65             :         } else                                                  \
      66             :             ++pass;                                             \
      67             :     } while (0)
      68             : 
      69             :     // Same formats.
      70          19 :     for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
      71          18 :         TEST(pixfmt_list[i], pixfmt_list[i]);
      72             : 
      73             :     // Formats containing the same data in different layouts.
      74           1 :     TEST(AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE);
      75           1 :     TEST(AV_PIX_FMT_NV12,      AV_PIX_FMT_YUV420P);
      76           1 :     TEST(AV_PIX_FMT_P010,      AV_PIX_FMT_YUV420P10);
      77           1 :     TEST(AV_PIX_FMT_P016,      AV_PIX_FMT_YUV420P16);
      78           1 :     TEST(AV_PIX_FMT_NV16,      AV_PIX_FMT_YUV422P);
      79           1 :     TEST(AV_PIX_FMT_YUYV422,   AV_PIX_FMT_YUV422P);
      80           1 :     TEST(AV_PIX_FMT_UYVY422,   AV_PIX_FMT_YUV422P);
      81           1 :     TEST(AV_PIX_FMT_BGR565,    AV_PIX_FMT_RGB565);
      82           1 :     TEST(AV_PIX_FMT_BGR24,     AV_PIX_FMT_RGB24);
      83           1 :     TEST(AV_PIX_FMT_GBRP,      AV_PIX_FMT_RGB24);
      84           1 :     TEST(AV_PIX_FMT_0RGB,      AV_PIX_FMT_RGB24);
      85           1 :     TEST(AV_PIX_FMT_GBRP16,    AV_PIX_FMT_RGB48);
      86             : 
      87             :     // Formats additionally containing alpha (here ignored).
      88           1 :     TEST(AV_PIX_FMT_YA8,       AV_PIX_FMT_GRAY8);
      89           1 :     TEST(AV_PIX_FMT_YA16,      AV_PIX_FMT_GRAY16);
      90           1 :     TEST(AV_PIX_FMT_YUVA420P,  AV_PIX_FMT_YUV420P);
      91           1 :     TEST(AV_PIX_FMT_YUVA422P,  AV_PIX_FMT_YUV422P);
      92           1 :     TEST(AV_PIX_FMT_YUVA444P,  AV_PIX_FMT_YUV444P);
      93           1 :     TEST(AV_PIX_FMT_AYUV64,    AV_PIX_FMT_YUV444P16);
      94           1 :     TEST(AV_PIX_FMT_RGBA,      AV_PIX_FMT_RGB24);
      95           1 :     TEST(AV_PIX_FMT_ABGR,      AV_PIX_FMT_RGB24);
      96           1 :     TEST(AV_PIX_FMT_GBRAP,     AV_PIX_FMT_RGB24);
      97           1 :     TEST(AV_PIX_FMT_RGBA64,    AV_PIX_FMT_RGB48);
      98           1 :     TEST(AV_PIX_FMT_BGRA64,    AV_PIX_FMT_RGB48);
      99           1 :     TEST(AV_PIX_FMT_GBRAP16,   AV_PIX_FMT_RGB48);
     100             : 
     101             :     // Formats requiring upsampling to represent exactly.
     102           1 :     TEST(AV_PIX_FMT_GRAY12,    AV_PIX_FMT_GRAY16);
     103           1 :     TEST(AV_PIX_FMT_YUV410P,   AV_PIX_FMT_YUV420P);
     104           1 :     TEST(AV_PIX_FMT_YUV411P,   AV_PIX_FMT_YUV422P);
     105           1 :     TEST(AV_PIX_FMT_UYYVYY411, AV_PIX_FMT_YUV422P);
     106           1 :     TEST(AV_PIX_FMT_YUV440P,   AV_PIX_FMT_YUV444P);
     107           1 :     TEST(AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV444P10);
     108           1 :     TEST(AV_PIX_FMT_YUV440P12, AV_PIX_FMT_YUV444P16);
     109           1 :     TEST(AV_PIX_FMT_YUV420P9,  AV_PIX_FMT_YUV420P10);
     110           1 :     TEST(AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV420P16);
     111           1 :     TEST(AV_PIX_FMT_YUV444P9,  AV_PIX_FMT_YUV444P10);
     112           1 :     TEST(AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P16);
     113           1 :     TEST(AV_PIX_FMT_BGR4,      AV_PIX_FMT_RGB565);
     114           1 :     TEST(AV_PIX_FMT_RGB444,    AV_PIX_FMT_RGB565);
     115           1 :     TEST(AV_PIX_FMT_RGB555,    AV_PIX_FMT_RGB565);
     116           1 :     TEST(AV_PIX_FMT_GBRP10,    AV_PIX_FMT_RGB48);
     117           1 :     TEST(AV_PIX_FMT_GBRAP10,   AV_PIX_FMT_RGB48);
     118           1 :     TEST(AV_PIX_FMT_GBRAP12,   AV_PIX_FMT_RGB48);
     119             : 
     120             :     // Formats containing the same data in different endianness.
     121           1 :     TEST(AV_PIX_FMT_GRAY10BE,    AV_PIX_FMT_GRAY10);
     122           1 :     TEST(AV_PIX_FMT_GRAY10LE,    AV_PIX_FMT_GRAY10);
     123           1 :     TEST(AV_PIX_FMT_GRAY16BE,    AV_PIX_FMT_GRAY16);
     124           1 :     TEST(AV_PIX_FMT_GRAY16LE,    AV_PIX_FMT_GRAY16);
     125           1 :     TEST(AV_PIX_FMT_YUV422P10BE, AV_PIX_FMT_YUV422P10);
     126           1 :     TEST(AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV422P10);
     127           1 :     TEST(AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUV444P16);
     128           1 :     TEST(AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUV444P16);
     129           1 :     TEST(AV_PIX_FMT_RGB565BE,    AV_PIX_FMT_RGB565);
     130           1 :     TEST(AV_PIX_FMT_RGB565LE,    AV_PIX_FMT_RGB565);
     131           1 :     TEST(AV_PIX_FMT_RGB48BE,     AV_PIX_FMT_RGB48);
     132           1 :     TEST(AV_PIX_FMT_RGB48LE,     AV_PIX_FMT_RGB48);
     133             : 
     134             :     // Opaque formats are least unlike each other.
     135           1 :     TEST(AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_VDPAU);
     136             : 
     137           1 :     printf("%d tests passed, %d tests failed.\n", pass, fail);
     138           1 :     return !!fail;
     139             : }

Generated by: LCOV version 1.13