| @@ -41,88 +41,7 @@ · 40 unmodified lines |
| 41 | #include "formats.h" | 41 | #include "formats.h" |
| 42 | #include "internal.h" | 42 | #include "internal.h" |
| 43 | #include "video.h" | 43 | #include "video.h" |
| 44 | | 44 | #include "v360.h" |
| 45 | enum Projections { | | |
| 46 | EQUIRECTANGULAR, | | |
| 47 | CUBEMAP_3_2, | | |
| 48 | CUBEMAP_6_1, | | |
| 49 | EQUIANGULAR, | | |
| 50 | FLAT, | | |
| 51 | DUAL_FISHEYE, | | |
| 52 | BARREL, | | |
| 53 | CUBEMAP_1_6, | | |
| 54 | NB_PROJECTIONS, | | |
| 55 | }; | | |
| 56 | | | |
| 57 | enum InterpMethod { | | |
| 58 | NEAREST, | | |
| 59 | BILINEAR, | | |
| 60 | BICUBIC, | | |
| 61 | LANCZOS, | | |
| 62 | NB_INTERP_METHODS, | | |
| 63 | }; | | |
| 64 | | | |
| 65 | enum Faces { | | |
| 66 | TOP_LEFT, | | |
| 67 | TOP_MIDDLE, | | |
| 68 | TOP_RIGHT, | | |
| 69 | BOTTOM_LEFT, | | |
| 70 | BOTTOM_MIDDLE, | | |
| 71 | BOTTOM_RIGHT, | | |
| 72 | NB_FACES, | | |
| 73 | }; | | |
| 74 | | | |
| 75 | enum Direction { | | |
| 76 | RIGHT, ///< Axis +X | | |
| 77 | LEFT, ///< Axis -X | | |
| 78 | UP, ///< Axis +Y | | |
| 79 | DOWN, ///< Axis -Y | | |
| 80 | FRONT, ///< Axis -Z | | |
| 81 | BACK, ///< Axis +Z | | |
| 82 | NB_DIRECTIONS, | | |
| 83 | }; | | |
| 84 | | | |
| 85 | enum Rotation { | | |
| 86 | ROT_0, | | |
| 87 | ROT_90, | | |
| 88 | ROT_180, | | |
| 89 | ROT_270, | | |
| 90 | NB_ROTATIONS, | | |
| 91 | }; | | |
| 92 | | | |
| 93 | typedef struct V360Context { | | |
| 94 | const AVClass *class; | | |
| 95 | int in, out; | | |
| 96 | int interp; | | |
| 97 | int width, height; | | |
| 98 | char* in_forder; | | |
| 99 | char* out_forder; | | |
| 100 | char* in_frot; | | |
| 101 | char* out_frot; | | |
| 102 | | | |
| 103 | int in_cubemap_face_order[6]; | | |
| 104 | int out_cubemap_direction_order[6]; | | |
| 105 | int in_cubemap_face_rotation[6]; | | |
| 106 | int out_cubemap_face_rotation[6]; | | |
| 107 | | | |
| 108 | float in_pad, out_pad; | | |
| 109 | | | |
| 110 | float yaw, pitch, roll; | | |
| 111 | | | |
| 112 | int h_flip, v_flip, d_flip; | | |
| 113 | | | |
| 114 | float h_fov, v_fov; | | |
| 115 | float flat_range[3]; | | |
| 116 | | | |
| 117 | int planewidth[4], planeheight[4]; | | |
| 118 | int inplanewidth[4], inplaneheight[4]; | | |
| 119 | int nb_planes; | | |
| 120 | | | |
| 121 | uint16_t *u[4], *v[4]; | | |
| 122 | int16_t *ker[4]; | | |
| 123 | | | |
| 124 | int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); | | |
| 125 | } V360Context; | | |
| 126 | | 45 | |
| 127 | typedef struct ThreadData { | 46 | typedef struct ThreadData { |
| 128 | AVFrame *in; | 47 | AVFrame *in; |
| @@ -251,47 +170,22 @@ static int query_formats(AVFilterContext *ctx) · 122 unmodified lines |
| 251 | return ff_set_common_formats(ctx, fmts_list); | 170 | return ff_set_common_formats(ctx, fmts_list); |
| 252 | } | 171 | } |
| 253 | | 172 | |
| 254 | /** | 173 | #define DEFINE_REMAP1_LINE(bits, div) \ |
| 255 | * Generate no-interpolation remapping function with a given pixel depth. | 174 | static void remap1_##bits##bit_line_c(uint8_t *dst, int width, const uint8_t *src, \ |
| 256 | * | 175 | ptrdiff_t in_linesize, \ |
| 257 | * @param bits number of bits per pixel | 176 | const uint16_t *u, const uint16_t *v, const int16_t *ker) \ |
| 258 | * @param div number of bytes per pixel | 177 | { \ |
| 259 | */ | 178 | const uint##bits##_t *s = (const uint##bits##_t *)src; \ |
| 260 | #define DEFINE_REMAP1(bits, div) \ | 179 | uint##bits##_t *d = (uint##bits##_t *)dst; \ |
| 261 | static int remap1_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ | 180 | \ |
| 262 | { \ | 181 | in_linesize /= div; \ |
| 263 | ThreadData *td = (ThreadData*)arg; \ | 182 | \ |
| 264 | const V360Context *s = ctx->priv; \ | 183 | for (int x = 0; x < width; x++) \ |
| 265 | const AVFrame *in = td->in; \ | 184 | d[x] = s[v[x] * in_linesize + u[x]]; \ |
| 266 | AVFrame *out = td->out; \ | | |
| 267 | \ | | |
| 268 | int plane, x, y; \ | | |
| 269 | \ | | |
| 270 | for (plane = 0; plane < s->nb_planes; plane++) { \ | | |
| 271 | const int in_linesize = in->linesize[plane] / div; \ | | |
| 272 | const int out_linesize = out->linesize[plane] / div; \ | | |
| 273 | const uint##bits##_t *src = (const uint##bits##_t *)in->data[plane]; \ | | |
| 274 | uint##bits##_t *dst = (uint##bits##_t *)out->data[plane]; \ | | |
| 275 | const int width = s->planewidth[plane]; \ | | |
| 276 | const int height = s->planeheight[plane]; \ | | |
| 277 | \ | | |
| 278 | const int slice_start = (height * jobnr ) / nb_jobs; \ | | |
| 279 | const int slice_end = (height * (jobnr + 1)) / nb_jobs; \ | | |
| 280 | \ | | |
| 281 | for (y = slice_start; y < slice_end; y++) { \ | | |
| 282 | const uint16_t *u = s->u[plane] + y * width; \ | | |
| 283 | const uint16_t *v = s->v[plane] + y * width; \ | | |
| 284 | uint##bits##_t *d = dst + y * out_linesize; \ | | |
| 285 | for (x = 0; x < width; x++) \ | | |
| 286 | *d++ = src[v[x] * in_linesize + u[x]]; \ | | |
| 287 | } \ | | |
| 288 | } \ | | |
| 289 | \ | | |
| 290 | return 0; \ | | |
| 291 | } | 185 | } |
| 292 | | 186 | |
| 293 | DEFINE_REMAP1( 8, 1) | 187 | DEFINE_REMAP1_LINE( 8, 1) |
| 294 | DEFINE_REMAP1(16, 2) | 188 | DEFINE_REMAP1_LINE(16, 2) |
| 295 | | 189 | |
| 296 | typedef struct XYRemap { | 190 | typedef struct XYRemap { |
| 297 | uint16_t u[4][4]; | 191 | uint16_t u[4][4]; |
| @@ -304,9 +198,8 @@ typedef struct XYRemap { · 6 unmodified lines |
| 304 | * | 198 | * |
| 305 | * @param ws size of interpolation window | 199 | * @param ws size of interpolation window |
| 306 | * @param bits number of bits per pixel | 200 | * @param bits number of bits per pixel |
| 307 | * @param div number of bytes per pixel | | |
| 308 | */ | 201 | */ |
| 309 | #define DEFINE_REMAP(ws, bits, div) \ | 202 | #define DEFINE_REMAP(ws, bits) \ |
| 310 | static int remap##ws##_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ | 203 | static int remap##ws##_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ |
| 311 | { \ | 204 | { \ |
| 312 | ThreadData *td = (ThreadData*)arg; \ | 205 | ThreadData *td = (ThreadData*)arg; \ |
| @@ -314,48 +207,85 @@ static int remap##ws##_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jo · 1 unmodified line |
| 314 | const AVFrame *in = td->in; \ | 207 | const AVFrame *in = td->in; \ |
| 315 | AVFrame *out = td->out; \ | 208 | AVFrame *out = td->out; \ |
| 316 | \ | 209 | \ |
| 317 | int plane, x, y, i, j; \ | 210 | for (int plane = 0; plane < s->nb_planes; plane++) { \ |
| 318 | \ | 211 | const int in_linesize = in->linesize[plane]; \ |
| 319 | for (plane = 0; plane < s->nb_planes; plane++) { \ | 212 | const int out_linesize = out->linesize[plane]; \ |
| 320 | const int in_linesize = in->linesize[plane] / div; \ | 213 | const uint8_t *src = in->data[plane]; \ |
| 321 | const int out_linesize = out->linesize[plane] / div; \ | 214 | uint8_t *dst = out->data[plane]; \ |
| 322 | const uint##bits##_t *src = (const uint##bits##_t *)in->data[plane]; \ | | |
| 323 | uint##bits##_t *dst = (uint##bits##_t *)out->data[plane]; \ | | |
| 324 | const int width = s->planewidth[plane]; \ | 215 | const int width = s->planewidth[plane]; \ |
| 325 | const int height = s->planeheight[plane]; \ | 216 | const int height = s->planeheight[plane]; \ |
| 326 | \ | 217 | \ |
| 327 | const int slice_start = (height * jobnr ) / nb_jobs; \ | 218 | const int slice_start = (height * jobnr ) / nb_jobs; \ |
| 328 | const int slice_end = (height * (jobnr + 1)) / nb_jobs; \ | 219 | const int slice_end = (height * (jobnr + 1)) / nb_jobs; \ |
| 329 | \ | 220 | \ |
| 330 | for (y = slice_start; y < slice_end; y++) { \ | 221 | for (int y = slice_start; y < slice_end; y++) { \ |
| 331 | uint##bits##_t *d = dst + y * out_linesize; \ | | |
| 332 | const uint16_t *u = s->u[plane] + y * width * ws * ws; \ | 222 | const uint16_t *u = s->u[plane] + y * width * ws * ws; \ |
| 333 | const uint16_t *v = s->v[plane] + y * width * ws * ws; \ | 223 | const uint16_t *v = s->v[plane] + y * width * ws * ws; \ |
| 334 | const int16_t *ker = s->ker[plane] + y * width * ws * ws; \ | 224 | const int16_t *ker = s->ker[plane] + y * width * ws * ws; \ |
| 335 | for (x = 0; x < width; x++) { \ | | |
| 336 | const uint16_t *uu = u + x * ws * ws; \ | | |
| 337 | const uint16_t *vv = v + x * ws * ws; \ | | |
| 338 | const int16_t *kker = ker + x * ws * ws; \ | | |
| 339 | int tmp = 0; \ | | |
| 340 | \ | | |
| 341 | for (i = 0; i < ws; i++) { \ | | |
| 342 | for (j = 0; j < ws; j++) { \ | | |
| 343 | tmp += kker[i * ws + j] * src[vv[i * ws + j] * in_linesize + uu[i * ws + j]]; \ | | |
| 344 | } \ | | |
| 345 | } \ | | |
| 346 | \ | 225 | \ |
| 347 | *d++ = av_clip_uint##bits(tmp >> (15 - ws)); \ | 226 | s->remap_line(dst + y * out_linesize, width, src, in_linesize, u, v, ker); \ |
| 348 | } \ | | |
| 349 | } \ | 227 | } \ |
| 350 | } \ | 228 | } \ |
| 351 | \ | 229 | \ |
| 352 | return 0; \ | 230 | return 0; \ |
| 353 | } | 231 | } |
| 354 | | 232 | |
| 355 | DEFINE_REMAP(2, 8, 1) | 233 | DEFINE_REMAP(1, 8) |
| 356 | DEFINE_REMAP(4, 8, 1) | 234 | DEFINE_REMAP(2, 8) |
| 357 | DEFINE_REMAP(2, 16, 2) | 235 | DEFINE_REMAP(4, 8) |
| 358 | DEFINE_REMAP(4, 16, 2) | 236 | DEFINE_REMAP(1, 16) |
| | 237 | DEFINE_REMAP(2, 16) |
| | 238 | DEFINE_REMAP(4, 16) |
| | 239 | |
| | 240 | #define DEFINE_REMAP_LINE(ws, bits, div) \ |
| | 241 | static void remap##ws##_##bits##bit_line_c(uint8_t *dst, int width, const uint8_t *src, \ |
| | 242 | ptrdiff_t in_linesize, \ |
| | 243 | const uint16_t *u, const uint16_t *v, const int16_t *ker) \ |
| | 244 | { \ |
| | 245 | const uint##bits##_t *s = (const uint##bits##_t *)src; \ |
| | 246 | uint##bits##_t *d = (uint##bits##_t *)dst; \ |
| | 247 | \ |
| | 248 | in_linesize /= div; \ |
| | 249 | \ |
| | 250 | for (int x = 0; x < width; x++) { \ |
| | 251 | const uint16_t *uu = u + x * ws * ws; \ |
| | 252 | const uint16_t *vv = v + x * ws * ws; \ |
| | 253 | const int16_t *kker = ker + x * ws * ws; \ |
| | 254 | int tmp = 0; \ |
| | 255 | \ |
| | 256 | for (int i = 0; i < ws; i++) { \ |
| | 257 | for (int j = 0; j < ws; j++) { \ |
| | 258 | tmp += kker[i * ws + j] * s[vv[i * ws + j] * in_linesize + uu[i * ws + j]]; \ |
| | 259 | } \ |
| | 260 | } \ |
| | 261 | \ |
| | 262 | d[x] = av_clip_uint##bits(tmp >> 14); \ |
| | 263 | } \ |
| | 264 | } |
| | 265 | |
| | 266 | DEFINE_REMAP_LINE(2, 8, 1) |
| | 267 | DEFINE_REMAP_LINE(4, 8, 1) |
| | 268 | DEFINE_REMAP_LINE(2, 16, 2) |
| | 269 | DEFINE_REMAP_LINE(4, 16, 2) |
| | 270 | |
| | 271 | void ff_v360_init(V360Context *s, int depth) |
| | 272 | { |
| | 273 | switch (s->interp) { |
| | 274 | case NEAREST: |
| | 275 | s->remap_line = depth <= 8 ? remap1_8bit_line_c : remap1_16bit_line_c; |
| | 276 | break; |
| | 277 | case BILINEAR: |
| | 278 | s->remap_line = depth <= 8 ? remap2_8bit_line_c : remap2_16bit_line_c; |
| | 279 | break; |
| | 280 | case BICUBIC: |
| | 281 | case LANCZOS: |
| | 282 | s->remap_line = depth <= 8 ? remap4_8bit_line_c : remap4_16bit_line_c; |
| | 283 | break; |
| | 284 | } |
| | 285 | |
| | 286 | if (ARCH_X86_64) |
| | 287 | ff_v360_init_x86(s, depth); |
| | 288 | } |
| 359 | | 289 | |
| 360 | /** | 290 | /** |
| 361 | * Save nearest pixel coordinates for remapping. | 291 | * Save nearest pixel coordinates for remapping. |
| @@ -399,10 +329,10 @@ static void bilinear_kernel(float du, float dv, const XYRemap *r_tmp, · 37 unmodified lines |
| 399 | } | 329 | } |
| 400 | } | 330 | } |
| 401 | | 331 | |
| 402 | ker[0] = (1.f - du) * (1.f - dv) * 8192; | 332 | ker[0] = (1.f - du) * (1.f - dv) * 16384; |
| 403 | ker[1] = du * (1.f - dv) * 8192; | 333 | ker[1] = du * (1.f - dv) * 16384; |
| 404 | ker[2] = (1.f - du) * dv * 8192; | 334 | ker[2] = (1.f - du) * dv * 16384; |
| 405 | ker[3] = du * dv * 8192; | 335 | ker[3] = du * dv * 16384; |
| 406 | } | 336 | } |
| 407 | | 337 | |
| 408 | /** | 338 | /** |
| @@ -446,7 +376,7 @@ static void bicubic_kernel(float du, float dv, const XYRemap *r_tmp, · 37 unmodified lines |
| 446 | for (j = 0; j < 4; j++) { | 376 | for (j = 0; j < 4; j++) { |
| 447 | u[i * 4 + j] = r_tmp->u[i][j]; | 377 | u[i * 4 + j] = r_tmp->u[i][j]; |
| 448 | v[i * 4 + j] = r_tmp->v[i][j]; | 378 | v[i * 4 + j] = r_tmp->v[i][j]; |
| 449 | ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 2048; | 379 | ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 16384; |
| 450 | } | 380 | } |
| 451 | } | 381 | } |
| 452 | } | 382 | } |
| @@ -501,7 +431,7 @@ static void lanczos_kernel(float du, float dv, const XYRemap *r_tmp, · 48 unmodified lines |
| 501 | for (j = 0; j < 4; j++) { | 431 | for (j = 0; j < 4; j++) { |
| 502 | u[i * 4 + j] = r_tmp->u[i][j]; | 432 | u[i * 4 + j] = r_tmp->u[i][j]; |
| 503 | v[i * 4 + j] = r_tmp->v[i][j]; | 433 | v[i * 4 + j] = r_tmp->v[i][j]; |
| 504 | ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 2048; | 434 | ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 16384; |
| 505 | } | 435 | } |
| 506 | } | 436 | } |
| 507 | } | 437 | } |
| @@ -2038,6 +1968,8 @@ static int config_output(AVFilterLink *outlink) · 1530 unmodified lines |
| 2038 | av_assert0(0); | 1968 | av_assert0(0); |
| 2039 | } | 1969 | } |
| 2040 | | 1970 | |
| | 1971 | ff_v360_init(s, depth); |
| | 1972 | |
| 2041 | switch (s->in) { | 1973 | switch (s->in) { |
| 2042 | case EQUIRECTANGULAR: | 1974 | case EQUIRECTANGULAR: |
| 2043 | in_transform = xyz_to_equirect; | 1975 | in_transform = xyz_to_equirect; |