42 #define REFERENCE_WHITE 100.0f
144 float a = 0.15f,
b = 0.50f,
c = 0.10f, d = 0.20f, e = 0.02f, f = 0.30f;
145 return (in * (in * a +
b *
c) + d * e) / (in * (in * a +
b) + d * f) - e / f;
148 static float mobius(
float in,
float j,
double peak)
155 a = -j * j * (peak - 1.0f) / (j * j - 2.0f * j + peak);
156 b = (j * j - 2.0f * j * peak + peak) /
FFMAX(peak - 1.0f, 1e-6);
158 return (b * b + 2.0f * b * j + j * j) / (b -
a) * (in + a) / (in +
b);
161 #define MIX(x,y,a) (x) * (1 - (a)) + (y) * (a)
165 const float *r_in = (
const float *)(in->
data[0] + x * desc->
comp[0].
step + y * in->
linesize[0]);
166 const float *b_in = (
const float *)(in->
data[1] + x * desc->
comp[1].
step + y * in->
linesize[1]);
167 const float *g_in = (
const float *)(in->
data[2] + x * desc->
comp[2].
step + y * in->
linesize[2]);
182 *r_out =
MIX(*r_in, luma, overbright);
183 *g_out =
MIX(*g_in, luma, overbright);
184 *b_out =
MIX(*b_in, luma, overbright);
199 sig = sig * s->
param / peak;
202 sig = sig > 0.05f ? pow(sig / peak, 1.0f / s->
param)
203 : sig * pow(0.05f / peak, 1.0f / s->
param) / 0.05f;
206 sig = av_clipf(sig * s->
param, 0, 1.0f);
212 sig = sig / (sig + s->
param) * (peak + s->
param) / peak;
221 *r_out *= sig / sig_orig;
222 *g_out *= sig / sig_orig;
223 *b_out *= sig / sig_orig;
234 double peak = s->
peak;
236 if (!desc || !odesc) {
280 for (y = 0; y < out->
height; y++)
281 for (x = 0; x < out->
width; x++)
282 tonemap(s, out, in, desc, x, y, peak);
290 for (y = 0; y < out->
height; y++) {
291 for (x = 0; x < out->
width; x++) {
303 #define OFFSET(x) offsetof(TonemapContext, x)
304 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
351 .priv_class = &tonemap_class,
static double determine_signal_peak(AVFrame *in)
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
unsigned MaxCLL
Max content light level (cd/m^2).
"Linear transfer characteristics"
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
int h
agreed upon image height
Content light level (based on CTA-861.3).
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Mastering display metadata associated with a video frame.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
functionally identical to above
const char * av_color_space_name(enum AVColorSpace space)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
static int query_formats(AVFilterContext *ctx)
Structure to hold side data for an AVFrame.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static const AVFilterPad tonemap_outputs[]
static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB]
static const AVOption tonemap_options[]
A filter pad used for either input or output.
A link between two filters.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
static const AVClass tonemap_class
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVColorSpace colorspace
YUV colorspace type.
int w
agreed upon image width
common internal API header
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
static float hable(float in)
ITU-R BT2020 non-constant luminance system.
static const AVFilterPad outputs[]
static av_cold int init(AVFilterContext *ctx)
enum TonemapAlgorithm tonemap
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
int format
agreed upon media format
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
const LumaCoefficients * coeffs
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Describe the class of an AVClass context structure.
const char * name
Filter name.
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
AVFilterLink ** outputs
array of pointers to output links
static int filter_frame(AVFilterLink *link, AVFrame *in)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static enum AVPixelFormat pix_fmts[]
ITU-R BT2020 constant luminance system.
static float mobius(float in, float j, double peak)
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRAPF32
AVFilterContext * dst
dest filter
enum AVColorTransferCharacteristic color_trc
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
AVPixelFormat
Pixel format.
static const AVFilterPad tonemap_inputs[]
static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in, const AVPixFmtDescriptor *desc, int x, int y, double peak)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
int step
Number of elements between 2 horizontally consecutive pixels.