FFmpeg
Loading...
Searching...
No Matches
vf_lut3d.c File Reference

3D Lookup table filter More...

#include <float.h>
#include "config_components.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/file_open.h"
#include "libavutil/intfloat.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "drawutils.h"
#include "filters.h"
#include "video.h"
#include "lut3d.h"

Go to the source code of this file.

Macros

#define R   0
 
#define G   1
 
#define B   2
 
#define A   3
 
#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define TFLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
#define COMMON_OPTIONS
 
#define EXPONENT_MASK   0x7F800000
 
#define MANTISSA_MASK   0x007FFFFF
 
#define SIGN_MASK   0x80000000
 
#define NEAR(x)
 
#define PREV(x)
 
#define NEXT(x)
 
#define DEFINE_INTERP_FUNC_PLANAR(name, nbits, depth)
 
#define DEFINE_INTERP_FUNC_PLANAR_FLOAT(name, depth)
 
#define DEFINE_INTERP_FUNC(name, nbits)
 
#define MAX_LINE_SIZE   512
 
#define NEXT_LINE(loop_cond)
 
#define NEXT_LINE_OR_GOTO(loop_cond, label)
 
#define SET_COLOR(id)
 
#define NEXT_FLOAT_OR_GOTO(value, label)
 

Functions

static float sanitizef (float f)
 
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.
 
static struct rgbvec interp_trilinear (const LUT3DContext *lut3d, const struct rgbvec *s)
 Interpolate using the 8 vertices of a cube.
 
static struct rgbvec interp_pyramid (const LUT3DContext *lut3d, const struct rgbvec *s)
 
static struct rgbvec interp_prism (const LUT3DContext *lut3d, const struct rgbvec *s)
 
static struct rgbvec interp_tetrahedral (const LUT3DContext *lut3d, const struct rgbvec *s)
 Tetrahedral interpolation.
 
static float prelut_interp_1d_linear (const Lut3DPreLut *prelut, int idx, const float s)
 
static struct rgbvec apply_prelut (const Lut3DPreLut *prelut, const struct rgbvec *s)
 
static int skip_line (const char *p)
 
static char * fget_next_word (char *dst, int max, FILE *f)
 
static int allocate_3dlut (AVFilterContext *ctx, int lutsize, int prelut)
 
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 nearest_sample_index (float *data, float x, int low, int hi)
 
static int parse_cinespace (AVFilterContext *ctx, FILE *f)
 
static int set_identity_matrix (AVFilterContext *ctx, int size)
 

Variables

static enum AVPixelFormat pix_fmts []
 

Detailed Description

3D Lookup table filter

Definition in file vf_lut3d.c.

Macro Definition Documentation

◆ R

#define R   0

Definition at line 42 of file vf_lut3d.c.

◆ G

#define G   1

Definition at line 43 of file vf_lut3d.c.

◆ B

#define B   2

Definition at line 44 of file vf_lut3d.c.

◆ A

#define A   3

Definition at line 45 of file vf_lut3d.c.

◆ OFFSET

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

Definition at line 47 of file vf_lut3d.c.

◆ FLAGS

Definition at line 48 of file vf_lut3d.c.

◆ TFLAGS

◆ COMMON_OPTIONS

#define COMMON_OPTIONS
Value:
{ "interp", "select interpolation mode", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, NB_INTERP_MODE-1, TFLAGS, .unit = "interp_mode" }, \
{ "nearest", "use values from the nearest defined points", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_NEAREST}, 0, 0, TFLAGS, .unit = "interp_mode" }, \
{ "trilinear", "interpolate values using the 8 points defining a cube", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TRILINEAR}, 0, 0, TFLAGS, .unit = "interp_mode" }, \
{ "tetrahedral", "interpolate values using a tetrahedron", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, 0, TFLAGS, .unit = "interp_mode" }, \
{ "pyramid", "interpolate values using a pyramid", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_PYRAMID}, 0, 0, TFLAGS, .unit = "interp_mode" }, \
{ "prism", "interpolate values using a prism", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_PRISM}, 0, 0, TFLAGS, .unit = "interp_mode" }, \
{ NULL }
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
#define TFLAGS
Definition af_afade.c:66
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ INTERPOLATE_TRILINEAR
Definition lut3d.h:32
@ INTERPOLATE_PYRAMID
Definition lut3d.h:34
@ NB_INTERP_MODE
Definition lut3d.h:36
@ INTERPOLATE_TETRAHEDRAL
Definition lut3d.h:33
@ INTERPOLATE_PRISM
Definition lut3d.h:35
@ INTERPOLATE_NEAREST
Definition lut3d.h:31

