42 #define LANCZOS_RESOLUTION 256
94 #define OFFSET(x) offsetof(LensfunContext, x)
95 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
108 {
"focal_length",
"focal length of video (zoom; constant for the duration of the use of this filter)",
OFFSET(focal_length),
AV_OPT_TYPE_FLOAT, {.dbl=18}, 0.0, DBL_MAX,
FLAGS },
109 {
"aperture",
"aperture (constant for the duration of the use of this filter)",
OFFSET(aperture),
AV_OPT_TYPE_FLOAT, {.dbl=3.5}, 0.0, DBL_MAX,
FLAGS },
110 {
"focus_distance",
"focus distance (constant for the duration of the use of this filter)",
OFFSET(focus_distance),
AV_OPT_TYPE_FLOAT, {.dbl=1000.0f}, 0.0, DBL_MAX,
FLAGS },
111 {
"target_geometry",
"target geometry of the lens correction (only when geometry correction is enabled)",
OFFSET(target_geometry),
AV_OPT_TYPE_INT, {.i64=LF_RECTILINEAR}, 0, INT_MAX,
FLAGS,
"lens_geometry" },
112 {
"rectilinear",
"rectilinear lens (default)", 0,
AV_OPT_TYPE_CONST, {.i64=LF_RECTILINEAR}, 0, 0,
FLAGS,
"lens_geometry" },
114 {
"panoramic",
"panoramic (cylindrical)", 0,
AV_OPT_TYPE_CONST, {.i64=LF_PANORAMIC}, 0, 0,
FLAGS,
"lens_geometry" },
115 {
"equirectangular",
"equirectangular", 0,
AV_OPT_TYPE_CONST, {.i64=LF_EQUIRECTANGULAR}, 0, 0,
FLAGS,
"lens_geometry" },
116 {
"fisheye_orthographic",
"orthographic fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_ORTHOGRAPHIC}, 0, 0,
FLAGS,
"lens_geometry" },
117 {
"fisheye_stereographic",
"stereographic fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_STEREOGRAPHIC}, 0, 0,
FLAGS,
"lens_geometry" },
118 {
"fisheye_equisolid",
"equisolid fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_EQUISOLID}, 0, 0,
FLAGS,
"lens_geometry" },
119 {
"fisheye_thoby",
"fisheye as measured by thoby", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_THOBY}, 0, 0,
FLAGS,
"lens_geometry" },
134 const lfCamera **cameras;
135 const lfLens **lenses;
137 if (!lensfun->
make) {
140 }
else if (!lensfun->
model) {
148 lensfun->
lens = lf_lens_new();
149 lensfun->
camera = lf_camera_new();
152 if (lf_db_load(db) != LF_NO_ERROR) {
158 cameras = lf_db_find_cameras(db, lensfun->
make, lensfun->
model);
159 if (cameras && *cameras) {
160 lf_camera_copy(lensfun->
camera, *cameras);
171 if (lenses && *lenses) {
172 lf_lens_copy(lensfun->
lens, *lenses);
198 }
else if (x > -2.0
f && x < 2.0
f) {
211 int lensfun_mode = 0;
216 lensfun->
camera->CropFactor,
220 lensfun_mode |= LF_MODIFY_VIGNETTING;
222 lensfun_mode |= LF_MODIFY_DISTORTION | LF_MODIFY_GEOMETRY | LF_MODIFY_SCALE;
224 lensfun_mode |= LF_MODIFY_TCA;
225 lf_modifier_initialize(lensfun->
modifier,
248 lf_modifier_apply_subpixel_geometry_distortion(lensfun->
modifier,
250 inlink->
w, inlink->
h,
254 lf_modifier_apply_subpixel_distortion(lensfun->
modifier,
256 inlink->
w, inlink->
h,
264 lf_modifier_apply_geometry_distortion(lensfun->
modifier,
266 inlink->
w, inlink->
h,
280 a = sqrtf((
float)index / LANCZOS_RESOLUTION);
292 const int slice_start = thread_data->
height * jobnr / nb_jobs;
295 lf_modifier_apply_color_modification(thread_data->
modifier,
300 slice_end - slice_start,
315 const int slice_start = thread_data->
height * jobnr / nb_jobs;
318 int x, y, i, j, rgb_index;
319 float interpolated, new_x, new_y, d, norm;
320 int new_x_int, new_y_int;
321 for (y = slice_start; y <
slice_end; ++y)
322 for (x = 0; x < thread_data->
width; ++x)
323 for (rgb_index = 0; rgb_index < 3; ++rgb_index) {
328 new_x_int = thread_data->
distortion_coords[x * 2 * 3 + y * thread_data->
width * 2 * 3 + rgb_index * 2] + 0.5f;
329 new_y_int = thread_data->
distortion_coords[x * 2 * 3 + y * thread_data->
width * 2 * 3 + rgb_index * 2 + 1] + 0.5f;
330 if (new_x_int < 0 || new_x_int >= thread_data->
width || new_y_int < 0 || new_y_int >= thread_data->
height) {
342 if (new_x_int < 0 || new_x_int + 1 >= thread_data->
width || new_y_int < 0 || new_y_int + 1 >= thread_data->
height) {
346 thread_data->
data_in[ new_x_int * 3 + rgb_index + new_y_int * thread_data->
linesize_in] * (new_x_int + 1 - new_x) * (new_y_int + 1 - new_y)
347 + thread_data->
data_in[(new_x_int + 1) * 3 + rgb_index + new_y_int * thread_data->
linesize_in] * (new_x - new_x_int) * (new_y_int + 1 - new_y)
348 + thread_data->
data_in[ new_x_int * 3 + rgb_index + (new_y_int + 1) * thread_data->
linesize_in] * (new_x_int + 1 - new_x) * (new_y - new_y_int)
349 + thread_data->
data_in[(new_x_int + 1) * 3 + rgb_index + (new_y_int + 1) * thread_data->
linesize_in] * (new_x - new_x_int) * (new_y - new_y_int);
359 for (j = 0; j < 4; ++j)
360 for (i = 0; i < 4; ++i) {
361 if (new_x_int + i - 2 < 0 || new_x_int + i - 2 >= thread_data->
width || new_y_int + j - 2 < 0 || new_y_int + j - 2 >= thread_data->
height)
363 d =
square(new_x - (new_x_int + i - 2)) *
square(new_y - (new_y_int + j - 2));
368 interpolated += thread_data->
data_in[(new_x_int + i - 2) * 3 + rgb_index + (new_y_int + j - 2) * thread_data->
linesize_in] * d;
373 interpolated /= norm;
374 thread_data->
data_out[x * 3 + rgb_index + y * thread_data->
linesize_out] = interpolated < 0.0f ? 0.0f : interpolated > 255.0f ? 255.0f : interpolated;
384 if (new_x_int < 0 || new_x_int >= thread_data->
width || new_y_int < 0 || new_y_int >= thread_data->
height) {
396 if (new_x_int < 0 || new_x_int + 1 >= thread_data->
width || new_y_int < 0 || new_y_int + 1 >= thread_data->
height) {
400 thread_data->
data_in[ new_x_int * 3 + rgb_index + new_y_int * thread_data->
linesize_in] * (new_x_int + 1 - new_x) * (new_y_int + 1 - new_y)
401 + thread_data->
data_in[(new_x_int + 1) * 3 + rgb_index + new_y_int * thread_data->
linesize_in] * (new_x - new_x_int) * (new_y_int + 1 - new_y)
402 + thread_data->
data_in[ new_x_int * 3 + rgb_index + (new_y_int + 1) * thread_data->
linesize_in] * (new_x_int + 1 - new_x) * (new_y - new_y_int)
403 + thread_data->
data_in[(new_x_int + 1) * 3 + rgb_index + (new_y_int + 1) * thread_data->
linesize_in] * (new_x - new_x_int) * (new_y - new_y_int);
413 for (j = 0; j < 4; ++j)
414 for (i = 0; i < 4; ++i) {
415 if (new_x_int + i - 2 < 0 || new_x_int + i - 2 >= thread_data->
width || new_y_int + j - 2 < 0 || new_y_int + j - 2 >= thread_data->
height)
417 d =
square(new_x - (new_x_int + i - 2)) *
square(new_y - (new_y_int + j - 2));
422 interpolated += thread_data->
data_in[(new_x_int + i - 2) * 3 + rgb_index + (new_y_int + j - 2) * thread_data->
linesize_in] * d;
427 interpolated /= norm;
428 thread_data->
data_out[x * 3 + rgb_index + y * thread_data->
linesize_out] = interpolated < 0.0f ? 0.0f : interpolated > 255.0f ? 255.0f : interpolated;
456 .data_in = in->
data[0],
464 &vignetting_thread_data,
481 .data_in = in->
data[0],
482 .data_out = out->
data[0],
486 .mode = lensfun->
mode,
492 &distortion_correction_thread_data,
508 lf_camera_destroy(lensfun->
camera);
510 lf_lens_destroy(lensfun->
lens);
512 lf_modifier_destroy(lensfun->
modifier);
537 .description =
NULL_IF_CONFIG_SMALL(
"Apply correction to an image based on info derived from the lensfun database."),
544 .priv_class = &lensfun_class,
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
int h
agreed upon image height
static const AVFilterPad lensfun_outputs[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
struct AVFilterGraph * graph
filtergraph this filter belongs to
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static float lanczos_kernel(float x)
static uint32_t reverse(uint32_t num, int bits)
static int query_formats(AVFilterContext *ctx)
Mode
Frame type (Table 1a in 3GPP TS 26.101)
int nb_threads
Maximum number of threads used by filters in this graph.
const float * distortion_coords
A filter pad used for either input or output.
A link between two filters.
static int distortion_correction_filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold int init(AVFilterContext *ctx)
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 AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
simple assert() macros that are a bit more flexible than ISO C assert().
static av_cold void uninit(AVFilterContext *ctx)
static float square(float x)
static const AVOption lensfun_options[]
int w
agreed upon image width
static int config_props(AVFilterLink *inlink)
AVFILTER_DEFINE_CLASS(lensfun)
float * distortion_coords
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
#define AV_LOG_INFO
Standard information.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int vignetting_filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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.
#define LANCZOS_RESOLUTION
const char * name
Filter name.
static const AVFilterPad lensfun_inputs[]
AVFilterLink ** outputs
array of pointers to output links
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const float * interpolation
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVFilterContext * dst
dest filter
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define av_malloc_array(a, b)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVPixelFormat
Pixel format.
mode
Use these values in ebur128_init (or'ed).
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.