Coverage Report

Created: 2026-01-13 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebp/src/dsp/dec.c
Line
Count
Source
1
// Copyright 2010 Google Inc. All Rights Reserved.
2
//
3
// Use of this source code is governed by a BSD-style license
4
// that can be found in the COPYING file in the root of the source
5
// tree. An additional intellectual property rights grant can be found
6
// in the file PATENTS. All contributing project authors may
7
// be found in the AUTHORS file in the root of the source tree.
8
// -----------------------------------------------------------------------------
9
//
10
// Speed-critical decoding functions, default plain-C implementations.
11
//
12
// Author: Skal (pascal.massimino@gmail.com)
13
14
#include <assert.h>
15
#include <stddef.h>
16
#include <string.h>
17
18
#include "src/dec/common_dec.h"
19
#include "src/dec/vp8i_dec.h"
20
#include "src/dsp/cpu.h"
21
#include "src/dsp/dsp.h"
22
#include "src/utils/utils.h"
23
#include "src/webp/types.h"
24
25
//------------------------------------------------------------------------------
26
27
11.1M
static WEBP_INLINE uint8_t clip_8b(int v) {
28
11.1M
  return (!(v & ~0xff)) ? v : (v < 0) ? 0 : 255;
29
11.1M
}
30
31
//------------------------------------------------------------------------------
32
// Transforms (Paragraph 14.4)
33
34
#define STORE(x, y, v) \
35
11.1M
  dst[(x) + (y) * BPS] = clip_8b(dst[(x) + (y) * BPS] + ((v) >> 3))
36
37
#define STORE2(y, dc, d, c) \
38
922k
  do {                      \
39
922k
    const int DC = (dc);    \
40
922k
    STORE(0, y, DC + (d));  \
41
922k
    STORE(1, y, DC + (c));  \
42
922k
    STORE(2, y, DC - (c));  \
43
922k
    STORE(3, y, DC - (d));  \
44
922k
  } while (0)
