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_SWSCALE_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
257static void round_xyz12(uint8_t *plane, int stride, int width, int height, int y,
258 int big_endian)
259{
260 uint8_t *ptr = plane + stride * y;
261 for (int i = 0; i < height; i++) {
262 for (int j = 0; j < 3 * width; j++) {
263 unsigned v = big_endian ? AV_RB16(ptr + 2 * j) : AV_RL16(ptr + 2 * j);
264 v = FFMIN(v + 8, UINT16_MAX) & 0xFFF0;
265 if (big_endian)
266 AV_WB16(ptr + 2 * j, v);
267 else
268 AV_WL16(ptr + 2 * j, v);
269 }
270 ptr += stride;
271 }
272}
273
274
275#define DEBUG_SWSCALE_BUFFERS 0
276#define DEBUG_BUFFERS(...) \
277 if (DEBUG_SWSCALE_BUFFERS) \
278 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
279
280int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[],
281 int srcSliceY, int srcSliceH, uint8_t *const dst[],
282 const int dstStride[], int dstSliceY, int dstSliceH)
283{
284 const int scale_dst = dstSliceY > 0 || dstSliceH < c->opts.dst_h;
285
286 /* load a few things into local vars to make the code more readable?
287 * and faster */
288 const int dstW = c->opts.dst_w;
289 int dstH = c->opts.dst_h;
290
291 const enum AVPixelFormat dstFormat = c->opts.dst_format;
292 const int flags = c->opts.flags;
293 int32_t *vLumFilterPos = c->vLumFilterPos;
294 int32_t *vChrFilterPos = c->vChrFilterPos;
295
296 const int vLumFilterSize = c->vLumFilterSize;
297 const int vChrFilterSize = c->vChrFilterSize;
298
299 yuv2planar1_fn yuv2plane1 = c->yuv2plane1;
300 yuv2planarX_fn yuv2planeX = c->yuv2planeX;
301 yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX;
302 yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
303 yuv2packed2_fn yuv2packed2 = c->yuv2packed2;
304 yuv2packedX_fn yuv2packedX = c->yuv2packedX;
305 yuv2anyX_fn yuv2anyX = c->yuv2anyX;
306 const int chrSrcSliceY = srcSliceY >> c->chrSrcVSubSample;
307 const int chrSrcSliceH = AV_CEIL_RSHIFT(srcSliceH, c->chrSrcVSubSample);
308 int should_dither = isNBPS(c->opts.src_format) ||
309 is16BPS(c->opts.src_format);
310 int lastDstY;
311
312 /* vars which will change and which we need to store back in the context */
313 int dstY = c->dstY;
314 int lastInLumBuf = c->lastInLumBuf;
315 int lastInChrBuf = c->lastInChrBuf;
316
317 int lumStart = 0;
318 int lumEnd = c->descIndex[0];
319 int chrStart = lumEnd;
320 int chrEnd = c->descIndex[1];
321 int vStart = chrEnd;
322 int vEnd = c->numDesc;
323 SwsSlice *src_slice = &c->slice[lumStart];
324 SwsSlice *hout_slice = &c->slice[c->numSlice-2];
325 SwsSlice *vout_slice = &c->slice[c->numSlice-1];
326 SwsFilterDescriptor *desc = c->desc;
327
328 int needAlpha = c->needAlpha;
329
330 int hasLumHoles = 1;
331 int hasChrHoles = 1;
332
333 const uint8_t *src2[4];
334 int srcStride2[4];
335
336 if (isPacked(c->opts.src_format)) {
337 src2[0] =
338 src2[1] =
339 src2[2] =
340 src2[3] = src[0];
341 srcStride2[0] =
342 srcStride2[1] =
343 srcStride2[2] =
344 srcStride2[3] = srcStride[0];
345 } else {
346 memcpy(src2, src, sizeof(src2));
347 memcpy(srcStride2, srcStride, sizeof(srcStride2));
348 }
349
350 srcStride2[1] *= 1 << c->vChrDrop;
351 srcStride2[2] *= 1 << c->vChrDrop;
352
353 DEBUG_BUFFERS("swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
354 src2[0], srcStride2[0], src2[1], srcStride2[1],
355 src2[2], srcStride2[2], src2[3], srcStride2[3],
356 dst[0], dstStride[0], dst[1], dstStride[1],
357 dst[2], dstStride[2], dst[3], dstStride[3]);
358 DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
359 srcSliceY, srcSliceH, dstY, dstH);
360 DEBUG_BUFFERS("vLumFilterSize: %d vChrFilterSize: %d\n",
361 vLumFilterSize, vChrFilterSize);
362
363 if (dstStride[0]&15 || dstStride[1]&15 ||
364 dstStride[2]&15 || dstStride[3]&15) {
365 SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c;
366 if (flags & SWS_PRINT_INFO &&
367 !atomic_exchange_explicit(&ctx->stride_unaligned_warned, 1, memory_order_relaxed)) {
369 "Warning: dstStride is not aligned!\n"
370 " ->cannot do aligned memory accesses anymore\n");
371 }
372 }
373
374#if ARCH_X86
375 if ( (uintptr_t) dst[0]&15 || (uintptr_t) dst[1]&15 || (uintptr_t) dst[2]&15
376 || (uintptr_t)src2[0]&15 || (uintptr_t)src2[1]&15 || (uintptr_t)src2[2]&15
377 || srcStride2[0]&15 || srcStride2[1]&15 || srcStride2[2]&15 || srcStride2[3]&15
378 ) {
379 SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c;
381 if (flags & SWS_PRINT_INFO && HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) &&
382 !atomic_exchange_explicit(&ctx->stride_unaligned_warned,1, memory_order_relaxed)) {
383 av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speed loss\n");
384 }
385 }
386#endif
387
388 if (scale_dst) {
389 dstY = dstSliceY;
390 dstH = dstY + dstSliceH;
391 lastInLumBuf = -1;
392 lastInChrBuf = -1;
393 } else if (srcSliceY == 0) {
394 /* Note the user might start scaling the picture in the middle so this
395 * will not get executed. This is not really intended but works
396 * currently, so people might do it. */
397 dstY = 0;
398 lastInLumBuf = -1;
399 lastInChrBuf = -1;
400 }
401
402 if (!should_dither) {
403 c->chrDither8 = c->lumDither8 = sws_pb_64;
404 }
405 lastDstY = dstY;
406
407 ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
408 yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, c->use_mmx_vfilter);
409
410 ff_init_slice_from_src(src_slice, (uint8_t**)src2, srcStride2, c->opts.src_w,
411 srcSliceY, srcSliceH, chrSrcSliceY, chrSrcSliceH, 1);
412
413 ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->opts.dst_w,
414 dstY, dstSliceH, dstY >> c->chrDstVSubSample,
415 AV_CEIL_RSHIFT(dstSliceH, c->chrDstVSubSample), scale_dst);
416 if (srcSliceY == 0) {
417 hout_slice->plane[0].sliceY = lastInLumBuf + 1;
418 hout_slice->plane[1].sliceY = lastInChrBuf + 1;
419 hout_slice->plane[2].sliceY = lastInChrBuf + 1;
420 hout_slice->plane[3].sliceY = lastInLumBuf + 1;
421
422 hout_slice->plane[0].sliceH =
423 hout_slice->plane[1].sliceH =
424 hout_slice->plane[2].sliceH =
425 hout_slice->plane[3].sliceH = 0;
426 hout_slice->width = dstW;
427 }
428
429 for (; dstY < dstH; dstY++) {
430 const int chrDstY = dstY >> c->chrDstVSubSample;
431 int use_mmx_vfilter= c->use_mmx_vfilter;
432
433 // First line needed as input
434 const int firstLumSrcY = FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
435 const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), c->opts.dst_h - 1)]);
436 // First line needed as input
437 const int firstChrSrcY = FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
438
439 // Last line needed as input
440 int lastLumSrcY = FFMIN(c->opts.src_h, firstLumSrcY + vLumFilterSize) - 1;
441 int lastLumSrcY2 = FFMIN(c->opts.src_h, firstLumSrcY2 + vLumFilterSize) - 1;
442 int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
443 int enough_lines;
444
445 int i;
446 int posY, cPosY, firstPosY, lastPosY, firstCPosY, lastCPosY;
447
448 // handle holes (FAST_BILINEAR & weird filters)
449 if (firstLumSrcY > lastInLumBuf) {
450
451 hasLumHoles = lastInLumBuf != firstLumSrcY - 1;
452 if (hasLumHoles) {
453 hout_slice->plane[0].sliceY = firstLumSrcY;
454 hout_slice->plane[3].sliceY = firstLumSrcY;
455 hout_slice->plane[0].sliceH =
456 hout_slice->plane[3].sliceH = 0;
457 }
458
459 lastInLumBuf = firstLumSrcY - 1;
460 }
461 if (firstChrSrcY > lastInChrBuf) {
462
463 hasChrHoles = lastInChrBuf != firstChrSrcY - 1;
464 if (hasChrHoles) {
465 hout_slice->plane[1].sliceY = firstChrSrcY;
466 hout_slice->plane[2].sliceY = firstChrSrcY;
467 hout_slice->plane[1].sliceH =
468 hout_slice->plane[2].sliceH = 0;
469 }
470
471 lastInChrBuf = firstChrSrcY - 1;
472 }
473
474 DEBUG_BUFFERS("dstY: %d\n", dstY);
475 DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
476 firstLumSrcY, lastLumSrcY, lastInLumBuf);
477 DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
478 firstChrSrcY, lastChrSrcY, lastInChrBuf);
479
480 // Do we have enough lines in this slice to output the dstY line
481 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
482 lastChrSrcY < AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample);
483
484 if (!enough_lines) {
485 lastLumSrcY = srcSliceY + srcSliceH - 1;
486 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
487 DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
488 lastLumSrcY, lastChrSrcY);
489 }
490
491 av_assert0((lastLumSrcY - firstLumSrcY + 1) <= hout_slice->plane[0].available_lines);
492 av_assert0((lastChrSrcY - firstChrSrcY + 1) <= hout_slice->plane[1].available_lines);
493
494
495 posY = hout_slice->plane[0].sliceY + hout_slice->plane[0].sliceH;
496 if (posY <= lastLumSrcY && !hasLumHoles) {
497 firstPosY = FFMAX(firstLumSrcY, posY);
498 lastPosY = FFMIN(firstLumSrcY + hout_slice->plane[0].available_lines - 1, srcSliceY + srcSliceH - 1);
499 } else {
500 firstPosY = posY;
501 lastPosY = lastLumSrcY;
502 }
503
504 cPosY = hout_slice->plane[1].sliceY + hout_slice->plane[1].sliceH;
505 if (cPosY <= lastChrSrcY && !hasChrHoles) {
506 firstCPosY = FFMAX(firstChrSrcY, cPosY);
507 lastCPosY = FFMIN(firstChrSrcY + hout_slice->plane[1].available_lines - 1, AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample) - 1);
508 } else {
509 firstCPosY = cPosY;
510 lastCPosY = lastChrSrcY;
511 }
512
513 ff_rotate_slice(hout_slice, lastPosY, lastCPosY);
514
515 if (posY < lastLumSrcY + 1) {
516 for (i = lumStart; i < lumEnd; ++i)
517 desc[i].process(c, &desc[i], firstPosY, lastPosY - firstPosY + 1);
518 }
519
520 lastInLumBuf = lastLumSrcY;
521
522 if (cPosY < lastChrSrcY + 1) {
523 for (i = chrStart; i < chrEnd; ++i)
524 desc[i].process(c, &desc[i], firstCPosY, lastCPosY - firstCPosY + 1);
525 }
526
527 lastInChrBuf = lastChrSrcY;
528
529 if (!enough_lines)
530 break; // we can't output a dstY line so let's try with the next slice
531
532#if ARCH_X86 && HAVE_MMX
534 c->dstW_mmx = c->opts.dst_w;
535#endif
536 if (should_dither) {
537 c->chrDither8 = ff_dither_8x8_128[chrDstY & 7];
538 c->lumDither8 = ff_dither_8x8_128[dstY & 7];
539 }
540 if (dstY >= c->opts.dst_h - 2) {
541 /* hmm looks like we can't use MMX here without overwriting
542 * this array's tail */
543 ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX,
544 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
545 use_mmx_vfilter= 0;
546 ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
547 yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, use_mmx_vfilter);
548 }
549
550 for (i = vStart; i < vEnd; ++i)
551 desc[i].process(c, &desc[i], dstY, 1);
552 }
553 if (isPlanar(dstFormat) && isALPHA(dstFormat) && !needAlpha) {
554 int offset = lastDstY - dstSliceY;
555 int length = dstW;
556 int height = dstY - lastDstY;
557
558 if (is16BPS(dstFormat) || isNBPS(dstFormat)) {
559 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
560 fillPlane16(dst[3], dstStride[3], length, height, offset,
561 1, desc->comp[3].depth,
562 isBE(dstFormat));
563 } else if (is32BPS(dstFormat)) {
564 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
565 fillPlane32(dst[3], dstStride[3], length, height, offset,
566 1, desc->comp[3].depth,
567 isBE(dstFormat), desc->flags & AV_PIX_FMT_FLAG_FLOAT);
568 } else
569 fillPlane(dst[3], dstStride[3], length, height, offset, 255);
570 }
571
572 /* XYZ is scaled on its codes like 16-bit RGB */
573 if (c->srcXYZ && c->dstXYZ)
574 round_xyz12(dst[0], dstStride[0], dstW, dstY - lastDstY, lastDstY - dstSliceY,
575 isBE(dstFormat));
576
577#if HAVE_MMXEXT_INLINE
579 __asm__ volatile ("sfence" ::: "memory");
580#endif
581 emms_c();
582
583 /* store changed local vars back in the context */
584 c->dstY = dstY;
585 c->lastInLumBuf = lastInLumBuf;
586 c->lastInChrBuf = lastInChrBuf;
587
588 return dstY - lastDstY;
589}
590
591/*
592 * Solve for coeff and offset:
593 * dst = ((src << src_shift) * coeff + offset) >> (mult_shift + src_shift)
594 *
595 * If SwsInternal->dstBpc is > 14, coeff is uint16_t and offset is int32_t,
596 * otherwise (SwsInternal->dstBpc is <= 14) coeff is uint32_t and offset is
597 * int64_t.
598 */
599static void solve_range_convert(uint16_t src_min, uint16_t src_max,
600 uint16_t dst_min, uint16_t dst_max,
601 uint16_t src_ref, uint16_t dst_ref,
602 int src_bits, int src_shift, int mult_shift,
603 uint32_t *coeff, int64_t *offset)
604{
605 uint16_t src_range = src_max - src_min;
606 uint16_t dst_range = dst_max - dst_min;
607 int total_shift = mult_shift + src_shift;
608 *coeff = AV_CEIL_RSHIFT(((uint64_t) dst_range << total_shift) / src_range, src_shift);
609 *offset = ((int64_t) dst_ref << total_shift) -
610 ((int64_t) src_ref << src_shift) * *coeff +
611 (1U << (mult_shift - 1));
612}
613
615{
616 const int bit_depth = c->dstBpc ? FFMIN(c->dstBpc, 16) : 8;
617 const int src_bits = bit_depth <= 14 ? 15 : 19;
618 const int src_shift = src_bits - bit_depth;
619 const int mult_shift = bit_depth <= 14 ? 14 : 18;
620 const uint16_t mpeg_min = 16U << (bit_depth - 8);
621 const uint16_t mpeg_max_lum = 235U << (bit_depth - 8);
622 const uint16_t mpeg_max_chr = 240U << (bit_depth - 8);
623 const uint16_t chr_center = 128U << (bit_depth - 8);
624 const uint16_t jpeg_max = (1U << bit_depth) - 1;
625 uint16_t src_min, src_max_lum, src_max_chr;
626 uint16_t dst_min, dst_max_lum, dst_max_chr;
627 if (c->opts.src_range) {
628 src_min = 0;
629 src_max_lum = jpeg_max;
630 src_max_chr = jpeg_max;
631 dst_min = mpeg_min;
632 dst_max_lum = mpeg_max_lum;
633 dst_max_chr = mpeg_max_chr;
634 } else {
635 src_min = mpeg_min;
636 src_max_lum = mpeg_max_lum;
637 src_max_chr = mpeg_max_chr;
638 dst_min = 0;
639 dst_max_lum = jpeg_max;
640 dst_max_chr = jpeg_max;
641 }
642 solve_range_convert(src_min, src_max_lum, dst_min, dst_max_lum,
643 src_max_lum, dst_max_lum,
644 src_bits, src_shift, mult_shift,
645 &c->lumConvertRange_coeff, &c->lumConvertRange_offset);
646 solve_range_convert(src_min, src_max_chr, dst_min, dst_max_chr,
647 chr_center, chr_center,
648 src_bits, src_shift, mult_shift,
649 &c->chrConvertRange_coeff, &c->chrConvertRange_offset);
650}
651
653{
654 c->lumConvertRange = NULL;
655 c->chrConvertRange = NULL;
656 if (c->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format)) {
658 if (c->dstBpc <= 14) {
659 if (c->opts.src_range) {
660 c->lumConvertRange = lumRangeFromJpeg_c;
661 c->chrConvertRange = chrRangeFromJpeg_c;
662 } else {
663 c->lumConvertRange = lumRangeToJpeg_c;
664 c->chrConvertRange = chrRangeToJpeg_c;
665 }
666 } else {
667 if (c->opts.src_range) {
668 c->lumConvertRange = lumRangeFromJpeg16_c;
669 c->chrConvertRange = chrRangeFromJpeg16_c;
670 } else {
671 c->lumConvertRange = lumRangeToJpeg16_c;
672 c->chrConvertRange = chrRangeToJpeg16_c;
673 }
674 }
675
676#if ARCH_AARCH64
678#elif ARCH_LOONGARCH64
680#elif ARCH_RISCV
682#elif ARCH_X86
684#endif
685 }
686}
687
689{
690 enum AVPixelFormat srcFormat = c->opts.src_format;
691
693
694 ff_sws_init_output_funcs(c, &c->yuv2plane1, &c->yuv2planeX,
695 &c->yuv2nv12cX, &c->yuv2packed1,
696 &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
697
698 ff_sws_init_input_funcs(c, &c->lumToYV12, &c->alpToYV12, &c->chrToYV12,
699 &c->readLumPlanar, &c->readAlpPlanar, &c->readChrPlanar);
700
701 if (c->srcBpc == 8) {
702 if (c->dstBpc <= 14) {
703 c->hyScale = c->hcScale = hScale8To15_c;
704 if (c->opts.flags & SWS_FAST_BILINEAR) {
705 c->hyscale_fast = ff_hyscale_fast_c;
706 c->hcscale_fast = ff_hcscale_fast_c;
707 }
708 } else {
709 c->hyScale = c->hcScale = hScale8To19_c;
710 }
711 } else {
712 c->hyScale = c->hcScale = c->dstBpc > 14 ? hScale16To19_c
714 }
715
717
718 if (!(isGray(srcFormat) || isGray(c->opts.dst_format) ||
719 srcFormat == AV_PIX_FMT_MONOBLACK || srcFormat == AV_PIX_FMT_MONOWHITE))
720 c->needs_hcscale = 1;
721}
722
724{
726
727#if ARCH_PPC
729#elif ARCH_X86
731#elif ARCH_AARCH64
733#elif ARCH_ARM
735#elif ARCH_LOONGARCH64
737#elif ARCH_RISCV
739#endif
740}
741
742static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
743{
744 if (!isALPHA(format))
745 src[3] = NULL;
746 if (!isPlanar(format)) {
747 src[3] = src[2] = NULL;
748
749 if (!usePal(format))
750 src[1] = NULL;
751 }
752}
753
754static int check_image_pointers(const uint8_t * const data[4], enum AVPixelFormat pix_fmt,
755 const int linesizes[4], int h)
756{
758 int i;
759
761
762 for (i = 0; i < 4; i++) {
763 int plane = desc->comp[i].plane;
764 if (!data[plane] || !linesizes[plane] || FFABS((int64_t)linesizes[plane]) * h > INT_MAX)
765 return 0;
766 }
767
768 return 1;
769}
770
771static void xyz12Torgb48_c(const SwsInternal *c, uint8_t *dst, int dst_stride,
772 const uint8_t *src, int src_stride, int w, int h)
773{
774 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.src_format);
775
776 for (int yp = 0; yp < h; yp++) {
777 const uint16_t *src16 = (const uint16_t *) src;
778 uint16_t *dst16 = (uint16_t *) dst;
779
780 for (int xp = 0; xp < 3 * w; xp += 3) {
781 int x, y, z, r, g, b;
782
783 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
784 x = AV_RB16(src16 + xp + 0);
785 y = AV_RB16(src16 + xp + 1);
786 z = AV_RB16(src16 + xp + 2);
787 } else {
788 x = AV_RL16(src16 + xp + 0);
789 y = AV_RL16(src16 + xp + 1);
790 z = AV_RL16(src16 + xp + 2);
791 }
792
793 x = c->xyz2rgb.gamma.in[x >> 4];
794 y = c->xyz2rgb.gamma.in[y >> 4];
795 z = c->xyz2rgb.gamma.in[z >> 4];
796
797 // convert from XYZlinear to sRGBlinear
798 r = c->xyz2rgb.mat[0][0] * x +
799 c->xyz2rgb.mat[0][1] * y +
800 c->xyz2rgb.mat[0][2] * z >> 12;
801 g = c->xyz2rgb.mat[1][0] * x +
802 c->xyz2rgb.mat[1][1] * y +
803 c->xyz2rgb.mat[1][2] * z >> 12;
804 b = c->xyz2rgb.mat[2][0] * x +
805 c->xyz2rgb.mat[2][1] * y +
806 c->xyz2rgb.mat[2][2] * z >> 12;
807
808 // limit values to 16-bit depth
809 r = av_clip_uint16(r);
810 g = av_clip_uint16(g);
811 b = av_clip_uint16(b);
812
813 // convert from sRGBlinear to RGB and scale from 12bit to 16bit
814 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
815 AV_WB16(dst16 + xp + 0, c->xyz2rgb.gamma.out[r] << 4);
816 AV_WB16(dst16 + xp + 1, c->xyz2rgb.gamma.out[g] << 4);
817 AV_WB16(dst16 + xp + 2, c->xyz2rgb.gamma.out[b] << 4);
818 } else {
819 AV_WL16(dst16 + xp + 0, c->xyz2rgb.gamma.out[r] << 4);
820 AV_WL16(dst16 + xp + 1, c->xyz2rgb.gamma.out[g] << 4);
821 AV_WL16(dst16 + xp + 2, c->xyz2rgb.gamma.out[b] << 4);
822 }
823 }
824
825 src += src_stride;
826 dst += dst_stride;
827 }
828}
829
830static void rgb48Toxyz12_c(const SwsInternal *c, uint8_t *dst, int dst_stride,
831 const uint8_t *src, int src_stride, int w, int h)
832{
833 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->opts.dst_format);
834
835 for (int yp = 0; yp < h; yp++) {
836 uint16_t *src16 = (uint16_t *) src;
837 uint16_t *dst16 = (uint16_t *) dst;
838
839 for (int xp = 0; xp < 3 * w; xp += 3) {
840 int x, y, z, r, g, b;
841
842 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
843 r = AV_RB16(src16 + xp + 0);
844 g = AV_RB16(src16 + xp + 1);
845 b = AV_RB16(src16 + xp + 2);
846 } else {
847 r = AV_RL16(src16 + xp + 0);
848 g = AV_RL16(src16 + xp + 1);
849 b = AV_RL16(src16 + xp + 2);
850 }
851
852 r = c->rgb2xyz.gamma.in[r >> 4];
853 g = c->rgb2xyz.gamma.in[g >> 4];
854 b = c->rgb2xyz.gamma.in[b >> 4];
855
856 // convert from sRGBlinear to XYZlinear
857 x = c->rgb2xyz.mat[0][0] * r +
858 c->rgb2xyz.mat[0][1] * g +
859 c->rgb2xyz.mat[0][2] * b >> 12;
860 y = c->rgb2xyz.mat[1][0] * r +
861 c->rgb2xyz.mat[1][1] * g +
862 c->rgb2xyz.mat[1][2] * b >> 12;
863 z = c->rgb2xyz.mat[2][0] * r +
864 c->rgb2xyz.mat[2][1] * g +
865 c->rgb2xyz.mat[2][2] * b >> 12;
866
867 // limit values to 16-bit depth
868 x = av_clip_uint16(x);
869 y = av_clip_uint16(y);
870 z = av_clip_uint16(z);
871
872 // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
873 if (desc->flags & AV_PIX_FMT_FLAG_BE) {
874 AV_WB16(dst16 + xp + 0, c->rgb2xyz.gamma.out[x] << 4);
875 AV_WB16(dst16 + xp + 1, c->rgb2xyz.gamma.out[y] << 4);
876 AV_WB16(dst16 + xp + 2, c->rgb2xyz.gamma.out[z] << 4);
877 } else {
878 AV_WL16(dst16 + xp + 0, c->rgb2xyz.gamma.out[x] << 4);
879 AV_WL16(dst16 + xp + 1, c->rgb2xyz.gamma.out[y] << 4);
880 AV_WL16(dst16 + xp + 2, c->rgb2xyz.gamma.out[z] << 4);
881 }
882 }
883
884 src += src_stride;
885 dst += dst_stride;
886 }
887}
888
890{
891 c->xyz12Torgb48 = xyz12Torgb48_c;
892 c->rgb48Toxyz12 = rgb48Toxyz12_c;
893
894#if ARCH_AARCH64
896#endif
897}
898
899void ff_update_palette(SwsInternal *c, const uint32_t *pal)
900{
901 uint32_t *rgb2yuv = c->input_rgb2yuv_table;
902
903 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
904 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
905 int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
906
907 for (int i = 0; i < 256; i++) {
908 int r, g, b, y, u, v, a = 0xff;
909 if (c->opts.src_format == AV_PIX_FMT_PAL8) {
910 uint32_t p = pal[i];
911 a = (p >> 24) & 0xFF;
912 r = (p >> 16) & 0xFF;
913 g = (p >> 8) & 0xFF;
914 b = p & 0xFF;
915 } else if (c->opts.src_format == AV_PIX_FMT_RGB8) {
916 r = ( i >> 5 ) * 36;
917 g = ((i >> 2) & 7) * 36;
918 b = ( i & 3) * 85;
919 } else if (c->opts.src_format == AV_PIX_FMT_BGR8) {
920 b = ( i >> 6 ) * 85;
921 g = ((i >> 3) & 7) * 36;
922 r = ( i & 7) * 36;
923 } else if (c->opts.src_format == AV_PIX_FMT_RGB4_BYTE) {
924 r = ( i >> 3 ) * 255;
925 g = ((i >> 1) & 3) * 85;
926 b = ( i & 1) * 255;
927 } else if (c->opts.src_format == AV_PIX_FMT_GRAY8 || c->opts.src_format == AV_PIX_FMT_GRAY8A) {
928 r = g = b = i;
929 } else {
930 av_assert1(c->opts.src_format == AV_PIX_FMT_BGR4_BYTE);
931 b = ( i >> 3 ) * 255;
932 g = ((i >> 1) & 3) * 85;
933 r = ( i & 1) * 255;
934 }
935
936 y = av_clip_uint8((ry * r + gy * g + by * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
937 u = av_clip_uint8((ru * r + gu * g + bu * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
938 v = av_clip_uint8((rv * r + gv * g + bv * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
939
940 c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
941
942 switch (c->opts.dst_format) {
943 case AV_PIX_FMT_BGR32:
944#if !HAVE_BIGENDIAN
945 case AV_PIX_FMT_RGB24:
946#endif
947 c->pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
948 break;
950#if HAVE_BIGENDIAN
951 case AV_PIX_FMT_BGR24:
952#endif
953 c->pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
954 break;
956#if HAVE_BIGENDIAN
957 case AV_PIX_FMT_RGB24:
958#endif
959 c->pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
960 break;
961 case AV_PIX_FMT_GBRP:
962 case AV_PIX_FMT_GBRAP:
963#if HAVE_BIGENDIAN
964 c->pal_rgb[i]= a + (r<<8) + (b<<16) + ((unsigned)g<<24);
965#else
966 c->pal_rgb[i]= g + (b<<8) + (r<<16) + ((unsigned)a<<24);
967#endif
968 break;
969 case AV_PIX_FMT_RGB32:
970#if !HAVE_BIGENDIAN
971 case AV_PIX_FMT_BGR24:
972#endif
973 default:
974 c->pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
975 }
976 }
977}
978
979static int scale_internal(SwsContext *sws,
980 const uint8_t * const srcSlice[], const int srcStride[],
981 int srcSliceY, int srcSliceH,
982 uint8_t *const dstSlice[], const int dstStride[],
983 int dstSliceY, int dstSliceH);
984
986 const uint8_t * const srcSlice[], const int srcStride[],
987 int srcSliceY, int srcSliceH,
988 uint8_t * const dstSlice[], const int dstStride[],
989 int dstSliceY, int dstSliceH)
990{
991 int ret = scale_internal(c->cascaded_context[0],
992 srcSlice, srcStride, srcSliceY, srcSliceH,
993 c->cascaded_tmp[0], c->cascaded_tmpStride[0], 0, c->opts.src_h);
994
995 if (ret < 0)
996 return ret;
997
998 if (c->cascaded_context[2])
999 ret = scale_internal(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp[0],
1000 c->cascaded_tmpStride[0], srcSliceY, srcSliceH,
1001 c->cascaded_tmp[1], c->cascaded_tmpStride[1], 0, c->opts.dst_h);
1002 else
1003 ret = scale_internal(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp[0],
1004 c->cascaded_tmpStride[0], srcSliceY, srcSliceH,
1005 dstSlice, dstStride, dstSliceY, dstSliceH);
1006
1007 if (ret < 0)
1008 return ret;
1009
1010 if (c->cascaded_context[2]) {
1011 const int dstY1 = sws_internal(c->cascaded_context[1])->dstY;
1012 ret = scale_internal(c->cascaded_context[2], (const uint8_t * const *)c->cascaded_tmp[1],
1013 c->cascaded_tmpStride[1], dstY1 - ret, dstY1,
1014 dstSlice, dstStride, dstSliceY, dstSliceH);
1015 }
1016 return ret;
1017}
1018
1020 const uint8_t * const srcSlice[], const int srcStride[],
1021 int srcSliceY, int srcSliceH,
1022 uint8_t * const dstSlice[], const int dstStride[],
1023 int dstSliceY, int dstSliceH)
1024{
1025 const int dstH0 = c->cascaded_context[0]->dst_h;
1026 int ret = scale_internal(c->cascaded_context[0],
1027 srcSlice, srcStride, srcSliceY, srcSliceH,
1028 c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1029 0, dstH0);
1030 if (ret < 0)
1031 return ret;
1032
1033 /* The first stage assembles the full intermediate image from the input,
1034 * one slice at a time (it is itself a regular slice-capable context). The
1035 * second stage scales that whole intermediate to the output in one step,
1036 * so it can only run once the entire source has been consumed. The first
1037 * stage resets its slice direction to 0 at end of frame; until then the
1038 * intermediate is incomplete and this call produces no output lines. */
1039 if (sws_internal(c->cascaded_context[0])->sliceDir != 0)
1040 return 0;
1041
1042 ret = scale_internal(c->cascaded_context[1],
1043 (const uint8_t * const * )c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1044 0, dstH0, dstSlice, dstStride, dstSliceY, dstSliceH);
1045 return ret;
1046}
1047
1049 const uint8_t * const srcSlice[], const int srcStride[],
1050 int srcSliceY, int srcSliceH,
1051 uint8_t *const dstSlice[], const int dstStride[],
1052 int dstSliceY, int dstSliceH)
1053{
1054 SwsInternal *c = sws_internal(sws);
1055 const int scale_dst = dstSliceY > 0 || dstSliceH < sws->dst_h;
1056 const int frame_start = scale_dst || !c->sliceDir;
1057 int i, ret;
1058 const uint8_t *src2[4];
1059 uint8_t *dst2[4];
1060 int macro_height_src = isBayer(sws->src_format) ? 2 : (1 << c->chrSrcVSubSample);
1061 int macro_height_dst = isBayer(sws->dst_format) ? 2 : (1 << c->chrDstVSubSample);
1062 // copy strides, so they can safely be modified
1063 int srcStride2[4];
1064 int dstStride2[4];
1065 int srcSliceY_internal = srcSliceY;
1066
1067 if (!srcStride || !dstStride || !dstSlice || !srcSlice) {
1068 av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n");
1069 return AVERROR(EINVAL);
1070 }
1071
1072 if ((srcSliceY & (macro_height_src - 1)) ||
1073 ((srcSliceH & (macro_height_src - 1)) && srcSliceY + srcSliceH != sws->src_h) ||
1074 srcSliceY + srcSliceH > sws->src_h ||
1075 srcSliceY < 0 ||
1076 srcSliceH < 0 ||
1077 (isBayer(sws->src_format) && srcSliceH <= 1)) {
1078 av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH);
1079 return AVERROR(EINVAL);
1080 }
1081
1082 if ((dstSliceY & (macro_height_dst - 1)) ||
1083 ((dstSliceH & (macro_height_dst - 1)) && dstSliceY + dstSliceH != sws->dst_h) ||
1084 dstSliceY + dstSliceH > sws->dst_h) {
1085 av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", dstSliceY, dstSliceH);
1086 return AVERROR(EINVAL);
1087 }
1088
1089 if (!check_image_pointers(srcSlice, sws->src_format, srcStride, sws->src_h)) {
1090 av_log(c, AV_LOG_ERROR, "bad src image pointers or strides\n");
1091 return AVERROR(EINVAL);
1092 }
1093 if (!check_image_pointers((const uint8_t* const*)dstSlice, sws->dst_format, dstStride, sws->dst_h)) {
1094 av_log(c, AV_LOG_ERROR, "bad dst image pointers or strides\n");
1095 return AVERROR(EINVAL);
1096 }
1097
1098 // do not mess up sliceDir if we have a "trailing" 0-size slice
1099 if (srcSliceH == 0)
1100 return 0;
1101
1102 if (sws->gamma_flag && c->cascaded_context[0])
1103 return scale_gamma(c, srcSlice, srcStride, srcSliceY, srcSliceH,
1104 dstSlice, dstStride, dstSliceY, dstSliceH);
1105
1106 if (c->cascaded_context[0])
1107 return scale_cascaded(c, srcSlice, srcStride, srcSliceY, srcSliceH,
1108 dstSlice, dstStride, dstSliceY, dstSliceH);
1109
1110 if (!srcSliceY && (sws->flags & SWS_BITEXACT) && sws->dither == SWS_DITHER_ED && c->dither_error[0])
1111 for (i = 0; i < 4; i++)
1112 memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (sws->dst_w+2));
1113
1114 if (usePal(sws->src_format))
1115 ff_update_palette(c, (const uint32_t *)srcSlice[1]);
1116
1117 memcpy(src2, srcSlice, sizeof(src2));
1118 memcpy(dst2, dstSlice, sizeof(dst2));
1119 memcpy(srcStride2, srcStride, sizeof(srcStride2));
1120 memcpy(dstStride2, dstStride, sizeof(dstStride2));
1121
1122 if (frame_start && !scale_dst) {
1123 if (srcSliceY != 0 && srcSliceY + srcSliceH != sws->src_h) {
1124 av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
1125 return AVERROR(EINVAL);
1126 }
1127
1128 c->sliceDir = (srcSliceY == 0) ? 1 : -1;
1129 } else if (scale_dst)
1130 c->sliceDir = 1;
1131
1132 if (c->src0Alpha && !c->dst0Alpha && isALPHA(sws->dst_format)) {
1133 uint8_t *base;
1134 int x,y;
1135
1136 av_fast_malloc(&c->rgb0_scratch, &c->rgb0_scratch_allocated,
1137 FFABS((int64_t)srcStride[0]) * srcSliceH + 32);
1138 if (!c->rgb0_scratch)
1139 return AVERROR(ENOMEM);
1140
1141 base = srcStride[0] < 0 ? c->rgb0_scratch - srcStride[0] * (srcSliceH-1) :
1142 c->rgb0_scratch;
1143 for (y=0; y<srcSliceH; y++){
1144 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*sws->src_w);
1145 for (x=c->src0Alpha-1; x<4*sws->src_w; x+=4) {
1146 base[ srcStride[0]*y + x] = 0xFF;
1147 }
1148 }
1149 src2[0] = base;
1150 }
1151
1152 if (c->srcXYZ && !c->dstXYZ) {
1153 uint8_t *base;
1154
1155 av_fast_malloc(&c->xyz_scratch, &c->xyz_scratch_allocated,
1156 FFABS((int64_t)srcStride[0]) * srcSliceH + 32);
1157 if (!c->xyz_scratch)
1158 return AVERROR(ENOMEM);
1159
1160 base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) :
1161 c->xyz_scratch;
1162
1163 c->xyz12Torgb48(c, base, srcStride[0], src2[0], srcStride[0], sws->src_w, srcSliceH);
1164 src2[0] = base;
1165 }
1166
1167 if (c->sliceDir != 1) {
1168 // slices go from bottom to top => we flip the image internally
1169 for (i=0; i<4; i++) {
1170 srcStride2[i] *= -1;
1171 dstStride2[i] *= -1;
1172 }
1173
1174 src2[0] += (srcSliceH - 1) * srcStride[0];
1175 if (!usePal(sws->src_format))
1176 src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1];
1177 src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2];
1178 src2[3] += (srcSliceH - 1) * srcStride[3];
1179 dst2[0] += ( sws->dst_h - 1) * dstStride[0];
1180 dst2[1] += ((sws->dst_h >> c->chrDstVSubSample) - 1) * dstStride[1];
1181 dst2[2] += ((sws->dst_h >> c->chrDstVSubSample) - 1) * dstStride[2];
1182 dst2[3] += ( sws->dst_h - 1) * dstStride[3];
1183
1184 srcSliceY_internal = sws->src_h-srcSliceY-srcSliceH;
1185 }
1186 reset_ptr(src2, sws->src_format);
1187 reset_ptr((void*)dst2, sws->dst_format);
1188
1189 if (c->convert_unscaled) {
1190 int offset = srcSliceY_internal;
1191 int slice_h = srcSliceH;
1192
1193 // for dst slice scaling, offset the pointers to match the unscaled API
1194 if (scale_dst) {
1195 av_assert0(offset == 0);
1196 for (i = 0; i < 4 && src2[i]; i++) {
1197 if (!src2[i] || (i > 0 && usePal(sws->src_format)))
1198 break;
1199 src2[i] += (dstSliceY >> ((i == 1 || i == 2) ? c->chrSrcVSubSample : 0)) * srcStride2[i];
1200 }
1201
1202 for (i = 0; i < 4 && dst2[i]; i++) {
1203 if (!dst2[i] || (i > 0 && usePal(sws->dst_format)))
1204 break;
1205 dst2[i] -= (dstSliceY >> ((i == 1 || i == 2) ? c->chrDstVSubSample : 0)) * dstStride2[i];
1206 }
1207 offset = dstSliceY;
1208 slice_h = dstSliceH;
1209 }
1210
1211 ret = c->convert_unscaled(c, src2, srcStride2, offset, slice_h,
1212 dst2, dstStride2);
1213 if (scale_dst)
1214 dst2[0] += dstSliceY * dstStride2[0];
1215 } else {
1216 ret = ff_swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH,
1217 dst2, dstStride2, dstSliceY, dstSliceH);
1218 }
1219
1220 if (c->dstXYZ && !c->srcXYZ) {
1221 uint8_t *dst;
1222
1223 if (scale_dst) {
1224 dst = dst2[0];
1225 } else {
1226 int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH;
1227
1228 av_assert0(dstY >= ret);
1229 av_assert0(ret >= 0);
1230 av_assert0(sws->dst_h >= dstY);
1231 dst = dst2[0] + (dstY - ret) * dstStride2[0];
1232 }
1233
1234 /* replace on the same data */
1235 c->rgb48Toxyz12(c, dst, dstStride2[0], dst, dstStride2[0], sws->dst_w, ret);
1236 }
1237
1238 /* reset slice direction at end of frame */
1239 if ((srcSliceY_internal + srcSliceH == sws->src_h) || scale_dst)
1240 c->sliceDir = 0;
1241
1242 return ret;
1243}
1244
1246{
1247 SwsInternal *c = sws_internal(sws);
1248 if (!c->is_legacy_init)
1249 return;
1250 av_frame_unref(c->frame_src);
1251 av_frame_unref(c->frame_dst);
1252 c->src_ranges.nb_ranges = 0;
1253}
1254
1255static int ptr_in_buf(const uint8_t *ptr, const AVBufferRef *buf)
1256{
1257 uintptr_t ptr_val = (uintptr_t) ptr;
1258 uintptr_t buf_start = (uintptr_t) buf->data;
1259 return ptr_val >= buf_start && ptr_val < buf_start + buf->size;
1260}
1261
1262/* Similar to av_frame_ref() but only references planes in the given map */
1263static int frame_ref(AVFrame *dst, const AVFrame *src, const int plane_copy[4])
1264{
1265 int copied[AV_NUM_DATA_POINTERS] = {0};
1266 int nb_copied = 0;
1267
1268 for (int i = 0; i < 4; i++) {
1269 const int idx = plane_copy[i];
1270 if (idx < 0)
1271 continue;
1272 /* Find corresponding source buffer */
1273 uint8_t *src_data = src->data[idx];
1274 if (!src_data)
1275 return AVERROR(EINVAL);
1276 for (int j = 0; j < FF_ARRAY_ELEMS(src->buf); j++) {
1277 AVBufferRef *buf = src->buf[j];
1278 if (!buf)
1279 break;
1280 if (!ptr_in_buf(src_data, buf))
1281 continue;
1282 if (!copied[j]) {
1284 if (!ref)
1285 return AVERROR(ENOMEM);
1286 dst->buf[nb_copied++] = ref;
1287 copied[j] = 1;
1288 }
1289 dst->data[i] = src_data;
1290 dst->linesize[i] = src->linesize[idx];
1291 break;
1292 }
1293 }
1294
1295 return 0;
1296}
1297
1298/* Returns the number of buffers allocated */
1300{
1301 SwsInternal *c = sws_internal(sws);
1302 FFFramePool *pool = &c->frame_pool;
1303 av_assert0(!frame->hw_frames_ctx);
1304
1305 /* Find first free buffer slot */
1306 int buf_start = 0;
1307 while (frame->buf[buf_start])
1308 buf_start++;
1309 int nb_bufs = 0;
1310
1311 for (int i = 0; i < 4 && pool->pools[i]; i++) {
1312 if (frame->data[i])
1313 continue; /* already ref'd by frame_ref */
1314
1315 const int idx = buf_start + nb_bufs++;
1316 av_assert1(idx < FF_ARRAY_ELEMS(frame->buf));
1317 frame->buf[idx] = av_buffer_pool_get(pool->pools[i]);
1318 if (!frame->buf[idx]) {
1320 return AVERROR(ENOMEM);
1321 }
1322 frame->data[i] = frame->buf[idx]->data;
1323 frame->linesize[i] = pool->linesize[i];
1324 }
1325
1326 return nb_bufs;
1327}
1328
1330{
1331 SwsInternal *c = sws_internal(sws);
1332 int ret, allocated = 0;
1333 if (!c->is_legacy_init)
1334 return AVERROR(EINVAL);
1335
1336 ret = av_frame_ref(c->frame_src, src);
1337 if (ret < 0)
1338 return ret;
1339
1340 if (!dst->buf[0]) {
1341 dst->width = sws->dst_w;
1342 dst->height = sws->dst_h;
1343 dst->format = sws->dst_format;
1344
1346 if (ret < 0)
1347 return ret;
1348 allocated = 1;
1349 }
1350
1351 ret = av_frame_ref(c->frame_dst, dst);
1352 if (ret < 0) {
1353 if (allocated)
1355
1356 return ret;
1357 }
1358
1359 return 0;
1360}
1361
1363 unsigned int slice_height)
1364{
1365 SwsInternal *c = sws_internal(sws);
1366 int ret;
1367 if (!c->is_legacy_init)
1368 return AVERROR(EINVAL);
1369
1370 ret = ff_range_add(&c->src_ranges, slice_start, slice_height);
1371 if (ret < 0)
1372 return ret;
1373
1374 return 0;
1375}
1376
1378{
1379 SwsInternal *c = sws_internal(sws);
1380 if (c->slice_ctx)
1381 return sws_internal(c->slice_ctx[0])->dst_slice_align;
1382
1383 return c->dst_slice_align;
1384}
1385
1387 unsigned int slice_height)
1388{
1389 SwsInternal *c = sws_internal(sws);
1390 unsigned int align = sws_receive_slice_alignment(sws);
1391 uint8_t *dst[4];
1392 if (!c->is_legacy_init)
1393 return AVERROR(EINVAL);
1394
1395 /* wait until complete input has been received */
1396 if (!(c->src_ranges.nb_ranges == 1 &&
1397 c->src_ranges.ranges[0].start == 0 &&
1398 c->src_ranges.ranges[0].len == sws->src_h))
1399 return AVERROR(EAGAIN);
1400
1401 if ((slice_start > 0 || slice_height < sws->dst_h) &&
1402 (slice_start % align || slice_height % align)) {
1404 "Incorrectly aligned output: %u/%u not multiples of %u\n",
1405 slice_start, slice_height, align);
1406 return AVERROR(EINVAL);
1407 }
1408
1409 if (c->slicethread) {
1410 int nb_jobs = c->nb_slice_ctx;
1411 if (c->slice_ctx[0]->dither == SWS_DITHER_ED)
1412 nb_jobs = 1;
1413
1414 c->dst_slice_start = slice_start;
1415 c->dst_slice_height = slice_height;
1416
1417 return avpriv_slicethread_execute2(c->slicethread, nb_jobs, 0);
1418 }
1419
1420 for (int i = 0; i < FF_ARRAY_ELEMS(dst); i++) {
1421 ptrdiff_t offset = c->frame_dst->linesize[i] * (ptrdiff_t)(slice_start >> c->chrDstVSubSample);
1422 dst[i] = FF_PTR_ADD(c->frame_dst->data[i], offset);
1423 }
1424
1425 return scale_internal(sws, (const uint8_t * const *)c->frame_src->data,
1426 c->frame_src->linesize, 0, sws->src_h,
1427 dst, c->frame_dst->linesize, slice_start, slice_height);
1428}
1429
1431{
1432 for (int i = 0; i < FF_ARRAY_ELEMS(frame->linesize); i++)
1433 if (FFABS((int64_t)frame->linesize[i]) * frame->height > INT_MAX)
1434 return 0;
1435 return 1;
1436}
1437
1439{
1440 int ret, allocated = 0;
1441 SwsInternal *c = sws_internal(sws);
1442 if (!src || !dst)
1443 return AVERROR(EINVAL);
1444
1445 if (c->is_legacy_init) {
1446 /* Context has been initialized with explicit values, fall back to
1447 * legacy API behavior. */
1448 ret = sws_frame_start(sws, dst, src);
1449 if (ret < 0)
1450 return ret;
1451
1452 ret = sws_send_slice(sws, 0, src->height);
1453 if (ret >= 0)
1454 ret = sws_receive_slice(sws, 0, dst->height);
1455
1456 sws_frame_end(sws);
1457
1458 return ret;
1459 }
1460
1461 ret = sws_frame_setup(sws, dst, src);
1462 if (ret < 0)
1463 return ret;
1464
1465 if (!src->data[0])
1466 return 0;
1467
1468 if (!frame_strides_fit(src) || (dst->data[0] && !frame_strides_fit(dst))) {
1469 av_log(sws, AV_LOG_ERROR, "Frame planes larger than INT_MAX bytes are not supported\n");
1470 return AVERROR(EINVAL);
1471 }
1472
1473 const SwsGraph *top = c->graph[FIELD_TOP];
1474 const SwsGraph *bot = c->graph[FIELD_BOTTOM];
1475 if (dst->data[0]) /* user-provided buffers */
1476 goto process_frame;
1477
1478 /* Sanity */
1479 memset(dst->buf, 0, sizeof(dst->buf));
1480 memset(dst->data, 0, sizeof(dst->data));
1481 memset(dst->linesize, 0, sizeof(dst->linesize));
1482 dst->extended_data = dst->data;
1483
1484 if (src->buf[0]) {
1485 /* Determine end-to-end plane copy map */
1486 int plane_copy[FF_ARRAY_ELEMS(top->plane_copy)];
1487 memcpy(plane_copy, top->plane_copy, sizeof(plane_copy));
1488 for (int i = 0; bot && i < FF_ARRAY_ELEMS(plane_copy); i++) {
1489 if (bot->plane_copy[i] != plane_copy[i])
1490 plane_copy[i] = -1;
1491 }
1492
1493 ret = frame_ref(dst, src, plane_copy);
1494 if (ret < 0)
1495 return ret;
1496 }
1497
1498 /* Allocate any missing buffers not yet ref'd */
1499 ret = frame_alloc_buffers(sws, dst);
1500 if (ret < 0)
1501 return ret;
1502 else if (!ret)
1503 return 0; /* no buffers allocated, no-op (all ref'd) */
1504 else
1505 allocated = 1;
1506
1508 for (int field = 0; field < (bot ? 2 : 1); field++) {
1509 ret = ff_sws_graph_run(c->graph[field], dst, src);
1510 if (ret < 0) {
1511 if (allocated)
1513 return ret;
1514 }
1515 }
1516
1517 return 0;
1518}
1519
1521{
1522#define VALIDATE(field, min, max) \
1523 if (ctx->field < min || ctx->field > max) { \
1524 av_log(ctx, AV_LOG_ERROR, "'%s' (%d) out of range [%d, %d]\n", \
1525 #field, (int) ctx->field, min, max); \
1526 return AVERROR(EINVAL); \
1527 }
1528
1529 VALIDATE(threads, 0, SWS_MAX_THREADS);
1531 VALIDATE(alpha_blend, 0, SWS_ALPHA_BLEND_NB - 1)
1532 VALIDATE(intent, 0, SWS_INTENT_NB - 1);
1533 VALIDATE(scaler, 0, SWS_SCALE_NB - 1)
1534 VALIDATE(scaler_sub, 0, SWS_SCALE_NB - 1)
1535 return 0;
1536}
1537
1538static int bottom_field_fits(const AVFrame *frame, const SwsFormat *field)
1539{
1540 const int vsub = field->desc->log2_chroma_h;
1541 return 2 * AV_CEIL_RSHIFT(field->height, vsub) <= AV_CEIL_RSHIFT(frame->height, vsub);
1542}
1543
1545{
1547 const char *err_msg;
1548 int ret;
1549
1550 if (!src || !dst)
1551 return AVERROR(EINVAL);
1552 if ((ret = validate_params(ctx)) < 0)
1553 return ret;
1554
1555 const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src->format);
1556 const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst->format);
1557 av_assert0(src_desc);
1558 av_assert0(dst_desc);
1559
1560 const int src_is_hwaccel = !!(src_desc->flags & AV_PIX_FMT_FLAG_HWACCEL);
1561 const int dst_is_hwaccel = !!(dst_desc->flags & AV_PIX_FMT_FLAG_HWACCEL);
1562 if (src_is_hwaccel && !src->hw_frames_ctx)
1563 return AVERROR(EINVAL);
1564 if (dst_is_hwaccel && !dst->hw_frames_ctx)
1565 return AVERROR(EINVAL);
1566
1567 /* For now, if a single frame has a context, then both need a context */
1568 if (src_is_hwaccel ^ dst_is_hwaccel) {
1569 return AVERROR(ENOTSUP);
1570 } else if (src_is_hwaccel) {
1571 /* Both hardware frames must already be allocated */
1572 if (!src->data[0] || !dst->data[0])
1573 return AVERROR(EINVAL);
1574
1575 AVHWFramesContext *src_hwfc, *dst_hwfc;
1576 src_hwfc = (AVHWFramesContext *)src->hw_frames_ctx->data;
1577 dst_hwfc = (AVHWFramesContext *)dst->hw_frames_ctx->data;
1578
1579 /* Both frames must live on the same device */
1580 if (src_hwfc->device_ref->data != dst_hwfc->device_ref->data)
1581 return AVERROR(EINVAL);
1582
1583 /* Only Vulkan devices are supported */
1584 AVHWDeviceContext *dev_ctx;
1585 dev_ctx = (AVHWDeviceContext *)src_hwfc->device_ref->data;
1586 if (dev_ctx->type != AV_HWDEVICE_TYPE_VULKAN)
1587 return AVERROR(ENOTSUP);
1588
1589#if CONFIG_SWSCALE_VULKAN
1590 ret = ff_sws_vk_init(ctx, src_hwfc->device_ref);
1591 if (ret < 0)
1592 return ret;
1593#endif
1594 }
1595
1596 int dst_width = dst->width;
1598 for (int field = 0; field < 2; field++) {
1599 SwsFormat src_fmt = ff_fmt_from_frame(src, field);
1600 SwsFormat dst_fmt = ff_fmt_from_frame(dst, field);
1601 int src_ok, dst_ok;
1602
1603 if ((src->flags ^ dst->flags) & AV_FRAME_FLAG_INTERLACED) {
1604 err_msg = "Cannot convert interlaced to progressive frames or vice versa.\n";
1605 ret = AVERROR(EINVAL);
1606 goto fail;
1607 }
1608
1609 if (src_fmt.height <= 0 || dst_fmt.height <= 0) {
1610 err_msg = "Interlaced frames need at least two lines";
1611 ret = AVERROR(EINVAL);
1612 goto fail;
1613 }
1614
1615 if (field == FIELD_BOTTOM &&
1616 (!bottom_field_fits(src, &src_fmt) || !bottom_field_fits(dst, &dst_fmt))) {
1617 err_msg = "The bottom field has fewer chroma rows than its height requires";
1618 ret = AVERROR(EINVAL);
1619 goto fail;
1620 }
1621
1622 src_ok = ff_test_fmt(backends, &src_fmt, 0);
1623 dst_ok = ff_test_fmt(backends, &dst_fmt, 1);
1624 if ((!src_ok || !dst_ok) && !ff_fmt_equal(&src_fmt, &dst_fmt)) {
1625 err_msg = src_ok ? "Unsupported output" : "Unsupported input";
1626 ret = AVERROR(ENOTSUP);
1627 goto fail;
1628 }
1629
1630 if (!s->graph[field]) {
1631 s->graph[field] = ff_sws_graph_alloc();
1632 if (!s->graph[field]) {
1633 err_msg = "Failed allocating scaling graph";
1634 ret = AVERROR(ENOMEM);
1635 goto fail;
1636 }
1637 }
1638
1639 ret = ff_sws_graph_reinit(s->graph[field], ctx, &dst_fmt, &src_fmt);
1640 if (ret < 0) {
1641 err_msg = "Failed initializing scaling graph";
1642 goto fail;
1643 }
1644
1645 const SwsGraph *graph = s->graph[field];
1646 if (graph->incomplete && ctx->flags & SWS_STRICT) {
1647 err_msg = "Incomplete scaling graph";
1648 ret = AVERROR(EINVAL);
1649 goto fail;
1650 }
1651
1652 if (!graph->noop) {
1653 av_assert0(graph->num_passes);
1654 const SwsPass *last_pass = graph->passes[graph->num_passes - 1];
1655 const int aligned_w = ff_sws_pass_aligned_width(last_pass, dst->width);
1656 dst_width = FFMAX(dst_width, aligned_w);
1657 }
1658
1659 if (!src_fmt.interlaced) {
1661 break;
1662 }
1663
1664 continue;
1665
1666 fail:
1667 av_log(ctx, AV_LOG_ERROR, "%s (%s): fmt:%s csp:%s prim:%s trc:%s ->"
1668 " fmt:%s csp:%s prim:%s trc:%s\n",
1669 err_msg, av_err2str(ret),
1674
1675 for (int i = 0; i < FF_ARRAY_ELEMS(s->graph); i++)
1676 ff_sws_graph_free(&s->graph[i]);
1677
1678 return ret;
1679 }
1680
1681 if (!dst->hw_frames_ctx) {
1682 ret = ff_frame_pool_video_reinit(&s->frame_pool, dst_width, dst->height,
1683 dst->format, av_cpu_max_align());
1684 if (ret < 0)
1685 return ret;
1686 }
1687
1688 return 0;
1689}
1690
1691/**
1692 * swscale wrapper, so we don't need to export the SwsContext.
1693 * Assumes planar YUV to be in YUV order instead of YVU.
1694 */
1696 const uint8_t * const srcSlice[],
1697 const int srcStride[], int srcSliceY,
1698 int srcSliceH, uint8_t *const dst[],
1699 const int dstStride[])
1700{
1701 SwsInternal *c = sws_internal(sws);
1702 if (!c->is_legacy_init)
1703 return AVERROR(EINVAL);
1704
1705 if (c->nb_slice_ctx) {
1706 sws = c->slice_ctx[0];
1707 c = sws_internal(sws);
1708 }
1709
1710 return scale_internal(sws, srcSlice, srcStride, srcSliceY, srcSliceH,
1711 dst, dstStride, 0, sws->dst_h);
1712}
1713
1714int ff_sws_slice_worker(void *priv, int jobnr, int threadnr,
1715 int nb_jobs, int nb_threads)
1716{
1717 SwsInternal *parent = priv;
1718 SwsContext *sws = parent->slice_ctx[threadnr];
1719 SwsInternal *c = sws_internal(sws);
1720
1721 const int slice_height = FFALIGN(FFMAX((parent->dst_slice_height + nb_jobs - 1) / nb_jobs, 1),
1722 c->dst_slice_align);
1723 const int slice_start = jobnr * slice_height;
1724 const int slice_end = FFMIN((jobnr + 1) * slice_height, parent->dst_slice_height);
1725 int err = 0;
1726
1727 if (slice_end > slice_start) {
1728 uint8_t *dst[4] = { NULL };
1729
1730 for (int i = 0; i < FF_ARRAY_ELEMS(dst) && parent->frame_dst->data[i]; i++) {
1731 const int vshift = (i == 1 || i == 2) ? c->chrDstVSubSample : 0;
1732 const ptrdiff_t offset = parent->frame_dst->linesize[i] *
1733 (ptrdiff_t)((slice_start + parent->dst_slice_start) >> vshift);
1734
1735 dst[i] = parent->frame_dst->data[i] + offset;
1736 }
1737
1738 err = scale_internal(sws, (const uint8_t * const *)parent->frame_src->data,
1739 parent->frame_src->linesize, 0, sws->src_h,
1740 dst, parent->frame_dst->linesize,
1742 }
1743
1744 if (err < 0)
1745 return err;
1746
1747 return 0; /* ff_slicethread_execute() aborts on non-zero */
1748}
uint8_t * _dst
Definition dsp.h:66
uint8_t ptrdiff_t const uint8_t * _src
Definition dsp.h:66
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
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:445
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 emms_c()
Definition emms.h:88
static const uint8_t bits[8]
Definition fastaudio.c:100
int ret
Definition ffplay.c:391
static av_always_inline int process_frame(AVTextFormatContext *tfc, InputFile *ifile, AVFrame *frame, const AVPacket *pkt, int *packet_new)
Definition ffprobe.c:1713
@ 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:129
#define AV_NUM_DATA_POINTERS
Definition frame.h:480
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:1034
SwsGraph * ff_sws_graph_alloc(void)
Allocate an empty SwsGraph.
Definition graph.c:874
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:981
void ff_sws_graph_free(SwsGraph **pgraph)
Uninitialize any state associate with this filter graph and free it.
Definition graph.c:950
#define fail
Definition test.h:479
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition buffer.c:396
#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:702
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition frame.c:209
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:281
#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:661
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:1386
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:1438
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:1362
unsigned int sws_receive_slice_alignment(const SwsContext *sws)
Get the alignment required for slices.
Definition swscale.c:1377
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:1695
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:1544
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:1245
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:1329
@ 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
#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:288
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
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 FF_PTR_ADD(ptr, off)
Definition internal.h:83
#define attribute_align_arg
Definition internal.h:51
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:692
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:1711
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:3302
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3884
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:3404
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition pixdesc.c:3851
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition pixdesc.c:3818
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition pixdesc.h:116
#define AV_PIX_FMT_BGR32
Definition pixfmt.h:522
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:521
#define AV_PIX_FMT_BGR32_1
Definition pixfmt.h:523
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:520
av_cold void ff_sws_init_swscale_ppc(SwsInternal *c)
Definition swscale.c:25
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.
@ memory_order_relaxed
Definition stdatomic.h:29
#define atomic_exchange_explicit(object, desired, order)
Definition stdatomic.h:259
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:479
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
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:524
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
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
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:65
enum AVColorTransferCharacteristic trc
Definition format.h:66
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:91
enum AVPixelFormat format
Definition format.h:85
int interlaced
Definition format.h:83
const AVPixFmtDescriptor * desc
Definition format.h:90
enum AVColorSpace csp
Definition format.h:88
int height
Definition format.h:82
Filter graph, which represents a 'baked' pixel format conversion.
Definition graph.h:133
bool noop
Definition graph.h:138
SwsPass ** passes
Sorted sequence of filter passes to apply.
Definition graph.h:154
bool incomplete
Definition graph.h:137
int num_passes
Definition graph.h:155
int plane_copy[4]
Map of planes which directly copied from the input.
Definition graph.h:151
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:771
static int validate_params(SwsContext *ctx)
Definition swscale.c:1520
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:688
void ff_sws_init_scale(SwsInternal *c)
Definition swscale.c:723
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:1714
static int check_image_pointers(const uint8_t *const data[4], enum AVPixelFormat pix_fmt, const int linesizes[4], int h)
Definition swscale.c:754
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:280
static int frame_alloc_buffers(SwsContext *sws, AVFrame *frame)
Definition swscale.c:1299
static int frame_strides_fit(const AVFrame *frame)
Definition swscale.c:1430
static void init_range_convert_constants(SwsInternal *c)
Definition swscale.c:614
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:1263
#define DEBUG_BUFFERS(...)
Definition swscale.c:276
static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
Definition swscale.c:742
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:985
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:1048
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:1019
av_cold void ff_sws_init_range_convert(SwsInternal *c)
Definition swscale.c:652
static int bottom_field_fits(const AVFrame *frame, const SwsFormat *field)
Definition swscale.c:1538
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:889
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:830
static void solve_range_convert(uint16_t src_min, uint16_t src_max, uint16_t dst_min, uint16_t dst_max, uint16_t src_ref, uint16_t dst_ref, int src_bits, int src_shift, int mult_shift, uint32_t *coeff, int64_t *offset)
Definition swscale.c:599
static int ptr_in_buf(const uint8_t *ptr, const AVBufferRef *buf)
Definition swscale.c:1255
static void round_xyz12(uint8_t *plane, int stride, int width, int height, int y, int big_endian)
Definition swscale.c:257
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:899
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_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:2471
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:99
#define width
Definition dsp.h:99
static const Backend backends[]
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)
uint8_t base
Definition vp3data.h:128
static double c[64]
int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
Definition ops.c:40
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition dec.c:851