2015-02-25 09:34:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012-2013 Oka Motofumi (chikuzen.mo at gmail dot com)
|
|
|
|
* Copyright (c) 2015 Paul B Mahol
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2022-02-23 12:56:49 +00:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
#include "libavutil/imgutils.h"
|
2018-05-03 10:48:47 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2015-02-25 09:34:32 +00:00
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "avfilter.h"
|
|
|
|
#include "formats.h"
|
|
|
|
#include "internal.h"
|
|
|
|
#include "video.h"
|
|
|
|
|
2018-05-01 13:05:43 +00:00
|
|
|
typedef struct ThreadData {
|
|
|
|
AVFrame *in, *out;
|
|
|
|
} ThreadData;
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
typedef struct NContext {
|
|
|
|
const AVClass *class;
|
|
|
|
int planeheight[4];
|
|
|
|
int planewidth[4];
|
|
|
|
int nb_planes;
|
|
|
|
int threshold[4];
|
|
|
|
int coordinates;
|
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
int depth;
|
2018-11-17 10:07:58 +00:00
|
|
|
int max;
|
2018-05-03 10:48:47 +00:00
|
|
|
int bpc;
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
void (*filter)(uint8_t *dst, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc);
|
2015-02-25 09:34:32 +00:00
|
|
|
} NContext;
|
|
|
|
|
2021-09-29 13:57:43 +00:00
|
|
|
static const enum AVPixelFormat pix_fmts[] = {
|
|
|
|
AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
|
|
|
|
AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
|
|
|
|
AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
|
|
|
|
AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
|
|
|
|
AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
|
|
|
|
AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
|
|
|
|
AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12,
|
|
|
|
AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
|
|
|
|
AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
|
|
|
|
AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
|
|
|
|
AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
|
|
|
|
AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
|
|
|
|
AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
|
|
|
|
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
|
|
|
|
AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
|
|
|
|
AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
|
|
|
|
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
|
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
};
|
2015-02-25 09:34:32 +00:00
|
|
|
|
|
|
|
static void erosion(uint8_t *dst, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2015-02-25 09:34:32 +00:00
|
|
|
{
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int min = p1[x];
|
|
|
|
int limit = FFMAX(min - threshold, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (coord & (1 << i)) {
|
|
|
|
min = FFMIN(min, *(coordinates[i] + x));
|
|
|
|
}
|
|
|
|
min = FFMAX(min, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[x] = min;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
static void erosion16(uint8_t *dstp, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2018-05-03 10:48:47 +00:00
|
|
|
{
|
|
|
|
uint16_t *dst = (uint16_t *)dstp;
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int min = AV_RN16A(&p1[2 * x]);
|
|
|
|
int limit = FFMAX(min - threshold, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (coord & (1 << i)) {
|
|
|
|
min = FFMIN(min, AV_RN16A(coordinates[i] + x * 2));
|
|
|
|
}
|
|
|
|
min = FFMAX(min, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[x] = min;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
static void dilation(uint8_t *dst, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2015-02-25 09:34:32 +00:00
|
|
|
{
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int max = p1[x];
|
|
|
|
int limit = FFMIN(max + threshold, 255);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (coord & (1 << i)) {
|
|
|
|
max = FFMAX(max, *(coordinates[i] + x));
|
|
|
|
}
|
|
|
|
max = FFMIN(max, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[x] = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
static void dilation16(uint8_t *dstp, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2018-05-03 10:48:47 +00:00
|
|
|
{
|
|
|
|
uint16_t *dst = (uint16_t *)dstp;
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int max = AV_RN16A(&p1[x * 2]);
|
2018-11-17 10:07:58 +00:00
|
|
|
int limit = FFMIN(max + threshold, maxc);
|
2018-05-03 10:48:47 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (coord & (1 << i)) {
|
|
|
|
max = FFMAX(max, AV_RN16A(coordinates[i] + x * 2));
|
|
|
|
}
|
|
|
|
max = FFMIN(max, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[x] = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
static void deflate(uint8_t *dst, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2015-02-25 09:34:32 +00:00
|
|
|
{
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int sum = 0;
|
|
|
|
int limit = FFMAX(p1[x] - threshold, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; sum += *(coordinates[i++] + x));
|
|
|
|
|
|
|
|
dst[x] = FFMAX(FFMIN(sum / 8, p1[x]), limit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
static void deflate16(uint8_t *dstp, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2018-05-03 10:48:47 +00:00
|
|
|
{
|
|
|
|
uint16_t *dst = (uint16_t *)dstp;
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int sum = 0;
|
|
|
|
int limit = FFMAX(AV_RN16A(&p1[2 * x]) - threshold, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; sum += AV_RN16A(coordinates[i++] + x * 2));
|
|
|
|
|
2018-11-17 10:07:58 +00:00
|
|
|
dst[x] = FFMAX(FFMIN(sum / 8, AV_RN16A(&p1[2 * x])), limit);
|
2018-05-03 10:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
static void inflate(uint8_t *dst, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2015-02-25 09:34:32 +00:00
|
|
|
{
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int sum = 0;
|
|
|
|
int limit = FFMIN(p1[x] + threshold, 255);
|
|
|
|
|
|
|
|
for (i = 0; i < 8; sum += *(coordinates[i++] + x));
|
|
|
|
|
|
|
|
dst[x] = FFMIN(FFMAX(sum / 8, p1[x]), limit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
static void inflate16(uint8_t *dstp, const uint8_t *p1, int width,
|
2018-11-17 10:07:58 +00:00
|
|
|
int threshold, const uint8_t *coordinates[], int coord,
|
|
|
|
int maxc)
|
2018-05-03 10:48:47 +00:00
|
|
|
{
|
|
|
|
uint16_t *dst = (uint16_t *)dstp;
|
|
|
|
int x, i;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
int sum = 0;
|
2018-11-17 10:07:58 +00:00
|
|
|
int limit = FFMIN(AV_RN16A(&p1[2 * x]) + threshold, maxc);
|
2018-05-03 10:48:47 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 8; sum += AV_RN16A(coordinates[i++] + x * 2));
|
|
|
|
|
2018-11-17 10:07:58 +00:00
|
|
|
dst[x] = FFMIN(FFMAX(sum / 8, AV_RN16A(&p1[x * 2])), limit);
|
2018-05-03 10:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
static int config_input(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
NContext *s = ctx->priv;
|
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
|
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
s->depth = desc->comp[0].depth;
|
2018-11-17 10:07:58 +00:00
|
|
|
s->max = (1 << s->depth) - 1;
|
2018-05-03 10:48:47 +00:00
|
|
|
s->bpc = (s->depth + 7) / 8;
|
2015-02-25 09:34:32 +00:00
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
|
|
|
|
s->planewidth[0] = s->planewidth[3] = inlink->w;
|
2016-01-27 15:19:38 +00:00
|
|
|
s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
|
2015-02-25 09:34:32 +00:00
|
|
|
s->planeheight[0] = s->planeheight[3] = inlink->h;
|
|
|
|
|
|
|
|
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
|
|
|
|
|
|
|
|
if (!strcmp(ctx->filter->name, "erosion"))
|
2018-05-03 10:48:47 +00:00
|
|
|
s->filter = s->depth > 8 ? erosion16 : erosion;
|
2015-02-25 09:34:32 +00:00
|
|
|
else if (!strcmp(ctx->filter->name, "dilation"))
|
2018-05-03 10:48:47 +00:00
|
|
|
s->filter = s->depth > 8 ? dilation16 : dilation;
|
2015-02-25 09:34:32 +00:00
|
|
|
else if (!strcmp(ctx->filter->name, "deflate"))
|
2018-05-03 10:48:47 +00:00
|
|
|
s->filter = s->depth > 8 ? deflate16 : deflate;
|
2015-02-25 09:34:32 +00:00
|
|
|
else if (!strcmp(ctx->filter->name, "inflate"))
|
2018-05-03 10:48:47 +00:00
|
|
|
s->filter = s->depth > 8 ? inflate16 : inflate;
|
2015-02-25 09:34:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-01 13:05:43 +00:00
|
|
|
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
2015-02-25 09:34:32 +00:00
|
|
|
{
|
|
|
|
NContext *s = ctx->priv;
|
2018-05-01 13:05:43 +00:00
|
|
|
ThreadData *td = arg;
|
|
|
|
AVFrame *out = td->out;
|
|
|
|
AVFrame *in = td->in;
|
2015-02-25 09:34:32 +00:00
|
|
|
int plane, y;
|
|
|
|
|
|
|
|
for (plane = 0; plane < s->nb_planes; plane++) {
|
2018-05-03 10:48:47 +00:00
|
|
|
const int bpc = s->bpc;
|
2015-02-25 09:34:32 +00:00
|
|
|
const int threshold = s->threshold[plane];
|
2018-05-01 12:50:48 +00:00
|
|
|
const int stride = in->linesize[plane];
|
|
|
|
const int dstride = out->linesize[plane];
|
|
|
|
const int height = s->planeheight[plane];
|
|
|
|
const int width = s->planewidth[plane];
|
2018-05-01 13:05:43 +00:00
|
|
|
const int slice_start = (height * jobnr) / nb_jobs;
|
|
|
|
const int slice_end = (height * (jobnr+1)) / nb_jobs;
|
|
|
|
const uint8_t *src = (const uint8_t *)in->data[plane] + slice_start * stride;
|
|
|
|
uint8_t *dst = out->data[plane] + slice_start * dstride;
|
2018-05-01 12:50:48 +00:00
|
|
|
|
|
|
|
if (!threshold) {
|
2018-05-03 10:48:47 +00:00
|
|
|
av_image_copy_plane(dst, dstride, src, stride, width * bpc, slice_end - slice_start);
|
2018-05-01 12:50:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2015-02-25 09:34:32 +00:00
|
|
|
|
2018-05-01 13:05:43 +00:00
|
|
|
for (y = slice_start; y < slice_end; y++) {
|
2018-05-01 12:50:48 +00:00
|
|
|
const int nh = y > 0;
|
|
|
|
const int ph = y < height - 1;
|
2018-05-03 10:48:47 +00:00
|
|
|
const uint8_t *coordinates[] = { src - nh * stride, src + 1 * bpc - nh * stride, src + 2 * bpc - nh * stride,
|
|
|
|
src, src + 2 * bpc,
|
|
|
|
src + ph * stride, src + 1 * bpc + ph * stride, src + 2 * bpc + ph * stride};
|
2018-05-01 12:50:48 +00:00
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
const uint8_t *coordinateslb[] = { src + 1 * bpc - nh * stride, src - nh * stride, src + 1 * bpc - nh * stride,
|
|
|
|
src + 1 * bpc, src + 1 * bpc,
|
|
|
|
src + 1 * bpc + ph * stride, src + ph * stride, src + 1 * bpc + ph * stride};
|
2018-05-01 12:50:48 +00:00
|
|
|
|
2018-05-03 10:48:47 +00:00
|
|
|
const uint8_t *coordinatesrb[] = { src + (width - 2) * bpc - nh * stride, src + (width - 1) * bpc - nh * stride, src + (width - 2) * bpc - nh * stride,
|
|
|
|
src + (width - 2) * bpc, src + (width - 2) * bpc,
|
|
|
|
src + (width - 2) * bpc + ph * stride, src + (width - 1) * bpc + ph * stride, src + (width - 2) * bpc + ph * stride};
|
2018-05-01 12:50:48 +00:00
|
|
|
|
2019-10-11 09:18:10 +00:00
|
|
|
s->filter(dst, src, 1, threshold, coordinateslb, s->coordinates, s->max);
|
|
|
|
if (width > 1) {
|
|
|
|
s->filter(dst + 1 * bpc, src + 1 * bpc, width - 2, threshold, coordinates, s->coordinates, s->max);
|
|
|
|
s->filter(dst + (width - 1) * bpc, src + (width - 1) * bpc, 1, threshold, coordinatesrb, s->coordinates, s->max);
|
|
|
|
}
|
2018-05-01 12:50:48 +00:00
|
|
|
|
|
|
|
src += stride;
|
|
|
|
dst += dstride;
|
2015-02-25 09:34:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 13:05:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
NContext *s = ctx->priv;
|
|
|
|
ThreadData td;
|
|
|
|
AVFrame *out;
|
|
|
|
|
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
|
|
|
if (!out) {
|
|
|
|
av_frame_free(&in);
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
av_frame_copy_props(out, in);
|
|
|
|
|
|
|
|
td.in = in;
|
|
|
|
td.out = out;
|
2021-08-15 19:33:25 +00:00
|
|
|
ff_filter_execute(ctx, filter_slice, &td, NULL,
|
|
|
|
FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx)));
|
2018-05-01 13:05:43 +00:00
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
av_frame_free(&in);
|
|
|
|
return ff_filter_frame(outlink, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const AVFilterPad neighbor_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.filter_frame = filter_frame,
|
|
|
|
.config_props = config_input,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad neighbor_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(NContext, x)
|
2019-12-27 19:21:20 +00:00
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
|
2015-02-25 09:34:32 +00:00
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
#define DEFINE_NEIGHBOR_FILTER(name_, description_, priv_class_) \
|
2021-04-19 16:33:56 +00:00
|
|
|
const AVFilter ff_vf_##name_ = { \
|
2015-02-25 09:34:32 +00:00
|
|
|
.name = #name_, \
|
|
|
|
.description = NULL_IF_CONFIG_SMALL(description_), \
|
2021-09-10 20:58:21 +00:00
|
|
|
.priv_class = &priv_class_##_class, \
|
2015-02-25 09:34:32 +00:00
|
|
|
.priv_size = sizeof(NContext), \
|
2021-08-12 11:05:31 +00:00
|
|
|
FILTER_INPUTS(neighbor_inputs), \
|
|
|
|
FILTER_OUTPUTS(neighbor_outputs), \
|
2021-09-27 19:23:04 +00:00
|
|
|
FILTER_PIXFMTS_ARRAY(pix_fmts), \
|
2018-05-01 13:05:43 +00:00
|
|
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC| \
|
|
|
|
AVFILTER_FLAG_SLICE_THREADS, \
|
2019-12-27 19:21:20 +00:00
|
|
|
.process_command = ff_filter_process_command, \
|
2015-02-25 09:34:32 +00:00
|
|
|
}
|
|
|
|
|
2021-01-03 15:41:39 +00:00
|
|
|
/* The following options are shared between all filters here;
|
|
|
|
* the de/inflate filters only use the threshold* options. */
|
|
|
|
#define DEINFLATE_OPTIONS_OFFSET (CONFIG_EROSION_FILTER || CONFIG_DILATION_FILTER)
|
|
|
|
static const AVOption options[] = {
|
|
|
|
#if CONFIG_EROSION_FILTER || CONFIG_DILATION_FILTER
|
|
|
|
{ "coordinates", "set coordinates", OFFSET(coordinates), AV_OPT_TYPE_INT, {.i64=255}, 0, 255, FLAGS },
|
|
|
|
#endif
|
2015-02-25 09:34:32 +00:00
|
|
|
{ "threshold0", "set threshold for 1st plane", OFFSET(threshold[0]), AV_OPT_TYPE_INT, {.i64=65535}, 0, 65535, FLAGS },
|
|
|
|
{ "threshold1", "set threshold for 2nd plane", OFFSET(threshold[1]), AV_OPT_TYPE_INT, {.i64=65535}, 0, 65535, FLAGS },
|
|
|
|
{ "threshold2", "set threshold for 3rd plane", OFFSET(threshold[2]), AV_OPT_TYPE_INT, {.i64=65535}, 0, 65535, FLAGS },
|
|
|
|
{ "threshold3", "set threshold for 4th plane", OFFSET(threshold[3]), AV_OPT_TYPE_INT, {.i64=65535}, 0, 65535, FLAGS },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
AVFILTER_DEFINE_CLASS_EXT(erosion_dilation, "erosion/dilation", options);
|
|
|
|
|
2021-01-03 15:41:39 +00:00
|
|
|
#if CONFIG_EROSION_FILTER
|
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
DEFINE_NEIGHBOR_FILTER(erosion, "Apply erosion effect.", erosion_dilation);
|
2015-02-25 09:34:32 +00:00
|
|
|
|
|
|
|
#endif /* CONFIG_EROSION_FILTER */
|
|
|
|
|
|
|
|
#if CONFIG_DILATION_FILTER
|
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
DEFINE_NEIGHBOR_FILTER(dilation, "Apply dilation effect.", erosion_dilation);
|
2015-02-25 09:34:32 +00:00
|
|
|
|
|
|
|
#endif /* CONFIG_DILATION_FILTER */
|
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
AVFILTER_DEFINE_CLASS_EXT(deflate_inflate, "deflate/inflate",
|
|
|
|
&options[DEINFLATE_OPTIONS_OFFSET]);
|
|
|
|
|
2015-02-25 09:34:32 +00:00
|
|
|
#if CONFIG_DEFLATE_FILTER
|
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
DEFINE_NEIGHBOR_FILTER(deflate, "Apply deflate effect.", deflate_inflate);
|
2015-02-25 09:34:32 +00:00
|
|
|
|
|
|
|
#endif /* CONFIG_DEFLATE_FILTER */
|
|
|
|
|
|
|
|
#if CONFIG_INFLATE_FILTER
|
|
|
|
|
2021-09-10 20:58:21 +00:00
|
|
|
DEFINE_NEIGHBOR_FILTER(inflate, "Apply inflate effect.", deflate_inflate);
|
2015-02-25 09:34:32 +00:00
|
|
|
|
|
|
|
#endif /* CONFIG_INFLATE_FILTER */
|