FFmpeg
vsrc_gradients.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Paul B Mahol
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 "avfilter.h"
22 #include "filters.h"
23 #include "video.h"
24 #include "internal.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/lfg.h"
28 #include "libavutil/random_seed.h"
29 #include <float.h>
30 #include <math.h>
31 
32 typedef struct GradientsContext {
33  const AVClass *class;
34  int w, h;
35  int type;
37  int64_t pts;
38  int64_t duration; ///< duration expressed in microseconds
39  float speed;
40  float angle;
41 
42  uint8_t color_rgba[8][4];
43  float color_rgbaf[8][4];
44  int nb_colors;
45  int x0, y0, x1, y1;
46  float fx0, fy0, fx1, fy1;
47 
48  int64_t seed;
49 
51  int (*draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs);
53 
54 #define OFFSET(x) offsetof(GradientsContext, x)
55 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
56 #define VFT AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
57 
58 static const AVOption gradients_options[] = {
59  {"size", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="640x480"}, 0, 0, FLAGS },
60  {"s", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="640x480"}, 0, 0, FLAGS },
61  {"rate", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
62  {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
63  {"c0", "set 1st color", OFFSET(color_rgba[0]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
64  {"c1", "set 2nd color", OFFSET(color_rgba[1]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
65  {"c2", "set 3rd color", OFFSET(color_rgba[2]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
66  {"c3", "set 4th color", OFFSET(color_rgba[3]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
67  {"c4", "set 5th color", OFFSET(color_rgba[4]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
68  {"c5", "set 6th color", OFFSET(color_rgba[5]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
69  {"c6", "set 7th color", OFFSET(color_rgba[6]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
70  {"c7", "set 8th color", OFFSET(color_rgba[7]), AV_OPT_TYPE_COLOR, {.str = "random"}, 0, 0, FLAGS },
71  {"x0", "set gradient line source x0", OFFSET(x0), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS },
72  {"y0", "set gradient line source y0", OFFSET(y0), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS },
73  {"x1", "set gradient line destination x1", OFFSET(x1), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS },
74  {"y1", "set gradient line destination y1", OFFSET(y1), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS },
75  {"nb_colors", "set the number of colors", OFFSET(nb_colors), AV_OPT_TYPE_INT, {.i64=2}, 2, 8, FLAGS },
76  {"n", "set the number of colors", OFFSET(nb_colors), AV_OPT_TYPE_INT, {.i64=2}, 2, 8, FLAGS },
77  {"seed", "set the seed", OFFSET(seed), AV_OPT_TYPE_INT64, {.i64=-1}, -1, UINT32_MAX, FLAGS },
78  {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
79  {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
80  {"speed", "set gradients rotation speed", OFFSET(speed), AV_OPT_TYPE_FLOAT,{.dbl=0.01}, 0, 1, VFT },
81  {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, VFT, .unit = "type" },
82  {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, VFT, .unit = "type" },
83  { "linear", "set linear gradient", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, VFT, .unit = "type" },
84  { "radial", "set radial gradient", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, VFT, .unit = "type" },
85  { "circular", "set circular gradient", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, VFT, .unit = "type" },
86  { "spiral", "set spiral gradient", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, VFT, .unit = "type" },
87  { "square", "set square gradient", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, VFT, .unit = "type" },
88  {NULL},
89 };
90 
91 AVFILTER_DEFINE_CLASS(gradients);
92 
93 static float lerpf(float a, float b, float x)
94 {
95  const float y = 1.f - x;
96 
97  return a * y + b * x;
98 }
99 
100 static uint32_t lerp_color(uint8_t c0[4], uint8_t c1[4], float x)
101 {
102  const float y = 1.f - x;
103 
104  return (lrintf(c0[0] * y + c1[0] * x)) << 0 |
105  (lrintf(c0[1] * y + c1[1] * x)) << 8 |
106  (lrintf(c0[2] * y + c1[2] * x)) << 16 |
107  (lrintf(c0[3] * y + c1[3] * x)) << 24;
108 }
109 
110 static uint64_t lerp_color16(uint8_t c0[4], uint8_t c1[4], float x)
111 {
112  const float y = 1.f - x;
113 
114  return ((uint64_t)llrintf((c0[0] * y + c1[0] * x) * 256)) << 0 |
115  ((uint64_t)llrintf((c0[1] * y + c1[1] * x) * 256)) << 16 |
116  ((uint64_t)llrintf((c0[2] * y + c1[2] * x) * 256)) << 32 |
117  ((uint64_t)llrintf((c0[3] * y + c1[3] * x) * 256)) << 48;
118 }
119 
120 static uint32_t lerp_colors(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
121 {
122  float scl;
123  int i, j;
124 
125  if (nb_colors == 1 || step <= 0.0) {
126  return arr[0][0] | (arr[0][1] << 8) | (arr[0][2] << 16) | (arr[0][3] << 24);
127  } else if (step >= 1.0) {
128  i = nb_colors - 1;
129  return arr[i][0] | (arr[i][1] << 8) | (arr[i][2] << 16) | (arr[i][3] << 24);
130  }
131 
132  scl = step * (nb_wrap_colors - 1);
133  i = floorf(scl);
134  j = i + 1;
135  if (i >= nb_colors - 1) {
136  i = nb_colors - 1;
137  j = 0;
138  }
139 
140  return lerp_color(arr[i], arr[j], scl - i);
141 }
142 
143 static uint64_t lerp_colors16(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
144 {
145  float scl;
146  int i, j;
147 
148  if (nb_colors == 1 || step <= 0.0) {
149  return ((uint64_t)arr[0][0] << 8) | ((uint64_t)arr[0][1] << 24) | ((uint64_t)arr[0][2] << 40) | ((uint64_t)arr[0][3] << 56);
150  } else if (step >= 1.0) {
151  i = nb_colors - 1;
152  return ((uint64_t)arr[i][0] << 8) | ((uint64_t)arr[i][1] << 24) | ((uint64_t)arr[i][2] << 40) | ((uint64_t)arr[i][3] << 56);
153  }
154 
155  scl = step * (nb_wrap_colors - 1);
156  i = floorf(scl);
157  j = i + 1;
158  if (i >= nb_colors - 1) {
159  i = nb_colors - 1;
160  j = 0;
161  }
162 
163  return lerp_color16(arr[i], arr[j], scl - i);
164 }
165 
166 static void lerp_colors32(float arr[8][4], int nb_colors,
167  int nb_wrap_colors, float step,
168  float *r, float *g, float *b, float *a)
169 {
170  float scl, x;
171  int i, j;
172 
173  if (nb_colors == 1 || step <= 0.0) {
174  *r = arr[0][0];
175  *g = arr[0][1];
176  *b = arr[0][2];
177  *a = arr[0][3];
178  return;
179  } else if (step >= 1.0) {
180  i = nb_colors - 1;
181  *r = arr[i][0];
182  *g = arr[i][1];
183  *b = arr[i][2];
184  *a = arr[i][3];
185  return;
186  }
187 
188  scl = step * (nb_wrap_colors - 1);
189  i = floorf(scl);
190  j = i + 1;
191  if (i >= nb_colors - 1) {
192  i = nb_colors - 1;
193  j = 0;
194  }
195  x = scl - i;
196 
197  *r = lerpf(arr[i][0], arr[j][0], x);
198  *g = lerpf(arr[i][1], arr[j][1], x);
199  *b = lerpf(arr[i][2], arr[j][2], x);
200  *a = lerpf(arr[i][3], arr[j][3], x);
201 }
202 
203 static float project(float origin_x, float origin_y,
204  float dest_x, float dest_y,
205  float point_x, float point_y, int type)
206 {
207  float op_x = point_x - origin_x;
208  float op_y = point_y - origin_y;
209  float od_x = dest_x - origin_x;
210  float od_y = dest_y - origin_y;
211  float op_x_od;
212  float od_s_q;
213 
214  switch (type) {
215  case 0:
216  od_s_q = od_x * od_x + od_y * od_y;
217  break;
218  case 1:
219  od_s_q = sqrtf(od_x * od_x + od_y * od_y);
220  break;
221  case 2:
222  case 3:
223  od_s_q = M_PI * 2.f;
224  break;
225  case 4:
226  od_s_q = fmaxf(fabsf(od_x), fabsf(od_y));
227  break;
228  }
229 
230  switch (type) {
231  case 0:
232  op_x_od = op_x * od_x + op_y * od_y;
233  break;
234  case 1:
235  op_x_od = sqrtf(op_x * op_x + op_y * op_y);
236  break;
237  case 2:
238  op_x_od = atan2f(op_x, op_y) + M_PI;
239  break;
240  case 3:
241  op_x_od = fmodf(atan2f(op_x, op_y) + M_PI + point_x / fmaxf(origin_x, dest_x), 2.f * M_PI);
242  break;
243  case 4:
244  op_x_od = fmaxf(fabsf(op_x), fabsf(op_y));
245  break;
246  }
247 
248  // Normalize and clamp range.
249  return av_clipf(op_x_od / od_s_q, 0.f, 1.f);
250 }
251 
252 static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
253 {
254  GradientsContext *s = ctx->priv;
255  AVFrame *frame = arg;
256  const int width = frame->width;
257  const int height = frame->height;
258  const int start = (height * job ) / nb_jobs;
259  const int end = (height * (job+1)) / nb_jobs;
260  const ptrdiff_t linesize = frame->linesize[0] / 4;
261  uint32_t *dst = (uint32_t *)frame->data[0] + start * linesize;
262  const int type = s->type;
263 
264  for (int y = start; y < end; y++) {
265  for (int x = 0; x < width; x++) {
266  float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
267  dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor);
268  }
269 
270  dst += linesize;
271  }
272 
273  return 0;
274 }
275 
276 static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
277 {
278  GradientsContext *s = ctx->priv;
279  AVFrame *frame = arg;
280  const int width = frame->width;
281  const int height = frame->height;
282  const int start = (height * job ) / nb_jobs;
283  const int end = (height * (job+1)) / nb_jobs;
284  const ptrdiff_t linesize = frame->linesize[0] / 8;
285  uint64_t *dst = (uint64_t *)frame->data[0] + start * linesize;
286  const int type = s->type;
287 
288  for (int y = start; y < end; y++) {
289  for (int x = 0; x < width; x++) {
290  float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
291  dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor);
292  }
293 
294  dst += linesize;
295  }
296 
297  return 0;
298 }
299 
300 static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
301 {
302  GradientsContext *s = ctx->priv;
303  AVFrame *frame = arg;
304  const int width = frame->width;
305  const int height = frame->height;
306  const int start = (height * job ) / nb_jobs;
307  const int end = (height * (job+1)) / nb_jobs;
308  const ptrdiff_t linesize_g = frame->linesize[0] / 4;
309  const ptrdiff_t linesize_b = frame->linesize[1] / 4;
310  const ptrdiff_t linesize_r = frame->linesize[2] / 4;
311  const ptrdiff_t linesize_a = frame->linesize[3] / 4;
312  float *dst_g = (float *)frame->data[0] + start * linesize_g;
313  float *dst_b = (float *)frame->data[1] + start * linesize_b;
314  float *dst_r = (float *)frame->data[2] + start * linesize_r;
315  float *dst_a = (float *)frame->data[3] + start * linesize_a;
316  const int type = s->type;
317 
318  for (int y = start; y < end; y++) {
319  for (int x = 0; x < width; x++) {
320  float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
321  lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor,
322  &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
323  }
324 
325  dst_g += linesize_g;
326  dst_b += linesize_b;
327  dst_r += linesize_r;
328  dst_a += linesize_a;
329  }
330 
331  return 0;
332 }
333 
334 static int config_output(AVFilterLink *outlink)
335 {
336  AVFilterContext *ctx = outlink->src;
337  GradientsContext *s = ctx->priv;
339 
340  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
341  return AVERROR(EINVAL);
342 
343  outlink->w = s->w;
344  outlink->h = s->h;
345  outlink->time_base = av_inv_q(s->frame_rate);
346  outlink->sample_aspect_ratio = (AVRational) {1, 1};
347  outlink->frame_rate = s->frame_rate;
348  if (s->seed == -1)
349  s->seed = av_get_random_seed();
350  av_lfg_init(&s->lfg, s->seed);
351 
352  switch (desc->comp[0].depth) {
353  case 8:
354  s->draw_slice = draw_gradients_slice;
355  break;
356  case 16:
357  s->draw_slice = draw_gradients_slice16;
358  break;
359  case 32:
360  s->draw_slice = draw_gradients_slice32_planar;
361  break;
362  default:
363  return AVERROR_BUG;
364  }
365 
366  if (s->x0 < 0 || s->x0 >= s->w)
367  s->x0 = av_lfg_get(&s->lfg) % s->w;
368  if (s->y0 < 0 || s->y0 >= s->h)
369  s->y0 = av_lfg_get(&s->lfg) % s->h;
370  if (s->x1 < 0 || s->x1 >= s->w)
371  s->x1 = av_lfg_get(&s->lfg) % s->w;
372  if (s->y1 < 0 || s->y1 >= s->h)
373  s->y1 = av_lfg_get(&s->lfg) % s->h;
374 
375  for (int n = 0; n < 8; n++) {
376  for (int c = 0; c < 4; c++)
377  s->color_rgbaf[n][c] = s->color_rgba[n][c] / 255.f;
378  }
379 
380  return 0;
381 }
382 
384 {
385  GradientsContext *s = ctx->priv;
386  AVFilterLink *outlink = ctx->outputs[0];
387 
388  if (s->duration >= 0 &&
389  av_rescale_q(s->pts, outlink->time_base, AV_TIME_BASE_Q) >= s->duration) {
390  ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
391  return 0;
392  }
393 
394  if (ff_outlink_frame_wanted(outlink)) {
395  AVFrame *frame = ff_get_video_buffer(outlink, s->w, s->h);
396  float angle = fmodf(s->angle, 2.f * M_PI);
397  const float w2 = s->w / 2.f;
398  const float h2 = s->h / 2.f;
399 
400  s->angle = angle + s->speed;
401 
402  s->fx0 = (s->x0 - w2) * cosf(angle) - (s->y0 - h2) * sinf(angle) + w2;
403  s->fy0 = (s->x0 - w2) * sinf(angle) + (s->y0 - h2) * cosf(angle) + h2;
404 
405  s->fx1 = (s->x1 - w2) * cosf(angle) - (s->y1 - h2) * sinf(angle) + w2;
406  s->fy1 = (s->x1 - w2) * sinf(angle) + (s->y1 - h2) * cosf(angle) + h2;
407 
408  if (!frame)
409  return AVERROR(ENOMEM);
410 
411 #if FF_API_FRAME_KEY
413  frame->key_frame = 1;
415 #endif
416 
418 #if FF_API_INTERLACED_FRAME
420  frame->interlaced_frame = 0;
422 #endif
426  frame->pts = s->pts++;
427  frame->duration = 1;
428 
429  ff_filter_execute(ctx, s->draw_slice, frame, NULL,
430  FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
431 
432  return ff_filter_frame(outlink, frame);
433  }
434 
435  return FFERROR_NOT_READY;
436 }
437 
438 static const AVFilterPad gradients_outputs[] = {
439  {
440  .name = "default",
441  .type = AVMEDIA_TYPE_VIDEO,
442  .config_props = config_output,
443  },
444 };
445 
447  .name = "gradients",
448  .description = NULL_IF_CONFIG_SMALL("Draw a gradients."),
449  .priv_size = sizeof(GradientsContext),
450  .priv_class = &gradients_class,
451  .inputs = NULL,
454  .activate = activate,
456  .process_command = ff_filter_process_command,
457 };
GradientsContext::nb_colors
int nb_colors
Definition: vsrc_gradients.c:44
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:112
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
draw_gradients_slice32_planar
static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vsrc_gradients.c:300
r
const char * r
Definition: vf_curves.c:126
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
GradientsContext::pts
int64_t pts
Definition: vsrc_gradients.c:37
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1007
ff_vsrc_gradients
const AVFilter ff_vsrc_gradients
Definition: vsrc_gradients.c:446
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:807
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2968
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:238
floorf
static __device__ float floorf(float a)
Definition: cuda_runtime.h:172
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
atan2f
#define atan2f(y, x)
Definition: libm.h:45
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
lerp_colors
static uint32_t lerp_colors(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
Definition: vsrc_gradients.c:120
AVFrame::width
int width
Definition: frame.h:412
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:294
b
#define b
Definition: input.c:41
GradientsContext::lfg
AVLFG lfg
Definition: vsrc_gradients.c:50
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:239
float.h
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:649
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
c1
static const uint64_t c1
Definition: murmur3.c:52
video.h
lerp_colors16
static uint64_t lerp_colors16(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
Definition: vsrc_gradients.c:143
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:167
cosf
#define cosf(x)
Definition: libm.h:78
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
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
AVFrame::interlaced_frame
attribute_deprecated int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:530
GradientsContext::y0
int y0
Definition: vsrc_gradients.c:45
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:628
duration
int64_t duration
Definition: movenc.c:64
GradientsContext::fy0
float fy0
Definition: vsrc_gradients.c:46
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
width
#define width
llrintf
#define llrintf(x)
Definition: libm.h:399
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
g
const char * g
Definition: vf_curves.c:127
lfg.h
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:226
filters.h
gradients_options
static const AVOption gradients_options[]
Definition: vsrc_gradients.c:58
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVFrame::key_frame
attribute_deprecated int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:436
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
frame
static AVFrame * frame
Definition: demux_decode.c:54
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:472
GradientsContext::seed
int64_t seed
Definition: vsrc_gradients.c:48
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
OFFSET
#define OFFSET(x)
Definition: vsrc_gradients.c:54
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
gradients_outputs
static const AVFilterPad gradients_outputs[]
Definition: vsrc_gradients.c:438
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:240
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
GradientsContext::duration
int64_t duration
duration expressed in microseconds
Definition: vsrc_gradients.c:38
GradientsContext::y1
int y1
Definition: vsrc_gradients.c:45
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
sinf
#define sinf(x)
Definition: libm.h:419
av_clipf
av_clipf
Definition: af_crystalizer.c:121
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
seed
static unsigned int seed
Definition: videogen.c:78
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
GradientsContext::fx0
float fx0
Definition: vsrc_gradients.c:46
GradientsContext::w
int w
Definition: vsrc_gradients.c:34
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
f
f
Definition: af_crystalizer.c:121
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:442
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
FLAGS
#define FLAGS
Definition: vsrc_gradients.c:55
GradientsContext::h
int h
Definition: vsrc_gradients.c:34
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: internal.h:168
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
GradientsContext::x0
int x0
Definition: vsrc_gradients.c:45
fmaxf
float fmaxf(float, float)
GradientsContext::speed
float speed
Definition: vsrc_gradients.c:39
GradientsContext::x1
int x1
Definition: vsrc_gradients.c:45
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:879
height
#define height
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
draw_gradients_slice
static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vsrc_gradients.c:252
GradientsContext::fx1
float fx1
Definition: vsrc_gradients.c:46
lerpf
static float lerpf(float a, float b, float x)
Definition: vsrc_gradients.c:93
M_PI
#define M_PI
Definition: mathematics.h:67
GradientsContext::color_rgbaf
float color_rgbaf[8][4]
Definition: vsrc_gradients.c:43
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
VFT
#define VFT
Definition: vsrc_gradients.c:56
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
GradientsContext
Definition: vsrc_gradients.c:32
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:814
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:636
AVFilter
Filter definition.
Definition: avfilter.h:166
GradientsContext::fy1
float fy1
Definition: vsrc_gradients.c:46
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(gradients)
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:447
AVFrame::height
int height
Definition: frame.h:412
random_seed.h
GradientsContext::type
int type
Definition: vsrc_gradients.c:35
lerp_color16
static uint64_t lerp_color16(uint8_t c0[4], uint8_t c1[4], float x)
Definition: vsrc_gradients.c:110
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:513
lerp_colors32
static void lerp_colors32(float arr[8][4], int nb_colors, int nb_wrap_colors, float step, float *r, float *g, float *b, float *a)
Definition: vsrc_gradients.c:166
AVFilterContext
An instance of a filter.
Definition: avfilter.h:409
factor
static const int factor[16]
Definition: vf_pp7.c:78
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
GradientsContext::draw_slice
int(* draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vsrc_gradients.c:51
GradientsContext::color_rgba
uint8_t color_rgba[8][4]
Definition: vsrc_gradients.c:42
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
project
static float project(float origin_x, float origin_y, float dest_x, float dest_y, float point_x, float point_y, int type)
Definition: vsrc_gradients.c:203
activate
static int activate(AVFilterContext *ctx)
Definition: vsrc_gradients.c:383
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
GradientsContext::frame_rate
AVRational frame_rate
Definition: vsrc_gradients.c:36
config_output
static int config_output(AVFilterLink *outlink)
Definition: vsrc_gradients.c:334
GradientsContext::angle
float angle
Definition: vsrc_gradients.c:40
imgutils.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrame::linesize
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:385
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:134
int
int
Definition: ffmpeg_filter.c:424
lerp_color
static uint32_t lerp_color(uint8_t c0[4], uint8_t c1[4], float x)
Definition: vsrc_gradients.c:100
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
draw_gradients_slice16
static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vsrc_gradients.c:276