58#define OFFSET(x) offsetof(BilateralContext, x)
59#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
94 float inv_sigma_range;
96 inv_sigma_range = 1.0f / (
s->sigmaR * ((1 <<
s->depth) - 1));
100 for (
int i = 0;
i < (1 <<
s->depth);
i++)
101 s->range_table[
i] =
s->alpha *
expf(-
i * inv_sigma_range);
116 s->depth =
desc->comp[0].depth;
120 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
122 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
127 for (
int p = 0; p <
s->nb_planes; p++) {
128 const int w =
s->planewidth[p];
129 const int h =
s->planeheight[p];
135 s->slice_factor_a[p] =
av_calloc(
w,
sizeof(
float));
136 s->slice_factor_b[p] =
av_calloc(
w,
sizeof(
float));
140 if (!
s->img_out_f[p] ||
142 !
s->map_factor_a[p] ||
143 !
s->map_factor_b[p] ||
144 !
s->slice_factor_a[p] ||
145 !
s->slice_factor_a[p] ||
146 !
s->line_factor_a[p] ||
147 !
s->line_factor_a[p])
154#define BILATERAL_H(type, name) \
155static void bilateralh_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \
156 int jobnr, int nb_jobs, int plane) \
158 const int width = s->planewidth[plane]; \
159 const int height = s->planeheight[plane]; \
160 const int slice_start = ff_slice_pos(height, jobnr, nb_jobs); \
161 const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs); \
162 const int src_linesize = in->linesize[plane] / sizeof(type); \
163 const type *src = (const type *)in->data[plane]; \
164 float *img_temp = s->img_temp[plane]; \
165 float *map_factor_a = s->map_factor_a[plane]; \
166 const float *const range_table = s->range_table; \
167 const float alpha = s->alpha; \
168 float ypr, ycr, fp, fc; \
169 const float inv_alpha_ = 1.f - alpha; \
171 for (int y = slice_start; y < slice_end; y++) { \
172 float *temp_factor_x, *temp_x = &img_temp[y * width]; \
173 const type *in_x = &src[y * src_linesize]; \
174 const type *texture_x = &src[y * src_linesize]; \
177 *temp_x++ = ypr = *in_x++; \
178 tpr = *texture_x++; \
180 temp_factor_x = &map_factor_a[y * width]; \
181 *temp_factor_x++ = fp = 1; \
183 for (int x = 1; x < width; x++) { \
186 type tcr = *texture_x++; \
187 type dr = abs(tcr - tpr); \
190 alpha_ = range_table[range_dist]; \
191 *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \
194 *temp_factor_x++ = fc = inv_alpha_ + alpha_ * fp; \
197 --temp_x; *temp_x = ((*temp_x) + (*--in_x)); \
198 tpr = *--texture_x; \
201 --temp_factor_x; *temp_factor_x = ((*temp_factor_x) + 1); \
204 for (int x = width - 2; x >= 0; x--) { \
205 type tcr = *--texture_x; \
206 type dr = abs(tcr - tpr); \
207 int range_dist = dr; \
208 float alpha_ = range_table[range_dist]; \
210 ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \
211 --temp_x; *temp_x = ((*temp_x) + ycr); \
215 fc = inv_alpha_ + alpha_*fp; \
217 *temp_factor_x = ((*temp_factor_x) + fc); \
226#define BILATERAL_V(type, name) \
227static void bilateralv_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \
228 int jobnr, int nb_jobs, int plane) \
230 const int width = s->planewidth[plane]; \
231 const int height = s->planeheight[plane]; \
232 const int slice_start = ff_slice_pos(width, jobnr, nb_jobs); \
233 const int slice_end = ff_slice_pos(width, jobnr + 1, nb_jobs); \
234 const int src_linesize = in->linesize[plane] / sizeof(type); \
235 const type *src = (const type *)in->data[plane] + slice_start; \
236 float *img_out_f = s->img_out_f[plane] + slice_start; \
237 float *img_temp = s->img_temp[plane] + slice_start; \
238 float *map_factor_a = s->map_factor_a[plane] + slice_start; \
239 float *map_factor_b = s->map_factor_b[plane] + slice_start; \
240 float *slice_factor_a = s->slice_factor_a[plane] + slice_start; \
241 float *slice_factor_b = s->slice_factor_b[plane] + slice_start; \
242 float *line_factor_a = s->line_factor_a[plane] + slice_start; \
243 float *line_factor_b = s->line_factor_b[plane] + slice_start; \
244 const float *const range_table = s->range_table; \
245 const float alpha = s->alpha; \
246 float *ycy, *ypy, *xcy; \
247 const float inv_alpha_ = 1.f - alpha; \
248 float *ycf, *ypf, *xcf, *in_factor; \
249 const type *tcy, *tpy; \
252 memcpy(img_out_f, img_temp, sizeof(float) * (slice_end - slice_start)); \
254 in_factor = map_factor_a; \
255 memcpy(map_factor_b, in_factor, sizeof(float) * (slice_end - slice_start)); \
256 for (int y = 1; y < height; y++) { \
257 tpy = &src[(y - 1) * src_linesize]; \
258 tcy = &src[y * src_linesize]; \
259 xcy = &img_temp[y * width]; \
260 ypy = &img_out_f[(y - 1) * width]; \
261 ycy = &img_out_f[y * width]; \
263 xcf = &in_factor[y * width]; \
264 ypf = &map_factor_b[(y - 1) * width]; \
265 ycf = &map_factor_b[y * width]; \
266 for (int x = 0; x < slice_end - slice_start; x++) { \
267 type dr = abs((*tcy++) - (*tpy++)); \
268 int range_dist = dr; \
269 float alpha_ = range_table[range_dist]; \
271 *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \
272 *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \
276 ycf = line_factor_a; \
277 ypf = line_factor_b; \
278 memcpy(ypf, &in_factor[h1 * width], sizeof(float) * (slice_end - slice_start)); \
279 for (int x = 0, k = 0; x < slice_end - slice_start; x++) \
280 map_factor_b[h1 * width + x] = (map_factor_b[h1 * width + x] + ypf[k++]); \
282 ycy = slice_factor_a; \
283 ypy = slice_factor_b; \
284 memcpy(ypy, &img_temp[h1 * width], sizeof(float) * (slice_end - slice_start)); \
285 for (int x = 0, k = 0; x < slice_end - slice_start; x++) { \
286 int idx = h1 * width + x; \
287 img_out_f[idx] = (img_out_f[idx] + ypy[k++]) / map_factor_b[h1 * width + x]; \
290 for (int y = h1 - 1; y >= 0; y--) { \
291 float *ycf_, *ypf_, *factor_; \
292 float *ycy_, *ypy_, *out_; \
294 tpy = &src[(y + 1) * src_linesize]; \
295 tcy = &src[y * src_linesize]; \
296 xcy = &img_temp[y * width]; \
299 out_ = &img_out_f[y * width]; \
301 xcf = &in_factor[y * width]; \
304 factor_ = &map_factor_b[y * width]; \
305 for (int x = 0; x < slice_end - slice_start; x++) { \
306 type dr = abs((*tcy++) - (*tpy++)); \
307 int range_dist = dr; \
308 float alpha_ = range_table[range_dist]; \
309 float ycc, fcc = inv_alpha_*(*xcf++) + alpha_*(*ypf_++); \
312 *factor_ = (*factor_ + fcc); \
314 ycc = inv_alpha_*(*xcy++) + alpha_*(*ypy_++); \
316 *out_ = (*out_ + ycc) / (*factor_); \
329#define BILATERAL_O(type, name) \
330static void bilateralo_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \
331 int jobnr, int nb_jobs, int plane) \
333 const int width = s->planewidth[plane]; \
334 const int height = s->planeheight[plane]; \
335 const int slice_start = ff_slice_pos(height, jobnr, nb_jobs); \
336 const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs); \
337 const int dst_linesize = out->linesize[plane] / sizeof(type); \
339 for (int i = slice_start; i < slice_end; i++) { \
340 type *dst = (type *)out->data[plane] + i * dst_linesize; \
341 const float *const img_out_f = s->img_out_f[plane] + i * width; \
342 for (int j = 0; j < width; j++) \
343 dst[j] = lrintf(img_out_f[j]); \
351 int jobnr,
int nb_jobs)
358 for (
int plane = 0; plane <
s->nb_planes; plane++) {
359 if (!(
s->planes & (1 << plane)))
363 bilateralh_byte(
s,
out, in, jobnr, nb_jobs, plane);
365 bilateralh_word(
s,
out, in, jobnr, nb_jobs, plane);
372 int jobnr,
int nb_jobs)
379 for (
int plane = 0; plane <
s->nb_planes; plane++) {
380 if (!(
s->planes & (1 << plane)))
384 bilateralv_byte(
s,
out, in, jobnr, nb_jobs, plane);
386 bilateralv_word(
s,
out, in, jobnr, nb_jobs, plane);
393 int jobnr,
int nb_jobs)
400 for (
int plane = 0; plane <
s->nb_planes; plane++) {
401 if (!(
s->planes & (1 << plane))) {
403 const int height =
s->planeheight[plane];
406 const int width =
s->planewidth[plane];
407 const int linesize = in->
linesize[plane];
408 const int dst_linesize =
out->linesize[plane];
409 const uint8_t *
src = in->
data[plane];
410 uint8_t *
dst =
out->data[plane];
416 width * ((
s->depth + 7) / 8),
423 bilateralo_byte(
s,
out, in, jobnr, nb_jobs, plane);
425 bilateralo_word(
s,
out, in, jobnr, nb_jobs, plane);
465 for (
int p = 0; p <
s->nb_planes; p++) {
502 .p.name =
"bilateral",
504 .p.priv_class = &bilateral_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)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_vf_bilateral
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next 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.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
static __device__ float sqrtf(float a)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#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 AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
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.
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)
#define FILTER_INPUTS(array)
#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)
#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 * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
float * slice_factor_b[4]
float * slice_factor_a[4]
Used for passing data between threads.
static AVFormatContext * ctx
static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
#define BILATERAL_V(type, name)
static int bilateralv_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int bilateralo_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static const AVOption bilateral_options[]
#define BILATERAL_H(type, name)
static av_cold void uninit(AVFilterContext *ctx)
#define BILATERAL_O(type, name)
static int config_params(AVFilterContext *ctx)
static const AVFilterPad bilateral_inputs[]
static int bilateralh_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)