/src/ffmpeg/libswscale/uops_tmpl.c
Line | Count | Source |
1 | | /** |
2 | | * Copyright (C) 2026 Niklas Haas |
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 <libavutil/bswap.h> |
22 | | |
23 | | #include "uops_tmpl.h" |
24 | | |
25 | | #ifndef BIT_DEPTH |
26 | | # define BIT_DEPTH 8 |
27 | | #endif |
28 | | |
29 | | #if IS_FLOAT && BIT_DEPTH == 32 |
30 | | # define PIXEL_TYPE SWS_PIXEL_F32 |
31 | 0 | # define pixel_t float |
32 | 0 | # define inter_t float |
33 | 0 | # define vec3_t v3f32_t |
34 | | # define PX F32 |
35 | 0 | # define px f32 |
36 | | #elif BIT_DEPTH == 32 |
37 | 0 | # define PIXEL_MAX 0xFFFFFFFFu |
38 | 0 | # define PIXEL_SWAP av_bswap32 |
39 | 0 | # define pixel_t uint32_t |
40 | | # define inter_t int64_t |
41 | | # define PX U32 |
42 | 0 | # define px u32 |
43 | | #elif BIT_DEPTH == 16 |
44 | 0 | # define PIXEL_MAX 0xFFFFu |
45 | 0 | # define PIXEL_SWAP av_bswap16 |
46 | 0 | # define pixel_t uint16_t |
47 | 0 | # define inter_t int64_t |
48 | | # define PX U16 |
49 | 0 | # define px u16 |
50 | | #elif BIT_DEPTH == 8 |
51 | 0 | # define PIXEL_MAX 0xFFu |
52 | 0 | # define pixel_t uint8_t |
53 | 0 | # define inter_t int32_t |
54 | | # define PX U8 |
55 | 0 | # define px u8 |
56 | | #else |
57 | | # error Invalid BIT_DEPTH |
58 | | #endif |
59 | | |
60 | | /********************************* |
61 | | * Generic read/write operations * |
62 | | *********************************/ |
63 | | |
64 | | DECL_READ(read_planar, const SwsCompMask mask) |
65 | 0 | { |
66 | 0 | SWS_LOOP |
67 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
68 | 0 | if (X) x[i] = in0[i]; |
69 | 0 | if (Y) y[i] = in1[i]; |
70 | 0 | if (Z) z[i] = in2[i]; |
71 | 0 | if (W) w[i] = in3[i]; |
72 | 0 | } |
73 | |
|
74 | 0 | if (X) iter->in[0] += SIZEOF_BLOCK; |
75 | 0 | if (Y) iter->in[1] += SIZEOF_BLOCK; |
76 | 0 | if (Z) iter->in[2] += SIZEOF_BLOCK; |
77 | 0 | if (W) iter->in[3] += SIZEOF_BLOCK; |
78 | |
|
79 | 0 | CONTINUE(x, y, z, w); |
80 | 0 | } Unexecuted instantiation: uops_backend.c:read_planar_U8 Unexecuted instantiation: uops_backend.c:read_planar_U16 Unexecuted instantiation: uops_backend.c:read_planar_U32 Unexecuted instantiation: uops_backend.c:read_planar_F32 |
81 | | |
82 | | DECL_READ(read_packed, const SwsCompMask mask) |
83 | 0 | { |
84 | 0 | const int elems = W ? 4 : Z ? 3 : Y ? 2 : 1; |
85 | |
|
86 | 0 | SWS_LOOP |
87 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
88 | 0 | if (X) x[i] = in0[elems * i + 0]; |
89 | 0 | if (Y) y[i] = in0[elems * i + 1]; |
90 | 0 | if (Z) z[i] = in0[elems * i + 2]; |
91 | 0 | if (W) w[i] = in0[elems * i + 3]; |
92 | 0 | } |
93 | |
|
94 | 0 | iter->in[0] += SIZEOF_BLOCK * elems; |
95 | 0 | CONTINUE(x, y, z, w); |
96 | 0 | } Unexecuted instantiation: uops_backend.c:read_packed_U8 Unexecuted instantiation: uops_backend.c:read_packed_U16 Unexecuted instantiation: uops_backend.c:read_packed_U32 Unexecuted instantiation: uops_backend.c:read_packed_F32 |
97 | | |
98 | | DECL_WRITE(write_planar, const SwsCompMask mask) |
99 | 0 | { |
100 | 0 | SWS_LOOP |
101 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
102 | 0 | if (X) out0[i] = x[i]; |
103 | 0 | if (Y) out1[i] = y[i]; |
104 | 0 | if (Z) out2[i] = z[i]; |
105 | 0 | if (W) out3[i] = w[i]; |
106 | 0 | } |
107 | |
|
108 | 0 | if (X) iter->out[0] += SIZEOF_BLOCK; |
109 | 0 | if (Y) iter->out[1] += SIZEOF_BLOCK; |
110 | 0 | if (Z) iter->out[2] += SIZEOF_BLOCK; |
111 | 0 | if (W) iter->out[3] += SIZEOF_BLOCK; |
112 | 0 | } Unexecuted instantiation: uops_backend.c:write_planar_U8 Unexecuted instantiation: uops_backend.c:write_planar_U16 Unexecuted instantiation: uops_backend.c:write_planar_U32 Unexecuted instantiation: uops_backend.c:write_planar_F32 |
113 | | |
114 | | DECL_WRITE(write_packed, const SwsCompMask mask) |
115 | 0 | { |
116 | 0 | const int elems = W ? 4 : Z ? 3 : Y ? 2 : 1; |
117 | |
|
118 | 0 | SWS_LOOP |
119 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
120 | 0 | if (X) out0[elems * i + 0] = x[i]; |
121 | 0 | if (Y) out0[elems * i + 1] = y[i]; |
122 | 0 | if (Z) out0[elems * i + 2] = z[i]; |
123 | 0 | if (W) out0[elems * i + 3] = w[i]; |
124 | 0 | } |
125 | |
|
126 | 0 | iter->out[0] += SIZEOF_BLOCK * elems; |
127 | 0 | } Unexecuted instantiation: uops_backend.c:write_packed_U8 Unexecuted instantiation: uops_backend.c:write_packed_U16 Unexecuted instantiation: uops_backend.c:write_packed_U32 Unexecuted instantiation: uops_backend.c:write_packed_F32 |
128 | | |
129 | | #if BIT_DEPTH == 8 |
130 | | |
131 | | DECL_READ(read_bit, const SwsCompMask mask) |
132 | 0 | { |
133 | 0 | av_assert2(mask == SWS_COMP_ELEMS(1)); |
134 | |
|
135 | 0 | SWS_LOOP |
136 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i += 8) { |
137 | 0 | const pixel_t val = ((const pixel_t *) in0)[i >> 3]; |
138 | 0 | x[i + 0] = (val >> 7) & 1; |
139 | 0 | x[i + 1] = (val >> 6) & 1; |
140 | 0 | x[i + 2] = (val >> 5) & 1; |
141 | 0 | x[i + 3] = (val >> 4) & 1; |
142 | 0 | x[i + 4] = (val >> 3) & 1; |
143 | 0 | x[i + 5] = (val >> 2) & 1; |
144 | 0 | x[i + 6] = (val >> 1) & 1; |
145 | 0 | x[i + 7] = (val >> 0) & 1; |
146 | 0 | } |
147 | |
|
148 | 0 | iter->in[0] += SIZEOF_BLOCK >> 3; |
149 | 0 | CONTINUE(x, y, z, w); |
150 | 0 | } |
151 | | |
152 | | DECL_READ(read_nibble, const SwsCompMask mask) |
153 | 0 | { |
154 | 0 | av_assert2(mask == SWS_COMP_ELEMS(1)); |
155 | |
|
156 | 0 | SWS_LOOP |
157 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i += 2) { |
158 | 0 | const pixel_t val = in0[i >> 1]; |
159 | 0 | x[i + 0] = val >> 4; /* high nibble */ |
160 | 0 | x[i + 1] = val & 0xF; /* low nibble */ |
161 | 0 | } |
162 | |
|
163 | 0 | iter->in[0] += SIZEOF_BLOCK >> 1; |
164 | 0 | CONTINUE(x, y, z, w); |
165 | 0 | } |
166 | | |
167 | | DECL_READ(read_palette, const SwsCompMask mask) |
168 | 0 | { |
169 | 0 | av_assert2(mask == SWS_COMP_ELEMS(4)); |
170 | |
|
171 | 0 | SWS_LOOP |
172 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
173 | 0 | const pixel_t index = in0[i]; |
174 | 0 | const pixel_t *value = &in1[index * 4]; |
175 | 0 | x[i] = value[0]; |
176 | 0 | y[i] = value[1]; |
177 | 0 | z[i] = value[2]; |
178 | 0 | w[i] = value[3]; |
179 | 0 | } |
180 | |
|
181 | 0 | iter->in[0] += SIZEOF_BLOCK; |
182 | 0 | CONTINUE(x, y, z, w); |
183 | 0 | } |
184 | | |
185 | | DECL_WRITE(write_bit, const SwsCompMask mask) |
186 | 0 | { |
187 | 0 | av_assert2(mask == SWS_COMP_ELEMS(1)); |
188 | |
|
189 | 0 | SWS_LOOP |
190 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i += 8) { |
191 | 0 | out0[i >> 3] = x[i + 0] << 7 | |
192 | 0 | x[i + 1] << 6 | |
193 | 0 | x[i + 2] << 5 | |
194 | 0 | x[i + 3] << 4 | |
195 | 0 | x[i + 4] << 3 | |
196 | 0 | x[i + 5] << 2 | |
197 | 0 | x[i + 6] << 1 | |
198 | 0 | x[i + 7]; |
199 | 0 | } |
200 | |
|
201 | 0 | iter->out[0] += SIZEOF_BLOCK >> 3; |
202 | 0 | } |
203 | | |
204 | | DECL_WRITE(write_nibble, const SwsCompMask mask) |
205 | 0 | { |
206 | 0 | av_assert2(mask == SWS_COMP_ELEMS(1)); |
207 | |
|
208 | 0 | SWS_LOOP |
209 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i += 2) |
210 | 0 | out0[i >> 1] = x[i] << 4 | x[i + 1]; |
211 | |
|
212 | 0 | iter->out[0] += SIZEOF_BLOCK >> 1; |
213 | 0 | } |
214 | | |
215 | | #endif /* BIT_DEPTH == 8 */ |
216 | | |
217 | | SWS_FOR(PX, READ_PLANAR, DECL_IMPL_READ, read_planar) |
218 | | SWS_FOR(PX, READ_PACKED, DECL_IMPL_READ, read_packed) |
219 | | SWS_FOR(PX, READ_NIBBLE, DECL_IMPL_READ, read_nibble) |
220 | | SWS_FOR(PX, READ_BIT, DECL_IMPL_READ, read_bit) |
221 | | SWS_FOR(PX, READ_PALETTE, DECL_IMPL_READ, read_palette) |
222 | | SWS_FOR(PX, WRITE_PLANAR, DECL_IMPL_WRITE, write_planar) |
223 | | SWS_FOR(PX, WRITE_PACKED, DECL_IMPL_WRITE, write_packed) |
224 | | SWS_FOR(PX, WRITE_NIBBLE, DECL_IMPL_WRITE, write_nibble) |
225 | | SWS_FOR(PX, WRITE_BIT, DECL_IMPL_WRITE, write_bit) |
226 | | |
227 | | SWS_FOR_STRUCT(PX, READ_PLANAR, DECL_ENTRY) |
228 | | SWS_FOR_STRUCT(PX, READ_PACKED, DECL_ENTRY) |
229 | | SWS_FOR_STRUCT(PX, READ_NIBBLE, DECL_ENTRY) |
230 | | SWS_FOR_STRUCT(PX, READ_BIT, DECL_ENTRY) |
231 | | SWS_FOR_STRUCT(PX, READ_PALETTE, DECL_ENTRY) |
232 | | SWS_FOR_STRUCT(PX, WRITE_PLANAR, DECL_ENTRY) |
233 | | SWS_FOR_STRUCT(PX, WRITE_PACKED, DECL_ENTRY) |
234 | | SWS_FOR_STRUCT(PX, WRITE_NIBBLE, DECL_ENTRY) |
235 | | SWS_FOR_STRUCT(PX, WRITE_BIT, DECL_ENTRY) |
236 | | |
237 | | /***************************** |
238 | | * Scaling / filtering reads * |
239 | | *****************************/ |
240 | | |
241 | | DECL_SETUP(setup_filter_v, params, out) |
242 | 0 | { |
243 | 0 | if (params->uop->par.filter.type != SWS_PIXEL_F32) |
244 | 0 | return AVERROR(ENOTSUP); |
245 | | |
246 | 0 | const SwsFilterWeights *filter = params->uop->data.kernel; |
247 | 0 | static_assert(sizeof(out->priv.ptr) <= sizeof(int32_t[2]), |
248 | 0 | ">8 byte pointers not supported"); |
249 | | |
250 | | /* Pre-convert weights to float */ |
251 | 0 | float *weights = av_calloc(filter->num_weights, sizeof(float)); |
252 | 0 | if (!weights) |
253 | 0 | return AVERROR(ENOMEM); |
254 | | |
255 | 0 | for (int i = 0; i < filter->num_weights; i++) |
256 | 0 | weights[i] = (float) filter->weights[i] / SWS_FILTER_SCALE; |
257 | |
|
258 | 0 | out->priv.ptr = weights; |
259 | 0 | out->priv.i32[2] = filter->filter_size; |
260 | 0 | out->free = ff_op_priv_free; |
261 | 0 | return 0; |
262 | 0 | } Unexecuted instantiation: uops_backend.c:setup_filter_v_U8 Unexecuted instantiation: uops_backend.c:setup_filter_v_U16 Unexecuted instantiation: uops_backend.c:setup_filter_v_F32 Unexecuted instantiation: uops_backend.c:setup_filter_v_U32 |
263 | | |
264 | | /* Fully general vertical planar filter case */ |
265 | | DECL_READ(read_planar_fv, const SwsCompMask mask, const SwsPixelType type) |
266 | 0 | { |
267 | 0 | av_assert2(type == SWS_PIXEL_F32); |
268 | 0 | const SwsOpExec *exec = iter->exec; |
269 | 0 | const float *restrict weights = impl->priv.ptr; |
270 | 0 | const int filter_size = impl->priv.i32[2]; |
271 | 0 | weights += filter_size * iter->y; |
272 | |
|
273 | 0 | block_t xs, ys, zs, ws; |
274 | 0 | if (X) memset(&xs.f32, 0, sizeof(xs.f32)); |
275 | 0 | if (Y) memset(&ys.f32, 0, sizeof(ys.f32)); |
276 | 0 | if (Z) memset(&zs.f32, 0, sizeof(zs.f32)); |
277 | 0 | if (W) memset(&ws.f32, 0, sizeof(ws.f32)); |
278 | |
|
279 | 0 | for (int j = 0; j < filter_size; j++) { |
280 | 0 | const float weight = weights[j]; |
281 | |
|
282 | 0 | SWS_LOOP |
283 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
284 | 0 | if (X) xs.f32[i] += weight * in0[i]; |
285 | 0 | if (Y) ys.f32[i] += weight * in1[i]; |
286 | 0 | if (Z) zs.f32[i] += weight * in2[i]; |
287 | 0 | if (W) ws.f32[i] += weight * in3[i]; |
288 | 0 | } |
289 | |
|
290 | 0 | if (X) in0 = bump_ptr(in0, exec->in_stride[0]); |
291 | 0 | if (Y) in1 = bump_ptr(in1, exec->in_stride[1]); |
292 | 0 | if (Z) in2 = bump_ptr(in2, exec->in_stride[2]); |
293 | 0 | if (W) in3 = bump_ptr(in3, exec->in_stride[3]); |
294 | 0 | } |
295 | |
|
296 | 0 | if (X) iter->in[0] += SIZEOF_BLOCK; |
297 | 0 | if (Y) iter->in[1] += SIZEOF_BLOCK; |
298 | 0 | if (Z) iter->in[2] += SIZEOF_BLOCK; |
299 | 0 | if (W) iter->in[3] += SIZEOF_BLOCK; |
300 | |
|
301 | 0 | CONTINUE(&xs, &ys, &zs, &ws); |
302 | 0 | } Unexecuted instantiation: uops_backend.c:read_planar_fv_U8 Unexecuted instantiation: uops_backend.c:read_planar_fv_U16 Unexecuted instantiation: uops_backend.c:read_planar_fv_F32 Unexecuted instantiation: uops_backend.c:read_planar_fv_U32 |
303 | | |
304 | | DECL_SETUP(setup_filter_h, params, out) |
305 | 0 | { |
306 | 0 | if (params->uop->par.filter.type != SWS_PIXEL_F32) |
307 | 0 | return AVERROR(ENOTSUP); |
308 | | |
309 | 0 | SwsFilterWeights *filter = params->uop->data.kernel; |
310 | 0 | out->priv.ptr = av_refstruct_ref(filter->weights); |
311 | 0 | out->priv.i32[2] = filter->filter_size; |
312 | 0 | out->free = ff_op_priv_unref; |
313 | 0 | return 0; |
314 | 0 | } Unexecuted instantiation: uops_backend.c:setup_filter_h_U8 Unexecuted instantiation: uops_backend.c:setup_filter_h_U16 Unexecuted instantiation: uops_backend.c:setup_filter_h_F32 Unexecuted instantiation: uops_backend.c:setup_filter_h_U32 |
315 | | |
316 | | /* Fully general horizontal planar filter case */ |
317 | | DECL_READ(read_planar_fh, const SwsCompMask mask, const SwsPixelType type) |
318 | 0 | { |
319 | 0 | av_assert2(type == SWS_PIXEL_F32); |
320 | 0 | const SwsOpExec *exec = iter->exec; |
321 | 0 | const int *restrict weights = impl->priv.ptr; |
322 | 0 | const int filter_size = impl->priv.i32[2]; |
323 | 0 | const float scale = 1.0f / SWS_FILTER_SCALE; |
324 | 0 | const int xpos = iter->x; |
325 | 0 | weights += filter_size * iter->x; |
326 | |
|
327 | 0 | block_t xs, ys, zs, ws; |
328 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
329 | 0 | const int offset = exec->in_offset_x[xpos + i]; |
330 | 0 | pixel_t *start0 = bump_ptr(in0, offset); |
331 | 0 | pixel_t *start1 = bump_ptr(in1, offset); |
332 | 0 | pixel_t *start2 = bump_ptr(in2, offset); |
333 | 0 | pixel_t *start3 = bump_ptr(in3, offset); |
334 | |
|
335 | 0 | inter_t sx = 0, sy = 0, sz = 0, sw = 0; |
336 | 0 | for (int j = 0; j < filter_size; j++) { |
337 | 0 | const int weight = weights[j]; |
338 | 0 | if (X) sx += weight * start0[j]; |
339 | 0 | if (Y) sy += weight * start1[j]; |
340 | 0 | if (Z) sz += weight * start2[j]; |
341 | 0 | if (W) sw += weight * start3[j]; |
342 | 0 | } |
343 | |
|
344 | 0 | if (X) xs.f32[i] = (float) sx * scale; |
345 | 0 | if (Y) ys.f32[i] = (float) sy * scale; |
346 | 0 | if (Z) zs.f32[i] = (float) sz * scale; |
347 | 0 | if (W) ws.f32[i] = (float) sw * scale; |
348 | |
|
349 | 0 | weights += filter_size; |
350 | 0 | } |
351 | |
|
352 | 0 | CONTINUE(&xs, &ys, &zs, &ws); |
353 | 0 | } Unexecuted instantiation: uops_backend.c:read_planar_fh_U8 Unexecuted instantiation: uops_backend.c:read_planar_fh_U16 Unexecuted instantiation: uops_backend.c:read_planar_fh_F32 Unexecuted instantiation: uops_backend.c:read_planar_fh_U32 |
354 | | |
355 | | SWS_FOR(PX, READ_PLANAR_FV, DECL_IMPL_READ, read_planar_fv) |
356 | | SWS_FOR(PX, READ_PLANAR_FH, DECL_IMPL_READ, read_planar_fh) |
357 | | SWS_FOR_STRUCT(PX, READ_PLANAR_FV, DECL_ENTRY, .setup = fn(setup_filter_v) ) |
358 | | SWS_FOR_STRUCT(PX, READ_PLANAR_FH, DECL_ENTRY, .setup = fn(setup_filter_h) ) |
359 | | |
360 | | /*************************** |
361 | | * Permutation and copying * |
362 | | ***************************/ |
363 | | |
364 | | DECL_FUNC(permute, const SwsCompMask mask, int num_moves, |
365 | | int8_t d0, int8_t d1, int8_t d2, int8_t d3, int8_t d4, int8_t d5, |
366 | | int8_t s0, int8_t s1, int8_t s2, int8_t s3, int8_t s4, int8_t s5) |
367 | 0 | { |
368 | 0 | const int8_t dst[SWS_UOP_MOVE_MAX] = { d0, d1, d2, d3, d4, d5 }; |
369 | 0 | const int8_t src[SWS_UOP_MOVE_MAX] = { s0, s1, s2, s3, s4, s5 }; |
370 | |
|
371 | 0 | pixel_t *ptr[5] = { NULL, x, y, z, w }; |
372 | 0 | for (int n = 0; n < num_moves; n++) |
373 | 0 | ptr[dst[n] + 1] = ptr[src[n] + 1]; |
374 | | |
375 | | /* The unneeded registers may still alias the used ones, so point them |
376 | | * back at the stack to avoid collisions */ |
377 | 0 | block_t xx, yy, zz, ww; |
378 | 0 | CONTINUE(X ? ptr[1] : xx.px, |
379 | 0 | Y ? ptr[2] : yy.px, |
380 | 0 | Z ? ptr[3] : zz.px, |
381 | 0 | W ? ptr[4] : ww.px); |
382 | 0 | } Unexecuted instantiation: uops_backend.c:permute_U8 Unexecuted instantiation: uops_backend.c:permute_U16 Unexecuted instantiation: uops_backend.c:permute_U32 Unexecuted instantiation: uops_backend.c:permute_F32 |
383 | | |
384 | | DECL_FUNC(copy, const SwsCompMask mask, int num_moves, |
385 | | int8_t d0, int8_t d1, int8_t d2, int8_t d3, int8_t d4, int8_t d5, |
386 | | int8_t s0, int8_t s1, int8_t s2, int8_t s3, int8_t s4, int8_t s5) |
387 | 0 | { |
388 | 0 | const size_t block_size = SWS_BLOCK_SIZE * sizeof(pixel_t); |
389 | 0 | const int8_t dst[SWS_UOP_MOVE_MAX] = { d0, d1, d2, d3, d4, d5 }; |
390 | 0 | const int8_t src[SWS_UOP_MOVE_MAX] = { s0, s1, s2, s3, s4, s5 }; |
391 | |
|
392 | 0 | block_t data[5]; |
393 | 0 | memcpy(&data[1].px, x, block_size); |
394 | 0 | memcpy(&data[2].px, y, block_size); |
395 | 0 | memcpy(&data[3].px, z, block_size); |
396 | 0 | memcpy(&data[4].px, w, block_size); |
397 | |
|
398 | 0 | for (int n = 0; n < num_moves; n++) |
399 | 0 | data[dst[n] + 1] = data[src[n] + 1]; |
400 | |
|
401 | 0 | memcpy(x, &data[1].px, block_size); |
402 | 0 | memcpy(y, &data[2].px, block_size); |
403 | 0 | memcpy(z, &data[3].px, block_size); |
404 | 0 | memcpy(w, &data[4].px, block_size); |
405 | |
|
406 | 0 | CONTINUE(x, y, z, w); |
407 | 0 | } Unexecuted instantiation: uops_backend.c:copy_U8 Unexecuted instantiation: uops_backend.c:copy_U16 Unexecuted instantiation: uops_backend.c:copy_U32 Unexecuted instantiation: uops_backend.c:copy_F32 |
408 | | |
409 | | SWS_FOR(PX, PERMUTE, DECL_IMPL, permute) |
410 | | SWS_FOR(PX, COPY, DECL_IMPL, copy) |
411 | | SWS_FOR_STRUCT(PX, PERMUTE, DECL_ENTRY) |
412 | | SWS_FOR_STRUCT(PX, COPY, DECL_ENTRY) |
413 | | |
414 | | /********************* |
415 | | * Format conversion * |
416 | | *********************/ |
417 | | |
418 | | #define DECL_CAST(DST, dst) \ |
419 | | DECL_FUNC(to_##dst, const SwsCompMask mask) \ |
420 | 0 | { \ |
421 | 0 | block_t xx, yy, zz, ww; \ |
422 | 0 | \ |
423 | 0 | SWS_LOOP \ |
424 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { \ |
425 | 0 | if (X) xx.dst[i] = x[i]; \ |
426 | 0 | if (Y) yy.dst[i] = y[i]; \ |
427 | 0 | if (Z) zz.dst[i] = z[i]; \ |
428 | 0 | if (W) ww.dst[i] = w[i]; \ |
429 | 0 | } \ |
430 | 0 | \ |
431 | 0 | CONTINUE(&xx, &yy, &zz, &ww); \ |
432 | 0 | } \ Unexecuted instantiation: uops_backend.c:to_u16_U8 Unexecuted instantiation: uops_backend.c:to_u32_U8 Unexecuted instantiation: uops_backend.c:to_f32_U8 Unexecuted instantiation: uops_backend.c:to_u8_U16 Unexecuted instantiation: uops_backend.c:to_u32_U16 Unexecuted instantiation: uops_backend.c:to_f32_U16 Unexecuted instantiation: uops_backend.c:to_u16_U32 Unexecuted instantiation: uops_backend.c:to_f32_U32 Unexecuted instantiation: uops_backend.c:to_u8_F32 Unexecuted instantiation: uops_backend.c:to_u16_F32 Unexecuted instantiation: uops_backend.c:to_u32_F32 Unexecuted instantiation: uops_backend.c:to_u8_U8 Unexecuted instantiation: uops_backend.c:to_u16_U16 Unexecuted instantiation: uops_backend.c:to_u8_U32 Unexecuted instantiation: uops_backend.c:to_u32_U32 Unexecuted instantiation: uops_backend.c:to_f32_F32 |
433 | | \ |
434 | | SWS_FOR(PX, TO_##DST, DECL_IMPL, to_##dst) \ |
435 | | SWS_FOR_STRUCT(PX, TO_##DST, DECL_ENTRY) |
436 | | |
437 | | DECL_CAST(U8, u8) |
438 | | DECL_CAST(U16, u16) |
439 | | DECL_CAST(U32, u32) |
440 | | DECL_CAST(F32, f32) |
441 | | |
442 | | /******************** |
443 | | * Bit manipulation * |
444 | | ********************/ |
445 | | |
446 | | #if !IS_FLOAT |
447 | | DECL_FUNC(lshift, const SwsCompMask mask, const uint8_t amount) |
448 | 0 | { |
449 | 0 | SWS_LOOP |
450 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
451 | 0 | if (X) x[i] <<= amount; |
452 | 0 | if (Y) y[i] <<= amount; |
453 | 0 | if (Z) z[i] <<= amount; |
454 | 0 | if (W) w[i] <<= amount; |
455 | 0 | } |
456 | |
|
457 | 0 | CONTINUE(x, y, z, w); |
458 | 0 | } Unexecuted instantiation: uops_backend.c:lshift_U16 Unexecuted instantiation: uops_backend.c:lshift_U32 Unexecuted instantiation: uops_backend.c:lshift_U8 |
459 | | |
460 | | DECL_FUNC(rshift, const SwsCompMask mask, const uint8_t amount) |
461 | 0 | { |
462 | 0 | SWS_LOOP |
463 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
464 | 0 | if (X) x[i] >>= amount; |
465 | 0 | if (Y) y[i] >>= amount; |
466 | 0 | if (Z) z[i] >>= amount; |
467 | 0 | if (W) w[i] >>= amount; |
468 | 0 | } |
469 | |
|
470 | 0 | CONTINUE(x, y, z, w); |
471 | 0 | } Unexecuted instantiation: uops_backend.c:rshift_U16 Unexecuted instantiation: uops_backend.c:rshift_U8 Unexecuted instantiation: uops_backend.c:rshift_U32 |
472 | | #endif |
473 | | |
474 | | SWS_FOR(PX, LSHIFT, DECL_IMPL, lshift) |
475 | | SWS_FOR(PX, RSHIFT, DECL_IMPL, rshift) |
476 | | |
477 | | SWS_FOR_STRUCT(PX, LSHIFT, DECL_ENTRY) |
478 | | SWS_FOR_STRUCT(PX, RSHIFT, DECL_ENTRY) |
479 | | |
480 | | #ifdef PIXEL_SWAP |
481 | | DECL_FUNC(swap_bytes, const SwsCompMask mask) |
482 | 0 | { |
483 | 0 | SWS_LOOP |
484 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
485 | 0 | if (X) x[i] = PIXEL_SWAP(x[i]); |
486 | 0 | if (Y) y[i] = PIXEL_SWAP(y[i]); |
487 | 0 | if (Z) z[i] = PIXEL_SWAP(z[i]); |
488 | 0 | if (W) w[i] = PIXEL_SWAP(w[i]); |
489 | 0 | } |
490 | |
|
491 | 0 | CONTINUE(x, y, z, w); |
492 | 0 | } Unexecuted instantiation: uops_backend.c:swap_bytes_U16 Unexecuted instantiation: uops_backend.c:swap_bytes_U32 |
493 | | #endif /* PIXEL_SWAP */ |
494 | | |
495 | | SWS_FOR(PX, SWAP_BYTES, DECL_IMPL, swap_bytes) |
496 | | SWS_FOR_STRUCT(PX, SWAP_BYTES, DECL_ENTRY) |
497 | | |
498 | | #ifdef PIXEL_MAX |
499 | | DECL_FUNC(expand_bit, const SwsCompMask mask) |
500 | 0 | { |
501 | 0 | SWS_LOOP |
502 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
503 | 0 | if (X) x[i] = x[i] ? PIXEL_MAX : 0; |
504 | 0 | if (Y) y[i] = y[i] ? PIXEL_MAX : 0; |
505 | 0 | if (Z) z[i] = z[i] ? PIXEL_MAX : 0; |
506 | 0 | if (W) w[i] = w[i] ? PIXEL_MAX : 0; |
507 | 0 | } |
508 | |
|
509 | 0 | CONTINUE(x, y, z, w); |
510 | 0 | } Unexecuted instantiation: uops_backend.c:expand_bit_U8 Unexecuted instantiation: uops_backend.c:expand_bit_U16 Unexecuted instantiation: uops_backend.c:expand_bit_U32 |
511 | | #endif |
512 | | |
513 | | #if BIT_DEPTH == 8 |
514 | | DECL_FUNC(expand_pair, const SwsCompMask mask) |
515 | 0 | { |
516 | 0 | block_t x16, y16, z16, w16; |
517 | |
|
518 | 0 | SWS_LOOP |
519 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
520 | 0 | if (X) x16.u16[i] = x[i] << 8 | x[i]; |
521 | 0 | if (Y) y16.u16[i] = y[i] << 8 | y[i]; |
522 | 0 | if (Z) z16.u16[i] = z[i] << 8 | z[i]; |
523 | 0 | if (W) w16.u16[i] = w[i] << 8 | w[i]; |
524 | 0 | } |
525 | |
|
526 | 0 | CONTINUE(&x16, &y16, &z16, &w16); |
527 | 0 | } |
528 | | |
529 | | DECL_FUNC(expand_quad, const SwsCompMask mask) |
530 | 0 | { |
531 | 0 | block_t x32, y32, z32, w32; |
532 | 0 |
|
533 | 0 | SWS_LOOP |
534 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
535 | 0 | if (X) x32.u32[i] = (uint32_t) x[i] << 24 | x[i] << 16 | x[i] << 8 | x[i]; |
536 | 0 | if (Y) y32.u32[i] = (uint32_t) y[i] << 24 | y[i] << 16 | y[i] << 8 | y[i]; |
537 | 0 | if (Z) z32.u32[i] = (uint32_t) z[i] << 24 | z[i] << 16 | z[i] << 8 | z[i]; |
538 | 0 | if (W) w32.u32[i] = (uint32_t) w[i] << 24 | w[i] << 16 | w[i] << 8 | w[i]; |
539 | 0 | } |
540 | 0 |
|
541 | 0 | CONTINUE(&x32, &y32, &z32, &w32); |
542 | 0 | } |
543 | | #endif /* BIT_DEPTH == 8 */ |
544 | | |
545 | | SWS_FOR(PX, EXPAND_BIT, DECL_IMPL, expand_bit) |
546 | | SWS_FOR(PX, EXPAND_PAIR, DECL_IMPL, expand_pair) |
547 | | SWS_FOR(PX, EXPAND_QUAD, DECL_IMPL, expand_quad) |
548 | | SWS_FOR_STRUCT(PX, EXPAND_BIT, DECL_ENTRY) |
549 | | SWS_FOR_STRUCT(PX, EXPAND_PAIR, DECL_ENTRY) |
550 | | SWS_FOR_STRUCT(PX, EXPAND_QUAD, DECL_ENTRY) |
551 | | |
552 | | /************************* |
553 | | * Packing and unpacking * |
554 | | ************************/ |
555 | | |
556 | | #if !IS_FLOAT |
557 | | DECL_FUNC(unpack, const SwsCompMask mask, |
558 | | const uint8_t bx, const uint8_t by, |
559 | | const uint8_t bz, const uint8_t bw) |
560 | 0 | { |
561 | 0 | const uint8_t sx = bw + bz + by; |
562 | 0 | const uint8_t sy = bw + bz; |
563 | 0 | const uint8_t sz = bw; |
564 | 0 | const uint8_t sw = 0; |
565 | |
|
566 | 0 | const pixel_t mx = (1 << bx) - 1; |
567 | 0 | const pixel_t my = (1 << by) - 1; |
568 | 0 | const pixel_t mz = (1 << bz) - 1; |
569 | 0 | const pixel_t mw = (1 << bw) - 1; |
570 | |
|
571 | 0 | SWS_LOOP |
572 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
573 | 0 | const pixel_t val = x[i]; |
574 | 0 | if (X) x[i] = (val >> sx) & mx; |
575 | 0 | if (Y) y[i] = (val >> sy) & my; |
576 | 0 | if (Z) z[i] = (val >> sz) & mz; |
577 | 0 | if (W) w[i] = (val >> sw) & mw; |
578 | 0 | } |
579 | |
|
580 | 0 | CONTINUE(x, y, z, w); |
581 | 0 | } Unexecuted instantiation: uops_backend.c:unpack_U8 Unexecuted instantiation: uops_backend.c:unpack_U16 Unexecuted instantiation: uops_backend.c:unpack_U32 |
582 | | |
583 | | DECL_FUNC(pack, const SwsCompMask mask, |
584 | | const uint8_t bx, const uint8_t by, |
585 | | const uint8_t bz, const uint8_t bw) |
586 | 0 | { |
587 | 0 | const uint8_t sx = bw + bz + by; |
588 | 0 | const uint8_t sy = bw + bz; |
589 | 0 | const uint8_t sz = bw; |
590 | 0 | const uint8_t sw = 0; |
591 | |
|
592 | 0 | SWS_LOOP |
593 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
594 | 0 | pixel_t val = 0; |
595 | 0 | if (X) val |= x[i] << sx; |
596 | 0 | if (Y) val |= y[i] << sy; |
597 | 0 | if (Z) val |= z[i] << sz; |
598 | 0 | if (W) val |= w[i] << sw; |
599 | 0 | x[i] = val; |
600 | 0 | } |
601 | |
|
602 | 0 | CONTINUE(x, y, z, w); |
603 | 0 | } Unexecuted instantiation: uops_backend.c:pack_U8 Unexecuted instantiation: uops_backend.c:pack_U16 Unexecuted instantiation: uops_backend.c:pack_U32 |
604 | | #endif /* !IS_FLOAT */ |
605 | | |
606 | | SWS_FOR(PX, UNPACK, DECL_IMPL, unpack) |
607 | | SWS_FOR(PX, PACK, DECL_IMPL, pack) |
608 | | SWS_FOR_STRUCT(PX, UNPACK, DECL_ENTRY) |
609 | | SWS_FOR_STRUCT(PX, PACK, DECL_ENTRY) |
610 | | |
611 | | /*********************** |
612 | | * Pixel data clearing * |
613 | | ***********************/ |
614 | | |
615 | | #ifdef PIXEL_MAX |
616 | | DECL_FUNC(clear, const SwsCompMask mask, const SwsCompMask one, |
617 | | const SwsCompMask zero) |
618 | 0 | { |
619 | 0 | #define ONE(N) SWS_COMP_TEST(one, N) |
620 | 0 | #define ZERO(N) SWS_COMP_TEST(zero, N) |
621 | 0 | const pixel_t cx = ONE(0) ? PIXEL_MAX : ZERO(0) ? 0 : impl->priv.px[0]; |
622 | 0 | const pixel_t cy = ONE(1) ? PIXEL_MAX : ZERO(1) ? 0 : impl->priv.px[1]; |
623 | 0 | const pixel_t cz = ONE(2) ? PIXEL_MAX : ZERO(2) ? 0 : impl->priv.px[2]; |
624 | 0 | const pixel_t cw = ONE(3) ? PIXEL_MAX : ZERO(3) ? 0 : impl->priv.px[3]; |
625 | |
|
626 | 0 | SWS_LOOP |
627 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
628 | 0 | if (X) x[i] = cx; |
629 | 0 | if (Y) y[i] = cy; |
630 | 0 | if (Z) z[i] = cz; |
631 | 0 | if (W) w[i] = cw; |
632 | 0 | } |
633 | |
|
634 | 0 | CONTINUE(x, y, z, w); |
635 | 0 | } Unexecuted instantiation: uops_backend.c:clear_U8 Unexecuted instantiation: uops_backend.c:clear_U16 Unexecuted instantiation: uops_backend.c:clear_U32 |
636 | | #endif |
637 | | |
638 | | SWS_FOR(PX, CLEAR, DECL_IMPL, clear) |
639 | | SWS_FOR_STRUCT(PX, CLEAR, DECL_ENTRY, .setup = ff_sws_setup_vec4) |
640 | | |
641 | | /************************* |
642 | | * Arithmetic operations * |
643 | | *************************/ |
644 | | |
645 | | DECL_FUNC(scale, const SwsCompMask mask) |
646 | 0 | { |
647 | 0 | const pixel_t scale = impl->priv.px[0]; |
648 | |
|
649 | 0 | SWS_LOOP |
650 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
651 | 0 | if (X) x[i] *= scale; |
652 | 0 | if (Y) y[i] *= scale; |
653 | 0 | if (Z) z[i] *= scale; |
654 | 0 | if (W) w[i] *= scale; |
655 | 0 | } |
656 | |
|
657 | 0 | CONTINUE(x, y, z, w); |
658 | 0 | } Unexecuted instantiation: uops_backend.c:scale_U8 Unexecuted instantiation: uops_backend.c:scale_U16 Unexecuted instantiation: uops_backend.c:scale_U32 Unexecuted instantiation: uops_backend.c:scale_F32 |
659 | | |
660 | | DECL_FUNC(add, const SwsCompMask mask) |
661 | 0 | { |
662 | 0 | SWS_LOOP |
663 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
664 | 0 | if (X) x[i] += impl->priv.px[0]; |
665 | 0 | if (Y) y[i] += impl->priv.px[1]; |
666 | 0 | if (Z) z[i] += impl->priv.px[2]; |
667 | 0 | if (W) w[i] += impl->priv.px[3]; |
668 | 0 | } |
669 | |
|
670 | 0 | CONTINUE(x, y, z, w); |
671 | 0 | } Unexecuted instantiation: uops_backend.c:add_F32 Unexecuted instantiation: uops_backend.c:add_U8 Unexecuted instantiation: uops_backend.c:add_U16 Unexecuted instantiation: uops_backend.c:add_U32 |
672 | | |
673 | | DECL_FUNC(min, const SwsCompMask mask) |
674 | 0 | { |
675 | 0 | SWS_LOOP |
676 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
677 | 0 | if (X) x[i] = FFMIN(x[i], impl->priv.px[0]); |
678 | 0 | if (Y) y[i] = FFMIN(y[i], impl->priv.px[1]); |
679 | 0 | if (Z) z[i] = FFMIN(z[i], impl->priv.px[2]); |
680 | 0 | if (W) w[i] = FFMIN(w[i], impl->priv.px[3]); |
681 | 0 | } |
682 | |
|
683 | 0 | CONTINUE(x, y, z, w); |
684 | 0 | } Unexecuted instantiation: uops_backend.c:min_F32 Unexecuted instantiation: uops_backend.c:min_U8 Unexecuted instantiation: uops_backend.c:min_U16 Unexecuted instantiation: uops_backend.c:min_U32 |
685 | | |
686 | | DECL_FUNC(max, const SwsCompMask mask) |
687 | 0 | { |
688 | 0 | SWS_LOOP |
689 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
690 | 0 | if (X) x[i] = FFMAX(x[i], impl->priv.px[0]); |
691 | 0 | if (Y) y[i] = FFMAX(y[i], impl->priv.px[1]); |
692 | 0 | if (Z) z[i] = FFMAX(z[i], impl->priv.px[2]); |
693 | 0 | if (W) w[i] = FFMAX(w[i], impl->priv.px[3]); |
694 | 0 | } |
695 | |
|
696 | 0 | CONTINUE(x, y, z, w); |
697 | 0 | } Unexecuted instantiation: uops_backend.c:max_F32 Unexecuted instantiation: uops_backend.c:max_U8 Unexecuted instantiation: uops_backend.c:max_U16 Unexecuted instantiation: uops_backend.c:max_U32 |
698 | | |
699 | | SWS_FOR(PX, SCALE, DECL_IMPL, scale) |
700 | | SWS_FOR(PX, ADD, DECL_IMPL, add) |
701 | | SWS_FOR(PX, MIN, DECL_IMPL, min) |
702 | | SWS_FOR(PX, MAX, DECL_IMPL, max) |
703 | | SWS_FOR_STRUCT(PX, SCALE, DECL_ENTRY, .setup = ff_sws_setup_scalar ) |
704 | | SWS_FOR_STRUCT(PX, ADD, DECL_ENTRY, .setup = ff_sws_setup_vec4 ) |
705 | | SWS_FOR_STRUCT(PX, MIN, DECL_ENTRY, .setup = ff_sws_setup_vec4 ) |
706 | | SWS_FOR_STRUCT(PX, MAX, DECL_ENTRY, .setup = ff_sws_setup_vec4 ) |
707 | | |
708 | | /************* |
709 | | * Dithering * |
710 | | *************/ |
711 | | |
712 | | DECL_SETUP(setup_dither, params, out) |
713 | 0 | { |
714 | 0 | const SwsUOp *uop = params->uop; |
715 | 0 | const SwsDitherUOp *dither = &uop->par.dither; |
716 | 0 | const int size = 1 << dither->size_log2; |
717 | 0 | if (size >= SWS_BLOCK_SIZE) { |
718 | | /* No extra padding needed */ |
719 | 0 | out->priv.ptr = av_refstruct_ref(uop->data.ptr); |
720 | 0 | out->free = ff_op_priv_unref; |
721 | 0 | return 0; |
722 | 0 | } |
723 | | |
724 | 0 | const int stride = FFMAX(size, SWS_BLOCK_SIZE); |
725 | 0 | const int height = ff_sws_dither_height(dither); |
726 | 0 | pixel_t *matrix = av_malloc(sizeof(pixel_t) * height * stride); |
727 | 0 | if (!matrix) |
728 | 0 | return AVERROR(ENOMEM); |
729 | 0 | out->priv.ptr = matrix; |
730 | 0 | out->free = ff_op_priv_free; |
731 | | |
732 | | /* Pad to multiple of block size. We don't need extra padding for the |
733 | | * height because ff_sws_dither_height() already includes any padding |
734 | | * necessary for the y_offset */ |
735 | 0 | for (int y = 0; y < height; y++) { |
736 | 0 | pixel_t *row = &matrix[y * stride]; |
737 | 0 | for (int x = 0; x < size; x++) |
738 | 0 | row[x] = uop->data.ptr[y * size + x].px; |
739 | 0 | for (int x = size; x < stride; x++) |
740 | 0 | row[x] = row[x % size]; |
741 | 0 | } |
742 | |
|
743 | 0 | return 0; |
744 | 0 | } Unexecuted instantiation: uops_backend.c:setup_dither_F32 Unexecuted instantiation: uops_backend.c:setup_dither_U8 Unexecuted instantiation: uops_backend.c:setup_dither_U16 Unexecuted instantiation: uops_backend.c:setup_dither_U32 |
745 | | |
746 | | DECL_FUNC(dither, const SwsCompMask mask, |
747 | | const uint8_t off0, const uint8_t off1, |
748 | | const uint8_t off2, const uint8_t off3, |
749 | | const uint8_t size_log2) |
750 | 0 | { |
751 | 0 | const int size = 1 << size_log2; |
752 | 0 | const int stride = FFMAX(size, SWS_BLOCK_SIZE); |
753 | |
|
754 | 0 | const pixel_t *matrix = impl->priv.ptr; |
755 | 0 | matrix += (iter->y & (size - 1)) * stride; |
756 | 0 | matrix += (iter->x & (size - 1)) & ~(SWS_BLOCK_SIZE - 1); |
757 | |
|
758 | 0 | const pixel_t *const row0 = &matrix[off0 * stride]; |
759 | 0 | const pixel_t *const row1 = &matrix[off1 * stride]; |
760 | 0 | const pixel_t *const row2 = &matrix[off2 * stride]; |
761 | 0 | const pixel_t *const row3 = &matrix[off3 * stride]; |
762 | |
|
763 | 0 | SWS_LOOP |
764 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
765 | 0 | if (X) x[i] += row0[i]; |
766 | 0 | if (Y) y[i] += row1[i]; |
767 | 0 | if (Z) z[i] += row2[i]; |
768 | 0 | if (W) w[i] += row3[i]; |
769 | 0 | } |
770 | |
|
771 | 0 | CONTINUE(x, y, z, w); |
772 | 0 | } Unexecuted instantiation: uops_backend.c:dither_F32 Unexecuted instantiation: uops_backend.c:dither_U8 Unexecuted instantiation: uops_backend.c:dither_U16 Unexecuted instantiation: uops_backend.c:dither_U32 |
773 | | |
774 | | SWS_FOR(PX, DITHER, DECL_IMPL, dither) |
775 | | SWS_FOR_STRUCT(PX, DITHER, DECL_ENTRY, .setup = fn(setup_dither) ) |
776 | | |
777 | | /********************* |
778 | | * Linear operations * |
779 | | *********************/ |
780 | | |
781 | | typedef struct { |
782 | | /* Stored in split form for convenience */ |
783 | | pixel_t m[4][4]; |
784 | | pixel_t k[4]; |
785 | | } fn(LinCoeffs); |
786 | | |
787 | | DECL_SETUP(setup_linear, params, out) |
788 | 0 | { |
789 | 0 | const SwsUOp *uop = params->uop; |
790 | 0 | fn(LinCoeffs) c; |
791 | |
|
792 | 0 | for (int i = 0; i < 4; i++) { |
793 | 0 | for (int j = 0; j < 4; j++) |
794 | 0 | c.m[i][j] = uop->data.mat4[i][j].px; |
795 | 0 | c.k[i] = uop->data.mat4[i][4].px; |
796 | 0 | } |
797 | |
|
798 | 0 | out->priv.ptr = av_memdup(&c, sizeof(c)); |
799 | 0 | out->free = ff_op_priv_free; |
800 | 0 | return out->priv.ptr ? 0 : AVERROR(ENOMEM); |
801 | 0 | } Unexecuted instantiation: uops_backend.c:setup_linear_F32 Unexecuted instantiation: uops_backend.c:setup_linear_U8 Unexecuted instantiation: uops_backend.c:setup_linear_U16 Unexecuted instantiation: uops_backend.c:setup_linear_U32 |
802 | | |
803 | | /** |
804 | | * Fully general case for a 5x5 linear affine transformation. Should never be |
805 | | * called without constant `mask`. This function will compile down to the |
806 | | * appropriately optimized version for the required subset of operations when |
807 | | * called with a constant mask. |
808 | | */ |
809 | | DECL_FUNC(linear, const SwsCompMask mask, const uint32_t one, const uint32_t zero) |
810 | 0 | { |
811 | 0 | const fn(LinCoeffs) c = *(const fn(LinCoeffs) *) impl->priv.ptr; |
812 | |
|
813 | 0 | SWS_LOOP |
814 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
815 | 0 | const pixel_t xx = x[i]; |
816 | 0 | const pixel_t yy = y[i]; |
817 | 0 | const pixel_t zz = z[i]; |
818 | 0 | const pixel_t ww = w[i]; |
819 | |
|
820 | 0 | #define LIN_VAL(I, J, val) \ |
821 | 0 | ((one & SWS_MASK(I, J)) ? (val) : c.m[I][J] * (val)) |
822 | |
|
823 | 0 | #define LIN_ROW(I, var) do { \ |
824 | 0 | var[i] = (zero & SWS_MASK(I, 4)) ? 0 : c.k[I]; \ |
825 | 0 | if (!(zero & SWS_MASK(I, 0))) var[i] += LIN_VAL(I, 0, xx); \ |
826 | 0 | if (!(zero & SWS_MASK(I, 1))) var[i] += LIN_VAL(I, 1, yy); \ |
827 | 0 | if (!(zero & SWS_MASK(I, 2))) var[i] += LIN_VAL(I, 2, zz); \ |
828 | 0 | if (!(zero & SWS_MASK(I, 3))) var[i] += LIN_VAL(I, 3, ww); \ |
829 | 0 | } while (0) |
830 | |
|
831 | 0 | if (X) LIN_ROW(0, x); |
832 | 0 | if (Y) LIN_ROW(1, y); |
833 | 0 | if (Z) LIN_ROW(2, z); |
834 | 0 | if (W) LIN_ROW(3, w); |
835 | 0 | } |
836 | |
|
837 | 0 | CONTINUE(x, y, z, w); |
838 | 0 | } Unexecuted instantiation: uops_backend.c:linear_F32 Unexecuted instantiation: uops_backend.c:linear_U8 Unexecuted instantiation: uops_backend.c:linear_U16 Unexecuted instantiation: uops_backend.c:linear_U32 |
839 | | |
840 | | SWS_FOR(PX, LINEAR, DECL_IMPL, linear) |
841 | | SWS_FOR_STRUCT(PX, LINEAR, DECL_ENTRY, .setup = fn(setup_linear) ) |
842 | | |
843 | | /****************** |
844 | | * Look-up tables * |
845 | | ******************/ |
846 | | |
847 | | DECL_SETUP(setup_lut3d, params, out) |
848 | 0 | { |
849 | 0 | const SwsLut3D *lut = params->uop->data.lut3d; |
850 | 0 | out->priv.ptr = (void *) av_refstruct_ref_c(lut); |
851 | 0 | out->free = ff_op_priv_unref; |
852 | 0 | return 0; |
853 | 0 | } Unexecuted instantiation: uops_backend.c:setup_lut3d_F32 Unexecuted instantiation: uops_backend.c:setup_lut3d_U8 Unexecuted instantiation: uops_backend.c:setup_lut3d_U16 Unexecuted instantiation: uops_backend.c:setup_lut3d_U32 |
854 | | |
855 | | #if IS_FLOAT |
856 | | av_always_inline static vec3_t fn(vec3)(v3u16_t v) |
857 | 0 | { |
858 | 0 | return (vec3_t) { v.x, v.y, v.z }; |
859 | 0 | } |
860 | | |
861 | 0 | #define lerp(a, b, w) ((a) + (w) * ((pixel_t) (b) - (a))) |
862 | | |
863 | | av_always_inline static |
864 | | vec3_t fn(lerp3)(vec3_t a, vec3_t b, pixel_t w) |
865 | 0 | { |
866 | 0 | return (vec3_t) { |
867 | 0 | lerp(a.x, b.x, w), |
868 | 0 | lerp(a.y, b.y, w), |
869 | 0 | lerp(a.z, b.z, w), |
870 | 0 | }; |
871 | 0 | } |
872 | | |
873 | | av_always_inline static |
874 | | vec3_t fn(lut3d_static)(const SwsLut3D *restrict lut3d, vec3_t rgb) |
875 | 0 | { |
876 | 0 | const int r_base = (int) rgb.x; |
877 | 0 | const int g_base = (int) rgb.y; |
878 | 0 | const int b_base = (int) rgb.z; |
879 | |
|
880 | 0 | int off0 = (r_base < INPUT_LUT_SIZE - 1); |
881 | 0 | int off1 = (g_base < INPUT_LUT_SIZE - 1) * INPUT_LUT_SIZE; |
882 | 0 | int off2 = (b_base < INPUT_LUT_SIZE - 1) * INPUT_LUT_SIZE * INPUT_LUT_SIZE; |
883 | 0 | pixel_t f0 = rgb.x - r_base; |
884 | 0 | pixel_t f1 = rgb.y - g_base; |
885 | 0 | pixel_t f2 = rgb.z - b_base; |
886 | | |
887 | | /* Sort offsets descending by relative weight */ |
888 | 0 | if (f0 < f1) { |
889 | 0 | FFSWAP(pixel_t, f0, f1); |
890 | 0 | FFSWAP(int, off0, off1); |
891 | 0 | } |
892 | 0 | if (f0 < f2) { |
893 | 0 | FFSWAP(pixel_t, f0, f2); |
894 | 0 | FFSWAP(int, off0, off2); |
895 | 0 | } |
896 | 0 | if (f1 < f2) { |
897 | 0 | FFSWAP(pixel_t, f1, f2); |
898 | 0 | FFSWAP(int, off1, off2); |
899 | 0 | } |
900 | | |
901 | | /* Tetrahedral interpolation */ |
902 | 0 | const pixel_t w0 = 1 - f0; |
903 | 0 | const pixel_t w1 = f0 - f1; |
904 | 0 | const pixel_t w2 = f1 - f2; |
905 | 0 | const pixel_t w3 = f2; |
906 | |
|
907 | 0 | const v3u16_t *restrict base = &lut3d->input[b_base][g_base][r_base]; |
908 | 0 | const vec3_t v0 = fn(vec3)(base[0]); |
909 | 0 | const vec3_t v1 = fn(vec3)(base[off0]); |
910 | 0 | const vec3_t v2 = fn(vec3)(base[off0 + off1]); |
911 | 0 | const vec3_t v3 = fn(vec3)(base[off0 + off1 + off2]); |
912 | |
|
913 | 0 | return (vec3_t) { |
914 | 0 | w0 * v0.x + w1 * v1.x + w2 * v2.x + w3 * v3.x, |
915 | 0 | w0 * v0.y + w1 * v1.y + w2 * v2.y + w3 * v3.y, |
916 | 0 | w0 * v0.z + w1 * v1.z + w2 * v2.z + w3 * v3.z, |
917 | 0 | }; |
918 | 0 | } |
919 | | |
920 | | av_always_inline static |
921 | | vec3_t fn(lut3d_dynamic)(const SwsLut3D *restrict lut3d, vec3_t rgb) |
922 | 0 | { |
923 | 0 | rgb.x *= (TONE_LUT_SIZE - 1) / (pixel_t) UINT16_MAX; |
924 | | |
925 | | /* Linear interpolation */ |
926 | 0 | const int Ix = (int) rgb.x; |
927 | 0 | const pixel_t If = rgb.x - Ix; |
928 | |
|
929 | 0 | const v2u16_t a = lut3d->tone_map[Ix]; |
930 | 0 | const v2u16_t b = lut3d->tone_map[Ix + 1]; |
931 | |
|
932 | 0 | const pixel_t k = lerp(a.y, b.y, If); |
933 | 0 | const pixel_t bias = (1 << 15) - k; |
934 | 0 | const pixel_t scale = k / (pixel_t) (1 << 15); |
935 | |
|
936 | 0 | rgb.x = lerp(a.x, b.x, If); |
937 | 0 | rgb.y = bias + scale * rgb.y; |
938 | 0 | rgb.z = bias + scale * rgb.z; |
939 | | |
940 | | /* Re-scale to output LUT size */ |
941 | 0 | rgb.x *= (OUTPUT_LUT_SIZE_I - 1) / (pixel_t) UINT16_MAX; |
942 | 0 | rgb.y *= (OUTPUT_LUT_SIZE_PT - 1) / (pixel_t) UINT16_MAX; |
943 | 0 | rgb.z *= (OUTPUT_LUT_SIZE_PT - 1) / (pixel_t) UINT16_MAX; |
944 | | |
945 | | /* Trilinear interpolation */ |
946 | 0 | const int lo0 = (int) rgb.x; |
947 | 0 | const int lo1 = (int) rgb.y; |
948 | 0 | const int lo2 = (int) rgb.z; |
949 | |
|
950 | 0 | const int hi0 = FFMIN(lo0 + 1, OUTPUT_LUT_SIZE_I - 1); |
951 | 0 | const int hi1 = FFMIN(lo1 + 1, OUTPUT_LUT_SIZE_PT - 1); |
952 | 0 | const int hi2 = FFMIN(lo2 + 1, OUTPUT_LUT_SIZE_PT - 1); |
953 | |
|
954 | 0 | const pixel_t w0 = rgb.x - lo0; |
955 | 0 | const vec3_t c000 = fn(vec3)(lut3d->output[lo2][lo1][lo0]); |
956 | 0 | const vec3_t c001 = fn(vec3)(lut3d->output[lo2][lo1][hi0]); |
957 | 0 | const vec3_t c00 = fn(lerp3)(c000, c001, w0); |
958 | 0 | const vec3_t c010 = fn(vec3)(lut3d->output[lo2][hi1][lo0]); |
959 | 0 | const vec3_t c011 = fn(vec3)(lut3d->output[lo2][hi1][hi0]); |
960 | 0 | const vec3_t c01 = fn(lerp3)(c010, c011, w0); |
961 | 0 | const vec3_t c100 = fn(vec3)(lut3d->output[hi2][lo1][lo0]); |
962 | 0 | const vec3_t c101 = fn(vec3)(lut3d->output[hi2][lo1][hi0]); |
963 | 0 | const vec3_t c10 = fn(lerp3)(c100, c101, w0); |
964 | 0 | const vec3_t c110 = fn(vec3)(lut3d->output[hi2][hi1][lo0]); |
965 | 0 | const vec3_t c111 = fn(vec3)(lut3d->output[hi2][hi1][hi0]); |
966 | 0 | const vec3_t c11 = fn(lerp3)(c110, c111, w0); |
967 | |
|
968 | 0 | const pixel_t w1 = rgb.y - lo1; |
969 | 0 | const vec3_t c0 = fn(lerp3)(c00, c01, w1); |
970 | 0 | const vec3_t c1 = fn(lerp3)(c10, c11, w1); |
971 | |
|
972 | 0 | const pixel_t w2 = rgb.z - lo2; |
973 | 0 | return fn(lerp3)(c0, c1, w2); |
974 | 0 | } |
975 | | |
976 | | DECL_FUNC(lut3d, const SwsCompMask mask, const int dynamic) |
977 | 0 | { |
978 | 0 | const SwsLut3D *restrict lut3d = impl->priv.ptr; |
979 | |
|
980 | 0 | SWS_LOOP |
981 | 0 | for (int i = 0; i < SWS_BLOCK_SIZE; i++) { |
982 | 0 | vec3_t c = { x[i], y[i], z[i] }; |
983 | 0 | c = fn(lut3d_static)(lut3d, c); |
984 | 0 | if (dynamic) |
985 | 0 | c = fn(lut3d_dynamic)(lut3d, c); |
986 | |
|
987 | 0 | x[i] = c.x; |
988 | 0 | y[i] = c.y; |
989 | 0 | z[i] = c.z; |
990 | 0 | } |
991 | |
|
992 | 0 | CONTINUE(x, y, z, w); |
993 | 0 | } |
994 | | #endif /* IS_FLOAT */ |
995 | | |
996 | | SWS_FOR(PX, LUT_3D, DECL_IMPL, lut3d) |
997 | | SWS_FOR_STRUCT(PX, LUT_3D, DECL_ENTRY, .setup = fn(setup_lut3d) ) |
998 | | |
999 | | #undef PIXEL_MAX |
1000 | | #undef PIXEL_SWAP |
1001 | | #undef pixel_t |
1002 | | #undef inter_t |
1003 | | #undef vec3_t |
1004 | | #undef PX |
1005 | | #undef px |