From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3383A42987 for ; Mon, 10 Jan 2022 14:58:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE35A68ADDB; Mon, 10 Jan 2022 16:58:52 +0200 (EET) Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D77F868A744 for ; Mon, 10 Jan 2022 16:58:46 +0200 (EET) Received: by mail-ed1-f74.google.com with SMTP id z8-20020a056402274800b003f8580bfb99so10353792edd.11 for ; Mon, 10 Jan 2022 06:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=F7EyLm06knB9HPqr7TbosorOd9emWq1Ry/5vPDN5t9E=; b=Mrx//8IobFl3I/kNT9ukZSbdfp8RFs5ZUnYHEp76yjgqeGA8S3dC6w+XT0fjQ+0MgF 2IT/obF3aChiBoKVchDstTU0iGAAkdtO+wq7BeLWspse7OEMDGEg3xbqQXuORFBwjCy5 dE1hw9jObUBi1NopSCnoNiTet+VAt5Qr/OaBy47xEwdq7Wy6R8WS+I7ndhjacTzuJzVw K9bcULldsUHwiZRty31PfWgS2xUx1A0+zhs105QJ0ifftL34zd1Z9BJIhrY19PaUlQq6 UbmMtXnq/Hbhj3JJTGdxWQSk+GrvM3qgECpSHn5yzXlQV8GrVA5zls1eVjBsmWcYlJ/T k3ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=F7EyLm06knB9HPqr7TbosorOd9emWq1Ry/5vPDN5t9E=; b=53IOckBW/bgh8HKp/O2iKkY1+EifL1tDLvct+Ok8xSIkrV7x0kBxFGUGw6MITeAWPf mU54VhHGr9PFOd2mfEMIrDZnc4grnMZR9vcjSWRKnE/i1er62L73gyAw827gRRdGYdyr K7cMKlgyaDgm4GtajZ41VlLInFLr+W0wt6cBusVmOuWgSgGAdXhnPPLXgplTIuGLtbXI h63kmYYg7nMMdpYdIpzaI7D5ze3ApPPA+f4C8K46iUH3EyIeh/HtQACQbS0hcmoAuvM/ 8c1dufIB63Gi2QeklzS0aU6TYPmJ7y2+yFtghCnIBsbcpWAbwVbeDvj36M+rPTrxHxU7 bD8g== X-Gm-Message-State: AOAM533J/hqANIke7+dXZJGTR/PZgRwTUQJphnDHS5FMfIADht+cnOxF rLFvOqP3weC98YUMjjUseai8CfsRXG+IW1fV4/n9WKRnxZnPnDZ8QyYRwXZbCQEMPF3Unsla9Dx k6I7h+AJIIKRHhkfats7FXrRRGb0es++NtW4kUBBmmaxmXffn60foeb6U9uGIndh68Z2NAX0= X-Google-Smtp-Source: ABdhPJx+bp9s+BDesmCKQynaZgfIz20+Eos4W5ck/GkNLnr0jFI9IvKWtQmW5G9tGL537d/WC50DR6IOzkIswpA= X-Received: from alankelly0.zrh.corp.google.com ([2a00:79e0:61:301:b61d:d4c4:5dce:c0af]) (user=alankelly job=sendgmr) by 2002:a17:906:cc50:: with SMTP id mm16mr85224ejb.515.1641826725977; Mon, 10 Jan 2022 06:58:45 -0800 (PST) Date: Mon, 10 Jan 2022 15:58:33 +0100 Message-Id: <20220110145836.3449558-1-alankelly@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.575.g55b058a8bb-goog From: Alan Kelly To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 1/4] libswscale: Re-factor ff_shuffle_filter_coefficients. 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: Alan Kelly Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Make the code more readable, follow the style guide and propagate memory allocation errors. --- libswscale/swscale_internal.h | 2 +- libswscale/utils.c | 68 ++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 3a78d95ba6..26d28d42e6 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -1144,5 +1144,5 @@ void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, #define MAX_LINES_AHEAD 4 //shuffle filter and filterPos for hyScale and hcScale filters in avx2 -void ff_shuffle_filter_coefficients(SwsContext *c, int* filterPos, int filterSize, int16_t *filter, int dstW); +int ff_shuffle_filter_coefficients(SwsContext *c, int* filterPos, int filterSize, int16_t *filter, int dstW); #endif /* SWSCALE_SWSCALE_INTERNAL_H */ diff --git a/libswscale/utils.c b/libswscale/utils.c index c5ea8853d5..52f07e1661 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -278,39 +278,47 @@ static const FormatEntry format_entries[] = { [AV_PIX_FMT_P416LE] = { 1, 1 }, }; -void ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, int filterSize, int16_t *filter, int dstW){ +int ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, + int filterSize, int16_t *filter, + int dstW) +{ #if ARCH_X86_64 - int i, j, k, l; + int i = 0, j = 0, k = 0; int cpu_flags = av_get_cpu_flags(); + if (!filter || dstW % 16 != 0) return 0; if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & AV_CPU_FLAG_SLOW_GATHER)) { - if ((c->srcBpc == 8) && (c->dstBpc <= 14)){ - if (dstW % 16 == 0){ - if (filter != NULL){ - for (i = 0; i < dstW; i += 8){ - FFSWAP(int, filterPos[i + 2], filterPos[i+4]); - FFSWAP(int, filterPos[i + 3], filterPos[i+5]); - } - if (filterSize > 4){ - int16_t *tmp2 = av_malloc(dstW * filterSize * 2); - memcpy(tmp2, filter, dstW * filterSize * 2); - for (i = 0; i < dstW; i += 16){//pixel - for (k = 0; k < filterSize / 4; ++k){//fcoeff - for (j = 0; j < 16; ++j){//inner pixel - for (l = 0; l < 4; ++l){//coeff - int from = i * filterSize + j * filterSize + k * 4 + l; - int to = (i) * filterSize + j * 4 + l + k * 64; - filter[to] = tmp2[from]; - } - } - } - } - av_free(tmp2); - } - } - } + if ((c->srcBpc == 8) && (c->dstBpc <= 14)) { + int16_t *filterCopy = NULL; + if (filterSize > 4) { + if (!FF_ALLOC_TYPED_ARRAY(filterCopy, dstW * filterSize)) + return AVERROR(ENOMEM); + memcpy(filterCopy, filter, dstW * filterSize * sizeof(int16_t)); + } + // Do not swap filterPos for pixels which won't be processed by + // the main loop. + for (i = 0; i + 8 <= dstW; i += 8) { + FFSWAP(int, filterPos[i + 2], filterPos[i + 4]); + FFSWAP(int, filterPos[i + 3], filterPos[i + 5]); + } + if (filterSize > 4) { + // 16 pixels are processed at a time. + for (i = 0; i + 16 <= dstW; i += 16) { + // 4 filter coeffs are processed at a time. + for (k = 0; k + 4 <= filterSize; k += 4) { + for (j = 0; j < 16; ++j) { + int from = (i + j) * filterSize + k; + int to = i * filterSize + j * 4 + k * 16; + memcpy(&filter[to], &filterCopy[from], 4 * sizeof(int16_t)); + } + } + } + } + if (filterCopy) + av_free(filterCopy); } } #endif + return 0; } int sws_isSupportedInput(enum AVPixelFormat pix_fmt) @@ -1836,7 +1844,8 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, get_local_pos(c, 0, 0, 0), get_local_pos(c, 0, 0, 0))) < 0) goto fail; - ff_shuffle_filter_coefficients(c, c->hLumFilterPos, c->hLumFilterSize, c->hLumFilter, dstW); + if ((ret = ff_shuffle_filter_coefficients(c, c->hLumFilterPos, c->hLumFilterSize, c->hLumFilter, dstW)) != 0) + goto nomem; if ((ret = initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, c->chrSrcW, c->chrDstW, filterAlign, 1 << 14, @@ -1846,7 +1855,8 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, get_local_pos(c, c->chrSrcHSubSample, c->src_h_chr_pos, 0), get_local_pos(c, c->chrDstHSubSample, c->dst_h_chr_pos, 0))) < 0) goto fail; - ff_shuffle_filter_coefficients(c, c->hChrFilterPos, c->hChrFilterSize, c->hChrFilter, c->chrDstW); + if ((ret = ff_shuffle_filter_coefficients(c, c->hChrFilterPos, c->hChrFilterSize, c->hChrFilter, c->chrDstW)) != 0) + goto nomem; } } // initialize horizontal stuff -- 2.34.1.575.g55b058a8bb-goog _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".