Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Lossless video DSP utils | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include "config.h" | ||
22 | #include "lossless_videodsp.h" | ||
23 | #include "libavcodec/mathops.h" | ||
24 | |||
25 | // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size | ||
26 | #define pb_7f (~0UL / 255 * 0x7f) | ||
27 | #define pb_80 (~0UL / 255 * 0x80) | ||
28 | |||
29 | 29379 | static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w) | |
30 | { | ||
31 | long i; | ||
32 | |||
33 |
2/2✓ Branch 0 taken 2391200 times.
✓ Branch 1 taken 29379 times.
|
2420579 | for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) { |
34 | 2391200 | long a = *(long *) (src + i); | |
35 | 2391200 | long b = *(long *) (dst + i); | |
36 | 2391200 | *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80); | |
37 | } | ||
38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29379 times.
|
29379 | for (; i < w; i++) |
39 | ✗ | dst[i + 0] += src[i + 0]; | |
40 | 29379 | } | |
41 | |||
42 | 47711 | static void add_median_pred_c(uint8_t *dst, const uint8_t *src1, | |
43 | const uint8_t *diff, ptrdiff_t w, | ||
44 | int *left, int *left_top) | ||
45 | { | ||
46 | int i; | ||
47 | uint8_t l, lt; | ||
48 | |||
49 | 47711 | l = *left; | |
50 | 47711 | lt = *left_top; | |
51 | |||
52 |
2/2✓ Branch 0 taken 28773536 times.
✓ Branch 1 taken 47711 times.
|
28821247 | for (i = 0; i < w; i++) { |
53 | 28773536 | l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i]; | |
54 | 28773536 | lt = src1[i]; | |
55 | 28773536 | dst[i] = l; | |
56 | } | ||
57 | |||
58 | 47711 | *left = l; | |
59 | 47711 | *left_top = lt; | |
60 | 47711 | } | |
61 | |||
62 | 391296 | static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w, | |
63 | int acc) | ||
64 | { | ||
65 | int i; | ||
66 | |||
67 |
2/2✓ Branch 0 taken 57865264 times.
✓ Branch 1 taken 391296 times.
|
58256560 | for (i = 0; i < w - 1; i++) { |
68 | 57865264 | acc += src[i]; | |
69 | 57865264 | dst[i] = acc; | |
70 | 57865264 | i++; | |
71 | 57865264 | acc += src[i]; | |
72 | 57865264 | dst[i] = acc; | |
73 | } | ||
74 | |||
75 |
2/2✓ Branch 0 taken 5516 times.
✓ Branch 1 taken 391296 times.
|
396812 | for (; i < w; i++) { |
76 | 5516 | acc += src[i]; | |
77 | 5516 | dst[i] = acc; | |
78 | } | ||
79 | |||
80 | 391296 | return acc; | |
81 | } | ||
82 | |||
83 | 359203 | static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){ | |
84 | int i; | ||
85 | |||
86 |
2/2✓ Branch 0 taken 49609172 times.
✓ Branch 1 taken 359203 times.
|
49968375 | for(i=0; i<w-1; i++){ |
87 | 49609172 | acc+= src[i]; | |
88 | 49609172 | dst[i]= acc &= mask; | |
89 | 49609172 | i++; | |
90 | 49609172 | acc+= src[i]; | |
91 | 49609172 | dst[i]= acc &= mask; | |
92 | } | ||
93 | |||
94 |
2/2✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 359203 times.
|
364303 | for(; i<w; i++){ |
95 | 5100 | acc+= src[i]; | |
96 | 5100 | dst[i]= acc &= mask; | |
97 | } | ||
98 | |||
99 | 359203 | return acc; | |
100 | } | ||
101 | |||
102 | 2697 | static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){ | |
103 | int A, B, C, i; | ||
104 | |||
105 |
2/2✓ Branch 0 taken 404664 times.
✓ Branch 1 taken 2697 times.
|
407361 | for (i = 0; i < width; i++) { |
106 | 404664 | A = src[i - stride]; | |
107 | 404664 | B = src[i - (stride + 1)]; | |
108 | 404664 | C = src[i - 1]; | |
109 | 404664 | src[i] = (A - B + C + src[i]) & 0xFF; | |
110 | } | ||
111 | 2697 | } | |
112 | |||
113 | 178 | void ff_llviddsp_init(LLVidDSPContext *c) | |
114 | { | ||
115 | 178 | c->add_bytes = add_bytes_c; | |
116 | 178 | c->add_median_pred = add_median_pred_c; | |
117 | 178 | c->add_left_pred = add_left_pred_c; | |
118 | |||
119 | 178 | c->add_left_pred_int16 = add_left_pred_int16_c; | |
120 | 178 | c->add_gradient_pred = add_gradient_pred_c; | |
121 | |||
122 | #if ARCH_PPC | ||
123 | ff_llviddsp_init_ppc(c); | ||
124 | #elif ARCH_RISCV | ||
125 | ff_llviddsp_init_riscv(c); | ||
126 | #elif ARCH_X86 | ||
127 | 178 | ff_llviddsp_init_x86(c); | |
128 | #endif | ||
129 | 178 | } | |
130 |