From patchwork Mon Feb 1 03:51:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Da Silva X-Patchwork-Id: 25316 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 45F72449034 for ; Mon, 1 Feb 2021 05:51:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2ECFF68A30C; Mon, 1 Feb 2021 05:51:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0-10.i-mecca.net (mx0-10.i-mecca.net [76.74.184.244]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CF6668A26E for ; Mon, 1 Feb 2021 05:51:13 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id D1D3F16166F for ; Sun, 31 Jan 2021 19:51:11 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id 3504A161664 for ; Sun, 31 Jan 2021 19:51:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=GxscE9YSogz1a+ZknGoSHZ43BwetnbjAldFMczeHLhU=; b=l3mKCMat0dE9AiZPrYhFmV6D2fZpolNjhh/y/XjOp/TlkitvG7fE52CiMVK5vwK/Yw owCs78BfNNI33ycNX89rzvDiFZoNaaj01j83jibfYRYzqM0xthtSdDZpWUUh+1C88bpY KJJ0x3uE4fnj64TCSf1DUmFvNkpMUJ2lZn17giDYPgFiI0T7DTu6hRVMiSHZ+X35R0ZH QWnjCcVInJ4+z7Q60y588h/8XOxYYv9dUTNsTRt4WPlstnw3GmqlpaceXm7Ya9yogN+w aRYKYjkxcyzgk9qRvgJEKEUdFL4T608bYcty9oP4MLCbnw7+HnbMEWu52d9/KYTuRph8 ULCg== X-MES: 1.0 X-MM: 1.0 Received: from drived.localnet (d66-183-117-75.bchsia.telus.net [66.183.117.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ns2.i-mecca.net (Postfix) with ESMTPSA id D27E63001FF for ; Sun, 31 Jan 2021 22:51:09 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jan 2021 19:51:10 -0800 User-Agent: KMail/1.13.7 (Linux/2.6.38.8-desktop586-10.mga; KDE/4.6.5; i686; ; ) MIME-Version: 1.0 Message-Id: <202101311951.10576.digital@joescat.com> Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/xbmdec: get_nibble() minor speed increase, and binary reduction X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Replace av_isxdigit(*ptr) and convert(*ptr) with get_nibble(*ptr) which returns a valid nibble=={0x00..0x0f} or false==255 for all other values. This way we only need to work with *ptr once instead of twice. Removing inline av_isxdigit(x) functions also shrinks executable size. Signed-off-by: Joe Da Silva --- libavcodec/xbmdec.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) -- 2.30.0 diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c index 52615dc7ab..c1fc6cb650 100644 --- a/libavcodec/xbmdec.c +++ b/libavcodec/xbmdec.c @@ -26,15 +26,19 @@ #include "internal.h" #include "mathops.h" -static int convert(uint8_t x) +static int get_nibble(uint8_t x) { - if (x <= '9') - x -= '0'; - else if (x >= 'a') - x -= ('a' - 10); - else - x -= ('A' - 10); - return x; + int ret = 255; + + if (x <= '9') { + if (x >= '0') + ret = x - '0'; + } else if (x >= 'a') { + if (x <= 'f') + ret = x - ('a' - 10); + } else if (x >= 'A' && x <= 'F') + ret = x - ('A' - 10); + return ret; } static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) @@ -94,22 +98,26 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data, for (i = 0; i < avctx->height; i++) { dst = p->data[0] + i * p->linesize[0]; for (j = 0; j < linesize; j++) { - uint8_t val; + uint8_t nib, val; while (ptr < end && *ptr != 'x' && *ptr != '$') ptr++; ptr ++; - if (ptr < end && av_isxdigit(*ptr)) { - val = convert(*ptr++); - if (av_isxdigit(*ptr)) - val = (val << 4) + convert(*ptr++); + if (ptr < end && (val = get_nibble(*ptr)) <= 15) { + ptr++; + if ((nib = get_nibble(*ptr)) <= 15) { + val = (val << 4) + nib; + ptr++; + } *dst++ = ff_reverse[val]; - if (av_isxdigit(*ptr) && j+1 < linesize) { + if ((val = get_nibble(*ptr)) <= 15 && j+1 < linesize) { j++; - val = convert(*ptr++); - if (av_isxdigit(*ptr)) - val = (val << 4) + convert(*ptr++); + ptr++; + if ((nib = get_nibble(*ptr)) <= 15) { + val = (val << 4) + nib; + ptr++; + } *dst++ = ff_reverse[val]; } } else {