Skip to content

Latest commit

 

History

History
202 lines (176 loc) · 5.66 KB

filters_msa.c

File metadata and controls

202 lines (176 loc) · 5.66 KB
 
Nov 10, 2019
Nov 10, 2019
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
// MSA variant of alpha filters
//
// Author: Prashant Patil (prashant.patil@imgtec.com)
#include "src/dsp/dsp.h"
#if defined(WEBP_USE_MSA)
#include "src/dsp/msa_macro.h"
#include <assert.h>
static WEBP_INLINE void PredictLineInverse0(const uint8_t* src,
const uint8_t* pred,
uint8_t* dst, int length) {
v16u8 src0, pred0, dst0;
assert(length >= 0);
while (length >= 32) {
v16u8 src1, pred1, dst1;
LD_UB2(src, 16, src0, src1);
LD_UB2(pred, 16, pred0, pred1);
SUB2(src0, pred0, src1, pred1, dst0, dst1);
ST_UB2(dst0, dst1, dst, 16);
src += 32;
pred += 32;
dst += 32;
length -= 32;
}
if (length > 0) {
int i;
if (length >= 16) {
src0 = LD_UB(src);
pred0 = LD_UB(pred);
dst0 = src0 - pred0;
ST_UB(dst0, dst);
src += 16;
pred += 16;
dst += 16;
length -= 16;
}
for (i = 0; i < length; i++) {
dst[i] = src[i] - pred[i];
}
}
}
//------------------------------------------------------------------------------
// Helpful macro.
#define SANITY_CHECK(in, out) \
assert(in != NULL); \
assert(out != NULL); \
assert(width > 0); \
assert(height > 0); \
assert(stride >= width);
//------------------------------------------------------------------------------
// Horrizontal filter
static void HorizontalFilter_MSA(const uint8_t* data, int width, int height,
int stride, uint8_t* filtered_data) {
const uint8_t* preds = data;
const uint8_t* in = data;
uint8_t* out = filtered_data;
int row = 1;
SANITY_CHECK(in, out);
// Leftmost pixel is the same as input for topmost scanline.
out[0] = in[0];
PredictLineInverse0(in + 1, preds, out + 1, width - 1);
preds += stride;
in += stride;
out += stride;
// Filter line-by-line.
while (row < height) {
// Leftmost pixel is predicted from above.
PredictLineInverse0(in, preds - stride, out, 1);
PredictLineInverse0(in + 1, preds, out + 1, width - 1);
++row;
preds += stride;
in += stride;
out += stride;
}
}
//------------------------------------------------------------------------------
// Gradient filter
static WEBP_INLINE void PredictLineGradient(const uint8_t* pinput,
const uint8_t* ppred,
uint8_t* poutput, int stride,
int size) {
int w;
const v16i8 zero = { 0 };
while (size >= 16) {
v16u8 pred0, dst0;
v8i16 a0, a1, b0, b1, c0, c1;
const v16u8 tmp0 = LD_UB(ppred - 1);
const v16u8 tmp1 = LD_UB(ppred - stride);
const v16u8 tmp2 = LD_UB(ppred - stride - 1);
const v16u8 src0 = LD_UB(pinput);
ILVRL_B2_SH(zero, tmp0, a0, a1);
ILVRL_B2_SH(zero, tmp1, b0, b1);
ILVRL_B2_SH(zero, tmp2, c0, c1);
ADD2(a0, b0, a1, b1, a0, a1);
SUB2(a0, c0, a1, c1, a0, a1);
CLIP_SH2_0_255(a0, a1);
pred0 = (v16u8)__msa_pckev_b((v16i8)a1, (v16i8)a0);
dst0 = src0 - pred0;
ST_UB(dst0, poutput);
ppred += 16;
pinput += 16;
poutput += 16;
size -= 16;
}
for (w = 0; w < size; ++w) {
const int pred = ppred[w - 1] + ppred[w - stride] - ppred[w - stride - 1];
poutput[w] = pinput[w] - (pred < 0 ? 0 : pred > 255 ? 255 : pred);
}
}
static void GradientFilter_MSA(const uint8_t* data, int width, int height,
int stride, uint8_t* filtered_data) {
const uint8_t* in = data;
const uint8_t* preds = data;
uint8_t* out = filtered_data;
int row = 1;
SANITY_CHECK(in, out);
// left prediction for top scan-line
out[0] = in[0];
PredictLineInverse0(in + 1, preds, out + 1, width - 1);
preds += stride;
in += stride;
out += stride;
// Filter line-by-line.
while (row < height) {
out[0] = in[0] - preds[- stride];
PredictLineGradient(preds + 1, in + 1, out + 1, stride, width - 1);
++row;
preds += stride;
in += stride;
out += stride;
}
}
//------------------------------------------------------------------------------
// Vertical filter
static void VerticalFilter_MSA(const uint8_t* data, int width, int height,
int stride, uint8_t* filtered_data) {
const uint8_t* in = data;
const uint8_t* preds = data;
uint8_t* out = filtered_data;
int row = 1;
SANITY_CHECK(in, out);
// Very first top-left pixel is copied.
out[0] = in[0];
// Rest of top scan-line is left-predicted.
PredictLineInverse0(in + 1, preds, out + 1, width - 1);
in += stride;
out += stride;
// Filter line-by-line.
while (row < height) {
PredictLineInverse0(in, preds, out, width);
++row;
preds += stride;
in += stride;
out += stride;
}
}
#undef SANITY_CHECK
//------------------------------------------------------------------------------
// Entry point
extern void VP8FiltersInitMSA(void);
WEBP_TSAN_IGNORE_FUNCTION void VP8FiltersInitMSA(void) {
WebPFilters[WEBP_FILTER_HORIZONTAL] = HorizontalFilter_MSA;
WebPFilters[WEBP_FILTER_VERTICAL] = VerticalFilter_MSA;
WebPFilters[WEBP_FILTER_GRADIENT] = GradientFilter_MSA;
}
#else // !WEBP_USE_MSA
WEBP_DSP_INIT_STUB(VP8FiltersInitMSA)
#endif // WEBP_USE_MSA