Go to the documentation of this file.
126 #define OFFSET(x) offsetof(MorphoContext, x)
127 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
140 {
"first",
"process only first structure, ignore rest", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0,
FLAGS,
"str" },
169 static void min_fun(uint8_t *
c,
const uint8_t *
a,
const uint8_t *
b,
int x)
171 for (
int i = 0;
i < x;
i++)
177 for (
int i = 0;
i < x;
i++)
181 static void max_fun(uint8_t *
c,
const uint8_t *
a,
const uint8_t *
b,
int x)
183 for (
int i = 0;
i < x;
i++)
189 for (
int i = 0;
i < x;
i++)
195 for (
int i = 0;
i < x;
i++)
201 for (
int i = 0;
i < x;
i++)
205 static void min16_fun(uint8_t *cc,
const uint8_t *aa,
const uint8_t *bb,
int x)
207 const uint16_t *
a = (
const uint16_t *)aa;
208 const uint16_t *
b = (
const uint16_t *)bb;
209 uint16_t *
c = (uint16_t *)cc;
211 for (
int i = 0;
i < x;
i++)
217 uint16_t *
a = (uint16_t *)aa;
218 const uint16_t *
b = (
const uint16_t *)bb;
220 for (
int i = 0;
i < x;
i++)
224 static void diff16_fun(uint8_t *aa,
const uint8_t *bb,
int x)
226 const uint16_t *
b = (
const uint16_t *)bb;
227 uint16_t *
a = (uint16_t *)aa;
229 for (
int i = 0;
i < x;
i++)
235 uint16_t *
a = (uint16_t *)aa;
236 const uint16_t *
b = (
const uint16_t *)bb;
238 for (
int i = 0;
i < x;
i++)
242 static void max16_fun(uint8_t *cc,
const uint8_t *aa,
const uint8_t *bb,
int x)
244 const uint16_t *
a = (
const uint16_t *)aa;
245 const uint16_t *
b = (
const uint16_t *)bb;
246 uint16_t *
c = (uint16_t *)cc;
248 for (
int i = 0;
i < x;
i++)
254 uint16_t *
a = (uint16_t *)aa;
255 const uint16_t *
b = (
const uint16_t *)bb;
257 for (
int i = 0;
i < x;
i++)
268 pre_pad_x = 0 -
SE->minX;
279 for (
int i = 0;
i < Ty->
I;
i++) {
284 memset(arr[
i], UINT8_MAX, pre_pad_x * type_size);
288 arr[
i] = &(arr[
i][pre_pad_x * type_size]);
302 if (!
table->base_arr)
308 for (
int i = 0;
i <
table->I;
i++) {
323 if (!Ty->
arr || Ty->
I !=
SE->Lnum ||
327 Ty->
max_r !=
SE->maxY + num - 1) {
335 Ty->
max_r =
SE->maxY + num - 1;
352 for (
int r = Ty->
min_r; r < Ty->max_r;
r++)
361 if (y +
r >= 0 && y + r < f->
h) {
367 for (
int i = 1;
i <
SE->Lnum;
i++) {
368 int d =
SE->R[
i] -
SE->R[
i - 1];
374 memcpy(Ty->
arr[
r][
i] + (Ty->
X -
d) *
f->type_size,
375 Ty->
arr[
r][
i - 1] + (Ty->
X -
d) *
f->type_size,
382 for (
int i = 0;
i < num;
i++)
394 for (
int r = Ty->
min_r; r <= Ty->max_r;
r++)
402 if (y +
r >= 0 && y + r < f->
h) {
408 for (
int i = 1;
i <
SE->Lnum;
i++) {
409 int d =
SE->R[
i] -
SE->R[
i - 1];
415 memcpy(Ty->
arr[
r][
i] + (Ty->
X -
d) *
f->type_size,
416 Ty->
arr[
r][
i - 1] + (Ty->
X -
d) *
f->type_size,
423 for (
int i = 0;
i < num;
i++)
435 for (
int r = Ty->
min_r; r <= Ty->max_r;
r++)
443 memset(
g->img[y], 0,
g->w *
g->type_size);
445 for (
int c = 0;
c <
SE->size;
c++) {
446 g->max_in_place(
g->img[y],
454 memset(
g->img[y], UINT8_MAX,
g->w *
g->type_size);
456 for (
int c = 0;
c <
SE->size;
c++) {
457 g->min_in_place(
g->img[y],
470 for (
int y = 1; y <
f->h; y++) {
485 for (
int y = 1; y <
f->h; y++) {
495 for (
int y = 0; y <
f->h; y++)
496 f->diff_in_place(
g->img[y],
f->img[y],
f->w);
501 for (
int y = 0; y <
f->h; y++)
502 f->diff_rin_place(
g->img[y],
f->img[y],
f->w);
508 if (chords->
size == chords->
cap) {
516 chords->
C[chords->
size].
x =
c.x;
517 chords->
C[chords->
size].
y =
c.y;
518 chords->
C[chords->
size++].
l =
c.l;
549 chords->
minX = INT16_MAX;
550 chords->
maxX = INT16_MIN;
551 chords->
minY = INT16_MAX;
552 chords->
maxY = INT16_MIN;
563 return (
a.l >
b.l) - (
a.l <
b.l);
572 return (
a.y >
b.y) - (
a.y <
b.y);
577 const int mid = 1 << (
SE->depth - 1);
578 int chord_length_index;
579 int chord_start,
val,
ret;
580 int centerX, centerY;
591 centerX = (
SE->w - 1) / 2;
592 centerY = (
SE->h - 1) / 2;
597 for (
int y = 0; y <
SE->h; y++) {
601 for (x = 0; x <
SE->w; x++) {
602 if (
SE->type_size == 1) {
605 if (
SE->img[y][x] >= mid && chord_start == -1) {
608 }
else if (
SE->img[y][x] < mid && chord_start != -1) {
610 c.x = chord_start - centerX;
612 c.l = x - chord_start;
621 if (
AV_RN16(&
SE->img[y][x * 2]) >= mid && chord_start == -1) {
624 }
else if (
AV_RN16(&
SE->img[y][x * 2]) < mid && chord_start != -1) {
626 c.x = chord_start - centerX;
628 c.l = x - chord_start;
636 if (chord_start != -1) {
638 c.x = chord_start - centerX;
640 c.l = x - chord_start;
660 if (chords->
size > 0) {
662 if (chords->
Lnum >= r_cap) {
668 chords->
R[chords->
Lnum++] = 1;
672 for (
int i = 0;
i < chords->
size;
i++) {
673 if (
val != chords->
C[
i].
l) {
674 while (2 * val < chords->
C[
i].l &&
val != 0) {
675 if (chords->
Lnum >= r_cap) {
682 chords->
R[chords->
Lnum++] = 2 *
val;
687 if (chords->
Lnum >= r_cap) {
702 chord_length_index = 0;
703 for (
int i = 0;
i < chords->
size;
i++) {
704 while (chords->
R[chord_length_index] < chords->
C[
i].
l)
705 chord_length_index++;
706 chords->
C[
i].
i = chord_length_index;
725 int w,
int h,
int R,
int type_size,
int depth)
744 for (
int y = 0; y <
h; y++)
745 imp->
img[y] = (uint8_t *)dst + y * dst_linesize;
755 s->depth =
desc->comp[0].depth;
756 s->type_size = (
s->depth + 7) / 8;
757 s->nb_planes =
desc->nb_components;
759 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
761 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
775 s->splanewidth[0] =
s->splanewidth[3] =
inlink->w;
777 s->splaneheight[0] =
s->splaneheight[3] =
inlink->h;
810 for (
int p = 0; p <
s->nb_planes; p++) {
811 const uint8_t *
src = in->
data[p];
813 const uint8_t *ssrc = structurepic->data[p];
814 const int ssrc_linesize = structurepic->linesize[p];
815 uint8_t *dst =
out->data[p];
816 int dst_linesize =
out->linesize[p];
817 const int swidth =
s->splanewidth[p];
818 const int sheight =
s->splaneheight[p];
819 const int width =
s->planewidth[p];
820 const int height =
s->planeheight[p];
821 const int depth =
s->depth;
822 int type_size =
s->type_size;
824 if (
ctx->is_disabled || !(
s->planes & (1 << p))) {
830 width * ((
s->depth + 7) / 8),
835 if (!
s->got_structure[p] ||
s->structures) {
838 ret =
read_iplane(&
s->SEimg[p], ssrc, ssrc_linesize, swidth, sheight, 1, type_size, depth);
844 s->got_structure[p] = 1;
847 if (
s->SE[p].minX == INT16_MAX ||
848 s->SE[p].minY == INT16_MAX ||
849 s->SE[p].maxX == INT16_MIN ||
850 s->SE[p].maxY == INT16_MIN)
857 ret =
read_iplane(&
s->g[p], dst, dst_linesize,
s->f[p].w,
s->f[p].h,
s->f[p].range, type_size, depth);
863 ret =
erode(&
s->g[p], &
s->f[p], &
s->SE[p], &
s->Ty[0][p]);
872 ret =
erode(&
s->h[p], &
s->f[p], &
s->SE[p], &
s->Ty[0][p]);
884 ret =
erode(&
s->g[p], &
s->h[p], &
s->SE[p], &
s->Ty[1][p]);
893 ret =
erode(&
s->h[p], &
s->f[p], &
s->SE[p], &
s->Ty[1][p]);
902 ret =
erode(&
s->h[p], &
s->f[p], &
s->SE[p], &
s->Ty[0][p]);
917 ret =
erode(&
s->g[p], &
s->h[p], &
s->SE[p], &
s->Ty[1][p]);
950 outlink->
w = mainlink->
w;
951 outlink->
h = mainlink->
h;
964 s->plane_f =
av_calloc(outlink->
w * outlink->
h,
sizeof(*
s->plane_f));
965 s->plane_g =
av_calloc(outlink->
w * outlink->
h,
sizeof(*
s->plane_g));
966 if (!
s->plane_f || !
s->plane_g)
976 for (
int p = 0; p < 4; p++) {
1000 .name =
"structure",
1017 .preinit = morpho_framesync_preinit,
1019 .priv_class = &morpho_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRAP16
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
AVPixelFormat
Pixel format.
static void line_erode(IPlane *g, LUT *Ty, chord_set *SE, int y, int tid)
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.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static void free_chord_set(chord_set *SE)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static void mininplace_fun(uint8_t *a, const uint8_t *b, int x)
void(* min_in_place)(uint8_t *a, const uint8_t *b, int x)
#define FILTER_PIXFMTS_ARRAY(array)
static void diffinplace_fun(uint8_t *a, const uint8_t *b, int x)
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
static int activate(AVFilterContext *ctx)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
static const uint16_t table[]
#define AV_PIX_FMT_YUV420P10
static int alloc_lut_if_necessary(LUT *Ty, IPlane *f, chord_set *SE, int y, int num, enum MorphModes mode)
const AVFilter ff_vf_morpho
FRAMESYNC_DEFINE_CLASS(morpho, MorphoContext, fs)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
void(* min_out_place)(uint8_t *c, const uint8_t *a, const uint8_t *b, int x)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_GBRP14
static int alloc_lut(LUT *Ty, chord_set *SE, int type_size, int mode)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUVA444P16
static void min16_fun(uint8_t *cc, const uint8_t *aa, const uint8_t *bb, int x)
#define AV_PIX_FMT_YUV422P9
static double val(void *priv, double ch)
#define AV_PIX_FMT_GRAY16
static enum AVPixelFormat pix_fmts[]
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static av_cold void uninit(AVFilterContext *ctx)
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
#define AV_PIX_FMT_YUV422P16
static int do_morpho(FFFrameSync *fs)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_GBRAP10
static void maxinplace16_fun(uint8_t *aa, const uint8_t *bb, int x)
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static void mininplace16_fun(uint8_t *aa, const uint8_t *bb, int x)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
static const AVFilterPad morpho_inputs[]
static void difference2(IPlane *g, IPlane *f)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
static int insert_chord_set(chord_set *chords, chord c)
#define AV_PIX_FMT_GRAY14
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static const struct @321 planes[]
#define AV_PIX_FMT_GRAY10
static void compute_max_row(IPlane *f, LUT *Ty, chord_set *SE, int r, int y)
#define av_realloc_f(p, o, n)
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
void(* diff_in_place)(uint8_t *a, const uint8_t *b, int x)
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 config_input_structure(AVFilterLink *inlink)
static void maxinplace_fun(uint8_t *a, const uint8_t *b, int x)
static void diff16_fun(uint8_t *aa, const uint8_t *bb, int x)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static const AVFilterPad morpho_outputs[]
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
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
static int init_chordset(chord_set *chords)
static void free_lut(LUT *table)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
static void copy(const float *p1, float *p2, const int length)
#define AV_PIX_FMT_YUV422P12
static void free_iplane(IPlane *imp)
static int read_iplane(IPlane *imp, const uint8_t *dst, int dst_linesize, int w, int h, int R, int type_size, int depth)
#define AV_PIX_FMT_YUV444P12
static void line_dilate(IPlane *g, LUT *Ty, chord_set *SE, int y, int tid)
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.
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
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
static int build_chord_set(IPlane *SE, chord_set *chords)
static void max_fun(uint8_t *c, const uint8_t *a, const uint8_t *b, int x)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static int config_output(AVFilterLink *outlink)
#define AV_PIX_FMT_GBRP12
static void diffinplace16_fun(uint8_t *aa, const uint8_t *bb, int x)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
#define AV_PIX_FMT_YUV444P9
static void max16_fun(uint8_t *cc, const uint8_t *aa, const uint8_t *bb, int x)
#define AV_PIX_FMT_YUVA444P9
static void update_max_lut(IPlane *f, LUT *Ty, chord_set *SE, int y, int tid, int num)
#define AV_PIX_FMT_YUV420P12
static void circular_swap(LUT *Ty)
#define AV_PIX_FMT_YUV422P14
int h
agreed upon image height
static void diff_fun(uint8_t *a, const uint8_t *b, int x)
#define AV_PIX_FMT_YUVA422P12
static int config_input(AVFilterLink *inlink)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
static int comp_chord(const void *p, const void *q)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static void min_fun(uint8_t *c, const uint8_t *a, const uint8_t *b, int x)
static int compute_max_lut(LUT *Ty, IPlane *f, chord_set *SE, int y, int num)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
static int comp_chord_length(const void *p, const void *q)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static void update_min_lut(IPlane *f, LUT *Ty, chord_set *SE, int y, int tid, int num)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
void(* max_out_place)(uint8_t *c, const uint8_t *a, const uint8_t *b, int x)
#define AV_PIX_FMT_YUV440P12
static void difference(IPlane *g, IPlane *f)
#define AV_PIX_FMT_YUV444P14
void(* max_in_place)(uint8_t *a, const uint8_t *b, int x)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
#define AV_PIX_FMT_GRAY12
static int erode(IPlane *g, IPlane *f, chord_set *SE, LUT *Ty)
static int compute_min_lut(LUT *Ty, IPlane *f, chord_set *SE, int y, int num)
static const AVOption morpho_options[]
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14
static void compute_min_row(IPlane *f, LUT *Ty, chord_set *SE, int r, int y)
void(* diff_rin_place)(uint8_t *a, const uint8_t *b, int x)
static int dilate(IPlane *g, IPlane *f, chord_set *SE, LUT *Ty)