From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CD20140A5A for ; Sat, 5 Mar 2022 16:58:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 42C6A68A7DD; Sat, 5 Mar 2022 18:58:50 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACEB368A7DD for ; Sat, 5 Mar 2022 18:58:43 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 272374702E; Sat, 5 Mar 2022 17:58:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1646499523; bh=IIMMUyNq8Id6JQaDR6zchCKQ71RECpFtSZp1VdKc7wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HNwR6zPl/sq4mwtJcvgZjbJkD2ksVN6p+1P5xXodfbxFgVEL8SruDIUcItq9zrFas x/5ZcL+SC6loWSdgY7BJ9dIWG0mww9lupXTSrp+INVMUT/aw06S4DQzmGZ0WcIT8Zf xKRmbOEpDUhFkT3O7xZ8EIg7sWHTmdqtwvU9RJrQ= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Mar 2022 17:58:32 +0100 Message-Id: <20220305165833.18668-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305165833.18668-1-ffmpeg@haasn.xyz> References: <20220305165833.18668-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] h274: avoid copying AVFilmGrainH274Params into the stack frame X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas There's very little reason to make a local copy of this entire ~10 kB struct, only to precompute three minor arithmetic operations. Just move the logic to the per-block function call instead. Signed-off-by: Niklas Haas --- libavcodec/h274.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/libavcodec/h274.c b/libavcodec/h274.c index 170086543f..265bd49ea1 100644 --- a/libavcodec/h274.c +++ b/libavcodec/h274.c @@ -192,14 +192,18 @@ static av_always_inline void generate(int8_t *out, int out_stride, return; } - h = num_values > 1 ? av_clip(h274->comp_model_value[c][s][1], 2, 14) - 2 : 6; - v = num_values > 2 ? av_clip(h274->comp_model_value[c][s][2], 2, 14) - 2 : h; - init_slice(database, h, v); - scale = h274->comp_model_value[c][s][0]; if (invert) scale = -scale; + if (c > 0) + scale >>= 1; // reduce intensity for chroma (as per SMPTE RDD 5-2006) + h = num_values > 1 ? h274->comp_model_value[c][s][1] : 8; + v = num_values > 2 ? h274->comp_model_value[c][s][2] : h; + h = av_clip(h << (c > 0 ? 1 : 0), 2, 14) - 2; + v = av_clip(v << (c > 0 ? 1 : 0), 2, 14) - 2; + + init_slice(database, h, v); synth_grain_8x8_c(out, out_stride, scale, shift, &database->db[h][v][y_offset][x_offset]); @@ -219,9 +223,9 @@ int ff_h274_apply_film_grain(AVFrame *out_frame, const AVFrame *in_frame, H274FilmGrainDatabase *database, const AVFilmGrainParams *params) { - AVFilmGrainH274Params h274 = params->codec.h274; + const AVFilmGrainH274Params *h274 = ¶ms->codec.h274; av_assert1(params->type == AV_FILM_GRAIN_PARAMS_H274); - if (h274.model_id != 0) + if (h274->model_id != 0) return AVERROR_PATCHWELCOME; av_assert1(out_frame->format == in_frame->format); @@ -241,21 +245,12 @@ int ff_h274_apply_film_grain(AVFrame *out_frame, const AVFrame *in_frame, const uint8_t * const in = in_frame->data[c]; const int in_stride = in_frame->linesize[c]; - if (!h274.component_model_present[c]) { + if (!h274->component_model_present[c]) { av_image_copy_plane(out, out_stride, in, in_stride, width * sizeof(uint8_t), height); continue; } - if (c > 0) { - // Adaptation for 4:2:0 chroma subsampling - for (int i = 0; i < h274.num_intensity_intervals[c]; i++) { - h274.comp_model_value[c][i][0] >>= 1; - h274.comp_model_value[c][i][1] *= 2; - h274.comp_model_value[c][i][2] *= 2; - } - } - // Film grain synthesis is done in 8x8 blocks, but the PRNG state is // only advanced in 16x16 blocks, so use a nested loop for (int y = 0; y < height; y += 16) { @@ -271,7 +266,7 @@ int ff_h274_apply_film_grain(AVFrame *out_frame, const AVFrame *in_frame, for (int xx = 0; xx < 16 && x+xx < width; xx += 8) { generate(grain + (y+yy) * grain_stride + (x+xx), grain_stride, in + (y+yy) * in_stride + (x+xx), in_stride, - database, &h274, c, invert, (x+xx) > 0, + database, h274, c, invert, (x+xx) > 0, y_offset + yy, x_offset + xx); } } -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".