From patchwork Sun Aug 20 15:10:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cox X-Patchwork-Id: 43274 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:47ca:b0:130:ccc6:6c4b with SMTP id ey10csp936508pzb; Sun, 20 Aug 2023 08:11:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoUhIIi8lgsUTquCW56FXcVMsZ2vMPkGYRWMVjaGOnlfoa103LcMy0vY/xTSbf81sh4Ebp X-Received: by 2002:a17:907:b15:b0:99b:605b:1f49 with SMTP id h21-20020a1709070b1500b0099b605b1f49mr3080559ejl.36.1692544272385; Sun, 20 Aug 2023 08:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692544272; cv=none; d=google.com; s=arc-20160816; b=IVpoVRjJT8taBO4INPFkq7yVWA5ggHvvXjIMqBAoTa4Z/eLHKpSGkg8PamSCNer67j O9OiDRk5IFOJUbQdDUaMTN34K353q0/Jl48V3YPUWSVPo/s7m4bLqGQGQDQIapTzgPj0 inuNG2IldCYryl8LIgC2AaeT4d5ZEwcrvw5ulg6RGzW2/4v72IxbL6caB5GsYWfEX/FL gxVt+RhvaKmbIiFiK8dSql8VwLYe6OQN3fUNuP0cT4PtYTJE6byNr/D2wEnAbA9tItW6 yzXrqpVNxTOal+touKJfzyI0ArSOCYWd4DEJlQ8GZBMeOcCuinO9FWdkWr0BKxaPlirG hZrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Ler2g8kpTLO02GTJO6vooZJaBgkTIU+2Wtft2EfO0tA=; fh=9QDi6dFFPFAV43XzYhuUbqo2pwrpR9p92hw/7eQiArk=; b=Tf+0yhFuG535dONf1lU3iJKxD8DsY086z/FJNepEnobFLhwbSoWZFh1g+AM2vjp5pb Y4HEQ5vEtFWnO5Wy+sAmC7q+Vaf5UBxBHmxt/MTYcZo9YSOq6L8w8oXGBqGmK9xQaXnb YWc8Qt9dtTMVD2NF4EzUR+QhzFIKs1OlSLdsmc4ixjIltOnyTkifzR81tT8+D9rOp+sM 429t5ws1ekCZvmiAlGLDCMQGwPmCXB99Ya5pdTCb/R5gLmD1tfYpqTc72q3y7iAJRRGZ a2r6VGSEenn2XJMmoj8Cn8rxLPzb/Acu3wRdA1DR2lDPe8Whs0Rgn2Gt4tZd7J8K6wOS mFkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kynesim-co-uk.20221208.gappssmtp.com header.s=20221208 header.b=oDwNDQcm; 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 r23-20020a170906351700b0099b49483268si4350840eja.301.2023.08.20.08.11.11; Sun, 20 Aug 2023 08:11:12 -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=@kynesim-co-uk.20221208.gappssmtp.com header.s=20221208 header.b=oDwNDQcm; 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 59B0368C3DA; Sun, 20 Aug 2023 18:10:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C2EB568B4D7 for ; Sun, 20 Aug 2023 18:10:34 +0300 (EEST) Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-31ad9155414so2231011f8f.3 for ; Sun, 20 Aug 2023 08:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kynesim-co-uk.20221208.gappssmtp.com; s=20221208; t=1692544234; x=1693149034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RW7Z5hSNrilKF35jOoSyVGRkjm9ouDODSPZ2NWky/SE=; b=oDwNDQcmVpqQ6b62u06vT0GC10nyhBkbOUDtOMsgkKi/gAZPGSfQ15i73nToUJH41J bBuku8/r/AF69Dp6mkMTpEyGBQCR10NCr5bMLqMFzww1XmnVHiXrOWz/FZA8iI2Xq08b CQ9gpRMkYGp7INY2rBXCKeWkFFIAdh3VZZO7pUqGiBraQYf6yVwU2S6mZAoitQFiNU+s XxXZnCjx4Js5D1Z6IY0UfzBPtsb++9eQQsZ1G00ifiK0skARRZagYkX9w6kzxwTues6a /AnTbWYVJAfFpJQ0c2fyFf7KHVFuYIillotKmxkX9yqnXAWVa4Y2HCuqxRROuRCLxGK6 DA8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692544234; x=1693149034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RW7Z5hSNrilKF35jOoSyVGRkjm9ouDODSPZ2NWky/SE=; b=epPCn7vxBiS8ct+tOlzjjnw8DcGlpDjMDCb0wm4utlnG1XFKMxsXMj8nsaIC4eSV+8 93gBRiRM7/Es8Q/CjVsb4a0GXKYtZX0TS3aSphAMJZA1o2iz3NXnoXIEy4O7Kx+usvf9 0RuTAuKtJ5GdfjvLtjathTNG0aj3zupEwnYV/xvToeQf0cjMfQaxJy10uvxzJ9SuVDGi Ny3x2DQCpT90y0PxGP9RAJpbIv95ooAFl9eX9uSEIq5a5oMpjQAL6RXo5g1ns/BuD1Yf MSggwOXzuPVCC8X5n/99DVCwDTYa88vy+xKDr7KbhB0iMSjQcQ3JTED3Mn9bZaL8fEe5 jZDQ== X-Gm-Message-State: AOJu0Yxoe3WpiIMMI1v9yi6eLZ86sEGeEVU23Us2Xrm8YTIGHApxWQji 6yU+8/xHNGDiFv/QEgJ68ndngtsu9xhHWZcIFOs= X-Received: by 2002:a5d:60c1:0:b0:317:3deb:a899 with SMTP id x1-20020a5d60c1000000b003173deba899mr3015485wrt.1.1692544234212; Sun, 20 Aug 2023 08:10:34 -0700 (PDT) Received: from sucnaath.outer.uphall.net (cpc1-cmbg20-2-0-cust759.5-4.cable.virginm.net. [86.21.218.248]) by smtp.gmail.com with ESMTPSA id b4-20020adff904000000b003197c7d08ddsm9494476wrr.71.2023.08.20.08.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 08:10:34 -0700 (PDT) From: John Cox To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Aug 2023 15:10:19 +0000 Message-Id: <20230820151022.2204421-4-jc@kynesim.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230820151022.2204421-1-jc@kynesim.co.uk> References: <20230820151022.2204421-1-jc@kynesim.co.uk> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 3/6] swscale: Add explicit rgb24->yv12 conversion X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: John Cox Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: It53zB/IBUrz Add a rgb24->yuv420p conversion. Uses the same code as the existing bgr24->yuv converter but permutes the conversion array to swap R & B coefficients. Signed-off-by: John Cox --- libswscale/rgb2rgb.c | 5 +++++ libswscale/rgb2rgb.h | 7 +++++++ libswscale/rgb2rgb_template.c | 38 ++++++++++++++++++++++++++++++----- libswscale/swscale_unscaled.c | 24 +++++++++++++++++++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index 8707917800..de90e5193f 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -83,6 +83,11 @@ void (*ff_bgr24toyv12)(const uint8_t *src, uint8_t *ydst, int width, int height, int lumStride, int chromStride, int srcStride, int32_t *rgb2yuv); +void (*ff_rgb24toyv12)(const uint8_t *src, uint8_t *ydst, + uint8_t *udst, uint8_t *vdst, + int width, int height, + int lumStride, int chromStride, int srcStride, + int32_t *rgb2yuv); void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride); void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h index 305b830920..f7a76a92ba 100644 --- a/libswscale/rgb2rgb.h +++ b/libswscale/rgb2rgb.h @@ -79,6 +79,9 @@ void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size); void ff_bgr24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride, int32_t *rgb2yuv); +void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, + uint8_t *vdst, int width, int height, int lumStride, + int chromStride, int srcStride, int32_t *rgb2yuv); /** * Height should be a multiple of 2 and width should be a multiple of 16. @@ -128,6 +131,10 @@ extern void (*ff_bgr24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, int width, int height, int lumStride, int chromStride, int srcStride, int32_t *rgb2yuv); +extern void (*ff_rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + int width, int height, + int lumStride, int chromStride, int srcStride, + int32_t *rgb2yuv); extern void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride); diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c index 8ef4a2cf5d..e57bfa6545 100644 --- a/libswscale/rgb2rgb_template.c +++ b/libswscale/rgb2rgb_template.c @@ -646,13 +646,14 @@ static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst, * others are ignored in the C version. * FIXME: Write HQ version. */ -void ff_bgr24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, +static void rgb24toyv12_x(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, - int chromStride, int srcStride, int32_t *rgb2yuv) + int chromStride, int srcStride, int32_t *rgb2yuv, + const uint8_t x[9]) { - int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX]; - int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX]; - int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX]; + int32_t ry = rgb2yuv[x[0]], gy = rgb2yuv[x[1]], by = rgb2yuv[x[2]]; + int32_t ru = rgb2yuv[x[3]], gu = rgb2yuv[x[4]], bu = rgb2yuv[x[5]]; + int32_t rv = rgb2yuv[x[6]], gv = rgb2yuv[x[7]], bv = rgb2yuv[x[8]]; int y; const int chromWidth = width >> 1; @@ -707,6 +708,32 @@ void ff_bgr24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, } } +static const uint8_t x_bgr[9] = { + RY_IDX, GY_IDX, BY_IDX, + RU_IDX, GU_IDX, BU_IDX, + RV_IDX, GV_IDX, BV_IDX, +}; + +static const uint8_t x_rgb[9] = { + BY_IDX, GY_IDX, RY_IDX, + BU_IDX, GU_IDX, RU_IDX, + BV_IDX, GV_IDX, RV_IDX, +}; + +void ff_bgr24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, + uint8_t *vdst, int width, int height, int lumStride, + int chromStride, int srcStride, int32_t *rgb2yuv) +{ + rgb24toyv12_x(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride, rgb2yuv, x_bgr); +} + +void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, + uint8_t *vdst, int width, int height, int lumStride, + int chromStride, int srcStride, int32_t *rgb2yuv) +{ + rgb24toyv12_x(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride, rgb2yuv, x_rgb); +} + static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2, uint8_t *dest, int width, int height, int src1Stride, int src2Stride, int dstStride) @@ -979,6 +1006,7 @@ static av_cold void rgb2rgb_init_c(void) yuv422ptouyvy = yuv422ptouyvy_c; yuy2toyv12 = yuy2toyv12_c; planar2x = planar2x_c; + ff_rgb24toyv12 = ff_rgb24toyv12_c; ff_bgr24toyv12 = ff_bgr24toyv12_c; interleaveBytes = interleaveBytes_c; deinterleaveBytes = deinterleaveBytes_c; diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index 32e0d7f63c..751bdcb2e4 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -1654,6 +1654,23 @@ static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[], return srcSliceH; } +static int rgb24ToYv12Wrapper(SwsContext *c, const uint8_t *src[], + int srcStride[], int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + ff_rgb24toyv12( + src[0], + dst[0] + srcSliceY * dstStride[0], + dst[1] + (srcSliceY >> 1) * dstStride[1], + dst[2] + (srcSliceY >> 1) * dstStride[2], + c->srcW, srcSliceH, + dstStride[0], dstStride[1], srcStride[0], + c->input_rgb2yuv_table); + if (dst[3]) + fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); + return srcSliceH; +} + static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]) @@ -2035,8 +2052,13 @@ void ff_get_unscaled_swscale(SwsContext *c) /* bgr24toYV12 */ if (srcFormat == AV_PIX_FMT_BGR24 && (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) && - !(flags & SWS_ACCURATE_RND) && !(dstW&1)) + !(flags & (SWS_ACCURATE_RND | SWS_BITEXACT)) && !(dstW&1)) c->convert_unscaled = bgr24ToYv12Wrapper; + /* rgb24toYV12 */ + if (srcFormat == AV_PIX_FMT_RGB24 && + (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) && + !(flags & (SWS_ACCURATE_RND | SWS_BITEXACT)) && !(dstW&1)) + c->convert_unscaled = rgb24ToYv12Wrapper; /* RGB/BGR -> RGB/BGR (no dither needed forms) */ if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)