FFmpeg
Macros | Functions | Variables
vf_lut3d.c File Reference
#include "float.h"
#include "libavutil/opt.h"
#include "libavutil/file.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "drawutils.h"
#include "formats.h"
#include "internal.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)   offsetof(LUT3DContext, 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)   ((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_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)
 
#define SET_FUNC(name)
 

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. 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_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. More...
 
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)
 
static int config_input (AVFilterLink *inlink)
 
static AVFrameapply_lut (AVFilterLink *inlink, AVFrame *in)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 

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

◆ G

#define G   1

Definition at line 42 of file vf_lut3d.c.

◆ B

#define B   2

Definition at line 43 of file vf_lut3d.c.

◆ A

#define A   3

Definition at line 44 of file vf_lut3d.c.

◆ OFFSET

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

Definition at line 46 of file vf_lut3d.c.

◆ FLAGS

Definition at line 47 of file vf_lut3d.c.

◆ TFLAGS

Definition at line 48 of file vf_lut3d.c.

◆ 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, "interp_mode" }, \
{ "nearest", "use values from the nearest defined points", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_NEAREST}, 0, 0, TFLAGS, "interp_mode" }, \
{ "trilinear", "interpolate values using the 8 points defining a cube", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TRILINEAR}, 0, 0, TFLAGS, "interp_mode" }, \
{ "tetrahedral", "interpolate values using a tetrahedron", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, 0, TFLAGS, "interp_mode" }, \
{ "pyramid", "interpolate values using a pyramid", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_PYRAMID}, 0, 0, TFLAGS, "interp_mode" }, \
{ "prism", "interpolate values using a prism", 0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_PRISM}, 0, 0, TFLAGS, "interp_mode" }, \
{ NULL }

Definition at line 49 of file vf_lut3d.c.

◆ EXPONENT_MASK

#define EXPONENT_MASK   0x7F800000

Definition at line 58 of file vf_lut3d.c.

◆ MANTISSA_MASK

#define MANTISSA_MASK   0x007FFFFF

Definition at line 59 of file vf_lut3d.c.

◆ SIGN_MASK

#define SIGN_MASK   0x80000000

Definition at line 60 of file vf_lut3d.c.

◆ NEAR

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

Definition at line 95 of file vf_lut3d.c.

◆ PREV

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

Definition at line 96 of file vf_lut3d.c.

◆ NEXT

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

Definition at line 97 of file vf_lut3d.c.

◆ DEFINE_INTERP_FUNC_PLANAR

#define DEFINE_INTERP_FUNC_PLANAR (   name,
  nbits,
  depth 
)

Definition at line 320 of file vf_lut3d.c.

◆ DEFINE_INTERP_FUNC_PLANAR_FLOAT

#define DEFINE_INTERP_FUNC_PLANAR_FLOAT (   name,
  depth 
)

Definition at line 418 of file vf_lut3d.c.

◆ DEFINE_INTERP_FUNC

#define DEFINE_INTERP_FUNC (   name,
  nbits 
)

Definition at line 485 of file vf_lut3d.c.

◆ MAX_LINE_SIZE

#define MAX_LINE_SIZE   512

Definition at line 546 of file vf_lut3d.c.

◆ 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)

Definition at line 589 of file vf_lut3d.c.

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

◆ 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)

◆ 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; \
}

Definition at line 863 of file vf_lut3d.c.

◆ SET_FUNC

#define SET_FUNC (   name)
Value:
do { \
if (planar && !isfloat) { \
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 (isfloat) { lut3d->interp = interp_##name##_pf32; \
} else if (is16bit) { lut3d->interp = interp_16_##name; \
} else { lut3d->interp = interp_8_##name; } \
} while (0)

Function Documentation

◆ sanitizef()

static float sanitizef ( float  f)
inlinestatic

Definition at line 62 of file vf_lut3d.c.

Referenced by parse_cinespace().

◆ lerpf()

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

Definition at line 82 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 87 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 102 of file vf_lut3d.c.

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

◆ interp_pyramid()

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

Definition at line 138 of file vf_lut3d.c.

◆ interp_prism()

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

Definition at line 188 of file vf_lut3d.c.

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

◆ prelut_interp_1d_linear()

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

Definition at line 292 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 306 of file vf_lut3d.c.

◆ skip_line()

static int skip_line ( const char *  p)
static

Definition at line 548 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 555 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 639 of file vf_lut3d.c.

◆ parse_cube()

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

Definition at line 674 of file vf_lut3d.c.

◆ parse_3dl()

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

Definition at line 731 of file vf_lut3d.c.

◆ parse_m3d()

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

Definition at line 766 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 835 of file vf_lut3d.c.

Referenced by parse_cinespace().

◆ parse_cinespace()

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

Definition at line 873 of file vf_lut3d.c.

◆ set_identity_matrix()

static int set_identity_matrix ( AVFilterContext ctx,
int  size 
)
static

Definition at line 1070 of file vf_lut3d.c.

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 1113 of file vf_lut3d.c.

Referenced by process_command().

◆ apply_lut()

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

Definition at line 1158 of file vf_lut3d.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 1188 of file vf_lut3d.c.

◆ process_command()

static int process_command ( AVFilterContext ctx,
const char *  cmd,
const char *  args,
char *  res,
int  res_len,
int  flags 
)
static

Definition at line 1197 of file vf_lut3d.c.

Variable Documentation

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:426
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
av_isspace
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:227
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
INTERPOLATE_PYRAMID
@ INTERPOLATE_PYRAMID
Definition: lut3d.h:32
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:422
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:420
INTERPOLATE_NEAREST
@ INTERPOLATE_NEAREST
Definition: lut3d.h:29
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:424
OFFSET
#define OFFSET(x)
Definition: vf_lut3d.c:46
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:425
INTERPOLATE_PRISM
@ INTERPOLATE_PRISM
Definition: lut3d.h:33
ctx
AVFormatContext * ctx
Definition: movenc.c:48
fget_next_word
static char * fget_next_word(char *dst, int max, FILE *f)
Definition: vf_lut3d.c:555
f
#define f(width, name)
Definition: cbs_vp9.c:255
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:423
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:394
av_sscanf
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:960
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:395
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:230
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:419
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:433
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:390
line
Definition: graph2dot.c:48
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:228
interpolation
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:336
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:399
NB_INTERP_MODE
@ NB_INTERP_MODE
Definition: lut3d.h:34
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:421
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
INTERPOLATE_TETRAHEDRAL
@ INTERPOLATE_TETRAHEDRAL
Definition: lut3d.h:31
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:229
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:434
TFLAGS
#define TFLAGS
Definition: vf_lut3d.c:48
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
INTERPOLATE_TRILINEAR
@ INTERPOLATE_TRILINEAR
Definition: lut3d.h:30
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:227
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
thread_data::p
int p
Definition: vf_nlmeans.c:326
planar
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_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1<< 16)) 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_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_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+ch,(const uint8_t **) in->ch+ch, off *(out-> planar
Definition: audioconvert.c:56
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233