From patchwork Mon Jan 21 19:09:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Dana X-Patchwork-Id: 11813 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 3A7BA44DA3F for ; Mon, 21 Jan 2019 21:16:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F28468AB22; Mon, 21 Jan 2019 21:16:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3FF468AABE for ; Mon, 21 Jan 2019 21:15:58 +0200 (EET) Received: by mail-qt1-f195.google.com with SMTP id k12so24730052qtf.7 for ; Mon, 21 Jan 2019 11:16:15 -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:mime-version :content-transfer-encoding; bh=8O53pxoj3FqbK8aLsvd0zjBX6JwGUPJr66SOk9dndzg=; b=TkUhRr4qxHNB1P0TAOABemWpywHoLpFa1ZSAFj5FsUJmRDwEu1y8o1yzWYZy53KBPp mLqVyXpdI1lbeQdX88tkCq2RUM5w0a8leJzmA22iYPp6spbtNzjeuDU1TWiP8y+ZsIG9 3KWi8eVKAJa9YYfbH2RiD/t8vUwkWJmdYWg5DkuUPG/XVG8fz9szGYL+W2WObZ5SSCk0 eb6+cEnbriBGnTEwNQ504vKItzeu3169DlK4QfxvZQLzSaqMebfZtAI1DgfvI4EPYnr4 pZOIGz5jxBMk2RFG1PUHHQLFgj0iAbRSnfFk5mvto6S//MoDuC/9srvY32ULADWvJ6Sb l87w== 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:mime-version :content-transfer-encoding; bh=8O53pxoj3FqbK8aLsvd0zjBX6JwGUPJr66SOk9dndzg=; b=PskDW0THuuiLEx0Daqt8scu0TblMzNk7mWoym9oe6TsXs6ngdbx0B/PKviD68yMbVB 6YegfonbXoPU5UnAF3f9ecbT3KB1rqX1sPSjbhSb46M2Jhg97EIdEEDofu24TYIVxt+T gZeBo+oVX4i7Bv/+NbFQYM25i5zSCGvYnUcy+D0J0sP/nIOgIcMBdhEuMtBB60JT3HMh SosfqwncgVOJ0UMNtoE6ayXxXc3yrl+itA2fOSTh/ApbGFta4dQQluMIursYvhehFmrV FklpcaPV2K795r6JLvcq1NXXvgCvvMQGkbEas+7qeX6dCUaV9xNW2WaZW6vUENCGmVDQ 9gYg== X-Gm-Message-State: AJcUukfCKsboJlfEXfoy5+DBhcmzf0yLxL3ZCB9APVUFL4EDX2nslA5Q j6z9NEq1tmsb5jzrkO9qk9QaMet8 X-Google-Smtp-Source: ALg8bN5O2USZDLClvM70X7Ye27Hunj8UzaJolagyXdBBB93j8xv02aIN+j17DJKv0wmj5IlH2gocLQ== X-Received: by 2002:aed:38a1:: with SMTP id k30mr27600080qte.50.1548097782162; Mon, 21 Jan 2019 11:09:42 -0800 (PST) Received: from teevey.local (ool-44c5019e.dyn.optonline.net. [68.197.1.158]) by smtp.gmail.com with ESMTPSA id q72sm61328115qki.24.2019.01.21.11.09.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 11:09:41 -0800 (PST) From: "FeRD (Frank Dana)" To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Jan 2019 14:09:36 -0500 Message-Id: <20190121190936.24902-1-ferdnyc@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil: Rename RSHIFT macro to ROUNDED_RSHIFT 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: "FeRD \(Frank Dana\)" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The RSHIFT macro in libavutil/common.h does not actually perform a bitwise right-shift, but rather a rounded version of the same operation, as is noted by a comment above the macro. The rounded divsion macro on the very next line is named ROUNDED_DIV, which seems far more clear. This patch renames RSHIFT to ROUNDED_RSHIFT, then updates all uses of the macro to use the new name. (These are all located in three codec files under libavcodec/.) Signed-off-by: FeRD (Frank Dana) --- libavcodec/mpeg4videodec.c | 4 ++-- libavcodec/vp3.c | 16 ++++++++-------- libavcodec/vp56.c | 4 ++-- libavutil/common.h | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index f44ee76bd4..5d63ba12ba 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -601,7 +601,7 @@ static inline int get_amv(Mpeg4DecContext *ctx, int n) if (ctx->divx_version == 500 && ctx->divx_build == 413 && a >= s->quarter_sample) sum = s->sprite_offset[0][n] / (1 << (a - s->quarter_sample)); else - sum = RSHIFT(s->sprite_offset[0][n] * (1 << s->quarter_sample), a); + sum = ROUNDED_RSHIFT(s->sprite_offset[0][n] * (1 << s->quarter_sample), a); } else { dx = s->sprite_delta[n][0]; dy = s->sprite_delta[n][1]; @@ -623,7 +623,7 @@ static inline int get_amv(Mpeg4DecContext *ctx, int n) v += dx; } } - sum = RSHIFT(sum, a + 8 - s->quarter_sample); + sum = ROUNDED_RSHIFT(sum, a + 8 - s->quarter_sample); } if (sum < -len) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index a5d8c2ed0b..13b3d6e22a 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -861,10 +861,10 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) if (s->chroma_y_shift) { if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { - motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] + - motion_x[2] + motion_x[3], 2); - motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] + - motion_y[2] + motion_y[3], 2); + motion_x[0] = ROUNDED_RSHIFT(motion_x[0] + motion_x[1] + + motion_x[2] + motion_x[3], 2); + motion_y[0] = ROUNDED_RSHIFT(motion_y[0] + motion_y[1] + + motion_y[2] + motion_y[3], 2); } motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1); motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1); @@ -873,10 +873,10 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) s->motion_val[1][frag][1] = motion_y[0]; } else if (s->chroma_x_shift) { if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { - motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1); - motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1); - motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1); - motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1); + motion_x[0] = ROUNDED_RSHIFT(motion_x[0] + motion_x[1], 1); + motion_y[0] = ROUNDED_RSHIFT(motion_y[0] + motion_y[1], 1); + motion_x[1] = ROUNDED_RSHIFT(motion_x[2] + motion_x[3], 1); + motion_y[1] = ROUNDED_RSHIFT(motion_y[2] + motion_y[3], 1); } else { motion_x[1] = motion_x[0]; motion_y[1] = motion_y[0]; diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c index b69fe6c176..9359b48bc6 100644 --- a/libavcodec/vp56.c +++ b/libavcodec/vp56.c @@ -197,8 +197,8 @@ static void vp56_decode_4mv(VP56Context *s, int row, int col) /* chroma vectors are average luma vectors */ if (s->avctx->codec->id == AV_CODEC_ID_VP5) { - s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2); - s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2); + s->mv[4].x = s->mv[5].x = ROUNDED_RSHIFT(mv.x,2); + s->mv[4].y = s->mv[5].y = ROUNDED_RSHIFT(mv.y,2); } else { s->mv[4] = s->mv[5] = (VP56mv) {mv.x/4, mv.y/4}; } diff --git a/libavutil/common.h b/libavutil/common.h index 8db0291170..0bff7f8f72 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -51,7 +51,7 @@ #endif //rounded division & shift -#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) +#define ROUNDED_RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) /* assume b>0 */ #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) /* Fast a/(1<=0 and b>=0 */