From patchwork Fri Sep 4 23:17:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22105 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 02AEE440046 for ; Sat, 5 Sep 2020 02:17:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE9EB68B2B1; Sat, 5 Sep 2020 02:17:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A4B71687ED6 for ; Sat, 5 Sep 2020 02:17:48 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id w5so8949729wrp.8 for ; Fri, 04 Sep 2020 16:17:48 -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=1vH+sQ7iqDnm4kxjdFVJH+uZ+fTWmuC3HgbD2wf4VdA=; b=m1tBCNnzoK1GojPE5bswQAahPAJMC8FFMDaU0d95KUpKESvuF4VbRg6xkPqi7o578P jU0d6YyoMhPgT2Z80xbFyfkDDzbBfW9s+UpKKLWyfHF5O5jek6T0Lh5wkPhY5uCeubhC pi8yPOhc6RHXmw7qp1iw2vHFSRw5u++6TVr5HDzknNMbcBiiTahl63vsCUhDjsDAZ2yE 9gIyUX2A01ctngyedKUlGO4eL2EngyvSu3OAI2evXbvptG391n3aln+yu65lP02A48hV floVGuhvpVtsZ7teU3gn/rnXuSD5t6DjmW0+Xll7+s0O5qwT+XxMjgjo1u7ikkhOEcVr vfAA== 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=1vH+sQ7iqDnm4kxjdFVJH+uZ+fTWmuC3HgbD2wf4VdA=; b=CoOKZaWoQCRePu9QI6XHZbLdIOGrkwG6bHgSpOBqvKRHTv0AGK4aLWRJ+85xbPl9oX KLsX5pl3egoc0vGM8QKJi9Y0LeHvP6mABrNGBa/9ll2kBy/tChSIhOcYCxfcJfiyKY1f i4ImLJnNK2XNBjRYoKO1Lev90zktNT1oHs65UXLWdMl2tqKEZnjExj/bbDPlOYl/lzCv AzCdRjQc8Wh6czZKuygIYr1IlrsWZrV5MYMJRCOsoUupQJaLiL97BJh/0QjCm++7vleK 1ksfZ5qymsK108RqABLcbhKDeyCORDUykxuh3emFCKnUR/34NQ+EAhx3eQnpMSBBLlus 1TxA== X-Gm-Message-State: AOAM532k6FRucHf8Etpe9X9v93bFgWiCyYGVqhNeQR/3ag8Sqs6azN7f xkKb1qlHVw96u1Km0VWE3mQUPGhmk+E= X-Google-Smtp-Source: ABdhPJx1zIHpl8ny7IrbeQO9CepIPKfLA4/XRuM0qLIYuVg0XwDk60w9bjureakAoFVkX0zGYShRPw== X-Received: by 2002:adf:9e43:: with SMTP id v3mr5335027wre.306.1599261467751; Fri, 04 Sep 2020 16:17:47 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id f14sm14598098wrv.72.2020.09.04.16.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 16:17:47 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Sep 2020 01:17:11 +0200 Message-Id: <20200904231716.16182-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200904231716.16182-1-andreas.rheinhardt@gmail.com> References: <20200904231716.16182-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] avcodec/jpeglsenc: Move check out of loop 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" ls_encode_line() encodes a line of input, going from left to right. In order to calculate a predicted value it uses the left and upper-left value of the output picture (that is, it uses how a decoder would see the already encoded part of the picture), unless this is the very first pixel of this line in which case one uses the first pixel of the last (upper) line and the line before the last line. Therefore the loop contained a check for whether this is the beginning of a new line. This commit moves said check out of the loop by initializing these values before the loop and by updating these values at the end of the loop body; already read/calculated values are reused for this (the prediction also needs the value of the upper pixel and this can be reused for the upper left value of the next iteration of the loop). Signed-off-by: Andreas Rheinhardt --- libavcodec/jpeglsenc.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c index 67897ce8ae..b9c04e979c 100644 --- a/libavcodec/jpeglsenc.c +++ b/libavcodec/jpeglsenc.c @@ -145,16 +145,14 @@ static inline void ls_encode_line(JLSState *state, PutBitContext *pb, int stride, int comp, int bits) { int x = 0; - int Ra, Rb, Rc, Rd; + int Ra = R(last, 0), Rb, Rc = last2, Rd; int D0, D1, D2; while (x < w) { int err, pred, sign; /* compute gradients */ - Ra = x ? R(cur, x - stride) : R(last, x); Rb = R(last, x); - Rc = x ? R(last, x - stride) : last2; Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride); D0 = Rd - Rb; D1 = Rb - Rc; @@ -194,9 +192,9 @@ static inline void ls_encode_line(JLSState *state, PutBitContext *pb, Ra = av_clip(pred + err * state->twonear, 0, state->maxval); else Ra = av_clip(pred - err * state->twonear, 0, state->maxval); - W(cur, x, Ra); } else - W(cur, x, R(in, x)); + Ra = R(in, x); + W(cur, x, Ra); if (err < 0) err += state->range; @@ -236,12 +234,13 @@ static inline void ls_encode_line(JLSState *state, PutBitContext *pb, Ra = av_clip(pred + err * state->twonear, 0, state->maxval); else Ra = av_clip(pred - err * state->twonear, 0, state->maxval); - W(cur, x, Ra); } else - W(cur, x, R(in, x)); + Ra = R(in, x); + W(cur, x, Ra); ls_encode_regular(state, pb, context, err); } + Rc = Rb; x += stride; } }