| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * Copyright (C) 2025 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 | #ifndef SWSCALE_OPS_INTERNAL_H | ||
| 22 | #define SWSCALE_OPS_INTERNAL_H | ||
| 23 | |||
| 24 | #include "libavutil/mem_internal.h" | ||
| 25 | |||
| 26 | #include "ops.h" | ||
| 27 | #include "ops_dispatch.h" | ||
| 28 | |||
| 29 | #define Q(N) ((AVRational) { N, 1 }) | ||
| 30 | |||
| 31 | 1049176 | static inline AVRational ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to) | |
| 32 | { | ||
| 33 | 1049176 | const int src = ff_sws_pixel_type_size(from); | |
| 34 | 1049176 | const int dst = ff_sws_pixel_type_size(to); | |
| 35 |
2/2✓ Branch 0 taken 896150 times.
✓ Branch 1 taken 153026 times.
|
1049176 | if (src > dst) |
| 36 | 896150 | return Q(0); | |
| 37 | 153026 | int scale = 1; | |
| 38 |
2/2✓ Branch 0 taken 119340 times.
✓ Branch 1 taken 153026 times.
|
272366 | for (int i = 1; i < dst / src; i++) |
| 39 | 119340 | scale = (scale << (src * 8)) | 1; | |
| 40 | 153026 | return Q(scale); | |
| 41 | } | ||
| 42 | |||
| 43 | 157504 | static inline void ff_sws_pack_op_decode(const SwsOp *op, uint64_t mask[4], int shift[4]) | |
| 44 | { | ||
| 45 | 157504 | int size = 0; | |
| 46 |
2/2✓ Branch 0 taken 630016 times.
✓ Branch 1 taken 157504 times.
|
787520 | for (int i = 0; i < 4; i++) |
| 47 | 630016 | size += op->pack.pattern[i]; | |
| 48 |
2/2✓ Branch 0 taken 630016 times.
✓ Branch 1 taken 157504 times.
|
787520 | for (int i = 0; i < 4; i++) { |
| 49 | 630016 | const int bits = op->pack.pattern[i]; | |
| 50 | 630016 | mask[i] = (UINT64_C(1) << bits) - 1; | |
| 51 |
2/2✓ Branch 0 taken 472512 times.
✓ Branch 1 taken 157504 times.
|
630016 | shift[i] = (i ? shift[i - 1] : size) - bits; |
| 52 | } | ||
| 53 | 157504 | } | |
| 54 | |||
| 55 | typedef struct SwsOpBackend { | ||
| 56 | const char *name; /* Descriptive name for this backend */ | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Compile an operation list to an implementation chain. May modify `ops` | ||
| 60 | * freely; the original list will be freed automatically by the caller. | ||
| 61 | * | ||
| 62 | * Returns 0 or a negative error code. | ||
| 63 | */ | ||
| 64 | int (*compile)(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out); | ||
| 65 | |||
| 66 | /** | ||
| 67 | * If NONE, backend only supports software frames. | ||
| 68 | * Otherwise, frame hardware format must match hw_format for the backend | ||
| 69 | * to be used. | ||
| 70 | */ | ||
| 71 | enum AVPixelFormat hw_format; | ||
| 72 | } SwsOpBackend; | ||
| 73 | |||
| 74 | /* List of all backends, terminated by NULL */ | ||
| 75 | extern const SwsOpBackend *const ff_sws_op_backends[]; | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Attempt to compile a list of operations using a specific backend. | ||
| 79 | * | ||
| 80 | * Returns 0 on success, or a negative error code on failure. | ||
| 81 | */ | ||
| 82 | int ff_sws_ops_compile_backend(SwsContext *ctx, const SwsOpBackend *backend, | ||
| 83 | const SwsOpList *ops, SwsCompiledOp *out); | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Compile a list of operations using the best available backend. | ||
| 87 | * | ||
| 88 | * Returns 0 on success, or a negative error code on failure. | ||
| 89 | */ | ||
| 90 | int ff_sws_ops_compile(SwsContext *ctx, const SwsOpList *ops, SwsCompiledOp *out); | ||
| 91 | |||
| 92 | /** | ||
| 93 | * "Solve" an op list into a fixed shuffle mask, with an optional ability to | ||
| 94 | * also directly clear the output value (for e.g. rgb24 -> rgb0). This can | ||
| 95 | * accept any operation chain that only consists of the following operations: | ||
| 96 | * | ||
| 97 | * - SWS_OP_READ (non-planar, non-fractional) | ||
| 98 | * - SWS_OP_SWIZZLE | ||
| 99 | * - SWS_OP_SWAP_BYTES | ||
| 100 | * - SWS_OP_CLEAR to zero (when clear_val is specified) | ||
| 101 | * - SWS_OP_CONVERT (integer expand) | ||
| 102 | * - SWS_OP_WRITE (non-planar, non-fractional) | ||
| 103 | * | ||
| 104 | * Basically, any operation that purely consists of moving around and reordering | ||
| 105 | * bytes within a single plane, can be turned into a shuffle mask. | ||
| 106 | * | ||
| 107 | * @param ops The operation list to decompose. | ||
| 108 | * @param shuffle The output shuffle mask. | ||
| 109 | * @param size The size (in bytes) of the output shuffle mask. | ||
| 110 | * @param clear_val If nonzero, this index will be used to clear the output. | ||
| 111 | * @param read_bytes Returns the number of bytes read per shuffle iteration. | ||
| 112 | * @param write_bytes Returns the number of bytes written per shuffle iteration. | ||
| 113 | * | ||
| 114 | * @return The number of pixels processed per iteration, or a negative error | ||
| 115 | code; in particular AVERROR(ENOTSUP) for unsupported operations. | ||
| 116 | */ | ||
| 117 | int ff_sws_solve_shuffle(const SwsOpList *ops, uint8_t shuffle[], int size, | ||
| 118 | uint8_t clear_val, int *read_bytes, int *write_bytes); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Eliminate SWS_OP_FILTER_* operations by merging them with prior SWS_OP_READ | ||
| 122 | * operations. This may require splitting the op list into multiple subpasses, | ||
| 123 | * along filter boundaries. After this function, `ops` will no longer contain | ||
| 124 | * bare filtering operations. The remainder, if any, is output to `out_rest`. | ||
| 125 | * | ||
| 126 | * Returns 0 or a negative error code. | ||
| 127 | */ | ||
| 128 | int ff_sws_op_list_subpass(SwsOpList *ops, SwsOpList **out_rest); | ||
| 129 | |||
| 130 | #endif /* SWSCALE_OPS_INTERNAL_H */ | ||
| 131 |