Definition at line 50 of file vf_lut3d.c.

◆ EXPONENT_MASK

#define EXPONENT_MASK   0x7F800000

Definition at line 59 of file vf_lut3d.c.

Referenced by sanitizef().

◆ MANTISSA_MASK

#define MANTISSA_MASK   0x007FFFFF

Definition at line 60 of file vf_lut3d.c.

Referenced by sanitizef().

◆ SIGN_MASK

#define SIGN_MASK   0x80000000

Definition at line 61 of file vf_lut3d.c.

Referenced by sanitizef().

◆ NEAR

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

Definition at line 96 of file vf_lut3d.c.

Referenced by interp_nearest().

◆ PREV

#define PREV ( x)

◆ NEXT

#define NEXT ( x)
Value:
(FFMIN((int)(x) + 1, lut3d->lutsize - 1))
#define FFMIN(a, b)
Definition macros.h:49

Definition at line 98 of file vf_lut3d.c.

Referenced by config_input(), denoise(), interp_prism(), interp_pyramid(), interp_tetrahedral(), interp_trilinear(), and uninit().

◆ DEFINE_INTERP_FUNC_PLANAR

#define DEFINE_INTERP_FUNC_PLANAR ( name,
nbits,
depth )

Definition at line 321 of file vf_lut3d.c.

◆ DEFINE_INTERP_FUNC_PLANAR_FLOAT

#define DEFINE_INTERP_FUNC_PLANAR_FLOAT ( name,
depth )

Definition at line 419 of file vf_lut3d.c.

◆ DEFINE_INTERP_FUNC

#define DEFINE_INTERP_FUNC ( name,
nbits )

Definition at line 486 of file vf_lut3d.c.

◆ MAX_LINE_SIZE

◆ NEXT_LINE

#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 f(width, name)
Definition cbs_vp8.c:236
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static AVFormatContext * ctx
Definition movenc.c:49

Definition at line 590 of file vf_lut3d.c.

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

◆ NEXT_LINE_OR_GOTO

#define NEXT_LINE_OR_GOTO ( loop_cond,
label )
Value:
do { \
if (!fgets(line, sizeof(line), f)) { \
av_log(ctx, AV_LOG_ERROR, "Unexpected EOF\n"); \
goto label; \
} \
} while (loop_cond)

Definition at line 597 of file vf_lut3d.c.

Referenced by parse_cinespace().

◆ SET_COLOR

#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)
enum AVCodecID id
Definition dts2pts.c:607
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition avstring.h:218

Referenced by parse_m3d().

◆ NEXT_FLOAT_OR_GOTO

#define NEXT_FLOAT_OR_GOTO ( value,
label )
Value:
if (!fget_next_word(line, sizeof(line) ,f)) { \
goto label; \
} \
if (av_sscanf(line, "%f", &value) != 1) { \
goto label; \
}
int av_sscanf(const char *string, const char *format,...)
Definition avsscanf.c:962
double value
Definition eval.c:102
static char * fget_next_word(char *dst, int max, FILE *f)
Definition vf_lut3d.c:556

Definition at line 865 of file vf_lut3d.c.

Referenced by parse_cinespace().

Function Documentation

◆ sanitizef()

static float sanitizef ( float f)
inlinestatic

Definition at line 63 of file vf_lut3d.c.

Referenced by parse_cinespace().

