FFmpeg
Loading...
Searching...
No Matches
uops.c
Go to the documentation of this file.
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 <float.h>
22#include <math.h>
23#include <stdbool.h>
24
25#include "libavutil/avassert.h"
26#include "libavutil/intmath.h"
27#include "libavutil/mem.h"
28#include "libavutil/refstruct.h"
29
30#include "ops.h"
31#include "uops.h"
32#include "uops_list.h"
33#include "swscale_internal.h"
34
35int ff_sws_uop_cmp(const SwsUOp *a, const SwsUOp *b)
36{
37 if (a->type != b->type)
38 return (int) a->type - b->type;
39 if (a->uop != b->uop)
40 return (int) a->uop - b->uop;
41 if (a->mask != b->mask)
42 return (int) a->mask - b->mask;
43 return memcmp(&a->par, &b->par, sizeof(a->par));
44}
45
46static const struct {
47 char abbr[32];
49#define UOP_NAME(OP, ABBR) [OP] = { ABBR },
51#undef UOP_NAME
52};
53
55{
56 AVBPrint bp;
58
59 if (op->type != SWS_PIXEL_NONE)
60 av_bprintf(&bp, "%s_", ff_sws_pixel_type_name(op->type));
61 av_bprintf(&bp, "%s", uop_names[op->uop].abbr);
62
63 if (op->mask)
64 av_bprintf(&bp, "_%s", ff_sws_comp_mask_str(op->mask));
65
66 const SwsUOpParams *par = &op->par;
67 switch (op->uop) {
72 break;
74 av_bprintf(&bp, "_%x_%u_%u", par->shuffle.clear_value,
76 break;
77 case SWS_UOP_LSHIFT:
78 case SWS_UOP_RSHIFT:
79 av_bprintf(&bp, "_%u", par->shift.amount);
80 break;
81 case SWS_UOP_PERMUTE:
82 case SWS_UOP_COPY:
83 av_bprint_chars(&bp, '_', 1);
84 for (int i = 0; i < par->move.num_moves; i++)
85 av_bprint_chars(&bp, "txyzw"[par->move.dst[i] + 1], 1);
86 av_bprint_chars(&bp, '_', 1);
87 for (int i = 0; i < par->move.num_moves; i++)
88 av_bprint_chars(&bp, "txyzw"[par->move.src[i] + 1], 1);
89 break;
90 case SWS_UOP_PACK:
91 case SWS_UOP_UNPACK:
92 av_bprint_chars(&bp, '_', 1);
93 for (int i = 0; i < 4 && par->pack.pattern[i]; i++)
94 av_bprintf(&bp, "%x", par->pack.pattern[i]);
95 break;
96 case SWS_UOP_CLEAR:
97 av_bprint_chars(&bp, '_', 1);
98 for (int i = 0; i < 4; i++) {
99 if (!SWS_COMP_TEST(op->mask, i))
100 continue;
101 else if (SWS_COMP_TEST(par->clear.one, i))
102 av_bprint_chars(&bp, '1', 1);
103 else if (SWS_COMP_TEST(par->clear.zero, i))
104 av_bprint_chars(&bp, '0', 1);
105 else
106 av_bprint_chars(&bp, 'x', 1);
107 }
108 break;
109 case SWS_UOP_LINEAR:
111 for (int i = 0; i < 4; i++) {
112 if (!SWS_COMP_TEST(op->mask, i))
113 continue;
114 av_bprint_chars(&bp, '_', 1);
115 for (int j = 0; j < 5; j++) {
116 if (par->lin.one & SWS_MASK(i, j))
117 av_bprint_chars(&bp, '1', 1);
118 else if (par->lin.zero & SWS_MASK(i, j))
119 av_bprint_chars(&bp, '0', 1);
120 else if (par->lin.exact & SWS_MASK(i, j))
121 av_bprint_chars(&bp, 'X', 1);
122 else
123 av_bprint_chars(&bp, 'x', 1);
124 }
125 }
126 break;
127 case SWS_UOP_DITHER:
128 for (int i = 0; i < 4; i++) {
129 if (SWS_COMP_TEST(op->mask, i))
130 av_bprintf(&bp, "_%d", par->dither.y_offset[i]);
131 }
132 const unsigned size = 1u << par->dither.size_log2;
133 av_bprintf(&bp, "_%ux%u", size, size);
134 break;
135 case SWS_UOP_LUT_3D:
136 av_bprintf(&bp, "_%s", par->lut3d.dynamic ? "dynamic" : "static");
137 break;
138 }
139
141}
142
143static void uop_uninit(SwsUOp *uop)
144{
145 switch (uop->uop) {
146 case SWS_UOP_DITHER:
148 break;
153 break;
154 case SWS_UOP_LUT_3D:
156 break;
157 }
158
159 *uop = (SwsUOp) {0};
160}
161
163{
164 SwsUOpList *ops = *p_ops;
165 if (!ops)
166 return;
167
168 for (int i = 0; i < ops->num_ops; i++)
169 uop_uninit(&ops->ops[i]);
170
171 av_freep(&ops->ops);
172 av_free(ops);
173 *p_ops = NULL;
174}
175
177{
178 return av_mallocz(sizeof(SwsUOpList));
179}
180
182{
183 if (!av_dynarray2_add((void **) &uops->ops, &uops->num_ops,
184 sizeof(*uop), (uint8_t *) uop))
185 {
186 uop_uninit(uop);
187 return AVERROR(ENOMEM);
188 }
189
190 *uop = (SwsUOp) {0};
191 return 0;
192}
193
194void ff_sws_uop_list_remove_at(SwsUOpList *uops, int index, int count)
195{
196 const int end = uops->num_ops - count;
197 av_assert2(index >= 0 && count >= 0 && index + count <= uops->num_ops);
198 for (int i = 0; i < count; i++)
199 uop_uninit(&uops->ops[index + i]);
200 for (int i = index; i < end; i++)
201 uops->ops[i] = uops->ops[i + count];
202 uops->num_ops = end;
203}
204
205void ff_sws_uop_list_print(void *log, int lev, const SwsUOpList *uops)
206{
207 if (av_log_get_level() < lev)
208 return;
209
210 av_log(log, lev, "Compiled micro-ops:\n");
211 for (int i = 0; i < uops->num_ops; i++) {
213 ff_sws_uop_name(&uops->ops[i], name);
214 av_log(log, lev, " %s\n", name);
215 }
216}
217
219{
220 int max_offset = 0;
221 for (int i = 0; i < 4; i++)
222 max_offset = FFMAX(max_offset, dither->y_offset[i]);
223 return (1 << dither->size_log2) + max_offset;
224}
225
226/* Conditionally promotes a pixel type to integer only if allowed by the flags */
228{
230 return type;
231
232 switch (ff_sws_pixel_type_size(type)) {
233 case 1: return SWS_PIXEL_U8;
234 case 2: return SWS_PIXEL_U16;
235 case 4: return SWS_PIXEL_U32;
236 default: break;
237 }
238
239 av_unreachable("Invalid pixel type!");
240 return SWS_PIXEL_NONE;
241}
242
243static int significant_bits_f32(float f)
244{
245 int exp;
246 const uint32_t mant = ldexpf(frexpf(fabsf(f), &exp), FLT_MANT_DIG);
247 return mant ? FLT_MANT_DIG - ff_ctz(mant) : 0;
248}
249
250static bool exact_prod(SwsPixel coef, const SwsOpPad *input)
251{
252 if (ff_sws_pixel_type_is_int(input->type))
253 return true;
254
255 switch (input->type) {
256 case SWS_PIXEL_F32: {
257 const int bits = significant_bits_f32(coef.f32);
258 if (bits <= 1)
259 return true; /* power of two */
260 if (!(input->flags & SWS_COMP_EXACT) || input->min.den != 1 || input->max.den != 1)
261 return false; /* not only integers, or unknown bounds */
262
263 const uint64_t lo = FFABS64U(input->min.num), hi = FFABS64U(input->max.num);
264 const uint64_t max = FFMAX(lo, hi);
265 if (max >= 1ULL << FLT_MANT_DIG)
266 return false;
267 return bits + (max ? av_log2(max) + 1 : 0) <= FLT_MANT_DIG;
268 }
269 }
270
271 av_unreachable("Invalid pixel type!");
272 return false;
273}
274
276{
277 if (!(flags & SWS_UOP_FLAG_FMA))
278 return false;
279 if (!(ctx->flags & SWS_BITEXACT))
280 return true;
281 if (!ff_sws_pixel_type_is_int(op->rw.type))
282 return false;
283
284 const int bits = ff_sws_pixel_type_size(op->rw.type) * 8;
285 const uint64_t max_val = UINT64_MAX >> (64 - bits);
286
287 /* Maximum value representable losslessly as float. Note that this is
288 * currently true only for U8, but that may change if we ever update the
289 * value of SWS_FILTER_SCALE. */
290 return max_val * SWS_FILTER_SCALE <= (1 << 22);
291}
292
294 const SwsOp *op)
295{
296 SwsUOp uop = {
297 .type = op->rw.type,
298 .mask = SWS_COMP_MASK(op->rw.elems > 0, op->rw.elems > 1,
299 op->rw.elems > 2, op->rw.elems > 3),
300 };
301
302 /* Non-filtered reads don't care about the exact pixel contents */
303 if (!op->rw.filter.op)
304 uop.type = pixel_type_to_int(flags, op->rw.type);
305
306 const bool is_read = op->op == SWS_OP_READ;
307 if (op->rw.filter.op) {
308 if (op->op == SWS_OP_WRITE || op->rw.frac || op->rw.mode != SWS_RW_PLANAR)
309 return AVERROR(ENOTSUP);
310 uop.par.filter.type = op->rw.filter.type;
311 uop.data.kernel = av_refstruct_ref(op->rw.filter.kernel);
312 if (op->rw.filter.op == SWS_OP_FILTER_H) {
314 } else if (check_filter_fma(ctx, flags, op)) {
316 } else {
318 }
319 } else if (op->rw.mode == SWS_RW_PACKED && op->rw.elems > 1) {
320 if (op->rw.frac)
321 return AVERROR(ENOTSUP);
323 } else if (op->rw.mode == SWS_RW_PALETTE) {
324 if (!(flags & SWS_UOP_FLAG_READ_PALETTE) || op->rw.frac || !is_read)
325 return AVERROR(ENOTSUP);
327 } else if (op->rw.frac == 3) {
328 uop.uop = is_read ? SWS_UOP_READ_BIT : SWS_UOP_WRITE_BIT;
329 } else if (op->rw.frac == 1) {
331 } else {
332 av_assert0(!op->rw.frac);
334 }
335
336 const int planes = ff_sws_rw_op_planes(op);
337 if (op->op == SWS_OP_READ) {
339 } else {
341 }
342
343 return ff_sws_uop_list_append(ops, &uop);
344}
345
346static int count_idx(const int *arr, size_t size, int val)
347{
348 int num = 0;
349 for (size_t i = 0; i < size; i++) {
350 if (arr[i] == val)
351 num++;
352 }
353
354 return num;
355}
356
358{
359 SwsUOp uop = {
360 .uop = SWS_UOP_PERMUTE,
363 };
364 SwsMoveUOp *par = &uop.par.move;
365
366 /* Mask of components that are not yet satisfied */
367 SwsCompMask todo = uop.mask;
368 for (int i = 0; i < 4; i++) {
369 if (op->swizzle.in[i] == i)
370 todo &= ~SWS_COMP(i);
371 }
372
373 /* Mask of components whose value is required for the final output */
374 SwsCompMask needed = 0;
375 for (int i = 0; i < 4; i++) {
376 if (SWS_OP_NEEDED(op, i))
377 needed |= SWS_COMP(op->swizzle.in[i]);
378 }
379
380 /* Current mapping of registers to components */
381 int idx[4 + 1] = { 0, 1, 2, 3, -1 }; /* +1 for tmp */
382
383 /* Decompose the swizzle mask into a series of register-register moves */
384 while (todo) {
385 int dst = -1, src = -1;
386
387 /* Find next unsatisfied dst <- src move that doesn't clobber a value */
388 for (dst = 0; dst < 4; dst++) {
389 if (!SWS_COMP_TEST(todo, dst))
390 continue; /* already satisfied */
391 const int cur = idx[dst];
392 if (count_idx(idx, FF_ARRAY_ELEMS(idx), cur) == 1 && SWS_COMP_TEST(needed, cur))
393 continue; /* clobbers last remaining, still-needed value */
394 for (src = 0; src < FF_ARRAY_ELEMS(idx); src++) {
395 if (idx[src] == op->swizzle.in[dst]) {
396 /* Prevent read-after-write dependency. */
397 if (par->num_moves > 0 && src == par->dst[par->num_moves - 1])
398 src = par->src[par->num_moves - 1];
399 break;
400 }
401 }
403 todo &= ~SWS_COMP(dst);
404 break;
405 }
406
407 if (dst == 4) {
408 /* Stuck in a cycle, break it by saving to the scratch register */
409 dst = 4;
410 for (src = 0; src < 4; src++) {
411 if (SWS_COMP_TEST(todo, src)) {
412 needed &= ~SWS_COMP(idx[src]);
413 break;
414 }
415 }
416 av_assert1(src < 4);
417 }
418
420 par->dst[par->num_moves] = dst > 3 ? -1 : dst;
421 par->src[par->num_moves] = src > 3 ? -1 : src;
422 par->num_moves++;
423 idx[dst] = idx[src];
424 }
425
426 /* Check for duplicates in the final register map */
427 SwsCompMask seen = 0;
428 for (int i = 0; i < 4; i++) {
429 if (!SWS_COMP_TEST(uop.mask, i))
430 continue;
431 av_assert2(idx[i] >= 0); /* should be no tmp register */
432 const SwsCompMask bit = SWS_COMP(idx[i]);
433 if (seen & bit) {
434 uop.uop = SWS_UOP_COPY;
435 break;
436 }
437 seen |= bit;
438 }
439
440 /* Add any extra unused components to the mask, to prevent generating
441 * duplicate uops like permute_xyz_txy_xyt and permute_xyzw_txy_xyt */
442 for (int i = 0; i < 4; i++) {
443 const SwsCompMask bit = SWS_COMP(i);
444 if (!(seen & bit) && idx[i] == i)
445 uop.mask |= bit;
446 }
447
448 return ff_sws_uop_list_append(ops, &uop);
449}
450
452{
453 SwsUOp uop = {
454 .type = ff_sws_op_input_type(op),
455 .uop = SWS_UOP_DITHER,
456 .par.dither.size_log2 = op->dither.size_log2,
457 };
458
459 if ((flags & SWS_UOP_FLAG_ADD) && op->dither.size_log2 == 0) {
460 /* Constant offset */
461 const SwsPixel val = ff_sws_pixel_from_q64(uop.type, op->dither.matrix[0]);
462 uop.uop = SWS_UOP_ADD;
463 for (int i = 0; i < 4; i++) {
464 if (!SWS_OP_NEEDED(op, i) || op->dither.y_offset[i] < 0)
465 continue;
466 uop.mask |= SWS_COMP(i);
467 uop.data.vec4[i] = val;
468 }
469
470 return ff_sws_uop_list_append(ops, &uop);
471 }
472
473 const int size = 1 << op->dither.size_log2;
474 for (int i = 0; i < 4; i++) {
475 if (!SWS_OP_NEEDED(op, i) || op->dither.y_offset[i] < 0)
476 continue;
477 const uint8_t off = op->dither.y_offset[i] & (size - 1);
478 uop.mask |= SWS_COMP(i);
479 uop.par.dither.y_offset[i] = off;
480 }
481
482 /* Allocate extra rows to allow over-reading for row offsets. Note that
483 * y_offset is currently never larger than 5, so the extra space needed
484 * for this over-allocation is bounded by 5 * size * sizeof(float),
485 * typically 320 bytes for a 16x16 dither matrix. */
486 const int stride = size * sizeof(SwsPixel);
487 const int num_rows = ff_sws_dither_height(&uop.par.dither);
488 SwsPixel *matrix = uop.data.ptr = ff_refstruct_calloc(num_rows, stride);
489 if (!matrix)
490 return AVERROR(ENOMEM);
491
492 for (int i = 0; i < size * size; i++)
493 matrix[i] = ff_sws_pixel_from_q64(uop.type, op->dither.matrix[i]);
494 memcpy(&matrix[size * size], matrix, (num_rows - size) * stride);
495
496 return ff_sws_uop_list_append(ops, &uop);
497}
498
500 SwsUOpFlags flags, const SwsOp *op,
501 const SwsOpPad inputs[4])
502{
503 SwsUOp uop = {
504 .type = ff_sws_op_input_type(op),
505 .uop = SWS_UOP_LINEAR,
506 };
507
508 const SwsPixel one = ff_sws_pixel_from_q64(uop.type, (AVRational64) {1, 1});
509 const uint32_t mask = ff_sws_linear_mask(&op->lin);
510 const bool bitexact = ctx->flags & SWS_BITEXACT;
511 uint32_t exact = 0;
512
513 for (int i = 0; i < 4; i++) {
514 if (!SWS_OP_NEEDED(op, i) || !(mask & SWS_MASK_ROW(i))) {
515 uop.par.lin.zero |= SWS_MASK_ROW(i) ^ SWS_MASK(i, i);
516 uop.par.lin.one |= SWS_MASK(i, i);
517 uop.data.mat4x5[i][i] = one;
518 continue;
519 }
520 uop.mask |= SWS_COMP(i);
521 bool nonzero = (op->lin.m[i][4].num != 0);
522 for (int j = 0; j < 5; j++) {
523 const AVRational64 k = op->lin.m[i][j];
524 const SwsPixel px = ff_sws_pixel_from_q64(uop.type, k);
525 uop.data.mat4x5[i][j] = px;
526 if (k.num == 0)
527 uop.par.lin.zero |= SWS_MASK(i, j);
528 else if (j < 4 && k.num == k.den)
529 uop.par.lin.one |= SWS_MASK(i, j);
530 else if (j < 4 && nonzero && (!bitexact || exact_prod(px, &inputs[j])))
531 exact |= SWS_MASK(i, j);
532 if (k.num != 0)
533 nonzero = true;
534 }
535 }
536
538 /* multiplication by 1 and 0 are always exact by definition */
540 uop.par.lin.exact = exact | uop.par.lin.zero | uop.par.lin.one;
541 }
542
543 return ff_sws_uop_list_append(ops, &uop);
544}
545
547 const SwsOp *op, const SwsOpPad inputs[4])
548{
549 switch (op->op) {
550 case SWS_OP_FILTER_H:
551 case SWS_OP_FILTER_V:
552 return AVERROR(ENOTSUP); /* always handled by subpass splitting */
553 case SWS_OP_READ:
554 case SWS_OP_WRITE:
555 return translate_rw_op(ctx, uops, flags, op);
556 case SWS_OP_SWIZZLE:
557 return translate_swizzle(uops, flags, op);
558 case SWS_OP_DITHER:
559 return translate_dither_op(uops, flags, op);
560 case SWS_OP_LINEAR:
561 return translate_linear_op(ctx, uops, flags, op, inputs);
562 default:
563 break;
564 }
565
566 /* Default handling for "simple" ops */
567 SwsUOp uop = {
568 .uop = SWS_UOP_INVALID,
569 .type = ff_sws_op_input_type(op),
571 };
572
573 switch (op->op) {
574 case SWS_OP_CONVERT:
575 switch (op->convert.to) {
576 case SWS_PIXEL_U8: uop.uop = SWS_UOP_TO_U8; break;
577 case SWS_PIXEL_U16: uop.uop = SWS_UOP_TO_U16; break;
578 case SWS_PIXEL_U32: uop.uop = SWS_UOP_TO_U32; break;
579 case SWS_PIXEL_F32: uop.uop = SWS_UOP_TO_F32; break;
580 }
581 break;
582 case SWS_OP_UNPACK:
583 case SWS_OP_PACK:
585 uop.mask = 0;
586 for (int i = 0; i < 4 && op->pack.pattern[i]; i++) {
587 uop.par.pack.pattern[i] = op->pack.pattern[i];
588 if (op->op == SWS_OP_PACK || SWS_OP_NEEDED(op, i))
589 uop.mask |= SWS_COMP(i);
590 }
591 break;
592 case SWS_OP_LSHIFT:
593 case SWS_OP_RSHIFT:
595 uop.par.shift.amount = op->shift.amount;
596 break;
597 case SWS_OP_CLEAR:
598 uop.uop = SWS_UOP_CLEAR;
599 uop.mask &= op->clear.mask;
600 for (int i = 0; i < 4; i++) {
601 if (!SWS_COMP_TEST(op->clear.mask, i))
602 continue;
603 const AVRational64 v = op->clear.value[i];
604 const SwsPixelType type = op->clear.type[i];
605 const SwsPixel px = ff_sws_pixel_from_q64(type, v);
608 if (v.num == 0)
609 uop.par.clear.zero |= SWS_COMP(i);
610 else if (ff_sws_pixel_is_1s(type, px))
611 uop.par.clear.one |= SWS_COMP(i);
612 }
613 break;
614 case SWS_OP_SCALE:
615 uop.uop = SWS_UOP_SCALE;
616 uop.data.scalar = ff_sws_pixel_from_q64(uop.type, op->scale.factor);
617 break;
618 case SWS_OP_MIN:
619 case SWS_OP_MAX:
620 uop.uop = op->op == SWS_OP_MIN ? SWS_UOP_MIN : SWS_UOP_MAX;
621 uop.mask &= ff_sws_comp_mask_q4(op->clamp.limit);
622 for (int i = 0; i < 4; i++) {
623 if (SWS_COMP_TEST(uop.mask, i))
624 uop.data.vec4[i] = ff_sws_pixel_from_q64(uop.type, op->clamp.limit[i]);
625 }
626 break;
629 uop.type = pixel_type_to_int(flags, uop.type);
630 break;
631 case SWS_OP_LUT_3D:
632 uop.uop = SWS_UOP_LUT_3D;
633 uop.par.lut3d.dynamic = op->lut3d.dynamic;
634 uop.data.lut3d = av_refstruct_ref_c(op->lut3d.lut);
635 break;
636 default:
637 return AVERROR(ENOTSUP);
638 }
639
641 return ff_sws_uop_list_append(uops, &uop);
642}
643
646{
647 const SwsOpPad *inputs = ops->inputs;
648 for (int n = 0; n < ops->num_ops; n++) {
649 const SwsOp *op = &ops->ops[n];
650 for (int i = 0; i < 4; i++) {
651 if (!SWS_OP_NEEDED(op, i))
652 continue;
653 const int pixel_size = ff_sws_pixel_type_size(op->outputs[i].type);
654 if (pixel_size > uops->pixel_size_max)
655 uops->pixel_size_max = pixel_size;
656 }
657
658 int ret = translate_op(ctx, uops, flags, op, inputs);
659 if (ret < 0)
660 return ret;
661 inputs = op->outputs;
662 }
663
664 return ff_sws_uop_list_optimize(ctx, flags, uops);
665}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
static const AVFilterPad inputs[]
Definition af_aap.c:299
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:121
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define bit(string, value)
Definition cbs_mpeg2.c:56
#define f(width, name)
Definition cbs_vp8.c:236
static LevelCodes lev[4+3+3]
Definition clearvideo.c:80
#define FFABS64U(a)
Definition common.h:92
#define NULL
Definition coverity.c:32
static __device__ float fabsf(float a)
#define max(a, b)
int8_t exp
Definition eval.c:76
static const uint8_t bits[8]
Definition fastaudio.c:100
int ret
Definition ffplay.c:391
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition bprint.h:218
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition bprint.c:129
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
Definition bprint.c:84
#define AVERROR(e)
Definition error.h:45
int av_log_get_level(void)
Get the current log level.
Definition log.c:477
#define ff_ctz
Definition intmath.h:105
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
Definition mem.c:447
@ SWS_BITEXACT
Definition swscale.h:178
int index
Definition gxfenc.c:90
int a
#define b
Definition input.c:43
#define av_log2
Definition intmath.h:84
enum MPFType type
Definition jpegmpfenc.c:55
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition anm.c:76
@ SWS_FILTER_SCALE
14-bit coefficients are picked to fit comfortably within int16_t for efficient SIMD processing (e....
Definition filters.h:40
static const struct @257111027162314367033347246032313251342043035002 planes[]
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
uint32_t ff_sws_linear_mask(const SwsLinearOp *c)
Definition ops.c:861
SwsPixelType ff_sws_op_input_type(const SwsOp *op)
Return the input/output type of an operation, if all inputs/outputs are the same type,...
Definition ops.c:186
SwsCompMask ff_sws_comp_mask_needed(const SwsOp *op)
Definition ops.c:123
const char * ff_sws_pixel_type_name(SwsPixelType type)
Definition ops.c:56
SwsCompMask ff_sws_comp_mask_q4(const AVRational64 q[4])
Definition ops.c:100
int ff_sws_rw_op_planes(const SwsOp *op)
Return the number of planes involved in a read/write operation.
Definition ops.c:133
@ SWS_OP_RSHIFT
Definition ops.h:49
@ SWS_OP_SWIZZLE
Definition ops.h:43
@ SWS_OP_LSHIFT
Definition ops.h:48
@ SWS_OP_FILTER_V
Definition ops.h:64
@ SWS_OP_SCALE
Definition ops.h:56
@ SWS_OP_FILTER_H
Definition ops.h:63
@ SWS_OP_WRITE
Definition ops.h:41
@ SWS_OP_READ
Definition ops.h:40
@ SWS_OP_CLEAR
Definition ops.h:52
@ SWS_OP_SWAP_BYTES
Definition ops.h:42
@ SWS_OP_MIN
Definition ops.h:54
@ SWS_OP_UNPACK
Definition ops.h:46
@ SWS_OP_LINEAR
Definition ops.h:57
@ SWS_OP_PACK
Definition ops.h:47
@ SWS_OP_DITHER
Definition ops.h:60
@ SWS_OP_MAX
Definition ops.h:55
@ SWS_OP_LUT_3D
Definition ops.h:67
@ SWS_OP_CONVERT
Definition ops.h:53
@ SWS_RW_PALETTE
Definition ops.h:89
@ SWS_RW_PLANAR
Note: 1-component reads are either SWS_RW_PLANAR or SWS_RW_PACKED, depending on the underlying interp...
Definition ops.h:87
@ SWS_RW_PACKED
Definition ops.h:88
@ SWS_COMP_EXACT
Definition ops.h:230
#define SWS_OP_NEEDED(op, idx)
Definition ops.h:282
int ff_sws_uop_list_optimize(SwsContext *ctx, SwsUOpFlags flags, SwsUOpList *uops)
Called internally by ff_sws_ops_translate().
const char * name
Definition qsvenc.c:142
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
Definition refstruct.c:150
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition refstruct.c:141
#define FF_ARRAY_ELEMS(a)
64-bit Rational number (pair of numerator and denominator).
Definition rational64.h:52
int64_t num
Numerator.
Definition rational64.h:53
int64_t den
Denominator.
Definition rational64.h:54
SwsCompMask one
Definition uops.h:263
SwsCompMask zero
Definition uops.h:264
Main external API structure.
Definition swscale.h:227
uint8_t size_log2
Definition uops.h:283
uint8_t y_offset[4]
Definition uops.h:282
SwsPixelType type
Definition uops.h:237
uint32_t zero
Definition uops.h:269
uint32_t one
Definition uops.h:268
uint32_t exact
Definition uops.h:272
int dynamic
Definition uops.h:287
int8_t src[SWS_UOP_MOVE_MAX]
Definition uops.h:251
int num_moves
Definition uops.h:247
int8_t dst[SWS_UOP_MOVE_MAX]
Definition uops.h:250
Helper struct for representing a list of operations.
Definition ops.h:318
SwsOp * ops
Definition ops.h:319
SwsOpPad inputs[4]
Source component metadata associated with pixel values from each corresponding component (in plane/me...
Definition ops.h:337
int num_ops
Definition ops.h:320
SwsCompFlags flags
Definition ops.h:239
AVRational64 min
Definition ops.h:243
AVRational64 max
Definition ops.h:243
SwsPixelType type
Definition ops.h:238
Definition ops.h:252
uint8_t pattern[4]
Definition uops.h:255
uint8_t amount
Definition uops.h:241
uint8_t write_size
Definition uops.h:228
uint8_t read_size
Definition uops.h:227
uint8_t clear_value
Definition uops.h:226
SwsUOp * ops
Definition uops.h:345
int pixel_size_max
Definition uops.h:351
int num_ops
Definition uops.h:346
SwsCompMask planes_in
Definition uops.h:349
SwsCompMask planes_out
Definition uops.h:350
Definition uops.h:308
SwsPixel scalar
Definition uops.h:319
SwsCompMask mask
Definition uops.h:312
SwsUOpType uop
Definition uops.h:311
SwsUOpParams par
Definition uops.h:313
const SwsLut3D * lut3d
Definition uops.h:323
SwsFilterWeights * kernel
Definition uops.h:317
SwsPixel * ptr
Definition uops.h:318
union SwsUOp::@242237116251216327057105100216205033300341206345 data
SwsPixelType type
Definition uops.h:310
SwsPixel mat4x5[4][5]
Definition uops.h:321
SwsPixel vec4[4]
Definition uops.h:320
#define stride
static void * ff_refstruct_calloc(size_t n, size_t size)
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
int num
Definition error.c:23
int size
float f32
Definition uops.h:85
SwsMoveUOp move
Definition uops.h:300
SwsClearUOp clear
Definition uops.h:302
SwsDitherUOp dither
Definition uops.h:304
SwsFilterUOp filter
Definition uops.h:298
SwsLut3DUOp lut3d
Definition uops.h:305
SwsShuffleUOp shuffle
Definition uops.h:297
SwsLinearUOp lin
Definition uops.h:303
SwsShiftUOp shift
Definition uops.h:299
SwsPackUOp pack
Definition uops.h:301
char abbr[32]
Definition uops.c:47
int ff_sws_ops_translate(SwsContext *ctx, const SwsOpList *ops, SwsUOpFlags flags, SwsUOpList *uops)
Translate a list of operations down to micro-ops, which can be further optimized and then directly ex...
Definition uops.c:644
int ff_sws_dither_height(const SwsDitherUOp *dither)
Computes (1 << size_log2) + MAX(y_offset).
Definition uops.c:218
static bool check_filter_fma(SwsContext *ctx, SwsUOpFlags flags, const SwsOp *op)
Definition uops.c:275
static void uop_uninit(SwsUOp *uop)
Definition uops.c:143
int ff_sws_uop_list_append(SwsUOpList *uops, SwsUOp *uop)
Definition uops.c:181
static bool exact_prod(SwsPixel coef, const SwsOpPad *input)
Definition uops.c:250
#define UOP_NAME(OP, ABBR)
void ff_sws_uop_name(const SwsUOp *op, char buf[SWS_UOP_NAME_MAX])
Definition uops.c:54
static int translate_dither_op(SwsUOpList *ops, SwsUOpFlags flags, const SwsOp *op)
Definition uops.c:451
int ff_sws_uop_cmp(const SwsUOp *a, const SwsUOp *b)
Copyright (C) 2026 Niklas Haas.
Definition uops.c:35
static SwsPixelType pixel_type_to_int(SwsUOpFlags flags, const SwsPixelType type)
Definition uops.c:227
SwsUOpList * ff_sws_uop_list_alloc(void)
Definition uops.c:176
void ff_sws_uop_list_free(SwsUOpList **p_ops)
Definition uops.c:162
static int translate_swizzle(SwsUOpList *ops, SwsUOpFlags flags, const SwsOp *op)
Definition uops.c:357
static int translate_rw_op(SwsContext *ctx, SwsUOpList *ops, SwsUOpFlags flags, const SwsOp *op)
Definition uops.c:293
void ff_sws_uop_list_remove_at(SwsUOpList *uops, int index, int count)
Definition uops.c:194
static int count_idx(const int *arr, size_t size, int val)
Definition uops.c:346
void ff_sws_uop_list_print(void *log, int lev, const SwsUOpList *uops)
Print the micro-ops of a compiled list at the given log level.
Definition uops.c:205
static int translate_linear_op(SwsContext *ctx, SwsUOpList *ops, SwsUOpFlags flags, const SwsOp *op, const SwsOpPad inputs[4])
Definition uops.c:499
static const struct @145311200363243152256244361015041277337174162300 uop_names[SWS_UOP_TYPE_NB]
static int translate_op(SwsContext *ctx, SwsUOpList *uops, SwsUOpFlags flags, const SwsOp *op, const SwsOpPad inputs[4])
Definition uops.c:546
static int significant_bits_f32(float f)
Definition uops.c:243
uint32_t SwsUOpFlags
Definition uops.h:158
SwsPixelType
Definition uops.h:40
@ SWS_PIXEL_F32
Definition uops.h:45
@ SWS_PIXEL_U32
Definition uops.h:44
@ SWS_PIXEL_U16
Definition uops.h:43
@ SWS_PIXEL_NONE
Definition uops.h:41
@ SWS_PIXEL_U8
Definition uops.h:42
#define SWS_COMP(X)
Definition uops.h:133
#define ff_sws_comp_mask_str(mask)
Definition uops.h:146
#define SWS_UOP_MOVE_MAX
Definition uops.h:246
#define SWS_MASK_ROW(I)
Definition uops.h:277
#define SWS_COMP_TEST(mask, X)
Definition uops.h:134
#define SWS_COMP_ELEMS(N)
Definition uops.h:136
#define SWS_MASK(I, J)
Definition uops.h:275
@ SWS_UOP_TO_U8
Definition uops.h:199
@ SWS_UOP_PACK
Definition uops.h:212
@ SWS_UOP_PERMUTE
Definition uops.h:191
@ SWS_UOP_READ_PLANAR
Definition uops.h:173
@ SWS_UOP_WRITE_PLANAR
Definition uops.h:182
@ SWS_UOP_READ_NIBBLE
Definition uops.h:178
@ SWS_UOP_MAX
Definition uops.h:208
@ SWS_UOP_READ_BIT
Definition uops.h:179
@ SWS_UOP_SWAP_BYTES
Definition uops.h:195
@ SWS_UOP_MIN
Definition uops.h:207
@ SWS_UOP_LINEAR
Definition uops.h:216
@ SWS_UOP_RSHIFT
Definition uops.h:214
@ SWS_UOP_COPY
Definition uops.h:192
@ SWS_UOP_WRITE_NIBBLE
Definition uops.h:184
@ SWS_UOP_INVALID
Definition uops.h:170
@ SWS_UOP_LINEAR_FMA
Definition uops.h:217
@ SWS_UOP_READ_PLANAR_FH
Definition uops.h:174
@ SWS_UOP_SCALE
Definition uops.h:205
@ SWS_UOP_WRITE_PACKED
Definition uops.h:183
@ SWS_UOP_WRITE_BIT
Definition uops.h:185
@ SWS_UOP_READ_PLANAR_FV_FMA
Definition uops.h:176
@ SWS_UOP_READ_PACKED
Definition uops.h:177
@ SWS_UOP_LUT_3D
Definition uops.h:219
@ SWS_UOP_TO_U16
Definition uops.h:200
@ SWS_UOP_DITHER
Definition uops.h:218
@ SWS_UOP_ADD
Definition uops.h:206
@ SWS_UOP_TYPE_NB
Definition uops.h:222
@ SWS_UOP_CLEAR
Definition uops.h:215
@ SWS_UOP_READ_PALETTE
Definition uops.h:180
@ SWS_UOP_READ_PLANAR_FV
Definition uops.h:175
@ SWS_UOP_TO_U32
Definition uops.h:201
@ SWS_UOP_RW_SHUFFLE
Definition uops.h:188
@ SWS_UOP_UNPACK
Definition uops.h:211
@ SWS_UOP_TO_F32
Definition uops.h:202
@ SWS_UOP_LSHIFT
Definition uops.h:213
#define SWS_COMP_MASK(X, Y, Z, W)
Definition uops.h:138
static bool ff_sws_pixel_is_1s(SwsPixelType type, SwsPixel val)
Definition uops.h:115
static SwsPixel ff_sws_pixel_expand32(SwsPixelType type, SwsPixel val)
Definition uops.h:105
static SwsPixel ff_sws_pixel_from_q64(SwsPixelType type, AVRational64 val)
Definition uops.h:91
@ SWS_UOP_FLAG_FMA
Definition uops.h:161
@ SWS_UOP_FLAG_ADD
Definition uops.h:165
@ SWS_UOP_FLAG_READ_PALETTE
Definition uops.h:164
@ SWS_UOP_FLAG_PUNNING
Definition uops.h:166
#define SWS_UOP_NAME_MAX
Generate a unique name for a SwsUOp.
Definition uops.h:341
static av_const bool ff_sws_pixel_type_is_int(SwsPixelType type)
Definition uops.h:64
uint8_t SwsCompMask
Bit-mask of components.
Definition uops.h:129
static av_const int ff_sws_pixel_type_size(SwsPixelType type)
Definition uops.h:51
#define UOPS_LIST(ENTRY)
This file is part of FFmpeg.
Definition uops_list.h:23
static const uint16_t dither[8][8]
Definition vf_gradfun.c:46