FFmpeg
Data Structures | Macros | Enumerations | Functions
vf_lut3d.c File Reference

3D Lookup table filter More...

#include "libavutil/opt.h"
#include "libavutil/file.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/avassert.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avstring.h"
#include "avfilter.h"
#include "drawutils.h"
#include "formats.h"
#include "framesync.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  rgbvec
 
struct  LUT3DContext
 
struct  ThreadData
 Used for passing data between threads. More...
 

Macros

#define R   0
 
#define G   1
 
#define B   2
 
#define A   3
 
#define MAX_LEVEL   128
 
#define OFFSET(x)   offsetof(LUT3DContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define COMMON_OPTIONS
 
#define NEAR(x)   ((int)((x) + .5))
 
#define PREV(x)   ((int)(x))
 
#define NEXT(x)   (FFMIN((int)(x) + 1, lut3d->lutsize - 1))
 
#define DEFINE_INTERP_FUNC_PLANAR(name, nbits, depth)
 
#define DEFINE_INTERP_FUNC(name, nbits)
 
#define MAX_LINE_SIZE   512
 
#define NEXT_LINE(loop_cond)
 
#define SET_COLOR(id)
 
#define SET_FUNC(name)
 

Enumerations

enum  interp_mode { INTERPOLATE_NEAREST, INTERPOLATE_TRILINEAR, INTERPOLATE_TETRAHEDRAL, NB_INTERP_MODE }
 

Functions

static float lerpf (float v0, float v1, float f)
 
static struct rgbvec lerp (const struct rgbvec *v0, const struct rgbvec *v1, float f)
 
static struct rgbvec interp_nearest (const LUT3DContext *lut3d, const struct rgbvec *s)
 Get the nearest defined point. More...
 
static struct rgbvec interp_trilinear (const LUT3DContext *lut3d, const struct rgbvec *s)
 Interpolate using the 8 vertices of a cube. More...
 
static struct rgbvec interp_tetrahedral (const LUT3DContext *lut3d, const struct rgbvec *s)
 Tetrahedral interpolation. More...
 
static int skip_line (const char *p)
 
static int parse_dat (AVFilterContext *ctx, FILE *f)
 
static int parse_cube (AVFilterContext *ctx, FILE *f)
 
static int parse_3dl (AVFilterContext *ctx, FILE *f)
 
static int parse_m3d (AVFilterContext *ctx, FILE *f)
 
static int parse_cinespace (AVFilterContext *ctx, FILE *f)
 
static void set_identity_matrix (LUT3DContext *lut3d, int size)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static AVFrameapply_lut (AVFilterLink *inlink, AVFrame *in)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 

Detailed Description

3D Lookup table filter

Definition in file vf_lut3d.c.

Macro Definition Documentation

#define R   0

Definition at line 40 of file vf_lut3d.c.

#define G   1

Definition at line 41 of file vf_lut3d.c.

#define B   2

Definition at line 42 of file vf_lut3d.c.

#define A   3

Definition at line 43 of file vf_lut3d.c.

#define MAX_LEVEL   128

Definition at line 58 of file vf_lut3d.c.

Referenced by filter_frame(), parse_cinespace(), parse_cube(), parse_dat(), and parse_m3d().

#define OFFSET (   x)    offsetof(LUT3DContext, x)

Definition at line 84 of file vf_lut3d.c.

Referenced by filter_frame().

Definition at line 85 of file vf_lut3d.c.

Referenced by filter_frame().

#define COMMON_OPTIONS
Value:
{ "interp", "select interpolation mode", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, NB_INTERP_MODE-1, FLAGS, "interp_mode" }, \
{ "nearest", "use values from the nearest defined points", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_NEAREST}, INT_MIN, INT_MAX, FLAGS, "interp_mode" }, \
{ "trilinear", "interpolate values using the 8 points defining a cube", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TRILINEAR}, INT_MIN, INT_MAX, FLAGS, "interp_mode" }, \
{ "tetrahedral", "interpolate values using a tetrahedron", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TETRAHEDRAL}, INT_MIN, INT_MAX, FLAGS, "interp_mode" }, \
{ NULL }
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: vf_lut3d.c:84
#define FLAGS
Definition: vf_lut3d.c:85
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
Definition: af_adeclick.c:351

Definition at line 86 of file vf_lut3d.c.

Referenced by filter_frame().

#define NEAR (   x)    ((int)((x) + .5))

Definition at line 106 of file vf_lut3d.c.

Referenced by filter_frame(), and interp_nearest().

#define PREV (   x)    ((int)(x))

Definition at line 107 of file vf_lut3d.c.

Referenced by filter_frame(), interp_tetrahedral(), and interp_trilinear().

#define NEXT (   x)    (FFMIN((int)(x) + 1, lut3d->lutsize - 1))

Definition at line 108 of file vf_lut3d.c.

Referenced by interp_tetrahedral(), and interp_trilinear().

#define DEFINE_INTERP_FUNC_PLANAR (   name,
  nbits,
  depth 
)

Definition at line 204 of file vf_lut3d.c.

#define DEFINE_INTERP_FUNC (   name,
  nbits 
)

Definition at line 283 of file vf_lut3d.c.

#define MAX_LINE_SIZE   512

