FFmpeg
Loading...
Searching...
No Matches
swscale.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
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 <stdint.h>
22#include <stdio.h>
23#include <string.h>
24
25#include "libavutil/avassert.h"
26#include "libavutil/bswap.h"
27#include "libavutil/common.h"
28#include "libavutil/cpu.h"
29#include "libavutil/emms.h"
31#include "libavutil/mem.h"
33#include "libavutil/pixdesc.h"
34#include "libavutil/hwcontext.h"
35#include "config.h"
36#include "swscale_internal.h"
37#include "swscale.h"
38#if CONFIG_VULKAN
39#include "vulkan/ops.h"
40#endif
41
42DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_128)[9][8] = {
43 { 36, 68, 60, 92, 34, 66, 58, 90, },
44 { 100, 4, 124, 28, 98, 2, 122, 26, },
45 { 52, 84, 44, 76, 50, 82, 42, 74, },
46 { 116, 20, 108, 12, 114, 18, 106, 10, },
47 { 32, 64, 56, 88, 38, 70, 62, 94, },
48 { 96, 0, 120, 24, 102, 6, 126, 30, },
49 { 48, 80, 40, 72, 54, 86, 46, 78, },
50 { 112, 16, 104, 8, 118, 22, 110, 14, },
51 { 36, 68, 60, 92, 34, 66, 58, 90, },
52};
53
54DECLARE_ALIGNED(8, static const uint8_t, sws_pb_64)[8] = {
55 64, 64, 64, 64, 64, 64, 64, 64
56};
57
58static av_always_inline void fillPlane(uint8_t *plane, int stride, int width,
59 int height, int y, uint8_t val)
60{
61 int i;
62 uint8_t *ptr = plane + stride * y;
63 for (i = 0; i < height; i++) {
64 memset(ptr, val, width);
65 ptr += stride;
66 }
67}
68
69static void hScale16To19_c(SwsInternal *c, int16_t *_dst, int dstW,
70 const uint8_t *_src, const int16_t *filter,
71 const int32_t *filterPos, int filterSize)
72{
73 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.src_format);
74 int i;
75 int32_t *dst = (int32_t *) _dst;
76 const uint16_t *src = (const uint16_t *) _src;
77 int bits = desc->comp[0].depth - 1;
78 int sh = bits - 4;
79
80 if ((isAnyRGB(c->opts.src_format) || c->opts.src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) {
81 sh = 9;
82 } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */
83 sh = 16 - 1 - 4;
84 }
85
86 for (i = 0; i < dstW; i++) {
87 int j;
88 int srcPos = filterPos[i];
89 int val = 0;
90
91 for (j = 0; j < filterSize; j++) {
92 val += src[srcPos + j] * filter[filterSize * i + j];
93 }
94 // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
95 dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
96 }
97}
98
99static void hScale16To15_c(SwsInternal *c, int16_t *dst, int dstW,
100 const uint8_t *_src, const int16_t *filter,
101 const int32_t *filterPos, int filterSize)
102{
103 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.src_format);
104 int i;
105 const uint16_t *src = (const uint16_t *) _src;
106 int sh = desc->comp[0].depth - 1;
107
108 if (sh<15) {
109 sh = isAnyRGB(c->opts.src_format) || c->opts.src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1);
110 } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */
111 sh = 16 - 1;
112 }
113
114 for (i = 0; i < dstW; i++) {
115 int j;
116 int srcPos = filterPos[i];
117 int val = 0;
118
119 for (j = 0; j < filterSize; j++) {
120 val += src[srcPos + j] * filter[filterSize * i + j];
121 }
122 // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
123 dst[i] = FFMIN(val >> sh, (1 << 15) - 1);
124 }
125}
126
127// bilinear / bicubic scaling
128static void hScale8To15_c(SwsInternal *c, int16_t *dst, int dstW,
129 const uint8_t *src, const int16_t *filter,
130 const int32_t *filterPos, int filterSize)
131{
132 int i;
133 for (i = 0; i < dstW; i++) {
134 int j;
135 int srcPos = filterPos[i];
136 int val = 0;
137 for (j = 0; j < filterSize; j++) {
138 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
139 }
140 dst[i] = FFMIN(val >> 7, (1 << 15) - 1); // the cubic equation does overflow ...
141 }
142}
143
144static void hScale8To19_c(SwsInternal *c, int16_t *_dst, int dstW,
145 const uint8_t *src, const int16_t *filter,
146 const int32_t *filterPos, int filterSize)
147{
148 int i;
149 int32_t *dst = (int32_t *) _dst;
150 for (i = 0; i < dstW; i++) {
151 int j;
152 int srcPos = filterPos[i];
153 int val = 0;
154 for (j = 0; j < filterSize; j++) {
155 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
156 }
157 dst[i] = FFMIN(val >> 3, (1 << 19) - 1); // the cubic equation does overflow ...
158 }
159}
160
161// FIXME all pal and rgb srcFormats could do this conversion as well
162// FIXME all scalers more complex than bilinear could do half of this transform
163static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width,
164 uint32_t _coeff, int64_t _offset)
165{
166 uint16_t coeff = _coeff;
167 int32_t offset = _offset;
168 int i;
169 for (i = 0; i < width; i++) {
170 int U = (dstU[i] * coeff + offset) >> 14;
171 int V = (dstV[i] * coeff + offset) >> 14;
172 dstU[i] = FFMIN(U, (1 << 15) - 1);
173 dstV[i] = FFMIN(V, (1 << 15) - 1);
174 }
175}
176
177static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width,
178 uint32_t _coeff, int64_t _offset)
179{
180 uint16_t coeff = _coeff;
181 int32_t offset = _offset;
182 int i;
183 for (i = 0; i < width; i++) {
184 dstU[i] = (dstU[i] * coeff + offset) >> 14;
185 dstV[i] = (dstV[i] * coeff + offset) >> 14;
186 }
187}
188
189static void lumRangeToJpeg_c(int16_t *dst, int width,
190 uint32_t _coeff, int64_t _offset)
191{
192 uint16_t coeff = _coeff;
193 int32_t offset = _offset;
194 int i;
195 for (i = 0; i < width; i++) {
196 int Y = (dst[i] * coeff + offset) >> 14;
197 dst[i] = FFMIN(Y, (1 << 15) - 1);
198 }
199}
200
201static void lumRangeFromJpeg_c(int16_t *dst, int width,
202 uint32_t _coeff, int64_t _offset)
203{
204 uint16_t coeff = _coeff;
205 int32_t offset = _offset;
206 int i;
207 for (i = 0; i < width; i++)
208 dst[i] = (dst[i] * coeff + offset) >> 14;
209}
210
211static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width,
212 uint32_t coeff, int64_t offset)
213{
214 int i;
215 int32_t *dstU = (int32_t *) _dstU;
216 int32_t *dstV = (int32_t *) _dstV;
217 for (i = 0; i < width; i++) {
218 int U = ((int64_t) dstU[i] * coeff + offset) >> 18;
219 int V = ((int64_t) dstV[i] * coeff + offset) >> 18;
220 dstU[i] = FFMIN(U, (1 << 19) - 1);
221 dstV[i] = FFMIN(V, (1 << 19) - 1);
222 }
223}
224
225static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width,
226 uint32_t coeff, int64_t offset)
227{
228 int i;
229 int32_t *dstU = (int32_t *) _dstU;
230 int32_t *dstV = (int32_t *) _dstV;
231 for (i = 0; i < width; i++) {
232 dstU[i] = ((int64_t) dstU[i] * coeff + offset) >> 18;
233 dstV[i] = ((int64_t) dstV[i] * coeff + offset) >> 18;
234 }
235}
236
237static void lumRangeToJpeg16_c(int16_t *_dst, int width,
238 uint32_t coeff, int64_t offset)
239{
240 int i;
241 int32_t *dst = (int32_t *) _dst;
242 for (i = 0; i < width; i++) {
243 int Y = ((int64_t) dst[i] * coeff + offset) >> 18;
244 dst[i] = FFMIN(Y, (1 << 19) - 1);
245 }
246}
247
248static void lumRangeFromJpeg16_c(int16_t *_dst, int width,
249 uint32_t coeff, int64_t offset)
250{
251 int i;
252 int32_t *dst = (int32_t *) _dst;
253 for (i = 0; i < width; i++)
254 dst[i] = ((int64_t) dst[i] * coeff + offset) >> 18;
255}
256
257
258#define DEBUG_SWSCALE_BUFFERS 0
259#define DEBUG_BUFFERS(...) \
260 if (DEBUG_SWSCALE_BUFFERS) \
261 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
262
263int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[],
264 int srcSliceY, int srcSliceH, uint8_t *const dst[],
265 const int dstStride[], int dstSliceY, int dstSliceH)
266{
267 const int scale_dst = dstSliceY > 0 || dstSliceH < c->opts.dst_h;
268
269 /* load a few things into local vars to make the code more readable?
270 * and faster */
271 const int dstW = c->opts.dst_w;
272 int dstH = c->opts.dst_h;
273
274 const enum AVPixelFormat dstFormat = c->opts.dst_format;
275 const int flags = c->opts.flags;
276 int32_t *vLumFilterPos = c->vLumFilterPos;
277 int32_t *vChrFilterPos = c->vChrFilterPos;
278
279 const int vLumFilterSize = c->vLumFilterSize;
280 const int vChrFilterSize = c->vChrFilterSize;
281
282 yuv2planar1_fn yuv2plane1 = c->yuv2plane1;
283 yuv2planarX_fn yuv2planeX = c->yuv2planeX;
284 yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX;
285 yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
286 yuv2packed2_fn yuv2packed2 = c->yuv2packed2;
287 yuv2packedX_fn yuv2packedX = c->yuv2packedX;
288 yuv2anyX_fn yuv2anyX = c->yuv2anyX;
289 const int chrSrcSliceY = srcSliceY >> c->chrSrcVSubSample;
290 const int chrSrcSliceH = AV_CEIL_RSHIFT(srcSliceH, c->chrSrcVSubSample);
291 int should_dither = isNBPS(c->opts.src_format) ||
292 is16BPS(c->opts.src_format);
293 int lastDstY;
294
295 /* vars which will change and which we need to store back in the context */
296 int dstY = c->dstY;
297 int lastInLumBuf = c->lastInLumBuf;
298 int lastInChrBuf = c->lastInChrBuf;
299
300 int lumStart = 0;
301 int lumEnd = c->descIndex[0];
302 int chrStart = lumEnd;
303 int chrEnd = c->descIndex[1];
304 int vStart = chrEnd;
305 int vEnd = c->numDesc;
306 SwsSlice *src_slice = &c->slice[lumStart];
307 SwsSlice *hout_slice = &c->slice[c->numSlice-2];
308 SwsSlice *vout_slice = &c->slice[c->numSlice-1];
309 SwsFilterDescriptor *desc = c->desc;
310
311 int needAlpha = c->needAlpha;
312
313 int hasLumHoles = 1;
314 int hasChrHoles = 1;
315
316 const uint8_t *src2[4];
317 int srcStride2[4];
318
319 if (isPacked(c->opts.src_format)) {
320 src2[0] =
321 src2[1] =
322 src2[2] =
323 src2[3] = src[0];
324 srcStride2[0] =
325 srcStride2[1] =
326 srcStride2[2] =
327 srcStride2[3] = srcStride[0];
328 } else {
329 memcpy(src2, src, sizeof(src2));
330 memcpy(srcStride2, srcStride, sizeof(srcStride2));
331 }
332
333 srcStride2[1] *= 1 << c->vChrDrop;
334 srcStride2[2] *= 1 << c->vChrDrop;
335
336 DEBUG_BUFFERS("swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
337 src2[0], srcStride2[0], src2[1], srcStride2[1],
338 src2[2], srcStride2[2], src2[3], srcStride2[3],
339 dst[0], dstStride[0], dst[1], dstStride[1],
340 dst[2], dstStride[2], dst[3], dstStride[3]);
341 DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
342 srcSliceY, srcSliceH, dstY, dstH);
343 DEBUG_BUFFERS("vLumFilterSize: %d vChrFilterSize: %d\n",
344 vLumFilterSize, vChrFilterSize);
345
346 if (dstStride[0]&15 || dstStride[1]&15 ||
347 dstStride[2]&15 || dstStride[3]&15) {
348 SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c;
349 if (flags & SWS_PRINT_INFO &&
350 !atomic_exchange_explicit(&ctx->stride_unaligned_warned, 1, memory_order_relaxed)) {
352 "Warning: dstStride is not aligned!\n"
353 " ->cannot do aligned memory accesses anymore\n");
354 }
355 }
356
357#if ARCH_X86
358 if ( (uintptr_t) dst[0]&15 || (uintptr_t) dst[1]&15 || (uintptr_t) dst[2]&15
359 || (uintptr_t)src2[0]&15 || (uintptr_t)src2[1]&15 || (uintptr_t)src2[2]&15
360 || srcStride2[0]&15 || srcStride2[1]&15 || srcStride2[2]&15 || srcStride2[3]&15
361 ) {
362 SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c;
364 if (flags & SWS_PRINT_INFO && HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) &&
365 !atomic_exchange_explicit(&ctx->stride_unaligned_warned,1, memory_order_relaxed)) {
366 av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speed loss\n");
367 }
368 }
369#endif
370
371 if (scale_dst) {
372 dstY = dstSliceY;
373 dstH = dstY + dstSliceH;
374 lastInLumBuf = -1;
375 lastInChrBuf = -1;
376 } else if (srcSliceY == 0) {
377 /* Note the user might start scaling the picture in the middle so this
378 * will not get executed. This is not really intended but works
379 * currently, so people might do it. */
380 dstY = 0;
381 lastInLumBuf = -1;
382 lastInChrBuf = -1;
383 }
384
385 if (!should_dither) {
386 c->chrDither8 = c->lumDither8 = sws_pb_64;
387 }
388 lastDstY = dstY;
389
390 ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
391 yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, c->use_mmx_vfilter);
392
393 ff_init_slice_from_src(src_slice, (uint8_t**)src2, srcStride2, c->opts.src_w,
394 srcSliceY, srcSliceH, chrSrcSliceY, chrSrcSliceH, 1);
395
396 ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->opts.dst_w,
397 dstY, dstSliceH, dstY >> c->chrDstVSubSample,
398 AV_CEIL_RSHIFT(dstSliceH, c->chrDstVSubSample), scale_dst);
399 if (srcSliceY == 0) {
400 hout_slice->plane[0].sliceY = lastInLumBuf + 1;
401 hout_slice->plane[1].sliceY = lastInChrBuf + 1;
402 hout_slice->plane[2].sliceY = lastInChrBuf + 1;
403 hout_slice->plane[3].sliceY = lastInLumBuf + 1;
404
405 hout_slice->plane[0].sliceH =
406 hout_slice->plane[1].sliceH =
407 hout_slice->plane[2].sliceH =
408 hout_slice->plane[3].sliceH = 0;
409 hout_slice->width = dstW;
410 }
411
412 for (; dstY < dstH; dstY++) {
413 const int chrDstY = dstY >> c->chrDstVSubSample;
414 int use_mmx_vfilter= c->use_mmx_vfilter;
415
416 // First line needed as input
417 const int firstLumSrcY = FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
418 const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), c->opts.dst_h - 1)]);
419 // First line needed as input
420 const int firstChrSrcY = FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
421
422 // Last line needed as input
423 int lastLumSrcY = FFMIN(c->opts.src_h, firstLumSrcY + vLumFilterSize) - 1;
424 int lastLumSrcY2 = FFMIN(c->opts.src_h, firstLumSrcY2 + vLumFilterSize) - 1;
425 int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
426 int enough_lines;
427
428 int i;
429 int posY, cPosY, firstPosY, lastPosY, firstCPosY, lastCPosY;
430
431 // handle holes (FAST_BILINEAR & weird filters)
432 if (firstLumSrcY > lastInLumBuf) {
433
434 hasLumHoles = lastInLumBuf != firstLumSrcY - 1;
435 if (hasLumHoles) {
436 hout_slice->plane[0].sliceY = firstLumSrcY;
437 hout_slice->plane[3].sliceY = firstLumSrcY;
438 hout_slice->plane[0].sliceH =
439 hout_slice->plane[3].sliceH = 0;
440 }
441
442 lastInLumBuf = firstLumSrcY - 1;
443 }
444 if (firstChrSrcY > lastInChrBuf) {
445
446 hasChrHoles = lastInChrBuf != firstChrSrcY - 1;
447 if (hasChrHoles) {
448 hout_slice->plane[1].sliceY = firstChrSrcY;
449 hout_slice->plane[2].sliceY = firstChrSrcY;
450 hout_slice->plane[1].sliceH =
451 hout_slice->plane[2].sliceH = 0;
452 }
453
454 lastInChrBuf = firstChrSrcY - 1;
455 }
456
457 DEBUG_BUFFERS("dstY: %d\n", dstY);
458 DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
459 firstLumSrcY, lastLumSrcY, lastInLumBuf);
460 DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
461 firstChrSrcY, lastChrSrcY, lastInChrBuf);
462
463 // Do we have enough lines in this slice to output the dstY line
464 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
465 lastChrSrcY < AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample);
466
467 if (!enough_lines) {
468 lastLumSrcY = srcSliceY + srcSliceH - 1;
469 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
470 DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
471 lastLumSrcY, lastChrSrcY);
472 }
473
474 av_assert0((lastLumSrcY - firstLumSrcY + 1) <= hout_slice->plane[0].available_lines);
475 av_assert0((lastChrSrcY - firstChrSrcY + 1) <= hout_slice->plane[1].available_lines);
476
477
478 posY = hout_slice->plane[0].sliceY + hout_slice->plane[0].sliceH;
479 if (posY <= lastLumSrcY && !hasLumHoles) {
480 firstPosY = FFMAX(firstLumSrcY, posY);
481 lastPosY = FFMIN(firstLumSrcY + hout_slice->plane[0].available_lines - 1, srcSliceY + srcSliceH - 1);
482 } else {
483 firstPosY = posY;
484 lastPosY = lastLumSrcY;
485 }
486
487 cPosY = hout_slice->plane[1].sliceY + hout_slice->plane[1].sliceH;
488 if (cPosY <= lastChrSrcY && !hasChrHoles) {
489 firstCPosY = FFMAX(firstChrSrcY, cPosY);
490 lastCPosY = FFMIN(firstChrSrcY + hout_slice->plane[1].available_lines - 1, AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample) - 1);
491 } else {
492 firstCPosY = cPosY;
493 lastCPosY = lastChrSrcY;
494 }
495
496 ff_rotate_slice(hout_slice, lastPosY, lastCPosY);
497
498 if (posY < lastLumSrcY + 1) {
499 for (i = lumStart; i < lumEnd; ++i)
500 desc[i].process(c, &desc[i], firstPosY, lastPosY - firstPosY + 1);
501 }
502
503 lastInLumBuf = lastLumSrcY;
504
505 if (cPosY < lastChrSrcY + 1) {
506 for (i = chrStart; i < chrEnd; ++i)
507 desc[i].process(c, &desc[i], firstCPosY, lastCPosY - firstCPosY + 1);
508 }
509
510 lastInChrBuf = lastChrSrcY;
511
512 if (!enough_lines)
513 break; // we can't output a dstY line so let's try with the next slice
514
515#if ARCH_X86 && HAVE_MMX
517 c->dstW_mmx = c->opts.dst_w;
518#endif
519 if (should_dither) {
520 c->chrDither8 = ff_dither_8x8_128[chrDstY & 7];
521 c->lumDither8 = ff_dither_8x8_128[dstY & 7];
522 }
523 if (dstY >= c->opts.dst_h - 2) {
524 /* hmm looks like we can't use MMX here without overwriting
525 * this array's tail */
526 ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX,
527 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
528 use_mmx_vfilter= 0;
529 ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
530 yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, use_mmx_vfilter);
531 }
532
533 for (i = vStart; i < vEnd; ++i)
534 desc[i].process(c, &desc[i], dstY, 1);
535 }
536 if (isPlanar(dstFormat) && isALPHA(dstFormat) && !needAlpha) {
537 int offset = lastDstY - dstSliceY;
538 int length = dstW;
539 int height = dstY - lastDstY;
540
541 if (is16BPS(dstFormat) || isNBPS(dstFormat)) {
542 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
543 fillPlane16(dst[3], dstStride[3], length, height, offset,
544 1, desc->comp[3].depth,
545 isBE(dstFormat));
546 } else if (is32BPS(dstFormat)) {
547 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
548 fillPlane32(dst[3], dstStride[3], length, height, offset,
549 1, desc->comp[3].depth,
550 isBE(dstFormat), desc->flags & AV_PIX_FMT_FLAG_FLOAT);
551 } else
552 fillPlane(dst[3], dstStride[3], length, height, offset, 255);
553 }
554
555#if HAVE_MMXEXT_INLINE
557 __asm__ volatile ("sfence" ::: "memory");
558#endif
559 emms_c();
560
561 /* store changed local vars back in the context */
562 c->dstY = dstY;
563 c->lastInLumBuf = lastInLumBuf;
564 c->lastInChrBuf = lastInChrBuf;
565
566 return dstY - lastDstY;
567}
568
569/*
570 * Solve for coeff and offset:
571 * dst = ((src << src_shift) * coeff + offset) >> (mult_shift + src_shift)
572 *
573 * If SwsInternal->dstBpc is > 14, coeff is uint16_t and offset is int32_t,
574 * otherwise (SwsInternal->dstBpc is <= 14) coeff is uint32_t and offset is
575 * int64_t.
576 */
577static void solve_range_convert(uint16_t src_min, uint16_t src_max,
578 uint16_t dst_min, uint16_t dst_max,
579 int src_bits, int src_shift, int mult_shift,
580 uint32_t *coeff, int64_t *offset)
581{
582 uint16_t src_range = src_max - src_min;
583 uint16_t dst_range = dst_max - dst_min;
584 int total_shift = mult_shift + src_shift;
585 *coeff = AV_CEIL_RSHIFT(((uint64_t) dst_range << total_shift) / src_range, src_shift);
586 *offset = ((int64_t) dst_max << total_shift) -
587 ((int64_t) src_max << src_shift) * *coeff +
588 (1U << (mult_shift - 1));
589}
590
592{
593 const int bit_depth = c->dstBpc ? FFMIN(c->dstBpc, 16) : 8;
594 const int src_bits = bit_depth <= 14 ? 15 : 19;
595 const int src_shift = src_bits - bit_depth;
596 const int mult_shift = bit_depth <= 14 ? 14 : 18;
597 const uint16_t mpeg_min = 16U << (bit_depth - 8);
598 const uint16_t mpeg_max_lum = 235U << (bit_depth - 8);
599 const uint16_t mpeg_max_chr = 240U << (bit_depth - 8);
600 const uint16_t jpeg_max = (1U << bit_depth) - 1;
601 uint16_t src_min, src_max_lum, src_max_chr;
602 uint16_t dst_min, dst_max_lum, dst_max_chr;
603 if (c->opts.src_range) {
604 src_min = 0;
605 src_max_lum = jpeg_max;
606 src_max_chr = jpeg_max;
607 dst_min = mpeg_min;
608 dst_max_lum = mpeg_max_lum;
609 dst_max_chr = mpeg_max_chr;
610 } else {
611 src_min = mpeg_min;
612 src_max_lum = mpeg_max_lum;
613 src_max_chr = mpeg_max_chr;
614 dst_min = 0;
615 dst_max_lum = jpeg_max;
616 dst_max_chr = jpeg_max;
617 }
618 solve_range_convert(src_min, src_max_lum, dst_min, dst_max_lum,
619 src_bits, src_shift, mult_shift,
620 &c->lumConvertRange_coeff, &c->lumConvertRange_offset);
621 solve_range_convert(src_min, src_max_chr, dst_min, dst_max_chr,
622 src_bits, src_shift, mult_shift,
623 &c->chrConvertRange_coeff, &c->chrConvertRange_offset);
624}
625
627{
628 c->lumConvertRange = NULL;
629 c->chrConvertRange = NULL;
630 if (c->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format) && c->dstBpc < 32) {
632 if (c->dstBpc <= 14) {
633 if (c->opts.src_range) {
634 c->lumConvertRange = lumRangeFromJpeg_c;
635 c->chrConvertRange = chrRangeFromJpeg_c;
636 } else {
637 c->lumConvertRange = lumRangeToJpeg_c;
638 c->chrConvertRange = chrRangeToJpeg_c;
639 }
640 } else {
641 if (c->opts.src_range) {
642 c->lumConvertRange = lumRangeFromJpeg16_c;
643 c->chrConvertRange = chrRangeFromJpeg16_c;
644 } else {
645 c->lumConvertRange = lumRangeToJpeg16_c;
646 c->chrConvertRange = chrRangeToJpeg16_c;
647 }
648 }
649
650#if ARCH_AARCH64
652#elif ARCH_LOONGARCH64
654#elif ARCH_RISCV
656#elif ARCH_X86
658#endif
659 }
660}
661
663{
664 enum AVPixelFormat srcFormat = c->opts.src_format;
665
667
668 ff_sws_init_output_funcs(c, &c->yuv2plane1, &c->yuv2planeX,
669 &c->yuv2nv12cX, &c->yuv2packed1,
670 &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
671
672 ff_sws_init_input_funcs(c, &c->lumToYV12, &c->alpToYV12, &c->chrToYV12,
673 &c->readLumPlanar, &c->readAlpPlanar, &c->readChrPlanar);
674
675 if (c->srcBpc == 8) {
676 if (c->dstBpc <= 14) {
677 c->hyScale = c->hcScale = hScale8To15_c;
678 if (c->opts.flags & SWS_FAST_BILINEAR) {
679 c->hyscale_fast = ff_hyscale_fast_c;
680 c->hcscale_fast = ff_hcscale_fast_c;
681 }
682 } else {
683 c->hyScale = c->hcScale = hScale8To19_c;
684 }
685 } else {
686 c->hyScale = c->hcScale = c->dstBpc > 14 ? hScale16To19_c
688 }
689
691
692 if (!(isGray(srcFormat) || isGray(c->opts.dst_format) ||
693 srcFormat == AV_PIX_FMT_MONOBLACK || srcFormat == AV_PIX_FMT_MONOWHITE))
694 c->needs_hcscale = 1;
695}
696
698{
700
701#if ARCH_PPC
703#elif ARCH_X86
705#elif ARCH_AARCH64
707#elif ARCH_ARM
709#elif ARCH_LOONGARCH64
711#elif ARCH_RISCV
713#endif
714}
715
716static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
717{
718 if (!isALPHA(format))
719 src[3] = NULL;
720 if (!isPlanar(format)) {
721 src[3] = src[2] = NULL;
722
723 if (!usePal(format))
724 src[1] = NULL;
725 }
726}
727
728static int check_image_pointers(const uint8_t * const data[4], enum AVPixelFormat pix_fmt,
729 const int linesizes[4])
730{
732 int i;
733
735
736 for (i = 0; i < 4; i++) {
737 int plane = desc->comp[i].plane;
738 if (!data[plane] || !linesizes[plane])
739 return 0;
740 }
741
742 return 1;
743}
744
745static void xyz12Torgb48_c(const SwsInternal *c, uint8_t *dst, int dst_stride,
746 const uint8_t *src, int src_stride, int w, int h)
747{
748 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.src_format);
749
750 for (int yp = 0; yp < h; yp++) {
751 const uint16_t *src16 = (const uint16_t *) src;
752 uint16_t *dst16 = (uint16_t *) dst;
753
754 for (int xp = 0; xp < 3 * w; xp += 3) {
755 int x, y, z, r, g, b;
756
757 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
758 x = AV_RB16(src16 + xp + 0);
759 y = AV_RB16(src16 + xp + 1);
760 z = AV_RB16(src16 + xp + 2);
761 } else {
762 x = AV_RL16(src16 + xp + 0);
763 y = AV_RL16(src16 + xp + 1);
764 z = AV_RL16(src16 + xp + 2);
765 }
766
767 x = c->xyz2rgb.gamma.in[x >> 4];
768 y = c->xyz2rgb.gamma.in[y >> 4];
769 z = c->xyz2rgb.gamma.in[z >> 4];
770
771 // convert from XYZlinear to sRGBlinear
772 r = c->xyz2rgb.mat[0][0] * x +
773 c->xyz2rgb.mat[0][1] * y +
774 c->xyz2rgb.mat[0][2] * z >> 12;
775 g = c->xyz2rgb.mat[1][0] * x +
776 c->xyz2rgb.mat[1][1] * y +
777 c->xyz2rgb.mat[1][2] * z >> 12;
778 b = c->xyz2rgb.mat[2][0] * x +
779 c->xyz2rgb.mat[2][1] * y +
780 c->xyz2rgb.mat[2][2] * z >> 12;
781
782 // limit values to 16-bit depth
783 r = av_clip_uint16(r);
784 g = av_clip_uint16(g);
785 b = av_clip_uint16(b);
786
787 // convert from sRGBlinear to RGB and scale from 12bit to 16bit
788 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
789 AV_WB16(dst16 + xp + 0, c->xyz2rgb.gamma.out[r] << 4);
790 AV_WB16(dst16 + xp + 1, c->xyz2rgb.gamma.out[g] << 4);
791 AV_WB16(dst16 + xp + 2, c->xyz2rgb.gamma.out[b] << 4);
792 } else {
793 AV_WL16(dst16 + xp + 0, c->xyz2rgb.gamma.out[r] << 4);
794 AV_WL16(dst16 + xp + 1, c->xyz2rgb.gamma.out[g] << 4);
795 AV_WL16(dst16 + xp + 2, c->xyz2rgb.gamma.out[b] << 4);
796 }
797 }
798
799 src += src_stride;
800 dst += dst_stride;
801 }
802}
803
804static void rgb48Toxyz12_c(const SwsInternal *c, uint8_t *dst, int dst_stride,
805 const uint8_t *src, int src_stride, int w, int h)
806{
807 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
808
809 for (int yp = 0; yp < h; yp++) {
810 uint16_t *src16 = (uint16_t *) src;
811 uint16_t *dst16 = (uint16_t *) dst;
812
813 for (int xp = 0; xp < 3 * w; xp += 3) {
814 int x, y, z, r, g, b;
815
816 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
817 r = AV_RB16(src16 + xp + 0);
818 g = AV_RB16(src16 + xp + 1);
819 b = AV_RB16(src16 + xp + 2);
820 } else {
821 r = AV_RL16(src16 + xp + 0);
822 g = AV_RL16(src16 + xp + 1);
823 b = AV_RL16(src16 + xp + 2);
824 }
825
826 r = c->rgb2xyz.gamma.in[r >> 4];
827 g = c->rgb2xyz.gamma.in[g >> 4];
828 b = c->rgb2xyz.gamma.in[b >> 4];
829
830 // convert from sRGBlinear to XYZlinear
831 x = c->rgb2xyz.mat[0][0] * r +
832 c->rgb2xyz.mat[0][1] * g +
833 c->rgb2xyz.mat[0][2] * b >> 12;
834 y = c->rgb2xyz.mat[1][0] * r +
835 c->rgb2xyz.mat[1][1] * g +
836 c->rgb2xyz.mat[1][2] * b >> 12;
837 z = c->rgb2xyz.mat[2][0] * r +
838 c->rgb2xyz.mat[2][1] * g +
839 c->rgb2xyz.mat[2][2] * b >> 12;
840
841 // limit values to 16-bit depth
842 x = av_clip_uint16(x);
843 y = av_clip_uint16(y);
844 z = av_clip_uint16(z);
845
846 // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
847 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
848 AV_WB16(dst16 + xp + 0, c->rgb2xyz.gamma.out[x] << 4);
849 AV_WB16(dst16 + xp + 1, c->rgb2xyz.gamma.out[y] << 4);
850 AV_WB16(dst16 + xp + 2, c->rgb2xyz.gamma.out[z] << 4);
851 } else {
852 AV_WL16(dst16 + xp + 0, c->rgb2xyz.gamma.out[x] << 4);
853 AV_WL16(dst16 + xp + 1, c->rgb2xyz.gamma.out[y] << 4);
854 AV_WL16(dst16 + xp + 2, c->rgb2xyz.gamma.out[z] << 4);
855 }
856 }
857
858 src += src_stride;
859 dst += dst_stride;
860 }
861}
862
864{
865 c->xyz12Torgb48 = xyz12Torgb48_c;
866 c->rgb48Toxyz12 = rgb48Toxyz12_c;
867
868#if ARCH_AARCH64
870#endif
871}
872
873void ff_update_palette(SwsInternal *c, const uint32_t *pal)
874{
875 uint32_t *rgb2yuv = c->input_rgb2yuv_table;
876
877 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
878 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
879 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
880
881 for (int i = 0; i < 256; i++) {
882 int r, g, b, y, u, v, a = 0xff;
883 if (c->opts.src_format == AV_PIX_FMT_PAL8) {
884 uint32_t p = pal[i];
885 a = (p >> 24) & 0xFF;
886 r = (p >> 16) & 0xFF;
887 g = (p >> 8) & 0xFF;
888 b = p & 0xFF;
889 } else if (c->opts.src_format == AV_PIX_FMT_RGB8) {
890 r = ( i >> 5 ) * 36;
891 g = ((i >> 2) & 7) * 36;
892 b = ( i & 3) * 85;
893 } else if (c->opts.src_format == AV_PIX_FMT_BGR8) {
894 b = ( i >> 6 ) * 85;
895 g = ((i >> 3) & 7) * 36;
896 r = ( i & 7) * 36;
897 } else if (c->opts.src_format == AV_PIX_FMT_RGB4_BYTE) {
898 r = ( i >> 3 ) * 255;
899 g = ((i >> 1) & 3) * 85;
900 b = ( i & 1) * 255;
901 } else if (c->opts.src_format == AV_PIX_FMT_GRAY8 || c->opts.src_format == AV_PIX_FMT_GRAY8A) {
902 r = g = b = i;
903 } else {
904 av_assert1(c->opts.src_format == AV_PIX_FMT_BGR4_BYTE);
905 b = ( i >> 3 ) * 255;
906 g = ((i >> 1) & 3) * 85;
907 r = ( i & 1) * 255;
908 }
909
910 y = av_clip_uint8((ry * r + gy * g + by * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
911 u = av_clip_uint8((ru * r + gu * g + bu * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
912 v = av_clip_uint8((rv * r + gv * g + bv * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
913
914 c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
915
916 switch (c->opts.dst_format) {
917 case AV_PIX_FMT_BGR32:
918#if !HAVE_BIGENDIAN
919 case AV_PIX_FMT_RGB24:
920#endif
921 c->pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
922 break;
924#if HAVE_BIGENDIAN
925 case AV_PIX_FMT_BGR24:
926#endif
927 c->pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
928 break;
930#if HAVE_BIGENDIAN
931 case AV_PIX_FMT_RGB24:
932#endif
933 c->pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
934 break;
935 case AV_PIX_FMT_GBRP:
936 case AV_PIX_FMT_GBRAP:
937#if HAVE_BIGENDIAN
938 c->pal_rgb[i]= a + (r<<8) + (b<<16) + ((unsigned)g<<24);
939#else
940 c->pal_rgb[i]= g + (b<<8) + (r<<16) + ((unsigned)a<<24);
941#endif
942 break;
943 case AV_PIX_FMT_RGB32:
944#if !HAVE_BIGENDIAN
945 case AV_PIX_FMT_BGR24:
946#endif
947 default:
948 c->pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
949 }
950 }
951}
952
953static int scale_internal(SwsContext *sws,
954 const uint8_t * const srcSlice[], const int srcStride[],
955 int srcSliceY, int srcSliceH,
956 uint8_t *const dstSlice[], const int dstStride[],
957 int dstSliceY, int dstSliceH);
958
960 const uint8_t * const srcSlice[], const int srcStride[],
961 int srcSliceY, int srcSliceH,
962 uint8_t * const dstSlice[], const int dstStride[],
963 int dstSliceY, int dstSliceH)
964{
965 int ret = scale_internal(c->cascaded_context[0],
966 srcSlice, srcStride, srcSliceY, srcSliceH,
967 c->cascaded_tmp[0], c->cascaded_tmpStride[0], 0, c->opts.src_h);
968
969 if (ret < 0)
970 return ret;
971
972 if (c->cascaded_context[2])
973 ret = scale_internal(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp[0],
974 c->cascaded_tmpStride[0], srcSliceY, srcSliceH,
975 c->cascaded_tmp[1], c->cascaded_tmpStride[1], 0, c->opts.dst_h);
976 else
977 ret = scale_internal(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp[0],
978 c->cascaded_tmpStride[0], srcSliceY, srcSliceH,
979 dstSlice, dstStride, dstSliceY, dstSliceH);
980
981 if (ret < 0)
982 return ret;
983
984 if (c->cascaded_context[2]) {
985 const int dstY1 = sws_internal(c->cascaded_context[1])->dstY;
986 ret = scale_internal(c->cascaded_context[2], (const uint8_t * const *)c->cascaded_tmp[1],
987 c->cascaded_tmpStride[1], dstY1 - ret, dstY1,
988 dstSlice, dstStride, dstSliceY, dstSliceH);
989 }
990 return ret;
991}
992
994 const uint8_t * const srcSlice[], const int srcStride[],
995 int srcSliceY, int srcSliceH,
996 uint8_t * const dstSlice[], const int dstStride[],
997 int dstSliceY, int dstSliceH)
998{
999 const int dstH0 = c->cascaded_context[0]->dst_h;
1000 int ret = scale_internal(c->cascaded_context[0],
1001 srcSlice, srcStride, srcSliceY, srcSliceH,
1002 c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1003 0, dstH0);
1004 if (ret < 0)
1005 return ret;
1006
1007 /* The first stage assembles the full intermediate image from the input,
1008 * one slice at a time (it is itself a regular slice-capable context). The
1009 * second stage scales that whole intermediate to the output in one step,
1010 * so it can only run once the entire source has been consumed. The first
1011 * stage resets its slice direction to 0 at end of frame; until then the
1012 * intermediate is incomplete and this call produces no output lines. */
1013 if (sws_internal(c->cascaded_context[0])->sliceDir != 0)
1014 return 0;
1015
1016 ret = scale_internal(c->cascaded_context[1],
1017 (const uint8_t * const * )c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1018 0, dstH0, dstSlice, dstStride, dstSliceY, dstSliceH);
1019 return ret;
1020}
1021
1023 const uint8_t * const srcSlice[], const int srcStride[],
1024 int srcSliceY, int srcSliceH,
1025 uint8_t *const dstSlice[], const int dstStride[],
1026 int dstSliceY, int dstSliceH)
1027{
1028 SwsInternal *c = sws_internal(sws);
1029 const int scale_dst = dstSliceY > 0 || dstSliceH < sws->dst_h;
1030 const int frame_start = scale_dst || !c->sliceDir;
1031 int i, ret;
1032 const uint8_t *src2[4];
1033 uint8_t *dst2[4];
1034 int macro_height_src = isBayer(sws->src_format) ? 2 : (1 << c->chrSrcVSubSample);
1035 int macro_height_dst = isBayer(sws->dst_format) ? 2 : (1 << c->chrDstVSubSample);
1036 // copy strides, so they can safely be modified
1037 int srcStride2[4];
1038 int dstStride2[4];
1039 int srcSliceY_internal = srcSliceY;
1040
1041 if (!srcStride || !dstStride || !dstSlice || !srcSlice) {
1042 av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n");
1043 return AVERROR(EINVAL);
1044 }
1045
1046 if ((srcSliceY & (macro_height_src - 1)) ||
1047 ((srcSliceH & (macro_height_src - 1)) && srcSliceY + srcSliceH != sws->src_h) ||
1048 srcSliceY + srcSliceH > sws->src_h ||
1049 srcSliceY < 0 ||
1050 srcSliceH < 0 ||
1051 (isBayer(sws->src_format) && srcSliceH <= 1)) {
1052 av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH);
1053 return AVERROR(EINVAL);
1054 }
1055
1056 if ((dstSliceY & (macro_height_dst - 1)) ||
1057 ((dstSliceH & (macro_height_dst - 1)) && dstSliceY + dstSliceH != sws->dst_h) ||
1058 dstSliceY + dstSliceH > sws->dst_h) {
1059 av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", dstSliceY, dstSliceH);
1060 return AVERROR(EINVAL);
1061 }
1062
1063 if (!check_image_pointers(srcSlice, sws->src_format, srcStride)) {
1064 av_log(c, AV_LOG_ERROR, "bad src image pointers\n");
1065 return AVERROR(EINVAL);
1066 }
1067 if (!check_image_pointers((const uint8_t* const*)dstSlice, sws->dst_format, dstStride)) {
1068 av_log(c, AV_LOG_ERROR, "bad dst image pointers\n");
1069 return AVERROR(EINVAL);
1070 }
1071
1072 // do not mess up sliceDir if we have a "trailing" 0-size slice
1073 if (srcSliceH == 0)
1074 return 0;
1075
1076 if (sws->gamma_flag && c->cascaded_context[0])
1077 return scale_gamma(c, srcSlice, srcStride, srcSliceY, srcSliceH,
1078 dstSlice, dstStride, dstSliceY, dstSliceH);
1079
1080 if (c->cascaded_context[0])
1081 return scale_cascaded(c, srcSlice, srcStride, srcSliceY, srcSliceH,
1082 dstSlice, dstStride, dstSliceY, dstSliceH);
1083
1084 if (!srcSliceY && (sws->flags & SWS_BITEXACT) && sws->dither == SWS_DITHER_ED && c->dither_error[0])
1085 for (i = 0; i < 4; i++)
1086 memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (sws->dst_w+2));
1087
1088 if (usePal(sws->src_format))
1089 ff_update_palette(c, (const uint32_t *)srcSlice[1]);
1090
1091 memcpy(src2, srcSlice, sizeof(src2));
1092 memcpy(dst2, dstSlice, sizeof(dst2));
1093 memcpy(srcStride2, srcStride, sizeof(srcStride2));
1094 memcpy(dstStride2, dstStride, sizeof(dstStride2));
1095
1096 if (frame_start && !scale_dst) {
1097 if (srcSliceY != 0 && srcSliceY + srcSliceH != sws->src_h) {
1098 av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
1099 return AVERROR(EINVAL);
1100 }
1101
1102 c->sliceDir = (srcSliceY == 0) ? 1 : -1;
1103 } else if (scale_dst)
1104 c->sliceDir = 1;
1105
1106 if (c->src0Alpha && !c->dst0Alpha && isALPHA(sws->dst_format)) {
1107 uint8_t *base;
1108 int x,y;
1109
1110 av_fast_malloc(&c->rgb0_scratch, &c->rgb0_scratch_allocated,
1111 FFABS(srcStride[0]) * srcSliceH + 32);
1112 if (!c->rgb0_scratch)
1113 return AVERROR(ENOMEM);
1114
1115 base = srcStride[0] < 0 ? c->rgb0_scratch - srcStride[0] * (srcSliceH-1) :
1116 c->rgb0_scratch;
1117 for (y=0; y<srcSliceH; y++){
1118 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*sws->src_w);
1119 for (x=c->src0Alpha-1; x<4*sws->src_w; x+=4) {
1120 base[ srcStride[0]*y + x] = 0xFF;
1121 }
1122 }
1123 src2[0] = base;
1124 }
1125
1126 if (c->srcXYZ && !(c->dstXYZ && sws->src_w==sws->dst_w && sws->src_h==sws->dst_h)) {
1127 uint8_t *base;
1128
1129 av_fast_malloc(&c->xyz_scratch, &c->xyz_scratch_allocated,
1130 FFABS(srcStride[0]) * srcSliceH + 32);
1131 if (!c->xyz_scratch)
1132 return AVERROR(ENOMEM);
1133
1134 base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) :
1135 c->xyz_scratch;
1136
1137 c->xyz12Torgb48(c, base, srcStride[0], src2[0], srcStride[0], sws->src_w, srcSliceH);
1138 src2[0] = base;
1139 }
1140
1141 if (c->sliceDir != 1) {
1142 // slices go from bottom to top => we flip the image internally
1143 for (i=0; i<4; i++) {
1144 srcStride2[i] *= -1;
1145 dstStride2[i] *= -1;
1146 }
1147
1148 src2[0] += (srcSliceH - 1) * srcStride[0];
1149 if (!usePal(sws->src_format))
1150 src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1];
1151 src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2];
1152 src2[3] += (srcSliceH - 1) * srcStride[3];
1153 dst2[0] += ( sws->dst_h - 1) * dstStride[0];
1154 dst2[1] += ((sws->dst_h >> c->chrDstVSubSample) - 1) * dstStride[1];
1155 dst2[2] += ((sws->dst_h >> c->chrDstVSubSample) - 1) * dstStride[2];
1156 dst2[3] += ( sws->dst_h - 1) * dstStride[3];
1157
1158 srcSliceY_internal = sws->src_h-srcSliceY-srcSliceH;
1159 }
1160 reset_ptr(src2, sws->src_format);
1161 reset_ptr((void*)dst2, sws->dst_format);
1162
1163 if (c->convert_unscaled) {
1164 int offset = srcSliceY_internal;
1165 int slice_h = srcSliceH;
1166
1167 // for dst slice scaling, offset the pointers to match the unscaled API
1168 if (scale_dst) {
1169 av_assert0(offset == 0);
1170 for (i = 0; i < 4 && src2[i]; i++) {
1171 if (!src2[i] || (i > 0 && usePal(sws->src_format)))
1172 break;
1173 src2[i] += (dstSliceY >> ((i == 1 || i == 2) ? c->chrSrcVSubSample : 0)) * srcStride2[i];
1174 }
1175
1176 for (i = 0; i < 4 && dst2[i]; i++) {
1177 if (!dst2[i] || (i > 0 && usePal(sws->dst_format)))
1178 break;
1179 dst2[i] -= (dstSliceY >> ((i == 1 || i == 2) ? c->chrDstVSubSample : 0)) * dstStride2[i];
1180 }
1181 offset = dstSliceY;
1182 slice_h = dstSliceH;
1183 }
1184
1185 ret = c->convert_unscaled(c, src2, srcStride2, offset, slice_h,
1186 dst2, dstStride2);
1187 if (scale_dst)
1188 dst2[0] += dstSliceY * dstStride2[0];
1189 } else {
1190 ret = ff_swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH,
1191 dst2, dstStride2, dstSliceY, dstSliceH);
1192 }
1193
1194 if (c->dstXYZ && !(c->srcXYZ && sws->src_w==sws->dst_w && sws->src_h==sws->dst_h)) {
1195 uint8_t *dst;
1196
1197 if (scale_dst) {
1198 dst = dst2[0];
1199 } else {
1200 int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH;
1201
1202 av_assert0(dstY >= ret);
1203 av_assert0(ret >= 0);
1204 av_assert0(sws->dst_h >= dstY);
1205 dst = dst2[0] + (dstY - ret) * dstStride2[0];
1206 }
1207
1208 /* replace on the same data */
1209 c->rgb48Toxyz12(c, dst, dstStride2[0], dst, dstStride2[0], sws->dst_w, ret);
1210 }
1211
1212 /* reset slice direction at end of frame */
1213 if ((srcSliceY_internal + srcSliceH == sws->src_h) || scale_dst)
1214 c->sliceDir = 0;
1215
1216 return ret;
1217}
1218
1220{
1221 SwsInternal *c = sws_internal(sws);
1222 if (!c->is_legacy_init)
1223 return;
1224 av_frame_unref(c->frame_src);
1225 av_frame_unref(c->frame_dst);
1226 c->src_ranges.nb_ranges = 0;
1227}
1228
1229static int ptr_in_buf(const uint8_t *ptr, const AVBufferRef *buf)
1230{
1231 uintptr_t ptr_val = (uintptr_t) ptr;
1232 uintptr_t buf_start = (uintptr_t) buf->data;
1233 return ptr_val >= buf_start && ptr_val < buf_start + buf->size;
1234}
1235
1236/* Similar to av_frame_ref() but only references planes in the given map */
1237static int frame_ref(AVFrame *dst, const AVFrame *src, const int plane_copy[4])
1238{
1239 int copied[AV_NUM_DATA_POINTERS] = {0};
1240 int nb_copied = 0;
1241
1242 for (int i = 0; i < 4; i++) {
1243 const int idx = plane_copy[i];
1244 if (idx < 0)
1245 continue;
1246 /* Find corresponding source buffer */
1247 uint8_t *src_data = src->data[idx];
1248 if (!src_data)
1249 return AVERROR(EINVAL);
1250 for (int j = 0; j < FF_ARRAY_ELEMS(src->buf); j++) {
1251 AVBufferRef *buf = src->buf[j];
1252 if (!buf)
1253 break;
1254 if (!ptr_in_buf(src_data, buf))
1255 continue;
1256 if (!copied[j]) {
1258 if (!ref)
1259 return AVERROR(ENOMEM);
1260 dst->buf[nb_copied++] = ref;
1261 copied[j] = 1;
1262 }
1263 dst->data[i] = src_data;
1264 dst->linesize[i] = src->linesize[idx];
1265 break;
1266 }
1267 }
1268
1269 return 0;
1270}
1271
1272/* Returns the number of buffers allocated */
1274{
1275 SwsInternal *c = sws_internal(sws);
1276 FFFramePool *pool = &c->frame_pool;
1277 av_assert0(!frame->hw_frames_ctx);
1278
1279 /* Find first free buffer slot */
1280 int buf_start = 0;
1281 while (frame->buf[buf_start])
1282 buf_start++;
1283 int nb_bufs = 0;
1284
1285 const int nb_planes = av_pix_fmt_count_planes(frame->format);
1286 for (int i = 0; i < nb_planes; i++) {
1287 if (frame->data[i])
1288 continue; /* already ref'd by frame_ref */
1289
1290 const int idx = buf_start + nb_bufs++;
1291 av_assert1(idx < FF_ARRAY_ELEMS(frame->buf));
1292 frame->buf[idx] = av_buffer_pool_get(pool->pools[i]);
1293 if (!frame->buf[idx]) {
1295 return AVERROR(ENOMEM);
1296 }
1297 frame->data[i] = frame->buf[idx]->data;
1298 frame->linesize[i] = pool->linesize[i];
1299 }
1300
1301 return nb_bufs;
1302}
1303
1305{
1306 SwsInternal *c = sws_internal(sws);
1307 int ret, allocated = 0;
1308 if (!c->is_legacy_init)
1309 return AVERROR(EINVAL);
1310
1311 ret = av_frame_ref(c->frame_src, src);
1312 if (ret < 0)
1313 return ret;
1314
1315 if (!dst->buf[0]) {
1316 dst->width = sws->dst_w;
1317 dst->height = sws->dst_h;
1318 dst->format = sws->dst_format;
1319
1320 ret = av_frame_get_buffer(dst, 0);
1321 if (ret < 0)
1322 return ret;
1323 allocated = 1;
1324 }
1325
1326 ret = av_frame_ref(c->frame_dst, dst);
1327 if (ret < 0) {
1328 if (allocated)
1330
1331 return ret;
1332 }
1333
1334 return 0;
1335}
1336
1338 unsigned int slice_height)
1339{
1340 SwsInternal *c = sws_internal(sws);
1341 int ret;
1342 if (!c->is_legacy_init)
1343 return AVERROR(EINVAL);
1344
1345 ret = ff_range_add(&c->src_ranges, slice_start, slice_height);
1346 if (ret < 0)
1347 return ret;
1348
1349 return 0;
1350}
1351
1353{
1354 SwsInternal *c = sws_internal(sws);
1355 if (c->slice_ctx)
1356 return sws_internal(c->slice_ctx[0])->dst_slice_align;
1357
1358 return c->dst_slice_align;
1359}
1360
1362 unsigned int slice_height)
1363{
1364 SwsInternal *c = sws_internal(sws);
1365 unsigned int align = sws_receive_slice_alignment(sws);
1366 uint8_t *dst[4];
1367 if (!c->is_legacy_init)
1368 return AVERROR(EINVAL);
1369
1370 /* wait until complete input has been received */
1371 if (!(c->src_ranges.nb_ranges == 1 &&
1372 c->src_ranges.ranges[0].start == 0 &&
1373 c->src_ranges.ranges[0].len == sws->src_h))
1374 return AVERROR(EAGAIN);
1375
1376 if ((slice_start > 0 || slice_height < sws->dst_h) &&
1377 (slice_start % align || slice_height % align)) {
1379 "Incorrectly aligned output: %u/%u not multiples of %u\n",
1380 slice_start, slice_height, align);
1381 return AVERROR(EINVAL);
1382 }
1383
1384 if (c->slicethread) {
1385 int nb_jobs = c->nb_slice_ctx;
1386 if (c->slice_ctx[0]->dither == SWS_DITHER_ED)
1387 nb_jobs = 1;
1388
1389 c->dst_slice_start = slice_start;
1390 c->dst_slice_height = slice_height;
1391
1392 return avpriv_slicethread_execute2(c->slicethread, nb_jobs, 0);
1393 }
1394
1395 for (int i = 0; i < FF_ARRAY_ELEMS(dst); i++) {
1396 ptrdiff_t offset = c->frame_dst->linesize[i] * (ptrdiff_t)(slice_start >> c->chrDstVSubSample);
1397 dst[i] = FF_PTR_ADD(c->frame_dst->data[i], offset);
1398 }
1399
1400 return scale_internal(sws, (const uint8_t * const *)c->frame_src->data,
1401 c->frame_src->linesize, 0, sws->src_h,
1402 dst, c->frame_dst->linesize, slice_start, slice_height);
1403}
1404
1406{
1407 int ret, allocated = 0;
1408 SwsInternal *c = sws_internal(sws);
1409 if (!src || !dst)
1410 return AVERROR(EINVAL);
1411
1412 if (c->is_legacy_init) {
1413 /* Context has been initialized with explicit values, fall back to
1414 * legacy API behavior. */
1415 ret = sws_frame_start(sws, dst, src);
1416 if (ret < 0)
1417 return ret;
1418
1419 ret = sws_send_slice(sws, 0, src->height);
1420 if (ret >= 0)
1421 ret = sws_receive_slice(sws, 0, dst->height);
1422
1423 sws_frame_end(sws);
1424
1425 return ret;
1426 }
1427
1428 ret = sws_frame_setup(sws, dst, src);
1429 if (ret < 0)
1430 return ret;
1431
1432 if (!src->data[0])
1433 return 0;
1434
1435 const SwsGraph *top = c->graph[FIELD_TOP];
1436 const SwsGraph *bot = c->graph[FIELD_BOTTOM];
1437 if (dst->data[0]) /* user-provided buffers */
1438 goto process_frame;
1439
1440 /* Sanity */
1441 memset(dst->buf, 0, sizeof(dst->buf));
1442 memset(dst->data, 0, sizeof(dst->data));
1443 memset(dst->linesize, 0, sizeof(dst->linesize));
1444 dst->extended_data = dst->data;
1445
1446 if (src->buf[0]) {
1447 /* Determine end-to-end plane copy map */
1448 int plane_copy[FF_ARRAY_ELEMS(top->plane_copy)];
1449 memcpy(plane_copy, top->plane_copy, sizeof(plane_copy));
1450 for (int i = 0; bot && i < FF_ARRAY_ELEMS(plane_copy); i++) {
1451 if (bot->plane_copy[i] != plane_copy[i])
1452 plane_copy[i] = -1;
1453 }
1454
1455 ret = frame_ref(dst, src, plane_copy);
1456 if (ret < 0)
1457 return ret;
1458 }
1459
1460 /* Allocate any missing buffers not yet ref'd */
1461 ret = frame_alloc_buffers(sws, dst);
1462 if (ret < 0)
1463 return ret;
1464 else if (!ret)
1465 return 0; /* no buffers allocated, no-op (all ref'd) */
1466 else
1467 allocated = 1;
1468
1470 for (int field = 0; field < (bot ? 2 : 1); field++) {
1471 ret = ff_sws_graph_run(c->graph[field], dst, src);
1472 if (ret < 0) {
1473 if (allocated)
1475 return ret;
1476 }
1477 }
1478
1479 return 0;
1480}
1481
1483{
1484#define VALIDATE(field, min, max) \
1485 if (ctx->field < min || ctx->field > max) { \
1486 av_log(ctx, AV_LOG_ERROR, "'%s' (%d) out of range [%d, %d]\n", \
1487 #field, (int) ctx->field, min, max); \
1488 return AVERROR(EINVAL); \
1489 }
1490
1491 VALIDATE(threads, 0, SWS_MAX_THREADS);
1493 VALIDATE(alpha_blend, 0, SWS_ALPHA_BLEND_NB - 1)
1494 VALIDATE(intent, 0, SWS_INTENT_NB - 1);
1495 VALIDATE(scaler, 0, SWS_SCALE_NB - 1)
1496 VALIDATE(scaler_sub, 0, SWS_SCALE_NB - 1)
1497 return 0;
1498}
1499
1501{
1503 const char *err_msg;
1504 int ret;
1505
1506 if (!src || !dst)
1507 return AVERROR(EINVAL);
1508 if ((ret = validate_params(ctx)) < 0)
1509 return ret;
1510
1511 /* For now, if a single frame has a context, then both need a context */
1512 if (!!src->hw_frames_ctx != !!dst->hw_frames_ctx) {
1513 return AVERROR(ENOTSUP);
1514 } else if (!!src->hw_frames_ctx) {
1515 /* Both hardware frames must already be allocated */
1516 if (!src->data[0] || !dst->data[0])
1517 return AVERROR(EINVAL);
1518
1519 AVHWFramesContext *src_hwfc, *dst_hwfc;
1520 src_hwfc = (AVHWFramesContext *)src->hw_frames_ctx->data;
1521 dst_hwfc = (AVHWFramesContext *)dst->hw_frames_ctx->data;
1522
1523 /* Both frames must live on the same device */
1524 if (src_hwfc->device_ref->data != dst_hwfc->device_ref->data)
1525 return AVERROR(EINVAL);
1526
1527 /* Only Vulkan devices are supported */
1528 AVHWDeviceContext *dev_ctx;
1529 dev_ctx = (AVHWDeviceContext *)src_hwfc->device_ref->data;
1530 if (dev_ctx->type != AV_HWDEVICE_TYPE_VULKAN)
1531 return AVERROR(ENOTSUP);
1532
1533#if CONFIG_UNSTABLE && CONFIG_VULKAN
1534 ret = ff_sws_vk_init(ctx, src_hwfc->device_ref);
1535 if (ret < 0)
1536 return ret;
1537#endif
1538 }
1539
1540 int dst_width = dst->width;
1541 const SwsBackend backends = ff_sws_enabled_backends(ctx);
1542 for (int field = 0; field < 2; field++) {
1543 SwsFormat src_fmt = ff_fmt_from_frame(src, field);
1544 SwsFormat dst_fmt = ff_fmt_from_frame(dst, field);
1545 int src_ok, dst_ok;
1546
1547 if ((src->flags ^ dst->flags) & AV_FRAME_FLAG_INTERLACED) {
1548 err_msg = "Cannot convert interlaced to progressive frames or vice versa.\n";
1549 ret = AVERROR(EINVAL);
1550 goto fail;
1551 }
1552
1553 src_ok = ff_test_fmt(backends, &src_fmt, 0);
1554 dst_ok = ff_test_fmt(backends, &dst_fmt, 1);
1555 if ((!src_ok || !dst_ok) && !ff_fmt_equal(&src_fmt, &dst_fmt)) {
1556 err_msg = src_ok ? "Unsupported output" : "Unsupported input";
1557 ret = AVERROR(ENOTSUP);
1558 goto fail;
1559 }
1560
1561 if (!s->graph[field]) {
1562 s->graph[field] = ff_sws_graph_alloc();
1563 if (!s->graph[field]) {
1564 err_msg = "Failed allocating scaling graph";
1565 ret = AVERROR(ENOMEM);
1566 goto fail;
1567 }
1568 }
1569
1570 ret = ff_sws_graph_reinit(s->graph[field], ctx, &dst_fmt, &src_fmt);
1571 if (ret < 0) {
1572 err_msg = "Failed initializing scaling graph";
1573 goto fail;
1574 }
1575
1576 const SwsGraph *graph = s->graph[field];
1577 if (graph->incomplete && ctx->flags & SWS_STRICT) {
1578 err_msg = "Incomplete scaling graph";
1579 ret = AVERROR(EINVAL);
1580 goto fail;
1581 }
1582
1583 if (!graph->noop) {
1584 av_assert0(graph->num_passes);
1585 const SwsPass *last_pass = graph->passes[graph->num_passes - 1];
1586 const int aligned_w = ff_sws_pass_aligned_width(last_pass, dst->width);
1587 dst_width = FFMAX(dst_width, aligned_w);
1588 }
1589
1590 if (!src_fmt.interlaced) {
1592 break;
1593 }
1594
1595 continue;
1596
1597 fail:
1598 av_log(ctx, AV_LOG_ERROR, "%s (%s): fmt:%s csp:%s prim:%s trc:%s ->"
1599 " fmt:%s csp:%s prim:%s trc:%s\n",
1600 err_msg, av_err2str(ret),
1605
1606 for (int i = 0; i < FF_ARRAY_ELEMS(s->graph); i++)
1607 ff_sws_graph_free(&s->graph[i]);
1608
1609 return ret;
1610 }
1611
1612 if (!dst->hw_frames_ctx) {
1613 ret = ff_frame_pool_video_reinit(&s->frame_pool, dst_width, dst->height,
1614 dst->format, av_cpu_max_align());
1615 if (ret < 0)
1616 return ret;
1617 }
1618
1619 return 0;
1620}
1621
1622/**
1623 * swscale wrapper, so we don't need to export the SwsContext.
1624 * Assumes planar YUV to be in YUV order instead of YVU.
1625 */
1627 const uint8_t * const srcSlice[],
1628 const int srcStride[], int srcSliceY,
1629 int srcSliceH, uint8_t *const dst[],
1630 const int dstStride[])
1631{
1632 SwsInternal *c = sws_internal(sws);
1633 if (!c->is_legacy_init)
1634 return AVERROR(EINVAL);
1635
1636 if (c->nb_slice_ctx) {
1637 sws = c->slice_ctx[0];
1638 c = sws_internal(sws);
1639 }
1640
1641 return scale_internal(sws, srcSlice, srcStride, srcSliceY, srcSliceH,
1642 dst, dstStride, 0, sws->dst_h);
1643}
1644
1645int ff_sws_slice_worker(void *priv, int jobnr, int threadnr,
1646 int nb_jobs, int nb_threads)
1647{
1648 SwsInternal *parent = priv;
1649 SwsContext *sws = parent->slice_ctx[threadnr];
1650 SwsInternal *c = sws_internal(sws);
1651
1652 const int slice_height = FFALIGN(FFMAX((parent->dst_slice_height + nb_jobs - 1) / nb_jobs, 1),
1653 c->dst_slice_align);
1654 const int slice_start = jobnr * slice_height;
1655 const int slice_end = FFMIN((jobnr + 1) * slice_height, parent->dst_slice_height);
1656 int err = 0;
1657
1658 if (slice_end > slice_start) {
1659 uint8_t *dst[4] = { NULL };
1660
1661 for (int i = 0; i < FF_ARRAY_ELEMS(dst) && parent->frame_dst->data[i]; i++) {
1662 const int vshift = (i == 1 || i == 2) ? c->chrDstVSubSample : 0;
1663 const ptrdiff_t offset = parent->frame_dst->linesize[i] *
1664 (ptrdiff_t)((slice_start + parent->dst_slice_start) >> vshift);
1665
1666 dst[i] = parent->frame_dst->data[i] + offset;
1667 }
1668
1669 err = scale_internal(sws, (const uint8_t * const *)parent->frame_src->data,
1670 parent->frame_src->linesize, 0, sws->src_h,
1671 dst, parent->frame_dst->linesize,
1673 }
1674
1675 if (err < 0)
1676 return err;
1677
1678 return 0; /* ff_slicethread_execute() aborts on non-zero */
1679}
uint8_t * _dst
Definition dsp.h:56
uint8_t ptrdiff_t const uint8_t * _src
Definition dsp.h:56
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
av_cold void ff_sws_init_xyzdsp_aarch64(SwsInternal *c)
Definition swscale.c:339
av_cold void ff_sws_init_swscale_aarch64(SwsInternal *c)
Definition swscale.c:350
av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c)
Definition swscale.c:314
static double val(void *priv, double ch)
Definition aeval.c:77
static const char *const format[]
Definition af_aiir.c:444
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition af_astats.c:246
static AVFormatContext * ctx
av_cold void ff_sws_init_swscale_arm(SwsInternal *c)
Definition swscale.c:33
#define U(x)
Definition vpx_arith.h:37
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
int32_t
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_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define V
Definition avdct.c:32
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define Y
Definition boxblur.h:37
byte swapping routines
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static void fn rgb2yuv(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t s, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8])
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_clip_uint8
Definition common.h:106
#define av_clip_uint16
Definition common.h:112
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static enum AVPixelFormat pix_fmt
static AVFrame * frame
#define atomic_exchange_explicit(object, desired, order)
Definition stdatomic.h:106
#define emms_c()
Definition emms.h:88
static const uint8_t bits[8]
Definition fastaudio.c:100
static av_always_inline int process_frame(AVTextFormatContext *tfc, InputFile *ifile, AVFrame *frame, const AVPacket *pkt, int *packet_new)
Definition ffprobe.c:1596
@ FIELD_TOP
Definition format.h:56
@ FIELD_BOTTOM
Definition format.h:57
static int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
Definition format.h:125
#define AV_NUM_DATA_POINTERS
Definition frame.h:473
int ff_sws_graph_run(SwsGraph *graph, const AVFrame *dst, const AVFrame *src)
Dispatch the filter graph on a single field of the given frames.
Definition graph.c:1026
SwsGraph * ff_sws_graph_alloc(void)
Allocate an empty SwsGraph.
Definition graph.c:866
int ff_sws_pass_aligned_width(const SwsPass *pass, int width)
Align width to the optimal size for pass.
Definition graph.c:46
int ff_sws_graph_reinit(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src)
Wrapper around ff_sws_graph_init() that reuses the existing graph if the format is compatible.
Definition graph.c:973
void ff_sws_graph_free(SwsGraph **pgraph)
Uninitialize any state associate with this filter graph and free it.
Definition graph.c:942
#define fail
Definition test.h:479
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:103
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition buffer.c:390
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition frame.h:695
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition frame.c:206
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition frame.c:278
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition mem.c:555
int sws_receive_slice(SwsContext *sws, unsigned int slice_start, unsigned int slice_height)
Request a horizontal slice of the output data to be written into the frame previously provided to sws...
Definition swscale.c:1361
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
Definition swscale.c:1405
int sws_send_slice(SwsContext *sws, unsigned int slice_start, unsigned int slice_height)
Indicate that a horizontal slice of input data is available in the source frame previously provided t...
Definition swscale.c:1337
unsigned int sws_receive_slice_alignment(const SwsContext *sws)
Get the alignment required for slices.
Definition swscale.c:1352
int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
Definition swscale.c:1626
SwsBackend
Definition swscale.h:110
int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
Like sws_scale_frame, but without actually scaling.
Definition swscale.c:1500
void sws_frame_end(SwsContext *sws)
Finish the scaling process for a pair of source/destination frames previously submitted with sws_fram...
Definition swscale.c:1219
int sws_frame_start(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Initialize the scaling process for a given pair of source/destination frames.
Definition swscale.c:1304
@ SWS_INTENT_NB
not part of the ABI
Definition swscale.h:215
@ SWS_DITHER_NB
Definition swscale.h:84
@ SWS_DITHER_ED
Definition swscale.h:81
@ SWS_ALPHA_BLEND_NB
Definition swscale.h:92
@ SWS_SCALE_NB
not part of the ABI
Definition swscale.h:106
@ SWS_PRINT_INFO
Emit verbose log of scaling parameters.
Definition swscale.h:141
@ SWS_BITEXACT
Definition swscale.h:178
@ SWS_STRICT
Return an error on underspecified conversions.
Definition swscale.h:136
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition swscale.h:197
int a
const pixel * src2
void ff_hcscale_fast_c(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc)
void ff_hyscale_fast_c(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc)
@ AV_HWDEVICE_TYPE_VULKAN
Definition hwcontext.h:39
#define r
Definition input.c:42
#define b
Definition input.c:43
#define AV_RL16(p)
#define AV_WB16(p, v)
#define AV_WL16(p, v)
#define AV_RB16(p)
unsigned offset
Definition libaomenc.c:763
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
int ff_frame_pool_video_reinit(FFFramePool *pool, int width, int height, enum AVPixelFormat format, int align)
Recreate the video frame pool if its current configuration differs from the provided configuration.
Definition framepool.c:223
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition cpu.c:287
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
Definition cpu.h:37
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition cpu.h:33
#define FF_PTR_ADD(ptr, off)
Definition internal.h:74
#define attribute_align_arg
Definition internal.h:50
const char * desc
Definition libsvtav1.c:83
int ff_test_fmt(const SwsBackend backends, const SwsFormat *fmt, int output)
Statically test if a given format is supported by the given set of backends.
Definition format.c:668
SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field)
This function also sanitizes and strips the input data, removing irrelevant fields for certain format...
Definition format.c:345
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition mpeg12dec.c:1697
static void frame_start(MPVMainEncContext *const m)
const char data[16]
Definition mxf.c:149
av_cold void ff_sws_init_output_funcs(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX)
Definition output.c:3291
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3860
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3380
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition pixdesc.c:3827
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition pixdesc.c:3794
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition pixdesc.h:116
#define AV_PIX_FMT_BGR32
Definition pixfmt.h:519
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:83
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition pixfmt.h:143
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
Definition pixfmt.h:93
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition pixfmt.h:90
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition pixfmt.h:95
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition pixfmt.h:92
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:82
#define AV_PIX_FMT_RGB32_1
Definition pixfmt.h:518
#define AV_PIX_FMT_BGR32_1
Definition pixfmt.h:520
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:517
av_cold void ff_sws_init_range_convert_riscv(SwsInternal *c)
Definition swscale.c:29
av_cold void ff_sws_init_swscale_riscv(SwsInternal *c)
Definition swscale.c:74
#define FF_ARRAY_ELEMS(a)
int ff_rotate_slice(SwsSlice *s, int lum, int chr)
Definition slice.c:120
int ff_init_slice_from_src(SwsSlice *s, uint8_t *const src[4], const int stride[4], int srcW, int lumY, int lumH, int chrY, int chrH, int relative)
Definition slice.c:148
int avpriv_slicethread_execute2(AVSliceThread *ctx, int nb_jobs, int execute_main)
Execute slice threading.
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
size_t size
Size of data in bytes.
Definition buffer.h:94
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition hwcontext.h:75
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition hwcontext.h:129
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Frame pool.
Definition framepool.h:32
AVBufferPool * pools[4]
Definition framepool.h:52
int linesize[4]
Definition framepool.h:51
enum AVColorPrimaries prim
Definition format.h:61
enum AVColorTransferCharacteristic trc
Definition format.h:62
Main external API structure.
Definition swscale.h:227
int src_h
Width and height of the source frame.
Definition swscale.h:272
int dst_format
Destination pixel format.
Definition swscale.h:275
int gamma_flag
Use gamma correct scaling.
Definition swscale.h:264
int dst_h
Width and height of the destination frame.
Definition swscale.h:273
int dst_w
Definition swscale.h:273
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition swscale.h:272
int src_format
Source pixel format.
Definition swscale.h:274
SwsDither dither
Dither mode.
Definition swscale.h:254
unsigned flags
Bitmask of SWS_*.
Definition swscale.h:238
Struct which holds all necessary data for processing a slice.
SwsColor color
Definition format.h:87
enum AVPixelFormat format
Definition format.h:81
int interlaced
Definition format.h:79
enum AVColorSpace csp
Definition format.h:84
Filter graph, which represents a 'baked' pixel format conversion.
Definition graph.h:132
bool noop
Definition graph.h:137
SwsPass ** passes
Sorted sequence of filter passes to apply.
Definition graph.h:153
bool incomplete
Definition graph.h:136
int num_passes
Definition graph.h:154
int plane_copy[4]
Map of planes which directly copied from the input.
Definition graph.h:150
int dstY
Last destination vertical line output from last slice.
SwsContext ** slice_ctx
int sliceDir
Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
unsigned int dst_slice_align
AVFrame * frame_src
AVFrame * frame_dst
Represents a single filter pass in the scaling graph.
Definition graph.h:85
int available_lines
max number of lines that can be hold by this plane
int sliceY
index of first line
int sliceH
number of lines
Struct which defines a slice of an image to be scaled or an output for a scaled slice.
SwsPlane plane[MAX_SLICE_PLANES]
color planes
int width
Slice line width.
#define stride
#define VALIDATE(field, min, max)
static void xyz12Torgb48_c(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
Definition swscale.c:745
static int validate_params(SwsContext *ctx)
Definition swscale.c:1482
const uint8_t ff_dither_8x8_128[9][8]
Definition swscale.c:42
static void hScale8To15_c(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition swscale.c:128
static av_cold void sws_init_swscale(SwsInternal *c)
Definition swscale.c:662
void ff_sws_init_scale(SwsInternal *c)
Definition swscale.c:697
static void lumRangeFromJpeg16_c(int16_t *_dst, int width, uint32_t coeff, int64_t offset)
Definition swscale.c:248
int ff_sws_slice_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
Definition swscale.c:1645
int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[], int dstSliceY, int dstSliceH)
Definition swscale.c:263
static int frame_alloc_buffers(SwsContext *sws, AVFrame *frame)
Definition swscale.c:1273
static void init_range_convert_constants(SwsInternal *c)
Definition swscale.c:591
static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width, uint32_t _coeff, int64_t _offset)
Definition swscale.c:163
static int frame_ref(AVFrame *dst, const AVFrame *src, const int plane_copy[4])
Definition swscale.c:1237
#define DEBUG_BUFFERS(...)
Definition swscale.c:259
static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
Definition swscale.c:716
static void hScale8To19_c(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition swscale.c:144
static int scale_gamma(SwsInternal *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH)
Definition swscale.c:959
static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width, uint32_t _coeff, int64_t _offset)
Definition swscale.c:177
static int scale_internal(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH)
Definition swscale.c:1022
static void lumRangeToJpeg16_c(int16_t *_dst, int width, uint32_t coeff, int64_t offset)
Definition swscale.c:237
static av_always_inline void fillPlane(uint8_t *plane, int stride, int width, int height, int y, uint8_t val)
Definition swscale.c:58
static void hScale16To19_c(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition swscale.c:69
static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width, uint32_t coeff, int64_t offset)
Definition swscale.c:211
static int scale_cascaded(SwsInternal *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH)
Definition swscale.c:993
static int check_image_pointers(const uint8_t *const data[4], enum AVPixelFormat pix_fmt, const int linesizes[4])
Definition swscale.c:728
av_cold void ff_sws_init_range_convert(SwsInternal *c)
Definition swscale.c:626
static void hScale16To15_c(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition swscale.c:99
av_cold void ff_sws_init_xyzdsp(SwsInternal *c)
Definition swscale.c:863
static void rgb48Toxyz12_c(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
Definition swscale.c:804
static int ptr_in_buf(const uint8_t *ptr, const AVBufferRef *buf)
Definition swscale.c:1229
static const uint8_t sws_pb_64[8]
Definition swscale.c:54
void ff_update_palette(SwsInternal *c, const uint32_t *pal)
Definition swscale.c:873
static void solve_range_convert(uint16_t src_min, uint16_t src_max, uint16_t dst_min, uint16_t dst_max, int src_bits, int src_shift, int mult_shift, uint32_t *coeff, int64_t *offset)
Definition swscale.c:577
static void lumRangeToJpeg_c(int16_t *dst, int width, uint32_t _coeff, int64_t _offset)
Definition swscale.c:189
static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width, uint32_t coeff, int64_t offset)
Definition swscale.c:225
static void lumRangeFromJpeg_c(int16_t *dst, int width, uint32_t _coeff, int64_t _offset)
Definition swscale.c:201
external API header
av_cold void ff_sws_init_swscale_ppc(SwsInternal *c)
av_cold void ff_sws_init_swscale_loongarch(SwsInternal *c)
av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c)
void ff_init_vscale_pfn(SwsInternal *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX, yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2, yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx)
setup vertical scaler functions
Definition vscale.c:258
void ff_updateMMXDitherTables(SwsInternal *c, int dstY)
Definition swscale.c:60
void(* yuv2packed1_fn)(SwsInternal *c, const int16_t *lumSrc, const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc, uint8_t *dest, int dstW, int uvalpha, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output without any additional v...
void(* yuv2planarX_fn)(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output with multi-point vertical scaling between...
int ff_range_add(RangeList *r, unsigned int start, unsigned int len)
Definition utils.c:2387
static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
#define BU_IDX
static void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, int alpha, int bits, const int big_endian)
#define RV_IDX
#define SWS_MAX_THREADS
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
void(* yuv2packedX_fn)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing multi-point ver...
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
void ff_sws_init_swscale_x86(SwsInternal *c)
Definition swscale.c:485
#define RY_IDX
#define BV_IDX
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
#define GV_IDX
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
SwsBackend ff_sws_enabled_backends(const SwsContext *ctx)
Definition utils.c:60
void(* yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output without any additional vertical scaling (...
static av_always_inline int isGray(enum AVPixelFormat pix_fmt)
static SwsInternal * sws_internal(const SwsContext *sws)
#define GU_IDX
static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
#define BY_IDX
av_cold void ff_sws_init_range_convert_x86(SwsInternal *c)
Definition swscale.c:469
void(* yuv2anyX_fn)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t **dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to YUV/RGB output by doing multi-point vertical scaling...
static void fillPlane32(uint8_t *plane, int stride, int width, int height, int y, int alpha, int bits, const int big_endian, int is_float)
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
void ff_sws_init_input_funcs(SwsInternal *c, planar1_YV12_fn *lumToYV12, planar1_YV12_fn *alpToYV12, planar2_YV12_fn *chrToYV12, planarX_YV12_fn *readLumPlanar, planarX_YV12_fn *readAlpPlanar, planarX2_YV12_fn *readChrPlanar)
void(* yuv2packed2_fn)(SwsInternal *c, const int16_t *lumSrc[2], const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing bilinear scalin...
void(* yuv2interleavedX_fn)(enum AVPixelFormat dstFormat, const uint8_t *chrDither, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int dstW)
Write one line of horizontally scaled chroma to interleaved output with multi-point vertical scaling ...
#define GY_IDX
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
#define RU_IDX
#define RGB2YUV_SHIFT
static av_always_inline int is32BPS(enum AVPixelFormat pix_fmt)
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
static void FUNC yuv2planeX(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
#define av_log(a,...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
const char * g
Definition vf_curves.c:128
static const uint16_t dither[8][8]
Definition vf_gradfun.c:46
static void process(NormalizeContext *s, AVFrame *in, AVFrame *out)
static const double coeff[2][5]
uint8_t base
Definition vp3data.h:128
static double c[64]
int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
Definition ops.c:41
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition dec.c:844