Go to the documentation of this file.
67 #define OFFSET(x) offsetof(ColorMapContext, x)
68 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
85 for (
int k = 0; k < n; k++) {
89 for (
int i = k + 1;
i < n;
i++)
94 A[k + n * m] =
A[k + n * k];
97 for (
int i = k + 1;
i < n;
i++)
100 for (
int i = k + 1;
i < n;
i++) {
101 double t2 =
A[
i + n * m];
102 A[
i + n * m] =
A[
i + n * k];
105 for (
int j = k + 1; j < n; j++)
106 for (
int i = k + 1;
i < n;
i++)
107 A[
i + n * j] +=
A[k + j * n] *
A[
i + k * n];
118 for(
int k = 0; k < n - 1; k++) {
123 for (
int i = k + 1;
i < n;
i++)
124 b[
i] +=
A[k + n *
i] * t;
127 for(
int k = n - 1; k > 0; k--) {
128 double t =
b[k] /=
A[k + n * k];
129 for (
int i = 0;
i < k;
i++)
130 b[
i] -=
A[k + n *
i] * t;
133 b[0] /=
A[0 + 0 * n];
150 #define P2(x) ((x)*(x))
154 const float d2 =
P2(x[0]-y[0]) +
162 const float rm = (x[0] + y[0]) * 0.5
f;
163 const float d2 =
P2(x[0]-y[0]) * (2.f + rm) +
164 P2(x[1]-y[1]) * 4.f +
165 P2(x[2]-y[2]) * (3.f - rm);
173 for (
int j = 0; j <
s->nb_maps; j++) {
174 s->target[j][0] =
s->target_type == 0 ?
s->source[j][0] +
s->ttarget[j][0] :
s->ttarget[j][0];
175 s->target[j][1] =
s->target_type == 0 ?
s->source[j][1] +
s->ttarget[j][1] :
s->ttarget[j][1];
176 s->target[j][2] =
s->target_type == 0 ?
s->source[j][2] +
s->ttarget[j][2] :
s->ttarget[j][2];
179 for (
int c = 0;
c < 3;
c++) {
180 for (
int j = 0; j <
s->nb_maps; j++)
181 s->coeff[j][
c] = 0.f;
183 for (
int j = 0; j < 4; j++) {
189 s->icoeff[
c+1][
c] = 1.f;
191 switch (
s->nb_maps) {
194 float div =
fabsf(
s->source[0][
c]) < 1e-6
f ? 1e-6
f :
s->source[0][
c];
195 s->icoeff[
c][1+
c] =
s->target[0][
c] / div;
200 double A[2 * 2] = { 1,
s->source[0][
c],
201 1,
s->source[1][
c] };
202 double b[2] = {
s->target[0][
c],
s->target[1][
c] };
207 s->icoeff[0 ][
c] =
b[0];
208 s->icoeff[1+
c][
c] =
b[1];
213 const uint8_t idx[3][3] = {{ 0, 1, 2 },
216 const uint8_t didx[3][4] = {{ 0, 1, 2, 2 },
219 const int C0 = idx[
c][0];
220 const int C1 = idx[
c][1];
221 const int C2 = idx[
c][2];
222 double A[3 * 3] = { 1,
s->source[0][
C0],
s->source[0][
C1] +
s->source[0][
C2],
223 1,
s->source[1][
C0],
s->source[1][
C1] +
s->source[1][
C2],
224 1,
s->source[2][
C0],
s->source[2][
C1] +
s->source[2][
C2] };
225 double b[3] = {
s->target[0][
c],
s->target[1][
c],
s->target[2][
c] };
230 s->icoeff[0][
c] =
b[didx[
c][0]];
231 s->icoeff[1][
c] =
b[didx[
c][1]];
232 s->icoeff[2][
c] =
b[didx[
c][2]];
233 s->icoeff[3][
c] =
b[didx[
c][3]];
238 double A[4 * 4] = { 1,
s->source[0][0],
s->source[0][1],
s->source[0][2],
239 1,
s->source[1][0],
s->source[1][1],
s->source[1][2],
240 1,
s->source[2][0],
s->source[2][1],
s->source[2][2],
241 1,
s->source[3][0],
s->source[3][1],
s->source[3][2] };
242 double b[4] = {
s->target[0][
c],
s->target[1][
c],
s->target[2][
c],
s->target[3][
c] };
249 s->icoeff[0][
c] =
b[0];
250 s->icoeff[1][
c] =
b[1];
251 s->icoeff[2][
c] =
b[2];
252 s->icoeff[3][
c] =
b[3];
257 const int N =
s->nb_maps;
258 const int N4 =
N + 4;
261 int *pivot =
s->pivot;
263 for (
int j = 0; j <
N; j++)
264 for (
int i = j;
i <
N;
i++)
265 A[j*N4+
i] =
A[
i*N4+j] =
s->kernel(
s->source[
i],
s->source[j]);
267 for (
int i = 0;
i <
N;
i++)
268 A[
i*N4+
N+0] =
A[(
N+0)*N4+
i] = 1;
269 for (
int i = 0;
i <
N;
i++)
270 A[
i*N4+
N+1] =
A[(
N+1)*N4+
i] =
s->source[
i][0];
271 for (
int i = 0;
i <
N;
i++)
272 A[
i*N4+
N+2] =
A[(
N+2)*N4+
i] =
s->source[
i][1];
273 for (
int i = 0;
i <
N;
i++)
274 A[
i*N4+
N+3] =
A[(
N+3)*N4+
i] =
s->source[
i][2];
276 for (
int j =
N; j < N4; j++)
277 for (
int i =
N;
i < N4;
i++)
281 for (
int i = 0;
i <
N;
i++)
282 b[
i] =
s->target[
i][
c];
288 for (
int i = 0;
i <
N;
i++)
289 s->coeff[
i][
c] =
b[
i];
291 for (
int i = 0;
i < 4;
i++)
292 s->icoeff[
i][
c] =
b[
N +
i];
309 const int maps =
s->nb_maps;
312 const int slice_start = (
height * jobnr) / nb_jobs;
314 const int sr_linesize = in->
linesize[2] / 4;
315 const int dr_linesize =
out->linesize[2] / 4;
316 const int sg_linesize = in->
linesize[0] / 4;
317 const int dg_linesize =
out->linesize[0] / 4;
318 const int sb_linesize = in->
linesize[1] / 4;
319 const int db_linesize =
out->linesize[1] / 4;
320 const float *sr = (
float *)in->
data[2] + slice_start * sr_linesize;
321 const float *sg = (
float *)in->
data[0] + slice_start * sg_linesize;
322 const float *sb = (
float *)in->
data[1] + slice_start * sb_linesize;
323 float *
r = (
float *)
out->data[2] + slice_start * dr_linesize;
324 float *
g = (
float *)
out->data[0] + slice_start * dg_linesize;
325 float *
b = (
float *)
out->data[1] + slice_start * db_linesize;
326 float (*kernel)(
const float *x,
const float *y) =
s->kernel;
327 const float *
icoeff[4] = {
s->icoeff[0],
s->icoeff[1],
s->icoeff[2],
s->icoeff[3] };
329 for (
int y = slice_start; y <
slice_end; y++) {
330 for (
int x = 0; x <
width; x++) {
331 const float input[3] = { sr[x], sg[x], sb[x] };
347 for (
int z = 0; z < maps && maps > 4; z++) {
348 const float *
coeff =
s->coeff[z];
350 const float cg =
coeff[1];
352 const float f = kernel(
input,
s->source[z]);
381 const int pw2 =
s->w / 2;
383 const int ph2 =
s->h / 2;
387 for (
int plane = 0; plane < 3; plane++) {
388 const int c = plane == 0 ? 1 : plane == 1 ? 2 : 0;
392 const float *
src = (
const float *)(in->
data[plane] + y * in->
linesize[plane]);
394 for (
int x = pw2; x < in->
width && idx <
MAX_SIZE; x += pw) {
398 if (
s->ttarget[idx][
c] !=
value)
402 if (
s->source[idx][
c] !=
value)
413 s->changed[is_target] = 1;
417 s->nb_maps =
FFMIN(idx,
s->size);
431 switch (
s->kernel_type) {
450 if (
s->changed[0] ||
s->changed[1]) {
452 s->changed[0] =
s->changed[1] = 0;
455 if (!
ctx->is_disabled) {
565 .priv_class = &colormap_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVRational time_base
Time base for the incoming frames.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
static double cb(void *priv, double x, double y)
static int gauss_solve(double *A, double *b, int n)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
AVFILTER_DEFINE_CLASS(colormap)
const char * name
Filter name.
@ EXT_INFINITY
Extend the frame to infinity.
A link between two filters.
static float euclidean_kernel(const float *x, const float *y)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const AVOption colormap_options[]
@ EXT_STOP
Completely stop all streams with this one.
static void build_map(AVFilterContext *ctx)
float ttarget[MAX_SIZE][4]
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
static __device__ float fabsf(float a)
float source[MAX_SIZE][4]
A filter pad used for either input or output.
#define FF_ARRAY_ELEMS(a)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
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,...
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void gauss_solve_triangular(const double *A, const int *p, double *b, int n)
#define FILTER_INPUTS(array)
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define fs(width, name, subs,...)
static int process_frame(FFFrameSync *fs)
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
float target[MAX_SIZE][4]
static int colormap_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static __device__ float sqrtf(float a)
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
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FILTER_PIXFMTS(...)
#define AV_PIX_FMT_GBRPF32
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
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.
double A[(MAX_SIZE+4) *(MAX_SIZE+4)]
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
static const AVFilterPad outputs[]
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#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.
Used for passing data between threads.
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 default value
static int import_map(AVFilterLink *inlink, AVFrame *in)
const char * name
Pad name.
static const AVFilterPad inputs[]
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
static int config_output(AVFilterLink *outlink)
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
int h
agreed upon image height
#define FF_INLINK_IDX(link)
Find the index of a link.
#define AV_PIX_FMT_GBRAPF32
static int gauss_make_triangular(double *A, int *p, int n)
static float weuclidean_kernel(const float *x, const float *y)
static av_cold void uninit(AVFilterContext *ctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static const double icoeff[2][5]
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
static double cr(void *priv, double x, double y)
#define FILTER_OUTPUTS(array)
float(* kernel)(const float *x, const float *y)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#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...
static const double coeff[2][5]
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
const AVFilter ff_vf_colormap
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static int activate(AVFilterContext *ctx)