From patchwork Mon Dec 5 05:36:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 39595 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2996024pzb; Sun, 4 Dec 2022 21:36:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf49nMkjmEsk96cRqNf1ZBZRAoWj2+P7T/W5PnNfgRWLQ2dMEPDRf8hD59fd79iEq9O25cDQ X-Received: by 2002:aa7:da10:0:b0:46c:43ff:6961 with SMTP id r16-20020aa7da10000000b0046c43ff6961mr9789838eds.14.1670218605855; Sun, 04 Dec 2022 21:36:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670218605; cv=none; d=google.com; s=arc-20160816; b=VMj4yuR/YamGLEMwzsPbJ87yoJWU+y6tQZ3n0VtmPOg8kE9BSKUWqI0k1o3elvS8fv sJRhfZL9joI40CakRAiZVBJd6CsYCZVVcmKTgY6876dR6+dLf5ptEXOtl+RJvYXlYBH2 kqhDyYDXlUZd0jN4VDcxEEYlmkAAhxaNCaU3rJ5DaRyDQVCJ0MjdcQeVqaw/QnuINpGa J+OljTP9qMR0cd+ZPxy+6+ujZIg7kOoDg6Q+VMxZ3Xseb2z3UdeHXixPg5PjE0jJ8Lxi RkzBc5RSG4NOy94j7tDPV6IqTBCDRWPA0rsbgDwA83riuoXL5qvyrM0x2sIsPnsHLoOx Iv6Q== 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=ZxpdLg3/Dz68+vC4yJ7jhAcNkCSCcxVDOkACZ0rYf2I=; b=JCTiQoBAzkkWwf3Xx9H22Lyfz8XGc0LLGR7zRm1vBdR3m94opzj25b/g4Nw34tlra2 caTG7fmq0zjJG6dCTpaI+NPhezm44hL4dodQTmdJCTjF36C8wgfO7Dk742GEeswtPqjk DIa3I+XGBIILX0qu7eF3wfE1GswogWD1/eTcBlatif9fIzhuLfkbgpL4uP7q2tQXhmAP 4iynvx5w2Y2mGH+Vt3dJKs3yXYot1ZhBbVijkl4eud7Ebiw1+mCV+He+HJ3OUWCCTAp9 x1Nq3ysq0pcL0fs8pDX0tBZ1od7y5R5RG0F6BSogT9zIJ14+yncQm96Xtr5Wnq6IaOTU GSiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=WLAHkZvU; 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 m14-20020a056402430e00b00461c50013b8si12452210edc.192.2022.12.04.21.36.45; Sun, 04 Dec 2022 21:36:45 -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=@gmail.com header.s=20210112 header.b=WLAHkZvU; 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 B65C968BC15; Mon, 5 Dec 2022 07:36:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0691368BC15 for ; Mon, 5 Dec 2022 07:36:37 +0200 (EET) Received: by mail-pl1-f169.google.com with SMTP id y17so9832619plp.3 for ; Sun, 04 Dec 2022 21:36:36 -0800 (PST) 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=byysOls1OPOcvHksnWGgZd6E9GrdSAcJX1FZiN2305E=; b=WLAHkZvUyY+CrcCB7i+Mtedd7IO+1CgYu39dKqMBV9d9tGlJoVzS0iaVyw0fIu4G05 Ih09TVEietH3jacpa5XlNrLnYhdRR+b8aBsX4pyIx27aCuJIxKdWnOy70ckSheAEkAbh kGRE6dYML9N9xIkPMwBDUwUOXNJl/ASsq2eNa/v06N7XWCRwYH7WqQ1MZACg13lTGgs3 GBtXGU1Lm4VDXFj6S+G3J/HB+moJeeP1oF5fe70oMut372c+kqJavCljKSsHuevmt/6U /SHTpLFoPa2AWwDYewf9DL0Xp6UB8/L3lMWpmzQJCYPbmGyG/He4UcYjenFSmj1MSrqS 4PNg== 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=byysOls1OPOcvHksnWGgZd6E9GrdSAcJX1FZiN2305E=; b=3OmBppATIVK0RJPjyqzya8zr6qZ3gIrvwYUvqU6j1+WB+ClGGEMqzLGEC9zcQpQZ5l oDtN3MQtK/aVCigeQcvgVtWCRl77Jx2qs0PZk/gEMZfVSI99gzbWr2JQai9iNaxxd+YB P5zANaEiX798kdQKYHEhKkEZaBlfdyg+7vIwuYOzihIbB42HJeprtjAfqj96Dc3rW5e7 8dLrZkMwXp5O8gJ5Z12cLmeBFif4X0b0Pz6j9l7RcZnwpmXpJF2ZuWAp7F7UvuZ+ZsXA 2teuhEcwJFTndyZxydahVSHhZuEqSeXlqPTzPQZRD682Vunqf1fr5n4Xe85DGDeW6rI2 FEmQ== X-Gm-Message-State: ANoB5pmssxZ0no4XLo21bB/1Sgc6W8c6Bz6GxqyKDes7NfF+c9U3fScs 9JHKsx/bAV7JnonlFv0v14xKInK9f1k= X-Received: by 2002:a17:90a:a616:b0:219:6afd:24be with SMTP id c22-20020a17090aa61600b002196afd24bemr23974368pjq.0.1670218594907; Sun, 04 Dec 2022 21:36:34 -0800 (PST) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id u9-20020a170903124900b00172f6726d8esm9668649plh.277.2022.12.04.21.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 21:36:34 -0800 (PST) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Dec 2022 21:36:20 -0800 Message-Id: <20221205053620.1263-2-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20221205053620.1263-1-mindmark@gmail.com> References: <20221205053620.1263-1-mindmark@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] libswscale: add AVBSwapDSPContext and use 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: 3TitxWvo5OXL From: Mark Reid There are some places in input.c that could use it too but they aren't currently being pass the SwsContext --- libswscale/output.c | 36 +++++++++++++++-------------------- libswscale/swscale_internal.h | 3 +++ libswscale/swscale_unscaled.c | 26 +++++++++---------------- libswscale/utils.c | 2 ++ 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index 5c85bff971..cd44081e3d 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -2313,13 +2313,11 @@ yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter, } } if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) { - for (i = 0; i < dstW; i++) { - dest16[0][i] = av_bswap16(dest16[0][i]); - dest16[1][i] = av_bswap16(dest16[1][i]); - dest16[2][i] = av_bswap16(dest16[2][i]); - if (hasAlpha) - dest16[3][i] = av_bswap16(dest16[3][i]); - } + c->bsdsp.bswap16_buf(dest16[0], dest16[0], dstW); + c->bsdsp.bswap16_buf(dest16[1], dest16[1], dstW); + c->bsdsp.bswap16_buf(dest16[2], dest16[2], dstW); + if (hasAlpha) + c->bsdsp.bswap16_buf(dest16[3], dest16[3], dstW); } } @@ -2385,13 +2383,11 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter, dest16[3][i] = av_clip_uintp2(A, 30) >> 14; } if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) { - for (i = 0; i < dstW; i++) { - dest16[0][i] = av_bswap16(dest16[0][i]); - dest16[1][i] = av_bswap16(dest16[1][i]); - dest16[2][i] = av_bswap16(dest16[2][i]); - if (hasAlpha) - dest16[3][i] = av_bswap16(dest16[3][i]); - } + c->bsdsp.bswap16_buf(dest16[0], dest16[0], dstW); + c->bsdsp.bswap16_buf(dest16[1], dest16[1], dstW); + c->bsdsp.bswap16_buf(dest16[2], dest16[2], dstW); + if (hasAlpha) + c->bsdsp.bswap16_buf(dest16[3], dest16[3], dstW); } } @@ -2461,13 +2457,11 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter, dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14)); } if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) { - for (i = 0; i < dstW; i++) { - dest32[0][i] = av_bswap32(dest32[0][i]); - dest32[1][i] = av_bswap32(dest32[1][i]); - dest32[2][i] = av_bswap32(dest32[2][i]); - if (hasAlpha) - dest32[3][i] = av_bswap32(dest32[3][i]); - } + c->bsdsp.bswap32_buf(dest32[0], dest32[0], dstW); + c->bsdsp.bswap32_buf(dest32[1], dest32[1], dstW); + c->bsdsp.bswap32_buf(dest32[2], dest32[2], dstW); + if (hasAlpha) + c->bsdsp.bswap32_buf(dest32[3], dest32[3], dstW); } } diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index abeebbb002..400f0bc8ed 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -26,6 +26,7 @@ #include "config.h" #include "libavutil/avassert.h" +#include "libavutil/bswapdsp.h" #include "libavutil/common.h" #include "libavutil/frame.h" #include "libavutil/intreadwrite.h" @@ -682,6 +683,8 @@ typedef struct SwsContext { atomic_int data_unaligned_warned; Half2FloatTables *h2f_tables; + + AVBSwapDSPContext bsdsp; } SwsContext; //FIXME check init (where 0) diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index 9af2e7ecc3..0010ab24d1 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -468,7 +468,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]) { - int i, j, p; + int i, p; for (p = 0; p < 4; p++) { int srcstr = srcStride[p] / 2; @@ -480,9 +480,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *src[], continue; dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr; for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) { - for (j = 0; j < min_stride; j++) { - dstPtr[j] = av_bswap16(srcPtr[j]); - } + c->bsdsp.bswap16_buf(dstPtr, srcPtr, min_stride); srcPtr += srcstr; dstPtr += dststr; } @@ -495,7 +493,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]) { - int i, j, p; + int i, p; for (p = 0; p < 4; p++) { int srcstr = srcStride[p] / 4; @@ -507,9 +505,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *src[], continue; dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr; for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) { - for (j = 0; j < min_stride; j++) { - dstPtr[j] = av_bswap32(srcPtr[j]); - } + c->bsdsp.bswap32_buf(dstPtr, srcPtr, min_stride); srcPtr += srcstr; dstPtr += dststr; } @@ -1616,19 +1612,17 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], conv(srcPtr, dstPtr + dstStride[0] * srcSliceY, (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp); else { - int i, j; + int i; dstPtr += dstStride[0] * srcSliceY; for (i = 0; i < srcSliceH; i++) { if(src_bswap) { - for(j=0; jsrcW; j++) - ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]); + c->bsdsp.bswap16_buf((uint16_t*)c->formatConvBuffer, (uint16_t*)srcPtr, c->srcW); conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp); }else conv(srcPtr, dstPtr, c->srcW * srcBpp); if(dst_bswap) - for(j=0; jsrcW; j++) - ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]); + c->bsdsp.bswap16_buf((uint16_t*)dstPtr, (uint16_t*)dstPtr, c->srcW); srcPtr += srcStride[0]; dstPtr += dstStride[0]; } @@ -1932,16 +1926,14 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[], isBE(c->srcFormat) != isBE(c->dstFormat)) { for (i = 0; i < height; i++) { - for (j = 0; j < length; j++) - ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]); + c->bsdsp.bswap16_buf((uint16_t *)dstPtr, (const uint16_t *)srcPtr, length); srcPtr += srcStride[plane]; dstPtr += dstStride[plane]; } } else if (isFloat(c->srcFormat) && isFloat(c->dstFormat) && isBE(c->srcFormat) != isBE(c->dstFormat)) { /* swap float plane */ for (i = 0; i < height; i++) { - for (j = 0; j < length; j++) - ((uint32_t *) dstPtr)[j] = av_bswap32(((const uint32_t *) srcPtr)[j]); + c->bsdsp.bswap32_buf((uint32_t *)dstPtr, (const uint32_t *)srcPtr, length); srcPtr += srcStride[plane]; dstPtr += dstStride[plane]; } diff --git a/libswscale/utils.c b/libswscale/utils.c index 90734f66ef..0514062d85 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1921,6 +1921,8 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, return 0; } + av_bswapdsp_init(&c->bsdsp); + /* unscaled special cases */ if (unscaled && !usesHFilter && !usesVFilter && (c->srcRange == c->dstRange || isAnyRGB(dstFormat) ||