From patchwork Sun Aug 8 17:29:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 29357 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp2207035ioh; Sun, 8 Aug 2021 10:31:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0VUj+F11pgmuMWdwgCpISVNLlcMnxdMDfrLMOjX+ztmw+rPUsFLCKIHE44M37+MCCk/xD X-Received: by 2002:a17:906:c9cb:: with SMTP id hk11mr18590621ejb.544.1628443865498; Sun, 08 Aug 2021 10:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628443865; cv=none; d=google.com; s=arc-20160816; b=C9Hz1ebUxJRS56zBWH0UObKvj3sVq21V+z30gPJWUN61cwv7cHkg+q9312buLqJktg tVdKhJqa5ee4F4m9pSmI+cXAKjbcEVmjX+QWB0K55WVtokrZToFo41MFhXfrZ8zkTqmP 8HfvTUoqFC8H3wOc3cLhQ+QT++vXdr2n1hGsmPLr2x41hgDLajmbswEc9LgHbuCSnR/b 7zmIcvqKlMGHR1lHoBfpU4ckNNlRD8n2x51qAEMNWsIt6QxFgJJK5d43Aldgv/OqfhTB p57ATdWXvPPPfljRYjj0hm20O/BjcZbDexA7v0PYDHvkG+7WzfP6IIVaY3//BI+xYHZ7 +mtw== 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=dTybKsgHqWshw2XvDxmVLQsD7Sr4LCv22Ucc4dxxCc8=; b=r/3jvYq2SOX6q8ZtjcTj8bPRq4EdVey9MzqtLvUHwURpDUlXpC39pGG5TbwWoqgMGH KCJ46M1oAwWVYogIm5rAJo/UkT+7Ogf/vgyA60NT+obPbBmQZcHEIl3LfIFtnisJO2GL OglRm0uKMsyfsNGyTUSgkIrIxM4RneG0bFBXxD1UqrJoGkP5ez3fbSz5UaQmgUlsfmnJ uHp7Fh9lUawE7j/1dxaotvpgQvYXZnnuzR8lcGBvLyiWySgb4jygwawFoPDZg5c5uDt4 w5XRy3s3b79FYfX+1W9G67SxZ25COg4Fuhq0slYIzlyjeiSDGBfrlSwgfdu7FAsH+ti+ 7Oog== 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 q6si16114950edj.487.2021.08.08.10.31.05; Sun, 08 Aug 2021 10:31:05 -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 64F9968A46C; Sun, 8 Aug 2021 20:30:01 +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 02A4B68A46C for ; Sun, 8 Aug 2021 20:29:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DAF74240699 for ; Sun, 8 Aug 2021 19:29:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dTffBEkh0_GO for ; Sun, 8 Aug 2021 19:29:48 +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 593E0240698 for ; Sun, 8 Aug 2021 19:29:46 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 49B493A1098; Sun, 8 Aug 2021 19:29:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 8 Aug 2021 19:29:39 +0200 Message-Id: <20210808172941.18238-8-anton@khirnov.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210808172941.18238-1-anton@khirnov.net> References: <20210808172941.18238-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/10] 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: PQyNmJyqeubd --- 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 7e70665cdd..b62fb37d4b 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -619,29 +619,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) @@ -788,11 +813,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);