Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -85,6 +85,12 @@ enum RotationOrder { · 84 unmodified lines | ||
| 85 | 85 | NB_RORDERS, |
| 86 | 86 | }; |
| 87 | 87 | |
| 88 | +typedef struct XYRemap { | |
| 89 | + uint16_t u[4][4]; | |
| 90 | + uint16_t v[4][4]; | |
| 91 | + float ker[4][4]; | |
| 92 | +} XYRemap; | |
| 93 | + | |
| 88 | 94 | typedef struct V360Context { |
| 89 | 95 | const AVClass *class; |
| 90 | 96 | int in, out; |
| @@ -130,11 +136,23 @@ typedef struct V360Context { · 39 unmodified lines | ||
| 130 | 136 | int uv_linesize[4]; |
| 131 | 137 | int nb_planes; |
| 132 | 138 | int nb_allocated; |
| 139 | + int elements; | |
| 133 | 140 | |
| 134 | 141 | uint16_t *u[4], *v[4]; |
| 135 | 142 | int16_t *ker[4]; |
| 136 | 143 | unsigned map[4]; |
| 137 | 144 | |
| 145 | + void (*in_transform)(const struct V360Context *s, | |
| 146 | + const float *vec, int width, int height, | |
| 147 | + uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv); | |
| 148 | + | |
| 149 | + void (*out_transform)(const struct V360Context *s, | |
| 150 | + int i, int j, int width, int height, | |
| 151 | + float *vec); | |
| 152 | + | |
| 153 | + void (*calculate_kernel)(float du, float dv, const XYRemap *rmap, | |
| 154 | + uint16_t *u, uint16_t *v, int16_t *ker); | |
| 155 | + | |
| 138 | 156 | int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); |
| 139 | 157 | |
| 140 | 158 | void (*remap_line)(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize, |
| @@ -207,12 +207,6 @@ static void remap1_##bits##bit_line_c(uint8_t *dst, int width, const uint8_t *sr · 206 unmodified lines | ||
| 207 | 207 | DEFINE_REMAP1_LINE( 8, 1) |
| 208 | 208 | DEFINE_REMAP1_LINE(16, 2) |
| 209 | 209 | |
| 210 | −typedef struct XYRemap { | |
| 211 | − uint16_t u[4][4]; | |
| 212 | − uint16_t v[4][4]; | |
| 213 | − float ker[4][4]; | |
| 214 | −} XYRemap; | |
| 215 | − | |
| 216 | 210 | /** |
| 217 | 211 | * Generate remapping function with a given window size and pixel depth. |
| 218 | 212 | * |
| @@ -2167,6 +2161,47 @@ static void set_dimensions(int *outw, int *outh, int w, int h, const AVPixFmtDes · 1948 unmodified lines | ||
| 2167 | 2161 | outh[0] = outh[3] = h; |
| 2168 | 2162 | } |
| 2169 | 2163 | |
| 2164 | +// Calculate remap data | |
| 2165 | +static av_always_inline void v360_filter(AVFilterContext *ctx) | |
| 2166 | +{ | |
| 2167 | + V360Context *s = ctx->priv; | |
| 2168 | + | |
| 2169 | + for (int p = 0; p < s->nb_allocated; p++) { | |
| 2170 | + const int width = s->pr_width[p]; | |
| 2171 | + const int uv_linesize = s->uv_linesize[p]; | |
| 2172 | + const int height = s->pr_height[p]; | |
| 2173 | + const int in_width = s->inplanewidth[p]; | |
| 2174 | + const int in_height = s->inplaneheight[p]; | |
| 2175 | + float du, dv; | |
| 2176 | + float vec[3]; | |
| 2177 | + XYRemap rmap; | |
| 2178 | + | |
| 2179 | + for (int j = 0; j < height; j++) { | |
| 2180 | + for (int i = 0; i < width; i++) { | |
| 2181 | + uint16_t *u = s->u[p] + (j * uv_linesize + i) * s->elements; | |
| 2182 | + uint16_t *v = s->v[p] + (j * uv_linesize + i) * s->elements; | |
| 2183 | + int16_t *ker = s->ker[p] + (j * uv_linesize + i) * s->elements; | |
| 2184 | + | |
| 2185 | + if (s->out_transpose) | |
| 2186 | + s->out_transform(s, j, i, height, width, vec); | |
| 2187 | + else | |
| 2188 | + s->out_transform(s, i, j, width, height, vec); | |
| 2189 | + av_assert1(!isnan(vec[0]) && !isnan(vec[1]) && !isnan(vec[2])); | |
| 2190 | + rotate(s->rot_mat, vec); | |
| 2191 | + av_assert1(!isnan(vec[0]) && !isnan(vec[1]) && !isnan(vec[2])); | |
| 2192 | + normalize_vector(vec); | |
| 2193 | + mirror(s->output_mirror_modifier, vec); | |
| 2194 | + if (s->in_transpose) | |
| 2195 | + s->in_transform(s, vec, in_height, in_width, rmap.v, rmap.u, &du, &dv); | |
| 2196 | + else | |
| 2197 | + s->in_transform(s, vec, in_width, in_height, rmap.u, rmap.v, &du, &dv); | |
| 2198 | + av_assert1(!isnan(du) && !isnan(dv)); | |
| 2199 | + s->calculate_kernel(du, dv, &rmap, u, v, ker); | |
| 2200 | + } | |
| 2201 | + } | |
| 2202 | + } | |
| 2203 | +} | |
| 2204 | + | |
| 2170 | 2205 | static int config_output(AVFilterLink *outlink) |
| 2171 | 2206 | { |
| 2172 | 2207 | AVFilterContext *ctx = outlink->src; |
| @@ -2176,20 +2211,11 @@ static int config_output(AVFilterLink *outlink) · 3 unmodified lines | ||
| 2176 | 2211 | const int depth = desc->comp[0].depth; |
| 2177 | 2212 | int sizeof_uv; |
| 2178 | 2213 | int sizeof_ker; |
| 2179 | − int elements; | |
| 2180 | 2214 | int err; |
| 2181 | 2215 | int h, w; |
| 2182 | 2216 | int in_offset_h, in_offset_w; |
| 2183 | 2217 | int out_offset_h, out_offset_w; |
| 2184 | 2218 | float hf, wf; |
| 2185 | − void (*in_transform)(const V360Context *s, | |
| 2186 | − const float *vec, int width, int height, | |
| 2187 | − uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv); | |
| 2188 | − void (*out_transform)(const V360Context *s, | |
| 2189 | − int i, int j, int width, int height, | |
| 2190 | − float *vec); | |
| 2191 | − void (*calculate_kernel)(float du, float dv, const XYRemap *rmap, | |
| 2192 | − uint16_t *u, uint16_t *v, int16_t *ker); | |
| 2193 | 2219 | int (*prepare_out)(AVFilterContext *ctx); |
| 2194 | 2220 | |
| 2195 | 2221 | s->input_mirror_modifier[0] = s->ih_flip ? -1.f : 1.f; |
| @@ -2197,32 +2223,32 @@ static int config_output(AVFilterLink *outlink) · 1 unmodified line | ||
| 2197 | 2223 | |
| 2198 | 2224 | switch (s->interp) { |
| 2199 | 2225 | case NEAREST: |
| 2200 | − calculate_kernel = nearest_kernel; | |
| 2226 | + s->calculate_kernel = nearest_kernel; | |
| 2201 | 2227 | s->remap_slice = depth <= 8 ? remap1_8bit_slice : remap1_16bit_slice; |
| 2202 | − elements = 1; | |
| 2203 | − sizeof_uv = sizeof(uint16_t) * elements; | |
| 2228 | + s->elements = 1; | |
| 2229 | + sizeof_uv = sizeof(uint16_t) * s->elements; | |
| 2204 | 2230 | sizeof_ker = 0; |
| 2205 | 2231 | break; |
| 2206 | 2232 | case BILINEAR: |
| 2207 | − calculate_kernel = bilinear_kernel; | |
| 2233 | + s->calculate_kernel = bilinear_kernel; | |
| 2208 | 2234 | s->remap_slice = depth <= 8 ? remap2_8bit_slice : remap2_16bit_slice; |
| 2209 | − elements = 2 * 2; | |
| 2210 | − sizeof_uv = sizeof(uint16_t) * elements; | |
| 2211 | − sizeof_ker = sizeof(uint16_t) * elements; | |
| 2235 | + s->elements = 2 * 2; | |
| 2236 | + sizeof_uv = sizeof(uint16_t) * s->elements; | |
| 2237 | + sizeof_ker = sizeof(uint16_t) * s->elements; | |
| 2212 | 2238 | break; |
| 2213 | 2239 | case BICUBIC: |
| 2214 | − calculate_kernel = bicubic_kernel; | |
| 2240 | + s->calculate_kernel = bicubic_kernel; | |
| 2215 | 2241 | s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice; |
| 2216 | − elements = 4 * 4; | |
| 2217 | − sizeof_uv = sizeof(uint16_t) * elements; | |
| 2218 | − sizeof_ker = sizeof(uint16_t) * elements; | |
| 2242 | + s->elements = 4 * 4; | |
| 2243 | + sizeof_uv = sizeof(uint16_t) * s->elements; | |
| 2244 | + sizeof_ker = sizeof(uint16_t) * s->elements; | |
| 2219 | 2245 | break; |
| 2220 | 2246 | case LANCZOS: |
| 2221 | − calculate_kernel = lanczos_kernel; | |
| 2247 | + s->calculate_kernel = lanczos_kernel; | |
| 2222 | 2248 | s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice; |
| 2223 | − elements = 4 * 4; | |
| 2224 | − sizeof_uv = sizeof(uint16_t) * elements; | |
| 2225 | − sizeof_ker = sizeof(uint16_t) * elements; | |
| 2249 | + s->elements = 4 * 4; | |
| 2250 | + sizeof_uv = sizeof(uint16_t) * s->elements; | |
| 2251 | + sizeof_ker = sizeof(uint16_t) * s->elements; | |
| 2226 | 2252 | break; |
| 2227 | 2253 | default: |
| 2228 | 2254 | av_assert0(0); |
| @@ -2277,31 +2303,31 @@ static int config_output(AVFilterLink *outlink) · 48 unmodified lines | ||
| 2277 | 2303 | |
| 2278 | 2304 | switch (s->in) { |
| 2279 | 2305 | case EQUIRECTANGULAR: |
| 2280 | − in_transform = xyz_to_equirect; | |
| 2306 | + s->in_transform = xyz_to_equirect; | |
| 2281 | 2307 | err = 0; |
| 2282 | 2308 | wf = w; |
| 2283 | 2309 | hf = h; |
| 2284 | 2310 | break; |
| 2285 | 2311 | case CUBEMAP_3_2: |
| 2286 | − in_transform = xyz_to_cube3x2; | |
| 2312 | + s->in_transform = xyz_to_cube3x2; | |
| 2287 | 2313 | err = prepare_cube_in(ctx); |
| 2288 | 2314 | wf = w / 3.f * 4.f; |
| 2289 | 2315 | hf = h; |
| 2290 | 2316 | break; |
| 2291 | 2317 | case CUBEMAP_1_6: |
| 2292 | − in_transform = xyz_to_cube1x6; | |
| 2318 | + s->in_transform = xyz_to_cube1x6; | |
| 2293 | 2319 | err = prepare_cube_in(ctx); |
| 2294 | 2320 | wf = w * 4.f; |
| 2295 | 2321 | hf = h / 3.f; |
| 2296 | 2322 | break; |
| 2297 | 2323 | case CUBEMAP_6_1: |
| 2298 | − in_transform = xyz_to_cube6x1; | |
| 2324 | + s->in_transform = xyz_to_cube6x1; | |
| 2299 | 2325 | err = prepare_cube_in(ctx); |
| 2300 | 2326 | wf = w / 3.f * 2.f; |
| 2301 | 2327 | hf = h * 2.f; |
| 2302 | 2328 | break; |
| 2303 | 2329 | case EQUIANGULAR: |
| 2304 | − in_transform = xyz_to_eac; | |
| 2330 | + s->in_transform = xyz_to_eac; | |
| 2305 | 2331 | err = prepare_eac_in(ctx); |
| 2306 | 2332 | wf = w; |
| 2307 | 2333 | hf = h / 9.f * 8.f; |
| @@ -2310,19 +2336,19 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines | ||
| 2310 | 2336 | av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n"); |
| 2311 | 2337 | return AVERROR(EINVAL); |
| 2312 | 2338 | case DUAL_FISHEYE: |
| 2313 | − in_transform = xyz_to_dfisheye; | |
| 2339 | + s->in_transform = xyz_to_dfisheye; | |
| 2314 | 2340 | err = 0; |
| 2315 | 2341 | wf = w; |
| 2316 | 2342 | hf = h; |
| 2317 | 2343 | break; |
| 2318 | 2344 | case BARREL: |
| 2319 | − in_transform = xyz_to_barrel; | |
| 2345 | + s->in_transform = xyz_to_barrel; | |
| 2320 | 2346 | err = 0; |
| 2321 | 2347 | wf = w / 5.f * 4.f; |
| 2322 | 2348 | hf = h; |
| 2323 | 2349 | break; |
| 2324 | 2350 | case STEREOGRAPHIC: |
| 2325 | − in_transform = xyz_to_stereographic; | |
| 2351 | + s->in_transform = xyz_to_stereographic; | |
| 2326 | 2352 | err = 0; |
| 2327 | 2353 | wf = w; |
| 2328 | 2354 | hf = h / 2.f; |
| @@ -2338,55 +2364,55 @@ static int config_output(AVFilterLink *outlink) · 9 unmodified lines | ||
| 2338 | 2364 | |
| 2339 | 2365 | switch (s->out) { |
| 2340 | 2366 | case EQUIRECTANGULAR: |
| 2341 | − out_transform = equirect_to_xyz; | |
| 2367 | + s->out_transform = equirect_to_xyz; | |
| 2342 | 2368 | prepare_out = NULL; |
| 2343 | 2369 | w = roundf(wf); |
| 2344 | 2370 | h = roundf(hf); |
| 2345 | 2371 | break; |
| 2346 | 2372 | case CUBEMAP_3_2: |
| 2347 | − out_transform = cube3x2_to_xyz; | |
| 2373 | + s->out_transform = cube3x2_to_xyz; | |
| 2348 | 2374 | prepare_out = prepare_cube_out; |
| 2349 | 2375 | w = roundf(wf / 4.f * 3.f); |
| 2350 | 2376 | h = roundf(hf); |
| 2351 | 2377 | break; |
| 2352 | 2378 | case CUBEMAP_1_6: |
| 2353 | − out_transform = cube1x6_to_xyz; | |
| 2379 | + s->out_transform = cube1x6_to_xyz; | |
| 2354 | 2380 | prepare_out = prepare_cube_out; |
| 2355 | 2381 | w = roundf(wf / 4.f); |
| 2356 | 2382 | h = roundf(hf * 3.f); |
| 2357 | 2383 | break; |
| 2358 | 2384 | case CUBEMAP_6_1: |
| 2359 | − out_transform = cube6x1_to_xyz; | |
| 2385 | + s->out_transform = cube6x1_to_xyz; | |
| 2360 | 2386 | prepare_out = prepare_cube_out; |
| 2361 | 2387 | w = roundf(wf / 2.f * 3.f); |
| 2362 | 2388 | h = roundf(hf / 2.f); |
| 2363 | 2389 | break; |
| 2364 | 2390 | case EQUIANGULAR: |
| 2365 | − out_transform = eac_to_xyz; | |
| 2391 | + s->out_transform = eac_to_xyz; | |
| 2366 | 2392 | prepare_out = prepare_eac_out; |
| 2367 | 2393 | w = roundf(wf); |
| 2368 | 2394 | h = roundf(hf / 8.f * 9.f); |
| 2369 | 2395 | break; |
| 2370 | 2396 | case FLAT: |
| 2371 | − out_transform = flat_to_xyz; | |
| 2397 | + s->out_transform = flat_to_xyz; | |
| 2372 | 2398 | prepare_out = prepare_flat_out; |
| 2373 | 2399 | w = roundf(wf); |
| 2374 | 2400 | h = roundf(hf); |
| 2375 | 2401 | break; |
| 2376 | 2402 | case DUAL_FISHEYE: |
| 2377 | − out_transform = dfisheye_to_xyz; | |
| 2403 | + s->out_transform = dfisheye_to_xyz; | |
| 2378 | 2404 | prepare_out = NULL; |
| 2379 | 2405 | w = roundf(wf); |
| 2380 | 2406 | h = roundf(hf); |
| 2381 | 2407 | break; |
| 2382 | 2408 | case BARREL: |
| 2383 | − out_transform = barrel_to_xyz; | |
| 2409 | + s->out_transform = barrel_to_xyz; | |
| 2384 | 2410 | prepare_out = NULL; |
| 2385 | 2411 | w = roundf(wf / 4.f * 5.f); |
| 2386 | 2412 | h = roundf(hf); |
| 2387 | 2413 | break; |
| 2388 | 2414 | case STEREOGRAPHIC: |
| 2389 | − out_transform = stereographic_to_xyz; | |
| 2415 | + s->out_transform = stereographic_to_xyz; | |
| 2390 | 2416 | prepare_out = prepare_stereographic_out; |
| 2391 | 2417 | w = roundf(wf); |
| 2392 | 2418 | h = roundf(hf * 2.f); |
| @@ -2467,41 +2493,7 @@ static int config_output(AVFilterLink *outlink) · 74 unmodified lines | ||
| 2467 | 2493 | calculate_rotation_matrix(s->yaw, s->pitch, s->roll, s->rot_mat, s->rotation_order); |
| 2468 | 2494 | set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, s->output_mirror_modifier); |
| 2469 | 2495 | |
| 2470 | − // Calculate remap data | |
| 2471 | − for (int p = 0; p < s->nb_allocated; p++) { | |
| 2472 | − const int width = s->pr_width[p]; | |
| 2473 | − const int uv_linesize = s->uv_linesize[p]; | |
| 2474 | − const int height = s->pr_height[p]; | |
| 2475 | − const int in_width = s->inplanewidth[p]; | |
| 2476 | − const int in_height = s->inplaneheight[p]; | |
| 2477 | − float du, dv; | |
| 2478 | − float vec[3]; | |
| 2479 | − XYRemap rmap; | |
| 2480 | − | |
| 2481 | − for (int j = 0; j < height; j++) { | |
| 2482 | − for (int i = 0; i < width; i++) { | |
| 2483 | − uint16_t *u = s->u[p] + (j * uv_linesize + i) * elements; | |
| 2484 | − uint16_t *v = s->v[p] + (j * uv_linesize + i) * elements; | |
| 2485 | − int16_t *ker = s->ker[p] + (j * uv_linesize + i) * elements; | |
| 2486 | − | |
| 2487 | − if (s->out_transpose) | |
| 2488 | − out_transform(s, j, i, height, width, vec); | |
| 2489 | − else | |
| 2490 | − out_transform(s, i, j, width, height, vec); | |
| 2491 | − av_assert1(!isnan(vec[0]) && !isnan(vec[1]) && !isnan(vec[2])); | |
| 2492 | − rotate(s->rot_mat, vec); | |
| 2493 | − av_assert1(!isnan(vec[0]) && !isnan(vec[1]) && !isnan(vec[2])); | |
| 2494 | − normalize_vector(vec); | |
| 2495 | − mirror(s->output_mirror_modifier, vec); | |
| 2496 | − if (s->in_transpose) | |
| 2497 | − in_transform(s, vec, in_height, in_width, rmap.v, rmap.u, &du, &dv); | |
| 2498 | − else | |
| 2499 | − in_transform(s, vec, in_width, in_height, rmap.u, rmap.v, &du, &dv); | |
| 2500 | − av_assert1(!isnan(du) && !isnan(dv)); | |
| 2501 | − calculate_kernel(du, dv, &rmap, u, v, ker); | |
| 2502 | − } | |
| 2503 | − } | |
| 2504 | − } | |
| 2496 | + v360_filter(ctx); | |
| 2505 | 2497 | |
| 2506 | 2498 | return 0; |
| 2507 | 2499 | } |