History

avfilter/vf_v360: refactor creation of remap data

Paul B Mahol committed 7 years ago

Commit 05ffaa21 parent a09213d2 files · +92 −82Browse files

Unified · Split

2 files
  1. libavfilter/v360.h +18 −0
  2. libavfilter/vf_v360.c +74 −82
libavfilter/v360.h+18−0
@@ -85,6 +85,12 @@ enum RotationOrder { · 84 unmodified lines
85 NB_RORDERS,85 NB_RORDERS,
86};86};
87 87
88typedef struct XYRemap {
89 uint16_t u[4][4];
90 uint16_t v[4][4];
91 float ker[4][4];
92} XYRemap;
93
88typedef struct V360Context {94typedef struct V360Context {
89 const AVClass *class;95 const AVClass *class;
90 int in, out;96 int in, out;
@@ -130,11 +136,23 @@ typedef struct V360Context { · 39 unmodified lines
130 int uv_linesize[4];136 int uv_linesize[4];
131 int nb_planes;137 int nb_planes;
132 int nb_allocated;138 int nb_allocated;
139 int elements;
133 140
134 uint16_t *u[4], *v[4];141 uint16_t *u[4], *v[4];
135 int16_t *ker[4];142 int16_t *ker[4];
136 unsigned map[4];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 int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);156 int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
139 157
140 void (*remap_line)(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,158 void (*remap_line)(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
libavfilter/vf_v360.c+74−82
@@ -207,12 +207,6 @@ static void remap1_##bits##bit_line_c(uint8_t *dst, int width, const uint8_t *sr · 206 unmodified lines
207DEFINE_REMAP1_LINE( 8, 1)207DEFINE_REMAP1_LINE( 8, 1)
208DEFINE_REMAP1_LINE(16, 2)208DEFINE_REMAP1_LINE(16, 2)
209 209
210typedef 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 * Generate remapping function with a given window size and pixel depth.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 outh[0] = outh[3] = h;2161 outh[0] = outh[3] = h;
2168}2162}
2169 2163
2164// Calculate remap data
2165static 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
2170static int config_output(AVFilterLink *outlink)2205static int config_output(AVFilterLink *outlink)
2171{2206{
2172 AVFilterContext *ctx = outlink->src;2207 AVFilterContext *ctx = outlink->src;
@@ -2176,20 +2211,11 @@ static int config_output(AVFilterLink *outlink) · 3 unmodified lines
2176 const int depth = desc->comp[0].depth;2211 const int depth = desc->comp[0].depth;
2177 int sizeof_uv;2212 int sizeof_uv;
2178 int sizeof_ker;2213 int sizeof_ker;
2179 int elements;
2180 int err;2214 int err;
2181 int h, w;2215 int h, w;
2182 int in_offset_h, in_offset_w;2216 int in_offset_h, in_offset_w;
2183 int out_offset_h, out_offset_w;2217 int out_offset_h, out_offset_w;
2184 float hf, wf;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 int (*prepare_out)(AVFilterContext *ctx);2219 int (*prepare_out)(AVFilterContext *ctx);
2194 2220
2195 s->input_mirror_modifier[0] = s->ih_flip ? -1.f : 1.f;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 switch (s->interp) {2224 switch (s->interp) {
2199 case NEAREST:2225 case NEAREST:
2200 calculate_kernel = nearest_kernel;2226 s->calculate_kernel = nearest_kernel;
2201 s->remap_slice = depth <= 8 ? remap1_8bit_slice : remap1_16bit_slice;2227 s->remap_slice = depth <= 8 ? remap1_8bit_slice : remap1_16bit_slice;
2202 elements = 1;2228 s->elements = 1;
2203 sizeof_uv = sizeof(uint16_t) * elements;2229 sizeof_uv = sizeof(uint16_t) * s->elements;
2204 sizeof_ker = 0;2230 sizeof_ker = 0;
2205 break;2231 break;
2206 case BILINEAR:2232 case BILINEAR:
2207 calculate_kernel = bilinear_kernel;2233 s->calculate_kernel = bilinear_kernel;
2208 s->remap_slice = depth <= 8 ? remap2_8bit_slice : remap2_16bit_slice;2234 s->remap_slice = depth <= 8 ? remap2_8bit_slice : remap2_16bit_slice;
2209 elements = 2 * 2;2235 s->elements = 2 * 2;
2210 sizeof_uv = sizeof(uint16_t) * elements;2236 sizeof_uv = sizeof(uint16_t) * s->elements;
2211 sizeof_ker = sizeof(uint16_t) * elements;2237 sizeof_ker = sizeof(uint16_t) * s->elements;
2212 break;2238 break;
2213 case BICUBIC:2239 case BICUBIC:
2214 calculate_kernel = bicubic_kernel;2240 s->calculate_kernel = bicubic_kernel;
2215 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;2241 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
2216 elements = 4 * 4;2242 s->elements = 4 * 4;
2217 sizeof_uv = sizeof(uint16_t) * elements;2243 sizeof_uv = sizeof(uint16_t) * s->elements;
2218 sizeof_ker = sizeof(uint16_t) * elements;2244 sizeof_ker = sizeof(uint16_t) * s->elements;
2219 break;2245 break;
2220 case LANCZOS:2246 case LANCZOS:
2221 calculate_kernel = lanczos_kernel;2247 s->calculate_kernel = lanczos_kernel;
2222 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;2248 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
2223 elements = 4 * 4;2249 s->elements = 4 * 4;
2224 sizeof_uv = sizeof(uint16_t) * elements;2250 sizeof_uv = sizeof(uint16_t) * s->elements;
2225 sizeof_ker = sizeof(uint16_t) * elements;2251 sizeof_ker = sizeof(uint16_t) * s->elements;
2226 break;2252 break;
2227 default:2253 default:
2228 av_assert0(0);2254 av_assert0(0);
@@ -2277,31 +2303,31 @@ static int config_output(AVFilterLink *outlink) · 48 unmodified lines
2277 2303
2278 switch (s->in) {2304 switch (s->in) {
2279 case EQUIRECTANGULAR:2305 case EQUIRECTANGULAR:
2280 in_transform = xyz_to_equirect;2306 s->in_transform = xyz_to_equirect;
2281 err = 0;2307 err = 0;
2282 wf = w;2308 wf = w;
2283 hf = h;2309 hf = h;
2284 break;2310 break;
2285 case CUBEMAP_3_2:2311 case CUBEMAP_3_2:
2286 in_transform = xyz_to_cube3x2;2312 s->in_transform = xyz_to_cube3x2;
2287 err = prepare_cube_in(ctx);2313 err = prepare_cube_in(ctx);
2288 wf = w / 3.f * 4.f;2314 wf = w / 3.f * 4.f;
2289 hf = h;2315 hf = h;
2290 break;2316 break;
2291 case CUBEMAP_1_6:2317 case CUBEMAP_1_6:
2292 in_transform = xyz_to_cube1x6;2318 s->in_transform = xyz_to_cube1x6;
2293 err = prepare_cube_in(ctx);2319 err = prepare_cube_in(ctx);
2294 wf = w * 4.f;2320 wf = w * 4.f;
2295 hf = h / 3.f;2321 hf = h / 3.f;
2296 break;2322 break;
2297 case CUBEMAP_6_1:2323 case CUBEMAP_6_1:
2298 in_transform = xyz_to_cube6x1;2324 s->in_transform = xyz_to_cube6x1;
2299 err = prepare_cube_in(ctx);2325 err = prepare_cube_in(ctx);
2300 wf = w / 3.f * 2.f;2326 wf = w / 3.f * 2.f;
2301 hf = h * 2.f;2327 hf = h * 2.f;
2302 break;2328 break;
2303 case EQUIANGULAR:2329 case EQUIANGULAR:
2304 in_transform = xyz_to_eac;2330 s->in_transform = xyz_to_eac;
2305 err = prepare_eac_in(ctx);2331 err = prepare_eac_in(ctx);
2306 wf = w;2332 wf = w;
2307 hf = h / 9.f * 8.f;2333 hf = h / 9.f * 8.f;
@@ -2310,19 +2336,19 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
2310 av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n");2336 av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n");
2311 return AVERROR(EINVAL);2337 return AVERROR(EINVAL);
2312 case DUAL_FISHEYE:2338 case DUAL_FISHEYE:
2313 in_transform = xyz_to_dfisheye;2339 s->in_transform = xyz_to_dfisheye;
2314 err = 0;2340 err = 0;
2315 wf = w;2341 wf = w;
2316 hf = h;2342 hf = h;
2317 break;2343 break;
2318 case BARREL:2344 case BARREL:
2319 in_transform = xyz_to_barrel;2345 s->in_transform = xyz_to_barrel;
2320 err = 0;2346 err = 0;
2321 wf = w / 5.f * 4.f;2347 wf = w / 5.f * 4.f;
2322 hf = h;2348 hf = h;
2323 break;2349 break;
2324 case STEREOGRAPHIC:2350 case STEREOGRAPHIC:
2325 in_transform = xyz_to_stereographic;2351 s->in_transform = xyz_to_stereographic;
2326 err = 0;2352 err = 0;
2327 wf = w;2353 wf = w;
2328 hf = h / 2.f;2354 hf = h / 2.f;
@@ -2338,55 +2364,55 @@ static int config_output(AVFilterLink *outlink) · 9 unmodified lines
2338 2364
2339 switch (s->out) {2365 switch (s->out) {
2340 case EQUIRECTANGULAR:2366 case EQUIRECTANGULAR:
2341 out_transform = equirect_to_xyz;2367 s->out_transform = equirect_to_xyz;
2342 prepare_out = NULL;2368 prepare_out = NULL;
2343 w = roundf(wf);2369 w = roundf(wf);
2344 h = roundf(hf);2370 h = roundf(hf);
2345 break;2371 break;
2346 case CUBEMAP_3_2:2372 case CUBEMAP_3_2:
2347 out_transform = cube3x2_to_xyz;2373 s->out_transform = cube3x2_to_xyz;
2348 prepare_out = prepare_cube_out;2374 prepare_out = prepare_cube_out;
2349 w = roundf(wf / 4.f * 3.f);2375 w = roundf(wf / 4.f * 3.f);
2350 h = roundf(hf);2376 h = roundf(hf);
2351 break;2377 break;
2352 case CUBEMAP_1_6:2378 case CUBEMAP_1_6:
2353 out_transform = cube1x6_to_xyz;2379 s->out_transform = cube1x6_to_xyz;
2354 prepare_out = prepare_cube_out;2380 prepare_out = prepare_cube_out;
2355 w = roundf(wf / 4.f);2381 w = roundf(wf / 4.f);
2356 h = roundf(hf * 3.f);2382 h = roundf(hf * 3.f);
2357 break;2383 break;
2358 case CUBEMAP_6_1:2384 case CUBEMAP_6_1:
2359 out_transform = cube6x1_to_xyz;2385 s->out_transform = cube6x1_to_xyz;
2360 prepare_out = prepare_cube_out;2386 prepare_out = prepare_cube_out;
2361 w = roundf(wf / 2.f * 3.f);2387 w = roundf(wf / 2.f * 3.f);
2362 h = roundf(hf / 2.f);2388 h = roundf(hf / 2.f);
2363 break;2389 break;
2364 case EQUIANGULAR:2390 case EQUIANGULAR:
2365 out_transform = eac_to_xyz;2391 s->out_transform = eac_to_xyz;
2366 prepare_out = prepare_eac_out;2392 prepare_out = prepare_eac_out;
2367 w = roundf(wf);2393 w = roundf(wf);
2368 h = roundf(hf / 8.f * 9.f);2394 h = roundf(hf / 8.f * 9.f);
2369 break;2395 break;
2370 case FLAT:2396 case FLAT:
2371 out_transform = flat_to_xyz;2397 s->out_transform = flat_to_xyz;
2372 prepare_out = prepare_flat_out;2398 prepare_out = prepare_flat_out;
2373 w = roundf(wf);2399 w = roundf(wf);
2374 h = roundf(hf);2400 h = roundf(hf);
2375 break;2401 break;
2376 case DUAL_FISHEYE:2402 case DUAL_FISHEYE:
2377 out_transform = dfisheye_to_xyz;2403 s->out_transform = dfisheye_to_xyz;
2378 prepare_out = NULL;2404 prepare_out = NULL;
2379 w = roundf(wf);2405 w = roundf(wf);
2380 h = roundf(hf);2406 h = roundf(hf);
2381 break;2407 break;
2382 case BARREL:2408 case BARREL:
2383 out_transform = barrel_to_xyz;2409 s->out_transform = barrel_to_xyz;
2384 prepare_out = NULL;2410 prepare_out = NULL;
2385 w = roundf(wf / 4.f * 5.f);2411 w = roundf(wf / 4.f * 5.f);
2386 h = roundf(hf);2412 h = roundf(hf);
2387 break;2413 break;
2388 case STEREOGRAPHIC:2414 case STEREOGRAPHIC:
2389 out_transform = stereographic_to_xyz;2415 s->out_transform = stereographic_to_xyz;
2390 prepare_out = prepare_stereographic_out;2416 prepare_out = prepare_stereographic_out;
2391 w = roundf(wf);2417 w = roundf(wf);
2392 h = roundf(hf * 2.f);2418 h = roundf(hf * 2.f);
@@ -2467,41 +2493,7 @@ static int config_output(AVFilterLink *outlink) · 74 unmodified lines
2467 calculate_rotation_matrix(s->yaw, s->pitch, s->roll, s->rot_mat, s->rotation_order);2493 calculate_rotation_matrix(s->yaw, s->pitch, s->roll, s->rot_mat, s->rotation_order);
2468 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, s->output_mirror_modifier);2494 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, s->output_mirror_modifier);
2469 2495
2470 // Calculate remap data2496 v360_filter(ctx);
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 }
2505 2497
2506 return 0;2498 return 0;
2507}2499}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t