History

hevcdec: move deblock template to h26x/h2656_deblock_template.c

Nuo Mi committed 2 years ago

Commit ae0a8341 parent 69e179e2 files · +116 −79Browse files

Showing the changes to libavcodec (2 of 2 files). Show all

Unified · Split

2 files
  1. libavcodec/h26x/h2656_deblock_template.c +99 −0
  2. libavcodec/hevcdsp_template.c +17 −79
libavcodec/h26x/h2656_deblock_template.c+99−0
@@ -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+}
libavcodec/hevcdsp_template.c+17−79
@@ -1319,19 +1319,20 @@ static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, · 1318 unmodified lines
13191319 #define TQ2 pix[2 * xstride + 3 * ystride]
13201320 #define TQ3 pix[3 * xstride + 3 * ystride]
13211321
1322+#include "h26x/h2656_deblock_template.c"
1323+
13221324 static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
13231325 ptrdiff_t _xstride, ptrdiff_t _ystride,
13241326 int beta, const int *_tc,
13251327 const uint8_t *_no_p, const uint8_t *_no_q)
13261328 {
1327− int d, j;
1328− pixel *pix = (pixel *)_pix;
13291329 ptrdiff_t xstride = _xstride / sizeof(pixel);
13301330 ptrdiff_t ystride = _ystride / sizeof(pixel);
13311331
13321332 beta <<= BIT_DEPTH - 8;
13331333
1334− for (j = 0; j < 2; j++) {
1334+ for (int j = 0; j < 2; j++) {
1335+ pixel* pix = (pixel*)_pix + j * 4 * ystride;
13351336 const int dp0 = abs(P2 - 2 * P1 + P0);
13361337 const int dq0 = abs(Q2 - 2 * Q1 + Q0);
13371338 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
13421343 const int no_p = _no_p[j];
13431344 const int no_q = _no_q[j];
13441345
1345− if (d0 + d3 >= beta) {
1346− pix += 4 * ystride;
1347− continue;
1348− } else {
1346+ if (d0 + d3 < beta) {
13491347 const int beta_3 = beta >> 3;
13501348 const int beta_2 = beta >> 2;
13511349 const int tc25 = ((tc * 5 + 1) >> 1);
@@ -1353,63 +1351,16 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix, · 1 unmodified line
13531351 if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
13541352 abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
13551353 (d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
1356− // strong filtering
13571354 const int tc2 = tc << 1;
1358− for (d = 0; d < 4; d++) {
1359− const int p3 = P3;
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
1355+ FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc2, tc2, tc2, no_p, no_q);
1356+ } else {
13801357 int nd_p = 1;
13811358 int nd_q = 1;
1382− const int tc_2 = tc >> 1;
13831359 if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
13841360 nd_p = 2;
13851361 if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
13861362 nd_q = 2;
1387−
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− }
1363+ FUNC(loop_filter_luma_weak)(pix, xstride, ystride, tc, beta, no_p, no_q, nd_p, nd_q);
14131364 }
14141365 }
14151366 }
@@ -1419,32 +1370,19 @@ static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride, · 3 unmodified lines
14191370 ptrdiff_t _ystride, const int *_tc,
14201371 const uint8_t *_no_p, const uint8_t *_no_q)
14211372 {
1422− int d, j, no_p, no_q;
1423− pixel *pix = (pixel *)_pix;
1373+ int no_p, no_q;
14241374 ptrdiff_t xstride = _xstride / sizeof(pixel);
14251375 ptrdiff_t ystride = _ystride / sizeof(pixel);
1376+ const int size = 4;
14261377
1427− for (j = 0; j < 2; j++) {
1378+ for (int j = 0; j < 2; j++) {
1379+ pixel *pix = (pixel *)_pix + j * size * ystride;
14281380 const int tc = _tc[j] << (BIT_DEPTH - 8);
1429− if (tc <= 0) {
1430− pix += 4 * ystride;
1431− continue;
1432− }
1433− no_p = _no_p[j];
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;
1381+ if (tc > 0) {
1382+ no_p = _no_p[j];
1383+ no_q = _no_q[j];
1384+
1385+ FUNC(loop_filter_chroma_weak)(pix, xstride, ystride, size, tc, no_p, no_q);
14481386 }
14491387 }
14501388 }

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