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
74 {
"relative",
"the target colors are relative", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 1,
FLAGS, .unit =
"type" },
75 {
"absolute",
"the target colors are absolute", 0,
AV_OPT_TYPE_CONST, {.i64=1}, 0, 1,
FLAGS, .unit =
"type" },
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.5f;
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-6f ? 1e-6f :
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];
283 for (
int i =
N;
i <
N + 4;
i++)
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;
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;
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] };
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) {
498 outlink->
w = inlink->
w;
499 outlink->
h = inlink->
h;
565 .p.name =
"colormap",
567 .p.priv_class = &colormap_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
const FFFilter ff_vf_colormap
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next 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.
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 int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
#define fs(width, name, subs,...)
common internal and external API header
static __device__ float sqrtf(float a)
static __device__ float fabsf(float a)
static __device__ float fabs(float a)
static av_always_inline int process_frame(AVTextFormatContext *tfc, InputFile *ifile, AVFrame *frame, const AVPacket *pkt, int *packet_new)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
@ EXT_INFINITY
Extend the frame to infinity.
@ 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_INT
Underlying C type is int.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#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 av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define FILTER_PIXFMTS(...)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FF_INLINK_IDX(link)
Find the index of a link.
#define AVFILTER_DEFINE_CLASS(fname)
Macro definitions for various function/variable attributes.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
@ EXT_STOP
Completely stop all streams with this one.
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRAPF32
#define FF_ARRAY_ELEMS(a)
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
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
float(* kernel)(const float *x, const float *y)
float ttarget[MAX_SIZE][4]
double A[(MAX_SIZE+4) *(MAX_SIZE+4)]
float target[MAX_SIZE][4]
float source[MAX_SIZE][4]
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
AVRational time_base
Time base for the incoming frames.
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
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.
Used for passing data between threads.
static AVFormatContext * ctx
static int gauss_make_triangular(double *A, int *p, int n)
static float euclidean_kernel(const float *x, const float *y)
static void gauss_solve_triangular(const double *A, const int *p, double *b, int n)
static void build_map(AVFilterContext *ctx)
static float weuclidean_kernel(const float *x, const float *y)
static int gauss_solve(double *A, double *b, int n)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption colormap_options[]
static int import_map(AVFilterLink *inlink, AVFrame *in)
static int config_output(AVFilterLink *outlink)
static int process_frame(FFFrameSync *fs)
static int colormap_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static double cr(void *priv, double x, double y)
static double cb(void *priv, double x, double y)
static const double coeff[2][5]
static const double icoeff[2][5]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)