FFmpeg
graph.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Niklas Haas
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/error.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/macros.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/slicethread.h"
29 
30 #include "libswscale/swscale.h"
31 #include "libswscale/format.h"
32 
33 #include "cms.h"
34 #include "lut3d.h"
35 #include "swscale_internal.h"
36 #include "graph.h"
37 #include "ops.h"
38 
39 static int pass_alloc_output(SwsPass *pass)
40 {
41  if (!pass || pass->output.fmt != AV_PIX_FMT_NONE)
42  return 0;
43  pass->output.fmt = pass->format;
44  return av_image_alloc(pass->output.data, pass->output.linesize, pass->width,
45  pass->num_slices * pass->slice_h, pass->format, 64);
46 }
47 
49  int width, int height, SwsPass *input,
50  int align, void *priv, sws_filter_run_t run)
51 {
52  int ret;
53  SwsPass *pass = av_mallocz(sizeof(*pass));
54  if (!pass)
55  return NULL;
56 
57  pass->graph = graph;
58  pass->run = run;
59  pass->priv = priv;
60  pass->format = fmt;
61  pass->width = width;
62  pass->height = height;
63  pass->input = input;
64  pass->output.fmt = AV_PIX_FMT_NONE;
65 
67  if (ret < 0) {
68  av_free(pass);
69  return NULL;
70  }
71 
72  if (!align) {
73  pass->slice_h = pass->height;
74  pass->num_slices = 1;
75  } else {
76  pass->slice_h = (pass->height + graph->num_threads - 1) / graph->num_threads;
77  pass->slice_h = FFALIGN(pass->slice_h, align);
78  pass->num_slices = (pass->height + pass->slice_h - 1) / pass->slice_h;
79  }
80 
81  ret = av_dynarray_add_nofree(&graph->passes, &graph->num_passes, pass);
82  if (ret < 0)
83  av_freep(&pass);
84  return pass;
85 }
86 
87 /* Wrapper around ff_sws_graph_add_pass() that chains a pass "in-place" */
88 static int pass_append(SwsGraph *graph, enum AVPixelFormat fmt, int w, int h,
89  SwsPass **pass, int align, void *priv, sws_filter_run_t run)
90 {
91  SwsPass *new = ff_sws_graph_add_pass(graph, fmt, w, h, *pass, align, priv, run);
92  if (!new)
93  return AVERROR(ENOMEM);
94  *pass = new;
95  return 0;
96 }
97 
98 static void run_copy(const SwsImg *out_base, const SwsImg *in_base,
99  int y, int h, const SwsPass *pass)
100 {
101  SwsImg in = ff_sws_img_shift(in_base, y);
102  SwsImg out = ff_sws_img_shift(out_base, y);
103 
104  for (int i = 0; i < FF_ARRAY_ELEMS(out.data) && out.data[i]; i++) {
105  const int lines = h >> ff_fmt_vshift(in.fmt, i);
106  av_assert1(in.data[i]);
107 
108  if (in.linesize[i] == out.linesize[i]) {
109  memcpy(out.data[i], in.data[i], lines * out.linesize[i]);
110  } else {
111  const int linesize = FFMIN(out.linesize[i], in.linesize[i]);
112  for (int j = 0; j < lines; j++) {
113  memcpy(out.data[i], in.data[i], linesize);
114  in.data[i] += in.linesize[i];
115  out.data[i] += out.linesize[i];
116  }
117  }
118  }
119 }
120 
121 static void run_rgb0(const SwsImg *out, const SwsImg *in, int y, int h,
122  const SwsPass *pass)
123 {
124  SwsInternal *c = pass->priv;
125  const int x0 = c->src0Alpha - 1;
126  const int w4 = 4 * pass->width;
127  const int src_stride = in->linesize[0];
128  const int dst_stride = out->linesize[0];
129  const uint8_t *src = in->data[0] + y * src_stride;
130  uint8_t *dst = out->data[0] + y * dst_stride;
131 
132  for (int y = 0; y < h; y++) {
133  memcpy(dst, src, w4 * sizeof(*dst));
134  for (int x = x0; x < w4; x += 4)
135  dst[x] = 0xFF;
136 
137  src += src_stride;
138  dst += dst_stride;
139  }
140 }
141 
142 static void run_xyz2rgb(const SwsImg *out, const SwsImg *in, int y, int h,
143  const SwsPass *pass)
144 {
145  const SwsInternal *c = pass->priv;
146  c->xyz12Torgb48(c, out->data[0] + y * out->linesize[0], out->linesize[0],
147  in->data[0] + y * in->linesize[0], in->linesize[0],
148  pass->width, h);
149 }
150 
151 static void run_rgb2xyz(const SwsImg *out, const SwsImg *in, int y, int h,
152  const SwsPass *pass)
153 {
154  const SwsInternal *c = pass->priv;
155  c->rgb48Toxyz12(c, out->data[0] + y * out->linesize[0], out->linesize[0],
156  in->data[0] + y * in->linesize[0], in->linesize[0],
157  pass->width, h);
158 }
159 
160 /***********************************************************************
161  * Internal ff_swscale() wrapper. This reuses the legacy scaling API. *
162  * This is considered fully deprecated, and will be replaced by a full *
163  * reimplementation ASAP. *
164  ***********************************************************************/
165 
166 static void free_legacy_swscale(void *priv)
167 {
168  SwsContext *sws = priv;
170 }
171 
172 static void setup_legacy_swscale(const SwsImg *out, const SwsImg *in,
173  const SwsPass *pass)
174 {
175  const SwsGraph *graph = pass->graph;
176  const SwsImg *in_orig = &graph->exec.input;
177  SwsContext *sws = pass->priv;
179  if (sws->flags & SWS_BITEXACT && sws->dither == SWS_DITHER_ED && c->dither_error[0]) {
180  for (int i = 0; i < 4; i++)
181  memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (sws->dst_w + 2));
182  }
183 
184  if (usePal(sws->src_format))
185  ff_update_palette(c, (const uint32_t *) in_orig->data[1]);
186 }
187 
188 static inline SwsContext *slice_ctx(const SwsPass *pass, int y)
189 {
190  SwsContext *sws = pass->priv;
191  SwsInternal *parent = sws_internal(sws);
192  if (pass->num_slices == 1)
193  return sws;
194 
195  av_assert1(parent->nb_slice_ctx == pass->num_slices);
196  sws = parent->slice_ctx[y / pass->slice_h];
197 
198  if (usePal(sws->src_format)) {
199  SwsInternal *sub = sws_internal(sws);
200  memcpy(sub->pal_yuv, parent->pal_yuv, sizeof(sub->pal_yuv));
201  memcpy(sub->pal_rgb, parent->pal_rgb, sizeof(sub->pal_rgb));
202  }
203 
204  return sws;
205 }
206 
207 static void run_legacy_unscaled(const SwsImg *out, const SwsImg *in_base,
208  int y, int h, const SwsPass *pass)
209 {
210  SwsContext *sws = slice_ctx(pass, y);
212  const SwsImg in = ff_sws_img_shift(in_base, y);
213 
214  c->convert_unscaled(c, (const uint8_t *const *) in.data, in.linesize, y, h,
215  out->data, out->linesize);
216 }
217 
218 static void run_legacy_swscale(const SwsImg *out_base, const SwsImg *in,
219  int y, int h, const SwsPass *pass)
220 {
221  SwsContext *sws = slice_ctx(pass, y);
223  const SwsImg out = ff_sws_img_shift(out_base, y);
224 
225  ff_swscale(c, (const uint8_t *const *) in->data, in->linesize, 0,
226  sws->src_h, out.data, out.linesize, y, h);
227 }
228 
229 static void get_chroma_pos(SwsGraph *graph, int *h_chr_pos, int *v_chr_pos,
230  const SwsFormat *fmt)
231 {
232  enum AVChromaLocation chroma_loc = fmt->loc;
233  const int sub_x = fmt->desc->log2_chroma_w;
234  const int sub_y = fmt->desc->log2_chroma_h;
235  int x_pos, y_pos;
236 
237  /* Explicitly default to center siting for compatibility with swscale */
238  if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED) {
239  chroma_loc = AVCHROMA_LOC_CENTER;
240  graph->incomplete |= sub_x || sub_y;
241  }
242 
243  /* av_chroma_location_enum_to_pos() always gives us values in the range from
244  * 0 to 256, but we need to adjust this to the true value range of the
245  * subsampling grid, which may be larger for h/v_sub > 1 */
246  av_chroma_location_enum_to_pos(&x_pos, &y_pos, chroma_loc);
247  x_pos *= (1 << sub_x) - 1;
248  y_pos *= (1 << sub_y) - 1;
249 
250  /* Fix vertical chroma position for interlaced frames */
251  if (sub_y && fmt->interlaced) {
252  /* When vertically subsampling, chroma samples are effectively only
253  * placed next to even rows. To access them from the odd field, we need
254  * to account for this shift by offsetting the distance of one luma row.
255  *
256  * For 4x vertical subsampling (v_sub == 2), they are only placed
257  * next to every *other* even row, so we need to shift by three luma
258  * rows to get to the chroma sample. */
259  if (graph->field == FIELD_BOTTOM)
260  y_pos += (256 << sub_y) - 256;
261 
262  /* Luma row distance is doubled for fields, so halve offsets */
263  y_pos >>= 1;
264  }
265 
266  /* Explicitly strip chroma offsets when not subsampling, because it
267  * interferes with the operation of flags like SWS_FULL_CHR_H_INP */
268  *h_chr_pos = sub_x ? x_pos : -513;
269  *v_chr_pos = sub_y ? y_pos : -513;
270 }
271 
272 static void legacy_chr_pos(SwsGraph *graph, int *chr_pos, int override, int *warned)
273 {
274  if (override == -513 || override == *chr_pos)
275  return;
276 
277  if (!*warned) {
279  "Setting chroma position directly is deprecated, make sure "
280  "the frame is tagged with the correct chroma location.\n");
281  *warned = 1;
282  }
283 
284  *chr_pos = override;
285 }
286 
287 /* Takes over ownership of `sws` */
290 {
292  const int src_w = sws->src_w, src_h = sws->src_h;
293  const int dst_w = sws->dst_w, dst_h = sws->dst_h;
294  const int unscaled = src_w == dst_w && src_h == dst_h;
295  int align = c->dst_slice_align;
296  SwsPass *pass = NULL;
297  int ret;
298 
299  if (c->cascaded_context[0]) {
300  const int num_cascaded = c->cascaded_context[2] ? 3 : 2;
301  for (int i = 0; i < num_cascaded; i++) {
302  const int is_last = i + 1 == num_cascaded;
303 
304  /* Steal cascaded context, so we can manage its lifetime independently */
305  SwsContext *sub = c->cascaded_context[i];
306  c->cascaded_context[i] = NULL;
307 
308  ret = init_legacy_subpass(graph, sub, input, is_last ? output : &input);
309  if (ret < 0)
310  break;
311  }
312 
314  return ret;
315  }
316 
317  if (sws->dither == SWS_DITHER_ED && !c->convert_unscaled)
318  align = 0; /* disable slice threading */
319 
320  if (c->src0Alpha && !c->dst0Alpha && isALPHA(sws->dst_format)) {
321  ret = pass_append(graph, AV_PIX_FMT_RGBA, src_w, src_h, &input, 1, c, run_rgb0);
322  if (ret < 0) {
324  return ret;
325  }
326  }
327 
328  if (c->srcXYZ && !(c->dstXYZ && unscaled)) {
329  ret = pass_append(graph, AV_PIX_FMT_RGB48, src_w, src_h, &input, 1, c, run_xyz2rgb);
330  if (ret < 0) {
332  return ret;
333  }
334  }
335 
336  pass = ff_sws_graph_add_pass(graph, sws->dst_format, dst_w, dst_h, input, align, sws,
337  c->convert_unscaled ? run_legacy_unscaled : run_legacy_swscale);
338  if (!pass) {
340  return AVERROR(ENOMEM);
341  }
342  pass->setup = setup_legacy_swscale;
343  pass->free = free_legacy_swscale;
344 
345  /**
346  * For slice threading, we need to create sub contexts, similar to how
347  * swscale normally handles it internally. The most important difference
348  * is that we handle cascaded contexts before threaded contexts; whereas
349  * context_init_threaded() does it the other way around.
350  */
351 
352  if (pass->num_slices > 1) {
353  c->slice_ctx = av_calloc(pass->num_slices, sizeof(*c->slice_ctx));
354  if (!c->slice_ctx)
355  return AVERROR(ENOMEM);
356 
357  for (int i = 0; i < pass->num_slices; i++) {
358  SwsContext *slice;
359  SwsInternal *c2;
360  slice = c->slice_ctx[i] = sws_alloc_context();
361  if (!slice)
362  return AVERROR(ENOMEM);
363  c->nb_slice_ctx++;
364 
365  c2 = sws_internal(slice);
366  c2->parent = sws;
367 
368  ret = av_opt_copy(slice, sws);
369  if (ret < 0)
370  return ret;
371 
373  if (ret < 0)
374  return ret;
375 
376  sws_setColorspaceDetails(slice, c->srcColorspaceTable,
377  slice->src_range, c->dstColorspaceTable,
378  slice->dst_range, c->brightness, c->contrast,
379  c->saturation);
380 
381  for (int i = 0; i < FF_ARRAY_ELEMS(c->srcColorspaceTable); i++) {
382  c2->srcColorspaceTable[i] = c->srcColorspaceTable[i];
383  c2->dstColorspaceTable[i] = c->dstColorspaceTable[i];
384  }
385  }
386  }
387 
388  if (c->dstXYZ && !(c->srcXYZ && unscaled)) {
389  ret = pass_append(graph, AV_PIX_FMT_RGB48, dst_w, dst_h, &pass, 1, c, run_rgb2xyz);
390  if (ret < 0)
391  return ret;
392  }
393 
394  *output = pass;
395  return 0;
396 }
397 
400 {
401  int ret, warned = 0;
402  SwsContext *const ctx = graph->ctx;
404  if (!sws)
405  return AVERROR(ENOMEM);
406 
407  sws->flags = ctx->flags;
408  sws->dither = ctx->dither;
409  sws->alpha_blend = ctx->alpha_blend;
410  sws->gamma_flag = ctx->gamma_flag;
411 
412  sws->src_w = src.width;
413  sws->src_h = src.height;
414  sws->src_format = src.format;
415  sws->src_range = src.range == AVCOL_RANGE_JPEG;
416 
417  sws->dst_w = dst.width;
418  sws->dst_h = dst.height;
419  sws->dst_format = dst.format;
420  sws->dst_range = dst.range == AVCOL_RANGE_JPEG;
423 
424  graph->incomplete |= src.range == AVCOL_RANGE_UNSPECIFIED;
425  graph->incomplete |= dst.range == AVCOL_RANGE_UNSPECIFIED;
426 
427  /* Allow overriding chroma position with the legacy API */
428  legacy_chr_pos(graph, &sws->src_h_chr_pos, ctx->src_h_chr_pos, &warned);
429  legacy_chr_pos(graph, &sws->src_v_chr_pos, ctx->src_v_chr_pos, &warned);
430  legacy_chr_pos(graph, &sws->dst_h_chr_pos, ctx->dst_h_chr_pos, &warned);
431  legacy_chr_pos(graph, &sws->dst_v_chr_pos, ctx->dst_v_chr_pos, &warned);
432 
433  sws->scaler_params[0] = ctx->scaler_params[0];
434  sws->scaler_params[1] = ctx->scaler_params[1];
435 
437  if (ret < 0) {
439  return ret;
440  }
441 
442  /* Set correct color matrices */
443  {
444  int in_full, out_full, brightness, contrast, saturation;
445  const int *inv_table, *table;
446  sws_getColorspaceDetails(sws, (int **)&inv_table, &in_full,
447  (int **)&table, &out_full,
448  &brightness, &contrast, &saturation);
449 
450  inv_table = sws_getCoefficients(src.csp);
452 
453  graph->incomplete |= src.csp != dst.csp &&
454  (src.csp == AVCOL_SPC_UNSPECIFIED ||
455  dst.csp == AVCOL_SPC_UNSPECIFIED);
456 
457  sws_setColorspaceDetails(sws, inv_table, in_full, table, out_full,
458  brightness, contrast, saturation);
459  }
460 
461  return init_legacy_subpass(graph, sws, input, output);
462 }
463 
464 /*********************
465  * Format conversion *
466  *********************/
467 
468 #if CONFIG_UNSTABLE
469 static int add_convert_pass(SwsGraph *graph, SwsFormat src, SwsFormat dst,
471 {
473 
474  SwsContext *ctx = graph->ctx;
475  SwsOpList *ops = NULL;
476  int ret = AVERROR(ENOTSUP);
477 
478  /* Mark the entire new ops infrastructure as experimental for now */
479  if (!(ctx->flags & SWS_UNSTABLE))
480  goto fail;
481 
482  /* The new format conversion layer cannot scale for now */
483  if (src.width != dst.width || src.height != dst.height ||
484  src.desc->log2_chroma_h || src.desc->log2_chroma_w ||
485  dst.desc->log2_chroma_h || dst.desc->log2_chroma_w)
486  goto fail;
487 
488  /* The new code does not yet support alpha blending */
489  if (src.desc->flags & AV_PIX_FMT_FLAG_ALPHA &&
490  ctx->alpha_blend != SWS_ALPHA_BLEND_NONE)
491  goto fail;
492 
493  ops = ff_sws_op_list_alloc();
494  if (!ops)
495  return AVERROR(ENOMEM);
496  ops->src = src;
497  ops->dst = dst;
498 
499  ret = ff_sws_decode_pixfmt(ops, src.format);
500  if (ret < 0)
501  goto fail;
502  ret = ff_sws_decode_colors(ctx, type, ops, src, &graph->incomplete);
503  if (ret < 0)
504  goto fail;
505  ret = ff_sws_encode_colors(ctx, type, ops, dst, &graph->incomplete);
506  if (ret < 0)
507  goto fail;
508  ret = ff_sws_encode_pixfmt(ops, dst.format);
509  if (ret < 0)
510  goto fail;
511 
512  av_log(ctx, AV_LOG_VERBOSE, "Conversion pass for %s -> %s:\n",
514 
515  av_log(ctx, AV_LOG_DEBUG, "Unoptimized operation list:\n");
517  av_log(ctx, AV_LOG_DEBUG, "Optimized operation list:\n");
518 
520  if (ops->num_ops == 0) {
521  av_log(ctx, AV_LOG_VERBOSE, " optimized into memcpy\n");
522  ff_sws_op_list_free(&ops);
523  *output = input;
524  return 0;
525  }
526 
528 
529  ret = ff_sws_compile_pass(graph, ops, 0, dst, input, output);
530  if (ret < 0)
531  goto fail;
532 
533  ret = 0;
534  /* fall through */
535 
536 fail:
537  ff_sws_op_list_free(&ops);
538  if (ret == AVERROR(ENOTSUP))
539  return add_legacy_sws_pass(graph, src, dst, input, output);
540  return ret;
541 }
542 #else
543 #define add_convert_pass add_legacy_sws_pass
544 #endif
545 
546 
547 /**************************
548  * Gamut and tone mapping *
549  **************************/
550 
551 static void free_lut3d(void *priv)
552 {
553  SwsLut3D *lut = priv;
554  ff_sws_lut3d_free(&lut);
555 }
556 
557 static void setup_lut3d(const SwsImg *out, const SwsImg *in, const SwsPass *pass)
558 {
559  SwsLut3D *lut = pass->priv;
560 
561  /* Update dynamic frame metadata from the original source frame */
562  ff_sws_lut3d_update(lut, &pass->graph->src.color);
563 }
564 
565 static void run_lut3d(const SwsImg *out_base, const SwsImg *in_base,
566  int y, int h, const SwsPass *pass)
567 {
568  SwsLut3D *lut = pass->priv;
569  const SwsImg in = ff_sws_img_shift(in_base, y);
570  const SwsImg out = ff_sws_img_shift(out_base, y);
571 
572  ff_sws_lut3d_apply(lut, in.data[0], in.linesize[0], out.data[0],
573  out.linesize[0], pass->width, h);
574 }
575 
578 {
579  enum AVPixelFormat fmt_in, fmt_out;
580  SwsColorMap map = {0};
581  SwsLut3D *lut;
582  SwsPass *pass;
583  int ret;
584 
585  /**
586  * Grayspace does not really have primaries, so just force the use of
587  * the equivalent other primary set to avoid a conversion. Technically,
588  * this does affect the weights used for the Grayscale conversion, but
589  * in practise, that should give the expected results more often than not.
590  */
591  if (isGray(dst.format)) {
592  dst.color = src.color;
593  } else if (isGray(src.format)) {
594  src.color = dst.color;
595  }
596 
597  /* Fully infer color spaces before color mapping logic */
598  graph->incomplete |= ff_infer_colors(&src.color, &dst.color);
599 
600  map.intent = graph->ctx->intent;
601  map.src = src.color;
602  map.dst = dst.color;
603 
605  return 0;
606 
607  lut = ff_sws_lut3d_alloc();
608  if (!lut)
609  return AVERROR(ENOMEM);
610 
611  fmt_in = ff_sws_lut3d_pick_pixfmt(src, 0);
612  fmt_out = ff_sws_lut3d_pick_pixfmt(dst, 1);
613  if (fmt_in != src.format) {
614  SwsFormat tmp = src;
615  tmp.format = fmt_in;
616  ret = add_convert_pass(graph, src, tmp, input, &input);
617  if (ret < 0)
618  return ret;
619  }
620 
621  ret = ff_sws_lut3d_generate(lut, fmt_in, fmt_out, &map);
622  if (ret < 0) {
623  ff_sws_lut3d_free(&lut);
624  return ret;
625  }
626 
627  pass = ff_sws_graph_add_pass(graph, fmt_out, src.width, src.height,
628  input, 1, lut, run_lut3d);
629  if (!pass) {
630  ff_sws_lut3d_free(&lut);
631  return AVERROR(ENOMEM);
632  }
633  pass->setup = setup_lut3d;
634  pass->free = free_lut3d;
635 
636  *output = pass;
637  return 0;
638 }
639 
640 /***************************************
641  * Main filter graph construction code *
642  ***************************************/
643 
644 static int init_passes(SwsGraph *graph)
645 {
646  SwsFormat src = graph->src;
647  SwsFormat dst = graph->dst;
648  SwsPass *pass = NULL; /* read from main input image */
649  int ret;
650 
651  ret = adapt_colors(graph, src, dst, pass, &pass);
652  if (ret < 0)
653  return ret;
654  src.format = pass ? pass->format : src.format;
655  src.color = dst.color;
656 
657  if (!ff_fmt_equal(&src, &dst)) {
658  ret = add_convert_pass(graph, src, dst, pass, &pass);
659  if (ret < 0)
660  return ret;
661  }
662 
663  if (!pass) {
664  /* No passes were added, so no operations were necessary */
665  graph->noop = 1;
666 
667  /* Add threaded memcpy pass */
668  pass = ff_sws_graph_add_pass(graph, dst.format, dst.width, dst.height,
669  pass, 1, NULL, run_copy);
670  if (!pass)
671  return AVERROR(ENOMEM);
672  }
673 
674  return 0;
675 }
676 
677 static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs,
678  int nb_threads)
679 {
680  SwsGraph *graph = priv;
681  const SwsPass *pass = graph->exec.pass;
682  const SwsImg *input = pass->input ? &pass->input->output : &graph->exec.input;
683  const SwsImg *output = pass->output.fmt != AV_PIX_FMT_NONE ? &pass->output : &graph->exec.output;
684  const int slice_y = jobnr * pass->slice_h;
685  const int slice_h = FFMIN(pass->slice_h, pass->height - slice_y);
686 
687  pass->run(output, input, slice_y, slice_h, pass);
688 }
689 
691  int field, SwsGraph **out_graph)
692 {
693  int ret;
694  SwsGraph *graph = av_mallocz(sizeof(*graph));
695  if (!graph)
696  return AVERROR(ENOMEM);
697 
698  graph->ctx = ctx;
699  graph->src = *src;
700  graph->dst = *dst;
701  graph->field = field;
702  graph->opts_copy = *ctx;
703 
704  graph->exec.input.fmt = src->format;
705  graph->exec.output.fmt = dst->format;
706 
707  ret = avpriv_slicethread_create(&graph->slicethread, (void *) graph,
708  sws_graph_worker, NULL, ctx->threads);
709  if (ret == AVERROR(ENOSYS))
710  graph->num_threads = 1;
711  else if (ret < 0)
712  goto error;
713  else
714  graph->num_threads = ret;
715 
716  ret = init_passes(graph);
717  if (ret < 0)
718  goto error;
719 
720  *out_graph = graph;
721  return 0;
722 
723 error:
724  ff_sws_graph_free(&graph);
725  return ret;
726 }
727 
729 {
730  SwsGraph *graph = *pgraph;
731  if (!graph)
732  return;
733 
735 
736  for (int i = 0; i < graph->num_passes; i++) {
737  SwsPass *pass = graph->passes[i];
738  if (pass->free)
739  pass->free(pass->priv);
740  if (pass->output.fmt != AV_PIX_FMT_NONE)
741  av_free(pass->output.data[0]);
742  av_free(pass);
743  }
744  av_free(graph->passes);
745 
746  av_free(graph);
747  *pgraph = NULL;
748 }
749 
750 /* Tests only options relevant to SwsGraph */
751 static int opts_equal(const SwsContext *c1, const SwsContext *c2)
752 {
753  return c1->flags == c2->flags &&
754  c1->threads == c2->threads &&
755  c1->dither == c2->dither &&
756  c1->alpha_blend == c2->alpha_blend &&
757  c1->gamma_flag == c2->gamma_flag &&
758  c1->src_h_chr_pos == c2->src_h_chr_pos &&
759  c1->src_v_chr_pos == c2->src_v_chr_pos &&
760  c1->dst_h_chr_pos == c2->dst_h_chr_pos &&
761  c1->dst_v_chr_pos == c2->dst_v_chr_pos &&
762  c1->intent == c2->intent &&
763  !memcmp(c1->scaler_params, c2->scaler_params, sizeof(c1->scaler_params));
764 
765 }
766 
768  int field, SwsGraph **out_graph)
769 {
770  SwsGraph *graph = *out_graph;
771  if (graph && ff_fmt_equal(&graph->src, src) &&
772  ff_fmt_equal(&graph->dst, dst) &&
773  opts_equal(ctx, &graph->opts_copy))
774  {
775  ff_sws_graph_update_metadata(graph, &src->color);
776  return 0;
777  }
778 
779  ff_sws_graph_free(out_graph);
780  return ff_sws_graph_create(ctx, dst, src, field, out_graph);
781 }
782 
784 {
785  if (!color)
786  return;
787 
789 }
790 
791 void ff_sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4],
792  const int out_linesize[4],
793  const uint8_t *const in_data[4],
794  const int in_linesize[4])
795 {
796  SwsImg *out = &graph->exec.output;
797  SwsImg *in = &graph->exec.input;
798  memcpy(out->data, out_data, sizeof(out->data));
799  memcpy(out->linesize, out_linesize, sizeof(out->linesize));
800  memcpy(in->data, in_data, sizeof(in->data));
801  memcpy(in->linesize, in_linesize, sizeof(in->linesize));
802 
803  for (int i = 0; i < graph->num_passes; i++) {
804  const SwsPass *pass = graph->passes[i];
805  graph->exec.pass = pass;
806  if (pass->setup) {
807  pass->setup(pass->output.fmt != AV_PIX_FMT_NONE ? &pass->output : out,
808  pass->input ? &pass->input->output : in, pass);
809  }
811  }
812 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
SwsGraph::exec
struct SwsGraph::@529 exec
Temporary execution state inside ff_sws_graph_run.
sws_setColorspaceDetails
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
Definition: utils.c:836
ff_sws_op_list_free
void ff_sws_op_list_free(SwsOpList **p_ops)
Definition: ops.c:230
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
SwsGraph::slicethread
AVSliceThread * slicethread
Definition: graph.h:110
SwsGraph::ctx
SwsContext * ctx
Definition: graph.h:109
SwsPass
Represents a single filter pass in the scaling graph.
Definition: graph.h:68
ff_sws_op_list_alloc
SwsOpList * ff_sws_op_list_alloc(void)
Definition: ops.c:219
SwsGraph::pass
const SwsPass * pass
Definition: graph.h:133
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
SwsGraph::passes
SwsPass ** passes
Sorted sequence of filter passes to apply.
Definition: graph.h:116
adapt_colors
static int adapt_colors(SwsGraph *graph, SwsFormat src, SwsFormat dst, SwsPass *input, SwsPass **output)
Definition: graph.c:576
out
FILE * out
Definition: movenc.c:55
color
Definition: vf_paletteuse.c:513
init_passes
static int init_passes(SwsGraph *graph)
Definition: graph.c:644
SwsPass::output
SwsImg output
Filter output buffer.
Definition: graph.h:91
SwsFormat::interlaced
int interlaced
Definition: format.h:79
SwsContext::src_w
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition: swscale.h:235
ff_sws_graph_reinit
int ff_sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, int field, SwsGraph **out_graph)
Wrapper around ff_sws_graph_create() that reuses the existing graph if the format is compatible.
Definition: graph.c:767
SwsPass::format
enum AVPixelFormat format
Definition: graph.h:77
saturation
static IPT saturation(const CmsCtx *ctx, IPT ipt)
Definition: cms.c:559
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:226
sws_filter_run_t
void(* sws_filter_run_t)(const SwsImg *out, const SwsImg *in, int y, int h, const SwsPass *pass)
Output h lines of filtered data.
Definition: graph.h:60
SwsGraph::src
SwsFormat src
Currently active format and processing parameters.
Definition: graph.h:128
avpriv_slicethread_execute
void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main)
Execute slice threading.
Definition: slicethread.c:271
pixdesc.h
ops.h
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
isGray
static av_always_inline int isGray(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:803
SWS_BITEXACT
@ SWS_BITEXACT
Definition: swscale.h:156
table
static const uint16_t table[]
Definition: prosumer.c:203
SwsContext::flags
unsigned flags
Bitmask of SWS_*.
Definition: swscale.h:202
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
ff_sws_lut3d_pick_pixfmt
enum AVPixelFormat ff_sws_lut3d_pick_pixfmt(SwsFormat fmt, int output)
Pick the best compatible pixfmt for a given SwsFormat.
Definition: lut3d.c:52
SwsPass::free
void(* free)(void *priv)
Optional private state and associated free() function.
Definition: graph.h:101
c1
static const uint64_t c1
Definition: murmur3.c:52
FIELD_BOTTOM
@ FIELD_BOTTOM
Definition: format.h:57
SwsImg
Represents a view into a single field of frame data.
Definition: graph.h:33
format.h
SWS_ALPHA_BLEND_NONE
@ SWS_ALPHA_BLEND_NONE
Definition: swscale.h:88
ff_sws_init_single_context
int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, SwsFilter *dstFilter)
Definition: utils.c:1108
SwsColorMap
Definition: cms.h:60
SwsPixelType
SwsPixelType
Copyright (C) 2025 Niklas Haas.
Definition: ops.h:30
SwsPass::width
int width
Definition: graph.h:78
ff_color_update_dynamic
static void ff_color_update_dynamic(SwsColor *dst, const SwsColor *src)
Definition: format.h:70
init_legacy_subpass
static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, SwsPass *input, SwsPass **output)
Definition: graph.c:288
SWS_PIXEL_F32
@ SWS_PIXEL_F32
Definition: ops.h:35
avpriv_slicethread_create
int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, void(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), void(*main_func)(void *priv), int nb_threads)
Create slice threading context.
Definition: slicethread.c:262
macros.h
pass_append
static int pass_append(SwsGraph *graph, enum AVPixelFormat fmt, int w, int h, SwsPass **pass, int align, void *priv, sws_filter_run_t run)
Definition: graph.c:88
fail
#define fail()
Definition: checkasm.h:214
SwsOpList::num_ops
int num_ops
Definition: ops.h:210
SwsContext::src_v_chr_pos
int src_v_chr_pos
Source vertical chroma position in luma grid / 256.
Definition: swscale.h:241
slice_ctx
static SwsContext * slice_ctx(const SwsPass *pass, int y)
Definition: graph.c:188
sws_init_context
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition: utils.c:1880
SwsGraph::opts_copy
SwsContext opts_copy
Cached copy of the public options that were used to construct this SwsGraph.
Definition: graph.h:123
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ff_sws_graph_create
int ff_sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, int field, SwsGraph **out_graph)
Allocate and initialize the filter graph.
Definition: graph.c:690
avassert.h
ff_sws_graph_run
void ff_sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4], const int out_linesize[4], const uint8_t *const in_data[4], const int in_linesize[4])
Dispatch the filter graph on a single field.
Definition: graph.c:791
SwsInternal::pal_rgb
uint32_t pal_rgb[256]
Definition: swscale_internal.h:396
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
legacy_chr_pos
static void legacy_chr_pos(SwsGraph *graph, int *chr_pos, int override, int *warned)
Definition: graph.c:272
SwsContext::dither
SwsDither dither
Dither mode.
Definition: swscale.h:217
SwsPass::priv
void * priv
Definition: graph.h:102
SwsInternal::nb_slice_ctx
int nb_slice_ctx
Definition: swscale_internal.h:340
SwsInternal::slice_ctx
SwsContext ** slice_ctx
Definition: swscale_internal.h:338
ff_sws_encode_colors
int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, const SwsFormat fmt, bool *incomplete)
av_chroma_location_enum_to_pos
int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: pixdesc.c:3898
ff_update_palette
void ff_update_palette(SwsInternal *c, const uint32_t *pal)
Definition: swscale.c:870
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1415
ff_sws_lut3d_alloc
SwsLut3D * ff_sws_lut3d_alloc(void)
Definition: lut3d.c:32
SwsPass::setup
void(* setup)(const SwsImg *out, const SwsImg *in, const SwsPass *pass)
Called once from the main thread before running the filter.
Definition: graph.h:96
SwsContext::intent
int intent
Desired ICC intent for color space conversions.
Definition: swscale.h:249
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
SwsGraph::num_passes
int num_passes
Definition: graph.h:117
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ff_sws_lut3d_update
void ff_sws_lut3d_update(SwsLut3D *lut3d, const SwsColor *new_src)
Update the tone mapping state.
Definition: lut3d.c:239
field
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
Definition: writing_filters.txt:78
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
SwsGraph::field
int field
Definition: graph.h:129
ff_sws_graph_add_pass
SwsPass * ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, int width, int height, SwsPass *input, int align, void *priv, sws_filter_run_t run)
Allocate and add a new pass to the filter graph.
Definition: graph.c:48
ff_sws_lut3d_free
void ff_sws_lut3d_free(SwsLut3D **plut3d)
Definition: lut3d.c:42
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:207
SwsContext::gamma_flag
int gamma_flag
Use gamma correct scaling.
Definition: swscale.h:227
run_xyz2rgb
static void run_xyz2rgb(const SwsImg *out, const SwsImg *in, int y, int h, const SwsPass *pass)
Definition: graph.c:142
ff_infer_colors
bool ff_infer_colors(SwsColor *src, SwsColor *dst)
Definition: format.c:508
SwsGraph::input
SwsImg input
Definition: graph.h:134
ff_sws_lut3d_generate
int ff_sws_lut3d_generate(SwsLut3D *lut3d, enum AVPixelFormat fmt_in, enum AVPixelFormat fmt_out, const SwsColorMap *map)
Recalculate the (static) 3DLUT state with new settings.
Definition: lut3d.c:211
SwsContext::src_range
int src_range
Source is full range.
Definition: swscale.h:239
SwsPass::graph
const SwsGraph * graph
Definition: graph.h:69
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
SwsContext::dst_h_chr_pos
int dst_h_chr_pos
Destination horizontal chroma position.
Definition: swscale.h:244
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
run_legacy_swscale
static void run_legacy_swscale(const SwsImg *out_base, const SwsImg *in, int y, int h, const SwsPass *pass)
Definition: graph.c:218
error.h
av_opt_copy
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:2151
av_image_alloc
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:218
ff_sws_graph_free
void ff_sws_graph_free(SwsGraph **pgraph)
Uninitialize any state associate with this filter graph and free it.
Definition: graph.c:728
SwsPass::height
int height
Definition: graph.h:78
SwsImg::linesize
int linesize[4]
Definition: graph.h:36
add_legacy_sws_pass
static int add_legacy_sws_pass(SwsGraph *graph, SwsFormat src, SwsFormat dst, SwsPass *input, SwsPass **output)
Definition: graph.c:398
lut3d.h
free_lut3d
static void free_lut3d(void *priv)
Definition: graph.c:551
height
#define height
Definition: dsp.h:89
sws_alloc_context
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition: utils.c:1019
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
usePal
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:934
setup_lut3d
static void setup_lut3d(const SwsImg *out, const SwsImg *in, const SwsPass *pass)
Definition: graph.c:557
ff_sws_lut3d_apply
void ff_sws_lut3d_apply(const SwsLut3D *lut3d, const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int w, int h)
Applies a color transformation to a plane.
Definition: lut3d.c:250
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:525
SwsContext::alpha_blend
SwsAlphaBlend alpha_blend
Alpha blending mode.
Definition: swscale.h:222
SwsOpList::src
SwsFormat src
Definition: ops.h:213
SwsContext::src_h
int src_h
Width and height of the source frame.
Definition: swscale.h:235
SwsGraph::output
SwsImg output
Definition: graph.h:135
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:797
SwsFormat
Definition: format.h:77
sws_getColorspaceDetails
int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
Definition: utils.c:994
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:419
SwsFormat::loc
enum AVChromaLocation loc
Definition: format.h:83
SwsColor
Definition: format.h:60
SwsContext::dst_format
int dst_format
Destination pixel format.
Definition: swscale.h:238
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
slicethread.h
AVChromaLocation
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:796
ff_sws_op_list_optimize
int ff_sws_op_list_optimize(SwsOpList *ops)
Fuse compatible and eliminate redundant operations, as well as replacing some operations with more ef...
Definition: ops_optimizer.c:412
sws
static SwsContext * sws[3]
Definition: swscale.c:73
free_legacy_swscale
static void free_legacy_swscale(void *priv)
Definition: graph.c:166
SwsLut3D
Definition: lut3d.h:50
SwsGraph::dst
SwsFormat dst
Definition: graph.h:128
ff_fmt_vshift
static av_always_inline av_const int ff_fmt_vshift(enum AVPixelFormat fmt, int plane)
Definition: graph.h:39
SwsPass::slice_h
int slice_h
Definition: graph.h:79
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
SwsGraph::num_threads
int num_threads
Definition: graph.h:111
opts_equal
static int opts_equal(const SwsContext *c1, const SwsContext *c2)
Definition: graph.c:751
run_rgb0
static void run_rgb0(const SwsImg *out, const SwsImg *in, int y, int h, const SwsPass *pass)
Definition: graph.c:121
SwsFormat::desc
const AVPixFmtDescriptor * desc
Definition: format.h:84
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
run_rgb2xyz
static void run_rgb2xyz(const SwsImg *out, const SwsImg *in, int y, int h, const SwsPass *pass)
Definition: graph.c:151
swscale_internal.h
graph.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
SwsContext::dst_h
int dst_h
Width and height of the destination frame.
Definition: swscale.h:236
run_copy
static void run_copy(const SwsImg *out_base, const SwsImg *in_base, int y, int h, const SwsPass *pass)
Definition: graph.c:98
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
ff_sws_img_shift
static av_const SwsImg ff_sws_img_shift(const SwsImg *base, const int y)
Definition: graph.h:45
ff_sws_decode_pixfmt
int ff_sws_decode_pixfmt(SwsOpList *ops, enum AVPixelFormat fmt)
Append a set of operations for decoding/encoding raw pixels.
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
get_chroma_pos
static void get_chroma_pos(SwsGraph *graph, int *h_chr_pos, int *v_chr_pos, const SwsFormat *fmt)
Definition: graph.c:229
SWS_DITHER_ED
@ SWS_DITHER_ED
Definition: swscale.h:83
SwsInternal
Definition: swscale_internal.h:330
ret
ret
Definition: filter_design.txt:187
SwsOpList::dst
SwsFormat dst
Definition: ops.h:213
ff_fmt_equal
static int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
Definition: format.h:129
ff_sws_decode_colors
int ff_sws_decode_colors(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, const SwsFormat fmt, bool *incomplete)
Append a set of operations for transforming decoded pixel values to/from normalized RGB in the specif...
SwsGraph::noop
bool noop
Definition: graph.h:113
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:315
c2
static const uint64_t c2
Definition: murmur3.c:53
ff_sws_compile_pass
int ff_sws_compile_pass(SwsGraph *graph, SwsOpList *ops, int flags, SwsFormat dst, SwsPass *input, SwsPass **output)
Resolves an operation list to a graph pass.
SwsContext::scaler_params
double scaler_params[2]
Extra parameters for fine-tuning certain scalers.
Definition: swscale.h:207
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:799
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
SwsFormat::color
SwsColor color
Definition: format.h:85
ff_sws_color_map_noop
bool ff_sws_color_map_noop(const SwsColorMap *map)
Returns true if the given color map is a semantic no-op - that is, the overall RGB end to end transfo...
Definition: cms.c:34
setup_legacy_swscale
static void setup_legacy_swscale(const SwsImg *out, const SwsImg *in, const SwsPass *pass)
Definition: graph.c:172
ff_swscale
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:259
cms.h
add_convert_pass
#define add_convert_pass
Definition: graph.c:543
SwsInternal::pal_yuv
uint32_t pal_yuv[256]
Definition: swscale_internal.h:395
SwsGraph::incomplete
bool incomplete
Definition: graph.h:112
mem.h
sws_getCoefficients
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
Definition: yuv2rgb.c:61
SwsContext::dst_w
int dst_w
Definition: swscale.h:236
SwsGraph
Filter graph, which represents a 'baked' pixel format conversion.
Definition: graph.h:108
SwsContext::src_format
int src_format
Source pixel format.
Definition: swscale.h:237
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
SwsImg::fmt
enum AVPixelFormat fmt
Definition: graph.h:34
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
SwsContext::dst_range
int dst_range
Destination is full range.
Definition: swscale.h:240
pass_alloc_output
static int pass_alloc_output(SwsPass *pass)
Definition: graph.c:39
run_legacy_unscaled
static void run_legacy_unscaled(const SwsImg *out, const SwsImg *in_base, int y, int h, const SwsPass *pass)
Definition: graph.c:207
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
SwsPass::run
sws_filter_run_t run
Filter main execution function.
Definition: graph.h:76
sws_free_context
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition: utils.c:2327
imgutils.h
ff_sws_op_list_print
void ff_sws_op_list_print(void *log, int lev, const SwsOpList *ops)
Print out the contents of an operation list.
Definition: ops.c:396
avpriv_slicethread_free
void avpriv_slicethread_free(AVSliceThread **pctx)
Destroy slice threading context.
Definition: slicethread.c:276
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
SwsContext::src_h_chr_pos
int src_h_chr_pos
Source horizontal chroma position.
Definition: swscale.h:242
sws_internal
static SwsInternal * sws_internal(const SwsContext *sws)
Definition: swscale_internal.h:74
SwsPass::input
const SwsPass * input
Filter input.
Definition: graph.h:86
h
h
Definition: vp9dsp_template.c:2070
SwsPass::num_slices
int num_slices
Definition: graph.h:80
width
#define width
Definition: dsp.h:89
SwsOpList
Helper struct for representing a list of operations.
Definition: ops.h:208
run_lut3d
static void run_lut3d(const SwsImg *out_base, const SwsImg *in_base, int y, int h, const SwsPass *pass)
Definition: graph.c:565
SwsContext::dst_v_chr_pos
int dst_v_chr_pos
Destination vertical chroma position.
Definition: swscale.h:243
SwsContext
Main external API structure.
Definition: swscale.h:189
sws_graph_worker
static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
Definition: graph.c:677
ff_sws_graph_update_metadata
void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color)
Update dynamic per-frame HDR metadata without requiring a full reinit.
Definition: graph.c:783
SWS_UNSTABLE
@ SWS_UNSTABLE
Allow using experimental new code paths.
Definition: swscale.h:163
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
src
#define src
Definition: vp8dsp.c:248
swscale.h
SwsImg::data
uint8_t * data[4]
Definition: graph.h:35
ff_sws_encode_pixfmt
int ff_sws_encode_pixfmt(SwsOpList *ops, enum AVPixelFormat fmt)
av_get_pix_fmt_name
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:3376
isALPHA
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:894