42 #define LANCZOS_RESOLUTION 256
95 #define OFFSET(x) offsetof(LensfunContext, x)
96 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
109 {
"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 },
110 {
"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 },
111 {
"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 },
112 {
"scale",
"scale factor applied after corrections (0.0 means automatic scaling)",
OFFSET(scale),
AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, DBL_MAX,
FLAGS },
113 {
"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" },
114 {
"rectilinear",
"rectilinear lens (default)", 0,
AV_OPT_TYPE_CONST, {.i64=LF_RECTILINEAR}, 0, 0,
FLAGS,
"lens_geometry" },
116 {
"panoramic",
"panoramic (cylindrical)", 0,
AV_OPT_TYPE_CONST, {.i64=LF_PANORAMIC}, 0, 0,
FLAGS,
"lens_geometry" },
117 {
"equirectangular",
"equirectangular", 0,
AV_OPT_TYPE_CONST, {.i64=LF_EQUIRECTANGULAR}, 0, 0,
FLAGS,
"lens_geometry" },
118 {
"fisheye_orthographic",
"orthographic fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_ORTHOGRAPHIC}, 0, 0,
FLAGS,
"lens_geometry" },
119 {
"fisheye_stereographic",
"stereographic fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_STEREOGRAPHIC}, 0, 0,
FLAGS,
"lens_geometry" },
120 {
"fisheye_equisolid",
"equisolid fisheye", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_EQUISOLID}, 0, 0,
FLAGS,
"lens_geometry" },
121 {
"fisheye_thoby",
"fisheye as measured by thoby", 0,
AV_OPT_TYPE_CONST, {.i64=LF_FISHEYE_THOBY}, 0, 0,
FLAGS,
"lens_geometry" },
136 const lfCamera **cameras;
137 const lfLens **lenses;
139 if (!lensfun->
make) {
142 }
else if (!lensfun->
model) {
150 lensfun->
lens = lf_lens_new();
151 lensfun->
camera = lf_camera_new();
154 if (lf_db_load(db) != LF_NO_ERROR) {
160 cameras = lf_db_find_cameras(db, lensfun->
make, lensfun->
model);
161 if (cameras && *cameras) {
162 lf_camera_copy(lensfun->
camera, *cameras);
173 if (lenses && *lenses) {
174 lf_lens_copy(lensfun->
lens, *lenses);
200 }
else if (x > -2.0
f && x < 2.0
f) {
213 int lensfun_mode = 0;
218 lensfun->
camera->CropFactor,
222 lensfun_mode |= LF_MODIFY_VIGNETTING;
224 lensfun_mode |= LF_MODIFY_DISTORTION | LF_MODIFY_GEOMETRY | LF_MODIFY_SCALE;
226 lensfun_mode |= LF_MODIFY_TCA;
227 lf_modifier_initialize(lensfun->
modifier,
250 lf_modifier_apply_subpixel_geometry_distortion(lensfun->
modifier,
256 lf_modifier_apply_subpixel_distortion(lensfun->
modifier,
266 lf_modifier_apply_geometry_distortion(lensfun->
modifier,
294 const int slice_start =
thread_data->height * jobnr / nb_jobs;
297 lf_modifier_apply_color_modification(
thread_data->modifier,
317 const int slice_start =
thread_data->height * jobnr / nb_jobs;
320 int x, y,
i, j, rgb_index;
321 float interpolated, new_x, new_y, d, norm;
322 int new_x_int, new_y_int;
323 for (y = slice_start; y <
slice_end; ++y)
325 for (rgb_index = 0; rgb_index < 3; ++rgb_index) {
330 new_x_int =
thread_data->distortion_coords[x * 2 * 3 + y *
thread_data->width * 2 * 3 + rgb_index * 2] + 0.5f;
331 new_y_int =
thread_data->distortion_coords[x * 2 * 3 + y *
thread_data->width * 2 * 3 + rgb_index * 2 + 1] + 0.5f;
332 if (new_x_int < 0 || new_x_int >=
thread_data->width || new_y_int < 0 || new_y_int >=
thread_data->height) {
344 if (new_x_int < 0 || new_x_int + 1 >=
thread_data->width || new_y_int < 0 || new_y_int + 1 >=
thread_data->height) {
348 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)
349 +
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)
350 +
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)
351 +
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);
361 for (j = 0; j < 4; ++j)
362 for (
i = 0;
i < 4; ++
i) {
363 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)
365 d =
square(new_x - (new_x_int +
i - 2)) *
square(new_y - (new_y_int + j - 2));
370 interpolated +=
thread_data->data_in[(new_x_int +
i - 2) * 3 + rgb_index + (new_y_int + j - 2) *
thread_data->linesize_in] * d;
375 interpolated /= norm;
376 thread_data->data_out[x * 3 + rgb_index + y *
thread_data->linesize_out] = interpolated < 0.0f ? 0.0f : interpolated > 255.0f ? 255.0f : interpolated;
386 if (new_x_int < 0 || new_x_int >=
thread_data->width || new_y_int < 0 || new_y_int >=
thread_data->height) {
398 if (new_x_int < 0 || new_x_int + 1 >=
thread_data->width || new_y_int < 0 || new_y_int + 1 >=
thread_data->height) {
402 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)
403 +
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)
404 +
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)
405 +
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);
415 for (j = 0; j < 4; ++j)
416 for (
i = 0;
i < 4; ++
i) {
417 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)
419 d =
square(new_x - (new_x_int +
i - 2)) *
square(new_y - (new_y_int + j - 2));
424 interpolated +=
thread_data->data_in[(new_x_int +
i - 2) * 3 + rgb_index + (new_y_int + j - 2) *
thread_data->linesize_in] * d;
429 interpolated /= norm;
430 thread_data->data_out[x * 3 + rgb_index + y *
thread_data->linesize_out] = interpolated < 0.0f ? 0.0f : interpolated > 255.0f ? 255.0f : interpolated;
458 .data_in =
in->data[0],
459 .linesize_in =
in->linesize[0],
466 &vignetting_thread_data,
483 .data_in =
in->data[0],
484 .data_out =
out->data[0],
485 .linesize_in =
in->linesize[0],
486 .linesize_out =
out->linesize[0],
488 .mode = lensfun->
mode,
494 &distortion_correction_thread_data,
510 lf_camera_destroy(lensfun->
camera);
512 lf_lens_destroy(lensfun->
lens);
514 lf_modifier_destroy(lensfun->
modifier);
539 .description =
NULL_IF_CONFIG_SMALL(
"Apply correction to an image based on info derived from the lensfun database."),
546 .priv_class = &lensfun_class,