From patchwork Thu Jul 6 22:00:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 4246 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp2716490vsb; Thu, 6 Jul 2017 15:00:42 -0700 (PDT) X-Received: by 10.28.66.22 with SMTP id p22mr74349wma.56.1499378442475; Thu, 06 Jul 2017 15:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499378442; cv=none; d=google.com; s=arc-20160816; b=UsK8RwhxyCCoy1KrMpWQubnNqdxRGAoTAjpt0DO9jiN4PiazvZvHDpC35Uldw1VrD4 cF2Sakj8W+mOYMpIW5iLzhI7yf1ioqn2wnwPuoFP+uXx6z405+lcv2HynSdGZ0fQz4ay 4XIwQ7iU6lx/Vvf0RrCd84XbAA1Q/xVVyFsQAVTgNSYSQY3aIxj5oXOMQh+WDkNrRtjf GgZOPmpIY0n/UmB56y0icYArZxUujyYExaJm+9jNW8mAVpPIpqu3/ghzdIxutjGiEgcY /ixJWC+KvWqJcZbom8VqwOmWS7eDTJaKIeI28YBKvOCgJ3KiM3iyXXrikAe/TGSyfnwe UaQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=7WG6bnq13Jgb/Vo/NDiDj5v49TYLtmuBpXnwlTvB7kc=; b=yJkygBBe8GysQQg6BA/6Nun4NjLPOBlOhV88Z+oW2Txi+IBJle02IKSED2+SWQ8EtP vuWoc7xKKR+TeUyvJdQ2Yak6CNXAaSTWhQVvSs9RSCRJKbajfpv+z/ANn7BcYNiojTN8 4O+mbwZ3igUpGOBNK46oEtJ8z+bzrFpdt1Ci7ElTuGod3JLXr3lB4nvOfftQeoNp2Jyc n/Cky8+ZTqHSAhq+TiruXhuAHG4W9Qy5XOwiNH04hahiL1qH94XRofETjhPGwgiyVQ98 2iauA10JQniG/DgK3Q61jA8anAC73FDRkgP3T/SGe8mbmOjrRiwSJTfoXkvWydQ28ecM dMbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.b=B/RnHfXS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c69si1095787wmd.129.2017.07.06.15.00.41; Thu, 06 Jul 2017 15:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.b=B/RnHfXS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 206B0689A66; Fri, 7 Jul 2017 01:00:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E35186897DD for ; Fri, 7 Jul 2017 01:00:30 +0300 (EEST) Received: by mail-wr0-f175.google.com with SMTP id 77so21345758wrb.1 for ; Thu, 06 Jul 2017 15:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=m6674js16bMXGLF5ko37TocFhFzCInBENMiKeq6brpk=; b=B/RnHfXSFy71BwsJMAg5gYXpF38m5/7ZzqKfdypnASwYj3G0E0oy6KNWADZwdGISZ4 nCZfhXecv+gpSASYDAp0Dwhb+pEaw2++Oly+C6AKfIjxLBt9VB8rtmSDYK3K6kFZaJC1 ZUPXyWNDJOyowYofQorStBmI4nm1AMlRpowaGq/bwR4wO/4UV7yX3KpFm3WHWY4jL/d4 XL8sO94n3ElnEs8kDSRPD9WNWYSk9gCRENVrlSbXONf77NaVUsHLEVZpeeaibwMYV2ik B2GxZfE6TZ/TJ6ISlGfqj76S1OMwXRFgnzQVXPAr5RfXUsWBPniAXHMEXsaRQ++9CiaE yezw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=m6674js16bMXGLF5ko37TocFhFzCInBENMiKeq6brpk=; b=JP/Mm1T0sAYqcBLW7VcfU7RUl3zfAN6j1hfhpF4LKCaSjxi9i/jhm/eNbm9GnQZtZv TbytH7Yy4201dj6CbLHKY2/BD5/aARTRAjETpiddT09eN2f0Pc50AxmG0KoKdL7wQTKY xmRwtiuJfSHakCmbIvTRgw2/3mi/vYHAO+koBqTascYsaOK6YDwMUO1FWsFHeRWhElgD VlnCvZEZ0BlXa4KtBWhmZF8NlYLmkPbYdDd5hU7AZC+s6/m0bPXfK/Bj49keLCLyUd73 Clm21+AYRRtIEn6fznBzcaNP4t5vlwu2bwvc5jeQkKbJMJwrT2rY5sndgJFRb41R16TN xLZg== X-Gm-Message-State: AIVw11285Ph1yxwDmlzRtLUO1dk2PJku9j8sxzwW90JoGOfO4RTBHKd3 +zFVP+ORlb0HwSEDv6c= X-Received: by 10.28.142.138 with SMTP id q132mr33158wmd.75.1499378433009; Thu, 06 Jul 2017 15:00:33 -0700 (PDT) Received: from [192.168.0.8] (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id 142sm1719081wmi.1.2017.07.06.15.00.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jul 2017 15:00:32 -0700 (PDT) To: FFmpeg development discussions and patches References: <8ef60c68-b260-83a2-8765-87737879e0b3@jkqxz.net> From: Mark Thompson Message-ID: <5ab6c8c6-9e2e-94d1-3a0d-7ab1cd2e90eb@jkqxz.net> Date: Thu, 6 Jul 2017 23:00:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <8ef60c68-b260-83a2-8765-87737879e0b3@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 2/2] pixdesc: Add a test for av_find_best_pix_fmt_of_2() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavutil/Makefile | 1 + libavutil/tests/pixfmt_best.c | 115 ++++++++++++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 ++ tests/ref/fate/pixfmt_best | 1 + 4 files changed, 121 insertions(+) create mode 100644 libavutil/tests/pixfmt_best.c create mode 100644 tests/ref/fate/pixfmt_best diff --git a/libavutil/Makefile b/libavutil/Makefile index b4464b0d76..b2662c843e 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -218,6 +218,7 @@ TESTPROGS = adler32 \ parseutils \ pixdesc \ pixelutils \ + pixfmt_best \ random_seed \ rational \ ripemd \ diff --git a/libavutil/tests/pixfmt_best.c b/libavutil/tests/pixfmt_best.c new file mode 100644 index 0000000000..b646d070c5 --- /dev/null +++ b/libavutil/tests/pixfmt_best.c @@ -0,0 +1,115 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/pixdesc.c" + +static const enum AVPixelFormat pixfmt_list[] = { + AV_PIX_FMT_GRAY8, + AV_PIX_FMT_GRAY10, + AV_PIX_FMT_GRAY16, + AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV420P10, + AV_PIX_FMT_YUV420P16, + AV_PIX_FMT_YUV422P, + AV_PIX_FMT_YUV422P10, + AV_PIX_FMT_YUV422P16, + AV_PIX_FMT_YUV444P, + AV_PIX_FMT_YUV444P10, + AV_PIX_FMT_YUV444P16, + AV_PIX_FMT_RGB565, + AV_PIX_FMT_RGB24, + AV_PIX_FMT_RGB48, + AV_PIX_FMT_VDPAU, +}; + +static enum AVPixelFormat find_best(enum AVPixelFormat pixfmt) +{ + enum AVPixelFormat best = AV_PIX_FMT_NONE; + int i; + for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++) + best = av_find_best_pix_fmt_of_2(best, pixfmt_list[i], + pixfmt, 0, NULL); + return best; +} + +int main(void) +{ + enum AVPixelFormat output; + int i, pass = 0, fail = 0; + +#define TEST(input, expected) do { \ + output = find_best(input); \ + if (output != expected) { \ + printf("Matching %s: got %s, expected %s\n", \ + av_get_pix_fmt_name(input), \ + av_get_pix_fmt_name(output), \ + av_get_pix_fmt_name(expected)); \ + ++fail; \ + } else \ + ++pass; \ + } while (0) + + // Same formats. + for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++) + TEST(pixfmt_list[i], pixfmt_list[i]); + + // Formats containing the same data in different layouts. + TEST(AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P); + TEST(AV_PIX_FMT_P010, AV_PIX_FMT_YUV420P10); + TEST(AV_PIX_FMT_P016, AV_PIX_FMT_YUV420P16); + TEST(AV_PIX_FMT_NV16, AV_PIX_FMT_YUV422P); + TEST(AV_PIX_FMT_YUYV422, AV_PIX_FMT_YUV422P); + TEST(AV_PIX_FMT_UYVY422, AV_PIX_FMT_YUV422P); + TEST(AV_PIX_FMT_BGR565, AV_PIX_FMT_RGB565); + TEST(AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24); + TEST(AV_PIX_FMT_GBRP, AV_PIX_FMT_RGB24); + TEST(AV_PIX_FMT_0RGB, AV_PIX_FMT_RGB24); + TEST(AV_PIX_FMT_GBRP16, AV_PIX_FMT_RGB48); + + // Formats additionally containing alpha (here ignored). + TEST(AV_PIX_FMT_YA8, AV_PIX_FMT_GRAY8); + TEST(AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P); + TEST(AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P); + TEST(AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P); + TEST(AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB24); + TEST(AV_PIX_FMT_ABGR, AV_PIX_FMT_RGB24); + TEST(AV_PIX_FMT_GBRAP, AV_PIX_FMT_RGB24); + TEST(AV_PIX_FMT_RGBA64, AV_PIX_FMT_RGB48); + TEST(AV_PIX_FMT_BGRA64, AV_PIX_FMT_RGB48); + + // Formats requiring upsampling to represent exactly. + TEST(AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16); + TEST(AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV420P); + TEST(AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV422P); + TEST(AV_PIX_FMT_UYYVYY411, AV_PIX_FMT_YUV422P); + TEST(AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P); + TEST(AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10); + TEST(AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV420P16); + TEST(AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10); + TEST(AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P16); + TEST(AV_PIX_FMT_BGR4, AV_PIX_FMT_RGB565); + TEST(AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB565); + TEST(AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB565); + TEST(AV_PIX_FMT_GBRP10, AV_PIX_FMT_RGB48); + + // Opaque formats are least unlike each other. + TEST(AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_VDPAU); + + printf("%d tests passed, %d tests failed.\n", pass, fail); + return !!fail; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 97eae8baf4..2938b47155 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -115,6 +115,10 @@ FATE_LIBAVUTIL-$(CONFIG_PIXELUTILS) += fate-pixelutils fate-pixelutils: libavutil/tests/pixelutils$(EXESUF) fate-pixelutils: CMD = run libavutil/tests/pixelutils +FATE_LIBAVUTIL += fate-pixfmt_best +fate-pixfmt_best: libavutil/tests/pixfmt_best$(EXESUF) +fate-pixfmt_best: CMD = run libavutil/tests/pixfmt_best + FATE_LIBAVUTIL += fate-display fate-display: libavutil/tests/display$(EXESUF) fate-display: CMD = run libavutil/tests/display diff --git a/tests/ref/fate/pixfmt_best b/tests/ref/fate/pixfmt_best new file mode 100644 index 0000000000..44df05594d --- /dev/null +++ b/tests/ref/fate/pixfmt_best @@ -0,0 +1 @@ +50 tests passed, 0 tests failed.