From patchwork Sat Mar 5 16:58:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 34621 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp49793nkx; Sat, 5 Mar 2022 08:59:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTILcEy6oDEnT4hYelvg0Rx/f/ALnA17ap4C9hisdZk71kPTHMl75v7r9frUO1AuvF2zZb X-Received: by 2002:a17:907:9619:b0:6d7:12d6:1e66 with SMTP id gb25-20020a170907961900b006d712d61e66mr3330847ejc.592.1646499557420; Sat, 05 Mar 2022 08:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646499557; cv=none; d=google.com; s=arc-20160816; b=p6lT6BbrAmSVPGUa/EQqg0p5ercB62C04WCkCWASyH9gWdtMAq23MiYG+aSi0bx3SH qu+yHFLQT638ouruOGafOxjjpsVn8POqKsqQwF1NUalnYIBYf2x/AajKtXvKsNBUm+nx RIzTtqHwZI+Hbw5jjwOhWdi7TuAzYWCDRnVswzXOiDfhyFUJ4s0Gtmri1WMcm9I+Pv5G cJpCAtfJgC54Xo2IYlk4qS8hVrNvfmlIyCDsPVLB/MaiPSUPgorDg4ybp/lZDGpmHoUJ n+h/PnOB9qO0fphqDkvlXLJKjock1T7GI/bD602+QuWfHqjPMzq4nvxOG8NcDRI7czHq Q6DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=V4PgFn+u+BGJuXaPfrFSTy+IetLG4O4rYAqOCrVC9J0=; b=G6WI4f84MGx+PicOSRXvQ9QgcKyg4SUhnLVlYc5e0kqQYnexMtbl1XhbW2pc2EU2du aEur4XYNgX088zfBaKF5Dq9ILAlTT0u1TQZi2ukudRGqn8tdGKyrWbezTzphveBuN5Kt 4KHzsHeJx49kblzQMXebNc728pHj7IafpnB85vXaXHpRXSa90LR9Ib9EvmZfcQny+G9U 060/MddsPITiaBJ8jENhD3w/o26oN40kHQ/X5sTXw8MqDpO5AO4nEdkDXFJ2xev3sCoz SINu7lPKSUTfWVWERohiBrTaVBQlNImdBsbp5clEWYW7BxCS7euFhoXuqaRohW5FeqbS OHkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=kuvMBumr; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v29-20020a17090610dd00b006d08c9350ebsi4719725ejv.640.2022.03.05.08.59.17; Sat, 05 Mar 2022 08:59:17 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=kuvMBumr; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8B9368B12A; Sat, 5 Mar 2022 18:58:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7779D68AF4C for ; Sat, 5 Mar 2022 18:58:44 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 08E4D47033; Sat, 5 Mar 2022 17:58:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1646499524; bh=eX7ajHkm6WlKM9YUbl1naIvOv76XMEc4mFJT1C4otkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kuvMBumr4qKMR7kidPMYIqiTogCIVjMH3W4FuAZuXBZFc9HixX0pOdvueLu1TtZVz /Z0JjEbpElHqxr+gD/wkFOjkjtDTCd/gslye+zKwc/3pjHWGEiVzDW0FdGV+fJ3s/R 4xGEoWWDYTyxIqU9DVnvzX78PpbugGX3/0WV2ZDs= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Mar 2022 17:58:33 +0100 Message-Id: <20220305165833.18668-3-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 3/3] h274: support a few more pixfmts 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cclTWSSugHyI From: Niklas Haas Based on extrapolating the intent of the SMPTE RDD 5-2006 spec, which only provides the parameter adaptation code for yuv420p. I've deduced that the change to `scale` has nothing to do with the reduction in grain frequency and merely reflects the fact that chroma planes have half the effective value range in typical integer encodings. As such, with this change can support e.g. 4:4:4 yuv420p as well, in which case we simply don't double the chroma grain frequencies. Still no support for 10-bit, but at least this is something. Signed-off-by: Niklas Haas --- libavcodec/h274.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libavcodec/h274.c b/libavcodec/h274.c index 265bd49ea1..e800351a3e 100644 --- a/libavcodec/h274.c +++ b/libavcodec/h274.c @@ -157,7 +157,8 @@ static av_always_inline void generate(int8_t *out, int out_stride, const uint8_t *in, int in_stride, H274FilmGrainDatabase *database, const AVFilmGrainH274Params *h274, - int c, int invert, int deblock, + int c, uint8_t xs, uint8_t ys, + int invert, int deblock, int y_offset, int x_offset) { const uint8_t shift = h274->log2_scale_factor + 6; @@ -200,8 +201,8 @@ static av_always_inline void generate(int8_t *out, int out_stride, 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; + h = av_clip(h << xs, 2, 14) - 2; + v = av_clip(v << ys, 2, 14) - 2; init_slice(database, h, v); synth_grain_8x8_c(out, out_stride, scale, shift, @@ -224,19 +225,34 @@ int ff_h274_apply_film_grain(AVFrame *out_frame, const AVFrame *in_frame, const AVFilmGrainParams *params) { const AVFilmGrainH274Params *h274 = ¶ms->codec.h274; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(out_frame->format); av_assert1(params->type == AV_FILM_GRAIN_PARAMS_H274); if (h274->model_id != 0) return AVERROR_PATCHWELCOME; av_assert1(out_frame->format == in_frame->format); - if (in_frame->format != AV_PIX_FMT_YUV420P) + switch (out_frame->format) { + case AV_PIX_FMT_YUV444P: + case AV_PIX_FMT_YUV440P: + case AV_PIX_FMT_YUV422P: + case AV_PIX_FMT_YUV420P: + case AV_PIX_FMT_YUV411P: + case AV_PIX_FMT_YUV410P: + // 8-bit YCbCr formats with varying subsampling + break; + + default: + // TODO: support higher bit depth formats! return AVERROR_PATCHWELCOME; + } for (int c = 0; c < 3; c++) { static const uint8_t color_offset[3] = { 0, 85, 170 }; uint32_t seed = Seed_LUT[(params->seed + color_offset[c]) % 256]; - const int width = c > 0 ? AV_CEIL_RSHIFT(out_frame->width, 1) : out_frame->width; - const int height = c > 0 ? AV_CEIL_RSHIFT(out_frame->height, 1) : out_frame->height; + const uint8_t xs = c > 0 ? desc->log2_chroma_w : 0; + const uint8_t ys = c > 0 ? desc->log2_chroma_h : 0; + const int width = AV_CEIL_RSHIFT(out_frame->width, xs); + const int height = AV_CEIL_RSHIFT(out_frame->height, ys); uint8_t * const out = out_frame->data[c]; const int out_stride = out_frame->linesize[c]; @@ -266,7 +282,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, xs, ys, invert, (x+xx) > 0, y_offset + yy, x_offset + xx); } }