Showing the changes to libavcodec (2 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,99 @@ | |||
| 1 | |||
| 2 | /* | ||
| 3 | * HEVC/VVC deblocking dsp template | ||
| 4 | * | ||
| 5 | * Copyright (C) 2024 Nuo Mi | ||
| 6 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
| 7 | * | ||
| 8 | * This file is part of FFmpeg. | ||
| 9 | * | ||
| 10 | * FFmpeg is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU Lesser General Public | ||
| 12 | * License as published by the Free Software Foundation; either | ||
| 13 | * version 2.1 of the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * Lesser General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU Lesser General Public | ||
| 21 | * License along with FFmpeg; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 23 | */ | ||
| 24 | |||
| 25 | static void FUNC(loop_filter_luma_strong)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, | ||
| 26 | const int32_t tc, const int32_t tc2, const int tc3, | ||
| 27 | const uint8_t no_p, const uint8_t no_q) | ||
| 28 | { | ||
| 29 | for (int d = 0; d < 4; d++) { | ||
| 30 | const int p3 = P3; | ||
| 31 | const int p2 = P2; | ||
| 32 | const int p1 = P1; | ||
| 33 | const int p0 = P0; | ||
| 34 | const int q0 = Q0; | ||
| 35 | const int q1 = Q1; | ||
| 36 | const int q2 = Q2; | ||
| 37 | const int q3 = Q3; | ||
| 38 | if (!no_p) { | ||
| 39 | P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc3, tc3); | ||
| 40 | P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2); | ||
| 41 | P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc, tc); | ||
| 42 | } | ||
| 43 | if (!no_q) { | ||
| 44 | Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc3, tc3); | ||
| 45 | Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2); | ||
| 46 | Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc, tc); | ||
| 47 | } | ||
| 48 | pix += ystride; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | static void FUNC(loop_filter_luma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, | ||
| 53 | const int32_t tc, const int32_t beta, const uint8_t no_p, const uint8_t no_q, const int nd_p, const int nd_q) | ||
| 54 | { | ||
| 55 | const int tc_2 = tc >> 1; | ||
| 56 | for (int d = 0; d < 4; d++) { | ||
| 57 | const int p2 = P2; | ||
| 58 | const int p1 = P1; | ||
| 59 | const int p0 = P0; | ||
| 60 | const int q0 = Q0; | ||
| 61 | const int q1 = Q1; | ||
| 62 | const int q2 = Q2; | ||
| 63 | int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4; | ||
| 64 | if (abs(delta0) < 10 * tc) { | ||
| 65 | delta0 = av_clip(delta0, -tc, tc); | ||
| 66 | if (!no_p) | ||
| 67 | P0 = av_clip_pixel(p0 + delta0); | ||
| 68 | if (!no_q) | ||
| 69 | Q0 = av_clip_pixel(q0 - delta0); | ||
| 70 | if (!no_p && nd_p > 1) { | ||
| 71 | const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2); | ||
| 72 | P1 = av_clip_pixel(p1 + deltap1); | ||
| 73 | } | ||
| 74 | if (!no_q && nd_q > 1) { | ||
| 75 | const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2); | ||
| 76 | Q1 = av_clip_pixel(q1 + deltaq1); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | pix += ystride; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | static void FUNC(loop_filter_chroma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, | ||
| 84 | const int size, const int32_t tc, const uint8_t no_p, const uint8_t no_q) | ||
| 85 | { | ||
| 86 | for (int d = 0; d < size; d++) { | ||
| 87 | int delta0; | ||
| 88 | const int p1 = P1; | ||
| 89 | const int p0 = P0; | ||
| 90 | const int q0 = Q0; | ||
| 91 | const int q1 = Q1; | ||
| 92 | delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc); | ||
| 93 | if (!no_p) | ||
| 94 | P0 = av_clip_pixel(p0 + delta0); | ||
| 95 | if (!no_q) | ||
| 96 | Q0 = av_clip_pixel(q0 - delta0); | ||
| 97 | pix += ystride; | ||
| 98 | } | ||
| 99 | } | ||
| @@ -1319,19 +1319,20 @@ static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, · 1318 unmodified lines | |||
| 1319 | #define TQ2 pix[2 * xstride + 3 * ystride] | 1319 | #define TQ2 pix[2 * xstride + 3 * ystride] |
| 1320 | #define TQ3 pix[3 * xstride + 3 * ystride] | 1320 | #define TQ3 pix[3 * xstride + 3 * ystride] |
| 1321 | 1321 | ||
| 1322 | #include "h26x/h2656_deblock_template.c" | ||
| 1323 | |||
| 1322 | static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, | 1324 | static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, |
| 1323 | ptrdiff_t _xstride, ptrdiff_t _ystride, | 1325 | ptrdiff_t _xstride, ptrdiff_t _ystride, |
| 1324 | int beta, const int *_tc, | 1326 | int beta, const int *_tc, |
| 1325 | const uint8_t *_no_p, const uint8_t *_no_q) | 1327 | const uint8_t *_no_p, const uint8_t *_no_q) |
| 1326 | { | 1328 | { |
| 1327 | int d, j; | ||
| 1328 | pixel *pix = (pixel *)_pix; | ||
| 1329 | ptrdiff_t xstride = _xstride / sizeof(pixel); | 1329 | ptrdiff_t xstride = _xstride / sizeof(pixel); |
| 1330 | ptrdiff_t ystride = _ystride / sizeof(pixel); | 1330 | ptrdiff_t ystride = _ystride / sizeof(pixel); |
| 1331 | 1331 | ||
| 1332 | beta <<= BIT_DEPTH - 8; | 1332 | beta <<= BIT_DEPTH - 8; |
| 1333 | 1333 | ||
| 1334 | for (j = 0; j < 2; j++) { | 1334 | for (int j = 0; j < 2; j++) { |
| 1335 | pixel* pix = (pixel*)_pix + j * 4 * ystride; | ||
| 1335 | const int dp0 = abs(P2 - 2 * P1 + P0); | 1336 | const int dp0 = abs(P2 - 2 * P1 + P0); |
| 1336 | const int dq0 = abs(Q2 - 2 * Q1 + Q0); | 1337 | const int dq0 = abs(Q2 - 2 * Q1 + Q0); |
| 1337 | const int dp3 = abs(TP2 - 2 * TP1 + TP0); | 1338 | const int dp3 = abs(TP2 - 2 * TP1 + TP0); |
| @@ -1342,10 +1343,7 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, · 4 unmodified lines | |||
| 1342 | const int no_p = _no_p[j]; | 1343 | const int no_p = _no_p[j]; |
| 1343 | const int no_q = _no_q[j]; | 1344 | const int no_q = _no_q[j]; |
| 1344 | 1345 | ||
| 1345 | if (d0 + d3 >= beta) { | 1346 | if (d0 + d3 < beta) { |
| 1346 | pix += 4 * ystride; | ||
| 1347 | continue; | ||
| 1348 | } else { | ||
| 1349 | const int beta_3 = beta >> 3; | 1347 | const int beta_3 = beta >> 3; |
| 1350 | const int beta_2 = beta >> 2; | 1348 | const int beta_2 = beta >> 2; |
| 1351 | const int tc25 = ((tc * 5 + 1) >> 1); | 1349 | const int tc25 = ((tc * 5 + 1) >> 1); |
| @@ -1353,63 +1351,16 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, · 1 unmodified line | |||
| 1353 | if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 && | 1351 | if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 && |
| 1354 | abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 && | 1352 | abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 && |
| 1355 | (d0 << 1) < beta_2 && (d3 << 1) < beta_2) { | 1353 | (d0 << 1) < beta_2 && (d3 << 1) < beta_2) { |
| 1356 | // strong filtering | ||
| 1357 | const int tc2 = tc << 1; | 1354 | const int tc2 = tc << 1; |
| 1358 | for (d = 0; d < 4; d++) { | 1355 | FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc2, tc2, tc2, no_p, no_q); |
| 1359 | const int p3 = P3; | 1356 | } else { |
| 1360 | const int p2 = P2; | ||
| 1361 | const int p1 = P1; | ||
| 1362 | const int p0 = P0; | ||
| 1363 | const int q0 = Q0; | ||
| 1364 | const int q1 = Q1; | ||
| 1365 | const int q2 = Q2; | ||
| 1366 | const int q3 = Q3; | ||
| 1367 | if (!no_p) { | ||
| 1368 | P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2); | ||
| 1369 | P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2); | ||
| 1370 | P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2); | ||
| 1371 | } | ||
| 1372 | if (!no_q) { | ||
| 1373 | Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2); | ||
| 1374 | Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2); | ||
| 1375 | Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2); | ||
| 1376 | } | ||
| 1377 | pix += ystride; | ||
| 1378 | } | ||
| 1379 | } else { // normal filtering | ||
| 1380 | int nd_p = 1; | 1357 | int nd_p = 1; |
| 1381 | int nd_q = 1; | 1358 | int nd_q = 1; |
| 1382 | const int tc_2 = tc >> 1; | ||
| 1383 | if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3)) | 1359 | if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3)) |
| 1384 | nd_p = 2; | 1360 | nd_p = 2; |
| 1385 | if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3)) | 1361 | if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3)) |
| 1386 | nd_q = 2; | 1362 | nd_q = 2; |
| 1387 | 1363 | FUNC(loop_filter_luma_weak)(pix, xstride, ystride, tc, beta, no_p, no_q, nd_p, nd_q); | |
| 1388 | for (d = 0; d < 4; d++) { | ||
| 1389 | const int p2 = P2; | ||
| 1390 | const int p1 = P1; | ||
| 1391 | const int p0 = P0; | ||
| 1392 | const int q0 = Q0; | ||
| 1393 | const int q1 = Q1; | ||
| 1394 | const int q2 = Q2; | ||
| 1395 | int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4; | ||
| 1396 | if (abs(delta0) < 10 * tc) { | ||
| 1397 | delta0 = av_clip(delta0, -tc, tc); | ||
| 1398 | if (!no_p) | ||
| 1399 | P0 = av_clip_pixel(p0 + delta0); | ||
| 1400 | if (!no_q) | ||
| 1401 | Q0 = av_clip_pixel(q0 - delta0); | ||
| 1402 | if (!no_p && nd_p > 1) { | ||
| 1403 | const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2); | ||
| 1404 | P1 = av_clip_pixel(p1 + deltap1); | ||
| 1405 | } | ||
| 1406 | if (!no_q && nd_q > 1) { | ||
| 1407 | const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2); | ||
| 1408 | Q1 = av_clip_pixel(q1 + deltaq1); | ||
| 1409 | } | ||
| 1410 | } | ||
| 1411 | pix += ystride; | ||
| 1412 | } | ||
| 1413 | } | 1364 | } |
| 1414 | } | 1365 | } |
| 1415 | } | 1366 | } |
| @@ -1419,32 +1370,19 @@ static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride, · 3 unmodified lines | |||
| 1419 | ptrdiff_t _ystride, const int *_tc, | 1370 | ptrdiff_t _ystride, const int *_tc, |
| 1420 | const uint8_t *_no_p, const uint8_t *_no_q) | 1371 | const uint8_t *_no_p, const uint8_t *_no_q) |
| 1421 | { | 1372 | { |
| 1422 | int d, j, no_p, no_q; | 1373 | int no_p, no_q; |
| 1423 | pixel *pix = (pixel *)_pix; | ||
| 1424 | ptrdiff_t xstride = _xstride / sizeof(pixel); | 1374 | ptrdiff_t xstride = _xstride / sizeof(pixel); |
| 1425 | ptrdiff_t ystride = _ystride / sizeof(pixel); | 1375 | ptrdiff_t ystride = _ystride / sizeof(pixel); |
| 1376 | const int size = 4; | ||
| 1426 | 1377 | ||
| 1427 | for (j = 0; j < 2; j++) { | 1378 | for (int j = 0; j < 2; j++) { |
| 1379 | pixel *pix = (pixel *)_pix + j * size * ystride; | ||
| 1428 | const int tc = _tc[j] << (BIT_DEPTH - 8); | 1380 | const int tc = _tc[j] << (BIT_DEPTH - 8); |
| 1429 | if (tc <= 0) { | 1381 | if (tc > 0) { |
| 1430 | pix += 4 * ystride; | 1382 | no_p = _no_p[j]; |
| 1431 | continue; | 1383 | no_q = _no_q[j]; |
| 1432 | } | 1384 | |
| 1433 | no_p = _no_p[j]; | 1385 | FUNC(loop_filter_chroma_weak)(pix, xstride, ystride, size, tc, no_p, no_q); |
| 1434 | no_q = _no_q[j]; | ||
| 1435 | |||
| 1436 | for (d = 0; d < 4; d++) { | ||
| 1437 | int delta0; | ||
| 1438 | const int p1 = P1; | ||
| 1439 | const int p0 = P0; | ||
| 1440 | const int q0 = Q0; | ||
| 1441 | const int q1 = Q1; | ||
| 1442 | delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc); | ||
| 1443 | if (!no_p) | ||
| 1444 | P0 = av_clip_pixel(p0 + delta0); | ||
| 1445 | if (!no_q) | ||
| 1446 | Q0 = av_clip_pixel(q0 - delta0); | ||
| 1447 | pix += ystride; | ||
| 1448 | } | 1386 | } |
| 1449 | } | 1387 | } |
| 1450 | } | 1388 | } |