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 5F9EB41A27 for ; Wed, 16 Feb 2022 21:21:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 255C568B26D; Wed, 16 Feb 2022 23:21:33 +0200 (EET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E45C68B199 for ; Wed, 16 Feb 2022 23:21:26 +0200 (EET) Received: from localhost (213-47-68-29.cable.dynamic.surfer.at [213.47.68.29]) (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 168E440003 for ; Wed, 16 Feb 2022 21:21:23 +0000 (UTC) Date: Wed, 16 Feb 2022 22:21:21 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20220216212121.GM2829255@pb2> References: <20220209090945.3450752-1-alankelly@google.com> MIME-Version: 1.0 In-Reply-To: <20220209090945.3450752-1-alankelly@google.com> Subject: Re: [FFmpeg-devel] [PATCH 1/5] 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 Content-Type: multipart/mixed; boundary="===============2828716242984995978==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2828716242984995978== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="l9txIO9iHfSkYklq" Content-Disposition: inline --l9txIO9iHfSkYklq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 09, 2022 at 10:09:45AM +0100, Alan Kelly wrote: > Make the code more readable and follow the style guide. > --- > libswscale/utils.c | 64 +++++++++++++++++++++++++++------------------- > 1 file changed, 37 insertions(+), 27 deletions(-) >=20 > diff --git a/libswscale/utils.c b/libswscale/utils.c > index c5ea8853d5..1d919e863a 100644 > --- a/libswscale/utils.c > +++ b/libswscale/utils.c > @@ -278,39 +278,49 @@ static const FormatEntry format_entries[] =3D { > [AV_PIX_FMT_P416LE] =3D { 1, 1 }, > }; > =20 > -void ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, int f= ilterSize, int16_t *filter, int dstW){ > +void 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, j, k; > int cpu_flags =3D av_get_cpu_flags(); > + // avx2 hscale filter processes 16 pixel blocks. > + if (!filter || dstW % 16 !=3D 0) > + return; > if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & AV_CPU_FLAG_SLOW_= GATHER)) { > - if ((c->srcBpc =3D=3D 8) && (c->dstBpc <=3D 14)){ > - if (dstW % 16 =3D=3D 0){ > - if (filter !=3D NULL){ > - for (i =3D 0; i < dstW; i +=3D 8){ > - FFSWAP(int, filterPos[i + 2], filterPos[i+4]); > - FFSWAP(int, filterPos[i + 3], filterPos[i+5]); > - } > - if (filterSize > 4){ > - int16_t *tmp2 =3D av_malloc(dstW * filterSize * = 2); > - memcpy(tmp2, filter, dstW * filterSize * 2); > - for (i =3D 0; i < dstW; i +=3D 16){//pixel > - for (k =3D 0; k < filterSize / 4; ++k){//fco= eff > - for (j =3D 0; j < 16; ++j){//inner pixel > - for (l =3D 0; l < 4; ++l){//coeff > - int from =3D i * filterSize + j = * filterSize + k * 4 + l; > - int to =3D (i) * filterSize + j = * 4 + l + k * 64; > - filter[to] =3D tmp2[from]; > - } > - } > - } > - } > - av_free(tmp2); > - } > - } > - } > + if ((c->srcBpc =3D=3D 8) && (c->dstBpc <=3D 14)) { > + int16_t *filterCopy =3D NULL; > + if (filterSize > 4) { > + if (!FF_ALLOC_TYPED_ARRAY(filterCopy, dstW * filterSize)) > + return; this is not a matter of style, it changes a null pointer dereference on err= or to simply returning with no error handling. I know the next patches change this again but that makes it just more messy > + memcpy(filterCopy, filter, dstW * filterSize * sizeof(int= 16_t)); > + } > + // Do not swap filterPos for pixels which won't be processed = by > + // the main loop. > + for (i =3D 0; i + 8 <=3D dstW; i +=3D 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 =3D 0; i + 16 <=3D dstW; i +=3D 16) { > + // 4 filter coeffs are processed at a time. > + for (k =3D 0; k + 4 <=3D filterSize; k +=3D 4) { > + for (j =3D 0; j < 16; ++j) { > + int from =3D (i + j) * filterSize + k; > + int to =3D i * filterSize + j * 4 + k * 16; > + memcpy(&filter[to], &filterCopy[from], 4 * si= zeof(int16_t)); > + } > + } > + } > + } > + if (filterCopy) > + av_free(filterCopy); The null check is unneeded [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Does the universe only have a finite lifespan? No, its going to go on forever, its just that you wont like living in it. -- Hiranya Peiri --l9txIO9iHfSkYklq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYg1qzgAKCRBhHseHBAsP q50CAJ4pjlCfXXoWZ1ajWBscINzq09bJagCfQE22k2883NH1wSRT0NsGInLncHE= =Ss/g -----END PGP SIGNATURE----- --l9txIO9iHfSkYklq-- --===============2828716242984995978== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============2828716242984995978==--