From patchwork Fri Mar 2 04:26:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 7787 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.181.170 with SMTP id m39csp5827512jaj; Thu, 1 Mar 2018 20:33:28 -0800 (PST) X-Google-Smtp-Source: AG47ELvcJXtkRFBmJYiTE1s4prOEAQEpKFwe4NcTT132PSGSs9+XTuvAziXCm/gT8qKJ1cWzQzBV X-Received: by 10.223.135.114 with SMTP id 47mr3591076wrz.238.1519965208853; Thu, 01 Mar 2018 20:33:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519965208; cv=none; d=google.com; s=arc-20160816; b=hS2AKC/zM0+zdc1VjAsVYtU6ooHdmp1VXzpkhYaLuXDUOCSqS0+H9xNwuVvkS6r8aX lTJq4R4HMfbG9pZNR8OwgooZxQq34GEaDm9RvFtrMIe/ejWnnZiS6C04oHkUpg2c81R3 ZwFtgt4VDEls0uatkB/fqoJ4aXyKoj65gqbl2TAdMxeCWh4w5hA1g8iR4Jz1jEfdozbN 88nqRa3xRaEEkRp1t1z/mQ8meKyFBTTTb4rnCUvOu253kvggKLRrv3i7fsrx3SjxkeO9 4si4vg33e4ydx1gu9m0XB7H8gmTmboE5D9YwiPujJndRCBle1T79t85i0j9WcPNPyUOK ITHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=ZXdumfxLoAiDw1YJvbDkQj1uV5qqDFeP4zHCB+QwDc4=; b=rvDHzbk6DW2/X8qHh7vwUWmPNjqAzqm3IIBhQ3jdMD0AHvVPMbQNlHpY7Raj4liLXh HVSfpHMIJ8WXyjL6LM3JH/en9v3xhE8hPl/zNzG1hhYe+moIkVpKTZqp4u3Vyn//w0RM rXbevZjZeNp5nkdPHgQ6kuSbl9KII9SBm2rDLQ08bG2DpB0YgJFEkKUiioKDYa8Wrdwz dvhIWqkuLMQqw8uqb3a5xuHi9Sm6gxIkib0xvlZPU1X/15o5Wexq23bYzrMoamz7fsM2 KfBXoOenlG9hEk6lErnnkRoJzmsBYShomVJS3sg6tXZZs7OYo3310ByheSbQW9nxdg5D Xlkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.s=mail header.b=OeC0B6he; 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 w18si3819973wra.159.2018.03.01.20.33.28; Thu, 01 Mar 2018 20:33:28 -0800 (PST) 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=@overt.org header.s=mail header.b=OeC0B6he; 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 DF33E68A4D1; Fri, 2 Mar 2018 06:33:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f226.google.com (mail-io0-f226.google.com [209.85.223.226]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07E4768A211 for ; Fri, 2 Mar 2018 06:33:15 +0200 (EET) Received: by mail-io0-f226.google.com with SMTP id v6so9547043iog.7 for ; Thu, 01 Mar 2018 20:33:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=JZy6cFbbK4PZ2+JDt8nzd0etxzWH+LmEvb5b49GjLgA=; b=X5cvpj/OcWm7OdEMirzKLjSPXgp1orBjcvYS0EFzpEprvoaJ8VKYFFUg8dQMddRm6l 2yUL6ZryX/f+RsnYM6uUctCai+vdekiS8eBOkqLwWKxoeHB8yzuq3Zs6qYxj5OkF6F1r 89TGVlwNi/0WSau0H9HB31CsJYC3d9D9lU10h7e1YBExeNBe4hZCe8SWsGAt366LxQFC 7NmgiJferbP/Hfe6iXOVbNbm77OZ7QEG4/YRCySGg4VVB2putzKjm+XaokfoyUtBFYMm tRBVp65cyBPmKNcXAVOFE1N9ngH9MaEtcZsrdrNFhc0RtglJQ7UNnMy9Usnp3qNUFvyw czyg== X-Gm-Message-State: AElRT7FEKwamjpGRRgbJv4l5x8Qr+1oWvhgvJp1mQ23pcavFFfogoRZd vbBy2G8HTFmEjHg57hdiTuwlblwy/3+5TyMa3pZJddjGLZHt0Q== X-Received: by 10.107.129.224 with SMTP id l93mr5033175ioi.140.1519964826315; Thu, 01 Mar 2018 20:27:06 -0800 (PST) Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com. [107.178.208.155]) by smtp-relay.gmail.com with ESMTPS id m31sm159342iti.1.2018.03.01.20.27.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 20:27:06 -0800 (PST) X-Relaying-Domain: gapps.overt.org Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id B5B0F601BE; Fri, 2 Mar 2018 04:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1519964825; bh=jP//JTkvLqrj2g8zfnZKfyCg2Q9ZWb8+I04DNfftWEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OeC0B6heEGTef8FMJ0KaJ6UnBErTFdYV3a4pojxNJHUpEDXp6gJpan5xMr8IBfVeL Yvh9a2XU0jWgEj6+zsxznQBHKsN8UI8Otk2fRJCntAx3J2Auqy/RUtbuegno9ivFag Cl0GuSTjx+f35ISGuzRLPK78yuzB8hTIVuy3sDLtjSWxp5R57tNA1rFNLqfLTXw9lN IuU7V6M3PP1l2WUDRnsu5D8kkyQj4w9o7IDAL692luhPKovK+8YXNi6cJiTS3en/z2 e60PzR1CJYjU8Zvdw4bV1i6n6u5slyYd1ur1VsoRP5TqnsAskGM4ym0wrJBDTaRX+w POQTZAHP3fgvQ== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Mar 2018 20:26:52 -0800 Message-Id: <20180302042653.14337-3-philipl@overt.org> In-Reply-To: <20180302042653.14337-1-philipl@overt.org> References: <20180302042653.14337-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 2/3] swscale: Add p016 output support and generalise yuv420p1x to p010 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 Cc: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" To make the best use of existing code, I generalised the wrapper that currently does yuv420p10 to p010 to support any mixture of input and output sizes between 10 and 16 bits. This had the side effect of yielding a working code path for all yuv420p1x formats to p01x. Signed-off-by: Philip Langdale --- libswscale/output.c | 31 +++++++++++++++++++++++++++++++ libswscale/swscale_unscaled.c | 35 +++++++++++++++++++++++++---------- libswscale/utils.c | 4 ++-- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index f30bce8dd3..0af2fffea4 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -180,6 +180,34 @@ yuv2planeX_16_c_template(const int16_t *filter, int filterSize, } } +static void yuv2p016cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize, + const int16_t **chrUSrc, const int16_t **chrVSrc, + uint8_t *dest8, int chrDstW) +{ + uint16_t *dest = (uint16_t*)dest8; + const int32_t **uSrc = (const int32_t **)chrUSrc; + const int32_t **vSrc = (const int32_t **)chrVSrc; + int shift = 15; + int big_endian = c->dstFormat == AV_PIX_FMT_P016BE; + int i, j; + + for (i = 0; i < chrDstW; i++) { + int u = 1 << (shift - 1); + int v = 1 << (shift - 1); + + /* See yuv2planeX_16_c_template for details. */ + u -= 0x40000000; + v -= 0x40000000; + for (j = 0; j < chrFilterSize; j++) { + u += uSrc[j][i] * (unsigned)chrFilter[j]; + v += vSrc[j][i] * (unsigned)chrFilter[j]; + } + + output_pixel(&dest[2*i] , u, 0x8000, int); + output_pixel(&dest[2*i+1], v, 0x8000, int); + } +} + #undef output_pixel #define output_pixel(pos, val) \ @@ -2257,6 +2285,9 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c, } else if (is16BPS(dstFormat)) { *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c; *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c; + if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) { + *yuv2nv12cX = yuv2p016cX_c; + } } else if (isNBPS(dstFormat)) { if (desc->comp[0].depth == 9) { *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c; diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index 5ec2116bcf..766c9b4872 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -180,16 +180,28 @@ static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *src[], return srcSliceH; } -static int planarToP010Wrapper(SwsContext *c, const uint8_t *src8[], +static int planarToP01xWrapper(SwsContext *c, const uint8_t *src8[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam8[], int dstStride[]) { + const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat); const uint16_t **src = (const uint16_t**)src8; uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY); uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2); int x, y; + /* Calculate net shift required for values. */ + const int shift[3] = { + dst_format->comp[0].depth + dst_format->comp[0].shift - + src_format->comp[0].depth - src_format->comp[0].shift, + dst_format->comp[1].depth + dst_format->comp[1].shift - + src_format->comp[1].depth - src_format->comp[1].shift, + dst_format->comp[2].depth + dst_format->comp[2].shift - + src_format->comp[2].depth - src_format->comp[2].shift, + }; + av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 || dstStride[0] % 2 || dstStride[1] % 2)); @@ -197,7 +209,7 @@ static int planarToP010Wrapper(SwsContext *c, const uint8_t *src8[], uint16_t *tdstY = dstY; const uint16_t *tsrc0 = src[0]; for (x = c->srcW; x > 0; x--) { - *tdstY++ = *tsrc0++ << 6; + *tdstY++ = *tsrc0++ << shift[0]; } src[0] += srcStride[0] / 2; dstY += dstStride[0] / 2; @@ -207,8 +219,8 @@ static int planarToP010Wrapper(SwsContext *c, const uint8_t *src8[], const uint16_t *tsrc1 = src[1]; const uint16_t *tsrc2 = src[2]; for (x = c->srcW / 2; x > 0; x--) { - *tdstUV++ = *tsrc1++ << 6; - *tdstUV++ = *tsrc2++ << 6; + *tdstUV++ = *tsrc1++ << shift[1]; + *tdstUV++ = *tsrc2++ << shift[2]; } src[1] += srcStride[1] / 2; src[2] += srcStride[2] / 2; @@ -1738,14 +1750,17 @@ void ff_get_unscaled_swscale(SwsContext *c) !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) { c->swscale = ff_yuv2rgb_get_func_ptr(c); } - /* yuv420p10_to_p010 */ - if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10) && - dstFormat == AV_PIX_FMT_P010) { - c->swscale = planarToP010Wrapper; + /* yuv420p1x_to_p01x */ + if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10 || + srcFormat == AV_PIX_FMT_YUV420P12 || + srcFormat == AV_PIX_FMT_YUV420P14 || + srcFormat == AV_PIX_FMT_YUV420P16 || srcFormat == AV_PIX_FMT_YUVA420P16) && + (dstFormat == AV_PIX_FMT_P010 || dstFormat == AV_PIX_FMT_P016)) { + c->swscale = planarToP01xWrapper; } - /* yuv420p_to_p010le */ + /* yuv420p_to_p01xle */ if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) && - dstFormat == AV_PIX_FMT_P010LE) { + (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P016LE)) { c->swscale = planar8ToP01xleWrapper; } diff --git a/libswscale/utils.c b/libswscale/utils.c index 4df09306d3..98a6b99476 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -254,8 +254,8 @@ static const FormatEntry format_entries[AV_PIX_FMT_NB] = { [AV_PIX_FMT_AYUV64LE] = { 1, 1}, [AV_PIX_FMT_P010LE] = { 1, 1 }, [AV_PIX_FMT_P010BE] = { 1, 1 }, - [AV_PIX_FMT_P016LE] = { 1, 0 }, - [AV_PIX_FMT_P016BE] = { 1, 0 }, + [AV_PIX_FMT_P016LE] = { 1, 1 }, + [AV_PIX_FMT_P016BE] = { 1, 1 }, }; int sws_isSupportedInput(enum AVPixelFormat pix_fmt)