From patchwork Mon Oct 31 00:32:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 39069 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8e01:b0:a3:a294:714c with SMTP id y1csp619755pzj; Sun, 30 Oct 2022 17:33:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MRrS2Nx3/zPkIAQ6yt3T1ELBD/GHbp+wQ7EZR1D+jbbx3DfZU4S7d1kWRTQUa02VJpxvX X-Received: by 2002:a17:906:8442:b0:7ad:960b:ef61 with SMTP id e2-20020a170906844200b007ad960bef61mr10601020ejy.702.1667176397847; Sun, 30 Oct 2022 17:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667176397; cv=none; d=google.com; s=arc-20160816; b=QdDi9sXBJs//9Ra1USDNr7AcMNMRRI9Rt5Pa2INoaX8QFCB4pv5/X3a6c0+Pq5zM/8 bvCtpJGZzv1DoLrBxGEsqO+E4nT9CxFzHBgJVOOv142o5B9LPvHixahYI7DHKwolFa76 YphBceY9/yHN+76trtBpG8V787+KGUSjwKPVSxEhcPoOcAJoLW5H8ujselhDKCsDIJV6 VvMsHZs/ThDjZ10+Z8e6k8vPzOKX0nJtF7TF0PGvqaYtk+21VwszrtlqQfsNQi/M4Ydr jaIt25hvofi6+1ToCJKuejudmwNTgE8Xp729RLEqWCJ6Avm+HjzNwJcww9yFmIo0bQZw BjpA== 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=M502uE2T8NvYnuZMAQkZjwPvGCY6CXRT8CAdV7M2uTs=; b=lbu/LLozgoBdtAiHgQKsz9UImYAJqHki8ByxFuRCSVpQXwQaKUvNSDmWPNo82OyRUL 7zapJA/JPPFKSFOfytZp/DC8tk0kobZsLeFpBoD8HlJ47kzyfczEJn7/lUb2CurU03wD /EXmT0jqNHfDeOtNzTNk3GkNCgikVvYTHqp5ipYRYDTv5PnXmnaFSNXcsyDTB8GHUBsE BMxHM5zvRV9wkz7gbwFhVYE58AiUyS+FYkA5xgsQuJXI3bUm7dQAsQje1fG58mJVmqtz rSkHOd0JViH7iSmxRaQKz1copn7QW2M5lqhxJkY/8DcPT609o0S1hirfujAi7M890rjh DuWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HFxE5D69; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b6-20020aa7c6c6000000b00462764a8b8esi5040080eds.592.2022.10.30.17.33.17; Sun, 30 Oct 2022 17:33:17 -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=@gmail.com header.s=20210112 header.b=HFxE5D69; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A6A968BDCC; Mon, 31 Oct 2022 02:33:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40ED568BD28 for ; Mon, 31 Oct 2022 02:33:01 +0200 (EET) Received: by mail-pj1-f42.google.com with SMTP id o7so5877853pjj.1 for ; Sun, 30 Oct 2022 17:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=lEQnxzIUumeilp+UNMA6dwRS1QqCHDKdOyTz1nNHhG4=; b=HFxE5D69X2JG04kT5PtOsPmj49ThBV58elNv7+jgIZV70/orzpUwSsrSEos/XjJ0eP SisaGqQ8AXaqpfoY+WyBW9Ud+IGfkCzPTtYOycy+Ns13lrLIUuHSRrZV4Nk0bl9srG5g +oYKwTvt4l2rr7d5Qldg35Gi39h2PR2fKiH40XU6szaimQhVdaXfyZnUWpqJ5DHXTqg/ MaN0ijVhwbLC1LIDV4F27zqJDDvuOwGk+cAXcqcGKD9PhaOPfTS+GJ8L1Gw/scCCAEcz N18Oe8oYvU+fzNLNOQ9VCcsQQkzzSTxwsVjBO2bP/ZY2xcgFdS3tBEdE/Ama8IgnmsuC HJ3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=lEQnxzIUumeilp+UNMA6dwRS1QqCHDKdOyTz1nNHhG4=; b=fnHqx3KWnLxb+JmWCv+TNMDmuVhTzYfmZ6SwkjT17BDW41TNKU0k3xN1DDO56GMfId hrJxED4ESiBtnHvdpO4/Wg3mk4o56Wrw6UDQsiD/QXVVQBDbVBTrteSzopxWYSRAsBUH IW7JWCxqeHJl5muj1hqnRzycBpjcUdzt81XIHbGHUo8wB7vTIbMozhtlJNITvseEnHM5 4DQK3Ifvnp2mMgyA0Ye/47lTKEPU0rUuWFlfbnNpUH+6748Gkj0Qr93eMfnSGVLuWxu9 eaDCPDyTwwgLiUDZWI82roFbSNGF27qK/LfeWT6SOGPp4ZkkFG4FnNDyNaLNpimgDO8d Nmyw== X-Gm-Message-State: ACrzQf2z5DpJDAzeVErtM+MFf9lBOXA//iNX4bsOGCwzPTQtOff3fbVk FK8AVQ7+ZjATgWCJj7wIls4mbE4D9JA= X-Received: by 2002:a17:90a:f294:b0:213:cb7e:632d with SMTP id fs20-20020a17090af29400b00213cb7e632dmr6301683pjb.117.1667176378578; Sun, 30 Oct 2022 17:32:58 -0700 (PDT) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id m18-20020a62a212000000b0056bd737fdf3sm3175699pff.123.2022.10.30.17.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 17:32:57 -0700 (PDT) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Oct 2022 17:32:32 -0700 Message-Id: <20221031003235.348-2-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20221031003235.348-1-mindmark@gmail.com> References: <20221031003235.348-1-mindmark@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/4] swscale/input: add rgbaf32 input support 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: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: E7/rMYgb13ZF From: Mark Reid --- libswscale/input.c | 172 +++++++++++++++++++++++++++++++++++++++++++++ libswscale/utils.c | 4 ++ 2 files changed, 176 insertions(+) diff --git a/libswscale/input.c b/libswscale/input.c index 7ff7bfaa01..4683284b0b 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -1284,6 +1284,136 @@ static void rgbaf16##endian_name##ToA_c(uint8_t *_dst, const uint8_t *_src, cons rgbaf16_funcs_endian(le, 0) rgbaf16_funcs_endian(be, 1) +#define rdpx(src) (is_be ? av_int2float(AV_RB32(&src)): av_int2float(AV_RL32(&src))) + +static av_always_inline void rgbaf32ToUV_half_endian(uint16_t *dstU, uint16_t *dstV, int is_be, + const float *src, int width, + int32_t *rgb2yuv, int comp) +{ + 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]; + int i; + for (i = 0; i < width; i++) { + int r = (lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+0]), 0.0f, 65535.0f)) + + lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+4]), 0.0f, 65535.0f))) >> 1; + int g = (lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+1]), 0.0f, 65535.0f)) + + lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+5]), 0.0f, 65535.0f))) >> 1; + int b = (lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+2]), 0.0f, 65535.0f)) + + lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+6]), 0.0f, 65535.0f))) >> 1; + + dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + } +} + +static av_always_inline void rgbaf32ToUV_endian(uint16_t *dstU, uint16_t *dstV, int is_be, + const float *src, int width, + int32_t *rgb2yuv, int comp) +{ + 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]; + int i; + for (i = 0; i < width; i++) { + int r = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+0]), 0.0f, 65535.0f)); + int g = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+1]), 0.0f, 65535.0f)); + int b = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+2]), 0.0f, 65535.0f)); + + dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + } +} + +static av_always_inline void rgbaf32ToY_endian(uint16_t *dst, const float *src, int is_be, + int width, int32_t *rgb2yuv, int comp) +{ + int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX]; + int i; + for (i = 0; i < width; i++) { + int r = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+0]), 0.0f, 65535.0f)); + int g = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+1]), 0.0f, 65535.0f)); + int b = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+2]), 0.0f, 65535.0f)); + + dst[i] = (ry*r + gy*g + by*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + } +} + +static av_always_inline void rgbaf32ToA_endian(uint16_t *dst, const float *src, int is_be, + int width, void *opq) +{ + int i; + for (i=0; isrcFormat; @@ -1570,6 +1700,18 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) case AV_PIX_FMT_RGBAF16LE: c->chrToYV12 = rgbaf16leToUV_half_c; break; + case AV_PIX_FMT_RGBF32BE: + c->chrToYV12 = rgbf32beToUV_half_c; + break; + case AV_PIX_FMT_RGBAF32BE: + c->chrToYV12 = rgbaf32beToUV_half_c; + break; + case AV_PIX_FMT_RGBF32LE: + c->chrToYV12 = rgbf32leToUV_half_c; + break; + case AV_PIX_FMT_RGBAF32LE: + c->chrToYV12 = rgbaf32leToUV_half_c; + break; } } else { switch (srcFormat) { @@ -1663,6 +1805,18 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) case AV_PIX_FMT_RGBAF16LE: c->chrToYV12 = rgbaf16leToUV_c; break; + case AV_PIX_FMT_RGBF32BE: + c->chrToYV12 = rgbf32beToUV_c; + break; + case AV_PIX_FMT_RGBAF32BE: + c->chrToYV12 = rgbaf32beToUV_c; + break; + case AV_PIX_FMT_RGBF32LE: + c->chrToYV12 = rgbf32leToUV_c; + break; + case AV_PIX_FMT_RGBAF32LE: + c->chrToYV12 = rgbaf32leToUV_c; + break; } } @@ -1973,6 +2127,18 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) case AV_PIX_FMT_RGBAF16LE: c->lumToYV12 = rgbaf16leToY_c; break; + case AV_PIX_FMT_RGBF32BE: + c->lumToYV12 = rgbf32beToY_c; + break; + case AV_PIX_FMT_RGBAF32BE: + c->lumToYV12 = rgbaf32beToY_c; + break; + case AV_PIX_FMT_RGBF32LE: + c->lumToYV12 = rgbf32leToY_c; + break; + case AV_PIX_FMT_RGBAF32LE: + c->lumToYV12 = rgbaf32leToY_c; + break; } if (c->needAlpha) { if (is16BPS(srcFormat) || isNBPS(srcFormat)) { @@ -1998,6 +2164,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) case AV_PIX_FMT_RGBAF16LE: c->alpToYV12 = rgbaf16leToA_c; break; + case AV_PIX_FMT_RGBAF32BE: + c->alpToYV12 = rgbaf32beToA_c; + break; + case AV_PIX_FMT_RGBAF32LE: + c->alpToYV12 = rgbaf32leToA_c; + break; case AV_PIX_FMT_YA8: c->alpToYV12 = uyvyToY_c; break; diff --git a/libswscale/utils.c b/libswscale/utils.c index 45baa22b23..6da1f21e25 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -266,6 +266,10 @@ static const FormatEntry format_entries[] = { [AV_PIX_FMT_VUYX] = { 1, 1 }, [AV_PIX_FMT_RGBAF16BE] = { 1, 0 }, [AV_PIX_FMT_RGBAF16LE] = { 1, 0 }, + [AV_PIX_FMT_RGBF32BE] = { 1, 0 }, + [AV_PIX_FMT_RGBF32LE] = { 1, 0 }, + [AV_PIX_FMT_RGBAF32BE] = { 1, 0 }, + [AV_PIX_FMT_RGBAF32LE] = { 1, 0 }, [AV_PIX_FMT_XV30LE] = { 1, 1 }, [AV_PIX_FMT_XV36LE] = { 1, 1 }, };