28 #include "libavutil/opt.h"
43 #define OFFSET(x) offsetof(EdgeDetectContext, x)
44 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
57 edgedetect->
low_u8 = edgedetect->
low * 255. + .5;
88 memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
89 memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
90 for (j = 2; j < h - 2; j++) {
93 for (i = 2; i < w - 2; i++) {
95 dst[i] = ((src[-2*src_linesize + i-2] + src[2*src_linesize + i-2]) * 2
96 + (src[-2*src_linesize + i-1] + src[2*src_linesize + i-1]) * 4
97 + (src[-2*src_linesize + i ] + src[2*src_linesize + i ]) * 5
98 + (src[-2*src_linesize + i+1] + src[2*src_linesize + i+1]) * 4
99 + (src[-2*src_linesize + i+2] + src[2*src_linesize + i+2]) * 2
101 + (src[ -src_linesize + i-2] + src[ src_linesize + i-2]) * 4
102 + (src[ -src_linesize + i-1] + src[ src_linesize + i-1]) * 9
103 + (src[ -src_linesize + i ] + src[ src_linesize + i ]) * 12
104 + (src[ -src_linesize + i+1] + src[ src_linesize + i+1]) * 9
105 + (src[ -src_linesize + i+2] + src[ src_linesize + i+2]) * 4
111 + src[i+2] * 5) / 159;
114 dst[i + 1] = src[i + 1];
119 memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
143 int tanpi8gx, tan3pi8gx;
148 tanpi8gx = 27146 * gx;
149 tan3pi8gx = 158218 * gx;
158 uint16_t *dst,
int dst_linesize,
164 for (j = 1; j < h - 1; j++) {
167 for (i = 1; i < w - 1; i++) {
169 -1*src[-src_linesize + i-1] + 1*src[-src_linesize + i+1]
170 -2*src[ i-1] + 2*src[ i+1]
171 -1*src[ src_linesize + i-1] + 1*src[ src_linesize + i+1];
173 -1*src[-src_linesize + i-1] + 1*src[ src_linesize + i-1]
174 -2*src[-src_linesize + i ] + 2*src[ src_linesize + i ]
175 -1*src[-src_linesize + i+1] + 1*src[ src_linesize + i+1];
184 uint8_t *dst,
int dst_linesize,
185 const uint16_t *
src,
int src_linesize)
190 #define COPY_MAXIMA(ay, ax, by, bx) do { \
191 if (src[i] > src[(ay)*src_linesize + i+(ax)] && \
192 src[i] > src[(by)*src_linesize + i+(bx)]) \
193 dst[i] = av_clip_uint8(src[i]); \
196 for (j = 1; j < h - 1; j++) {
199 for (i = 1; i < w - 1; i++) {
211 uint8_t *dst,
int dst_linesize,
216 const int low = edgedetect->
low_u8;
217 const int high = edgedetect->
high_u8;
219 for (j = 0; j < h; j++) {
220 for (i = 0; i < w; i++) {
226 if ((!i || i == w - 1 || !j || j == h - 1) &&
228 (src[-src_linesize + i-1] > high ||
229 src[-src_linesize + i ] > high ||
230 src[-src_linesize + i+1] > high ||
233 src[ src_linesize + i-1] > high ||
234 src[ src_linesize + i ] > high ||
235 src[ src_linesize + i+1] > high))
251 uint16_t *gradients = edgedetect->
gradients;
273 sobel(ctx, inlink->
w, inlink->
h,
274 gradients, inlink->
w,
279 memset(tmpbuf, 0, inlink->
w * inlink->
h);
282 gradients, inlink->
w);
321 .
name =
"edgedetect",
327 .
inputs = edgedetect_inputs,
329 .priv_class = &edgedetect_class,
static const AVFilterPad edgedetect_outputs[]
static void double_threshold(AVFilterContext *ctx, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
static av_cold void uninit(AVFilterContext *ctx)
This structure describes decoded (raw) audio or video data.
static void non_maximum_suppression(AVFilterContext *ctx, int w, int h, uint8_t *dst, int dst_linesize, const uint16_t *src, int src_linesize)
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
int h
agreed upon image height
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int query_formats(AVFilterContext *ctx)
A filter pad used for either input or output.
A link between two filters.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static const AVOption edgedetect_options[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFilter avfilter_vf_edgedetect
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int config_props(AVFilterLink *inlink)
AVPixelFormat
Pixel format.
int w
agreed upon image width
static void gaussian_blur(AVFilterContext *ctx, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int get_rounded_direction(int gx, int gy)
Main libavfilter public API header.
static const AVFilterPad edgedetect_inputs[]
AVFilterLink ** outputs
array of pointers to output links
static av_cold int init(AVFilterContext *ctx)
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilterContext * dst
dest filter
#define COPY_MAXIMA(ay, ax, by, bx)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define AVFILTER_DEFINE_CLASS(fname)
static void sobel(AVFilterContext *ctx, int w, int h, uint16_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.