Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (C) 2009 David Conrad | ||
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 "libavutil/attributes.h" | ||
23 | #include "libavutil/common.h" | ||
24 | #include "diracdsp.h" | ||
25 | |||
26 | #define FILTER(src, stride) \ | ||
27 | ((21*((src)[ 0*stride] + (src)[1*stride]) \ | ||
28 | -7*((src)[-1*stride] + (src)[2*stride]) \ | ||
29 | +3*((src)[-2*stride] + (src)[3*stride]) \ | ||
30 | -1*((src)[-3*stride] + (src)[4*stride]) + 16) >> 5) | ||
31 | |||
32 | ✗ | static void dirac_hpel_filter(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, const uint8_t *src, | |
33 | int stride, int width, int height) | ||
34 | { | ||
35 | int x, y; | ||
36 | |||
37 | ✗ | for (y = 0; y < height; y++) { | |
38 | ✗ | for (x = -3; x < width+5; x++) | |
39 | ✗ | dstv[x] = av_clip_uint8(FILTER(src+x, stride)); | |
40 | |||
41 | ✗ | for (x = 0; x < width; x++) | |
42 | ✗ | dstc[x] = av_clip_uint8(FILTER(dstv+x, 1)); | |
43 | |||
44 | ✗ | for (x = 0; x < width; x++) | |
45 | ✗ | dsth[x] = av_clip_uint8(FILTER(src+x, 1)); | |
46 | |||
47 | ✗ | src += stride; | |
48 | ✗ | dsth += stride; | |
49 | ✗ | dstv += stride; | |
50 | ✗ | dstc += stride; | |
51 | } | ||
52 | ✗ | } | |
53 | |||
54 | #define PIXOP_BILINEAR(PFX, OP, WIDTH) \ | ||
55 | static void ff_ ## PFX ## _dirac_pixels ## WIDTH ## _bilinear_c(uint8_t *dst, const uint8_t *src[5], int stride, int h) \ | ||
56 | { \ | ||
57 | int x; \ | ||
58 | const uint8_t *s0 = src[0]; \ | ||
59 | const uint8_t *s1 = src[1]; \ | ||
60 | const uint8_t *s2 = src[2]; \ | ||
61 | const uint8_t *s3 = src[3]; \ | ||
62 | const uint8_t *w = src[4]; \ | ||
63 | \ | ||
64 | while (h--) { \ | ||
65 | for (x = 0; x < WIDTH; x++) { \ | ||
66 | OP(dst[x], (s0[x]*w[0] + s1[x]*w[1] + s2[x]*w[2] + s3[x]*w[3] + 8) >> 4); \ | ||
67 | } \ | ||
68 | \ | ||
69 | dst += stride; \ | ||
70 | s0 += stride; \ | ||
71 | s1 += stride; \ | ||
72 | s2 += stride; \ | ||
73 | s3 += stride; \ | ||
74 | } \ | ||
75 | } | ||
76 | |||
77 | #define OP_PUT(dst, val) (dst) = (val) | ||
78 | #define OP_AVG(dst, val) (dst) = (((dst) + (val) + 1)>>1) | ||
79 | |||
80 | ✗ | PIXOP_BILINEAR(put, OP_PUT, 8) | |
81 | ✗ | PIXOP_BILINEAR(put, OP_PUT, 16) | |
82 | ✗ | PIXOP_BILINEAR(put, OP_PUT, 32) | |
83 | ✗ | PIXOP_BILINEAR(avg, OP_AVG, 8) | |
84 | ✗ | PIXOP_BILINEAR(avg, OP_AVG, 16) | |
85 | ✗ | PIXOP_BILINEAR(avg, OP_AVG, 32) | |
86 | |||
87 | #define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + (1<<(log2_denom-1))) >> log2_denom) | ||
88 | #define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + (1<<(log2_denom-1))) >> log2_denom) | ||
89 | |||
90 | #define DIRAC_WEIGHT(W) \ | ||
91 | static void weight_dirac_pixels ## W ## _c(uint8_t *block, int stride, int log2_denom, \ | ||
92 | int weight, int h) { \ | ||
93 | int x; \ | ||
94 | while (h--) { \ | ||
95 | for (x = 0; x < W; x++) { \ | ||
96 | op_scale1(x); \ | ||
97 | op_scale1(x+1); \ | ||
98 | } \ | ||
99 | block += stride; \ | ||
100 | } \ | ||
101 | } \ | ||
102 | static void biweight_dirac_pixels ## W ## _c(uint8_t *dst, const uint8_t *src, int stride, int log2_denom, \ | ||
103 | int weightd, int weights, int h) { \ | ||
104 | int x; \ | ||
105 | while (h--) { \ | ||
106 | for (x = 0; x < W; x++) { \ | ||
107 | op_scale2(x); \ | ||
108 | op_scale2(x+1); \ | ||
109 | } \ | ||
110 | dst += stride; \ | ||
111 | src += stride; \ | ||
112 | } \ | ||
113 | } | ||
114 | |||
115 | ✗ | DIRAC_WEIGHT(8) | |
116 | ✗ | DIRAC_WEIGHT(16) | |
117 | ✗ | DIRAC_WEIGHT(32) | |
118 | |||
119 | #define ADD_OBMC(xblen) \ | ||
120 | static void add_obmc ## xblen ## _c(uint16_t *dst, const uint8_t *src, int stride, \ | ||
121 | const uint8_t *obmc_weight, int yblen) \ | ||
122 | { \ | ||
123 | int x; \ | ||
124 | while (yblen--) { \ | ||
125 | for (x = 0; x < xblen; x += 2) { \ | ||
126 | dst[x ] += src[x ] * obmc_weight[x ]; \ | ||
127 | dst[x+1] += src[x+1] * obmc_weight[x+1]; \ | ||
128 | } \ | ||
129 | dst += stride; \ | ||
130 | src += stride; \ | ||
131 | obmc_weight += 32; \ | ||
132 | } \ | ||
133 | } | ||
134 | |||
135 |
4/4✓ Branch 0 taken 2253588 times.
✓ Branch 1 taken 563397 times.
✓ Branch 2 taken 563397 times.
✓ Branch 3 taken 70415 times.
|
2887400 | ADD_OBMC(8) |
136 |
4/4✓ Branch 0 taken 4507472 times.
✓ Branch 1 taken 563434 times.
✓ Branch 2 taken 563434 times.
✓ Branch 3 taken 35209 times.
|
5106115 | ADD_OBMC(16) |
137 |
4/4✓ Branch 0 taken 1808 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 113 times.
✓ Branch 3 taken 3 times.
|
1924 | ADD_OBMC(32) |
138 | |||
139 | 3615 | static void put_signed_rect_clamped_8bit_c(uint8_t *dst, int dst_stride, const uint8_t *_src, int src_stride, int width, int height) | |
140 | { | ||
141 | int x, y; | ||
142 | 3615 | const int16_t *src = (const int16_t *)_src; | |
143 |
2/2✓ Branch 0 taken 57840 times.
✓ Branch 1 taken 3615 times.
|
61455 | for (y = 0; y < height; y++) { |
144 |
2/2✓ Branch 0 taken 3936768 times.
✓ Branch 1 taken 57840 times.
|
3994608 | for (x = 0; x < width; x+=4) { |
145 | 3936768 | dst[x ] = av_clip_uint8(src[x ] + 128); | |
146 | 3936768 | dst[x+1] = av_clip_uint8(src[x+1] + 128); | |
147 | 3936768 | dst[x+2] = av_clip_uint8(src[x+2] + 128); | |
148 | 3936768 | dst[x+3] = av_clip_uint8(src[x+3] + 128); | |
149 | } | ||
150 | 57840 | dst += dst_stride; | |
151 | 57840 | src += src_stride >> 1; | |
152 | } | ||
153 | 3615 | } | |
154 | |||
155 | #define PUT_SIGNED_RECT_CLAMPED(PX) \ | ||
156 | static void put_signed_rect_clamped_ ## PX ## bit_c(uint8_t *_dst, int dst_stride, const uint8_t *_src, \ | ||
157 | int src_stride, int width, int height) \ | ||
158 | { \ | ||
159 | int x, y; \ | ||
160 | uint16_t *dst = (uint16_t *)_dst; \ | ||
161 | const int32_t *src = (const int32_t *)_src; \ | ||
162 | for (y = 0; y < height; y++) { \ | ||
163 | for (x = 0; x < width; x+=4) { \ | ||
164 | dst[x ] = av_clip_uintp2(src[x ] + (1U << (PX - 1)), PX); \ | ||
165 | dst[x+1] = av_clip_uintp2(src[x+1] + (1U << (PX - 1)), PX); \ | ||
166 | dst[x+2] = av_clip_uintp2(src[x+2] + (1U << (PX - 1)), PX); \ | ||
167 | dst[x+3] = av_clip_uintp2(src[x+3] + (1U << (PX - 1)), PX); \ | ||
168 | } \ | ||
169 | dst += dst_stride >> 1; \ | ||
170 | src += src_stride >> 2; \ | ||
171 | } \ | ||
172 | } | ||
173 | |||
174 |
4/4✓ Branch 0 taken 4790016 times.
✓ Branch 1 taken 72576 times.
✓ Branch 2 taken 72576 times.
✓ Branch 3 taken 4536 times.
|
4867128 | PUT_SIGNED_RECT_CLAMPED(10) |
175 |
4/4✓ Branch 0 taken 2965248 times.
✓ Branch 1 taken 41472 times.
✓ Branch 2 taken 41472 times.
✓ Branch 3 taken 2592 times.
|
3009312 | PUT_SIGNED_RECT_CLAMPED(12) |
176 | |||
177 | 2697 | static void add_rect_clamped_c(uint8_t *dst, const uint16_t *src, int stride, | |
178 | const int16_t *idwt, int idwt_stride, | ||
179 | int width, int height) | ||
180 | { | ||
181 | int x, y; | ||
182 | |||
183 |
2/2✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 2697 times.
|
16617 | for (y = 0; y < height; y++) { |
184 |
2/2✓ Branch 0 taken 1670400 times.
✓ Branch 1 taken 13920 times.
|
1684320 | for (x = 0; x < width; x+=2) { |
185 | 1670400 | dst[x ] = av_clip_uint8(((src[x ]+32)>>6) + idwt[x ]); | |
186 | 1670400 | dst[x+1] = av_clip_uint8(((src[x+1]+32)>>6) + idwt[x+1]); | |
187 | } | ||
188 | 13920 | dst += stride; | |
189 | 13920 | src += stride; | |
190 | 13920 | idwt += idwt_stride; | |
191 | } | ||
192 | 2697 | } | |
193 | |||
194 | #define DEQUANT_SUBBAND(PX) \ | ||
195 | static void dequant_subband_ ## PX ## _c(uint8_t *src, uint8_t *dst, ptrdiff_t stride, \ | ||
196 | const int qf, const int qs, int tot_v, int tot_h) \ | ||
197 | { \ | ||
198 | int i, y; \ | ||
199 | for (y = 0; y < tot_v; y++) { \ | ||
200 | PX c, *src_r = (PX *)src, *dst_r = (PX *)dst; \ | ||
201 | for (i = 0; i < tot_h; i++) { \ | ||
202 | c = *src_r++; \ | ||
203 | if (c < 0) c = -((-(unsigned)c*qf + qs) >> 2); \ | ||
204 | else if(c > 0) c = (( (unsigned)c*qf + qs) >> 2); \ | ||
205 | *dst_r++ = c; \ | ||
206 | } \ | ||
207 | src += tot_h << (sizeof(PX) >> 1); \ | ||
208 | dst += stride; \ | ||
209 | } \ | ||
210 | } | ||
211 | |||
212 |
8/8✓ Branch 0 taken 4884043 times.
✓ Branch 1 taken 6976949 times.
✓ Branch 2 taken 4850267 times.
✓ Branch 3 taken 2126682 times.
✓ Branch 4 taken 11860992 times.
✓ Branch 5 taken 1311552 times.
✓ Branch 6 taken 1311552 times.
✓ Branch 7 taken 416988 times.
|
13589532 | DEQUANT_SUBBAND(int16_t) |
213 |
8/8✓ Branch 0 taken 14665666 times.
✓ Branch 1 taken 16355390 times.
✓ Branch 2 taken 14417859 times.
✓ Branch 3 taken 1937531 times.
✓ Branch 4 taken 31021056 times.
✓ Branch 5 taken 3606768 times.
✓ Branch 6 taken 3606768 times.
✓ Branch 7 taken 1111968 times.
|
35739792 | DEQUANT_SUBBAND(int32_t) |
214 | |||
215 | #define PIXFUNC(PFX, WIDTH) \ | ||
216 | c->PFX ## _dirac_pixels_tab[WIDTH>>4][0] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _c; \ | ||
217 | c->PFX ## _dirac_pixels_tab[WIDTH>>4][1] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _l2_c; \ | ||
218 | c->PFX ## _dirac_pixels_tab[WIDTH>>4][2] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _l4_c; \ | ||
219 | c->PFX ## _dirac_pixels_tab[WIDTH>>4][3] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _bilinear_c | ||
220 | |||
221 | 109 | av_cold void ff_diracdsp_init(DiracDSPContext *c) | |
222 | { | ||
223 | 109 | c->dirac_hpel_filter = dirac_hpel_filter; | |
224 | 109 | c->add_rect_clamped = add_rect_clamped_c; | |
225 | 109 | c->put_signed_rect_clamped[0] = put_signed_rect_clamped_8bit_c; | |
226 | 109 | c->put_signed_rect_clamped[1] = put_signed_rect_clamped_10bit_c; | |
227 | 109 | c->put_signed_rect_clamped[2] = put_signed_rect_clamped_12bit_c; | |
228 | |||
229 | 109 | c->add_dirac_obmc[0] = add_obmc8_c; | |
230 | 109 | c->add_dirac_obmc[1] = add_obmc16_c; | |
231 | 109 | c->add_dirac_obmc[2] = add_obmc32_c; | |
232 | |||
233 | 109 | c->weight_dirac_pixels_tab[0] = weight_dirac_pixels8_c; | |
234 | 109 | c->weight_dirac_pixels_tab[1] = weight_dirac_pixels16_c; | |
235 | 109 | c->weight_dirac_pixels_tab[2] = weight_dirac_pixels32_c; | |
236 | 109 | c->biweight_dirac_pixels_tab[0] = biweight_dirac_pixels8_c; | |
237 | 109 | c->biweight_dirac_pixels_tab[1] = biweight_dirac_pixels16_c; | |
238 | 109 | c->biweight_dirac_pixels_tab[2] = biweight_dirac_pixels32_c; | |
239 | |||
240 | 109 | c->dequant_subband[0] = c->dequant_subband[2] = dequant_subband_int16_t_c; | |
241 | 109 | c->dequant_subband[1] = c->dequant_subband[3] = dequant_subband_int32_t_c; | |
242 | |||
243 | 109 | PIXFUNC(put, 8); | |
244 | 109 | PIXFUNC(put, 16); | |
245 | 109 | PIXFUNC(put, 32); | |
246 | 109 | PIXFUNC(avg, 8); | |
247 | 109 | PIXFUNC(avg, 16); | |
248 | 109 | PIXFUNC(avg, 32); | |
249 | |||
250 | #if ARCH_X86 | ||
251 | 109 | ff_diracdsp_init_x86(c); | |
252 | #endif | ||
253 | 109 | } | |
254 |