FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_colormatrix.c
Go to the documentation of this file.
1 /*
2  * ColorMatrix v2.2 for Avisynth 2.5.x
3  *
4  * Copyright (C) 2006-2007 Kevin Stone
5  *
6  * ColorMatrix 1.x is Copyright (C) Wilbert Dijkhof
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; either version 2 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * ColorMatrix 2.0 is based on the original ColorMatrix filter by Wilbert
26  * Dijkhof. It adds the ability to convert between any of: Rec.709, FCC,
27  * Rec.601, and SMPTE 240M. It also makes pre and post clipping optional,
28  * adds an option to use scaled or non-scaled coefficients, and more...
29  */
30 
31 #include <float.h>
32 #include "avfilter.h"
33 #include "formats.h"
34 #include "internal.h"
35 #include "video.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/avstring.h"
39 
40 #define NS(n) ((n) < 0 ? (int)((n)*65536.0-0.5+DBL_EPSILON) : (int)((n)*65536.0+0.5))
41 #define CB(n) av_clip_uint8(n)
42 
43 static const double yuv_coeff[4][3][3] = {
44  { { +0.7152, +0.0722, +0.2126 }, // Rec.709 (0)
45  { -0.3850, +0.5000, -0.1150 },
46  { -0.4540, -0.0460, +0.5000 } },
47  { { +0.5900, +0.1100, +0.3000 }, // FCC (1)
48  { -0.3310, +0.5000, -0.1690 },
49  { -0.4210, -0.0790, +0.5000 } },
50  { { +0.5870, +0.1140, +0.2990 }, // Rec.601 (ITU-R BT.470-2/SMPTE 170M) (2)
51  { -0.3313, +0.5000, -0.1687 },
52  { -0.4187, -0.0813, +0.5000 } },
53  { { +0.7010, +0.0870, +0.2120 }, // SMPTE 240M (3)
54  { -0.3840, +0.5000, -0.1160 },
55  { -0.4450, -0.0550, +0.5000 } },
56 };
57 
58 enum ColorMode {
65 };
66 
67 typedef struct {
68  const AVClass *class;
69  int yuv_convert[16][3][3];
71  int source, dest; ///< ColorMode
72  int mode;
73  int hsub, vsub;
75 
76 typedef struct ThreadData {
77  AVFrame *dst;
78  const AVFrame *src;
79  int c2;
80  int c3;
81  int c4;
82  int c5;
83  int c6;
84  int c7;
85 } ThreadData;
86 
87 #define OFFSET(x) offsetof(ColorMatrixContext, x)
88 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
89 
90 static const AVOption colormatrix_options[] = {
91  { "src", "set source color matrix", OFFSET(source), AV_OPT_TYPE_INT, {.i64=COLOR_MODE_NONE}, COLOR_MODE_NONE, COLOR_MODE_COUNT-1, .flags=FLAGS, .unit="color_mode" },
92  { "dst", "set destination color matrix", OFFSET(dest), AV_OPT_TYPE_INT, {.i64=COLOR_MODE_NONE}, COLOR_MODE_NONE, COLOR_MODE_COUNT-1, .flags=FLAGS, .unit="color_mode" },
93  { "bt709", "set BT.709 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT709}, .flags=FLAGS, .unit="color_mode" },
94  { "fcc", "set FCC colorspace ", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_FCC}, .flags=FLAGS, .unit="color_mode" },
95  { "bt601", "set BT.601 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
96  { "bt470", "set BT.470 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
97  { "smpte170m", "set SMTPE-170M colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
98  { "smpte240m", "set SMPTE-240M colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_SMPTE240M}, .flags=FLAGS, .unit="color_mode" },
99  { NULL }
100 };
101 
102 AVFILTER_DEFINE_CLASS(colormatrix);
103 
104 #define ma m[0][0]
105 #define mb m[0][1]
106 #define mc m[0][2]
107 #define md m[1][0]
108 #define me m[1][1]
109 #define mf m[1][2]
110 #define mg m[2][0]
111 #define mh m[2][1]
112 #define mi m[2][2]
113 
114 #define ima im[0][0]
115 #define imb im[0][1]
116 #define imc im[0][2]
117 #define imd im[1][0]
118 #define ime im[1][1]
119 #define imf im[1][2]
120 #define img im[2][0]
121 #define imh im[2][1]
122 #define imi im[2][2]
123 
124 static void inverse3x3(double im[3][3], const double m[3][3])
125 {
126  double det = ma * (me * mi - mf * mh) - mb * (md * mi - mf * mg) + mc * (md * mh - me * mg);
127  det = 1.0 / det;
128  ima = det * (me * mi - mf * mh);
129  imb = det * (mc * mh - mb * mi);
130  imc = det * (mb * mf - mc * me);
131  imd = det * (mf * mg - md * mi);
132  ime = det * (ma * mi - mc * mg);
133  imf = det * (mc * md - ma * mf);
134  img = det * (md * mh - me * mg);
135  imh = det * (mb * mg - ma * mh);
136  imi = det * (ma * me - mb * md);
137 }
138 
139 static void solve_coefficients(double cm[3][3], double rgb[3][3], const double yuv[3][3])
140 {
141  int i, j;
142  for (i = 0; i < 3; i++)
143  for (j = 0; j < 3; j++)
144  cm[i][j] = yuv[i][0] * rgb[0][j] + yuv[i][1] * rgb[1][j] + yuv[i][2] * rgb[2][j];
145 }
146 
148 {
149  ColorMatrixContext *color = ctx->priv;
150  double rgb_coeffd[4][3][3];
151  double yuv_convertd[16][3][3];
152  int v = 0;
153  int i, j, k;
154 
155  for (i = 0; i < 4; i++)
156  inverse3x3(rgb_coeffd[i], yuv_coeff[i]);
157  for (i = 0; i < 4; i++) {
158  for (j = 0; j < 4; j++) {
159  solve_coefficients(yuv_convertd[v], rgb_coeffd[i], yuv_coeff[j]);
160  for (k = 0; k < 3; k++) {
161  color->yuv_convert[v][k][0] = NS(yuv_convertd[v][k][0]);
162  color->yuv_convert[v][k][1] = NS(yuv_convertd[v][k][1]);
163  color->yuv_convert[v][k][2] = NS(yuv_convertd[v][k][2]);
164  }
165  if (color->yuv_convert[v][0][0] != 65536 || color->yuv_convert[v][1][0] != 0 ||
166  color->yuv_convert[v][2][0] != 0) {
167  av_log(ctx, AV_LOG_ERROR, "error calculating conversion coefficients\n");
168  }
169  v++;
170  }
171  }
172 }
173 
174 static const char * const color_modes[] = {"bt709", "fcc", "bt601", "smpte240m"};
175 
176 static av_cold int init(AVFilterContext *ctx)
177 {
178  ColorMatrixContext *color = ctx->priv;
179 
180  if (color->dest == COLOR_MODE_NONE) {
181  av_log(ctx, AV_LOG_ERROR, "Unspecified destination color space\n");
182  return AVERROR(EINVAL);
183  }
184 
185  if (color->source == color->dest) {
186  av_log(ctx, AV_LOG_ERROR, "Source and destination color space must not be identical\n");
187  return AVERROR(EINVAL);
188  }
189 
190  calc_coefficients(ctx);
191 
192  return 0;
193 }
194 
195 static int process_slice_uyvy422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
196 {
197  const ThreadData *td = arg;
198  const AVFrame *src = td->src;
199  AVFrame *dst = td->dst;
200  const int height = src->height;
201  const int width = src->width*2;
202  const int src_pitch = src->linesize[0];
203  const int dst_pitch = dst->linesize[0];
204  const int slice_start = (height * jobnr ) / nb_jobs;
205  const int slice_end = (height * (jobnr+1)) / nb_jobs;
206  const unsigned char *srcp = src->data[0] + slice_start * src_pitch;
207  unsigned char *dstp = dst->data[0] + slice_start * dst_pitch;
208  const int c2 = td->c2;
209  const int c3 = td->c3;
210  const int c4 = td->c4;
211  const int c5 = td->c5;
212  const int c6 = td->c6;
213  const int c7 = td->c7;
214  int x, y;
215 
216  for (y = slice_start; y < slice_end; y++) {
217  for (x = 0; x < width; x += 4) {
218  const int u = srcp[x + 0] - 128;
219  const int v = srcp[x + 2] - 128;
220  const int uvval = c2 * u + c3 * v + 1081344;
221  dstp[x + 0] = CB((c4 * u + c5 * v + 8421376) >> 16);
222  dstp[x + 1] = CB((65536 * (srcp[x + 1] - 16) + uvval) >> 16);
223  dstp[x + 2] = CB((c6 * u + c7 * v + 8421376) >> 16);
224  dstp[x + 3] = CB((65536 * (srcp[x + 3] - 16) + uvval) >> 16);
225  }
226  srcp += src_pitch;
227  dstp += dst_pitch;
228  }
229 
230  return 0;
231 }
232 
233 static int process_slice_yuv422p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
234 {
235  const ThreadData *td = arg;
236  const AVFrame *src = td->src;
237  AVFrame *dst = td->dst;
238  const int height = src->height;
239  const int width = src->width;
240  const int slice_start = (height * jobnr ) / nb_jobs;
241  const int slice_end = (height * (jobnr+1)) / nb_jobs;
242  const int src_pitchY = src->linesize[0];
243  const int src_pitchUV = src->linesize[1];
244  const unsigned char *srcpU = src->data[1] + slice_start * src_pitchUV;
245  const unsigned char *srcpV = src->data[2] + slice_start * src_pitchUV;
246  const unsigned char *srcpY = src->data[0] + slice_start * src_pitchY;
247  const int dst_pitchY = dst->linesize[0];
248  const int dst_pitchUV = dst->linesize[1];
249  unsigned char *dstpU = dst->data[1] + slice_start * dst_pitchUV;
250  unsigned char *dstpV = dst->data[2] + slice_start * dst_pitchUV;
251  unsigned char *dstpY = dst->data[0] + slice_start * dst_pitchY;
252  const int c2 = td->c2;
253  const int c3 = td->c3;
254  const int c4 = td->c4;
255  const int c5 = td->c5;
256  const int c6 = td->c6;
257  const int c7 = td->c7;
258  int x, y;
259 
260  for (y = slice_start; y < slice_end; y++) {
261  for (x = 0; x < width; x += 2) {
262  const int u = srcpU[x >> 1] - 128;
263  const int v = srcpV[x >> 1] - 128;
264  const int uvval = c2 * u + c3 * v + 1081344;
265  dstpY[x + 0] = CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
266  dstpY[x + 1] = CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
267  dstpU[x >> 1] = CB((c4 * u + c5 * v + 8421376) >> 16);
268  dstpV[x >> 1] = CB((c6 * u + c7 * v + 8421376) >> 16);
269  }
270  srcpY += src_pitchY;
271  dstpY += dst_pitchY;
272  srcpU += src_pitchUV;
273  srcpV += src_pitchUV;
274  dstpU += dst_pitchUV;
275  dstpV += dst_pitchUV;
276  }
277 
278  return 0;
279 }
280 
281 static int process_slice_yuv420p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
282 {
283  const ThreadData *td = arg;
284  const AVFrame *src = td->src;
285  AVFrame *dst = td->dst;
286  const int height = FFALIGN(src->height, 2) >> 1;
287  const int width = src->width;
288  const int slice_start = ((height * jobnr ) / nb_jobs) << 1;
289  const int slice_end = ((height * (jobnr+1)) / nb_jobs) << 1;
290  const int src_pitchY = src->linesize[0];
291  const int src_pitchUV = src->linesize[1];
292  const int dst_pitchY = dst->linesize[0];
293  const int dst_pitchUV = dst->linesize[1];
294  const unsigned char *srcpY = src->data[0] + src_pitchY * slice_start;
295  const unsigned char *srcpU = src->data[1] + src_pitchUV * (slice_start >> 1);
296  const unsigned char *srcpV = src->data[2] + src_pitchUV * (slice_start >> 1);
297  const unsigned char *srcpN = src->data[0] + src_pitchY * (slice_start + 1);
298  unsigned char *dstpU = dst->data[1] + dst_pitchUV * (slice_start >> 1);
299  unsigned char *dstpV = dst->data[2] + dst_pitchUV * (slice_start >> 1);
300  unsigned char *dstpY = dst->data[0] + dst_pitchY * slice_start;
301  unsigned char *dstpN = dst->data[0] + dst_pitchY * (slice_start + 1);
302  const int c2 = td->c2;
303  const int c3 = td->c3;
304  const int c4 = td->c4;
305  const int c5 = td->c5;
306  const int c6 = td->c6;
307  const int c7 = td->c7;
308  int x, y;
309 
310  for (y = slice_start; y < slice_end; y += 2) {
311  for (x = 0; x < width; x += 2) {
312  const int u = srcpU[x >> 1] - 128;
313  const int v = srcpV[x >> 1] - 128;
314  const int uvval = c2 * u + c3 * v + 1081344;
315  dstpY[x + 0] = CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
316  dstpY[x + 1] = CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
317  dstpN[x + 0] = CB((65536 * (srcpN[x + 0] - 16) + uvval) >> 16);
318  dstpN[x + 1] = CB((65536 * (srcpN[x + 1] - 16) + uvval) >> 16);
319  dstpU[x >> 1] = CB((c4 * u + c5 * v + 8421376) >> 16);
320  dstpV[x >> 1] = CB((c6 * u + c7 * v + 8421376) >> 16);
321  }
322  srcpY += src_pitchY << 1;
323  dstpY += dst_pitchY << 1;
324  srcpN += src_pitchY << 1;
325  dstpN += dst_pitchY << 1;
326  srcpU += src_pitchUV;
327  srcpV += src_pitchUV;
328  dstpU += dst_pitchUV;
329  dstpV += dst_pitchUV;
330  }
331 
332  return 0;
333 }
334 
335 static int config_input(AVFilterLink *inlink)
336 {
337  AVFilterContext *ctx = inlink->dst;
338  ColorMatrixContext *color = ctx->priv;
339  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
340 
341  color->hsub = pix_desc->log2_chroma_w;
342  color->vsub = pix_desc->log2_chroma_h;
343 
344  av_log(ctx, AV_LOG_VERBOSE, "%s -> %s\n",
345  color_modes[color->source], color_modes[color->dest]);
346 
347  return 0;
348 }
349 
351 {
352  static const enum AVPixelFormat pix_fmts[] = {
357  };
358  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
359  if (!fmts_list)
360  return AVERROR(ENOMEM);
361  return ff_set_common_formats(ctx, fmts_list);
362 }
363 
364 static int filter_frame(AVFilterLink *link, AVFrame *in)
365 {
366  AVFilterContext *ctx = link->dst;
367  ColorMatrixContext *color = ctx->priv;
368  AVFilterLink *outlink = ctx->outputs[0];
369  AVFrame *out;
370  ThreadData td = {0};
371 
372  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
373  if (!out) {
374  av_frame_free(&in);
375  return AVERROR(ENOMEM);
376  }
377  av_frame_copy_props(out, in);
378 
379  if (color->source == COLOR_MODE_NONE) {
381  enum ColorMode source;
382 
383  switch(cs) {
384  case AVCOL_SPC_BT709 : source = COLOR_MODE_BT709 ; break;
385  case AVCOL_SPC_FCC : source = COLOR_MODE_FCC ; break;
386  case AVCOL_SPC_SMPTE240M : source = COLOR_MODE_SMPTE240M ; break;
387  case AVCOL_SPC_BT470BG : source = COLOR_MODE_BT601 ; break;
388  case AVCOL_SPC_SMPTE170M : source = COLOR_MODE_BT601 ; break;
389  default :
390  av_log(ctx, AV_LOG_ERROR, "Input frame does not specify a supported colorspace, and none has been specified as source either\n");
391  av_frame_free(&out);
392  return AVERROR(EINVAL);
393  }
394  color->mode = source * 4 + color->dest;
395  } else
396  color->mode = color->source * 4 + color->dest;
397 
398  switch(color->dest) {
403  }
404 
405  td.src = in;
406  td.dst = out;
407  td.c2 = color->yuv_convert[color->mode][0][1];
408  td.c3 = color->yuv_convert[color->mode][0][2];
409  td.c4 = color->yuv_convert[color->mode][1][1];
410  td.c5 = color->yuv_convert[color->mode][1][2];
411  td.c6 = color->yuv_convert[color->mode][2][1];
412  td.c7 = color->yuv_convert[color->mode][2][2];
413 
414  if (in->format == AV_PIX_FMT_YUV422P)
415  ctx->internal->execute(ctx, process_slice_yuv422p, &td, NULL,
416  FFMIN(in->height, ctx->graph->nb_threads));
417  else if (in->format == AV_PIX_FMT_YUV420P)
418  ctx->internal->execute(ctx, process_slice_yuv420p, &td, NULL,
419  FFMIN(in->height / 2, ctx->graph->nb_threads));
420  else
421  ctx->internal->execute(ctx, process_slice_uyvy422, &td, NULL,
422  FFMIN(in->height, ctx->graph->nb_threads));
423 
424  av_frame_free(&in);
425  return ff_filter_frame(outlink, out);
426 }
427 
428 static const AVFilterPad colormatrix_inputs[] = {
429  {
430  .name = "default",
431  .type = AVMEDIA_TYPE_VIDEO,
432  .config_props = config_input,
433  .filter_frame = filter_frame,
434  },
435  { NULL }
436 };
437 
439  {
440  .name = "default",
441  .type = AVMEDIA_TYPE_VIDEO,
442  },
443  { NULL }
444 };
445 
447  .name = "colormatrix",
448  .description = NULL_IF_CONFIG_SMALL("Convert color matrix."),
449  .priv_size = sizeof(ColorMatrixContext),
450  .init = init,
452  .inputs = colormatrix_inputs,
453  .outputs = colormatrix_outputs,
454  .priv_class = &colormatrix_class,
456 };
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:502
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:83
#define NULL
Definition: coverity.c:32
float v
static av_cold int init(AVFilterContext *ctx)
static const char *const color_modes[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
#define mi
#define mf
BYTE int const BYTE int src_pitch
Definition: avisynth_c.h:676
AVOption.
Definition: opt.h:255
static int filter_frame(AVFilterLink *link, AVFrame *in)
const AVFrame * src
static const double yuv_coeff[4][3][3]
static void solve_coefficients(double cm[3][3], double rgb[3][3], const double yuv[3][3])
#define ma
int yuv_convert[16][3][3]
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:506
#define ima
#define me
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above ...
Definition: pixfmt.h:507
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
static int query_formats(AVFilterContext *ctx)
#define FFALIGN(x, a)
Definition: common.h:71
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:656
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:451
#define img
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
const char * name
Pad name.
Definition: internal.h:67
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
#define av_cold
Definition: attributes.h:74
#define mb
AVOptions.
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:500
#define NS(n)
static const AVFilterPad colormatrix_inputs[]
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:1203
#define imi
#define imd
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
static int config_input(AVFilterLink *inlink)
#define av_log(a,...)
#define cm
Definition: dvbsubdec.c:36
unsigned m
Definition: audioconvert.c:187
#define FLAGS
A filter pad used for either input or output.
Definition: internal.h:61
static int process_slice_yuv422p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int width
width and height of the video frame
Definition: frame.h:220
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:542
#define td
Definition: regdef.h:70
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
BYTE * dstp
Definition: avisynth_c.h:676
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
static int process_slice_uyvy422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:442
const char * arg
Definition: jacosubdec.c:66
AVFILTER_DEFINE_CLASS(colormatrix)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
static void inverse3x3(double im[3][3], const double m[3][3])
#define imh
#define FFMIN(a, b)
Definition: common.h:66
#define md
float y
ColorMode
#define ime
#define CB(n)
float u
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:505
static void calc_coefficients(AVFilterContext *ctx)
#define mc
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
AVFrame * dst
Definition: vf_blend.c:85
AVS_Value src
Definition: avisynth_c.h:482
float im
Definition: fft-test.c:73
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame)
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
const char * name
Filter name.
Definition: avfilter.h:474
#define imc
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:679
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
static const uint64_t c2
Definition: murmur3.c:50
avfilter_execute_func * execute
Definition: internal.h:162
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2073
#define imb
#define mg
A list of supported formats for one end of a filter link.
Definition: formats.h:64
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
An instance of a filter.
Definition: avfilter.h:633
static int process_slice_yuv420p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int height
Definition: frame.h:220
static const AVFilterPad colormatrix_outputs[]
AVFilter ff_vf_colormatrix
BYTE int dst_pitch
Definition: avisynth_c.h:676
internal API functions
int dest
ColorMode.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
static const AVOption colormatrix_options[]
#define imf
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548
#define mh
#define OFFSET(x)
static int width