From patchwork Wed Dec 19 22:00:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: matthew.w.fearnley@gmail.com X-Patchwork-Id: 11482 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 BDD9544C442 for ; Thu, 20 Dec 2018 00:00:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E3A2B68ABFD; Thu, 20 Dec 2018 00:00:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7695768ABE7 for ; Thu, 20 Dec 2018 00:00:35 +0200 (EET) Received: by mail-wr1-f53.google.com with SMTP id c14so21093770wrr.0 for ; Wed, 19 Dec 2018 14:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=DzpwdVvH4JYCq6DKSbE5sTe9IcRx4QrER/wbjLmLX/M=; b=enV1yuv8GhV0AhBORFtONFPiKYB9iVoAvX/D1Djv0r/diBVPscrbcrDd07gWgJZmiI M7gn4ofs8uSFQsGOmzhnjH0SsQTs7UKgZF0Ip56a0Aa/KvxPLgzjUKiztTXN1A1beq8C PII+h77PPLEYu8fjAAD5TvRun4c93ILc8dc+/1sSHaKbbuLhapk3y5WSbShp+D0m35K5 pOg6rkakb7me+B8N08HTNvvdAHHpV5c6QAQwNyYmOthusbJuwtyNYwumC9/a9u2BqTRo noc2DhTG/2SUdZEzddnzrtIUjrkviv+cncZkfmkJtuAytTSbG4Iqp1b81eHQoh6LGcbJ VgkQ== 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; bh=DzpwdVvH4JYCq6DKSbE5sTe9IcRx4QrER/wbjLmLX/M=; b=APYEX8pms6yVSS3uVfNgtV/fExkVqCeh+2zyKn2DJrGlOo9V4yIXSsYMbqNLoUSlSf 9V0DgMCf09ijYQ/x7pfeaDSl8N+u1Zza7SN2TJhDFmwEvheZnSPzfghssYv1zO9EvV9G RphiT1oXpimgLCIIxQlb8CQwjWsZ5S1Y2X3KgwK7CDS1Xsa35Mv9nLuMnT4/uq1xuIV/ qhWeUrT2kk9dvKWVzuRH54khcCjB4orYUwM391Kjknh+Pe4mSx/oHbVxtbyReco7yeS7 lqcg6dlO6SQ82EopYNxvNE+SgVW/oOaoBE7Gcn0gF2tVYDb2R3UO+J0sbTzFLlrBdo6Y zs0A== X-Gm-Message-State: AA+aEWbOsaQu8TtrvuhHHQZ6XQGRORuYgtxRiKuq6mh+PrQw1YdUcpWp R3D1XjBXdDK6lNuyrhXuslqJgIcj X-Google-Smtp-Source: AFSGD/V6sc61dLJdkm4MvLDO28o7JJ5CqxCpP09xaqsUDL9Iv6tifTM6R+RSJNOmlHfSihFSxqBdkA== X-Received: by 2002:adf:e846:: with SMTP id d6mr20885051wrn.72.1545256836984; Wed, 19 Dec 2018 14:00:36 -0800 (PST) Received: from localhost.localdomain (cpc131498-bagu18-2-0-cust88.know.cable.virginm.net. [86.9.33.89]) by smtp.gmail.com with ESMTPSA id k135sm8967078wmd.42.2018.12.19.14.00.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 14:00:35 -0800 (PST) From: matthew.w.fearnley@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Dec 2018 22:00:00 +0000 Message-Id: <20181219220003.27225-1-matthew.w.fearnley@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/4] zmbvenc: don't sum the entropy when blocks are equal 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: Matthew Fearnley MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Matthew Fearnley If *xored is 0, then histogram[0]==bw*bh and histogram[1..255]==0. Because histogram[0] is skipped over for the entropy calculation, the return value is always 0 when *xored==0, so we don't need to waste time calculating it. This addition both clarifies the behaviour of the code and improves the speed when the block matches. --- libavcodec/zmbvenc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c index 4d9147657d..2f041dae32 100644 --- a/libavcodec/zmbvenc.c +++ b/libavcodec/zmbvenc.c @@ -71,6 +71,7 @@ static inline int block_cmp(ZmbvEncContext *c, uint8_t *src, int stride, int i, j; uint8_t histogram[256] = {0}; + /* build frequency histogram of byte values for src[] ^ src2[] */ *xored = 0; for(j = 0; j < bh; j++){ for(i = 0; i < bw; i++){ @@ -82,6 +83,10 @@ static inline int block_cmp(ZmbvEncContext *c, uint8_t *src, int stride, src2 += stride2; } + /* early out if src and src2 are equal */ + if (!*xored) return 0; + + /* sum the entropy of the non-zero values */ for(i = 1; i < 256; i++) sum += c->score_tab[histogram[i]];