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 EC2A146097 for ; Thu, 4 May 2023 08:22:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2209268BDD8; Thu, 4 May 2023 11:22:28 +0300 (EEST) Received: from mail8.parnet.fi (mail8.parnet.fi [77.234.108.134]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E0C5268AB23 for ; Thu, 4 May 2023 11:22:21 +0300 (EEST) Received: from mail9.parnet.fi (mail9.parnet.fi [77.234.108.21]) by mail8.parnet.fi with ESMTP id 3448MKkN028531-3448MKkO028531; Thu, 4 May 2023 11:22:20 +0300 Received: from foo.martin.st (host-97-187.parnet.fi [77.234.97.187]) by mail9.parnet.fi (Postfix) with ESMTPS id DCCF1A1428; Thu, 4 May 2023 11:22:19 +0300 (EEST) Date: Thu, 4 May 2023 11:22:17 +0300 (EEST) From: =?ISO-8859-15?Q?Martin_Storsj=F6?= To: FFmpeg development discussions and patches In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-FE-Policy-ID: 3:14:2:SYSTEM Subject: Re: [FFmpeg-devel] [PATCH] avutil/imgutils: optimize image copy efficiency 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: xufuji456 <839789740@qq.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Thu, 4 May 2023, xufuji456 wrote: > It makes sense when copying 4K/8K video, if linesize > equals to aligned linesize. > > Signed-off-by: xufuji456 <839789740@qq.com> > --- > libavutil/imgutils.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c > index 9ab5757cf6..1d432e7a57 100644 > --- a/libavutil/imgutils.c > +++ b/libavutil/imgutils.c > @@ -525,10 +525,17 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size, > const uint8_t *src = src_data[i]; > h = (height + (1 << shift) - 1) >> shift; > > - for (j = 0; j < h; j++) { > - memcpy(dst, src, linesize[i]); > - dst += FFALIGN(linesize[i], align); > - src += src_linesize[i]; > + if (FFALIGN(linesize[i], align) == linesize[i] && src_linesize[i] == linesize[i]) { > + int size = linesize[i] * h; For cases like these, I would prefer to use "linesize[i] * (h - 1) + w" instead. For cases if copying e.g. into an offsetted position within a buffer, writing the last trailing padding would end up writing out of bounds. That said, I'm unsure about how much gain you get from this optimization here - some numbers to back it up would be useful. // Martin _______________________________________________ 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".