45
46
#if !WEBP_NEON_OMIT_C_CODE
47
static void TransformOne_C(const int16_t* WEBP_RESTRICT in,
48
0
                           uint8_t* WEBP_RESTRICT dst) {
49
0
  int C[4 * 4], *tmp;
50
0
  int i;
51
0
  tmp = C;
52
0
  for (i = 0; i < 4; ++i) {       // vertical pass
53
0
    const int a = in[0] + in[8];  // [-4096, 4094]
54
0
    const int b = in[0] - in[8];  // [-4095, 4095]
55
0
    const int c = WEBP_TRANSFORM_AC3_MUL2(in[4]) -
56
0
                  WEBP_TRANSFORM_AC3_MUL1(in[12]);  // [-3783, 3783]
57
0
    const int d = WEBP_TRANSFORM_AC3_MUL1(in[4]) +
58
0
                  WEBP_TRANSFORM_AC3_MUL2(in[12]);  // [-3785, 3781]
59
0
    tmp[0] = a + d;                                 // [-7881, 7875]
60
0
    tmp[1] = b + c;                                 // [-7878, 7878]
61
0
    tmp[2] = b - c;                                 // [-7878, 7878]
62
0
    tmp[3] = a - d;                                 // [-7877, 7879]
63
0
    tmp += 4;
64
0
    in++;
65
0
  }
66
  // Each pass is expanding the dynamic range by ~3.85 (upper bound).
67
  // The exact value is (2. + (20091 + 35468) / 65536).
68
  // After the second pass, maximum interval is [-3794, 3794], assuming
69
  // an input in [-2048, 2047] interval. We then need to add a dst value
70
  // in the [0, 255] range.
71
  // In the worst case scenario, the input to clip_8b() can be as large as
72
  // [-60713, 60968].
73
0
  tmp = C;
74
0
  for (i = 0; i < 4; ++i) {  // horizontal pass
75
0
    const int dc = tmp[0] + 4;
76
0
    const int a = dc + tmp[8];
77
0
    const int b = dc - tmp[8];
78
0
    const int c =
79
0
        WEBP_TRANSFORM_AC3_MUL2(tmp[4]) - WEBP_TRANSFORM_AC3_MUL1(tmp[12]);
80
0
    const int d =
81
0
        WEBP_TRANSFORM_AC3_MUL1(tmp[4]) + WEBP_TRANSFORM_AC3_MUL2(tmp[12]);
82
0
    STORE(0, 0, a + d);
83
0
    STORE(1, 0, b + c);
84
0
    STORE(2, 0, b - c);
85
0
    STORE(3, 0, a - d);
86
0
    tmp++;
87
0
    dst += BPS;
88
0
  }
89
0
}
90
91
// Simplified transform when only in[0], in[1] and in[4] are non-zero
92
static void TransformAC3_C(const int16_t* WEBP_RESTRICT in,
93
230k
                           uint8_t* WEBP_RESTRICT dst) {
94
230k
  const int a = in[0] + 4;
95
230k
  const int c4 = WEBP_TRANSFORM_AC3_MUL2(in[4]);
96
230k
  const int d4 = WEBP_TRANSFORM_AC3_MUL1(in[4]);
97
230k
  const int c1 = WEBP_TRANSFORM_AC3_MUL2(in[1]);
98
230k
  const int d1 = WEBP_TRANSFORM_AC3_MUL1(in[1]);
99
230k
  STORE2(0, a + d4, d1, c1);
100
230k
  STORE2(1, a + c4, d1, c1);
101
230k
  STORE2(2, a - c4, d1, c1);
102
230k
  STORE2(3, a - d4, d1, c1);
103
230k
}
104
#undef STORE2
105
106
static void TransformTwo_C(const int16_t* WEBP_RESTRICT in,
107
0
                           uint8_t* WEBP_RESTRICT dst, int do_two) {
108
0
  TransformOne_C(in, dst);
109
0
  if (do_two) {
110
0
    TransformOne_C(in + 16, dst + 4);
111
0
  }
112
0
}
113
#endif  // !WEBP_NEON_OMIT_C_CODE
114
115
static void TransformUV_C(const int16_t* WEBP_RESTRICT in,
116
62.6k
                          uint8_t* WEBP_RESTRICT dst) {
117
62.6k
  VP8Transform(in + 0 * 16, dst, 1);
118
62.6k
  VP8Transform(in + 2 * 16, dst + 4 * BPS, 1);
119
62.6k
}
120
121
#if !WEBP_NEON_OMIT_C_CODE
122
static void TransformDC_C(const int16_t* WEBP_RESTRICT in,
123
464k
                          uint8_t* WEBP_RESTRICT dst) {
124
464k
  const int DC = in[0] + 4;
125
464k
  int i, j;
126
2.32M
  for (j = 0; j < 4; ++j) {
127
9.29M
    for (i = 0; i < 4; ++i) {
128
7.43M
      STORE(i, j, DC);
129
7.43M
    }
130
1.85M
  }
131
464k
}
132
#endif  // !WEBP_NEON_OMIT_C_CODE
133
134
static void TransformDCUV_C(const int16_t* WEBP_RESTRICT in,
135
42.5k
                            uint8_t* WEBP_RESTRICT dst) {
136
42.5k
  if (in[0 * 16]) VP8TransformDC(in + 0 * 16, dst);
137
42.5k
  if (in[1 * 16]) VP8TransformDC(in + 1 * 16, dst + 4);
138
42.5k
  if (in[2 * 16]) VP8TransformDC(in + 2 * 16, dst + 4 * BPS);
139
42.5k
  if (in[3 * 16]) VP8TransformDC(in + 3 * 16, dst + 4 * BPS + 4);
140
42.5k
}
141
142
#undef STORE
143
144
//------------------------------------------------------------------------------
145
// Paragraph 14.3
146
147
#if !WEBP_NEON_OMIT_C_CODE
148
static void TransformWHT_C(const int16_t* WEBP_RESTRICT in,
149
5.27k
                           int16_t* WEBP_RESTRICT out) {
150
5.27k
  int tmp[16];
151
5.27k
  int i;
152
26.3k
  for (i = 0; i < 4; ++i) {
153
21.1k
    const int a0 = in[0 + i] + in[12 + i];
154
21.1k
    const int a1 = in[4 + i] + in[8 + i];
155
21.1k
    const int a2 = in[4 + i] - in[8 + i];
156
21.1k
    const int a3 = in[0 + i] - in[12 + i];
157
21.1k
    tmp[0 + i] = a0 + a1;
158
21.1k
    tmp[8 + i] = a0 - a1;
159
21.1k
    tmp[4 + i] = a3 + a2;
160
21.1k
    tmp[12 + i] = a3 - a2;
161
21.1k
  }
162
26.3k
  for (i = 0; i < 4; ++i) {
163
21.1k
    const int dc = tmp[0 + i * 4] + 3;  // w/ rounder
164
21.1k
    const int a0 = dc + tmp[3 + i * 4];
165
21.1k
    const int a1 = tmp[1 + i * 4] + tmp[2 + i * 4];
166
21.1k
    const int a2 = tmp[1 + i * 4] - tmp[2 + i * 4];
167
21.1k
    const int a3 = dc - tmp[3 + i * 4];
168
21.1k
    out[0] = (a0 + a1) >> 3;
169
21.1k
    out[16] = (a3 + a2) >> 3;
170
21.1k
    out[32] = (a0 - a1) >> 3;
171
21.1k
    out[48] = (a3 - a2) >> 3;
172
21.1k
    out += 64;
173
21.1k
  }
174
5.27k
}
175
#endif  // !WEBP_NEON_OMIT_C_CODE
176
177
VP8WHT VP8TransformWHT;
178
179
//------------------------------------------------------------------------------
180
// Intra predictions
181
182
342k
#define DST(x, y) dst[(x) + (y) * BPS]
183
184
#if !WEBP_NEON_OMIT_C_CODE
185
0
static WEBP_INLINE void TrueMotion(uint8_t* dst, int size) {
186
0
  const uint8_t* top = dst - BPS;
187
0
  const uint8_t* const clip0 = VP8kclip1 - top[-1];
188
0
  int y;
189
0
  for (y = 0; y < size; ++y) {
190
0
    const uint8_t* const clip = clip0 + dst[-1];
191
0
    int x;
192
0
    for (x = 0; x < size; ++x) {
193
0
      dst[x] = clip[top[x]];
194
0
    }
195
0
    dst += BPS;
196
0
  }
197
0
}
198
0
static void TM4_C(uint8_t* dst) { TrueMotion(dst, 4); }
199
0
static void TM8uv_C(uint8_t* dst) { TrueMotion(dst, 8); }
200
0
static void TM16_C(uint8_t* dst) { TrueMotion(dst, 16); }
201
202
//------------------------------------------------------------------------------
203
// 16x16
204
205
0
static void VE16_C(uint8_t* dst) {  // vertical
206
0
  int j;
207
0
  for (j = 0; j < 16; ++j) {
208
0
    memcpy(dst + j * BPS, dst - BPS, 16);
209
0
  }
210
0
}
211
212
0
static void HE16_C(uint8_t* dst) {  // horizontal
213
0
  int j;
214
0
  for (j = 16; j > 0; --j) {
215
0
    memset(dst, dst[-1], 16);
216
0
    dst += BPS;
217
0
  }
218
0
}
219
220
0
static WEBP_INLINE void Put16(int v, uint8_t* dst) {
221
0
  int j;
222
0
  for (j = 0; j < 16; ++j) {
223
0
    memset(dst + j * BPS, v, 16);
224
0
  }
225
0
}
226
227
0
static void DC16_C(uint8_t* dst) {  // DC
228
0
  int DC = 16;
229
0
  int j;
230
0
  for (j = 0; j < 16; ++j) {
231
0
    DC += dst[-1 + j * BPS] + dst[j - BPS];
232
0
  }
233
0
  Put16(DC >> 5, dst);
234
0
}
235
236
0
static void DC16NoTop_C(uint8_t* dst) {  // DC with top samples not available
237
0
  int DC = 8;
238
0
  int j;
239
0
  for (j = 0; j < 16; ++j) {
240
0
    DC += dst[-1 + j * BPS];
241
0
  }
242
0
  Put16(DC >> 4, dst);
243
0
}
244
245
0
static void DC16NoLeft_C(uint8_t* dst) {  // DC with left samples not available
246
0
  int DC = 8;
247
0
  int i;
248
0
  for (i = 0; i < 16; ++i) {
249
0
    DC += dst[i - BPS];
250
0
  }
251
0
  Put16(DC >> 4, dst);
252
0
}
253
254
0
static void DC16NoTopLeft_C(uint8_t* dst) {  // DC with no top and left samples
255
0
  Put16(0x80, dst);
256
0
}
257
#endif  // !WEBP_NEON_OMIT_C_CODE
258
259
VP8PredFunc VP8PredLuma16[NUM_B_DC_MODES];
260
261
//------------------------------------------------------------------------------
262
// 4x4
263
264
161k
#define AVG3(a, b, c) ((uint8_t)(((a) + 2 * (b) + (c) + 2) >> 2))
265
72.3k
#define AVG2(a, b) (((a) + (b) + 1) >> 1)
266
267
#if !WEBP_NEON_OMIT_C_CODE
268
0
static void VE4_C(uint8_t* dst) {  // vertical
269
0
  const uint8_t* top = dst - BPS;
270
0
  const uint8_t vals[4] = {
271
0
      AVG3(top[-1], top[0], top[1]),
272
0
      AVG3(top[0], top[1], top[2]),
273
0
      AVG3(top[1], top[2], top[3]),
274
0
      AVG3(top[2], top[3], top[4]),
275
0
  };
276
0
  int i;
277
0
  for (i = 0; i < 4; ++i) {
278
0
    memcpy(dst + i * BPS, vals, sizeof(vals));
279
0
  }
280
0
}
281
#endif  // !WEBP_NEON_OMIT_C_CODE
282
283
18.2k
static void HE4_C(uint8_t* dst) {  // horizontal
284
18.2k
  const int A = dst[-1 - BPS];
285
18.2k
  const int B = dst[-1];
286
18.2k
  const int C = dst[-1 + BPS];
287
18.2k
  const int D = dst[-1 + 2 * BPS];
288
18.2k
  const int E = dst[-1 + 3 * BPS];
289
18.2k
  WebPUint32ToMem(dst + 0 * BPS, 0x01010101U * AVG3(A, B, C));
290
18.2k
  WebPUint32ToMem(dst + 1 * BPS, 0x01010101U * AVG3(B, C, D));
291
18.2k
  WebPUint32ToMem(dst + 2 * BPS, 0x01010101U * AVG3(C, D, E));
292
18.2k
  WebPUint32ToMem(dst + 3 * BPS, 0x01010101U * AVG3(D, E, E));
293
18.2k
}
294
295
#if !WEBP_NEON_OMIT_C_CODE
296
2.78M
static void DC4_C(uint8_t* dst) {  // DC
297
2.78M
  uint32_t dc = 4;
298
2.78M
  int i;
299
13.9M
  for (i = 0; i < 4; ++i) dc += dst[i - BPS] + dst[-1 + i * BPS];
300
2.78M
  dc >>= 3;
301
13.9M
  for (i = 0; i < 4; ++i) memset(dst + i * BPS, dc, 4);
302
2.78M
}
303
304
0
static void RD4_C(uint8_t* dst) {  // Down-right
305
0
  const int I = dst[-1 + 0 * BPS];
306
0
  const int J = dst[-1 + 1 * BPS];
307
0
  const int K = dst[-1 + 2 * BPS];
308
0
  const int L = dst[-1 + 3 * BPS];
309
0
  const int X = dst[-1 - BPS];
310
0
  const int A = dst[0 - BPS];
311
0
  const int B = dst[1 - BPS];
312
0
  const int C = dst[2 - BPS];
313
0
  const int D = dst[3 - BPS];
314
0
  DST(0, 3) = AVG3(J, K, L);
315
0
  DST(1, 3) = DST(0, 2) = AVG3(I, J, K);
316
0
  DST(2, 3) = DST(1, 2) = DST(0, 1) = AVG3(X, I, J);
317
0
  DST(3, 3) = DST(2, 2) = DST(1, 1) = DST(0, 0) = AVG3(A, X, I);
318
0
  DST(3, 2) = DST(2, 1) = DST(1, 0) = AVG3(B, A, X);
319
0
  DST(3, 1) = DST(2, 0) = AVG3(C, B, A);
320
0
  DST(3, 0) = AVG3(D, C, B);
321
0
}
322
323
0
static void LD4_C(uint8_t* dst) {  // Down-Left
324
0
  const int A = dst[0 - BPS];
325
0
  const int B = dst[1 - BPS];
326
0
  const int C = dst[2 - BPS];
327
0
  const int D = dst[3 - BPS];
328
0
  const int E = dst[4 - BPS];
329
0
  const int F = dst[5 - BPS];
330
0
  const int G = dst[6 - BPS];
331
0
  const int H = dst[7 - BPS];
332
0
  DST(0, 0) = AVG3(A, B, C);
333
0
  DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
334
0
  DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
335
0
  DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
336
0
  DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
337
0
  DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
338
0
  DST(3, 3) = AVG3(G, H, H);
339
0
}
340
#endif  // !WEBP_NEON_OMIT_C_CODE
341
342
0
static void VR4_C(uint8_t* dst) {  // Vertical-Right
343
0
  const int I = dst[-1 + 0 * BPS];
344
0
  const int J = dst[-1 + 1 * BPS];
345
0
  const int K = dst[-1 + 2 * BPS];
346
0
  const int X = dst[-1 - BPS];
347
0
  const int A = dst[0 - BPS];
348
0
  const int B = dst[1 - BPS];
349
0
  const int C = dst[2 - BPS];
350
0
  const int D = dst[3 - BPS];
351
0
  DST(0, 0) = DST(1, 2) = AVG2(X, A);
352
0
  DST(1, 0) = DST(2, 2) = AVG2(A, B);
353
0
  DST(2, 0) = DST(3, 2) = AVG2(B, C);
354
0
  DST(3, 0) = AVG2(C, D);
355
356
0
  DST(0, 3) = AVG3(K, J, I);
357
0
  DST(0, 2) = AVG3(J, I, X);
358
0
  DST(0, 1) = DST(1, 3) = AVG3(I, X, A);
359
0
  DST(1, 1) = DST(2, 3) = AVG3(X, A, B);
360
0
  DST(2, 1) = DST(3, 3) = AVG3(A, B, C);
361
0
  DST(3, 1) = AVG3(B, C, D);
362
0
}
363
364
0
static void VL4_C(uint8_t* dst) {  // Vertical-Left
365
0
  const int A = dst[0 - BPS];
366
0
  const int B = dst[1 - BPS];
367
0
  const int C = dst[2 - BPS];
368
0
  const int D = dst[3 - BPS];
369
0
  const int E = dst[4 - BPS];
370
0
  const int F = dst[5 - BPS];
371
0
  const int G = dst[6 - BPS];
372
0
  const int H = dst[7 - BPS];
373
0
  DST(0, 0) = AVG2(A, B);
374
0
  DST(1, 0) = DST(0, 2) = AVG2(B, C);
375
0
  DST(2, 0) = DST(1, 2) = AVG2(C, D);
376
0
  DST(3, 0) = DST(2, 2) = AVG2(D, E);
377
378
0
  DST(0, 1) = AVG3(A, B, C);
379
0
  DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
380
0
  DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
381
0
  DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
382
0
  DST(3, 2) = AVG3(E, F, G);
383
0
  DST(3, 3) = AVG3(F, G, H);
384
0
}
385
386
13.2k
static void HU4_C(uint8_t* dst) {  // Horizontal-Up
387
13.2k
  const int I = dst[-1 + 0 * BPS];
388
13.2k
  const int J = dst[-1 + 1 * BPS];
389
13.2k
  const int K = dst[-1 + 2 * BPS];
390
13.2k
  const int L = dst[-1 + 3 * BPS];
391
13.2k
  DST(0, 0) = AVG2(I, J);
392
13.2k
  DST(2, 0) = DST(0, 1) = AVG2(J, K);
393
13.2k
  DST(2, 1) = DST(0, 2) = AVG2(K, L);
394
13.2k
  DST(1, 0) = AVG3(I, J, K);
395
13.2k
  DST(3, 0) = DST(1, 1) = AVG3(J, K, L);
396
13.2k
  DST(3, 1) = DST(1, 2) = AVG3(K, L, L);
397
13.2k
  DST(3, 2) = DST(2, 2) = DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L;
398
13.2k
}
399
400
8.16k
static void HD4_C(uint8_t* dst) {  // Horizontal-Down
401
8.16k
  const int I = dst[-1 + 0 * BPS];
402
8.16k
  const int J = dst[-1 + 1 * BPS];
403
8.16k
  const int K = dst[-1 + 2 * BPS];
404
8.16k
  const int L = dst[-1 + 3 * BPS];
405
8.16k
  const int X = dst[-1 - BPS];
406
8.16k
  const int A = dst[0 - BPS];
407
8.16k
  const int B = dst[1 - BPS];
408
8.16k
  const int C = dst[2 - BPS];
409
410
8.16k
  DST(0, 0) = DST(2, 1) = AVG2(I, X);
411
8.16k
  DST(0, 1) = DST(2, 2) = AVG2(J, I);
412
8.16k
  DST(0, 2) = DST(2, 3) = AVG2(K, J);
413
8.16k
  DST(0, 3) = AVG2(L, K);
414
415
8.16k
  DST(3, 0) = AVG3(A, B, C);
416
8.16k
  DST(2, 0) = AVG3(X, A, B);
417
8.16k
  DST(1, 0) = DST(3, 1) = AVG3(I, X, A);
418
8.16k
  DST(1, 1) = DST(3, 2) = AVG3(J, I, X);
419
8.16k
  DST(1, 2) = DST(3, 3) = AVG3(K, J, I);
420
8.16k
  DST(1, 3) = AVG3(L, K, J);
421
8.16k
}
422
423
#undef DST
424
#undef AVG3
425
#undef AVG2
426
427
VP8PredFunc VP8PredLuma4[NUM_BMODES];
428
429
//------------------------------------------------------------------------------
430
// Chroma
431
432
#if !WEBP_NEON_OMIT_C_CODE
433
0
static void VE8uv_C(uint8_t* dst) {  // vertical
434
0
  int j;
435
0
  for (j = 0; j < 8; ++j) {
436
0
    memcpy(dst + j * BPS, dst - BPS, 8);
437
0
  }
438
0
}
439
440
21.2k
static void HE8uv_C(uint8_t* dst) {  // horizontal
441
21.2k
  int j;
442
191k
  for (j = 0; j < 8; ++j) {
443
170k
    memset(dst, dst[-1], 8);
444
170k
    dst += BPS;
445
170k
  }
446
21.2k
}
447
448
// helper for chroma-DC predictions
449
0
static WEBP_INLINE void Put8x8uv(uint8_t value, uint8_t* dst) {
450
0
  int j;
451
0
  for (j = 0; j < 8; ++j) {
452
0
    memset(dst + j * BPS, value, 8);
453
0
  }
454
0
}
455
456
0
static void DC8uv_C(uint8_t* dst) {  // DC
457
0
  int dc0 = 8;
458
0
  int i;
459
0
  for (i = 0; i < 8; ++i) {
460
0
    dc0 += dst[i - BPS] + dst[-1 + i * BPS];
461
0
  }
462
0
  Put8x8uv(dc0 >> 4, dst);
463
0
}
464
465
0
static void DC8uvNoLeft_C(uint8_t* dst) {  // DC with no left samples
466
0
  int dc0 = 4;
467
0
  int i;
468
0
  for (i = 0; i < 8; ++i) {
469
0
    dc0 += dst[i - BPS];
470
0
  }
471
0
  Put8x8uv(dc0 >> 3, dst);
472
0
}
473
474
0
static void DC8uvNoTop_C(uint8_t* dst) {  // DC with no top samples
475
0
  int dc0 = 4;
476
0
  int i;
477
0
  for (i = 0; i < 8; ++i) {
478
0
    dc0 += dst[-1 + i * BPS];
479
0
  }
480
0
  Put8x8uv(dc0 >> 3, dst);
481
0
}
482
483
0
static void DC8uvNoTopLeft_C(uint8_t* dst) {  // DC with nothing
484
0
  Put8x8uv(0x80, dst);
485
0
}
486
#endif  // !WEBP_NEON_OMIT_C_CODE
487
488
VP8PredFunc VP8PredChroma8[NUM_B_DC_MODES];
489
490
//------------------------------------------------------------------------------
491
// Edge filtering functions
492
493
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
494
// 4 pixels in, 2 pixels out
495
0
static WEBP_INLINE void DoFilter2_C(uint8_t* p, int step) {
496
0
  const int p1 = p[-2 * step], p0 = p[-step], q0 = p[0], q1 = p[step];
497
0
  const int a = 3 * (q0 - p0) + VP8ksclip1[p1 - q1];  // in [-893,892]
498
0
  const int a1 = VP8ksclip2[(a + 4) >> 3];            // in [-16,15]
499
0
  const int a2 = VP8ksclip2[(a + 3) >> 3];
500
0
  p[-step] = VP8kclip1[p0 + a2];
501
0
  p[0] = VP8kclip1[q0 - a1];
502
0
}
503
504
// 4 pixels in, 4 pixels out
505
0
static WEBP_INLINE void DoFilter4_C(uint8_t* p, int step) {
506
0
  const int p1 = p[-2 * step], p0 = p[-step], q0 = p[0], q1 = p[step];
507
0
  const int a = 3 * (q0 - p0);
508
0
  const int a1 = VP8ksclip2[(a + 4) >> 3];
509
0
  const int a2 = VP8ksclip2[(a + 3) >> 3];
510
0
  const int a3 = (a1 + 1) >> 1;
511
0
  p[-2 * step] = VP8kclip1[p1 + a3];
512
0
  p[-step] = VP8kclip1[p0 + a2];
513
0
  p[0] = VP8kclip1[q0 - a1];
514
0
  p[step] = VP8kclip1[q1 - a3];
515
0
}
516
517
// 6 pixels in, 6 pixels out
518
0
static WEBP_INLINE void DoFilter6_C(uint8_t* p, int step) {
519
0
  const int p2 = p[-3 * step], p1 = p[-2 * step], p0 = p[-step];
520
0
  const int q0 = p[0], q1 = p[step], q2 = p[2 * step];
521
0
  const int a = VP8ksclip1[3 * (q0 - p0) + VP8ksclip1[p1 - q1]];
522
  // a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
523
0
  const int a1 = (27 * a + 63) >> 7;  // eq. to ((3 * a + 7) * 9) >> 7
524
0
  const int a2 = (18 * a + 63) >> 7;  // eq. to ((2 * a + 7) * 9) >> 7
525
0
  const int a3 = (9 * a + 63) >> 7;   // eq. to ((1 * a + 7) * 9) >> 7
526
0
  p[-3 * step] = VP8kclip1[p2 + a3];
527
0
  p[-2 * step] = VP8kclip1[p1 + a2];
528
0
  p[-step] = VP8kclip1[p0 + a1];
529
0
  p[0] = VP8kclip1[q0 - a1];
530
0
  p[step] = VP8kclip1[q1 - a2];
531
0
  p[2 * step] = VP8kclip1[q2 - a3];
532
0
}
533
534
0
static WEBP_INLINE int Hev(const uint8_t* p, int step, int thresh) {
535
0
  const int p1 = p[-2 * step], p0 = p[-step], q0 = p[0], q1 = p[step];
536
0
  return (VP8kabs0[p1 - p0] > thresh) || (VP8kabs0[q1 - q0] > thresh);
537
0
}
538
#endif  // !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
539
540
#if !WEBP_NEON_OMIT_C_CODE
541
0
static WEBP_INLINE int NeedsFilter_C(const uint8_t* p, int step, int t) {
542
0
  const int p1 = p[-2 * step], p0 = p[-step], q0 = p[0], q1 = p[step];
543
0
  return ((4 * VP8kabs0[p0 - q0] + VP8kabs0[p1 - q1]) <= t);
544
0
}
545
#endif  // !WEBP_NEON_OMIT_C_CODE
546
547
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
548
static WEBP_INLINE int NeedsFilter2_C(const uint8_t* p, int step, int t,
549
0
                                      int it) {
550
0
  const int p3 = p[-4 * step], p2 = p[-3 * step], p1 = p[-2 * step];
551
0
  const int p0 = p[-step], q0 = p[0];
552
0
  const int q1 = p[step], q2 = p[2 * step], q3 = p[3 * step];
553
0
  if ((4 * VP8kabs0[p0 - q0] + VP8kabs0[p1 - q1]) > t) return 0;
554
0
  return VP8kabs0[p3 - p2] <= it && VP8kabs0[p2 - p1] <= it &&
555
0
         VP8kabs0[p1 - p0] <= it && VP8kabs0[q3 - q2] <= it &&
556
0
         VP8kabs0[q2 - q1] <= it && VP8kabs0[q1 - q0] <= it;
557
0
}
558
#endif  // !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
559
560
//------------------------------------------------------------------------------
561
// Simple In-loop filtering (Paragraph 15.2)
562
563
#if !WEBP_NEON_OMIT_C_CODE
564
0
static void SimpleVFilter16_C(uint8_t* p, int stride, int thresh) {
565
0
  int i;
566
0
  const int thresh2 = 2 * thresh + 1;
567
0
  for (i = 0; i < 16; ++i) {
568
0
    if (NeedsFilter_C(p + i, stride, thresh2)) {
569
0
      DoFilter2_C(p + i, stride);
570
0
    }
571
0
  }
572
0
}
573
574
0
static void SimpleHFilter16_C(uint8_t* p, int stride, int thresh) {
575
0
  int i;
576
0
  const int thresh2 = 2 * thresh + 1;
577
0
  for (i = 0; i < 16; ++i) {
578
0
    if (NeedsFilter_C(p + i * stride, 1, thresh2)) {
579
0
      DoFilter2_C(p + i * stride, 1);
580
0
    }
581
0
  }
582
0
}
583
584
0
static void SimpleVFilter16i_C(uint8_t* p, int stride, int thresh) {
585
0
  int k;
586
0
  for (k = 3; k > 0; --k) {
587
0
    p += 4 * stride;
588
0
    SimpleVFilter16_C(p, stride, thresh);
589
0
  }
590
0
}
591
592
0
static void SimpleHFilter16i_C(uint8_t* p, int stride, int thresh) {
593
0
  int k;
594
0
  for (k = 3; k > 0; --k) {
595
0
    p += 4;
596
0
    SimpleHFilter16_C(p, stride, thresh);
597
0
  }
598
0
}
599
#endif  // !WEBP_NEON_OMIT_C_CODE
600
601
//------------------------------------------------------------------------------
602
// Complex In-loop filtering (Paragraph 15.3)
603
604
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
605
static WEBP_INLINE void FilterLoop26_C(uint8_t* p, int hstride, int vstride,
606
                                       int size, int thresh, int ithresh,
607
0
                                       int hev_thresh) {
608
0
  const int thresh2 = 2 * thresh + 1;
609
0
  while (size-- > 0) {
610
0
    if (NeedsFilter2_C(p, hstride, thresh2, ithresh)) {
611
0
      if (Hev(p, hstride, hev_thresh)) {
612
0
        DoFilter2_C(p, hstride);
613
0
      } else {
614
0
        DoFilter6_C(p, hstride);
615
0
      }
616
0
    }
617
0
    p += vstride;
618
0
  }
619
0
}
620
621
static WEBP_INLINE void FilterLoop24_C(uint8_t* p, int hstride, int vstride,
622
                                       int size, int thresh, int ithresh,
623
0
                                       int hev_thresh) {
624
0
  const int thresh2 = 2 * thresh + 1;
625
0
  while (size-- > 0) {
626
0
    if (NeedsFilter2_C(p, hstride, thresh2, ithresh)) {
627
0
      if (Hev(p, hstride, hev_thresh)) {
628
0
        DoFilter2_C(p, hstride);
629
0
      } else {
630
0
        DoFilter4_C(p, hstride);
631
0
      }
632
0
    }
633
0
    p += vstride;
634
0
  }
635
0
}
636
#endif  // !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
637
638
#if !WEBP_NEON_OMIT_C_CODE
639
// on macroblock edges
640
static void VFilter16_C(uint8_t* p, int stride, int thresh, int ithresh,
641
0
                        int hev_thresh) {
642
0
  FilterLoop26_C(p, stride, 1, 16, thresh, ithresh, hev_thresh);
643
0
}
644
645
static void HFilter16_C(uint8_t* p, int stride, int thresh, int ithresh,
646
0
                        int hev_thresh) {
647
0
  FilterLoop26_C(p, 1, stride, 16, thresh, ithresh, hev_thresh);
648
0
}
649
650
// on three inner edges
651
static void VFilter16i_C(uint8_t* p, int stride, int thresh, int ithresh,
652
0
                         int hev_thresh) {
653
0
  int k;
654
0
  for (k = 3; k > 0; --k) {
655
0
    p += 4 * stride;
656
0
    FilterLoop24_C(p, stride, 1, 16, thresh, ithresh, hev_thresh);
657
0
  }
658
0
}
659
#endif  // !WEBP_NEON_OMIT_C_CODE
660
661
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
662
static void HFilter16i_C(uint8_t* p, int stride, int thresh, int ithresh,
663
0
                         int hev_thresh) {
664
0
  int k;
665
0
  for (k = 3; k > 0; --k) {
666
0
    p += 4;
667
0
    FilterLoop24_C(p, 1, stride, 16, thresh, ithresh, hev_thresh);
668
0
  }
669
0
}
670
#endif  // !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
671
672
#if !WEBP_NEON_OMIT_C_CODE
673
// 8-pixels wide variant, for chroma filtering
674
static void VFilter8_C(uint8_t* WEBP_RESTRICT u, uint8_t* WEBP_RESTRICT v,
675
0
                       int stride, int thresh, int ithresh, int hev_thresh) {
676
0
  FilterLoop26_C(u, stride, 1, 8, thresh, ithresh, hev_thresh);
677
0
  FilterLoop26_C(v, stride, 1, 8, thresh, ithresh, hev_thresh);
678
0
}
679
#endif  // !WEBP_NEON_OMIT_C_CODE
680
681
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
682
static void HFilter8_C(uint8_t* WEBP_RESTRICT u, uint8_t* WEBP_RESTRICT v,
683
0
                       int stride, int thresh, int ithresh, int hev_thresh) {
684
0
  FilterLoop26_C(u, 1, stride, 8, thresh, ithresh, hev_thresh);
685
0
  FilterLoop26_C(v, 1, stride, 8, thresh, ithresh, hev_thresh);
686
0
}
687
#endif  // !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
688
689
#if !WEBP_NEON_OMIT_C_CODE
690
static void VFilter8i_C(uint8_t* WEBP_RESTRICT u, uint8_t* WEBP_RESTRICT v,
691
0
                        int stride, int thresh, int ithresh, int hev_thresh) {
692
0
  FilterLoop24_C(u + 4 * stride, stride, 1, 8, thresh, ithresh, hev_thresh);
693
0
  FilterLoop24_C(v + 4 * stride, stride, 1, 8, thresh, ithresh, hev_thresh);
694
0
}
695
#endif  // !WEBP_NEON_OMIT_C_CODE
696
697
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
698
static void HFilter8i_C(uint8_t* WEBP_RESTRICT u, uint8_t* WEBP_RESTRICT v,
699
0
                        int stride, int thresh, int ithresh, int hev_thresh) {
700
0
  FilterLoop24_C(u + 4, 1, stride, 8, thresh, ithresh, hev_thresh);
701
0
  FilterLoop24_C(v + 4, 1, stride, 8, thresh, ithresh, hev_thresh);
702
0
}
703
#endif  // !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
704
705
//------------------------------------------------------------------------------
706
707
static void DitherCombine8x8_C(const uint8_t* WEBP_RESTRICT dither,
708
0
                               uint8_t* WEBP_RESTRICT dst, int dst_stride) {
709
0
  int i, j;
710
0
  for (j = 0; j < 8; ++j) {
711
0
    for (i = 0; i < 8; ++i) {
712
0
      const int delta0 = dither[i] - VP8_DITHER_AMP_CENTER;
713
0
      const int delta1 =
714
0
          (delta0 + VP8_DITHER_DESCALE_ROUNDER) >> VP8_DITHER_DESCALE;
715
0
      dst[i] = clip_8b((int)dst[i] + delta1);
716
0
    }
717
0
    dst += dst_stride;
718
0
    dither += 8;
719
0
  }
720
0
}
721
722
//------------------------------------------------------------------------------
723
724
VP8DecIdct2 VP8Transform;
725
VP8DecIdct VP8TransformAC3;
726
VP8DecIdct VP8TransformUV;
727
VP8DecIdct VP8TransformDC;
728
VP8DecIdct VP8TransformDCUV;
729
730
VP8LumaFilterFunc VP8VFilter16;
731
VP8LumaFilterFunc VP8HFilter16;
732
VP8ChromaFilterFunc VP8VFilter8;
733
VP8ChromaFilterFunc VP8HFilter8;
734
VP8LumaFilterFunc VP8VFilter16i;
735
VP8LumaFilterFunc VP8HFilter16i;
736
VP8ChromaFilterFunc VP8VFilter8i;
737
VP8ChromaFilterFunc VP8HFilter8i;
738
VP8SimpleFilterFunc VP8SimpleVFilter16;
739
VP8SimpleFilterFunc VP8SimpleHFilter16;
740
VP8SimpleFilterFunc VP8SimpleVFilter16i;
741
VP8SimpleFilterFunc VP8SimpleHFilter16i;
742
743
void (*VP8DitherCombine8x8)(const uint8_t* WEBP_RESTRICT dither,
744
                            uint8_t* WEBP_RESTRICT dst, int dst_stride);