◆ lerpf()

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

Definition at line 83 of file vf_lut3d.c.

Referenced by lerp(), parse_cinespace(), and prelut_interp_1d_linear().

◆ lerp()

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

Definition at line 88 of file vf_lut3d.c.

Referenced by interp_trilinear().

◆ interp_nearest()

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

Get the nearest defined point.

Definition at line 103 of file vf_lut3d.c.

Referenced by interp_nearest().

◆ interp_trilinear()

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

Interpolate using the 8 vertices of a cube.

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

Definition at line 113 of file vf_lut3d.c.

Referenced by interp_trilinear().

◆ interp_pyramid()

static struct rgbvec interp_pyramid ( const LUT3DContext * lut3d,
const struct rgbvec * s )
inlinestatic

Definition at line 139 of file vf_lut3d.c.

Referenced by interp_pyramid().

◆ interp_prism()

static struct rgbvec interp_prism ( const LUT3DContext * lut3d,
const struct rgbvec * s )
inlinestatic

Definition at line 189 of file vf_lut3d.c.

Referenced by interp_prism().

◆ interp_tetrahedral()

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

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 238 of file vf_lut3d.c.

Referenced by interp_tetrahedral().

◆ prelut_interp_1d_linear()

static float prelut_interp_1d_linear ( const Lut3DPreLut * prelut,
int idx,
const float s )
inlinestatic

Definition at line 293 of file vf_lut3d.c.

Referenced by apply_prelut().

◆ apply_prelut()

static struct rgbvec apply_prelut ( const Lut3DPreLut * prelut,
const struct rgbvec * s )
inlinestatic

Definition at line 307 of file vf_lut3d.c.

Referenced by apply_prelut().

◆ skip_line()

static int skip_line ( const char * p)
static

Definition at line 549 of file vf_lut3d.c.

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

◆ fget_next_word()

static char * fget_next_word ( char * dst,
int max,
FILE * f )
static

Definition at line 556 of file vf_lut3d.c.

◆ allocate_3dlut()

static int allocate_3dlut ( AVFilterContext * ctx,
int lutsize,
int prelut )
static

◆ parse_dat()

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

Definition at line 640 of file vf_lut3d.c.

◆ parse_cube()

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

Definition at line 675 of file vf_lut3d.c.

◆ parse_3dl()

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

Definition at line 733 of file vf_lut3d.c.

◆ parse_m3d()

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

Definition at line 768 of file vf_lut3d.c.

◆ nearest_sample_index()

static int nearest_sample_index ( float * data,
float x,
int low,
int hi )
static

Definition at line 837 of file vf_lut3d.c.

Referenced by parse_cinespace().

◆ parse_cinespace()

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

Definition at line 875 of file vf_lut3d.c.

◆ set_identity_matrix()

static int set_identity_matrix ( AVFilterContext * ctx,
int size )
static

Definition at line 1072 of file vf_lut3d.c.

Variable Documentation

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static
Initial value:
= {
}
#define AV_PIX_FMT_GBRAP12
Definition pixfmt.h:569
#define AV_PIX_FMT_GBRPF32
Definition pixfmt.h:584
#define AV_PIX_FMT_GBRAP16
Definition pixfmt.h:571
#define AV_PIX_FMT_GBRP9
Definition pixfmt.h:563
#define AV_PIX_FMT_BGR48
Definition pixfmt.h:536
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_RGBA64
Definition pixfmt.h:535
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
#define AV_PIX_FMT_RGB48
Definition pixfmt.h:531
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition pixfmt.h:101
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition pixfmt.h:264
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition pixfmt.h:262
#define AV_PIX_FMT_BGRA64
Definition pixfmt.h:540
#define AV_PIX_FMT_GBRAP10
Definition pixfmt.h:568
#define AV_PIX_FMT_GBRP16
Definition pixfmt.h:567
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:566
#define AV_PIX_FMT_GBRAPF32
Definition pixfmt.h:585

Definition at line 1097 of file vf_lut3d.c.