From patchwork Fri Jul 19 23:19:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarek Samic X-Patchwork-Id: 14001 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 32D634481D0 for ; Sat, 20 Jul 2019 02:20:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0ADDB68AD4C; Sat, 20 Jul 2019 02:20:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7E12168AD3F for ; Sat, 20 Jul 2019 02:20:49 +0300 (EEST) Received: by mail-io1-f65.google.com with SMTP id f4so61852647ioh.6 for ; Fri, 19 Jul 2019 16:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ds4BNbcF7xCLnyxIQw5V/w6pMWYsr0uA5V7edKZyctI=; b=bKXuDKg0wiV2fw9VFVQVfnMCexNqtEz5791jZ2B/2F/fG9XfRyOydrYDIUHoVvrwfz oo2VVAHjcX7CzUU78ROp6SJYE49uIiwl6L37Y/qOn9VOwVGCN85W92ORbz2jqP55rtPZ D2aR62flcazP/sZK5yxhBCiFgCab/h8NPVSYg2CGuZMasPrYi7VfS5nHGbnnwaTjr43b IcSgupwIUpSKDc3zioEC25dw6ZVFT5fG9gpD1Bx9aaHGnq8nX/LzOXu7Ne45mVejFqas N/y6XMgDMazV6BtMltKCVD399k3sILoXw6n4HBLcu4t3+pmsbnFYVZgoYhEswuqabcaW Xjfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ds4BNbcF7xCLnyxIQw5V/w6pMWYsr0uA5V7edKZyctI=; b=KK9YUl+lkDjyT0IwxNguXXBE+P/c4sYIspqcVngRf9f50wRE6IMOzs3zMpz1QtEHHR O/KPKrukaTZZKF8ERZnGa/xzqCyblT+Wc9QlkdIaBt0T5gxH7ZbTf2NZum/Ebj2o8QzU St7pz5HTw7Z5aUy+8fo8qL+00O40N5sGeCVV0g3UCx78X7Ar5WiRpQ0cpdZ/5R68m60P DGDi2KzSWRYSK5OWrfn6Af64SZs5bHWEi5UB4jiZufXIZmcfXFwVlm5k5quobgPb9B+i 0U3eOty5scV05fyWryupWds1PRa0NV4GekHjYnSUZVwuHCLIlI8qAmfG5tPSVmpE+DMM mxww== X-Gm-Message-State: APjAAAWvff4ccCeDobagwuRj6Stt49vcKcKIsAOLUPDCj9+fOxanE9W6 Va+LSVa8P6NfIxQLbAhH1jfXaeSn5bs= X-Google-Smtp-Source: APXvYqyfmgi5M/cH0tpwtvDI7XvwfMVIJ7V4aLjDY4JggaXZgKW6B30sVitycaEecOAh8/2azqxQrw== X-Received: by 2002:a5d:80cd:: with SMTP id h13mr9791842ior.259.1563578447919; Fri, 19 Jul 2019 16:20:47 -0700 (PDT) Received: from cldire-arch.stormhome.local (rrcs-70-61-229-139.central.biz.rr.com. [70.61.229.139]) by smtp.gmail.com with ESMTPSA id e84sm38474803iof.39.2019.07.19.16.20.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 19 Jul 2019 16:20:47 -0700 (PDT) From: Jarek Samic To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Jul 2019 19:19:16 -0400 Message-Id: <20190719231917.16580-2-cldfire3@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190719231917.16580-1-cldfire3@gmail.com> References: <20190719231917.16580-1-cldfire3@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavfi: modify avfilter_get_matrix to support separate scale factors 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 Cc: Jarek Samic Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavfilter/transform.c | 13 ++++++++++--- libavfilter/transform.h | 30 +++++++++++++++++++----------- libavfilter/vf_deshake.c | 7 +++++-- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/libavfilter/transform.c b/libavfilter/transform.c index f92fc4d42f..f65de965cd 100644 --- a/libavfilter/transform.c +++ b/libavfilter/transform.c @@ -103,12 +103,19 @@ INTERPOLATE_METHOD(interpolate_biquadratic) } } -void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix) { - matrix[0] = zoom * cos(angle); +void avfilter_get_matrix( + float x_shift, + float y_shift, + float angle, + float scale_x, + float scale_y, + float *matrix +) { + matrix[0] = scale_x * cos(angle); matrix[1] = -sin(angle); matrix[2] = x_shift; matrix[3] = -matrix[1]; - matrix[4] = matrix[0]; + matrix[4] = scale_y * cos(angle); matrix[5] = y_shift; matrix[6] = 0; matrix[7] = 0; diff --git a/libavfilter/transform.h b/libavfilter/transform.h index 07436bfccb..0bdc9be123 100644 --- a/libavfilter/transform.h +++ b/libavfilter/transform.h @@ -60,20 +60,28 @@ enum FillMethod { #define FILL_DEFAULT FILL_ORIGINAL /** - * Get an affine transformation matrix from a given translation, rotation, and - * zoom factor. The matrix will look like: + * Get an affine transformation matrix from given translation, rotation, and + * zoom factors. The matrix will look like: * - * [ zoom * cos(angle), -sin(angle), x_shift, - * sin(angle), zoom * cos(angle), y_shift, - * 0, 0, 1 ] + * [ scale_x * cos(angle), -sin(angle), x_shift, + * sin(angle), scale_y * cos(angle), y_shift, + * 0, 0, 1 ] * - * @param x_shift horizontal translation - * @param y_shift vertical translation - * @param angle rotation in radians - * @param zoom scale percent (1.0 = 100%) - * @param matrix 9-item affine transformation matrix + * @param x_shift horizontal translation + * @param y_shift vertical translation + * @param angle rotation in radians + * @param scale_x x scale percent (1.0 = 100%) + * @param scale_y y scale percent (1.0 = 100%) + * @param matrix 9-item affine transformation matrix */ -void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix); +void avfilter_get_matrix( + float x_shift, + float y_shift, + float angle, + float scale_x, + float scale_y, + float *matrix +); /** * Add two matrices together. result = m1 + m2. diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c index c8480e74dd..9c89390e36 100644 --- a/libavfilter/vf_deshake.c +++ b/libavfilter/vf_deshake.c @@ -421,6 +421,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) const int chroma_width = AV_CEIL_RSHIFT(link->w, desc->log2_chroma_w); const int chroma_height = AV_CEIL_RSHIFT(link->h, desc->log2_chroma_h); int aligned; + float transform_zoom; out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { @@ -505,10 +506,12 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) deshake->last.angle = t.angle; deshake->last.zoom = t.zoom; + transform_zoom = 1.0 + t.zoom / 100.0; + // Generate a luma transformation matrix - avfilter_get_matrix(t.vec.x, t.vec.y, t.angle, 1.0 + t.zoom / 100.0, matrix_y); + avfilter_get_matrix(t.vec.x, t.vec.y, t.angle, transform_zoom, transform_zoom, matrix_y); // Generate a chroma transformation matrix - avfilter_get_matrix(t.vec.x / (link->w / chroma_width), t.vec.y / (link->h / chroma_height), t.angle, 1.0 + t.zoom / 100.0, matrix_uv); + avfilter_get_matrix(t.vec.x / (link->w / chroma_width), t.vec.y / (link->h / chroma_height), t.angle, transform_zoom, transform_zoom, matrix_uv); // Transform the luma and chroma planes ret = deshake->transform(link->dst, link->w, link->h, chroma_width, chroma_height, matrix_y, matrix_uv, INTERPOLATE_BILINEAR, deshake->edge, in, out);