745
746
extern VP8CPUInfo VP8GetCPUInfo;
747
extern void VP8DspInitSSE2(void);
748
extern void VP8DspInitSSE41(void);
749
extern void VP8DspInitNEON(void);
750
extern void VP8DspInitMIPS32(void);
751
extern void VP8DspInitMIPSdspR2(void);
752
extern void VP8DspInitMSA(void);
753
754
1
WEBP_DSP_INIT_FUNC(VP8DspInit) {
755
1
  VP8InitClipTables();
756
757
1
#if !WEBP_NEON_OMIT_C_CODE
758
1
  VP8TransformWHT = TransformWHT_C;
759
1
  VP8Transform = TransformTwo_C;
760
1
  VP8TransformDC = TransformDC_C;
761
1
  VP8TransformAC3 = TransformAC3_C;
762
1
#endif
763
1
  VP8TransformUV = TransformUV_C;
764
1
  VP8TransformDCUV = TransformDCUV_C;
765
766
1
#if !WEBP_NEON_OMIT_C_CODE
767
1
  VP8VFilter16 = VFilter16_C;
768
1
  VP8VFilter16i = VFilter16i_C;
769
1
  VP8HFilter16 = HFilter16_C;
770
1
  VP8VFilter8 = VFilter8_C;
771
1
  VP8VFilter8i = VFilter8i_C;
772
1
  VP8SimpleVFilter16 = SimpleVFilter16_C;
773
1
  VP8SimpleHFilter16 = SimpleHFilter16_C;
774
1
  VP8SimpleVFilter16i = SimpleVFilter16i_C;
775
1
  VP8SimpleHFilter16i = SimpleHFilter16i_C;
776
1
#endif
777
778
1
#if !WEBP_NEON_OMIT_C_CODE || WEBP_NEON_WORK_AROUND_GCC
779
1
  VP8HFilter16i = HFilter16i_C;
780
1
  VP8HFilter8 = HFilter8_C;
781
1
  VP8HFilter8i = HFilter8i_C;
782
1
#endif
783
784
1
#if !WEBP_NEON_OMIT_C_CODE
785
1
  VP8PredLuma4[0] = DC4_C;
786
1
  VP8PredLuma4[1] = TM4_C;
787
1
  VP8PredLuma4[2] = VE4_C;
788
1
  VP8PredLuma4[4] = RD4_C;
789
1
  VP8PredLuma4[6] = LD4_C;
790
1
#endif
791
792
1
  VP8PredLuma4[3] = HE4_C;
793
1
  VP8PredLuma4[5] = VR4_C;
794
1
  VP8PredLuma4[7] = VL4_C;
795
1
  VP8PredLuma4[8] = HD4_C;
796
1
  VP8PredLuma4[9] = HU4_C;
797
798
1
#if !WEBP_NEON_OMIT_C_CODE
799
1
  VP8PredLuma16[0] = DC16_C;
800
1
  VP8PredLuma16[1] = TM16_C;
801
1
  VP8PredLuma16[2] = VE16_C;
802
1
  VP8PredLuma16[3] = HE16_C;
803
1
  VP8PredLuma16[4] = DC16NoTop_C;
804
1
  VP8PredLuma16[5] = DC16NoLeft_C;
805
1
  VP8PredLuma16[6] = DC16NoTopLeft_C;
806
807
1
  VP8PredChroma8[0] = DC8uv_C;
808
1
  VP8PredChroma8[1] = TM8uv_C;
809
1
  VP8PredChroma8[2] = VE8uv_C;
810
1
  VP8PredChroma8[3] = HE8uv_C;
811
1
  VP8PredChroma8[4] = DC8uvNoTop_C;
812
1
  VP8PredChroma8[5] = DC8uvNoLeft_C;
813
1
  VP8PredChroma8[6] = DC8uvNoTopLeft_C;
814
1
#endif
815
816
1
  VP8DitherCombine8x8 = DitherCombine8x8_C;
817
818
  // If defined, use CPUInfo() to overwrite some pointers with faster versions.
819
1
  if (VP8GetCPUInfo != NULL) {
820
1
#if defined(WEBP_HAVE_SSE2)
821
1
    if (VP8GetCPUInfo(kSSE2)) {
822
1
      VP8DspInitSSE2();
823
1
#if defined(WEBP_HAVE_SSE41)
824
1
      if (VP8GetCPUInfo(kSSE4_1)) {
825
1
        VP8DspInitSSE41();
826
1
      }
827
1
#endif
828
1
    }
829
1
#endif
830
#if defined(WEBP_USE_MIPS32)
831
    if (VP8GetCPUInfo(kMIPS32)) {
832
      VP8DspInitMIPS32();
833
    }
834
#endif
835
#if defined(WEBP_USE_MIPS_DSP_R2)
836
    if (VP8GetCPUInfo(kMIPSdspR2)) {
837
      VP8DspInitMIPSdspR2();
838
    }
839
#endif
840
#if defined(WEBP_USE_MSA)
841
    if (VP8GetCPUInfo(kMSA)) {
842
      VP8DspInitMSA();
843
    }
844
#endif
845
1
  }
846
847
#if defined(WEBP_HAVE_NEON)
848
  if (WEBP_NEON_OMIT_C_CODE ||
849
      (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kNEON))) {
850
    VP8DspInitNEON();
851
  }
