78#define OFFSET(x) offsetof(GuidedContext, x)
79#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
80#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
118 const int radius =
s->radius;
119 const float *
src = t->
src;
124 w = (radius << 1) + 1;
127 for (
int j = 0;j <
width;j++) {
129 for (
int row = -radius;row <= radius;row++) {
130 for (
int col = -radius;col <= radius;col++) {
134 y = (y < 0) ? 0 : (y >=
width ?
width - 1 : y);
135 temp +=
src[x * src_stride + y];
138 dst[
i * dst_stride + j] =
temp / numPix;
173 }
else if (
s->mode ==
FAST) {
174 if (
s->radius >=
s->sub)
175 s->radius =
s->radius /
s->sub;
181 s->depth =
desc->comp[0].depth;
182 s->width =
ctx->inputs[0]->w;
183 s->height =
ctx->inputs[0]->h;
186 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
188 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
195#define GUIDED(type, name) \
196static int guided_##name(AVFilterContext *ctx, GuidedContext *s, \
197 const uint8_t *ssrc, const uint8_t *ssrcRef, \
198 uint8_t *ddst, int radius, float eps, int width, int height, \
199 int src_stride, int src_ref_stride, int dst_stride, \
203 type *dst = (type *)ddst; \
204 const type *src = (const type *)ssrc; \
205 const type *srcRef = (const type *)ssrcRef; \
208 int h = (height % sub) == 0 ? height / sub : height / sub + 1; \
209 int w = (width % sub) == 0 ? width / sub : width / sub + 1; \
212 const int nb_threads = ff_filter_get_nb_threads(ctx); \
217 float *meanI = s->meanI; \
218 float *meanII = s->meanII; \
219 float *meanP = s->meanP; \
220 float *meanIP = s->meanIP; \
223 float *meanA = s->meanA; \
224 float *meanB = s->meanB; \
226 for (int i = 0;i < h;i++) { \
227 for (int j = 0;j < w;j++) { \
229 I[x] = src[(i * src_stride + j) * sub] / maxval; \
230 II[x] = I[x] * I[x]; \
231 P[x] = srcRef[(i * src_ref_stride + j) * sub] / maxval; \
232 IP[x] = I[x] * P[x]; \
242 ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
245 ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
248 ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
251 ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
253 for (int i = 0;i < h;i++) { \
254 for (int j = 0;j < w;j++) { \
256 float varI = meanII[x] - (meanI[x] * meanI[x]); \
257 float covIP = meanIP[x] - (meanI[x] * meanP[x]); \
258 A[x] = covIP / (varI + eps); \
259 B[x] = meanP[x] - A[x] * meanI[x]; \
265 ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
268 ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
270 for (int i = 0;i < height;i++) { \
271 for (int j = 0;j < width;j++) { \
272 int x = i / sub * w + j / sub; \
273 dst[i * dst_stride + j] = meanA[x] * src[i * src_stride + j] + \
293 for (
int plane = 0; plane <
s->nb_planes; plane++) {
294 if (!(
s->planes & (1 << plane))) {
296 in->data[plane], in->linesize[plane],
297 s->planewidth[plane] * ((
s->depth + 7) / 8),
s->planeheight[plane]);
301 guided_byte(
ctx,
s, in->data[plane],
ref->data[plane], (*out)->data[plane],
s->radius,
s->eps,
302 s->planewidth[plane],
s->planeheight[plane],
303 in->linesize[plane],
ref->linesize[plane], (*out)->linesize[plane], (1 <<
s->depth) - 1.f);
305 guided_word(
ctx,
s, in->data[plane],
ref->data[plane], (*out)->data[plane],
s->radius,
s->eps,
306 s->planewidth[plane],
s->planeheight[plane],
307 in->linesize[plane] / 2,
ref->linesize[plane] / 2, (*out)->linesize[plane] / 2, (1 <<
s->depth) - 1.f);
323 if (
ctx->is_disabled)
344 if (
s->guidance ==
ON) {
345 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w ||
346 ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
352 outlink->
w =
w = mainlink->
w;
353 outlink->
h =
h = mainlink->
h;
372 if (!
s->I || !
s->II || !
s->P || !
s->IP || !
s->meanI || !
s->meanII || !
s->meanP ||
373 !
s->meanIP || !
s->A || !
s->B || !
s->meanA || !
s->meanB)
376 if (
s->guidance ==
OFF)
414 if (
ctx->is_disabled)
447 if (
s->guidance ==
ON) {
449 pad.
name =
"guidance";
462 if (
s->guidance ==
ON)
492 .p.priv_class = &guided_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_guided
static AVFormatContext * ctx
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
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_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
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_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
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_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#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 AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#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_ARRAY(array)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static const struct @257111027162314367033347246032313251342043035002 planes[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
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
int format
agreed upon media format
A filter pad used for either input or output.
int(* config_props)(AVFilterLink *link)
Link configuration callback.
enum AVMediaType type
AVFilterPad type.
const char * name
Pad name.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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.
int(* box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Used for passing data between threads.
static int ref[MAX_W *MAX_W]
#define GUIDED(type, name)
static int box_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *in, AVFrame *ref)
static const AVFilterPad guided_outputs[]
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static const AVOption guided_options[]
static int process_frame(FFFrameSync *fs)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int ref_frame(VVCFrame *dst, const VVCFrame *src)
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)