From patchwork Fri Mar 6 04:06:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 18070 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 B824244A29D for ; Fri, 6 Mar 2020 06:06:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EB6968AEC5; Fri, 6 Mar 2020 06:06:46 +0200 (EET) 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 8DB1068ACA6 for ; Fri, 6 Mar 2020 06:06:39 +0200 (EET) Received: by mail-pl1-f195.google.com with SMTP id ay11so316680plb.0 for ; Thu, 05 Mar 2020 20:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ABe2pBYgtGPono5Bsv+wh7LAEIfmDYcMaQtMpqrhdUc=; b=eB6W7Y65HdSmvU7sxgs4w2tuBLg4+kojPUyBndYyvVU10GGV8I13k3XyucF4wmXLTD SmCznusDFOdjOTjR17rdGB4idSSWhAzFi0myeMszoktg2au2UllZDph5s/xcBNdnhM4m HdqzMVFWv+x1L0s/cbEXejTyzQJC8hGGobvDqINUasG2snlSMTD9BEeEBKiUO0p+s2ar 97EtgRch+/uN4oYuY+i+Z69EJJCQZwrnDqg9eHXYDE2H1hnq8RMAgNJTfmqgdZXx40K/ ClCtxxhOARJPRbScPW8SojJhcNskLExjLlliiuh8ibUvzam0IoFwVuROXTQ/v1Eqyzzz 6cVA== 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:mime-version :content-transfer-encoding; bh=ABe2pBYgtGPono5Bsv+wh7LAEIfmDYcMaQtMpqrhdUc=; b=oRBUC7zG1z8rowxMdkhywdj2sQ8/rq0pn3qCTQvulB/tDjbhQmpnZGdnvj6VnKawv4 MiUiIQkcOH8XNT6ksgQQq1+68xJIkqzVFLop8ZHWGrhiVrIfw0FWRu4Yy73pljx7vHAt tcFea+yhUJCoD5XtYcGt6Kt8M8PmTF0Ao6tZlZOgaxWOprTMJ+deesAKmdvO5vrBw7s4 Ueq6fz3IIdYkGyQbsD7HX81j2dGO1uQdUx3wtcmhzW1ZIcZdahygfM+LiqybIUDtJ/oM bJO9vyaQaApNEuworX7StVhdEOIkH67C3Y3VDUzRzEqcrWGfn0R5y9O/RZxDF4Che4Te g1cg== X-Gm-Message-State: ANhLgQ0Zjo+j7eCKXamBUV2ZZ+chEpoTHf58h0/JZaY2q0YGFQRc3gBd vi29cZWJpBxYK/N2AvX0bJMsiE5H X-Google-Smtp-Source: ADFU+vvF3EJGyJ2+r8OhRc6r4U2rEZTZe39167cyP3yasPDhUy6scLjV2XppeZej5dsQvZE4vsnh6Q== X-Received: by 2002:a17:90a:8403:: with SMTP id j3mr1590696pjn.8.1583467597243; Thu, 05 Mar 2020 20:06:37 -0800 (PST) Received: from localhost.localdomain (S0106ac2e8c9e4f8e.vc.shawcable.net. [174.7.242.108]) by smtp.gmail.com with ESMTPSA id t15sm32808819pgr.60.2020.03.05.20.06.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Mar 2020 20:06:36 -0800 (PST) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Mar 2020 20:06:29 -0800 Message-Id: <20200306040629.11870-1-mindmark@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avcodec/exr: add cineon lin2log trc 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: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Mark Reid Hi, The following patch adds a cineon lin2log color transfer characteristic to exr. The purpose of this patch is to allow preserving of the dynamic range of an exr file when converting to DPX or when using video filter such as 3d luts. I wasn't sure if adding it to the AVColorTransferCharacteristic enum was the correct approach, as this might be a exr specific thing but I figured it was a good starting point. changes since v1: - updated fate test --- libavcodec/exr.c | 2 ++ libavutil/color_utils.c | 14 ++++++++++++++ libavutil/pixfmt.h | 1 + tests/ref/fate/color_utils | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+) -- 2.25.0 diff --git a/libavcodec/exr.c b/libavcodec/exr.c index 1db30a1ae0..f2900a7921 100644 --- a/libavcodec/exr.c +++ b/libavcodec/exr.c @@ -1938,6 +1938,8 @@ static const AVOption options[] = { AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST2084 }, INT_MIN, INT_MAX, VD, "apply_trc_type"}, { "smpte428_1", "SMPTE ST 428-1", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST428_1 }, INT_MIN, INT_MAX, VD, "apply_trc_type"}, + { "lin2log", "Default Cineon/DPX log", 0, + AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_CINE_LIN2LOG }, INT_MIN, INT_MAX, VD, "apply_trc_type"}, { NULL }, }; diff --git a/libavutil/color_utils.c b/libavutil/color_utils.c index eb8bc7b5fc..e33c019d4a 100644 --- a/libavutil/color_utils.c +++ b/libavutil/color_utils.c @@ -167,6 +167,16 @@ static double avpriv_trc_arib_std_b67(double Lc) { (Lc <= 1.0 / 12.0 ? sqrt(3.0 * Lc) : a * log(12.0 * Lc - b) + c); } +static double avpriv_trc_cine_lin2log(double Lc) { + const double blackpoint = 95.0; + const double whitepoint = 685.0; + const double gamma = 0.6; + const double offset = pow(10, (blackpoint - whitepoint) * 0.002 / gamma); + const double gain = 1.0 / (1.0 - offset); + + return (log10((Lc + offset) / gain) / (0.002 / gamma) + whitepoint ) / 1023.0; +} + avpriv_trc_function avpriv_get_trc_function_from_trc(enum AVColorTransferCharacteristic trc) { avpriv_trc_function func = NULL; @@ -225,6 +235,10 @@ avpriv_trc_function avpriv_get_trc_function_from_trc(enum AVColorTransferCharact func = avpriv_trc_arib_std_b67; break; + case AVCOL_TRC_CINE_LIN2LOG: + func = avpriv_trc_cine_lin2log; + break; + case AVCOL_TRC_RESERVED0: case AVCOL_TRC_UNSPECIFIED: case AVCOL_TRC_RESERVED: diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h index 1c625cfc8a..1f3f9988d7 100644 --- a/libavutil/pixfmt.h +++ b/libavutil/pixfmt.h @@ -499,6 +499,7 @@ enum AVColorTransferCharacteristic { AVCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1 AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428, AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma" + AVCOL_TRC_CINE_LIN2LOG = 19, ///< Default Cineon/DPX linear to log 1D curve AVCOL_TRC_NB ///< Not part of ABI }; diff --git a/tests/ref/fate/color_utils b/tests/ref/fate/color_utils index 10f8055916..41221c131a 100644 --- a/tests/ref/fate/color_utils +++ b/tests/ref/fate/color_utils @@ -302,3 +302,22 @@ AVColorTransferCharacteristic=18 calling func(15123.456700) expected=2.725380 AVColorTransferCharacteristic=18 calling func(19845.889230) expected=2.773978 AVColorTransferCharacteristic=18 calling func(98678.423100) expected=3.060803 AVColorTransferCharacteristic=18 calling func(99999.899998) expected=3.063182 +AVColorTransferCharacteristic=19 calling func(-0.100000) expected=nan +AVColorTransferCharacteristic=19 calling func(-0.018054) expected=nan +AVColorTransferCharacteristic=19 calling func(-0.010000) expected=-0.240327 +AVColorTransferCharacteristic=19 calling func(-0.004490) expected=0.023018 +AVColorTransferCharacteristic=19 calling func(0.000000) expected=0.091481 +AVColorTransferCharacteristic=19 calling func(0.003162) expected=0.124195 +AVColorTransferCharacteristic=19 calling func(0.005000) expected=0.139945 +AVColorTransferCharacteristic=19 calling func(0.009000) expected=0.168690 +AVColorTransferCharacteristic=19 calling func(0.015000) expected=0.202405 +AVColorTransferCharacteristic=19 calling func(0.100000) expected=0.388020 +AVColorTransferCharacteristic=19 calling func(1.000000) expected=0.669584 +AVColorTransferCharacteristic=19 calling func(52.370000) expected=1.172373 +AVColorTransferCharacteristic=19 calling func(125.098765) expected=1.283258 +AVColorTransferCharacteristic=19 calling func(1999.111230) expected=1.636205 +AVColorTransferCharacteristic=19 calling func(6945.443000) expected=1.794815 +AVColorTransferCharacteristic=19 calling func(15123.456700) expected=1.893921 +AVColorTransferCharacteristic=19 calling func(19845.889230) expected=1.928531 +AVColorTransferCharacteristic=19 calling func(98678.423100) expected=2.132798 +AVColorTransferCharacteristic=19 calling func(99999.899998) expected=2.134492