53#define OFFSET(x) offsetof(GradientsContext, x)
54#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
55#define VFT AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
84 {
"circular",
"set circular gradient", 0,
AV_OPT_TYPE_CONST, {.i64=2}, 0, 0,
VFT, .unit =
"type" },
92static float lerpf(
float a,
float b,
float x)
94 const float y = 1.f - x;
101 const float y = 1.f - x;
103 return (
lrintf(c0[0] * y +
c1[0] * x)) << 0 |
104 (
lrintf(c0[1] * y +
c1[1] * x)) << 8 |
105 (
lrintf(c0[2] * y +
c1[2] * x)) << 16 |
106 (
lrintf(c0[3] * y +
c1[3] * x)) << 24;
111 const float y = 1.f - x;
113 return ((uint64_t)
llrintf((c0[0] * y +
c1[0] * x) * 256)) << 0 |
114 ((uint64_t)
llrintf((c0[1] * y +
c1[1] * x) * 256)) << 16 |
115 ((uint64_t)
llrintf((c0[2] * y +
c1[2] * x) * 256)) << 32 |
116 ((uint64_t)
llrintf((c0[3] * y +
c1[3] * x) * 256)) << 48;
119static uint32_t
lerp_colors(uint8_t arr[8][4],
int nb_colors,
int nb_wrap_colors,
float step)
124 if (nb_colors == 1 || step <= 0.0) {
125 return arr[0][0] | (arr[0][1] << 8) | (arr[0][2] << 16) | (arr[0][3] << 24);
126 }
else if (step >= 1.0) {
128 return arr[
i][0] | (arr[
i][1] << 8) | (arr[
i][2] << 16) | (arr[
i][3] << 24);
131 scl = step * (nb_wrap_colors - 1);
134 if (
i >= nb_colors - 1) {
142static uint64_t
lerp_colors16(uint8_t arr[8][4],
int nb_colors,
int nb_wrap_colors,
float step)
147 if (nb_colors == 1 || step <= 0.0) {
148 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);
149 }
else if (step >= 1.0) {
151 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);
154 scl = step * (nb_wrap_colors - 1);
157 if (
i >= nb_colors - 1) {
166 int nb_wrap_colors,
float step,
167 float *
r,
float *
g,
float *
b,
float *
a)
172 if (nb_colors == 1 || step <= 0.0) {
178 }
else if (step >= 1.0) {
187 scl = step * (nb_wrap_colors - 1);
190 if (
i >= nb_colors - 1) {
196 *
r =
lerpf(arr[
i][0], arr[j][0], x);
197 *
g =
lerpf(arr[
i][1], arr[j][1], x);
198 *
b =
lerpf(arr[
i][2], arr[j][2], x);
199 *
a =
lerpf(arr[
i][3], arr[j][3], x);
202static float project(
float origin_x,
float origin_y,
203 float dest_x,
float dest_y,
204 float point_x,
float point_y,
int type)
206 float op_x = point_x - origin_x;
207 float op_y = point_y - origin_y;
208 float od_x = dest_x - origin_x;
209 float od_y = dest_y - origin_y;
215 od_s_q = od_x * od_x + od_y * od_y;
218 od_s_q =
sqrtf(od_x * od_x + od_y * od_y);
231 op_x_od = op_x * od_x + op_y * od_y;
234 op_x_od =
sqrtf(op_x * op_x + op_y * op_y);
240 op_x_od = fmodf(
atan2f(op_x, op_y) +
M_PI + point_x /
fmaxf(origin_x, dest_x), 2.f *
M_PI);
248 return av_clipf(op_x_od / od_s_q, 0.f, 1.f);
257 const int start = (
height * job ) / nb_jobs;
258 const int end = (
height * (job+1)) / nb_jobs;
259 const ptrdiff_t linesize =
frame->linesize[0] / 4;
260 uint32_t *
dst = (uint32_t *)
frame->data[0] + start * linesize;
261 const int type =
s->type;
263 for (
int y = start; y < end; y++) {
264 for (
int x = 0; x <
width; x++) {
281 const int start = (
height * job ) / nb_jobs;
282 const int end = (
height * (job+1)) / nb_jobs;
283 const ptrdiff_t linesize =
frame->linesize[0] / 8;
284 uint64_t *
dst = (uint64_t *)
frame->data[0] + start * linesize;
285 const int type =
s->type;
287 for (
int y = start; y < end; y++) {
288 for (
int x = 0; x <
width; x++) {
305 const int start = (
height * job ) / nb_jobs;
306 const int end = (
height * (job+1)) / nb_jobs;
307 const ptrdiff_t linesize_g =
frame->linesize[0] / 4;
308 const ptrdiff_t linesize_b =
frame->linesize[1] / 4;
309 const ptrdiff_t linesize_r =
frame->linesize[2] / 4;
310 const ptrdiff_t linesize_a =
frame->linesize[3] / 4;
311 float *dst_g = (
float *)
frame->data[0] + start * linesize_g;
312 float *dst_b = (
float *)
frame->data[1] + start * linesize_b;
313 float *dst_r = (
float *)
frame->data[2] + start * linesize_r;
314 float *dst_a = (
float *)
frame->data[3] + start * linesize_a;
315 const int type =
s->type;
317 for (
int y = start; y < end; y++) {
318 for (
int x = 0; x <
width; x++) {
321 &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
352 switch (
desc->comp[0].depth) {
366 if (
s->x0 < 0 ||
s->x0 >=
s->w)
368 if (
s->y0 < 0 ||
s->y0 >=
s->h)
370 if (
s->x1 < 0 ||
s->x1 >=
s->w)
372 if (
s->y1 < 0 ||
s->y1 >=
s->h)
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;
388 if (
s->duration >= 0 &&
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;
400 s->angle = angle +
s->speed;
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;
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;
436 .p.name =
"gradients",
438 .p.priv_class = &gradients_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFFilter ff_vsrc_gradients
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
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.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
static __device__ float sqrtf(float a)
static __device__ float fabsf(float a)
static __device__ float floorf(float a)
float fmaxf(float, float)
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_EOF
End of file.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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...
@ AV_PICTURE_TYPE_I
Intra.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS(...)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
static const int factor[16]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_RGBA64
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_PIX_FMT_GBRAPF32
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Context structure for the Lagged Fibonacci PRNG.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
int64_t duration
duration expressed in microseconds
int(* draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static float lerpf(float a, float b, float x)
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)
static float project(float origin_x, float origin_y, float dest_x, float dest_y, float point_x, float point_y, int type)
static uint32_t lerp_colors(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
static uint64_t lerp_colors16(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static uint32_t lerp_color(uint8_t c0[4], uint8_t c1[4], float x)
static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static int activate(AVFilterContext *ctx)
static uint64_t lerp_color16(uint8_t c0[4], uint8_t c1[4], float x)
static const AVOption gradients_options[]
static int config_output(AVFilterLink *outlink)
static const AVFilterPad gradients_outputs[]