From patchwork Sat May 30 04:33:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19980 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 DE270448ED3 for ; Sat, 30 May 2020 07:33:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C647268ABC2; Sat, 30 May 2020 07:33:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEF386898AE for ; Sat, 30 May 2020 07:33:43 +0300 (EEST) Received: by mail-wr1-f46.google.com with SMTP id e1so6136427wrt.5 for ; Fri, 29 May 2020 21:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lYJKgBP1T8Ma1z8O6HJcE+lvaJzd4tpMqBsFI69ZWmc=; b=GbgKz0sa0DUUjRT4QuG6WpbsGyrNZH2biTcTiJKgeBdjzHf0lu7o8VW56snRZc+VHk goeEkLynl8bNo2I7duaNtvIKkuNEPyv3QCxvYkGJSs0BHoBVqYqYk9Tm8krw6K2Fc0+A UTubkuVKy2eQZCKSmP8kNGroxK0RmuBcYdNs2lJMc9wf236pt2AlnFTtZCkMtAlaAKk4 d4xe3TujU7YcomHBFpNfrNqoCf8zVwJfEirfMnR0ZotgjeYGi7kN9KtcoGwh2FJOT3fo 8MfY15ZN6drbEpZ+ufZo4iXv74538ZSfK3rxmoizsN7UDlYsfmg9zL3rd0078D+uWngt K2MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lYJKgBP1T8Ma1z8O6HJcE+lvaJzd4tpMqBsFI69ZWmc=; b=B+GOxSnhNpUbuL0ySdhdplB3P1nDQ9o7c11eWi9nc+p5OvCPo0wk6jqKxmv6iDJdAl dxZAYIDtAwW6AB9miSX5V0CMbvSJXylp6+3Olzw6SPcRIB0+JwVNa8vwf8P+FAx+0Flm z+fHI0w1Kngjo0Rp2ezK4wXPChy0NNGne1x8SgtqqTP2mcmcVfECVpqC6Ipr3SL5GVRw L9TjVYpqBoMr8re0aXIOJW7WAGFAmnBhgaKaGRcfK/aDPolUoQOL9UZzMklM/0Hu266o aTDYkBw9/dN0ppmAAF63cjJhgkOCDIQj3+Oqclb7ZtOIyCIJAjIf0gxqGzjtxU54hNha YT3g== X-Gm-Message-State: AOAM530Izr6fb34MLFXjQPymcCKyi9PfV8ttZJ2LZ/h31G2xU8oj0giv X6Qc+hKXGl9tv65fb1eT+vNn9uSF X-Google-Smtp-Source: ABdhPJza+CJXQfvRowQ+0tWVfVUMMxdxMYHfF4IagvGmsMMxidoqX9TaNSMVyjBGL2ZPEEm4SHtv9w== X-Received: by 2002:a5d:4008:: with SMTP id n8mr11381175wrp.82.1590813222961; Fri, 29 May 2020 21:33:42 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id e5sm12283281wrw.19.2020.05.29.21.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 21:33:42 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 06:33:00 +0200 Message-Id: <20200530043300.19951-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530043300.19951-1-andreas.rheinhardt@gmail.com> References: <20200530043300.19951-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/anm: Don't unnecessarily use context variables 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/anm.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libavcodec/anm.c b/libavcodec/anm.c index e9b19d880d..134640ee36 100644 --- a/libavcodec/anm.c +++ b/libavcodec/anm.c @@ -31,13 +31,12 @@ typedef struct AnmContext { AVFrame *frame; int palette[AVPALETTE_COUNT]; - GetByteContext gb; - int x; ///< x coordinate position } AnmContext; static av_cold int decode_init(AVCodecContext *avctx) { AnmContext *s = avctx->priv_data; + GetByteContext gb; int i; if (avctx->extradata_size < 16 * 8 + 4 * 256) @@ -49,10 +48,10 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!s->frame) return AVERROR(ENOMEM); - bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size); - bytestream2_skipu(&s->gb, 16 * 8); + bytestream2_init(&gb, avctx->extradata, avctx->extradata_size); + bytestream2_skipu(&gb, 16 * 8); for (i = 0; i < 256; i++) - s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(&s->gb); + s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(&gb); return 0; } @@ -115,7 +114,8 @@ static int decode_frame(AVCodecContext *avctx, AnmContext *s = avctx->priv_data; const int buf_size = avpkt->size; uint8_t *dst, *dst_end; - int count, ret; + GetByteContext gb; + int count, ret, x = 0; if (buf_size < 7) return AVERROR_INVALIDDATA; @@ -125,37 +125,36 @@ static int decode_frame(AVCodecContext *avctx, dst = s->frame->data[0]; dst_end = s->frame->data[0] + s->frame->linesize[0]*avctx->height; - bytestream2_init(&s->gb, avpkt->data, buf_size); + bytestream2_init(&gb, avpkt->data, buf_size); - if (bytestream2_get_byte(&s->gb) != 0x42) { + if (bytestream2_get_byte(&gb) != 0x42) { avpriv_request_sample(avctx, "Unknown record type"); return AVERROR_INVALIDDATA; } - if (bytestream2_get_byte(&s->gb)) { + if (bytestream2_get_byte(&gb)) { avpriv_request_sample(avctx, "Padding bytes"); return AVERROR_PATCHWELCOME; } - bytestream2_skip(&s->gb, 2); + bytestream2_skip(&gb, 2); - s->x = 0; do { /* if statements are ordered by probability */ #define OP(gb, pixel, count) \ - op(&dst, dst_end, (gb), (pixel), (count), &s->x, avctx->width, s->frame->linesize[0]) + op(&dst, dst_end, (gb), (pixel), (count), &x, avctx->width, s->frame->linesize[0]) - int type = bytestream2_get_byte(&s->gb); + int type = bytestream2_get_byte(&gb); count = type & 0x7F; type >>= 7; if (count) { - if (OP(type ? NULL : &s->gb, -1, count)) break; + if (OP(type ? NULL : &gb, -1, count)) break; } else if (!type) { int pixel; - count = bytestream2_get_byte(&s->gb); /* count==0 gives nop */ - pixel = bytestream2_get_byte(&s->gb); + count = bytestream2_get_byte(&gb); /* count==0 gives nop */ + pixel = bytestream2_get_byte(&gb); if (OP(NULL, pixel, count)) break; } else { int pixel; - type = bytestream2_get_le16(&s->gb); + type = bytestream2_get_le16(&gb); count = type & 0x3FFF; type >>= 14; if (!count) { @@ -167,11 +166,11 @@ static int decode_frame(AVCodecContext *avctx, } continue; } - pixel = type == 3 ? bytestream2_get_byte(&s->gb) : -1; + pixel = type == 3 ? bytestream2_get_byte(&gb) : -1; if (type == 1) count += 0x4000; - if (OP(type == 2 ? &s->gb : NULL, pixel, count)) break; + if (OP(type == 2 ? &gb : NULL, pixel, count)) break; } - } while (bytestream2_get_bytes_left(&s->gb) > 0); + } while (bytestream2_get_bytes_left(&gb) > 0); memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);