From patchwork Tue Jun 9 23:56:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hutchinson X-Patchwork-Id: 20260 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 4A7C044979A for ; Wed, 10 Jun 2020 03:04:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2736468B4C8; Wed, 10 Jun 2020 03:04:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D07368B4C8 for ; Wed, 10 Jun 2020 03:04:07 +0300 (EEST) Received: by mail-qt1-f194.google.com with SMTP id u17so447687qtq.1 for ; Tue, 09 Jun 2020 17:04:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=ooAsN0u2Blr9B7Cng85cTwBmAoIveDSKuEX6sJCSBrk=; b=IaVJl0etQUWi2rUeQyqG6ItdW503NK4GwUp9b6eZvOuoheQLaRKKUG74CHyHWi3yom Y13MiMJUPEBmJoNEw9M/EKUSoYF+YSZ8x0l+zz0+0nuipdKqH4t7ATskUQ/F7ydGxhQp pjQdXJ/8vaXOShzQ3rmQv7QOxi5ZdxT4CwEgQaewAOFw85uqXjPDvLqc+EPrdlNUZ8tg mlV3xtpM+xw+5oGm1HQw67zagc/TfqE57YDTTwKBJxK18SonjocCOhsQQyPSjcLuiCGW nvB+hRoWr0TN3C53617JgGUoz+mKAb+M5F2JtFABHPpnmm1tg6H1ms14jwt/XpsuVQrA u8EQ== 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:mime-version :content-transfer-encoding; bh=ooAsN0u2Blr9B7Cng85cTwBmAoIveDSKuEX6sJCSBrk=; b=UF85IIorQNOWfT74yvu6q8+86i1U5wjG3gzUqF/GX7SUFddgKJVfHL4Yv2vfndldFs +icjJAvW3lzLhCRZ4H6dWclfflhuPDCF/LRVZCdXbDq9CEC1B0SBDnY8y/i6ox3ObKDF NXqOqsXh6Nsoh6NGCtSHHqmnqkAKUulbNeujArrJcjIoB6cEPEDS6NuS4I/LzC1WW79f 0ALbo7EoZuf7p2/Lp4PSwGnomIJF/jACfvVCfJNuIkHy55jhjuZYS6aL0K+osUqnWNbY ibm1XEb+CVJe83mj1zzuCrtxzoAWTHY4MKZboB3Ga9c3LvirgxmvMWfVivWllsZqTDIa sdLA== X-Gm-Message-State: AOAM530VB3NS+WfrG/0gZ8eKxPlkjsgesrUvMh+EZ1dL2dFrmS0y3hLe dfaozdNRRtxEflKC1fQvXGfspl4Y X-Google-Smtp-Source: ABdhPJyCJhU1+kEqX+IbHlaVN0zOfy0sJMOhhrC3y+RSPIKKOXln5dminURtCzHY8CwQvQrneTs78Q== X-Received: by 2002:aed:3b62:: with SMTP id q31mr450660qte.293.1591746980099; Tue, 09 Jun 2020 16:56:20 -0700 (PDT) Received: from localhost.localdomain ([75.115.109.114]) by smtp.gmail.com with ESMTPSA id s124sm8955343qke.40.2020.06.09.16.56.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 16:56:19 -0700 (PDT) From: Stephen Hutchinson To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jun 2020 19:56:14 -0400 Message-Id: <20200609235614.30918-1-qyot27@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avisynth: more intelligent RGB flipping 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" avs_is_color_space provides a generic way of checking whether the video is RGB, and has been available since 2.6. This means that GetProcAddress doesn't have to run on every frame. --- Also should probably be applied to the 4.3 branch as well. libavformat/avisynth.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 2c08ace8db..f029a0e842 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -57,6 +57,7 @@ typedef struct AviSynthLibrary { AVSC_DECLARE_FUNC(avs_get_version); AVSC_DECLARE_FUNC(avs_get_video_info); AVSC_DECLARE_FUNC(avs_invoke); + AVSC_DECLARE_FUNC(avs_is_color_space); AVSC_DECLARE_FUNC(avs_release_clip); AVSC_DECLARE_FUNC(avs_release_value); AVSC_DECLARE_FUNC(avs_release_video_frame); @@ -133,6 +134,7 @@ static av_cold int avisynth_load_library(void) LOAD_AVS_FUNC(avs_get_version, 0); LOAD_AVS_FUNC(avs_get_video_info, 0); LOAD_AVS_FUNC(avs_invoke, 0); + LOAD_AVS_FUNC(avs_is_color_space, 0); LOAD_AVS_FUNC(avs_release_clip, 0); LOAD_AVS_FUNC(avs_release_value, 0); LOAD_AVS_FUNC(avs_release_video_frame, 0); @@ -628,7 +630,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, const unsigned char *src_p; int n, i, plane, rowsize, planeheight, pitch, bits, ret; const char *error; - int avsplus av_unused; if (avs->curr_frame >= avs->vi->num_frames) return AVERROR_EOF; @@ -638,19 +639,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, if (discard) return 0; -#ifdef _WIN32 - /* Detect whether we're using AviSynth 2.6 or AviSynth+ by - * looking for whether avs_is_planar_rgb exists. */ - if (GetProcAddress(avs_library.library, "avs_is_planar_rgb") == NULL) - avsplus = 0; - else - avsplus = 1; -#else - /* AviSynth+ is now the only variant of AviSynth we support - * on Linux and macOS. */ - avsplus = 1; -#endif - bits = avs_library.avs_bits_per_pixel(avs->vi); /* Without the cast to int64_t, calculation overflows at about 9k x 9k @@ -687,14 +675,9 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, planeheight = avs_library.avs_get_height_p(frame, plane); /* Flip RGB video. */ - if (avs_is_rgb24(avs->vi) || avs_is_rgb(avs->vi)) { - src_p = src_p + (planeheight - 1) * pitch; - pitch = -pitch; - } - - /* Flip Planar RGB video */ - if (avsplus && (avs_library.avs_is_planar_rgb(avs->vi) || - avs_library.avs_is_planar_rgba(avs->vi))) { + if (avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR) || + avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR48) || + avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR64)) { src_p = src_p + (planeheight - 1) * pitch; pitch = -pitch; }