Definition at line 333 of file vf_lut3d.c.

Referenced by filter_frame(), parse_3dl(), parse_cinespace(), parse_cube(), parse_dat(), and parse_m3d().

#define NEXT_LINE (   loop_cond)
Value:
do { \
if (!fgets(line, sizeof(line), f)) { \
av_log(ctx, AV_LOG_ERROR, "Unexpected EOF\n"); \
} \
} while (loop_cond)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define f(width, name)
Definition: cbs_vp9.c:255
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
Definition: graph2dot.c:48
AVFormatContext * ctx
Definition: movenc.c:48
if(ret)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return

Definition at line 342 of file vf_lut3d.c.

Referenced by filter_frame(), parse_3dl(), parse_cinespace(), parse_cube(), parse_dat(), and parse_m3d().

#define SET_COLOR (   id)
Value:
do { \
while (av_isspace(*p)) \
p++; \
switch (*p) { \
case 'r': rgb_map[id] = 0; break; \
case 'g': rgb_map[id] = 1; break; \
case 'b': rgb_map[id] = 2; break; \
} \
while (*p && !av_isspace(*p)) \
p++; \
} while (0)
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:222
enum AVCodecID id

Referenced by parse_m3d().

#define SET_FUNC (   name)
Value:
do { \
if (planar) { \
switch (depth) { \
case 8: lut3d->interp = interp_8_##name##_p8; break; \
case 9: lut3d->interp = interp_16_##name##_p9; break; \
case 10: lut3d->interp = interp_16_##name##_p10; break; \
case 12: lut3d->interp = interp_16_##name##_p12; break; \
case 14: lut3d->interp = interp_16_##name##_p14; break; \
case 16: lut3d->interp = interp_16_##name##_p16; break; \
} \
} else if (is16bit) { lut3d->interp = interp_16_##name; \
} else { lut3d->interp = interp_8_##name; } \
} while (0)
if(ret)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63)))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT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FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){int planes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
Definition: audioconvert.c:56
const char * name
Definition: opengl_enc.c:102

Referenced by config_input().

Enumeration Type Documentation

Enumerator
INTERPOLATE_NEAREST 
INTERPOLATE_TRILINEAR 
INTERPOLATE_TETRAHEDRAL 
NB_INTERP_MODE 

Definition at line 45 of file vf_lut3d.c.

Function Documentation

static float lerpf ( float  v0,
float  v1,
float  f 
)
inlinestatic

Definition at line 93 of file vf_lut3d.c.

Referenced by filter_frame(), and lerp().

static struct rgbvec lerp ( const struct rgbvec v0,
const struct rgbvec v1,
float  f 
)
static

Definition at line 98 of file vf_lut3d.c.

Referenced by interp_trilinear().

static struct rgbvec interp_nearest ( const LUT3DContext lut3d,
const struct rgbvec s 
)
static

Get the nearest defined point.

Definition at line 113 of file vf_lut3d.c.

static struct rgbvec interp_trilinear ( const LUT3DContext lut3d,
const struct rgbvec s 
)
static

Interpolate using the 8 vertices of a cube.

See also
https://en.wikipedia.org/wiki/Trilinear_interpolation

Definition at line 123 of file vf_lut3d.c.

static struct rgbvec interp_tetrahedral ( const LUT3DContext lut3d,
const struct rgbvec s 
)
static

Tetrahedral interpolation.

Based on code found in Truelight Software Library paper.

See also
http://www.filmlight.ltd.uk/pdf/whitepapers/FL-TL-TN-0057-SoftwareLib.pdf

Definition at line 151 of file vf_lut3d.c.

static int skip_line ( const char *  p)
static

Definition at line 335 of file vf_lut3d.c.

Referenced by filter_frame(), parse_3dl(), parse_cinespace(), parse_cube(), and parse_dat().

static int parse_dat ( AVFilterContext ctx,
FILE *  f 
)
static

Definition at line 351 of file vf_lut3d.c.

Referenced by filter_frame().

static int parse_cube ( AVFilterContext ctx,
FILE *  f 
)
static

Definition at line 384 of file vf_lut3d.c.

Referenced by filter_frame().

static int parse_3dl ( AVFilterContext ctx,
FILE *  f 
)
static

Definition at line 441 of file vf_lut3d.c.

Referenced by filter_frame().

static int parse_m3d ( AVFilterContext ctx,
FILE *  f 
)
static

Definition at line 470 of file vf_lut3d.c.

Referenced by filter_frame().

static int parse_cinespace ( AVFilterContext ctx,
FILE *  f 
)
static

Definition at line 533 of file vf_lut3d.c.

Referenced by filter_frame().

static void set_identity_matrix ( LUT3DContext lut3d,
int  size 
)
static

Definition at line 627 of file vf_lut3d.c.

Referenced by filter_frame().

static int query_formats ( AVFilterContext ctx)
static

Definition at line 645 of file vf_lut3d.c.

Referenced by filter_frame().

static int config_input ( AVFilterLink inlink)
static

Definition at line 669 of file vf_lut3d.c.

Referenced by filter_frame().

static AVFrame* apply_lut ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 727 of file vf_lut3d.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 756 of file vf_lut3d.c.