From patchwork Thu May 16 07:12:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 13130 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 1964344848D for ; Thu, 16 May 2019 10:19:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EEAF568A6A1; Thu, 16 May 2019 10:19:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAD8F68A2C0 for ; Thu, 16 May 2019 10:19:06 +0300 (EEST) Received: by mail-pl1-f195.google.com with SMTP id f97so1162274plb.5 for ; Thu, 16 May 2019 00:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Dg2V7bKkS+Yk5EzC3Zaq9zFzXZcsRlf4l59BK1T3d2E=; b=IgqH0BS4YXQ2y5RM+Zs/lJPOxTSpQSc2m8GeaUey9BURxSYGKgTKObnsUHtnVJyY98 KDRSVhyKGqDUBMedlIgSj1Jc7PVFJlVlcIG2x39EKy7igFrtDM7BoFb5sSi39BjSpkiP PLzcKuoZ/eOLUSHTrzHGjchE4gyFLe69xgzxeJ7fs2fmTYLCIUk2B1VmuGmxxhGqhDRE HhqETfCVUo1Ae+TbIioQeKfu2XHCzEyQAwwnRZ6jow0MyNP4Nq+F7MlDTFz40xJetogx 6wdUkQrFGm6Hf6GwPyYNW2dxnjGJpRI/6d0NUxDTaSesTW1ZDr/l8r+F3PWfDpmKsKh+ MUag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Dg2V7bKkS+Yk5EzC3Zaq9zFzXZcsRlf4l59BK1T3d2E=; b=sFwU2PFhg8LEW4Q5d6EDs6GzLUEHSvNIauxADEaMuwRLmUedbPYqGIdjluH1ItIli4 sJtK0FB4vKIJu9Rdh8Fu7Sx7Zo2foYDGvHBaqy6nBXUMatxeDzdXsak4/XfaloToxUzy bnjlB15fv8f6y/DmHDYNpBFB+f3fiCTeGjcdJJO9ft9i9I1O6WEwclTJGCy6qmWpuVxa RRo3+QTDG5x9RxTg7D/sW8bJxMu3m3gVDPV4BSupPULgqT053+/UAeEwa8dtcGSbemwH Is6rmSnkM6groQpk56tv7fsrm7e+W5kg/0ihg+3uapT6N6y3oay0BCrWbq1vjutUFLUc kMwA== X-Gm-Message-State: APjAAAWJmpsK4oScd1aUV77Rdxm1+9ei846bT4nbdSnWfy1gH9wP1KtA lWxfeWdYdStA/xFSsWQVTndZazPNlRM= X-Google-Smtp-Source: APXvYqzJYBqt/3BjW5lioElrDv0cdvzwvWIfB/k9xx5xbJA7lndo9yaEWIU+DxJuG2Lgt+J+NrbQNA== X-Received: by 2002:a17:902:70c6:: with SMTP id l6mr30665637plt.84.1557990749758; Thu, 16 May 2019 00:12:29 -0700 (PDT) Received: from super.lan (c-73-193-9-32.hsd1.wa.comcast.net. [73.193.9.32]) by smtp.gmail.com with ESMTPSA id d67sm7049861pfa.35.2019.05.16.00.12.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 00:12:29 -0700 (PDT) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 May 2019 00:12:21 -0700 Message-Id: <20190516071222.30876-1-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH v3 1/2] lavu/display: add av_display_rotation_hflip_get and bump version 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add av_display_rotation_hflip_get to get information whether the matrix indicates horizontal flip. --- doc/APIchanges | 3 +++ libavutil/display.c | 13 +++++++++++++ libavutil/display.h | 14 ++++++++++++++ libavutil/tests/display.c | 26 ++++++++++++++++++++++++++ libavutil/version.h | 2 +- tests/ref/fate/display | 16 ++++++++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index cf426e2e3b..88e98cb885 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2019-05-16 - XXXXXXXXXX - lavu 56.29.100 - display.h + Add av_display_rotation_hflip_get + 2019-05-15 - b79b29ddb1 - lavu 56.28.100 - tx.h Add av_tx_init(), av_tx_uninit() and related definitions. diff --git a/libavutil/display.c b/libavutil/display.c index a0076e067b..89a1c6dcd1 100644 --- a/libavutil/display.c +++ b/libavutil/display.c @@ -71,3 +71,16 @@ void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip) for (i = 0; i < 9; i++) matrix[i] *= flip[i % 3]; } + +double av_display_rotation_hflip_get(const int32_t matrix[9], int *hflip) +{ + int32_t m[9]; + *hflip = 0; + memcpy(m, matrix, sizeof(m)); + + if (CONV_FP(m[0]) * CONV_FP(m[4]) < CONV_FP(m[1]) * CONV_FP(m[3])) { + *hflip = 1; + av_display_matrix_flip(m, 1, 0); + } + return av_display_rotation_get(m); +} diff --git a/libavutil/display.h b/libavutil/display.h index 515adad795..c37d10c741 100644 --- a/libavutil/display.h +++ b/libavutil/display.h @@ -106,6 +106,20 @@ void av_display_rotation_set(int32_t matrix[9], double angle); */ void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip); +/** + * Extract the rotation component and hflip status of the transformation matrix. + * + * @param matrix the transformation matrix + * @param hflip will be set to 1 if the matrix indicates horizontal flip + * @return the angle (in degrees) by which the transformation rotates the frame + * counterclockwise. The angle will be in range [-180.0, 180.0], + * or NaN if the matrix is singular. + * + * @note floating point numbers are inherently inexact, so callers are + * recommended to round the return value to nearest integer before use. + */ +double av_display_rotation_hflip_get(const int32_t matrix[9], int* hflip); + /** * @} * @} diff --git a/libavutil/tests/display.c b/libavutil/tests/display.c index 893ebb5543..b611f52828 100644 --- a/libavutil/tests/display.c +++ b/libavutil/tests/display.c @@ -35,6 +35,8 @@ static void print_matrix(int32_t matrix[9]) int main(void) { int32_t matrix[9]; + int hflip = 0; + double degree; // Set the matrix to 90 degrees av_display_rotation_set(matrix, 90); @@ -56,6 +58,30 @@ int main(void) print_matrix(matrix); printf("degrees: %f\n", av_display_rotation_get(matrix)); + // Set the matrix to 90 degrees + av_display_rotation_set(matrix, 90); + print_matrix(matrix); + degree = av_display_rotation_hflip_get(matrix, &hflip); + printf("degrees: %f, hflip: %i\n", degree, hflip); + + // Set the matrix to -45 degrees + av_display_rotation_set(matrix, -45); + print_matrix(matrix); + degree = av_display_rotation_hflip_get(matrix, &hflip); + printf("degrees: %f, hflip: %i\n", degree, hflip); + + // flip horizontal + av_display_matrix_flip(matrix, 1, 0); + print_matrix(matrix); + degree = av_display_rotation_hflip_get(matrix, &hflip); + printf("degrees: %f, hflip: %i\n", degree, hflip); + + // flip vertical + av_display_matrix_flip(matrix, 0, 1); + print_matrix(matrix); + degree = av_display_rotation_hflip_get(matrix, &hflip); + printf("degrees: %f, hflip: %i\n", degree, hflip); + return 0; } diff --git a/libavutil/version.h b/libavutil/version.h index 91ab71604b..dccbb38585 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 28 +#define LIBAVUTIL_VERSION_MINOR 29 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/tests/ref/fate/display b/tests/ref/fate/display index 251e7e0cdf..c91b19ef07 100644 --- a/tests/ref/fate/display +++ b/tests/ref/fate/display @@ -14,3 +14,19 @@ degrees: 135.000000 -46340 -46340 0 0 0 1073741824 degrees: -135.000000 +0 65536 0 +-65536 0 0 +0 0 1073741824 +degrees: -90.000000, hflip: 0 +46340 -46340 0 +46340 46340 0 +0 0 1073741824 +degrees: 45.000000, hflip: 0 +-46340 -46340 0 +-46340 46340 0 +0 0 1073741824 +degrees: 45.000000, hflip: 1 +-46340 46340 0 +-46340 -46340 0 +0 0 1073741824 +degrees: -135.000000, hflip: 0