39#define LANCZOS_RESOLUTION 256
92#define OFFSET(x) offsetof(LensfunContext, x)
93#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
107 {
"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 },
108 {
"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 },
109 {
"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, .unit =
"lens_geometry" },
112 {
"rectilinear",
"rectilinear lens (default)", 0,
AV_OPT_TYPE_CONST, {.i64=LF_RECTILINEAR}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
113 {
"fisheye",
"fisheye lens", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
114 {
"panoramic",
"panoramic (cylindrical)", 0,
AV_OPT_TYPE_CONST, {.i64=LF_PANORAMIC}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
115 {
"equirectangular",
"equirectangular", 0,
AV_OPT_TYPE_CONST, {.i64=LF_EQUIRECTANGULAR}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
116 {
"fisheye_orthographic",
"orthographic fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_ORTHOGRAPHIC}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
117 {
"fisheye_stereographic",
"stereographic fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_STEREOGRAPHIC}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
118 {
"fisheye_equisolid",
"equisolid fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_EQUISOLID}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
119 {
"fisheye_thoby",
"fisheye as measured by thoby", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_THOBY}, 0, 0,
FLAGS, .unit =
"lens_geometry" },
134 const lfCamera **cameras;
135 const lfLens **lenses;
138 if ((lensfun->
db_path ? lf_db_load_path(db, lensfun->
db_path) : lf_db_load(db)) != LF_NO_ERROR) {
146 const lfCamera *
const *cameras = lf_db_get_cameras(db);
150 for (
int i = 0; cameras && cameras[
i];
i++)
155 const lfLens *
const *lenses = lf_db_get_lenses(db);
159 for (
int i = 0; lenses && lenses[
i];
i++)
165 lensfun->
lens = lf_lens_create();
166 lensfun->
camera = lf_camera_create();
168 cameras = lf_db_find_cameras(db, lensfun->
make, lensfun->
model);
169 if (cameras && *cameras) {
170 lf_camera_copy(lensfun->
camera, *cameras);
181 if (lenses && *lenses) {
182 lf_lens_copy(lensfun->
lens, *lenses);
200 }
else if (x > -2.0f && x < 2.0f) {
201 return (2.0f * sin(
M_PI * x) * sin(
M_PI / 2.0f * x)) / (
M_PI *
M_PI * x * x);
218 lensfun->
camera->CropFactor,
220 inlink->
h, LF_PF_U8, lensfun->
reverse);
224 lf_modifier_enable_distortion_correction(lensfun->
modifier);
226 lf_modifier_enable_scaling(lensfun->
modifier, lensfun->
scale);
229 lf_modifier_enable_tca_correction(lensfun->
modifier);
243 lf_modifier_apply_subpixel_geometry_distortion(lensfun->
modifier,
245 inlink->
w, inlink->
h,
249 lf_modifier_apply_subpixel_distortion(lensfun->
modifier,
251 inlink->
w, inlink->
h,
259 lf_modifier_apply_geometry_distortion(lensfun->
modifier,
261 inlink->
w, inlink->
h,
290 lf_modifier_apply_color_modification(
thread_data->modifier,
313 int x, y,
i, j, rgb_index;
314 float interpolated, new_x, new_y, d, norm;
315 int new_x_int, new_y_int;
318 for (rgb_index = 0; rgb_index < 3; ++rgb_index) {
323 new_x_int =
thread_data->distortion_coords[x * 2 * 3 + y *
thread_data->width * 2 * 3 + rgb_index * 2] + 0.5f;
324 new_y_int =
thread_data->distortion_coords[x * 2 * 3 + y *
thread_data->width * 2 * 3 + rgb_index * 2 + 1] + 0.5f;
325 if (new_x_int < 0 || new_x_int >=
thread_data->width || new_y_int < 0 || new_y_int >=
thread_data->height) {
337 if (new_x_int < 0 || new_x_int + 1 >=
thread_data->width || new_y_int < 0 || new_y_int + 1 >=
thread_data->height) {
341 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)
342 +
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)
343 +
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)
344 +
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);
354 for (j = 0; j < 4; ++j)
355 for (
i = 0;
i < 4; ++
i) {
356 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)
358 d =
square(new_x - (new_x_int +
i - 2)) *
square(new_y - (new_y_int + j - 2));
363 interpolated +=
thread_data->data_in[(new_x_int +
i - 2) * 3 + rgb_index + (new_y_int + j - 2) *
thread_data->linesize_in] * d;
368 interpolated /= norm;
369 thread_data->data_out[x * 3 + rgb_index + y *
thread_data->linesize_out] = interpolated < 0.0f ? 0.0f : interpolated > 255.0f ? 255.0f : interpolated;
379 if (new_x_int < 0 || new_x_int >=
thread_data->width || new_y_int < 0 || new_y_int >=
thread_data->height) {
391 if (new_x_int < 0 || new_x_int + 1 >=
thread_data->width || new_y_int < 0 || new_y_int + 1 >=
thread_data->height) {
395 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)
396 +
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)
397 +
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)
398 +
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);
408 for (j = 0; j < 4; ++j)
409 for (
i = 0;
i < 4; ++
i) {
410 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)
412 d =
square(new_x - (new_x_int +
i - 2)) *
square(new_y - (new_y_int + j - 2));
417 interpolated +=
thread_data->data_in[(new_x_int +
i - 2) * 3 + rgb_index + (new_y_int + j - 2) *
thread_data->linesize_in] * d;
422 interpolated /= norm;
423 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],
463 &vignetting_thread_data,
NULL,
479 .data_in = in->
data[0],
480 .data_out =
out->data[0],
482 .linesize_out =
out->linesize[0],
484 .mode = lensfun->
mode,
489 &distortion_correction_thread_data,
NULL,
504 lf_camera_destroy(lensfun->
camera);
506 lf_lens_destroy(lensfun->
lens);
508 lf_modifier_destroy(lensfun->
modifier);
524 .p.description =
NULL_IF_CONFIG_SMALL(
"Apply correction to an image based on info derived from the lensfun database."),
525 .p.priv_class = &lensfun_class,
const FFFilter ff_vf_lensfun
Mode
Frame type (Table 1a in 3GPP TS 26.101)
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
static uint64_t reverse(uint64_t p, unsigned int deg)
static __device__ float sqrtf(float a)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_INFO
Standard information.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
static int config_props(AVBitStreamFilterLink *link)
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
const float * interpolation
const float * distortion_coords
float * distortion_coords
#define av_malloc_array(a, b)
#define NEAREST(type, name)
static int vignetting_filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static float lanczos_kernel(float x)
static int distortion_correction_filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVOption lensfun_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static const AVFilterPad lensfun_inputs[]
static int config_props(AVFilterLink *inlink)
static float square(float x)
static av_cold void uninit(AVFilterContext *ctx)
#define LANCZOS_RESOLUTION
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)