852
#endif
853
854
1
  assert(VP8TransformWHT != NULL);
855
1
  assert(VP8Transform != NULL);
856
1
  assert(VP8TransformDC != NULL);
857
1
  assert(VP8TransformAC3 != NULL);
858
1
  assert(VP8TransformUV != NULL);
859
1
  assert(VP8TransformDCUV != NULL);
860
1
  assert(VP8VFilter16 != NULL);
861
1
  assert(VP8HFilter16 != NULL);
862
1
  assert(VP8VFilter8 != NULL);
863
1
  assert(VP8HFilter8 != NULL);
864
1
  assert(VP8VFilter16i != NULL);
865
1
  assert(VP8HFilter16i != NULL);
866
1
  assert(VP8VFilter8i != NULL);
867
1
  assert(VP8HFilter8i != NULL);
868
1
  assert(VP8SimpleVFilter16 != NULL);
869
1
  assert(VP8SimpleHFilter16 != NULL);
870
1
  assert(VP8SimpleVFilter16i != NULL);
871
1
  assert(VP8SimpleHFilter16i != NULL);
872
1
  assert(VP8PredLuma4[0] != NULL);
873
1
  assert(VP8PredLuma4[1] != NULL);
874
1
  assert(VP8PredLuma4[2] != NULL);
