Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
aom-rav1e
Commits
519dbcf1
Commit
519dbcf1
authored
Dec 16, 2016
by
Debargha Mukherjee
Browse files
Further optimizations of loop restoration
Change-Id: I4c4300f3f565d8aecf65669b77aaa874bb73a3a0
parent
f10cba2b
Changes
4
Hide whitespace changes
Inline
Side-by-side
av1/common/restoration.c
View file @
519dbcf1
...
...
@@ -27,7 +27,7 @@ static int domaintxfmrf_vtable[DOMAINTXFMRF_ITERS][DOMAINTXFMRF_PARAMS][256];
static
const
int
override_y_only
[
RESTORE_TYPES
]
=
{
1
,
1
,
1
,
1
,
1
};
static
const
int
domaintxfmrf_params
[
DOMAINTXFMRF_PARAMS
]
=
{
48
,
52
,
56
,
6
0
,
64
,
68
,
72
,
76
,
80
,
82
,
84
,
86
,
88
,
32
,
40
,
48
,
5
6
,
64
,
68
,
72
,
76
,
80
,
82
,
84
,
86
,
88
,
90
,
92
,
94
,
96
,
97
,
98
,
99
,
100
,
101
,
102
,
103
,
104
,
105
,
106
,
107
,
108
,
109
,
110
,
111
,
112
,
113
,
114
,
115
,
116
,
117
,
118
,
119
,
120
,
121
,
122
,
123
,
124
,
125
,
126
,
127
,
128
,
130
,
132
,
134
,
...
...
@@ -252,8 +252,8 @@ static void loop_wiener_filter(uint8_t *data, int width, int height, int stride,
}
}
static
void
boxsum
(
int
64
_t
*
src
,
int
width
,
int
height
,
int
src_stride
,
int
r
,
int
sqr
,
int
64
_t
*
dst
,
int
dst_stride
,
int
64
_t
*
tmp
,
static
void
boxsum
(
int
32
_t
*
src
,
int
width
,
int
height
,
int
src_stride
,
int
r
,
int
sqr
,
int
32
_t
*
dst
,
int
dst_stride
,
int
32
_t
*
tmp
,
int
tmp_stride
)
{
int
i
,
j
;
...
...
@@ -342,11 +342,11 @@ void decode_xq(int *xqd, int *xq) {
}
#define APPROXIMATE_SGR 1
void
av1_selfguided_restoration
(
int
64
_t
*
dgd
,
int
width
,
int
height
,
int
stride
,
void
av1_selfguided_restoration
(
int
32
_t
*
dgd
,
int
width
,
int
height
,
int
stride
,
int
bit_depth
,
int
r
,
int
eps
,
void
*
tmpbuf
)
{
int
64
_t
*
A
=
(
int
64
_t
*
)
tmpbuf
;
int
64
_t
*
B
=
A
+
RESTORATION_TILEPELS_MAX
;
int
64
_t
*
T
=
B
+
RESTORATION_TILEPELS_MAX
;
int
32
_t
*
A
=
(
int
32
_t
*
)
tmpbuf
;
int
32
_t
*
B
=
A
+
RESTORATION_TILEPELS_MAX
;
int
32
_t
*
T
=
B
+
RESTORATION_TILEPELS_MAX
;
int8_t
num
[
RESTORATION_TILEPELS_MAX
];
int
i
,
j
;
eps
<<=
2
*
(
bit_depth
-
8
);
...
...
@@ -358,10 +358,9 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
for
(
j
=
0
;
j
<
width
;
++
j
)
{
const
int
k
=
i
*
width
+
j
;
const
int
n
=
num
[
k
];
int64_t
den
;
A
[
k
]
=
A
[
k
]
*
n
-
B
[
k
]
*
B
[
k
];
den
=
A
[
k
]
+
n
*
n
*
eps
;
A
[
k
]
=
((
A
[
k
]
<<
SGRPROJ_SGR_BITS
)
+
(
den
>>
1
))
/
den
;
const
int64_t
p
=
A
[
k
]
*
n
-
B
[
k
]
*
B
[
k
];
const
int64_t
q
=
p
+
n
*
n
*
eps
;
A
[
k
]
=
(
int32_t
)((
p
<<
SGRPROJ_SGR_BITS
)
+
(
q
>>
1
))
/
q
;
B
[
k
]
=
((
SGRPROJ_SGR
-
A
[
k
])
*
B
[
k
]
+
(
n
>>
1
))
/
n
;
}
}
...
...
@@ -372,11 +371,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
const
int
32
_t
a
=
3
*
A
[
k
]
+
2
*
A
[
k
+
1
]
+
2
*
A
[
k
+
width
]
+
A
[
k
+
width
+
1
];
const
int
64
_t
b
=
const
int
32
_t
b
=
3
*
B
[
k
]
+
2
*
B
[
k
+
1
]
+
2
*
B
[
k
+
width
]
+
B
[
k
+
width
+
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -386,11 +385,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
const
int
32
_t
a
=
3
*
A
[
k
]
+
2
*
A
[
k
-
1
]
+
2
*
A
[
k
+
width
]
+
A
[
k
+
width
-
1
];
const
int
64
_t
b
=
const
int
32
_t
b
=
3
*
B
[
k
]
+
2
*
B
[
k
-
1
]
+
2
*
B
[
k
+
width
]
+
B
[
k
+
width
-
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -400,11 +399,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
const
int
32
_t
a
=
3
*
A
[
k
]
+
2
*
A
[
k
+
1
]
+
2
*
A
[
k
-
width
]
+
A
[
k
-
width
+
1
];
const
int
64
_t
b
=
const
int
32
_t
b
=
3
*
B
[
k
]
+
2
*
B
[
k
+
1
]
+
2
*
B
[
k
-
width
]
+
B
[
k
-
width
+
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -414,11 +413,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
const
int
32
_t
a
=
3
*
A
[
k
]
+
2
*
A
[
k
-
1
]
+
2
*
A
[
k
-
width
]
+
A
[
k
-
width
-
1
];
const
int
64
_t
b
=
const
int
32
_t
b
=
3
*
B
[
k
]
+
2
*
B
[
k
-
1
]
+
2
*
B
[
k
-
width
]
+
B
[
k
-
width
-
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -427,11 +426,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
1
]
+
A
[
k
+
1
])
+
A
[
k
+
width
]
+
const
int
32
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
1
]
+
A
[
k
+
1
])
+
A
[
k
+
width
]
+
A
[
k
+
width
-
1
]
+
A
[
k
+
width
+
1
];
const
int
64
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
1
]
+
B
[
k
+
1
])
+
B
[
k
+
width
]
+
const
int
32
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
1
]
+
B
[
k
+
1
])
+
B
[
k
+
width
]
+
B
[
k
+
width
-
1
]
+
B
[
k
+
width
+
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -440,11 +439,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
1
]
+
A
[
k
+
1
])
+
A
[
k
-
width
]
+
const
int
32
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
1
]
+
A
[
k
+
1
])
+
A
[
k
-
width
]
+
A
[
k
-
width
-
1
]
+
A
[
k
-
width
+
1
];
const
int
64
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
1
]
+
B
[
k
+
1
])
+
B
[
k
-
width
]
+
const
int
32
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
1
]
+
B
[
k
+
1
])
+
B
[
k
-
width
]
+
B
[
k
-
width
-
1
]
+
B
[
k
-
width
+
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -453,11 +452,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
width
]
+
A
[
k
+
width
])
+
A
[
k
+
1
]
+
const
int
32
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
width
]
+
A
[
k
+
width
])
+
A
[
k
+
1
]
+
A
[
k
-
width
+
1
]
+
A
[
k
+
width
+
1
];
const
int
64
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
width
]
+
B
[
k
+
width
])
+
B
[
k
+
1
]
+
const
int
32
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
width
]
+
B
[
k
+
width
])
+
B
[
k
+
1
]
+
B
[
k
-
width
+
1
]
+
B
[
k
+
width
+
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -466,11 +465,11 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
3
;
const
int
64
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
width
]
+
A
[
k
+
width
])
+
A
[
k
-
1
]
+
const
int
32
_t
a
=
A
[
k
]
+
2
*
(
A
[
k
-
width
]
+
A
[
k
+
width
])
+
A
[
k
-
1
]
+
A
[
k
-
width
-
1
]
+
A
[
k
+
width
-
1
];
const
int
64
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
width
]
+
B
[
k
+
width
])
+
B
[
k
-
1
]
+
const
int
32
_t
b
=
B
[
k
]
+
2
*
(
B
[
k
-
width
]
+
B
[
k
+
width
])
+
B
[
k
-
1
]
+
B
[
k
-
width
-
1
]
+
B
[
k
+
width
-
1
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -479,17 +478,17 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
nb
=
5
;
const
int
64
_t
a
=
const
int
32
_t
a
=
(
A
[
k
]
+
A
[
k
-
1
]
+
A
[
k
+
1
]
+
A
[
k
-
width
]
+
A
[
k
+
width
])
*
4
+
(
A
[
k
-
1
-
width
]
+
A
[
k
-
1
+
width
]
+
A
[
k
+
1
-
width
]
+
A
[
k
+
1
+
width
])
*
3
;
const
int
64
_t
b
=
const
int
32
_t
b
=
(
B
[
k
]
+
B
[
k
-
1
]
+
B
[
k
+
1
]
+
B
[
k
-
width
]
+
B
[
k
+
width
])
*
4
+
(
B
[
k
-
1
-
width
]
+
B
[
k
-
1
+
width
]
+
B
[
k
+
1
-
width
]
+
B
[
k
+
1
+
width
])
*
3
;
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
a
*
dgd
[
l
]
+
b
)
<<
SGRPROJ_RST_BITS
)
+
(
1
<<
nb
)
/
2
)
>>
nb
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -503,7 +502,7 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
n
=
num
[
k
];
const
int
64
_t
v
=
const
int
32
_t
v
=
(((
A
[
k
]
*
dgd
[
l
]
+
B
[
k
])
<<
SGRPROJ_RST_BITS
)
+
(
n
>>
1
))
/
n
;
dgd
[
l
]
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_SGR_BITS
);
}
...
...
@@ -511,12 +510,13 @@ void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
#endif // APPROXIMATE_SGR
}
static
void
apply_selfguided_restoration
(
int
64
_t
*
dat
,
int
width
,
int
height
,
static
void
apply_selfguided_restoration
(
u
int
8
_t
*
dat
,
int
width
,
int
height
,
int
stride
,
int
bit_depth
,
int
eps
,
int
*
xqd
,
void
*
tmpbuf
)
{
int
*
xqd
,
uint8_t
*
dst
,
int
dst_stride
,
void
*
tmpbuf
)
{
int
xq
[
2
];
int
64
_t
*
flt1
=
(
int
64
_t
*
)
tmpbuf
;
int
64
_t
*
flt2
=
flt1
+
RESTORATION_TILEPELS_MAX
;
int
32
_t
*
flt1
=
(
int
32
_t
*
)
tmpbuf
;
int
32
_t
*
flt2
=
flt1
+
RESTORATION_TILEPELS_MAX
;
uint8_t
*
tmpbuf2
=
(
uint8_t
*
)(
flt2
+
RESTORATION_TILEPELS_MAX
);
int
i
,
j
;
for
(
i
=
0
;
i
<
height
;
++
i
)
{
...
...
@@ -535,13 +535,14 @@ static void apply_selfguided_restoration(int64_t *dat, int width, int height,
for
(
j
=
0
;
j
<
width
;
++
j
)
{
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int64_t
u
=
((
int64_t
)
dat
[
l
]
<<
SGRPROJ_RST_BITS
);
const
int64_t
f1
=
(
int64_t
)
flt1
[
k
]
-
u
;
const
int64_t
f2
=
(
int64_t
)
flt2
[
k
]
-
u
;
const
int
m
=
i
*
dst_stride
+
j
;
const
int32_t
u
=
((
int32_t
)
dat
[
l
]
<<
SGRPROJ_RST_BITS
);
const
int32_t
f1
=
(
int32_t
)
flt1
[
k
]
-
u
;
const
int32_t
f2
=
(
int32_t
)
flt2
[
k
]
-
u
;
const
int64_t
v
=
xq
[
0
]
*
f1
+
xq
[
1
]
*
f2
+
(
u
<<
SGRPROJ_PRJ_BITS
);
const
int16_t
w
=
(
int16_t
)
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_PRJ_BITS
+
SGRPROJ_RST_BITS
);
d
a
t
[
l
]
=
w
;
d
s
t
[
m
]
=
clip_pixel
(
w
)
;
}
}
}
...
...
@@ -552,10 +553,9 @@ static void loop_sgrproj_filter_tile(uint8_t *data, int tile_idx, int width,
int
dst_stride
)
{
const
int
tile_width
=
rst
->
tile_width
>>
rst
->
subsampling_x
;
const
int
tile_height
=
rst
->
tile_height
>>
rst
->
subsampling_y
;
int
i
,
j
;
int
h_start
,
h_end
,
v_start
,
v_end
;
uint8_t
*
data_p
,
*
dst_p
;
int
64
_t
*
dat
=
(
int
64
_t
*
)
rst
->
tmpbuf
;
u
int
8
_t
*
dat
=
(
u
int
8
_t
*
)
rst
->
tmpbuf
;
uint8_t
*
tmpbuf
=
(
uint8_t
*
)
rst
->
tmpbuf
+
RESTORATION_TILEPELS_MAX
*
sizeof
(
*
dat
);
...
...
@@ -568,22 +568,11 @@ static void loop_sgrproj_filter_tile(uint8_t *data, int tile_idx, int width,
tile_width
,
tile_height
,
width
,
height
,
0
,
0
,
&
h_start
,
&
h_end
,
&
v_start
,
&
v_end
);
data_p
=
data
+
h_start
+
v_start
*
stride
;
for
(
i
=
0
;
i
<
(
v_end
-
v_start
);
++
i
)
{
for
(
j
=
0
;
j
<
(
h_end
-
h_start
);
++
j
)
{
dat
[
i
*
(
h_end
-
h_start
)
+
j
]
=
data_p
[
i
*
stride
+
j
];
}
}
apply_selfguided_restoration
(
dat
,
h_end
-
h_start
,
v_end
-
v_start
,
h_end
-
h_start
,
8
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
ep
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
xqd
,
tmpbuf
);
dst_p
=
dst
+
h_start
+
v_start
*
dst_stride
;
for
(
i
=
0
;
i
<
(
v_end
-
v_start
);
++
i
)
{
for
(
j
=
0
;
j
<
(
h_end
-
h_start
);
++
j
)
{
dst_p
[
i
*
dst_stride
+
j
]
=
clip_pixel
((
int
)
dat
[
i
*
(
h_end
-
h_start
)
+
j
]);
}
}
apply_selfguided_restoration
(
data_p
,
h_end
-
h_start
,
v_end
-
v_start
,
stride
,
8
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
ep
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
xqd
,
dst_p
,
dst_stride
,
tmpbuf
);
}
static
void
loop_sgrproj_filter
(
uint8_t
*
data
,
int
width
,
int
height
,
...
...
@@ -857,6 +846,44 @@ static void loop_wiener_filter_highbd(uint8_t *data8, int width, int height,
}
}
static
void
apply_selfguided_restoration_highbd
(
uint16_t
*
dat
,
int
width
,
int
height
,
int
stride
,
int
bit_depth
,
int
eps
,
int
*
xqd
,
uint16_t
*
dst
,
int
dst_stride
,
void
*
tmpbuf
)
{
int
xq
[
2
];
int32_t
*
flt1
=
(
int32_t
*
)
tmpbuf
;
int32_t
*
flt2
=
flt1
+
RESTORATION_TILEPELS_MAX
;
uint8_t
*
tmpbuf2
=
(
uint8_t
*
)(
flt2
+
RESTORATION_TILEPELS_MAX
);
int
i
,
j
;
for
(
i
=
0
;
i
<
height
;
++
i
)
{
for
(
j
=
0
;
j
<
width
;
++
j
)
{
assert
(
i
*
width
+
j
<
RESTORATION_TILEPELS_MAX
);
flt1
[
i
*
width
+
j
]
=
dat
[
i
*
stride
+
j
];
flt2
[
i
*
width
+
j
]
=
dat
[
i
*
stride
+
j
];
}
}
av1_selfguided_restoration
(
flt1
,
width
,
height
,
width
,
bit_depth
,
sgr_params
[
eps
].
r1
,
sgr_params
[
eps
].
e1
,
tmpbuf2
);
av1_selfguided_restoration
(
flt2
,
width
,
height
,
width
,
bit_depth
,
sgr_params
[
eps
].
r2
,
sgr_params
[
eps
].
e2
,
tmpbuf2
);
decode_xq
(
xqd
,
xq
);
for
(
i
=
0
;
i
<
height
;
++
i
)
{
for
(
j
=
0
;
j
<
width
;
++
j
)
{
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
stride
+
j
;
const
int
m
=
i
*
dst_stride
+
j
;
const
int32_t
u
=
((
int32_t
)
dat
[
l
]
<<
SGRPROJ_RST_BITS
);
const
int32_t
f1
=
(
int32_t
)
flt1
[
k
]
-
u
;
const
int32_t
f2
=
(
int32_t
)
flt2
[
k
]
-
u
;
const
int64_t
v
=
xq
[
0
]
*
f1
+
xq
[
1
]
*
f2
+
(
u
<<
SGRPROJ_PRJ_BITS
);
const
int16_t
w
=
(
int16_t
)
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_PRJ_BITS
+
SGRPROJ_RST_BITS
);
dst
[
m
]
=
(
uint16_t
)
clip_pixel_highbd
(
w
,
bit_depth
);
}
}
}
static
void
loop_sgrproj_filter_tile_highbd
(
uint16_t
*
data
,
int
tile_idx
,
int
width
,
int
height
,
int
stride
,
RestorationInternal
*
rst
,
...
...
@@ -864,10 +891,9 @@ static void loop_sgrproj_filter_tile_highbd(uint16_t *data, int tile_idx,
int
dst_stride
)
{
const
int
tile_width
=
rst
->
tile_width
>>
rst
->
subsampling_x
;
const
int
tile_height
=
rst
->
tile_height
>>
rst
->
subsampling_y
;
int
i
,
j
;
int
h_start
,
h_end
,
v_start
,
v_end
;
uint16_t
*
data_p
,
*
dst_p
;
int6
4
_t
*
dat
=
(
int6
4
_t
*
)
rst
->
tmpbuf
;
u
int
1
6_t
*
dat
=
(
u
int
1
6_t
*
)
rst
->
tmpbuf
;
uint8_t
*
tmpbuf
=
(
uint8_t
*
)
rst
->
tmpbuf
+
RESTORATION_TILEPELS_MAX
*
sizeof
(
*
dat
);
...
...
@@ -880,22 +906,11 @@ static void loop_sgrproj_filter_tile_highbd(uint16_t *data, int tile_idx,
tile_width
,
tile_height
,
width
,
height
,
0
,
0
,
&
h_start
,
&
h_end
,
&
v_start
,
&
v_end
);
data_p
=
data
+
h_start
+
v_start
*
stride
;
for
(
i
=
0
;
i
<
(
v_end
-
v_start
);
++
i
)
{
for
(
j
=
0
;
j
<
(
h_end
-
h_start
);
++
j
)
{
dat
[
i
*
(
h_end
-
h_start
)
+
j
]
=
data_p
[
i
*
stride
+
j
];
}
}
apply_selfguided_restoration
(
dat
,
h_end
-
h_start
,
v_end
-
v_start
,
h_end
-
h_start
,
bit_depth
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
ep
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
xqd
,
tmpbuf
);
dst_p
=
dst
+
h_start
+
v_start
*
dst_stride
;
for
(
i
=
0
;
i
<
(
v_end
-
v_start
);
++
i
)
{
for
(
j
=
0
;
j
<
(
h_end
-
h_start
);
++
j
)
{
dst_p
[
i
*
dst_stride
+
j
]
=
clip_pixel_highbd
((
int
)
dat
[
i
*
(
h_end
-
h_start
)
+
j
],
bit_depth
);
}
}
apply_selfguided_restoration_highbd
(
data_p
,
h_end
-
h_start
,
v_end
-
v_start
,
stride
,
bit_depth
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
ep
,
rst
->
rsi
->
sgrproj_info
[
tile_idx
].
xqd
,
dst_p
,
dst_stride
,
tmpbuf
);
}
static
void
loop_sgrproj_filter_highbd
(
uint8_t
*
data8
,
int
width
,
int
height
,
...
...
av1/common/restoration.h
View file @
519dbcf1
...
...
@@ -42,11 +42,10 @@ extern "C" {
#define DOMAINTXFMRF_TMPBUF_SIZE (RESTORATION_TILEPELS_MAX * sizeof(int32_t))
#define DOMAINTXFMRF_BITS (DOMAINTXFMRF_PARAMS_BITS)
// 6 highprecision
64-bit
buffers needed for the filter:
// 6 highprecision buffers needed for the filter:
// 1 for the degraded frame, 2 for the restored versions and
// 3 for each restoration operation
// TODO(debargha): Explore if we can use 32-bit buffers
#define SGRPROJ_TMPBUF_SIZE (RESTORATION_TILEPELS_MAX * 6 * sizeof(int64_t))
#define SGRPROJ_TMPBUF_SIZE (RESTORATION_TILEPELS_MAX * 6 * sizeof(int32_t))
#define SGRPROJ_PARAMS_BITS 3
#define SGRPROJ_PARAMS (1 << SGRPROJ_PARAMS_BITS)
...
...
@@ -211,7 +210,7 @@ int av1_alloc_restoration_struct(RestorationInfo *rst_info, int width,
int
height
);
void
av1_free_restoration_struct
(
RestorationInfo
*
rst_info
);
void
av1_selfguided_restoration
(
int
64
_t
*
dgd
,
int
width
,
int
height
,
int
stride
,
void
av1_selfguided_restoration
(
int
32
_t
*
dgd
,
int
width
,
int
height
,
int
stride
,
int
bit_depth
,
int
r
,
int
eps
,
void
*
tmpbuf
);
void
av1_domaintxfmrf_restoration
(
uint8_t
*
dgd
,
int
width
,
int
height
,
int
stride
,
int
param
,
uint8_t
*
dst
,
...
...
av1/encoder/encoder.c
View file @
519dbcf1
...
...
@@ -739,7 +739,7 @@ static void alloc_util_frame_buffers(AV1_COMP *cpi) {
aom_internal_error
(
&
cm
->
error
,
AOM_CODEC_MEM_ERROR
,
"Failed to allocate trial restored frame buffer"
);
cpi
->
extra_rstbuf
=
(
uint8_t
*
)
aom_realloc
(
cpi
->
extra_rstbuf
,
RESTORATION_TILEPELS_MAX
*
sizeof
(
int
64
_t
));
cpi
->
extra_rstbuf
,
RESTORATION_TILEPELS_MAX
*
sizeof
(
int
32
_t
));
if
(
!
cpi
->
extra_rstbuf
)
aom_internal_error
(
&
cm
->
error
,
AOM_CODEC_MEM_ERROR
,
"Failed to allocate extra rstbuf for restoration"
);
...
...
av1/encoder/pickrst.c
View file @
519dbcf1
...
...
@@ -121,10 +121,10 @@ static int64_t try_restoration_frame(const YV12_BUFFER_CONFIG *src,
return
filt_err
;
}
static
int64_t
get_pixel_proj_error
(
int
64
_t
*
src
,
int
width
,
int
height
,
int
src_stride
,
int
64
_t
*
dgd
,
int
dgd_stride
,
int
64
_t
*
flt1
,
int
flt1_stride
,
int
64
_t
*
flt2
,
static
int64_t
get_pixel_proj_error
(
int
32
_t
*
src
,
int
width
,
int
height
,
int
src_stride
,
int
32
_t
*
dgd
,
int
dgd_stride
,
int
32
_t
*
flt1
,
int
flt1_stride
,
int
32
_t
*
flt2
,
int
flt2_stride
,
int
*
xqd
)
{
int
i
,
j
;
int64_t
err
=
0
;
...
...
@@ -132,12 +132,12 @@ static int64_t get_pixel_proj_error(int64_t *src, int width, int height,
decode_xq
(
xqd
,
xq
);
for
(
i
=
0
;
i
<
height
;
++
i
)
{
for
(
j
=
0
;
j
<
width
;
++
j
)
{
const
int
64
_t
s
=
(
int
64
_t
)
src
[
i
*
src_stride
+
j
];
const
int
64
_t
u
=
(
int
64
_t
)
dgd
[
i
*
dgd_stride
+
j
];
const
int
64
_t
f1
=
(
int
64
_t
)
flt1
[
i
*
flt1_stride
+
j
]
-
u
;
const
int
64
_t
f2
=
(
int
64
_t
)
flt2
[
i
*
flt2_stride
+
j
]
-
u
;
const
int
32
_t
s
=
(
int
32
_t
)
src
[
i
*
src_stride
+
j
];
const
int
32
_t
u
=
(
int
32
_t
)
dgd
[
i
*
dgd_stride
+
j
];
const
int
32
_t
f1
=
(
int
32
_t
)
flt1
[
i
*
flt1_stride
+
j
]
-
u
;
const
int
32
_t
f2
=
(
int
32
_t
)
flt2
[
i
*
flt2_stride
+
j
]
-
u
;
const
int64_t
v
=
xq
[
0
]
*
f1
+
xq
[
1
]
*
f2
+
(
u
<<
SGRPROJ_PRJ_BITS
);
const
int
64
_t
e
=
const
int
32
_t
e
=
ROUND_POWER_OF_TWO
(
v
,
SGRPROJ_RST_BITS
+
SGRPROJ_PRJ_BITS
)
-
ROUND_POWER_OF_TWO
(
s
,
SGRPROJ_RST_BITS
);
err
+=
e
*
e
;
...
...
@@ -146,9 +146,9 @@ static int64_t get_pixel_proj_error(int64_t *src, int width, int height,
return
err
;
}
static
void
get_proj_subspace
(
int
64
_t
*
src
,
int
width
,
int
height
,
int
src_stride
,
int
64
_t
*
dgd
,
int
dgd_stride
,
int
64
_t
*
flt1
,
int
flt1_stride
,
int
64
_t
*
flt2
,
static
void
get_proj_subspace
(
int
32
_t
*
src
,
int
width
,
int
height
,
int
src_stride
,
int
32
_t
*
dgd
,
int
dgd_stride
,
int
32
_t
*
flt1
,
int
flt1_stride
,
int
32
_t
*
flt2
,
int
flt2_stride
,
int
*
xq
)
{
int
i
,
j
;
double
H
[
2
][
2
]
=
{
{
0
,
0
},
{
0
,
0
}
};
...
...
@@ -198,10 +198,10 @@ static void search_selfguided_restoration(uint8_t *dat8, int width, int height,
int
src_stride
,
int
bit_depth
,
int
*
eps
,
int
*
xqd
,
void
*
srcbuf
,
void
*
rstbuf
)
{
int
64
_t
*
srd
=
(
int
64
_t
*
)
srcbuf
;
int
64
_t
*
dgd
=
(
int
64
_t
*
)
rstbuf
;
int
64
_t
*
flt1
=
dgd
+
RESTORATION_TILEPELS_MAX
;
int
64
_t
*
flt2
=
flt1
+
RESTORATION_TILEPELS_MAX
;
int
32
_t
*
srd
=
(
int
32
_t
*
)
srcbuf
;
int
32
_t
*
dgd
=
(
int
32
_t
*
)
rstbuf
;
int
32
_t
*
flt1
=
dgd
+
RESTORATION_TILEPELS_MAX
;
int
32
_t
*
flt2
=
flt1
+
RESTORATION_TILEPELS_MAX
;
uint8_t
*
tmpbuf2
=
(
uint8_t
*
)(
flt2
+
RESTORATION_TILEPELS_MAX
);
int
i
,
j
,
ep
,
bestep
=
0
;
int64_t
err
,
besterr
=
-
1
;
...
...
@@ -213,11 +213,11 @@ static void search_selfguided_restoration(uint8_t *dat8, int width, int height,
uint16_t
*
dat
=
CONVERT_TO_SHORTPTR
(
dat8
);
for
(
i
=
0
;
i
<
height
;
++
i
)
{
for
(
j
=
0
;
j
<
width
;
++
j
)
{
flt1
[
i
*
width
+
j
]
=
(
int
64
_t
)
dat
[
i
*
dat_stride
+
j
];
flt2
[
i
*
width
+
j
]
=
(
int
64
_t
)
dat
[
i
*
dat_stride
+
j
];
dgd
[
i
*
width
+
j
]
=
(
int
64
_t
)
dat
[
i
*
dat_stride
+
j
]
flt1
[
i
*
width
+
j
]
=
(
int
32
_t
)
dat
[
i
*
dat_stride
+
j
];
flt2
[
i
*
width
+
j
]
=
(
int
32
_t
)
dat
[
i
*
dat_stride
+
j
];
dgd
[
i
*
width
+
j
]
=
(
int
32
_t
)
dat
[
i
*
dat_stride
+
j
]
<<
SGRPROJ_RST_BITS
;
srd
[
i
*
width
+
j
]
=
(
int
64
_t
)
src
[
i
*
src_stride
+
j
]
srd
[
i
*
width
+
j
]
=
(
int
32
_t
)
src
[
i
*
src_stride
+
j
]
<<
SGRPROJ_RST_BITS
;
}
}
...
...
@@ -228,10 +228,10 @@ static void search_selfguided_restoration(uint8_t *dat8, int width, int height,
for
(
j
=
0
;
j
<
width
;
++
j
)
{
const
int
k
=
i
*
width
+
j
;
const
int
l
=
i
*
dat_stride
+
j
;
flt1
[
k
]
=
(
int
64
_t
)
dat
[
l
];
flt2
[
k
]
=
(
int
64
_t
)
dat
[
l
];
dgd
[
k
]
=
(
int
64
_t
)
dat
[
l
]
<<
SGRPROJ_RST_BITS
;
srd
[
k
]
=
(
int
64
_t
)
src
[
i
*
src_stride
+
j
]
<<
SGRPROJ_RST_BITS
;
flt1
[
k
]
=
(
int
32
_t
)
dat
[
l
];
flt2
[
k
]
=
(
int
32
_t
)
dat
[
l
];
dgd
[
k
]
=
(
int
32
_t
)
dat
[
l
]
<<
SGRPROJ_RST_BITS
;
srd
[
k
]
=
(
int
32
_t
)
src
[
i
*
src_stride
+
j
]
<<
SGRPROJ_RST_BITS
;
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment