FFmpeg  2.1.1
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 "dualinput.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  rgbvec
 
struct  LUT3DContext
 

Macros

#define R   0
 
#define G   1
 
#define B   2
 
#define A   3
 
#define MAX_LEVEL   64
 
#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(name, nbits)
 
#define MAX_LINE_SIZE   512
 
#define NEXT_LINE(loop_cond)
 
#define SET_COLOR(id)
 
#define SET_FUNC(name)
 
#define FILTER(nbits)
 

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

#define G   1

Definition at line 40 of file vf_lut3d.c.

#define B   2

Definition at line 41 of file vf_lut3d.c.

#define A   3

Definition at line 42 of file vf_lut3d.c.

#define MAX_LEVEL   64

Definition at line 57 of file vf_lut3d.c.

Referenced by parse_cube(), and parse_m3d().

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

Definition at line 79 of file vf_lut3d.c.

Definition at line 80 of file vf_lut3d.c.

#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 OFFSET(x)
Definition: vf_lut3d.c:79
#define FLAGS
Definition: vf_lut3d.c:80

Definition at line 81 of file vf_lut3d.c.

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

Definition at line 101 of file vf_lut3d.c.

Referenced by interp_nearest().

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

Definition at line 102 of file vf_lut3d.c.

Referenced by interp_tetrahedral(), and interp_trilinear().

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

Definition at line 103 of file vf_lut3d.c.

Referenced by interp_tetrahedral(), and interp_trilinear().

#define DEFINE_INTERP_FUNC (   name,
  nbits 
)
Value:
static struct rgbvec interp_##nbits##_##name(const LUT3DContext *lut3d, \
uint##nbits##_t r, \
uint##nbits##_t g, \
uint##nbits##_t b) \
{ \
const float scale = (1. / ((1<<nbits) - 1)) * (lut3d->lutsize - 1); \
const struct rgbvec scaled_rgb = {r * scale, g * scale, b * scale}; \
return interp_##name(lut3d, &scaled_rgb); \
}
const char * name
Definition: avisynth_c.h:675
const char * g
Definition: vf_curves.c:104
const char * b
Definition: vf_curves.c:105
#define _(x)
const char * r
Definition: vf_curves.c:103
return
static const uint16_t scale[4]

Definition at line 199 of file vf_lut3d.c.

#define MAX_LINE_SIZE   512

Definition at line 218 of file vf_lut3d.c.

Referenced by parse_3dl(), 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)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
Definition: graph2dot.c:48
return
#define AVERROR_INVALIDDATA

Definition at line 227 of file vf_lut3d.c.

Referenced by parse_3dl(), 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)
enum AVCodecID id
Definition: mxfenc.c:90
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.c:298

Referenced by parse_m3d().

#define SET_FUNC (   name)
Value:
do { \
if (lut3d->is16bit) lut3d->interp_16 = interp_16_##name; \
else lut3d->interp_8 = interp_8_##name; \
} while (0)
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965

Referenced by config_input().

#define FILTER (   nbits)
Value:
do { \
uint8_t *dstrow = out->data[0]; \
const uint8_t *srcrow = in ->data[0]; \
for (y = 0; y < inlink->h; y++) { \
uint##nbits##_t *dst = (uint##nbits##_t *)dstrow; \
const uint##nbits##_t *src = (const uint##nbits##_t *)srcrow; \
for (x = 0; x < inlink->w * step; x += step) { \
struct rgbvec vec = lut3d->interp_##nbits(lut3d, src[x + r], src[x + g], src[x + b]); \
dst[x + r] = av_clip_uint##nbits(vec.r * (float)((1<<nbits) - 1)); \
dst[x + g] = av_clip_uint##nbits(vec.g * (float)((1<<nbits) - 1)); \
dst[x + b] = av_clip_uint##nbits(vec.b * (float)((1<<nbits) - 1)); \
if (!direct && step == 4) \
dst[x + a] = src[x + a]; \
} \
dstrow += out->linesize[0]; \
srcrow += in ->linesize[0]; \
} \
} while (0)
const char * g
Definition: vf_curves.c:104
const char * b
Definition: vf_curves.c:105
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
uint8_t
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
const char * r
Definition: vf_curves.c:103
float y
AVS_Value src
Definition: avisynth_c.h:523
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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-> out
for(j=16;j >0;--j)

Definition at line 466 of file vf_lut3d.c.

Referenced by apply_lut().

Enumeration Type Documentation

Enumerator
INTERPOLATE_NEAREST 
INTERPOLATE_TRILINEAR 
INTERPOLATE_TETRAHEDRAL 
NB_INTERP_MODE 

Definition at line 44 of file vf_lut3d.c.

Function Documentation

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

Definition at line 88 of file vf_lut3d.c.

Referenced by lerp().

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

Definition at line 93 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 108 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 118 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 146 of file vf_lut3d.c.

static int skip_line ( const char *  p)
static

Definition at line 220 of file vf_lut3d.c.

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

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

Definition at line 236 of file vf_lut3d.c.

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

Definition at line 256 of file vf_lut3d.c.

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

Definition at line 308 of file vf_lut3d.c.

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

Definition at line 337 of file vf_lut3d.c.

static void set_identity_matrix ( LUT3DContext lut3d,
int  size 
)
static

Definition at line 400 of file vf_lut3d.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 418 of file vf_lut3d.c.

static int config_input ( AVFilterLink inlink)
static

Definition at line 434 of file vf_lut3d.c.

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

Definition at line 486 of file vf_lut3d.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 520 of file vf_lut3d.c.