From patchwork Mon Jul 12 11:07:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 28911 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp2812337ybk; Mon, 12 Jul 2021 04:09:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfDpw5/4xpAgY2fRbnRqIxr4p6wNKsf64gWTTKyPvlxSIWkUFwijkMaylF8Y6JSaRF6h4p X-Received: by 2002:aa7:da4f:: with SMTP id w15mr4357735eds.266.1626088147285; Mon, 12 Jul 2021 04:09:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626088147; cv=none; d=google.com; s=arc-20160816; b=vLXhhwu6YHPRDlOZHvnYPlAZja9B8SHVhspXnUhP1o6KsEEoy/7LgeNezIfU2zrsYy YoK+82WYloajkWv/kpP05xTHnUuvesmfEF0LNdXyuhLVAcNDPy8xRlm6vhaQZJQrRrqU zI0v5aFnF0gro2+qureQk5kIYF5x5HBJAA7KLZ6xEMLCdoSV/KJA7DY0n/RazH6N6bmV OHYJY/ECgNDQHRkZNQob+xfAc1cOOs1Zix488sdeex76Sg6cqvC6tE7vRf624zA8OLQ2 sO0MdgwuCoLcS3ayRwlMY503WGPQlAESEpe/M4xDjA2Qp6PkEplPMFBCyabIzGfw5X8M WfWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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:delivered-to; bh=fssuzNxo40bhBWXSNY8/4MCbglTivaUZHwmvzrO0+OU=; b=1Eos8tYarrhF3IvcE6xSTa9G+EUqPlVfpmKfP9GG+9Lo0QHVe4CgBW4FTzCzNHn+zS 4jTi/ZoPD63dLaPM8PoAUcaHOUOjQ7abI6DnZc51aEoO4n8cC/aAyK6v7asLeGm89IzE WKmXhJ8dHl6+IS0oYiaI8u9jfJ/iDYxjfpKZDVjv1bTCdEL1N6/qnHopGo5Pwa2pRGBa phLEVY8alTJNkzJ2BRLTsBKhFrGHggMpBWOgYn5nXqipdepPYJTrrHDdDxE/xwDbsIXl TG6Dk/D51PGfzWDTpm/Xu1DgB8EWZSqoA/QMdxPnuyN1Umz7p1JYdcOuyEvDrjHSZ0CS J7ZA== ARC-Authentication-Results: i=1; mx.google.com; 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 eb9si16559157ejc.720.2021.07.12.04.09.07; Mon, 12 Jul 2021 04:09:07 -0700 (PDT) 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; 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 4CA3968A980; Mon, 12 Jul 2021 14:08:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67CD568A94D for ; Mon, 12 Jul 2021 14:07:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0F25D240695 for ; Mon, 12 Jul 2021 13:07:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cIQCcSUaxaqa for ; Mon, 12 Jul 2021 13:07:55 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id AF0F9240697 for ; Mon, 12 Jul 2021 13:07:52 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id ADEDB3A0BCA; Mon, 12 Jul 2021 13:07:50 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jul 2021 13:07:07 +0200 Message-Id: <20210712110709.15532-7-anton@khirnov.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210712110709.15532-1-anton@khirnov.net> References: <20210712110709.15532-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/8] lavfi/vf_scale: convert to the frame-based sws API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9UzOr+dL96ju Content-Length: 3551 --- libavfilter/vf_scale.c | 73 ++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 39ab3a4b28..cdff3ab7ed 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -620,29 +620,54 @@ static int request_frame_ref(AVFilterLink *outlink) return ff_request_frame(outlink->src->inputs[1]); } -static int scale_slice(ScaleContext *scale, AVFrame *out_buf, AVFrame *cur_pic, struct SwsContext *sws, int y, int h, int mul, int field) +static void frame_offset(AVFrame *frame, int dir, int is_pal) { - const uint8_t *in[4]; - uint8_t *out[4]; - int in_stride[4],out_stride[4]; - int i; - - for (i=0; i<4; i++) { - int vsub= ((i+1)&2) ? scale->vsub : 0; - ptrdiff_t in_offset = ((y>>vsub)+field) * cur_pic->linesize[i]; - ptrdiff_t out_offset = field * out_buf->linesize[i]; - in_stride[i] = cur_pic->linesize[i] * mul; - out_stride[i] = out_buf->linesize[i] * mul; - in[i] = FF_PTR_ADD(cur_pic->data[i], in_offset); - out[i] = FF_PTR_ADD(out_buf->data[i], out_offset); - } - if (scale->input_is_pal) - in[1] = cur_pic->data[1]; - if (scale->output_is_pal) - out[1] = out_buf->data[1]; + for (int i = 0; i < 4 && frame->data[i]; i++) { + if (i == 1 && is_pal) + break; + frame->data[i] += frame->linesize[i] * dir; + } +} + +static int scale_field(ScaleContext *scale, AVFrame *dst, AVFrame *src, + int field) +{ + int orig_h_src = src->height; + int orig_h_dst = dst->height; + int ret; + + // offset the data pointers for the bottom field + if (field) { + frame_offset(src, 1, scale->input_is_pal); + frame_offset(dst, 1, scale->output_is_pal); + } + + // take every second line + for (int i = 0; i < 4; i++) { + src->linesize[i] *= 2; + dst->linesize[i] *= 2; + } + src->height /= 2; + dst->height /= 2; - return sws_scale(sws, in, in_stride, y/mul, h, - out,out_stride); + ret = sws_scale_frame(scale->isws[field], dst, src); + if (ret < 0) + return ret; + + // undo the changes we made above + for (int i = 0; i < 4; i++) { + src->linesize[i] /= 2; + dst->linesize[i] /= 2; + } + src->height = orig_h_src; + dst->height = orig_h_dst; + + if (field) { + frame_offset(src, -1, scale->input_is_pal); + frame_offset(dst, -1, scale->output_is_pal); + } + + return 0; } static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out) @@ -789,11 +814,11 @@ scale: INT_MAX); if (scale->interlaced>0 || (scale->interlaced<0 && in->interlaced_frame)) { - ret = scale_slice(scale, out, in, scale->isws[0], 0, (link->h+1)/2, 2, 0); + ret = scale_field(scale, out, in, 0); if (ret >= 0) - ret = scale_slice(scale, out, in, scale->isws[1], 0, link->h /2, 2, 1); + ret = scale_field(scale, out, in, 1); } else { - ret = scale_slice(scale, out, in, scale->sws, 0, link->h, 1, 0); + ret = sws_scale_frame(scale->sws, out, in); } av_frame_free(&in);