875
1
  assert(VP8PredLuma4[3] != NULL);
876
1
  assert(VP8PredLuma4[4] != NULL);
877
1
  assert(VP8PredLuma4[5] != NULL);
878
1
  assert(VP8PredLuma4[6] != NULL);
879
1
  assert(VP8PredLuma4[7] != NULL);
880
1
  assert(VP8PredLuma4[8] != NULL);
881
1
  assert(VP8PredLuma4[9] != NULL);
882
1
  assert(VP8PredLuma16[0] != NULL);
883
1
  assert(VP8PredLuma16[1] != NULL);
884
1
  assert(VP8PredLuma16[2] != NULL);
885
1
  assert(VP8PredLuma16[3] != NULL);
886
1
  assert(VP8PredLuma16[4] != NULL);
887
1
  assert(VP8PredLuma16[5] != NULL);
888
1
  assert(VP8PredLuma16[6] != NULL);
889
1
  assert(VP8PredChroma8[0] != NULL);
890
1
  assert(VP8PredChroma8[1] != NULL);
891
1
  assert(VP8PredChroma8[2] != NULL);
892
1
  assert(VP8PredChroma8[3] != NULL);
893
1
  assert(VP8PredChroma8[4] != NULL);
894
1
  assert(VP8PredChroma8[5] != NULL);
895
1
  assert(VP8PredChroma8[6] != NULL);
896
1
  assert(VP8DitherCombine8x8 != NULL);
897
1
}