From patchwork Mon Oct 14 03:09:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 15735 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 C219F443982 for ; Mon, 14 Oct 2019 06:40:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AC519689F6B; Mon, 14 Oct 2019 06:40:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15-111.126.com (m15-111.126.com [220.181.15.111]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8D884689F4D for ; Mon, 14 Oct 2019 06:40:33 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=FEqVhKEqcP3uwX4+45 QklLKpTPUkXjeeVvEVJax5+Rw=; b=DNtD68aY0tW7ckgLYn1lYpluJfc+AqFo5m Cpo/m01GXEgyHyzUGeBOT2SV+18lOz0/XjcPt2C7DPpx6o3m+iakKWD0wRzPTV28 6dlx+hkXsJAkCMQSJtv5ke1zDkTbbW7YxrGoJOcpoYwgwbtn7A3KQ751MJ4+bc+n btvJaBwig= Received: from localhost.localdomain (unknown [115.27.206.51]) by smtp1 (Coremail) with SMTP id C8mowAD3RK3h5qNdTCmIBw--.34020S4; Mon, 14 Oct 2019 11:09:22 +0800 (CST) From: hwren To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Oct 2019 11:09:15 +0800 Message-Id: <1571022557-19605-2-git-send-email-hwrenx@126.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1571022557-19605-1-git-send-email-hwrenx@126.com> References: <20191013210525.GA3219@michaelspb> <1571022557-19605-1-git-send-email-hwrenx@126.com> X-CM-TRANSID: C8mowAD3RK3h5qNdTCmIBw--.34020S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar47tw1DZF1fJrW8JFWrXwb_yoW8tFy5pw 1fCrsxtw15XF1SkFZ3Jw1SqF43WFWkWw1xCrsrJw1vvFyYvr1UWry7GrZrG3yUKrsrG34Y kF4kG3Z8GF1kA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Uv2NNUUUUU= X-Originating-IP: [115.27.206.51] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiJANO6VpD9p8pmAAAsB Subject: [FFmpeg-devel] [PATCH v2 2/4] lavc/libxavs2: optimize data access 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Optimize data access from multiplication to iteration. Signed-off-by: hwren --- libavcodec/libxavs2.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c index 0179a1e..7a41ca2 100644 --- a/libavcodec/libxavs2.c +++ b/libavcodec/libxavs2.c @@ -132,29 +132,38 @@ static av_cold int xavs2_init(AVCodecContext *avctx) static void xavs2_copy_frame_with_shift(xavs2_picture_t *pic, const AVFrame *frame, const int shift_in) { - int j, k; - for (k = 0; k < 3; k++) { - int i_stride = pic->img.i_stride[k]; - for (j = 0; j < pic->img.i_lines[k]; j++) { - uint16_t *p_plane = (uint16_t *)&pic->img.img_planes[k][j * i_stride]; - int i; - uint8_t *p_buffer = frame->data[k] + frame->linesize[k] * j; - memset(p_plane, 0, i_stride); - for (i = 0; i < pic->img.i_width[k]; i++) { - p_plane[i] = p_buffer[i] << shift_in; + uint16_t *p_plane; + uint8_t * p_buffer; + int wIdx, hIdx, plane; + + for (plane = 0; plane < 3; ++plane) { + p_plane = (uint16_t *)pic->img.img_planes[plane]; + p_buffer = frame->data[plane]; + for (hIdx = 0; hIdx < pic->img.i_lines[plane]; ++hIdx) { + memset(p_plane, 0, pic->img.i_stride[plane]); + for (wIdx = 0; wIdx < pic->img.i_width[plane]; ++wIdx) { + p_plane[wIdx] = p_buffer[wIdx] << shift_in; } + p_plane += pic->img.i_stride[plane]; + p_buffer += frame->linesize[plane]; } } } static void xavs2_copy_frame(xavs2_picture_t *pic, const AVFrame *frame) { - int j, k; - for (k = 0; k < 3; k++) { - for (j = 0; j < pic->img.i_lines[k]; j++) { - memcpy( pic->img.img_planes[k] + pic->img.i_stride[k] * j, - frame->data[k]+frame->linesize[k] * j, - pic->img.i_width[k] * pic->img.in_sample_size); + uint8_t *p_plane; + uint8_t *p_buffer; + int hIdx, plane, stride; + + for (plane = 0; plane < 3; ++plane) { + p_plane = pic->img.img_planes[plane]; + p_buffer = frame->data[plane]; + stride = pic->img.i_width[plane] * pic->img.in_sample_size; + for (hIdx = 0; hIdx < pic->img.i_lines[plane]; ++hIdx) { + memcpy(p_plane, p_buffer, stride); + p_plane += pic->img.i_stride[plane]; + p_buffer += frame->linesize[plane]; } } }