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 D298A49295 for ; Fri, 8 Mar 2024 00:52:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BAE4B68CBAD; Fri, 8 Mar 2024 02:51:59 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 39FF068C74E for ; Fri, 8 Mar 2024 02:51:53 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D98FDE9EDB for ; Fri, 8 Mar 2024 01:51:52 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2FyUT-JYQEaO for ; Fri, 8 Mar 2024 01:51:50 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 82B82E36D6 for ; Fri, 8 Mar 2024 01:51:50 +0100 (CET) Date: Fri, 8 Mar 2024 01:51:50 +0100 (CET) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: Message-ID: References: MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avcodec/xbmenc: Avoid snprintf() for data->hex conversion 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-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 Fri, 8 Mar 2024, Andreas Rheinhardt wrote: > Andreas Rheinhardt: >> Use a small LUT instead. Improves performance. >> >> Signed-off-by: Andreas Rheinhardt >> --- >> libavcodec/xbmenc.c | 21 +++++++++++++++------ >> 1 file changed, 15 insertions(+), 6 deletions(-) >> >> diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c >> index cd8b73afa3..5231d4691d 100644 >> --- a/libavcodec/xbmenc.c >> +++ b/libavcodec/xbmenc.c >> @@ -20,11 +20,9 @@ >> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA >> */ >> >> -#include "libavutil/reverse.h" >> #include "avcodec.h" >> #include "codec_internal.h" >> #include "encode.h" >> -#include "mathops.h" >> >> #define ANSI_MIN_READLINE 509 >> >> @@ -57,14 +55,25 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, >> buf += snprintf(buf, 39, "static unsigned char image_bits[] = {\n"); >> for (i = 0, l = lineout; i < avctx->height; i++) { >> for (j = 0; j < linesize; j++) { >> - buf += snprintf(buf, 6, " 0x%02X", ff_reverse[*ptr++]); >> + // 0..15 bitreversed as chars >> + static const char lut[] = { >> + '0', '8', '4', 'C', '2', 'A', '6', 'E', >> + '1', '9', '5', 'D', '3', 'B', '7', 'F' >> + }; >> + buf[0] = ' '; >> + buf[1] = '0'; >> + buf[2] = 'x'; >> + buf[3] = lut[*ptr & 0xF]; >> + buf[4] = lut[*ptr >> 4]; Maybe you could use *buf++ = ... here as well, to avoid the next line. But fine either way I guess. Thanks, Marton >> + buf += 5; >> + ptr++; >> if (--commas <= 0) { >> - buf += snprintf(buf, 2, "\n"); >> + *buf++ = '\n'; >> break; >> } >> - buf += snprintf(buf, 2, ","); >> + *buf++ = ','; >> if (--l <= 0) { >> - buf += snprintf(buf, 2, "\n"); >> + *buf++ = '\n'; >> l = lineout; >> } >> } > > Will apply this patch tomorrow unless there are objections. > > - Andreas > > _______________________________________________ > 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". > _______________________________________________ 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".