From patchwork Wed Jul 19 20:17:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 4374 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp1237073vsb; Wed, 19 Jul 2017 13:18:06 -0700 (PDT) X-Received: by 10.28.98.137 with SMTP id w131mr89803wmb.158.1500495486892; Wed, 19 Jul 2017 13:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500495486; cv=none; d=google.com; s=arc-20160816; b=YI51WNrulGRaRrOZMpzJGpiNFtBgtf/LMfybtvmtnMOa6Z3pm/6wH3EncVV3BMWG4q 6rEKdBAlxAR17o9GYD96Ba8p0mgsxcRIFx32qVUyKtNkDz0kLoFloM1IBpIot8eQWjwg VPNwkg3Mla1iADgsz31R2OH5Vobs9UsaC5SVAnvFe8T+siI0zCZ4/Q/+Qj015B5ZS6fg QNf4TcOisdR0PlTdJOK9uaONuRyQ3Y8ShrQ8qXOPHTUHGR6iba7KBItALjWgupWJgns3 qeT08Xc5r29w2XVoXxPlEWI/uPLvzuVDj8Ikg7NMHV6o2GS85bWdYKtcxcjcqHpGXduC mxiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=FKuhzmN4JELyPWXSskhmH5bZm9YYTmz1frmpqRPfyzs=; b=fbBUFvCnFjgOX+4Cgv3Wt/u67mQOVkZv1WEo+UUDqR7jz7yBs0WIcOmE5aev12hOm5 y/JFgGqSYdzt1m5sr4Yh+HhwmoMBgtU4GxPjx2hMXkhN1JZr3DtmhH3TiTqrzPpBdUhi gEz42dqWSuyCqsmx1nWyRxZhrIwxpKFi/M9KtrKPKyHylIXLVR3alZTN1XkPe6tpfHt4 7f93Y1Dm/rcEDRzUx8Qy8lIz9m/EE+tO8OG2zC0RcNJpBCaUjx+E6vVKNhE5ngOimcBc kvJ0dZXONFcP9wIL6zeF7gjPjUgowNtmEM5lmSnVxmQ8+xaqqjBjQomOjVI3+DtROEqi 5+KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=klQDE7fL; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y36si4669026wrc.77.2017.07.19.13.18.05; Wed, 19 Jul 2017 13:18:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=klQDE7fL; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D288689B73; Wed, 19 Jul 2017 23:17:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f182.google.com (mail-qt0-f182.google.com [209.85.216.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 087BF689AC7 for ; Wed, 19 Jul 2017 23:17:48 +0300 (EEST) Received: by mail-qt0-f182.google.com with SMTP id 32so9824188qtv.1 for ; Wed, 19 Jul 2017 13:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Nv4NhdKJ4PW8Mwg1bN9SCZBcPh9XF7LvfBTIH9rkI6o=; b=klQDE7fLUFMOVEearREg4cS5oZsozcxIA8ExM9beq4Xwvm5ejhsvRZUBw0hWpvDCtH 04jnvR9XSdxinCzPhwmwFTOtqjRbGzVkfiPmPaLzhbEmgs6vpLoRty2tqcGrkEhdgf1W ay2QtzWScyGHIgBI9mSP4bbW+06JwMTJ8t10pSPxFZs9CZ6v1mbxNOVYySG3yx2QcIQ0 KhpDKxlWlZuAmlDl1rK3HMRuF/USxhE3TCuTKq7pV7Fbqim3gInZ0TkEE4Hi3MmOx/lJ bYn2vP2AUn5dLcF49Rro7wtBad00HSOBrKZkvoNCBcsgOU64OPuZhD+jVVEeaLY+DFz1 zdhQ== 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:in-reply-to :references; bh=Nv4NhdKJ4PW8Mwg1bN9SCZBcPh9XF7LvfBTIH9rkI6o=; b=EQcHV1iTa1ZIOHj5UYkGU6LITlb+CTwY8btepcukieKh32e/+LVcCSU0lOrlZMe8cE C1p/1gwRLASvmtYUkAhPYij3IcDU6g+OlkjCYNq6Yne5f9WaBpd7F2qgA3tXldC4BUp8 VGtbWh6oirrVxVzgu7gXrbVgYErRuj5/ICAhcjuUjKJxKd0DJVL7pRQxW5ASDX1OzpCn kY8yAY/ACCLgHmM5KTHOpv8RsSkiaGVVdDNi+tlyDnFpd/4p3QltRK9RFT1TAPQowLKK zgw1nBkKoXT87/csYOeoRnkoT4crszcvTNsZlYow6V+q5b+izPKRHd3nmgvcJYcZBKso 3Z3g== X-Gm-Message-State: AIVw113StHbXLvjojvDwjR9T3+Nh5bZSBOEZTi/l9efFomPcd9AHRKNP 6nlW3C2SPm96aF+J X-Received: by 10.237.46.193 with SMTP id k59mr1901215qtd.158.1500495474029; Wed, 19 Jul 2017 13:17:54 -0700 (PDT) Received: from vimacbookpro.vimeo.iac.corp (93-40-167-184.ip39.fastwebnet.it. [93.40.167.184]) by smtp.gmail.com with ESMTPSA id m64sm622703qkm.62.2017.07.19.13.17.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 19 Jul 2017 13:17:52 -0700 (PDT) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Jul 2017 22:17:49 +0200 Message-Id: <20170719201749.5625-1-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170718193346.69345-1-vittorio.giovara@gmail.com> References: <20170718193346.69345-1-vittorio.giovara@gmail.com> Subject: [FFmpeg-devel] [PATCH] Add tonemap filter 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" Based off mpv automatic tonemapping capabilities. Signed-off-by: Vittorio Giovara --- Fixed documentation build. Vittorio doc/filters.texi | 106 ++++++++++++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_tonemap.c | 310 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 418 insertions(+) create mode 100644 libavfilter/vf_tonemap.c diff --git a/doc/filters.texi b/doc/filters.texi index 930ca4cfab..f1a9d3ab93 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -14295,6 +14295,111 @@ Vertical low-pass filtering can only be enabled for @option{mode} @end table +@section tonemap +Tone map colors from different dynamic ranges. + +This filter expects data in single precision floating point, as it needs to +operate on (and can output) out-of-range values. Another filter, such as +@ref{zscale}, is needed to convert the resulting frame to a usable format. + +The tonemapping algorithms implemented only work on linear light, so input +data should be linearized beforehand (and possibly correctly tagged). + +@example +ffmpeg -i INPUT -vf zscale=transfer=linear,tonemap=clip,zscale=transfer=bt709,format=yuv420p OUTPUT +@end example + +@subsection Options +The filter accepts the following options. + +@table @option +@item tonemap +Set the tone map algorithm to use. + +Possible values are: +@table @var +@item none +Do not apply any tone map, only desaturate overbright pixels. + +@item clip +Hard-clip any out-of-range values. Use it for perfect color accuracy for +in-range values, while distorting out-of-range values. + +@item linear +Stretch the entire reference gamut to a linear multiple of the display. + +@item gamma +Fit a logarithmic transfer between the tone curves. + +@item reinhard +Preserve overall image brightness with a simple curve, using nonlinear +contrast, which results in flattening details and degrading color accuracy. + +@item hable +Peserve both dark and bright details better than @var{reinhard}, at the cost +of slightly darkening everything. Use it when detail preservation is more +important than color and brightness accuracy. + +@item mobius +Smoothly map out-of-range values, while retaining contrast and colors for +in-range material as much as possible. Use it when color accuracy is more +important than detail preservation. +@end table + +Default is none. + +@item param +Tune the tone mapping algorithm. + +This affects the following algorithms: +@table @var +@item none +Ignored. + +@item linear +Specifies the scale factor to use while stretching. +Default to 1.0. + +@item gamma +Specifies the exponent of the function. +Default to 1.8. + +@item clip +Specify an extra linear coefficient to multiply into the signal before clipping. +Default to 1.0. + +@item reinhard +Specify the local contrast coefficient at the display peak. +Default to 0.5, which means that in-gamut values will be about half as bright +as when clipping. + +@item hable +Ignored. + +@item mobius +Specify the transition point from linear to mobius transform. Every value +below this point is guaranteed to be mapped 1:1. The higher the value, the +more accurate the result will be, at the cost of losing bright details. +Default to 0.3, which due to the steep initial slope still preserves in-range +colors fairly accurately. +@end table + +@item desat +Apply desaturation for highlights that exceed this level of brightness. The +higher the parameter, the more color information will be preserved. This +setting helps prevent unnaturally blown-out colors for super-highlights, by +(smoothly) turning into white instead. This makes images feel more natural, +at the cost of reducing information about out-of-range colors. + +The default of 2.0 is somewhat conservative and will mostly just apply to +skies or directly sunlit surfaces. A setting of 0.0 disables this option. + +@item peak +Override signal/nominal/reference peak with this value. Useful when the +embedded peak information in display metadata is not reliable or when tone +mapping from a lower range to a higher range. +@end table + @section transpose Transpose rows with columns in the input video and optionally flip it. @@ -15458,6 +15563,7 @@ zoompan=z='min(max(zoom,pzoom)+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih @end example @end itemize +@anchor{zscale} @section zscale Scale (resize) the input video, using the z.lib library: https://github.com/sekrit-twc/zimg. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index f023a0d5d6..0ada5d77b5 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -310,6 +310,7 @@ OBJS-$(CONFIG_THRESHOLD_FILTER) += vf_threshold.o OBJS-$(CONFIG_THUMBNAIL_FILTER) += vf_thumbnail.o OBJS-$(CONFIG_TILE_FILTER) += vf_tile.o OBJS-$(CONFIG_TINTERLACE_FILTER) += vf_tinterlace.o +OBJS-$(CONFIG_TONEMAP_FILTER) += vf_tonemap.o OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o OBJS-$(CONFIG_TRIM_FILTER) += trim.o OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index c1c52330ef..fa31e8d52a 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -321,6 +321,7 @@ static void register_all(void) REGISTER_FILTER(THUMBNAIL, thumbnail, vf); REGISTER_FILTER(TILE, tile, vf); REGISTER_FILTER(TINTERLACE, tinterlace, vf); + REGISTER_FILTER(TONEMAP, tonemap, vf); REGISTER_FILTER(TRANSPOSE, transpose, vf); REGISTER_FILTER(TRIM, trim, vf); REGISTER_FILTER(UNSHARP, unsharp, vf); diff --git a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c new file mode 100644 index 0000000000..35b5421d33 --- /dev/null +++ b/libavfilter/vf_tonemap.c @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2017 Vittorio Giovara + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * tonemap algorithms + */ + +#include +#include +#include + +#include "libavutil/imgutils.h" +#include "libavutil/internal.h" +#include "libavutil/mastering_display_metadata.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" + +#include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "video.h" + +#define REFERENCE_WHITE 100.0f + +enum TonemapAlgorithm { + TONEMAP_NONE, + TONEMAP_LINEAR, + TONEMAP_GAMMA, + TONEMAP_CLIP, + TONEMAP_REINHARD, + TONEMAP_HABLE, + TONEMAP_MOBIUS, + TONEMAP_MAX, +}; + +typedef struct TonemapContext { + const AVClass *class; + + enum TonemapAlgorithm tonemap; + double param; + double desat; + double peak; +} TonemapContext; + +static const enum AVPixelFormat pix_fmts[] = { + AV_PIX_FMT_YUV444F32, + AV_PIX_FMT_YUVA444F32, + AV_PIX_FMT_NONE, +}; + +static int query_formats(AVFilterContext *ctx) +{ + return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); +} + +static av_cold int init(AVFilterContext *ctx) +{ + TonemapContext *s = ctx->priv; + + switch(s->tonemap) { + case TONEMAP_GAMMA: + if (isnan(s->param)) + s->param = 1.8f; + break; + case TONEMAP_REINHARD: + if (!isnan(s->param)) + s->param = (1.0f - s->param) / s->param; + break; + case TONEMAP_MOBIUS: + if (isnan(s->param)) + s->param = 0.3f; + break; + } + + if (isnan(s->param)) + s->param = 1.0f; + + return 0; +} + +static double determine_signal_peak(AVFrame *in) +{ + AVFrameSideData *sd = av_frame_get_side_data(in, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + double peak = 0; + + if (sd) { + AVContentLightMetadata *clm = (AVContentLightMetadata *)sd->data; + peak = clm->MaxCLL / REFERENCE_WHITE; + } + + sd = av_frame_get_side_data(in, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + if (!peak && sd) { + AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data; + if (metadata->has_luminance) { + peak = av_q2d(metadata->max_luminance) / REFERENCE_WHITE; + } + } + + /* smpte2084 needs the side data above to work correctly + * if missing, assume that the original transfer was arib-std-b67 */ + if (!peak) + peak = 12; + + return peak; +} + +static float hable(float in) +{ + float a = 0.15f, b = 0.50f, c = 0.10f, d = 0.20f, e = 0.02f, f = 0.30f; + return (in * (in * a + b * c) + d * e) / (in * (in * a + b) + d * f) - e / f; +} + +static float mobius(float in, float j, double peak) +{ + float a, b; + + if (in <= j) + return in; + + a = -j * j * (peak - 1.0f) / (j * j - 2.0f * j + peak); + b = (j * j - 2.0f * j * peak + peak) / (peak - 1.0f); + + return (b * b + 2.0f * b * j + j * j) / (b - a) * (in + a) / (in + b); +} + +static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in, + const AVPixFmtDescriptor *desc, int x, int y, double peak) +{ + const float *y_in = (const float *)(in->data[0] + x * desc->comp[0].step + y * in->linesize[0]); + const float *cb_in = (const float *)(in->data[1] + x * desc->comp[1].step + y * in->linesize[1]); + const float *cr_in = (const float *)(in->data[2] + x * desc->comp[2].step + y * in->linesize[2]); + float *y_out = (float *)(out->data[0] + x * desc->comp[0].step + y * out->linesize[0]); + float *cb_out = (float *)(out->data[1] + x * desc->comp[1].step + y * out->linesize[1]); + float *cr_out = (float *)(out->data[2] + x * desc->comp[2].step + y * out->linesize[2]); + + /* prevent division by zero, just copy any input */ + if (!*y_in) { + *y_out = *y_in; + *cb_out = *cb_in; + *cr_out = *cr_in; + return; + } + + /* work on luma only to prevent excessive discoloration */ + switch(s->tonemap) { + default: + case TONEMAP_NONE: + *y_out = *y_in; + break; + case TONEMAP_LINEAR: + *y_out = *y_in * s->param / peak; + break; + case TONEMAP_GAMMA: + *y_out = pow(*y_in / peak, 1.0f / s->param); + break; + case TONEMAP_CLIP: + *y_out = av_clipf(*y_in * s->param, 0, 1.0f); + break; + case TONEMAP_HABLE: + *y_out = hable(*y_in) / hable(peak); + break; + case TONEMAP_REINHARD: + *y_out = *y_in / (*y_in + s->param) * (peak + s->param) / peak; + break; + case TONEMAP_MOBIUS: + *y_out = mobius(*y_in, s->param, peak); + break; + } + + /* cb and cr are relative to y, so rescale if needed */ + *cb_out = *cb_in * (*y_out / *y_in); + *cr_out = *cr_in * (*y_out / *y_in); + + /* desaturate to prevent unnatural colors */ + if (s->desat > 0 && s->desat < peak) { + float desat = FFMAX(*y_in - s->desat, 1e-6) / FFMAX(*y_in, 1e-6); + *cb_out *= 1.0f - desat; + *cr_out *= 1.0f - desat; + } +} + +static int filter_frame(AVFilterLink *link, AVFrame *in) +{ + TonemapContext *s = link->dst->priv; + AVFilterLink *outlink = link->dst->outputs[0]; + AVFrame *out; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format); + const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format); + int ret, x, y; + double peak = s->peak; + + /* any other transfer will yield incorrect results */ + if (in->color_trc != AVCOL_TRC_LINEAR) + av_log(outlink->dst, AV_LOG_WARNING, + "Tonemapping is supposed to work on linear light\n"); + + if (!desc || !odesc) { + av_frame_free(&in); + return AVERROR_BUG; + } + + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + av_frame_free(&in); + return AVERROR(ENOMEM); + } + + ret = av_frame_copy_props(out, in); + if (ret < 0) { + av_frame_free(&in); + av_frame_free(&out); + return ret; + } + + /* read peak from side data if not passed in */ + if (!peak) { + peak = determine_signal_peak(in); + av_log(outlink->dst, AV_LOG_DEBUG, "Computed signal peak: %f\n", peak); + } + + /* do the tone map */ + for (y = 0; y < in->height; y++) + for (x = 0; x < in->width; x++) + tonemap(s, out, in, desc, x, y, peak); + + /* copy/generate alpha if needed */ + if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) { + av_image_copy_plane(out->data[3], out->linesize[3], + in->data[3], in->linesize[3], + out->linesize[3], outlink->h); + } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) { + for (y = 0; y < outlink->h; y++) + memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w); + } + + av_frame_free(&in); + + return ff_filter_frame(outlink, out); +} + +#define OFFSET(x) offsetof(TonemapContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM +static const AVOption tonemap_options[] = { + { "tonemap", "tonemap algorithm selection", OFFSET(tonemap), AV_OPT_TYPE_INT, {.i64 = TONEMAP_NONE}, TONEMAP_NONE, TONEMAP_MAX - 1, FLAGS, "tonemap" }, + { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_NONE}, 0, 0, FLAGS, "tonemap" }, + { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_LINEAR}, 0, 0, FLAGS, "tonemap" }, + { "gamma", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_GAMMA}, 0, 0, FLAGS, "tonemap" }, + { "clip", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_CLIP}, 0, 0, FLAGS, "tonemap" }, + { "reinhard", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_REINHARD}, 0, 0, FLAGS, "tonemap" }, + { "hable", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_HABLE}, 0, 0, FLAGS, "tonemap" }, + { "mobius", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_MOBIUS}, 0, 0, FLAGS, "tonemap" }, + { "param", "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS }, + { "desat", "desaturation strength", OFFSET(desat), AV_OPT_TYPE_DOUBLE, {.dbl = 2}, 0, DBL_MAX, FLAGS }, + { "peak", "signal peak override", OFFSET(peak), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, DBL_MAX, FLAGS }, + { NULL } +}; + +static const AVClass tonemap_class = { + .class_name = "tonemap", + .item_name = av_default_item_name, + .option = tonemap_options, + .version = LIBAVUTIL_VERSION_INT, + .category = AV_CLASS_CATEGORY_FILTER, +}; + +static const AVFilterPad tonemap_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = filter_frame, + }, + { NULL } +}; + +static const AVFilterPad tonemap_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + }, + { NULL } +}; + +AVFilter ff_vf_tonemap = { + .name = "tonemap", + .description = NULL_IF_CONFIG_SMALL("Conversion to/from different dynamic ranges."), + .init = init, + .query_formats = query_formats, + .priv_size = sizeof(TonemapContext), + .priv_class = &tonemap_class, + .inputs = tonemap_inputs, + .outputs = tonemap_outputs, +};