Go to the documentation of this file.
57 #define OFFSET(x) offsetof(BilateralContext, x)
58 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
93 float inv_sigma_range;
95 inv_sigma_range = 1.0f / (
s->sigmaR * ((1 <<
s->depth) - 1));
99 for (
int i = 0;
i < (1 <<
s->depth);
i++)
100 s->range_table[
i] =
s->alpha *
expf(-
i * inv_sigma_range);
115 s->depth =
desc->comp[0].depth;
119 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
121 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
126 for (
int p = 0; p <
s->nb_planes; p++) {
127 const int w =
s->planewidth[p];
128 const int h =
s->planeheight[p];
134 s->slice_factor_a[p] =
av_calloc(
w,
sizeof(
float));
135 s->slice_factor_b[p] =
av_calloc(
w,
sizeof(
float));
139 if (!
s->img_out_f[p] ||
141 !
s->map_factor_a[p] ||
142 !
s->map_factor_b[p] ||
143 !
s->slice_factor_a[p] ||
144 !
s->slice_factor_a[p] ||
145 !
s->line_factor_a[p] ||
146 !
s->line_factor_a[p])
153 #define BILATERAL_H(type, name) \
154 static void bilateralh_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \
155 int jobnr, int nb_jobs, int plane) \
157 const int width = s->planewidth[plane]; \
158 const int height = s->planeheight[plane]; \
159 const int slice_start = (height * jobnr) / nb_jobs; \
160 const int slice_end = (height * (jobnr+1)) / nb_jobs; \
161 const int src_linesize = in->linesize[plane] / sizeof(type); \
162 const type *src = (const type *)in->data[plane]; \
163 float *img_temp = s->img_temp[plane]; \
164 float *map_factor_a = s->map_factor_a[plane]; \
165 const float *const range_table = s->range_table; \
166 const float alpha = s->alpha; \
167 float ypr, ycr, fp, fc; \
168 const float inv_alpha_ = 1.f - alpha; \
170 for (int y = slice_start; y < slice_end; y++) { \
171 float *temp_factor_x, *temp_x = &img_temp[y * width]; \
172 const type *in_x = &src[y * src_linesize]; \
173 const type *texture_x = &src[y * src_linesize]; \
176 *temp_x++ = ypr = *in_x++; \
177 tpr = *texture_x++; \
179 temp_factor_x = &map_factor_a[y * width]; \
180 *temp_factor_x++ = fp = 1; \
182 for (int x = 1; x < width; x++) { \
185 type tcr = *texture_x++; \
186 type dr = abs(tcr - tpr); \
189 alpha_ = range_table[range_dist]; \
190 *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \
193 *temp_factor_x++ = fc = inv_alpha_ + alpha_ * fp; \
196 --temp_x; *temp_x = ((*temp_x) + (*--in_x)); \
197 tpr = *--texture_x; \
200 --temp_factor_x; *temp_factor_x = ((*temp_factor_x) + 1); \
203 for (int x = width - 2; x >= 0; x--) { \
204 type tcr = *--texture_x; \
205 type dr = abs(tcr - tpr); \
206 int range_dist = dr; \
207 float alpha_ = range_table[range_dist]; \
209 ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \
210 --temp_x; *temp_x = ((*temp_x) + ycr); \
214 fc = inv_alpha_ + alpha_*fp; \
216 *temp_factor_x = ((*temp_factor_x) + fc); \
225 #define BILATERAL_V(type, name) \
226 static void bilateralv_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \
227 int jobnr, int nb_jobs, int plane) \
229 const int width = s->planewidth[plane]; \
230 const int height = s->planeheight[plane]; \
231 const int slice_start = (width * jobnr) / nb_jobs; \
232 const int slice_end = (width * (jobnr+1)) / nb_jobs; \
233 const int src_linesize = in->linesize[plane] / sizeof(type); \
234 const type *src = (const type *)in->data[plane] + slice_start; \
235 float *img_out_f = s->img_out_f[plane] + slice_start; \
236 float *img_temp = s->img_temp[plane] + slice_start; \
237 float *map_factor_a = s->map_factor_a[plane] + slice_start; \
238 float *map_factor_b = s->map_factor_b[plane] + slice_start; \
239 float *slice_factor_a = s->slice_factor_a[plane] + slice_start; \
240 float *slice_factor_b = s->slice_factor_b[plane] + slice_start; \
241 float *line_factor_a = s->line_factor_a[plane] + slice_start; \
242 float *line_factor_b = s->line_factor_b[plane] + slice_start; \
243 const float *const range_table = s->range_table; \
244 const float alpha = s->alpha; \
245 float *ycy, *ypy, *xcy; \
246 const float inv_alpha_ = 1.f - alpha; \
247 float *ycf, *ypf, *xcf, *in_factor; \
248 const type *tcy, *tpy; \
251 memcpy(img_out_f, img_temp, sizeof(float) * (slice_end - slice_start)); \
253 in_factor = map_factor_a; \
254 memcpy(map_factor_b, in_factor, sizeof(float) * (slice_end - slice_start)); \
255 for (int y = 1; y < height; y++) { \
256 tpy = &src[(y - 1) * src_linesize]; \
257 tcy = &src[y * src_linesize]; \
258 xcy = &img_temp[y * width]; \
259 ypy = &img_out_f[(y - 1) * width]; \
260 ycy = &img_out_f[y * width]; \
262 xcf = &in_factor[y * width]; \
263 ypf = &map_factor_b[(y - 1) * width]; \
264 ycf = &map_factor_b[y * width]; \
265 for (int x = 0; x < slice_end - slice_start; x++) { \
266 type dr = abs((*tcy++) - (*tpy++)); \
267 int range_dist = dr; \
268 float alpha_ = range_table[range_dist]; \
270 *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \
271 *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \
275 ycf = line_factor_a; \
276 ypf = line_factor_b; \
277 memcpy(ypf, &in_factor[h1 * width], sizeof(float) * (slice_end - slice_start)); \
278 for (int x = 0, k = 0; x < slice_end - slice_start; x++) \
279 map_factor_b[h1 * width + x] = (map_factor_b[h1 * width + x] + ypf[k++]); \
281 ycy = slice_factor_a; \
282 ypy = slice_factor_b; \
283 memcpy(ypy, &img_temp[h1 * width], sizeof(float) * (slice_end - slice_start)); \
284 for (int x = 0, k = 0; x < slice_end - slice_start; x++) { \
285 int idx = h1 * width + x; \
286 img_out_f[idx] = (img_out_f[idx] + ypy[k++]) / map_factor_b[h1 * width + x]; \
289 for (int y = h1 - 1; y >= 0; y--) { \
290 float *ycf_, *ypf_, *factor_; \
291 float *ycy_, *ypy_, *out_; \
293 tpy = &src[(y + 1) * src_linesize]; \
294 tcy = &src[y * src_linesize]; \
295 xcy = &img_temp[y * width]; \
298 out_ = &img_out_f[y * width]; \
300 xcf = &in_factor[y * width]; \
303 factor_ = &map_factor_b[y * width]; \
304 for (int x = 0; x < slice_end - slice_start; x++) { \
305 type dr = abs((*tcy++) - (*tpy++)); \
306 int range_dist = dr; \
307 float alpha_ = range_table[range_dist]; \
308 float ycc, fcc = inv_alpha_*(*xcf++) + alpha_*(*ypf_++); \
311 *factor_ = (*factor_ + fcc); \
313 ycc = inv_alpha_*(*xcy++) + alpha_*(*ypy_++); \
315 *out_ = (*out_ + ycc) / (*factor_); \
328 #define BILATERAL_O(type, name) \
329 static void bilateralo_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \
330 int jobnr, int nb_jobs, int plane) \
332 const int width = s->planewidth[plane]; \
333 const int height = s->planeheight[plane]; \
334 const int slice_start = (height * jobnr) / nb_jobs; \
335 const int slice_end = (height * (jobnr+1)) / nb_jobs; \
336 const int dst_linesize = out->linesize[plane] / sizeof(type); \
338 for (int i = slice_start; i < slice_end; i++) { \
339 type *dst = (type *)out->data[plane] + i * dst_linesize; \
340 const float *const img_out_f = s->img_out_f[plane] + i * width; \
341 for (int j = 0; j < width; j++) \
342 dst[j] = lrintf(img_out_f[j]); \
350 int jobnr,
int nb_jobs)
357 for (
int plane = 0; plane <
s->nb_planes; plane++) {
358 if (!(
s->planes & (1 << plane)))
362 bilateralh_byte(
s,
out, in, jobnr, nb_jobs, plane);
364 bilateralh_word(
s,
out, in, jobnr, nb_jobs, plane);
371 int jobnr,
int nb_jobs)
378 for (
int plane = 0; plane <
s->nb_planes; plane++) {
379 if (!(
s->planes & (1 << plane)))
383 bilateralv_byte(
s,
out, in, jobnr, nb_jobs, plane);
385 bilateralv_word(
s,
out, in, jobnr, nb_jobs, plane);
392 int jobnr,
int nb_jobs)
399 for (
int plane = 0; plane <
s->nb_planes; plane++) {
400 if (!(
s->planes & (1 << plane))) {
402 const int height =
s->planeheight[plane];
403 const int slice_start = (
height * jobnr) / nb_jobs;
405 const int width =
s->planewidth[plane];
406 const int linesize = in->
linesize[plane];
407 const int dst_linesize =
out->linesize[plane];
408 const uint8_t *
src = in->
data[plane];
409 uint8_t *dst =
out->data[plane];
413 src + slice_start * linesize,
415 width * ((
s->depth + 7) / 8),
422 bilateralo_byte(
s,
out, in, jobnr, nb_jobs, plane);
424 bilateralo_word(
s,
out, in, jobnr, nb_jobs, plane);
464 for (
int p = 0; p <
s->nb_planes; p++) {
504 .priv_class = &bilateral_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
AVPixelFormat
Pixel format.
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
static int config_params(AVFilterContext *ctx)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define FILTER_PIXFMTS_ARRAY(array)
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 bilateralv_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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
#define AV_PIX_FMT_YUV420P10
@ 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
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUVA444P16
float * slice_factor_a[4]
#define AV_PIX_FMT_YUV422P9
static av_cold void uninit(AVFilterContext *ctx)
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_GRAY16
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 ...
#define AV_PIX_FMT_YUV422P16
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
@ 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 int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int config_input(AVFilterLink *inlink)
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GRAY14
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
AVFILTER_DEFINE_CLASS(bilateral)
#define FILTER_INPUTS(array)
static const AVOption bilateral_options[]
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ 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 __device__ float sqrtf(float a)
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static const AVFilterPad bilateral_inputs[]
#define BILATERAL_H(type, name)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_YUV422P12
float * slice_factor_b[4]
#define AV_PIX_FMT_YUV444P12
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
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.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define BILATERAL_V(type, name)
static int bilateralh_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
#define AV_PIX_FMT_GBRP12
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
static const struct @363 planes[]
@ 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
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUV420P12
static int bilateralo_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUV422P14
static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
int h
agreed upon image height
@ 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
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
const AVFilter ff_vf_bilateral
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define flags(name, subs,...)
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)
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GRAY12
#define BILATERAL_O(type, name)
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14