46 #define OFFSET(x) offsetof(FOCContext, x)
47 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
97 for(y = 0; y < frame->
height; y++) {
98 for(x = 0; x < frame->
width; x++) {
116 int64_t oo_sum_v = 0;
117 int64_t hh_sum_v = 0;
118 int64_t oh_sum_v = 0;
123 int64_t o_sigma, h_sigma;
125 for(y = 0; y < obj->
height; y++) {
126 for(x = 0; x < obj->
width; x++) {
131 oo_sum_v += o_v * o_v;
132 hh_sum_v += h_v * h_v;
133 oh_sum_v += o_v * h_v;
138 o_sigma = n*oo_sum_v - o_sum_v*(int64_t)o_sum_v;
139 h_sigma = n*hh_sum_v - h_sum_v*(int64_t)h_sum_v;
141 if (o_sigma == 0 || h_sigma == 0)
144 c = (n*oh_sum_v - o_sum_v*(int64_t)h_sum_v) / (sqrt(o_sigma)*sqrt(h_sigma));
162 static float search(
FOCContext *foc,
int pass,
int maxpass,
int xmin,
int xmax,
int ymin,
int ymax,
int *best_x,
int *best_y,
float best_score)
166 if (pass + 1 <= maxpass) {
168 search(foc, pass+1, maxpass, xmin>>1, (xmax+1)>>1, ymin>>1, (ymax+1)>>1, &sub_x, &sub_y, 1.0);
169 xmin =
FFMAX(xmin, 2*sub_x - 4);
170 xmax =
FFMIN(xmax, 2*sub_x + 4);
171 ymin =
FFMAX(ymin, 2*sub_y - 4);
172 ymax =
FFMIN(ymax, 2*sub_y + 4);
175 for (y = ymin; y <= ymax; y++) {
176 for (x = xmin; x <= xmax; x++) {
179 if (score < best_score) {
198 for (i=1; i<foc->
mipmaps; i++) {
202 best_score =
search(foc, 0, 0,
207 &best_x, &best_y, 1.0);
210 &best_x, &best_y, best_score);
274 for (i = 1; i < foc->
mipmaps; i++) {
310 .priv_class = &foc_class,
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
This structure describes decoded (raw) audio or video data.
static const AVFilterPad outputs[]
#define LIBAVUTIL_VERSION_INT
int h
agreed upon image height
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static float search(FOCContext *foc, int pass, int maxpass, int xmin, int xmax, int ymin, int ymax, int *best_x, int *best_y, float best_score)
static av_cold void uninit(AVFilterContext *ctx)
AVDictionary * metadata
metadata.
static const AVFilterPad foc_outputs[]
static AVFrame * downscale(AVFrame *in)
A filter pad used for either input or output.
static const AVFilterPad foc_inputs[]
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
static const AVClass foc_class
int w
agreed upon image width
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
int ff_load_image(uint8_t *data[4], int linesize[4], int *w, int *h, enum AVPixelFormat *pix_fmt, const char *filename, void *log_ctx)
Load image from filename and put the resulting image in data.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static const AVOption foc_options[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFrame * haystack_frame[MAX_MIPMAPS]
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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_log(ac->avr, AV_LOG_TRACE,"%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 av_cold int init(AVFilterContext *ctx)
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it...
static int config_input(AVFilterLink *inlink)
AVFilterContext * dst
dest filter
static int query_formats(AVFilterContext *ctx)
AVPixelFormat
Pixel format.
Miscellaneous utilities which make use of the libavformat library.
AVFrame * needle_frame[MAX_MIPMAPS]