53 #define OFFSET(x) offsetof(V360Context, x)
54 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
55 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
254 #define DEFINE_REMAP1_LINE(bits, div) \
255 static void remap1_##bits##bit_line_c(uint8_t *dst, int width, const uint8_t *const src, \
256 ptrdiff_t in_linesize, \
257 const int16_t *const u, const int16_t *const v, \
258 const int16_t *const ker) \
260 const uint##bits##_t *const s = (const uint##bits##_t *const)src; \
261 uint##bits##_t *d = (uint##bits##_t *)dst; \
263 in_linesize /= div; \
265 for (int x = 0; x < width; x++) \
266 d[x] = s[v[x] * in_linesize + u[x]]; \
278 #define DEFINE_REMAP(ws, bits) \
279 static int remap##ws##_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
281 ThreadData *td = arg; \
282 const V360Context *s = ctx->priv; \
283 const SliceXYRemap *r = &s->slice_remap[jobnr]; \
284 const AVFrame *in = td->in; \
285 AVFrame *out = td->out; \
288 for (int stereo = 0; stereo < 1 + (s->out_stereo > STEREO_2D); stereo++) { \
289 for (int plane = 0; plane < s->nb_planes; plane++) { \
290 const unsigned map = s->map[plane]; \
291 const int in_linesize = in->linesize[plane]; \
292 const int out_linesize = out->linesize[plane]; \
293 const int uv_linesize = s->uv_linesize[plane]; \
294 const int in_offset_w = stereo ? s->in_offset_w[plane] : 0; \
295 const int in_offset_h = stereo ? s->in_offset_h[plane] : 0; \
296 const int out_offset_w = stereo ? s->out_offset_w[plane] : 0; \
297 const int out_offset_h = stereo ? s->out_offset_h[plane] : 0; \
298 const uint8_t *const src = in->data[plane] + \
299 in_offset_h * in_linesize + in_offset_w * (bits >> 3); \
300 uint8_t *dst = out->data[plane] + out_offset_h * out_linesize + out_offset_w * (bits >> 3); \
301 const uint8_t *mask = plane == 3 ? r->mask : NULL; \
302 const int width = s->pr_width[plane]; \
303 const int height = s->pr_height[plane]; \
305 const int slice_start = (height * jobnr ) / nb_jobs; \
306 const int slice_end = (height * (jobnr + 1)) / nb_jobs; \
308 for (int y = slice_start; y < slice_end && !mask; y++) { \
309 const int16_t *const u = r->u[map] + (y - slice_start) * uv_linesize * ws * ws; \
310 const int16_t *const v = r->v[map] + (y - slice_start) * uv_linesize * ws * ws; \
311 const int16_t *const ker = r->ker[map] + (y - slice_start) * uv_linesize * ws * ws; \
313 s->remap_line(dst + y * out_linesize, width, src, in_linesize, u, v, ker); \
316 for (int y = slice_start; y < slice_end && mask; y++) { \
317 memcpy(dst + y * out_linesize, mask + \
318 (y - slice_start) * width * (bits >> 3), width * (bits >> 3)); \
335 #define DEFINE_REMAP_LINE(ws, bits, div) \
336 static void remap##ws##_##bits##bit_line_c(uint8_t *dst, int width, const uint8_t *const src, \
337 ptrdiff_t in_linesize, \
338 const int16_t *const u, const int16_t *const v, \
339 const int16_t *const ker) \
341 const uint##bits##_t *const s = (const uint##bits##_t *const)src; \
342 uint##bits##_t *d = (uint##bits##_t *)dst; \
344 in_linesize /= div; \
346 for (int x = 0; x < width; x++) { \
347 const int16_t *const uu = u + x * ws * ws; \
348 const int16_t *const vv = v + x * ws * ws; \
349 const int16_t *const kker = ker + x * ws * ws; \
352 for (int i = 0; i < ws; i++) { \
353 const int iws = i * ws; \
354 for (int j = 0; j < ws; j++) { \
355 tmp += kker[iws + j] * s[vv[iws + j] * in_linesize + uu[iws + j]]; \
359 d[x] = av_clip_uint##bits(tmp >> 14); \
374 s->remap_line = depth <= 8 ? remap1_8bit_line_c : remap1_16bit_line_c;
377 s->remap_line = depth <= 8 ? remap2_8bit_line_c : remap2_16bit_line_c;
380 s->remap_line = depth <= 8 ? remap3_8bit_line_c : remap3_16bit_line_c;
387 s->remap_line = depth <= 8 ? remap4_8bit_line_c : remap4_16bit_line_c;
406 int16_t *
u, int16_t *v, int16_t *ker)
409 const int j =
lrintf(du) + 1;
411 u[0] = rmap->
u[
i][j];
412 v[0] = rmap->
v[
i][j];
426 int16_t *
u, int16_t *v, int16_t *ker)
428 for (
int i = 0;
i < 2;
i++) {
429 for (
int j = 0; j < 2; j++) {
430 u[
i * 2 + j] = rmap->
u[
i + 1][j + 1];
431 v[
i * 2 + j] = rmap->
v[
i + 1][j + 1];
435 ker[0] =
lrintf((1.f - du) * (1.f - dv) * 16385.f);
436 ker[1] =
lrintf( du * (1.f - dv) * 16385.f);
437 ker[2] =
lrintf((1.f - du) * dv * 16385.f);
438 ker[3] =
lrintf( du * dv * 16385.f);
449 coeffs[0] = (t - 1.f) * (t - 2.f) * 0.5f;
450 coeffs[1] = -t * (t - 2.f);
451 coeffs[2] = t * (t - 1.f) * 0.5f;
465 int16_t *
u, int16_t *v, int16_t *ker)
473 for (
int i = 0;
i < 3;
i++) {
474 for (
int j = 0; j < 3; j++) {
475 u[
i * 3 + j] = rmap->
u[
i + 1][j + 1];
476 v[
i * 3 + j] = rmap->
v[
i + 1][j + 1];
477 ker[
i * 3 + j] =
lrintf(du_coeffs[j] * dv_coeffs[
i] * 16385.f);
490 const float tt = t * t;
491 const float ttt = t * t * t;
493 coeffs[0] = - t / 3.f + tt / 2.f - ttt / 6.f;
494 coeffs[1] = 1.f - t / 2.f - tt + ttt / 2.f;
495 coeffs[2] = t + tt / 2.f - ttt / 2.f;
496 coeffs[3] = - t / 6.f + ttt / 6.f;
510 int16_t *
u, int16_t *v, int16_t *ker)
518 for (
int i = 0;
i < 4;
i++) {
519 for (
int j = 0; j < 4; j++) {
520 u[
i * 4 + j] = rmap->
u[
i][j];
521 v[
i * 4 + j] = rmap->
v[
i][j];
522 ker[
i * 4 + j] =
lrintf(du_coeffs[j] * dv_coeffs[
i] * 16385.f);
537 for (
int i = 0;
i < 4;
i++) {
538 const float x =
M_PI * (t -
i + 1);
542 coeffs[
i] =
sinf(x) *
sinf(x / 2.f) / (x * x / 2.f);
547 for (
int i = 0;
i < 4;
i++) {
563 int16_t *
u, int16_t *v, int16_t *ker)
571 for (
int i = 0;
i < 4;
i++) {
572 for (
int j = 0; j < 4; j++) {
573 u[
i * 4 + j] = rmap->
u[
i][j];
574 v[
i * 4 + j] = rmap->
v[
i][j];
575 ker[
i * 4 + j] =
lrintf(du_coeffs[j] * dv_coeffs[
i] * 16385.f);
588 coeffs[0] = ((-1.f / 3.f * t + 0.8f) * t - 7.f / 15.f) * t;
589 coeffs[1] = ((t - 9.f / 5.f) * t - 0.2f) * t + 1.f;
590 coeffs[2] = ((6.f / 5.f - t) * t + 0.8f) * t;
591 coeffs[3] = ((1.f / 3.f * t - 0.2f) * t - 2.f / 15.f) * t;
605 int16_t *
u, int16_t *v, int16_t *ker)
613 for (
int i = 0;
i < 4;
i++) {
614 for (
int j = 0; j < 4; j++) {
615 u[
i * 4 + j] = rmap->
u[
i][j];
616 v[
i * 4 + j] = rmap->
v[
i][j];
617 ker[
i * 4 + j] =
lrintf(du_coeffs[j] * dv_coeffs[
i] * 16385.f);
632 for (
int i = 0;
i < 4;
i++) {
633 const float x = t - (
i - 1);
637 coeffs[
i] =
expf(-2.f * x * x) *
expf(-x * x / 2.f);
642 for (
int i = 0;
i < 4;
i++) {
658 int16_t *
u, int16_t *v, int16_t *ker)
666 for (
int i = 0;
i < 4;
i++) {
667 for (
int j = 0; j < 4; j++) {
668 u[
i * 4 + j] = rmap->
u[
i][j];
669 v[
i * 4 + j] = rmap->
v[
i][j];
670 ker[
i * 4 + j] =
lrintf(du_coeffs[j] * dv_coeffs[
i] * 16385.f);
685 float p0 = (6.f - 2.f *
b) / 6.f,
686 p2 = (-18.f + 12.f *
b + 6.f *
c) / 6.f,
687 p3 = (12.f - 9.f *
b - 6.f *
c) / 6.f,
688 q0 = (8.f *
b + 24.f *
c) / 6.f,
689 q1 = (-12.f *
b - 48.f *
c) / 6.f,
690 q2 = (6.f *
b + 30.f *
c) / 6.f,
691 q3 = (-
b - 6.f *
c) / 6.f;
693 for (
int i = 0;
i < 4;
i++) {
694 const float x =
fabsf(t -
i + 1.f);
696 coeffs[
i] = (p0 + x * x * (p2 + x * p3)) *
697 (p0 + x * x * (p2 + x * p3 / 2.f) / 4.f);
698 }
else if (x < 2.f) {
699 coeffs[
i] = (
q0 + x * (
q1 + x * (q2 + x * q3))) *
700 (
q0 + x * (
q1 + x * (q2 + x / 2.f * q3) / 2.f) / 2.f);
707 for (
int i = 0;
i < 4;
i++) {
723 int16_t *
u, int16_t *v, int16_t *ker)
731 for (
int i = 0;
i < 4;
i++) {
732 for (
int j = 0; j < 4; j++) {
733 u[
i * 4 + j] = rmap->
u[
i][j];
734 v[
i * 4 + j] = rmap->
v[
i][j];
735 ker[
i * 4 + j] =
lrintf(du_coeffs[j] * dv_coeffs[
i] * 16385.f);
750 const int res =
a %
b;
882 for (
int face = 0; face <
NB_FACES; face++) {
883 const char c =
s->in_forder[face];
888 "Incomplete in_forder option. Direction for all 6 faces should be specified.\n");
893 if (direction == -1) {
895 "Incorrect direction symbol '%c' in in_forder option.\n",
c);
899 s->in_cubemap_face_order[direction] = face;
902 for (
int face = 0; face <
NB_FACES; face++) {
903 const char c =
s->in_frot[face];
908 "Incomplete in_frot option. Rotation for all 6 faces should be specified.\n");
913 if (rotation == -1) {
915 "Incorrect rotation symbol '%c' in in_frot option.\n",
c);
919 s->in_cubemap_face_rotation[face] = rotation;
936 for (
int face = 0; face <
NB_FACES; face++) {
937 const char c =
s->out_forder[face];
942 "Incomplete out_forder option. Direction for all 6 faces should be specified.\n");
947 if (direction == -1) {
949 "Incorrect direction symbol '%c' in out_forder option.\n",
c);
953 s->out_cubemap_direction_order[face] = direction;
956 for (
int face = 0; face <
NB_FACES; face++) {
957 const char c =
s->out_frot[face];
962 "Incomplete out_frot option. Rotation for all 6 faces should be specified.\n");
967 if (rotation == -1) {
969 "Incorrect rotation symbol '%c' in out_frot option.\n",
c);
973 s->out_cubemap_face_rotation[face] = rotation;
1038 const float norm = sqrtf(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
1058 float uf,
float vf,
int face,
1059 float *vec,
float scalew,
float scaleh)
1061 const int direction =
s->out_cubemap_direction_order[face];
1062 float l_x, l_y, l_z;
1069 switch (direction) {
1123 float *uf,
float *vf,
int *direction)
1125 const float phi =
atan2f(vec[0], vec[2]);
1126 const float theta = asinf(vec[1]);
1127 float phi_norm, theta_threshold;
1130 if (phi >= -M_PI_4 && phi < M_PI_4) {
1133 }
else if (phi >= -(
M_PI_2 + M_PI_4) && phi < -M_PI_4) {
1136 }
else if (phi >= M_PI_4 && phi <
M_PI_2 + M_PI_4) {
1141 phi_norm = phi + ((phi > 0.f) ? -
M_PI :
M_PI);
1144 theta_threshold =
atanf(
cosf(phi_norm));
1145 if (theta > theta_threshold) {
1147 }
else if (theta < -theta_threshold) {
1151 switch (*direction) {
1153 *uf = -vec[2] / vec[0];
1154 *vf = vec[1] / vec[0];
1157 *uf = -vec[2] / vec[0];
1158 *vf = -vec[1] / vec[0];
1161 *uf = -vec[0] / vec[1];
1162 *vf = -vec[2] / vec[1];
1165 *uf = vec[0] / vec[1];
1166 *vf = -vec[2] / vec[1];
1169 *uf = vec[0] / vec[2];
1170 *vf = vec[1] / vec[2];
1173 *uf = vec[0] / vec[2];
1174 *vf = -vec[1] / vec[2];
1180 face =
s->in_cubemap_face_order[*direction];
1197 float uf,
float vf,
int direction,
1198 float *new_uf,
float *new_vf,
int *face)
1217 *face =
s->in_cubemap_face_order[direction];
1220 if ((uf < -1.f || uf >= 1.f) && (vf < -1.f || vf >= 1.f)) {
1224 }
else if (uf < -1.f) {
1226 switch (direction) {
1260 }
else if (uf >= 1.f) {
1262 switch (direction) {
1296 }
else if (vf < -1.f) {
1298 switch (direction) {
1332 }
else if (vf >= 1.f) {
1334 switch (direction) {
1374 *face =
s->in_cubemap_face_order[direction];
1392 const float scalew =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
width / 3.f) : 1.f -
s->out_pad;
1393 const float scaleh =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
height / 2.f) : 1.f -
s->out_pad;
1395 const float ew =
width / 3.f;
1396 const float eh =
height / 2.f;
1398 const int u_face =
floorf(
i / ew);
1399 const int v_face =
floorf(j / eh);
1400 const int face = u_face + 3 * v_face;
1402 const int u_shift =
ceilf(ew * u_face);
1403 const int v_shift =
ceilf(eh * v_face);
1404 const int ewi =
ceilf(ew * (u_face + 1)) - u_shift;
1405 const int ehi =
ceilf(eh * (v_face + 1)) - v_shift;
1407 const float uf = 2.f * (
i - u_shift + 0.5f) / ewi - 1.f;
1408 const float vf = 2.f * (j - v_shift + 0.5f) / ehi - 1.f;
1429 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
1431 const float scalew =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
width / 3.f) : 1.f -
s->in_pad;
1432 const float scaleh =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
height / 2.f) : 1.f -
s->in_pad;
1433 const float ew =
width / 3.f;
1434 const float eh =
height / 2.f;
1438 int direction, face;
1446 face =
s->in_cubemap_face_order[direction];
1449 ewi =
ceilf(ew * (u_face + 1)) -
ceilf(ew * u_face);
1450 ehi =
ceilf(eh * (v_face + 1)) -
ceilf(eh * v_face);
1452 uf = 0.5f * ewi * (uf + 1.f) - 0.5f;
1453 vf = 0.5f * ehi * (vf + 1.f) - 0.5f;
1461 for (
int i = 0;
i < 4;
i++) {
1462 for (
int j = 0; j < 4; j++) {
1463 int new_ui =
ui + j - 1;
1464 int new_vi = vi +
i - 1;
1465 int u_shift, v_shift;
1466 int new_ewi, new_ehi;
1468 if (new_ui >= 0 && new_ui < ewi && new_vi >= 0 && new_vi < ehi) {
1469 face =
s->in_cubemap_face_order[direction];
1473 u_shift =
ceilf(ew * u_face);
1474 v_shift =
ceilf(eh * v_face);
1476 uf = 2.f * new_ui / ewi - 1.f;
1477 vf = 2.f * new_vi / ehi - 1.f;
1489 u_shift =
ceilf(ew * u_face);
1490 v_shift =
ceilf(eh * v_face);
1491 new_ewi =
ceilf(ew * (u_face + 1)) - u_shift;
1492 new_ehi =
ceilf(eh * (v_face + 1)) - v_shift;
1494 new_ui =
av_clip(
lrintf(0.5f * new_ewi * (uf + 1.f)), 0, new_ewi - 1);
1495 new_vi =
av_clip(
lrintf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);
1498 us[
i][j] = u_shift + new_ui;
1499 vs[
i][j] = v_shift + new_vi;
1520 const float scalew =
s->fout_pad > 0 ? 1.f - (float)(
s->fout_pad) /
width : 1.f -
s->out_pad;
1521 const float scaleh =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
height / 6.f) : 1.f -
s->out_pad;
1523 const float ew =
width;
1524 const float eh =
height / 6.f;
1526 const int face =
floorf(j / eh);
1528 const int v_shift =
ceilf(eh * face);
1529 const int ehi =
ceilf(eh * (face + 1)) - v_shift;
1531 const float uf = 2.f * (
i + 0.5f) / ew - 1.f;
1532 const float vf = 2.f * (j - v_shift + 0.5f) / ehi - 1.f;
1553 const float scalew =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
width / 6.f) : 1.f -
s->out_pad;
1554 const float scaleh =
s->fout_pad > 0 ? 1.f - (
float)(
s->fout_pad) /
height : 1.f -
s->out_pad;
1556 const float ew =
width / 6.f;
1559 const int face =
floorf(
i / ew);
1561 const int u_shift =
ceilf(ew * face);
1562 const int ewi =
ceilf(ew * (face + 1)) - u_shift;
1564 const float uf = 2.f * (
i - u_shift + 0.5f) / ewi - 1.f;
1565 const float vf = 2.f * (j + 0.5f) / eh - 1.f;
1586 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
1588 const float scalew =
s->fin_pad > 0 ? 1.f - (float)(
s->fin_pad) /
width : 1.f -
s->in_pad;
1589 const float scaleh =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
height / 6.f) : 1.f -
s->in_pad;
1590 const float eh =
height / 6.f;
1591 const int ewi =
width;
1595 int direction, face;
1602 face =
s->in_cubemap_face_order[direction];
1603 ehi =
ceilf(eh * (face + 1)) -
ceilf(eh * face);
1605 uf = 0.5f * ewi * (uf + 1.f) - 0.5f;
1606 vf = 0.5f * ehi * (vf + 1.f) - 0.5f;
1614 for (
int i = 0;
i < 4;
i++) {
1615 for (
int j = 0; j < 4; j++) {
1616 int new_ui =
ui + j - 1;
1617 int new_vi = vi +
i - 1;
1621 if (new_ui >= 0 && new_ui < ewi && new_vi >= 0 && new_vi < ehi) {
1622 face =
s->in_cubemap_face_order[direction];
1624 v_shift =
ceilf(eh * face);
1626 uf = 2.f * new_ui / ewi - 1.f;
1627 vf = 2.f * new_vi / ehi - 1.f;
1637 v_shift =
ceilf(eh * face);
1638 new_ehi =
ceilf(eh * (face + 1)) - v_shift;
1640 new_ui =
av_clip(
lrintf(0.5f * ewi * (uf + 1.f)), 0, ewi - 1);
1641 new_vi =
av_clip(
lrintf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);
1645 vs[
i][j] = v_shift + new_vi;
1666 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
1668 const float scalew =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
width / 6.f) : 1.f -
s->in_pad;
1669 const float scaleh =
s->fin_pad > 0 ? 1.f - (
float)(
s->fin_pad) /
height : 1.f -
s->in_pad;
1670 const float ew =
width / 6.f;
1675 int direction, face;
1682 face =
s->in_cubemap_face_order[direction];
1683 ewi =
ceilf(ew * (face + 1)) -
ceilf(ew * face);
1685 uf = 0.5f * ewi * (uf + 1.f) - 0.5f;
1686 vf = 0.5f * ehi * (vf + 1.f) - 0.5f;
1694 for (
int i = 0;
i < 4;
i++) {
1695 for (
int j = 0; j < 4; j++) {
1696 int new_ui =
ui + j - 1;
1697 int new_vi = vi +
i - 1;
1701 if (new_ui >= 0 && new_ui < ewi && new_vi >= 0 && new_vi < ehi) {
1702 face =
s->in_cubemap_face_order[direction];
1704 u_shift =
ceilf(ew * face);
1706 uf = 2.f * new_ui / ewi - 1.f;
1707 vf = 2.f * new_vi / ehi - 1.f;
1717 u_shift =
ceilf(ew * face);
1718 new_ewi =
ceilf(ew * (face + 1)) - u_shift;
1720 new_ui =
av_clip(
lrintf(0.5f * new_ewi * (uf + 1.f)), 0, new_ewi - 1);
1721 new_vi =
av_clip(
lrintf(0.5f * ehi * (vf + 1.f)), 0, ehi - 1);
1724 us[
i][j] = u_shift + new_ui;
1746 const float phi = ((2.f *
i + 0.5f) /
width - 1.f) *
M_PI;
1747 const float theta = ((2.f * j + 0.5f) /
height - 1.f) *
M_PI_2;
1749 const float sin_phi =
sinf(phi);
1750 const float cos_phi =
cosf(phi);
1751 const float sin_theta =
sinf(theta);
1752 const float cos_theta =
cosf(theta);
1754 vec[0] = cos_theta * sin_phi;
1756 vec[2] = cos_theta * cos_phi;
1775 const float phi = ((2.f *
i + 0.5f) /
width - 1.f) *
M_PI_2;
1776 const float theta = ((2.f * j + 0.5f) /
height - 1.f) *
M_PI_2;
1778 const float sin_phi =
sinf(phi);
1779 const float cos_phi =
cosf(phi);
1780 const float sin_theta =
sinf(theta);
1781 const float cos_theta =
cosf(theta);
1783 vec[0] = cos_theta * sin_phi;
1785 vec[2] = cos_theta * cos_phi;
1801 s->flat_range[0] = tanf(
FFMIN(
s->h_fov, 359.f) *
M_PI / 720.f);
1802 s->flat_range[1] = tanf(
FFMIN(
s->v_fov, 359.f) *
M_PI / 720.f);
1821 const float x = ((2.f *
i + 1.f) /
width - 1.f) *
s->flat_range[0];
1822 const float y = ((2.f * j + 1.f) /
height - 1.f) *
s->flat_range[1];
1823 const float r = hypotf(x, y);
1824 const float theta =
atanf(
r) * 2.f;
1825 const float sin_theta =
sinf(theta);
1827 vec[0] = x /
r * sin_theta;
1828 vec[1] = y /
r * sin_theta;
1829 vec[2] =
cosf(theta);
1847 s->iflat_range[0] = tanf(
FFMIN(
s->ih_fov, 359.f) *
M_PI / 720.f);
1848 s->iflat_range[1] = tanf(
FFMIN(
s->iv_fov, 359.f) *
M_PI / 720.f);
1867 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
1869 const float theta = acosf(vec[2]);
1870 const float r = tanf(theta * 0.5f);
1871 const float c =
r / hypotf(vec[0], vec[1]);
1872 const float x = vec[0] *
c /
s->iflat_range[0];
1873 const float y = vec[1] *
c /
s->iflat_range[1];
1875 const float uf = (x + 1.f) *
width / 2.f;
1876 const float vf = (y + 1.f) *
height / 2.f;
1879 const int vi =
floorf(vf);
1883 *du = visible ? uf -
ui : 0.f;
1884 *dv = visible ? vf - vi : 0.f;
1886 for (
int i = 0;
i < 4;
i++) {
1887 for (
int j = 0; j < 4; j++) {
1907 s->flat_range[0] =
sinf(
s->h_fov *
M_PI / 720.f);
1908 s->flat_range[1] =
sinf(
s->v_fov *
M_PI / 720.f);
1927 const float x = ((2.f *
i + 1.f) /
width - 1.f) *
s->flat_range[0];
1928 const float y = ((2.f * j + 1.f) /
height - 1.f) *
s->flat_range[1];
1929 const float r = hypotf(x, y);
1930 const float theta = asinf(
r) * 2.f;
1931 const float sin_theta =
sinf(theta);
1933 vec[0] = x /
r * sin_theta;
1934 vec[1] = y /
r * sin_theta;
1935 vec[2] =
cosf(theta);
1973 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
1975 const float theta = acosf(vec[2]);
1976 const float r =
sinf(theta * 0.5f);
1977 const float c =
r / hypotf(vec[0], vec[1]);
1978 const float x = vec[0] *
c /
s->iflat_range[0];
1979 const float y = vec[1] *
c /
s->iflat_range[1];
1981 const float uf = (x + 1.f) *
width / 2.f;
1982 const float vf = (y + 1.f) *
height / 2.f;
1985 const int vi =
floorf(vf);
1989 *du = visible ? uf -
ui : 0.f;
1990 *dv = visible ? vf - vi : 0.f;
1992 for (
int i = 0;
i < 4;
i++) {
1993 for (
int j = 0; j < 4; j++) {
2033 const float x = ((2.f *
i + 1.f) /
width - 1.f) *
s->flat_range[0];
2034 const float y = ((2.f * j + 1.f) /
height - 1.f) *
s->flat_range[1];
2035 const float r = hypotf(x, y);
2036 const float theta = asinf(
r);
2040 vec[2] =
cosf(theta);
2078 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2080 const float theta = acosf(vec[2]);
2081 const float r =
sinf(theta);
2082 const float c =
r / hypotf(vec[0], vec[1]);
2083 const float x = vec[0] *
c /
s->iflat_range[0];
2084 const float y = vec[1] *
c /
s->iflat_range[1];
2086 const float uf = (x + 1.f) *
width / 2.f;
2087 const float vf = (y + 1.f) *
height / 2.f;
2090 const int vi =
floorf(vf);
2092 const int visible = vec[2] >= 0.f &&
isfinite(x) &&
isfinite(y) && vi >= 0 && vi < height && ui >= 0 &&
ui <
width;
2094 *du = visible ? uf -
ui : 0.f;
2095 *dv = visible ? vf - vi : 0.f;
2097 for (
int i = 0;
i < 4;
i++) {
2098 for (
int j = 0; j < 4; j++) {
2121 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2123 const float phi =
atan2f(vec[0], vec[2]);
2124 const float theta = asinf(vec[1]);
2126 const float uf = (phi /
M_PI + 1.f) *
width / 2.f;
2127 const float vf = (theta /
M_PI_2 + 1.f) *
height / 2.f;
2130 const int vi =
floorf(vf);
2135 for (
int i = 0;
i < 4;
i++) {
2136 for (
int j = 0; j < 4; j++) {
2159 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2161 const float phi =
atan2f(vec[0], vec[2]);
2162 const float theta = asinf(vec[1]);
2164 const float uf = (phi /
M_PI_2 + 1.f) *
width / 2.f;
2165 const float vf = (theta /
M_PI_2 + 1.f) *
height / 2.f;
2168 const int vi =
floorf(vf);
2175 for (
int i = 0;
i < 4;
i++) {
2176 for (
int j = 0; j < 4; j++) {
2196 s->iflat_range[0] = tanf(0.5f *
s->ih_fov *
M_PI / 180.f);
2197 s->iflat_range[1] = tanf(0.5f *
s->iv_fov *
M_PI / 180.f);
2216 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2218 const float theta = acosf(vec[2]);
2219 const float r = tanf(theta);
2221 const float zf = vec[2];
2222 const float h = hypotf(vec[0], vec[1]);
2223 const float c =
h <= 1e-6f ? 1.f : rr /
h;
2224 float uf = vec[0] *
c /
s->iflat_range[0];
2225 float vf = vec[1] *
c /
s->iflat_range[1];
2226 int visible,
ui, vi;
2228 uf = zf >= 0.f ? (uf + 1.f) *
width / 2.f : 0.f;
2229 vf = zf >= 0.f ? (vf + 1.f) *
height / 2.f : 0.f;
2234 visible = vi >= 0 && vi < height && ui >= 0 && ui < width && zf >= 0.f;
2239 for (
int i = 0;
i < 4;
i++) {
2240 for (
int j = 0; j < 4; j++) {
2263 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2265 const float phi =
atan2f(vec[0], vec[2]);
2266 const float theta = vec[1];
2268 const float uf = (phi /
M_PI + 1.f) *
width / 2.f;
2269 const float vf = (
av_clipf(logf((1.f + theta) / (1.f - theta)) / (2.f *
M_PI), -1.f, 1.f) + 1.f) *
height / 2.f;
2272 const int vi =
floorf(vf);
2277 for (
int i = 0;
i < 4;
i++) {
2278 for (
int j = 0; j < 4; j++) {
2302 const float y = ((2.f * j + 1.f) /
height - 1.f) *
M_PI;
2303 const float div =
expf(2.f * y) + 1.f;
2305 const float sin_phi =
sinf(phi);
2306 const float cos_phi =
cosf(phi);
2307 const float sin_theta = 2.f *
expf(y) / div;
2308 const float cos_theta = (
expf(2.f * y) - 1.f) / div;
2310 vec[0] = -sin_theta * cos_phi;
2312 vec[2] = sin_theta * sin_phi;
2331 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2333 const float l = hypotf(vec[0], vec[1]);
2334 const float r = sqrtf(1.f - vec[2]) /
M_SQRT2;
2336 const float uf = (1.f +
r * vec[0] / (l > 0.f ? l : 1.f)) *
width * 0.5f;
2337 const float vf = (1.f +
r * vec[1] / (l > 0.f ? l : 1.f)) *
height * 0.5f;
2340 const int vi =
floorf(vf);
2345 for (
int i = 0;
i < 4;
i++) {
2346 for (
int j = 0; j < 4; j++) {
2369 const float x = (2.f *
i + 1.f) /
width - 1.f;
2370 const float y = (2.f * j + 1.f) /
height - 1.f;
2371 const float l = hypotf(x, y);
2374 const float z = 2.f * l * sqrtf(1.f - l * l);
2376 vec[0] = z * x / (l > 0.f ? l : 1.f);
2377 vec[1] = z * y / (l > 0.f ? l : 1.f);
2378 vec[2] = 1.f - 2.f * l * l;
2403 const float x = ((2.f *
i + 1.f) /
width - 1.f);
2404 const float y = ((2.f * j + 1.f) /
height - 1.f);
2406 const float xx = x * x;
2407 const float yy = y * y;
2409 const float z = sqrtf(1.f - xx * 0.5f - yy * 0.5f);
2412 const float b = 2.f * z * z - 1.f;
2414 const float aa =
a *
a;
2415 const float bb =
b *
b;
2417 const float w = sqrtf(1.f - 2.f * yy * z * z);
2419 vec[0] =
w * 2.f *
a *
b / (aa + bb);
2421 vec[2] =
w * (bb - aa) / (aa + bb);
2442 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2444 const float theta =
atan2f(vec[0], vec[2]);
2446 const float z = sqrtf(1.f + sqrtf(1.f - vec[1] * vec[1]) *
cosf(theta * 0.5f));
2447 const float x = sqrtf(1.f - vec[1] * vec[1]) *
sinf(theta * 0.5f) / z;
2448 const float y = vec[1] / z;
2450 const float uf = (x + 1.f) *
width / 2.f;
2451 const float vf = (y + 1.f) *
height / 2.f;
2454 const int vi =
floorf(vf);
2459 for (
int i = 0;
i < 4;
i++) {
2460 for (
int j = 0; j < 4; j++) {
2483 const float theta = ((2.f * j + 1.f) /
height - 1.f) *
M_PI_2;
2484 const float phi = ((2.f *
i + 1.f) /
width - 1.f) *
M_PI /
cosf(theta);
2486 const float sin_phi =
sinf(phi);
2487 const float cos_phi =
cosf(phi);
2488 const float sin_theta =
sinf(theta);
2489 const float cos_theta =
cosf(theta);
2491 vec[0] = cos_theta * sin_phi;
2493 vec[2] = cos_theta * cos_phi;
2514 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2516 const float theta = asinf(vec[1]);
2517 const float phi =
atan2f(vec[0], vec[2]) *
cosf(theta);
2519 const float uf = (phi /
M_PI + 1.f) *
width / 2.f;
2520 const float vf = (theta /
M_PI_2 + 1.f) *
height / 2.f;
2523 const int vi =
floorf(vf);
2528 for (
int i = 0;
i < 4;
i++) {
2529 for (
int j = 0; j < 4; j++) {
2608 const float pixel_pad = 2;
2609 const float u_pad = pixel_pad /
width;
2610 const float v_pad = pixel_pad /
height;
2612 int u_face, v_face, face;
2614 float l_x, l_y, l_z;
2616 float uf = (
i + 0.5f) /
width;
2617 float vf = (j + 0.5f) /
height;
2624 uf = 3.f * (uf - u_pad) / (1.f - 2.f * u_pad);
2628 }
else if (uf >= 3.f) {
2633 uf = fmodf(uf, 1.f) - 0.5f;
2637 v_face =
floorf(vf * 2.f);
2638 vf = (vf - v_pad - 0.5f * v_face) / (0.5f - 2.f * v_pad) - 0.5f;
2640 if (uf >= -0.5f && uf < 0.5f) {
2645 if (vf >= -0.5f && vf < 0.5f) {
2651 face = u_face + 3 * v_face;
2711 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2713 const float pixel_pad = 2;
2714 const float u_pad = pixel_pad /
width;
2715 const float v_pad = pixel_pad /
height;
2719 int direction, face;
2724 face =
s->in_cubemap_face_order[direction];
2728 uf = M_2_PI *
atanf(uf) + 0.5f;
2729 vf = M_2_PI *
atanf(vf) + 0.5f;
2732 uf = (uf + u_face) * (1.f - 2.f * u_pad) / 3.f + u_pad;
2733 vf = vf * (0.5f - 2.f * v_pad) + v_pad + 0.5f * v_face;
2747 for (
int i = 0;
i < 4;
i++) {
2748 for (
int j = 0; j < 4; j++) {
2768 s->flat_range[0] = tanf(0.5f *
s->h_fov *
M_PI / 180.f);
2769 s->flat_range[1] = tanf(0.5f *
s->v_fov *
M_PI / 180.f);
2788 const float l_x =
s->flat_range[0] * ((2.f *
i + 0.5f) /
width - 1.f);
2789 const float l_y =
s->flat_range[1] * ((2.f * j + 0.5f) /
height - 1.f);
2811 s->flat_range[0] =
s->h_fov / 180.f;
2812 s->flat_range[1] =
s->v_fov / 180.f;
2831 const float uf =
s->flat_range[0] * ((2.f *
i) /
width - 1.f);
2832 const float vf =
s->flat_range[1] * ((2.f * j + 1.f) /
height - 1.f);
2834 const float phi =
atan2f(vf, uf);
2835 const float theta =
M_PI_2 * (1.f - hypotf(uf, vf));
2837 const float sin_phi =
sinf(phi);
2838 const float cos_phi =
cosf(phi);
2839 const float sin_theta =
sinf(theta);
2840 const float cos_theta =
cosf(theta);
2842 vec[0] = cos_theta * cos_phi;
2843 vec[1] = cos_theta * sin_phi;
2862 s->iflat_range[0] =
s->ih_fov / 180.f;
2863 s->iflat_range[1] =
s->iv_fov / 180.f;
2882 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2884 const float h = hypotf(vec[0], vec[1]);
2885 const float lh =
h > 0.f ?
h : 1.f;
2888 float uf = vec[0] / lh * phi /
s->iflat_range[0];
2889 float vf = vec[1] / lh * phi /
s->iflat_range[1];
2891 const int visible = hypotf(uf, vf) <= 0.5f;
2894 uf = (uf + 0.5f) *
width;
2895 vf = (vf + 0.5f) *
height;
2900 *du = visible ? uf -
ui : 0.f;
2901 *dv = visible ? vf - vi : 0.f;
2903 for (
int i = 0;
i < 4;
i++) {
2904 for (
int j = 0; j < 4; j++) {
2927 const float uf = ((2.f *
i + 1.f) /
width - 1.f);
2928 const float vf = ((2.f * j + 1.f) /
height - 1.f);
2930 const float d =
s->h_fov;
2931 const float k = uf * uf / ((d + 1.f) * (d + 1.f));
2932 const float dscr = k * k * d * d - (k + 1.f) * (k * d * d - 1.f);
2933 const float clon = (-k * d + sqrtf(dscr)) / (k + 1.f);
2934 const float S = (d + 1.f) / (d + clon);
2935 const float lon =
atan2f(uf,
S * clon);
2936 const float lat =
atan2f(vf,
S);
2961 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
2963 const float phi =
atan2f(vec[0], vec[2]);
2964 const float theta = asinf(vec[1]);
2966 const float d =
s->ih_fov;
2967 const float S = (d + 1.f) / (d +
cosf(phi));
2969 const float x =
S *
sinf(phi);
2970 const float y =
S * tanf(theta);
2972 const float uf = (x + 1.f) *
width / 2.f;
2973 const float vf = (y + 1.f) *
height / 2.f;
2976 const int vi =
floorf(vf);
2978 const int visible = vi >= 0 && vi < height && ui >= 0 && ui < width && vec[2] >= 0.f;
2983 for (
int i = 0;
i < 4;
i++) {
2984 for (
int j = 0; j < 4; j++) {
3004 s->flat_range[0] =
M_PI *
s->h_fov / 360.f;
3005 s->flat_range[1] = tanf(0.5f *
s->v_fov *
M_PI / 180.f);
3024 const float uf =
s->flat_range[0] * ((2.f *
i + 1.f) /
width - 1.f);
3025 const float vf =
s->flat_range[1] * ((2.f * j + 1.f) /
height - 1.f);
3027 const float phi = uf;
3028 const float theta =
atanf(vf);
3030 const float sin_phi =
sinf(phi);
3031 const float cos_phi =
cosf(phi);
3032 const float sin_theta =
sinf(theta);
3033 const float cos_theta =
cosf(theta);
3035 vec[0] = cos_theta * sin_phi;
3037 vec[2] = cos_theta * cos_phi;
3055 s->iflat_range[0] =
M_PI *
s->ih_fov / 360.f;
3056 s->iflat_range[1] = tanf(0.5f *
s->iv_fov *
M_PI / 180.f);
3075 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3077 const float phi =
atan2f(vec[0], vec[2]) /
s->iflat_range[0];
3078 const float theta = asinf(vec[1]);
3080 const float uf = (phi + 1.f) * (
width - 1) / 2.f;
3081 const float vf = (tanf(theta) /
s->iflat_range[1] + 1.f) *
height / 2.f;
3084 const int vi =
floorf(vf);
3086 const int visible = vi >= 0 && vi < height && ui >= 0 &&
ui <
width &&
3087 theta <=
M_PI *
s->iv_fov / 180.f &&
3088 theta >= -
M_PI *
s->iv_fov / 180.f;
3093 for (
int i = 0;
i < 4;
i++) {
3094 for (
int j = 0; j < 4; j++) {
3117 const float uf = ((2.f *
i + 1.f) /
width - 1.f);
3118 const float vf = ((2.f * j + 1.f) /
height - 1.f);
3119 const float rh = hypotf(uf, vf);
3120 const float sinzz = 1.f - rh * rh;
3121 const float h = 1.f +
s->v_fov;
3122 const float sinz = (
h - sqrtf(sinzz)) / (
h / rh + rh /
h);
3123 const float sinz2 = sinz * sinz;
3126 const float cosz = sqrtf(1.f - sinz2);
3128 const float theta = asinf(cosz);
3129 const float phi =
atan2f(uf, vf);
3131 const float sin_phi =
sinf(phi);
3132 const float cos_phi =
cosf(phi);
3133 const float sin_theta =
sinf(theta);
3134 const float cos_theta =
cosf(theta);
3136 vec[0] = cos_theta * sin_phi;
3137 vec[1] = cos_theta * cos_phi;
3163 const float uf = (float)
i /
width;
3164 const float vf = (float)j /
height;
3166 vec[0] = uf < 0.5f ? uf * 4.f - 1.f : 3.f - uf * 4.f;
3167 vec[1] = 1.f - vf * 2.f;
3168 vec[2] = 2.f *
fabsf(1.f -
fabsf(1.f - uf * 2.f + vf)) - 1.f;
3189 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3191 const float d0 = vec[0] * 1.f + vec[1] * 1.f + vec[2] *-1.f;
3192 const float d1 = vec[0] *-1.f + vec[1] *-1.f + vec[2] *-1.f;
3193 const float d2 = vec[0] * 1.f + vec[1] *-1.f + vec[2] * 1.f;
3194 const float d3 = vec[0] *-1.f + vec[1] * 1.f + vec[2] * 1.f;
3197 float uf, vf, x, y, z;
3204 vf = 0.5f - y * 0.5f;
3206 if ((x + y >= 0.f && y + z >= 0.f && -z - x <= 0.f) ||
3207 (x + y <= 0.f && -y + z >= 0.f && z - x >= 0.f)) {
3208 uf = 0.25f * x + 0.25f;
3210 uf = 0.75f - 0.25f * x;
3222 for (
int i = 0;
i < 4;
i++) {
3223 for (
int j = 0; j < 4; j++) {
3246 const float ew =
width / 2.f;
3249 const int ei =
i >= ew ?
i - ew :
i;
3250 const float m =
i >= ew ? 1.f : -1.f;
3252 const float uf =
s->flat_range[0] * ((2.f * ei) / ew - 1.f);
3253 const float vf =
s->flat_range[1] * ((2.f * j + 1.f) / eh - 1.f);
3255 const float h = hypotf(uf, vf);
3256 const float lh =
h > 0.f ?
h : 1.f;
3257 const float theta = m *
M_PI_2 * (1.f -
h);
3259 const float sin_theta =
sinf(theta);
3260 const float cos_theta =
cosf(theta);
3262 vec[0] = cos_theta * m * uf / lh;
3263 vec[1] = cos_theta * vf / lh;
3285 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3287 const float ew =
width / 2.f;
3290 const float h = hypotf(vec[0], vec[1]);
3291 const float lh =
h > 0.f ?
h : 1.f;
3292 const float theta = acosf(
fabsf(vec[2])) /
M_PI;
3294 float uf = (theta * (vec[0] / lh) /
s->iflat_range[0] + 0.5f) * ew;
3295 float vf = (theta * (vec[1] / lh) /
s->iflat_range[1] + 0.5f) * eh;
3300 if (vec[2] >= 0.f) {
3301 u_shift =
ceilf(ew);
3313 for (
int i = 0;
i < 4;
i++) {
3314 for (
int j = 0; j < 4; j++) {
3337 const float scale = 0.99f;
3338 float l_x, l_y, l_z;
3341 const float theta_range = M_PI_4;
3343 const int ew = 4 *
width / 5;
3346 const float phi = ((2.f *
i) / ew - 1.f) *
M_PI / scale;
3347 const float theta = ((2.f * j) / eh - 1.f) * theta_range / scale;
3349 const float sin_phi =
sinf(phi);
3350 const float cos_phi =
cosf(phi);
3351 const float sin_theta =
sinf(theta);
3352 const float cos_theta =
cosf(theta);
3354 l_x = cos_theta * sin_phi;
3356 l_z = cos_theta * cos_phi;
3358 const int ew =
width / 5;
3359 const int eh =
height / 2;
3364 uf = 2.f * (
i - 4 * ew) / ew - 1.f;
3365 vf = 2.f * (j ) / eh - 1.f;
3374 uf = 2.f * (
i - 4 * ew) / ew - 1.f;
3375 vf = 2.f * (j - eh) / eh - 1.f;
3409 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3411 const float scale = 0.99f;
3413 const float phi =
atan2f(vec[0], vec[2]);
3414 const float theta = asinf(vec[1]);
3415 const float theta_range = M_PI_4;
3418 int u_shift, v_shift;
3422 if (theta > -theta_range && theta < theta_range) {
3429 uf = (phi /
M_PI * scale + 1.f) * ew / 2.f;
3430 vf = (theta / theta_range * scale + 1.f) * eh / 2.f;
3438 uf = -vec[0] / vec[1];
3439 vf = -vec[2] / vec[1];
3442 uf = vec[0] / vec[1];
3443 vf = -vec[2] / vec[1];
3447 uf = 0.5f * ew * (uf * scale + 1.f);
3448 vf = 0.5f * eh * (vf * scale + 1.f);
3457 for (
int i = 0;
i < 4;
i++) {
3458 for (
int j = 0; j < 4; j++) {
3460 vs[
i][j] = v_shift +
av_clip(vi +
i - 1, 0, eh - 1);
3481 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3483 const float phi =
atan2f(vec[0], vec[2]);
3484 const float theta = asinf(vec[1]);
3486 const float theta_range = M_PI_4;
3489 int u_shift, v_shift;
3493 if (theta >= -theta_range && theta <= theta_range) {
3494 const float scalew =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
width * 2.f / 3.f) : 1.f -
s->in_pad;
3495 const float scaleh =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
height / 2.f) : 1.f -
s->in_pad;
3504 vf = theta / M_PI_4;
3507 uf = uf >= 0.f ? fmodf(uf - 1.f, 1.f) : fmodf(uf + 1.f, 1.f);
3509 uf = (uf * scalew + 1.f) *
width / 3.f;
3510 vf = (vf * scaleh + 1.f) *
height / 4.f;
3512 const float scalew =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
width / 3.f) : 1.f -
s->in_pad;
3513 const float scaleh =
s->fin_pad > 0 ? 1.f -
s->fin_pad / (
height / 4.f) : 1.f -
s->in_pad;
3521 if (theta <= 0.f && theta >= -
M_PI_2 &&
3522 phi <= M_PI_2 && phi >= -
M_PI_2) {
3523 uf = -vec[0] / vec[1];
3524 vf = -vec[2] / vec[1];
3527 }
else if (theta >= 0.f && theta <=
M_PI_2 &&
3528 phi <= M_PI_2 && phi >= -
M_PI_2) {
3529 uf = vec[0] / vec[1];
3530 vf = -vec[2] / vec[1];
3531 v_shift =
height * 0.25f;
3532 }
else if (theta <= 0.f && theta >= -
M_PI_2) {
3533 uf = vec[0] / vec[1];
3534 vf = vec[2] / vec[1];
3538 uf = -vec[0] / vec[1];
3539 vf = vec[2] / vec[1];
3540 v_shift =
height * 0.75f;
3543 uf = 0.5f *
width / 3.f * (uf * scalew + 1.f);
3544 vf =
height * 0.25f * (vf * scaleh + 1.f) + v_offset;
3553 for (
int i = 0;
i < 4;
i++) {
3554 for (
int j = 0; j < 4; j++) {
3556 vs[
i][j] = v_shift +
av_clip(vi +
i - 1, 0, eh - 1);
3577 const float x = (
i + 0.5f) /
width;
3578 const float y = (j + 0.5f) /
height;
3579 float l_x, l_y, l_z;
3581 if (x < 2.f / 3.f) {
3582 const float scalew =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
width * 2.f / 3.f) : 1.f -
s->out_pad;
3583 const float scaleh =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
height / 2.f) : 1.f -
s->out_pad;
3585 const float back =
floorf(y * 2.f);
3587 const float phi = ((3.f / 2.f * x - 0.5f) / scalew - back) *
M_PI;
3588 const float theta = (y - 0.25f - 0.5f * back) / scaleh *
M_PI;
3590 const float sin_phi =
sinf(phi);
3591 const float cos_phi =
cosf(phi);
3592 const float sin_theta =
sinf(theta);
3593 const float cos_theta =
cosf(theta);
3595 l_x = cos_theta * sin_phi;
3597 l_z = cos_theta * cos_phi;
3599 const float scalew =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
width / 3.f) : 1.f -
s->out_pad;
3600 const float scaleh =
s->fout_pad > 0 ? 1.f -
s->fout_pad / (
height / 4.f) : 1.f -
s->out_pad;
3602 const int face =
floorf(y * 4.f);
3613 l_x = (0.5f - uf) / scalew;
3615 l_z = (0.5f - vf) / scaleh;
3620 vf = 1.f - (vf - 0.5f);
3622 l_x = (0.5f - uf) / scalew;
3624 l_z = (-0.5f + vf) / scaleh;
3627 vf = y * 2.f - 0.5f;
3628 vf = 1.f - (1.f - vf);
3630 l_x = (0.5f - uf) / scalew;
3632 l_z = (0.5f - vf) / scaleh;
3635 vf = y * 2.f - 1.5f;
3637 l_x = (0.5f - uf) / scalew;
3639 l_z = (-0.5f + vf) / scaleh;
3669 const float x = (
i + 0.5f) /
width;
3670 const float y = (j + 0.5f) /
height;
3673 vec[0] = x * 4.f - 1.f;
3674 vec[1] = (y * 2.f - 1.f);
3676 }
else if (x >= 0.6875f && x < 0.8125f &&
3677 y >= 0.375f && y < 0.625f) {
3678 vec[0] = -(x - 0.6875f) * 16.f + 1.f;
3679 vec[1] = (y - 0.375f) * 8.f - 1.f;
3681 }
else if (0.5f <= x && x < 0.6875f &&
3682 ((0.f <= y && y < 0.375f && y >= 2.f * (x - 0.5f)) ||
3683 (0.375f <= y && y < 0.625f) ||
3684 (0.625f <= y && y < 1.f && y <= 2.f * (1.f - x)))) {
3686 vec[1] = 2.f * (y - 2.f * x + 1.f) / (3.f - 4.f * x) - 1.f;
3687 vec[2] = -2.f * (x - 0.5f) / 0.1875f + 1.f;
3688 }
else if (0.8125f <= x && x < 1.f &&
3689 ((0.f <= y && y < 0.375f && x >= (1.f - y / 2.f)) ||
3690 (0.375f <= y && y < 0.625f) ||
3691 (0.625f <= y && y < 1.f && y <= (2.f * x - 1.f)))) {
3693 vec[1] = 2.f * (y + 2.f * x - 2.f) / (4.f * x - 3.f) - 1.f;
3694 vec[2] = 2.f * (x - 0.8125f) / 0.1875f - 1.f;
3695 }
else if (0.f <= y && y < 0.375f &&
3696 ((0.5f <= x && x < 0.8125f && y < 2.f * (x - 0.5f)) ||
3697 (0.6875f <= x && x < 0.8125f) ||
3698 (0.8125f <= x && x < 1.f && x < (1.f - y / 2.f)))) {
3699 vec[0] = 2.f * (1.f - x - 0.5f * y) / (0.5f - y) - 1.f;
3701 vec[2] = 2.f * (0.375f - y) / 0.375f - 1.f;
3703 vec[0] = 2.f * (0.5f - x + 0.5f * y) / (y - 0.5f) - 1.f;
3705 vec[2] = -2.f * (1.f - y) / 0.375f + 1.f;
3727 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3735 uf = (uf + 1.f) * 0.5f;
3736 vf = (vf + 1.f) * 0.5f;
3740 uf = 0.1875f * vf - 0.375f * uf * vf - 0.125f * uf + 0.8125f;
3741 vf = 0.375f - 0.375f * vf;
3747 uf = 1.f - 0.1875f * vf - 0.5f * uf + 0.375f * uf * vf;
3748 vf = 1.f - 0.375f * vf;
3751 vf = 0.25f * vf + 0.75f * uf * vf - 0.375f * uf + 0.375f;
3752 uf = 0.1875f * uf + 0.8125f;
3755 vf = 0.375f * uf - 0.75f * uf * vf + vf;
3756 uf = 0.1875f * uf + 0.5f;
3759 uf = 0.125f * uf + 0.6875f;
3760 vf = 0.25f * vf + 0.375f;
3773 for (
int i = 0;
i < 4;
i++) {
3774 for (
int j = 0; j < 4; j++) {
3797 const float x = ((
i + 0.5f) /
width) * 2.f - 1.f;
3798 const float y = ((j + 0.5f) /
height) * 2.f - 1.f;
3799 const float ax =
fabsf(x);
3800 const float ay =
fabsf(y);
3802 vec[2] = 1.f - (ax + ay);
3803 if (ax + ay > 1.f) {
3804 vec[0] = (1.f - ay) *
FFSIGN(x);
3805 vec[1] = (1.f - ax) *
FFSIGN(y);
3830 int16_t
us[4][4], int16_t vs[4][4],
float *du,
float *dv)
3846 uf = uf * 0.5f + 0.5f;
3847 vf = vf * 0.5f + 0.5f;
3858 for (
int i = 0;
i < 4;
i++) {
3859 for (
int j = 0; j < 4; j++) {
3870 c[0] =
a[0] *
b[0] -
a[1] *
b[1] -
a[2] *
b[2] -
a[3] *
b[3];
3871 c[1] =
a[1] *
b[0] +
a[0] *
b[1] +
a[2] *
b[3] -
a[3] *
b[2];
3872 c[2] =
a[2] *
b[0] +
a[0] *
b[2] +
a[3] *
b[1] -
a[1] *
b[3];
3873 c[3] =
a[3] *
b[0] +
a[0] *
b[3] +
a[1] *
b[2] -
a[2] *
b[1];
3888 float rot_quaternion[2][4],
3889 const int rotation_order[3])
3891 const float yaw_rad = yaw *
M_PI / 180.f;
3892 const float pitch_rad = pitch *
M_PI / 180.f;
3893 const float roll_rad = roll *
M_PI / 180.f;
3895 const float sin_yaw =
sinf(yaw_rad * 0.5f);
3896 const float cos_yaw =
cosf(yaw_rad * 0.5f);
3897 const float sin_pitch =
sinf(pitch_rad * 0.5f);
3898 const float cos_pitch =
cosf(pitch_rad * 0.5f);
3899 const float sin_roll =
sinf(roll_rad * 0.5f);
3900 const float cos_roll =
cosf(roll_rad * 0.5f);
3905 m[0][0] = cos_yaw; m[0][1] = 0.f; m[0][2] = sin_yaw; m[0][3] = 0.f;
3906 m[1][0] = cos_pitch; m[1][1] = sin_pitch; m[1][2] = 0.f; m[1][3] = 0.f;
3907 m[2][0] = cos_roll; m[2][1] = 0.f; m[2][2] = 0.f; m[2][3] = sin_roll;
3922 static inline void rotate(
const float rot_quaternion[2][4],
3925 float qv[4],
temp[4], rqv[4];
3943 modifier[0] = h_flip ? -1.f : 1.f;
3944 modifier[1] = v_flip ? -1.f : 1.f;
3945 modifier[2] = d_flip ? -1.f : 1.f;
3948 static inline void mirror(
const float *modifier,
float *vec)
3950 vec[0] *= modifier[0];
3951 vec[1] *= modifier[1];
3952 vec[2] *= modifier[2];
3955 static inline void input_flip(int16_t
u[4][4], int16_t v[4][4],
int w,
int h,
int hflip,
int vflip)
3958 for (
int i = 0;
i < 4;
i++) {
3959 for (
int j = 0; j < 4; j++)
3960 u[
i][j] =
w - 1 -
u[
i][j];
3965 for (
int i = 0;
i < 4;
i++) {
3966 for (
int j = 0; j < 4; j++)
3967 v[
i][j] =
h - 1 - v[
i][j];
3974 const int pr_height =
s->pr_height[p];
3976 for (
int n = 0; n <
s->nb_threads; n++) {
3978 const int slice_start = (pr_height * n ) /
s->nb_threads;
3979 const int slice_end = (pr_height * (n + 1)) /
s->nb_threads;
3986 if (!
r->u[p] || !
r->v[p])
3995 if (sizeof_mask && !p) {
4011 const float d = 0.5f * hypotf(
w,
h);
4012 const float l =
sinf(d_fov *
M_PI / 360.f) / d;
4014 *h_fov = asinf(
w * 0.5 * l) * 360.f /
M_PI;
4015 *v_fov = asinf(
h * 0.5 * l) * 360.f /
M_PI;
4017 if (d_fov > 180.f) {
4018 *h_fov = 180.f - *h_fov;
4019 *v_fov = 180.f - *v_fov;
4025 const float d = 0.5f * hypotf(
w,
h);
4026 const float l = d / (
sinf(d_fov *
M_PI / 720.f));
4028 *h_fov = 2.f * asinf(
w * 0.5f / l) * 360.f /
M_PI;
4029 *v_fov = 2.f * asinf(
h * 0.5f / l) * 360.f /
M_PI;
4034 const float d = 0.5f * hypotf(
w,
h);
4035 const float l = d / (tanf(d_fov *
M_PI / 720.f));
4037 *h_fov = 2.f *
atan2f(
w * 0.5f, l) * 360.f /
M_PI;
4038 *v_fov = 2.f *
atan2f(
h * 0.5f, l) * 360.f /
M_PI;
4043 const float d = 0.5f * hypotf(
w * 0.5f,
h);
4045 *h_fov = d /
w * 2.f * d_fov;
4046 *v_fov = d /
h * d_fov;
4051 const float d = 0.5f * hypotf(
w,
h);
4053 *h_fov = d /
w * d_fov;
4054 *v_fov = d /
h * d_fov;
4060 const float da = tanf(0.5f *
FFMIN(d_fov, 359.f) *
M_PI / 180.f);
4061 const float d = hypotf(
w,
h);
4078 outw[0] = outw[3] =
w;
4080 outh[0] = outh[3] =
h;
4089 for (
int p = 0; p <
s->nb_allocated; p++) {
4090 const int max_value =
s->max_value;
4091 const int width =
s->pr_width[p];
4092 const int uv_linesize =
s->uv_linesize[p];
4093 const int height =
s->pr_height[p];
4094 const int in_width =
s->inplanewidth[p];
4095 const int in_height =
s->inplaneheight[p];
4096 const int slice_start = (
height * jobnr ) / nb_jobs;
4103 for (
int j = slice_start; j <
slice_end; j++) {
4105 int16_t *
u =
r->u[p] + ((j - slice_start) * uv_linesize +
i) *
elements;
4106 int16_t *v =
r->v[p] + ((j - slice_start) * uv_linesize +
i) *
elements;
4107 int16_t *ker =
r->ker[p] + ((j - slice_start) * uv_linesize +
i) *
elements;
4108 uint8_t *mask8 = (p || !
r->mask) ?
NULL :
r->mask + ((j - slice_start) *
s->pr_width[0] +
i);
4109 uint16_t *mask16 = (p || !
r->mask) ?
NULL : (uint16_t *)
r->mask + ((j - slice_start) *
s->pr_width[0] +
i);
4110 int in_mask, out_mask;
4112 if (
s->out_transpose)
4117 rotate(
s->rot_quaternion, vec);
4120 mirror(
s->output_mirror_modifier, vec);
4121 if (
s->in_transpose)
4122 in_mask =
s->in_transform(
s, vec, in_height, in_width, rmap.
v, rmap.
u, &du, &dv);
4124 in_mask =
s->in_transform(
s, vec, in_width, in_height, rmap.
u, rmap.
v, &du, &dv);
4125 input_flip(rmap.
u, rmap.
v, in_width, in_height,
s->ih_flip,
s->iv_flip);
4127 s->calculate_kernel(du, dv, &rmap,
u, v, ker);
4129 if (!p &&
r->mask) {
4130 if (
s->mask_size == 1) {
4131 mask8[0] = 255 * (out_mask & in_mask);
4133 mask16[0] = max_value * (out_mask & in_mask);
4149 const int depth =
desc->comp[0].depth;
4150 const int sizeof_mask =
s->mask_size = (depth + 7) >> 3;
4155 int in_offset_h, in_offset_w;
4156 int out_offset_h, out_offset_w;
4161 s->max_value = (1 << depth) - 1;
4163 switch (
s->interp) {
4166 s->remap_slice = depth <= 8 ? remap1_8bit_slice : remap1_16bit_slice;
4168 sizeof_uv =
sizeof(int16_t) *
s->elements;
4173 s->remap_slice = depth <= 8 ? remap2_8bit_slice : remap2_16bit_slice;
4174 s->elements = 2 * 2;
4175 sizeof_uv =
sizeof(int16_t) *
s->elements;
4176 sizeof_ker =
sizeof(int16_t) *
s->elements;
4180 s->remap_slice = depth <= 8 ? remap3_8bit_slice : remap3_16bit_slice;
4181 s->elements = 3 * 3;
4182 sizeof_uv =
sizeof(int16_t) *
s->elements;
4183 sizeof_ker =
sizeof(int16_t) *
s->elements;
4187 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
4188 s->elements = 4 * 4;
4189 sizeof_uv =
sizeof(int16_t) *
s->elements;
4190 sizeof_ker =
sizeof(int16_t) *
s->elements;
4194 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
4195 s->elements = 4 * 4;
4196 sizeof_uv =
sizeof(int16_t) *
s->elements;
4197 sizeof_ker =
sizeof(int16_t) *
s->elements;
4201 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
4202 s->elements = 4 * 4;
4203 sizeof_uv =
sizeof(int16_t) *
s->elements;
4204 sizeof_ker =
sizeof(int16_t) *
s->elements;
4208 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
4209 s->elements = 4 * 4;
4210 sizeof_uv =
sizeof(int16_t) *
s->elements;
4211 sizeof_ker =
sizeof(int16_t) *
s->elements;
4215 s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
4216 s->elements = 4 * 4;
4217 sizeof_uv =
sizeof(int16_t) *
s->elements;
4218 sizeof_ker =
sizeof(int16_t) *
s->elements;
4226 for (
int order = 0; order <
NB_RORDERS; order++) {
4227 const char c =
s->rorder[order];
4232 "Incomplete rorder option. Direction for all 3 rotation orders should be specified. Switching to default rorder.\n");
4233 s->rotation_order[0] =
YAW;
4234 s->rotation_order[1] =
PITCH;
4235 s->rotation_order[2] =
ROLL;
4242 "Incorrect rotation order symbol '%c' in rorder option. Switching to default rorder.\n",
c);
4243 s->rotation_order[0] =
YAW;
4244 s->rotation_order[1] =
PITCH;
4245 s->rotation_order[2] =
ROLL;
4249 s->rotation_order[order] = rorder;
4252 switch (
s->in_stereo) {
4256 in_offset_w = in_offset_h = 0;
4277 s->in_width =
s->inplanewidth[0];
4278 s->in_height =
s->inplaneheight[0];
4280 if (
s->id_fov > 0.f)
4283 if (
s->in_transpose)
4284 FFSWAP(
int,
s->in_width,
s->in_height);
4588 if (
s->width > 0 &&
s->height <= 0 &&
s->h_fov > 0.f &&
s->v_fov > 0.f &&
4589 s->out ==
FLAT &&
s->d_fov == 0.f) {
4591 h =
w / tanf(
s->h_fov *
M_PI / 360.f) * tanf(
s->v_fov *
M_PI / 360.f);
4592 }
else if (
s->width <= 0 &&
s->height > 0 &&
s->h_fov > 0.f &&
s->v_fov > 0.f &&
4593 s->out ==
FLAT &&
s->d_fov == 0.f) {
4595 w =
h / tanf(
s->v_fov *
M_PI / 360.f) * tanf(
s->h_fov *
M_PI / 360.f);
4596 }
else if (
s->width > 0 &&
s->height > 0) {
4599 }
else if (
s->width > 0 ||
s->height > 0) {
4603 if (
s->out_transpose)
4606 if (
s->in_transpose)
4617 err = prepare_out(
ctx);
4624 switch (
s->out_stereo) {
4626 out_offset_w = out_offset_h = 0;
4645 for (
int i = 0;
i < 4;
i++)
4655 if (
desc->log2_chroma_h ==
desc->log2_chroma_w &&
desc->log2_chroma_h == 0) {
4656 s->nb_allocated = 1;
4657 s->map[0] =
s->map[1] =
s->map[2] =
s->map[3] = 0;
4659 s->nb_allocated = 2;
4660 s->map[0] =
s->map[3] = 0;
4661 s->map[1] =
s->map[2] = 1;
4664 if (!
s->slice_remap)
4665 s->slice_remap =
av_calloc(
s->nb_threads,
sizeof(*
s->slice_remap));
4666 if (!
s->slice_remap)
4669 for (
int i = 0;
i <
s->nb_allocated;
i++) {
4670 err =
allocate_plane(
s, sizeof_uv, sizeof_ker, sizeof_mask * have_alpha *
s->alpha,
i);
4676 s->rot_quaternion,
s->rotation_order);
4710 char *res,
int res_len,
int flags)
4715 s->yaw =
s->pitch =
s->roll = 0.f;
4728 s->rot_quaternion[0][0] = 1.f;
4729 s->rot_quaternion[0][1] =
s->rot_quaternion[0][2] =
s->rot_quaternion[0][3] = 0.f;
4738 for (
int n = 0; n <
s->nb_threads &&
s->slice_remap; n++) {
4741 for (
int p = 0; p <
s->nb_allocated; p++) {
4780 .priv_class = &v360_class,
static const char *const format[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
#define u(width, name, range_min, range_max)
#define us(width, name, range_min, range_max, subs,...)
#define FFSWAP(type, a, b)
static __device__ float fabsf(float a)
static __device__ float floorf(float a)
static __device__ float ceilf(float a)
#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.
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_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static const int16_t alpha[]
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
static const ElemCat * elements[ELEMENT_COUNT]
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Used for passing data between threads.
static const uint8_t q1[256]
static const uint8_t q0[256]
void ff_v360_init_x86(V360Context *s, int depth)
#define NEAREST(type, name)
static enum AVPixelFormat alpha_pix_fmts[]
static int prepare_orthographic_in(AVFilterContext *ctx)
Prepare data for processing orthographic input format.
static int prepare_cylindrical_in(AVFilterContext *ctx)
Prepare data for processing cylindrical input format.
static void set_dimensions(int *outw, int *outh, int w, int h, const AVPixFmtDescriptor *desc)
static av_always_inline int v360_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void nearest_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Save nearest pixel coordinates for remapping.
static int flat_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in flat format.
static void calculate_cubic_bc_coeffs(float t, float *coeffs, float b, float c)
Calculate 1-dimensional cubic_bc_spline coefficients.
static int hequirect_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in half equirectangular format.
static void spline16_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for spline16 interpolation.
static int prepare_eac_in(AVFilterContext *ctx)
Prepare data for processing equi-angular cubemap input format.
static int xyz_to_hequirect(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in half equirectangular format for corresponding 3D coordinates on sphere.
static int xyz_to_mercator(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in mercator format for corresponding 3D coordinates on sphere.
static int xyz_to_cube6x1(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in cubemap6x1 format for corresponding 3D coordinates on sphere.
static void calculate_bicubic_coeffs(float t, float *coeffs)
Calculate 1-dimensional cubic coefficients.
static void rotate(const float rot_quaternion[2][4], float *vec)
Rotate vector with given rotation quaternion.
#define DEFINE_REMAP1_LINE(bits, div)
static int xyz_to_barrel(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in barrel facebook's format for corresponding 3D coordinates on sphere.
static int cube3x2_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in cubemap3x2 format.
static int prepare_eac_out(AVFilterContext *ctx)
Prepare data for processing equi-angular cubemap output format.
static int xyz_to_equisolid(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in equisolid format for corresponding 3D coordinates on sphere.
static int barrelsplit_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in barrel split facebook's format...
static int prepare_flat_out(AVFilterContext *ctx)
Prepare data for processing flat output format.
static void input_flip(int16_t u[4][4], int16_t v[4][4], int w, int h, int hflip, int vflip)
static int xyz_to_eac(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in equi-angular cubemap format for corresponding 3D coordinates on sphere.
#define DEFINE_REMAP(ws, bits)
Generate remapping function with a given window size and pixel depth.
static int xyz_to_fisheye(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in fisheye format for corresponding 3D coordinates on sphere.
static int dfisheye_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in dual fisheye format.
static int sinusoidal_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in sinusoidal format.
static int xyz_to_octahedron(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in octahedron format for corresponding 3D coordinates on sphere.
static int ball_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in ball format.
static void calculate_lanczos_coeffs(float t, float *coeffs)
Calculate 1-dimensional lanczos coefficients.
static void calculate_gaussian_coeffs(float t, float *coeffs)
Calculate 1-dimensional gaussian coefficients.
static void conjugate_quaternion(float d[4], const float q[4])
static void normalize_vector(float *vec)
Normalize vector.
static int get_direction(char c)
Convert char to corresponding direction.
void ff_v360_init(V360Context *s, int depth)
static int equirect_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in equirectangular format.
static int cube1x6_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in cubemap1x6 format.
static void calculate_spline16_coeffs(float t, float *coeffs)
Calculate 1-dimensional spline16 coefficients.
static int reflectx(int x, int y, int w, int h)
Reflect x operation.
static int query_formats(AVFilterContext *ctx)
static int xyz_to_dfisheye(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in dual fisheye format for corresponding 3D coordinates on sphere.
static int xyz_to_pannini(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in pannini format for corresponding 3D coordinates on sphere.
static int orthographic_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in orthographic format.
static const AVFilterPad inputs[]
static int prepare_cube_in(AVFilterContext *ctx)
Prepare data for processing cubemap input format.
static int prepare_fisheye_in(AVFilterContext *ctx)
Prepare data for processing fisheye input format.
static void mirror(const float *modifier, float *vec)
static void lanczos_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for lanczos interpolation.
static void cube_to_xyz(const V360Context *s, float uf, float vf, int face, float *vec, float scalew, float scaleh)
Calculate 3D coordinates on sphere for corresponding cubemap position.
static int perspective_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in perspective format.
static const AVFilterPad outputs[]
static int ereflectx(int x, int y, int w, int h)
Reflect x operation for equirect.
static int prepare_equisolid_out(AVFilterContext *ctx)
Prepare data for processing equisolid output format.
static void gaussian_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for gaussian interpolation.
static int prepare_fisheye_out(AVFilterContext *ctx)
Prepare data for processing fisheye output format.
static int tspyramid_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in tspyramid format.
static void process_cube_coordinates(const V360Context *s, float uf, float vf, int direction, float *new_uf, float *new_vf, int *face)
Find position on another cube face in case of overflow/underflow.
static int get_rotation(char c)
Convert char to corresponding rotation angle.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int allocate_plane(V360Context *s, int sizeof_uv, int sizeof_ker, int sizeof_mask, int p)
static void rotate_cube_face(float *uf, float *vf, int rotation)
static int xyz_to_barrelsplit(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in barrel split facebook's format for corresponding 3D coordinates on sphere...
static int xyz_to_cylindrical(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in cylindrical format for corresponding 3D coordinates on sphere.
static int xyz_to_stereographic(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in stereographic format for corresponding 3D coordinates on sphere.
static int reflecty(int y, int h)
Reflect y operation.
static void bicubic_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for bicubic interpolation.
static int stereographic_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in stereographic format.
static void set_mirror_modifier(int h_flip, int v_flip, int d_flip, float *modifier)
static int xyz_to_cube1x6(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in cubemap1x6 format for corresponding 3D coordinates on sphere.
static int xyz_to_flat(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in flat format for corresponding 3D coordinates on sphere.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static av_cold int init(AVFilterContext *ctx)
static void lagrange_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for lagrange interpolation.
static int xyz_to_orthographic(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in orthographic format for corresponding 3D coordinates on sphere.
static void xyz_to_cube(const V360Context *s, const float *vec, float *uf, float *vf, int *direction)
Calculate cubemap position for corresponding 3D coordinates on sphere.
static int cube6x1_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in cubemap6x1 format.
static av_cold void uninit(AVFilterContext *ctx)
static int prepare_stereographic_out(AVFilterContext *ctx)
Prepare data for processing stereographic output format.
static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov)
static int xyz_to_equirect(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.
static int prepare_cylindrical_out(AVFilterContext *ctx)
Prepare data for processing cylindrical output format.
static int xyz_to_cube3x2(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in cubemap3x2 format for corresponding 3D coordinates on sphere.
static int xyz_to_hammer(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in hammer format for corresponding 3D coordinates on sphere.
static int pannini_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in pannini format.
static void mitchell_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for mitchell interpolation.
static int xyz_to_sinusoidal(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in sinusoidal format for corresponding 3D coordinates on sphere.
static int mercator_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in mercator format.
static void calculate_lagrange_coeffs(float t, float *coeffs)
Calculate 1-dimensional lagrange coefficients.
static int xyz_to_tetrahedron(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in tetrahedron format for corresponding 3D coordinates on sphere.
static int config_output(AVFilterLink *outlink)
static int prepare_flat_in(AVFilterContext *ctx)
Prepare data for processing flat input format.
static int prepare_orthographic_out(AVFilterContext *ctx)
Prepare data for processing orthographic output format.
static int tetrahedron_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in tetrahedron format.
static int cylindrical_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in cylindrical format.
static int hammer_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in hammer format.
static int prepare_equisolid_in(AVFilterContext *ctx)
Prepare data for processing equisolid input format.
static int barrel_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in barrel facebook's format.
static int equisolid_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in equisolid format.
static void multiply_quaternion(float c[4], const float a[4], const float b[4])
AVFILTER_DEFINE_CLASS(v360)
#define DEFINE_REMAP_LINE(ws, bits, div)
static int xyz_to_ball(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in ball format for corresponding 3D coordinates on sphere.
static void calculate_rotation(float yaw, float pitch, float roll, float rot_quaternion[2][4], const int rotation_order[3])
Calculate rotation quaternion for yaw/pitch/roll angles.
static int get_rorder(char c)
Convert char to corresponding rotation order.
static int eac_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in equi-angular cubemap format.
static int octahedron_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in octahedron format.
static int xyz_to_tspyramid(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
Calculate frame position in tspyramid format for corresponding 3D coordinates on sphere.
static int fisheye_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec)
Calculate 3D coordinates on sphere for corresponding frame position in fisheye format.
static void rotate_cube_face_inverse(float *uf, float *vf, int rotation)
static int prepare_cube_out(AVFilterContext *ctx)
Prepare data for processing cubemap output format.
static const AVOption v360_options[]
static int mod(int a, int b)
Modulo operation with only positive remainders.
static int prepare_stereographic_in(AVFilterContext *ctx)
Prepare data for processing stereographic input format.
static void bilinear_kernel(float du, float dv, const XYRemap *rmap, int16_t *u, int16_t *v, int16_t *ker)
Calculate kernel for bilinear interpolation.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.