Go to the documentation of this file.
53 #define OFFSET(x) offsetof(GradientsContext, x)
54 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
90 static float lerpf(
float a,
float b,
float x)
92 const float y = 1.f - x;
99 const float y = 1.f - x;
101 return (
lrintf(c0[0] * y +
c1[0] * x)) << 0 |
102 (
lrintf(c0[1] * y +
c1[1] * x)) << 8 |
103 (
lrintf(c0[2] * y +
c1[2] * x)) << 16 |
104 (
lrintf(c0[3] * y +
c1[3] * x)) << 24;
109 const float y = 1.f - x;
111 return ((uint64_t)
llrintf((c0[0] * y +
c1[0] * x) * 256)) << 0 |
112 ((uint64_t)
llrintf((c0[1] * y +
c1[1] * x) * 256)) << 16 |
113 ((uint64_t)
llrintf((c0[2] * y +
c1[2] * x) * 256)) << 32 |
114 ((uint64_t)
llrintf((c0[3] * y +
c1[3] * x) * 256)) << 48;
117 static uint32_t
lerp_colors(uint8_t arr[8][4],
int nb_colors,
int nb_wrap_colors,
float step)
122 if (nb_colors == 1 ||
step <= 0.0) {
123 return arr[0][0] | (arr[0][1] << 8) | (arr[0][2] << 16) | (arr[0][3] << 24);
124 }
else if (
step >= 1.0) {
126 return arr[
i][0] | (arr[
i][1] << 8) | (arr[
i][2] << 16) | (arr[
i][3] << 24);
129 scl =
step * (nb_wrap_colors - 1);
132 if (
i >= nb_colors - 1) {
145 if (nb_colors == 1 ||
step <= 0.0) {
146 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);
147 }
else if (
step >= 1.0) {
149 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);
152 scl =
step * (nb_wrap_colors - 1);
155 if (
i >= nb_colors - 1) {
164 int nb_wrap_colors,
float step,
165 float *
r,
float *
g,
float *
b,
float *
a)
170 if (nb_colors == 1 ||
step <= 0.0) {
176 }
else if (
step >= 1.0) {
185 scl =
step * (nb_wrap_colors - 1);
188 if (
i >= nb_colors - 1) {
194 *
r =
lerpf(arr[
i][0], arr[j][0], x);
195 *
g =
lerpf(arr[
i][1], arr[j][1], x);
196 *
b =
lerpf(arr[
i][2], arr[j][2], x);
197 *
a =
lerpf(arr[
i][3], arr[j][3], x);
200 static float project(
float origin_x,
float origin_y,
201 float dest_x,
float dest_y,
202 float point_x,
float point_y,
int type)
204 float op_x = point_x - origin_x;
205 float op_y = point_y - origin_y;
206 float od_x = dest_x - origin_x;
207 float od_y = dest_y - origin_y;
213 od_s_q = od_x * od_x + od_y * od_y;
216 od_s_q =
sqrtf(od_x * od_x + od_y * od_y);
226 op_x_od = op_x * od_x + op_y * od_y;
229 op_x_od =
sqrtf(op_x * op_x + op_y * op_y);
249 const int start = (
height * job ) / nb_jobs;
250 const int end = (
height * (job+1)) / nb_jobs;
252 uint32_t *dst = (uint32_t *)
frame->
data[0] + start * linesize;
253 const int type =
s->type;
255 for (
int y = start; y < end; y++) {
256 for (
int x = 0; x <
width; x++) {
273 const int start = (
height * job ) / nb_jobs;
274 const int end = (
height * (job+1)) / nb_jobs;
276 uint64_t *dst = (uint64_t *)
frame->
data[0] + start * linesize;
277 const int type =
s->type;
279 for (
int y = start; y < end; y++) {
280 for (
int x = 0; x <
width; x++) {
297 const int start = (
height * job ) / nb_jobs;
298 const int end = (
height * (job+1)) / nb_jobs;
303 float *dst_g = (
float *)
frame->
data[0] + start * linesize_g;
304 float *dst_b = (
float *)
frame->
data[1] + start * linesize_b;
305 float *dst_r = (
float *)
frame->
data[2] + start * linesize_r;
306 float *dst_a = (
float *)
frame->
data[3] + start * linesize_a;
307 const int type =
s->type;
309 for (
int y = start; y < end; y++) {
310 for (
int x = 0; x <
width; x++) {
313 &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
343 switch (
desc->comp[0].depth) {
357 if (
s->x0 < 0 ||
s->x0 >=
s->w)
359 if (
s->y0 < 0 ||
s->y0 >=
s->h)
361 if (
s->x1 < 0 ||
s->x1 >=
s->w)
363 if (
s->y1 < 0 ||
s->y1 >=
s->h)
366 for (
int n = 0; n < 8; n++) {
367 for (
int c = 0;
c < 4;
c++)
368 s->color_rgbaf[n][
c] =
s->color_rgba[n][
c] / 255.f;
379 if (
s->duration >= 0 &&
387 float angle = fmodf(
s->pts *
s->speed, 2.f *
M_PI);
388 const float w2 =
s->w / 2.f;
389 const float h2 =
s->h / 2.f;
391 s->fx0 = (
s->x0 - w2) *
cosf(angle) - (
s->y0 - h2) *
sinf(angle) + w2;
392 s->fy0 = (
s->x0 - w2) *
sinf(angle) + (
s->y0 - h2) *
cosf(angle) + h2;
394 s->fx1 = (
s->x1 - w2) *
cosf(angle) - (
s->y1 - h2) *
sinf(angle) + w2;
395 s->fy1 = (
s->x1 - w2) *
sinf(angle) + (
s->y1 - h2) *
cosf(angle) + h2;
407 #if FF_API_INTERLACED_FRAME
439 .priv_class = &gradients_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define FF_ENABLE_DEPRECATION_WARNINGS
static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
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
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVFilter ff_vsrc_gradients
int64_t duration
Duration of the frame, in the same units as pts.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
static __device__ float floorf(float a)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
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
static uint32_t lerp_colors(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
const char * name
Filter name.
A link between two filters.
static uint64_t lerp_colors16(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
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
A filter pad used for either input or output.
attribute_deprecated int interlaced_frame
The content of the picture is interlaced.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
static const AVOption gradients_options[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
attribute_deprecated int key_frame
1 -> keyframe, 0-> not
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_PIX_FMT_RGBA64
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
static const AVFilterPad gradients_outputs[]
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
@ AV_PICTURE_TYPE_I
Intra.
int64_t duration
duration expressed in microseconds
static __device__ float sqrtf(float a)
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
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
Context structure for the Lagged Fibonacci PRNG.
enum AVPictureType pict_type
Picture type of the frame.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FILTER_PIXFMTS(...)
float fmaxf(float, float)
int format
agreed upon media format
AVFilterContext * src
source filter
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
static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
static float lerpf(float a, float b, float x)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
AVFILTER_DEFINE_CLASS(gradients)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int h
agreed upon image height
static uint64_t lerp_color16(uint8_t c0[4], uint8_t c1[4], float x)
#define AV_PIX_FMT_GBRAPF32
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
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 const int factor[16]
#define FF_DISABLE_DEPRECATION_WARNINGS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
int(* draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static float project(float origin_x, float origin_y, float dest_x, float dest_y, float point_x, float point_y, int type)
static int activate(AVFilterContext *ctx)
#define FILTER_OUTPUTS(array)
static int config_output(AVFilterLink *outlink)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
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
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...
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static uint32_t lerp_color(uint8_t c0[4], uint8_t c1[4], float x)
static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int nb_jobs)