[FFmpeg-devel] [PATCH] avcodec/exr: add cineon lin2log trc

Hendrik Leppkes h.leppkes at gmail.com
Fri Mar 6 11:49:05 EET 2020


On Fri, Mar 6, 2020 at 12:25 AM <mindmark at gmail.com> wrote:
>
> From: Mark Reid <mindmark at gmail.com>
>
> 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.
>
> ---
>  libavcodec/exr.c        |  2 ++
>  libavutil/color_utils.c | 14 ++++++++++++++
>  libavutil/pixfmt.h      |  1 +
>  3 files changed, 17 insertions(+)
>
> 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

AVColorTransferCharacteristic should follow ISO/IEC 23001-8 and its
following standards (ISO/IEC 23091 I believe). Not sure we have a
solution for specialized variants, but adding one right there would
collide with the next addition to the standard...

- Hendrik


More information about the ffmpeg-devel mailing list